More than one tree with same treename in a root file

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Hi all,
I have some questions related to one problem:
Q1, Is there a storage limitation for a tree in a root file? how large is it?
Q2, In a root file, if there are several trees named with the same name, we can just take it as one to read? In my case, It seems I did not get branches from these trees simultaneously.

 What I am doing:
 I am trying to do BDT study. There will be 3 models so I train and predict my samples one model after one model.
 => then I found, for some trees, seems they are too large. Very time I store my result, there will be a new tree with the same name.
=> but when I read the final root file, I did not read one BDT score branch successfully. these 3 BDT scores are stored in different trees(same name).

Thank you very much! Hopefully, I express this problem well.

For Q2, I suppose you see inside the file something like


and so on. If that’s the case, just getting the tree without numbers (Get(“tree”)) should be enough, as ROOT takes the highest number by default, giving access to all data. Read about namecycle by searching at Get Started - ROOT (use the top right loupe icon), or search for that word on this forum or documentation; e.g. Aux;1 aux;2 aux3;

Hi @11111,

In reply to Q1, you can check this documentation. Also, keep in mind that due to a limtation (see issue #6734 on GitHub), the maximum size of a single entry in a TBranch is ~1GB.

Regarding Q2 (IIUC what you are doing), each object (be it a TTree or not) stored in a .root file is unique. That essentially means that ROOT will not do any magic to make branches from both trees appear as a single tree. To get that, you should open the “primary” tree and add the rest as friends (see here:


Thanks! Yes, in my case, it looks like this:

KEY: TTree WZ_nom;6 WZ_nom [current cycle]
KEY: TTree WZ_nom;5 WZ_nom [backup cycle]
KEY: TTree WZ_nom;2 WZ_nom [backup cycle]
int WZ_nom;6 → there is a branch named “lightgbm_mid”
int WZ_nom;2 → there is a branch named “lightgbm_low”

Problem: When I read WZ_nom, it seems that I can get access to lightgbm_mid:

0 entry of 303278entries
mid: 0.725336 low 5.56413e+07
mid: 0.00273314 low 5.56413e+07
mid: 0.0724209 low 5.56413e+07

===> Contrary to expectation,I did not read all the branches in the WZ_nom.
Thank you very much for any comment!!

Hi @11111,

Yes, that was exactly what I said in my last post. Apparently, WZ_nom has three cycles (enumerated 2, 5, and 6). If you open WZ_nom, ROOT will just read the current cycle, i.e. 6 in the list above (all the rest are considered backup/old versions).

Each of those is a different TTree, i.e., you can read data from a specific instance by specifying also the cycle number, e.g. WZ_nom;2.

Also, as I said, if you want to have a homogeneous view of branches in all the cycles, you can probably open WZ_nom;6 and add WZ_nom;2 as a friend. For that, check documentation here.


Q2: If you only want to store in the TFile the last cycle of the tree and not previous backups, use kWriteDelete: Adding entries to a TTree - #2 by brun

Hi @jalopezg,
Thank you very much! Yes, finally I took “AddFriend” which works for me.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.