Add different files with different weights


I have the following problem.

I have 3 file A.root, B.root and C.root. these files contain all exactly the same tree with the same branches. now I would like to add them up, i the following way: (pseudocode)

hadd -weights .5 .7 .1 A.root B.root C.root

what it does is: take .5 from A.root .7 from B.root and .1 events from C.root.

is it possible.

thx a lot.


a tree is an unweighted collection, like a vector. So you need to add weights to each event. You can create a new TTree (TNtuple), you fill just the weight for each original TTree. In the end you have one weight tree for each original tree. Then you merge the original trees into one and the weight trees into a second. When analyzing you declare the weight tree as friend of the original one, and you cam access the weight.

It might sound complex, but it’s actually pretty straight forward :slight_smile:

Cheers, Axel.