Filling a tchain with only some entries from each TFile

Hello,
I have three rootfiles with the same TTree, sig1.root, sig2.root and bkg.root.
Each sample has its own cross section and a different number of events; I want to “merge” this TTrees to the same integrated luminosity.
I must use the output TTree in RooFit, so I think that doing something like TTree::SetWeight for each TTree in the TChain will not work.

My idea was: compute the number of events, for each sample, corresponding to the same integrated luminosity, and then

TChain dataset("treename"); dataset.Add("sig1.root", sig1_wanted_events); dataset.Add("sig2.root", sig2_wanted_events); dataset.Add("bkg.root", bkg_wanted_events);
However, this solution does not work, I actually don’t know why (I even get some odd behaviour, e.g. the TChain::GetEntries() method returns a different value if called different times, something I quite do not understand). Any suggestions?

Thank you.

Hi,

The 2nd argument to TChain::Add is indicatively only and is used to pre-compute the chain total length before actually opening the file(s). Once the file is opened the actual number of entries is used.

The best solution is to use a TEntryList object to select which entries you want to use within the TTree/TChain (assuming that the tool you use is respecting the TEntryList).

Cheers,
Philippe.

Could the TTree::CloneTree method be a solution?

Hi,

Yes alternatively you could physically copy the files by using CloneTree on each of your input file and selecting a subset of the entries.

Cheers,
Philippe.