Confused over TTree Structure

Hey everyone,

I’ve worked with TTrees and TChains for weeks now, but I think I’ve never really understood the structure of a TTree.
I understood that a Tree has branches. But what are the entries? So, I have a tree with for example 10 Branches. When I have 5 Entries, does this means for every entry all 10 branches are filled?

I’ve got this question because in a code I wrote, I loop over all Entries, and than fill histograms with values at every entry but I’ve never told root like “take the branch of the entry where the loop is right now”.
I don’t know how to tell root to do that, but the histograms look fine, so does this happen automatically?
The part of the code is here. I’ve done this partly like the loop()-function of the MakeClass.

TChain *sig = new TChain("treename");
Long64_t snentries = sig->GetEntries();
       tree_sig is object from MakeClass
       it gets a TChain as parameter 
signal tree_sig(sig);
for (Long64_t jentry=0; jentry<snentries;jentry++) {
       Long64_t ientry = tree_sig.LoadTree(jentry);  
       if (ientry < 0) break;
       nb = tree_sig.GetEntry(jentry);   nbytes += nb;
       if(tree_sig.Branch1_size ==0 && tree_sig.Branch2_size==0){
         for(Long64_t i = 0; i<tree_sig.Branch3_size; i++){
           histo1_s->Fill(tree_sig.Branch3_1->at(i)); //Branch 3_1  is vector<float>
           histo2_s->Fill(tree_sig.Branch3_2->at(i)); //Branch 3_2 is vector<float>

I know that my TChain only ontains one tree - is that the reason why there are no problems? But still my question is, how does the code know from which entry it should take the branches?

Or is my understanding of the entries wrong? This is a very basic question but I don’t have an idea right now, if you could help me, I would be glad :slight_smile:

Best regards

Hi eneb,

When I have 5 Entries, does this means for every entry all 10 branches are filled?

Yes, exactly that. In first approximation, for simple situations, if you think your data as laid out in a table, entries are the rows of the table and branches are the columns.

The tree-like structure, with branches and leaves, is how one entry is structured. Every entry is structured like that, and each entry corresponds to one data-point, or one measurement, or one event, or one collision.

My opinion is that you’ll be ok for the most part if you think of entries as rows and branches as columns of a table.


P.S. if a TTree is a table, a TChain is just a list of tables

1 Like

Hi Enrico,

Thank you for your explanation :slight_smile:

And I think that GetEntry() is the function which sets my entry to the right one :slight_smile:

Best regards

Yes indeed! Closing this as resolved then.


1 Like

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