Reading a given tree across multiple root files

Hi all,

While trying to read a tree having same name from across multiple root files, I am looping all the root files and loading the tree and finally reading it using a TreeReader().

Is there any more efficient way in root to directly create a combined tree by merging all the entries in all the trees across the root files.
If yes, is this more efficient way of looping through the root files and loading the trees individually.? There are about 100 files.
PS: I tries using hadd however it takes significantly longer than the first approach and shows a message merging trees with different compression levels….

Thanks a lot


Are you perhaps looking for a TTreeReader based on a TChain instance?

I hope this helps.


1 Like

Thank You @Danilo,

Yes this is quite helpful.
A quick follow up, the analysis requires the one branch values to be modified by a polynomial function

Value = p0 + p1*value + p2*(value)^2

However the p0, p1 and p2 are duffer for each file containing tree.

In this scenario is it possible to use TChain to merge the entries and still treat them with the different coefficients for file or

I need to loop through each file and use RVecOps as mentioned here

Please share if I haven’t been able to clarify myself. Thanks

Thanks a lot


Apologies but I do not understand. Can you open a well scoped thread about the task you are trying to accomplish after having tried to do it yourself?


Thanks for your feedback.
Yes, sure Ill try opening a new thread for the problem at hand.

1 Like

@Danilo I think the question is clear.
Assuming @utkarsh-2000 uses a TChain, one needs automatic ways to call some function (defined by the user, of course) that will retrieve (or calculate) the “p0”, “p1”, and “p2” parameters for the currently processed TTree. That means always for the very first entry in every new tree (when switching trees) and for the very first entry in a “chunk of entries” (when they are analyzed in “parallel”, e.g., in separate threads so that each “chunk” will need different tree specific parameters). These parameters may then be “saved” in some global variables (and used by the analyzing code for all events that belong to the same tree or “chunk of entries”).