How to tell the number of branches in a root file?

Hello,

I am new here and new to using ROOT.
Currently, I am working on processing a ROOT tree, but I am having some problems understanding the structure of the Tree. The ROOT file I am using has one tree in it, and it is called “jet.”

When I type jet->Print() I get the results shown in the text file attached.JetPrintOutput.txt (84.0 KB)

I can tell that the top part of the output shown below is telling me the name of the tree and the number of entries in the tree. I am good with that.

******************************************************************************
*Tree    :jet       : jetTree                                                *
*Entries :     2817 : Total =        29096864 bytes  File  Size =   10104220 *
*        :          : Tree compression factor =   2.87                       *
******************************************************************************

I get confused with the segment shown below. I don’t know what the difference is between “Branch” and “Br.” Is Br a sub branch inside of Branch?

******************************************************************************
*Tree    :jet       : jetTree                                                *
*Entries :     2817 : Total =        29096864 bytes  File  Size =   10104220 *
*        :          : Tree compression factor =   2.87                       *
******************************************************************************
*Branch  :AntiKtR060NHits12                                                  *
*Entries :     2817 : BranchElement (see below)                              *
*............................................................................*
*Br    0 :fUniqueID : UInt_t                                                 *
*Entries :     2817 : Total  Size=      11837 bytes  File Size  =        157 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=  72.25     *
*............................................................................*
*Br    1 :fBits     : UInt_t                                                 *
*Entries :     2817 : Total  Size=      23172 bytes  File Size  =       3766 *
*Baskets :        2 : Basket Size=      32000 bytes  Compression=   6.03     *
*............................................................................*
*Br    2 :mRunId    : Int_t                                                  *
*Entries :     2817 : Total  Size=      11822 bytes  File Size  =        166 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=  68.31     *
*............................................................................*

Also, how do I know how many branches there are in the tree? When I try to use jet->Scan() I get the following output, which I thought should show me the branches inside the tree, but that doesn’t seem to be the case since I know that the branches should be named “AntiKtR060NHits12” or “AntiKtR050NHits12” and not " AntiKtR06"

***********************************************************************************************
*    Row   * Instance * AntiKtR06 * AntiKtR06 * AntiKtR06 * AntiKtR06 * AntiKtR06 * AntiKtR06 *
***********************************************************************************************
*        0 *        0 *         0 *  50331648 *  16155016 *   1250440 * 1.367e+09 *         2 *
*        0 *        1 *         0 *  50331648 *  16155016 *   1250440 * 1.367e+09 *        48 *
*        0 *        2 *         0 *  50331648 *  16155016 *   1250440 * 1.367e+09 *       113 *

Thank you very much for your help! I really appreciate it!

TTree

ROOT User’s Guide -> Trees

Thank you for the quick reply! I did come across these resources, but they did not address the the case where we have both “Branch” and “Br”. I don’t seem to be able to find an explanation to that. Would it be possible to address this? Thank you very much!

For Example, in the ROOT User’s Guide -> Trees, I find this:

**********************************************************************
*Tree    :T         : staff data from ascii file                     *
*Entries :3354      : Total = 245417 bytes  File  Size =        59945*
*                     Tree compression factor =   2.90               *
**********************************************************************
*Br    0 :staff     :Category/I:Flag:Age:Service:Children:Grade:...  *
*         | Cost                                                     *
*Entries :3354 : Total Size  = 154237 bytes  File Size = 32316       *
*Baskets :   3 : Basket Size =  32000 bytes  Compression= 2.97       *

But, it doesn’t have a “Branch” nor does it explain the difference between “Branch” and “Br.” The difference between the two and what it mean to have both of them in the same tree is what I am getting stuck on. Can you please address that? Than you very much!

“Br” in this printout is just a shortcut for “branch” (the very first branch, number 0, is named “staff”).

Thank you! Yes, I understand that, but in my case I have the following:

******************************************************************************
*Tree    :jet       : jetTree                                                *
*Entries :     2817 : Total =        29096864 bytes  File  Size =   10104220 *
*        :          : Tree compression factor =   2.87                       *
******************************************************************************
*Branch  :AntiKtR060NHits12                                                  *
*Entries :     2817 : BranchElement (see below)                              *
*............................................................................*
*Br    0 :fUniqueID : UInt_t                                                 *
*Entries :     2817 : Total  Size=      11837 bytes  File Size  =        157 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=  72.25     *
*............................................................................*
*Br    1 :fBits     : UInt_t                                                 *
*Entries :     2817 : Total  Size=      23172 bytes  File Size  =       3766 *
*Baskets :        2 : Basket Size=      32000 bytes  Compression=   6.03     *
*............................................................................*

And I can’t really tell what it means since I have a branch called AntiKtR060NHits12, but then I have *Br 0 :fUniqueID . I can’t tell if fUniqueID is a subbranch in the branch AntiKtR060NHits12 or if it means something else. Having both ''Branch" and “Br” in the same tree is throwing me off.

This is the result of a “splitting” of a branch … to split a branch (e.g. “AntiKtR060NHits12”) means to create a sub-branch for each data member in the object (e.g. fUniqueID, fBits, mRunId). Actually, the split-level can be set to 0 to disable splitting or it can be set to a number between 1 and 99 indicating the depth of splitting (search e.g. for “splitlevel” in the links that I gave you).

1 Like

Thank you very much!

I actually have one more question here. It is not very clear to me what the result of splitting is.

Case 1:
Before splitting, the tree has a branch named Events that stores events of class MyEvent which has the members fUniqueID , fBits , mRunId etc.
After splitting, now we have a tree with a branch named “Events” and within the branch Events, we have sub-branches fUniqueID , fBits , mRunId etc.

Case 2:
Before splitting, a tree has a branch named Events that stores events of class MyEvent which has the members fUniqueID , fBits , mRunId etc.
After splitting, we have a tree with branches fUniqueID , fBits , mRunId etc. So, the branch Events no longer exits because it was split?

Or it could be something that is not described by the two cases I provided.

Thank you very much for your patience!

I don’t think you can have " Case 2:". If an object is split (i.e. a branch in “decomposed object mode”) then it will still appear as a branch and then there will be sub-branches, i.e. there will appear “BranchElement (see below)”.

1 Like

Thank you very much! Taking your answer into consideration, I want to see if I am thinking about this correctly:

Let’s consider the following example:

Before splitting, the tree MyTree has a branch named Events that stores events of class MyEvent which has the members fUniqueID , fBits , mRunId , mEventId etc.
After splitting, now we have a tree MyTree with a branch named Events and within the branch Events, we have sub-branches fUniqueID , fBits , mRunId, mEventId etc.

Would this be the right way to process a branch from MyTree?

TChain* eventChain = new Chain("MyTree")

eventChain -> Add(eventFile.root) // Assuming that other files will be chained too.

MyEvent* event = 0;
eventChain->SetBranchAddress("Events", &event)

eventChain->GetEvent(1)

event->RunId() // Where RunId() is a member function of the class MyEvent
event->EventId() // Where EventId() is a member function of the class MyEvent

I am providing this example in an attempt to see if:

a) I need to assign a pointer to each sub-branch,

b) or if I can still have one pointer of class MyEvent and all the information from the sub-branches can be access using one pointer, in this case the pointer event, since one entry of the sub-branches corresponds to all the data members of class MyEvent and the pointer event is of type MyEvent.

Can you please let me know if I am reading the tree correctly and if either my interpretation in a or b is correct? If not, what is the correct way to go about it?

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

That is correct (and the answer to (a) is no you don’t need to).

1 Like