Access leaves from branches of a tree


I have seen so many “SetBranchAddress” (and “TTreeReader” for root 6) answers and tutorials but none of them explicitly show how we access “leaves” from a “branch” of a “tree”.

Suppose I have a file name “File.root”, that has a tree named “tree” with two branches “branch1” and “branch2” and inside those branches there are leaves named “leaf1/L” (contains Long64_t), “leaf2/I” (contains int) etc.

How do I access, for example values of “leaf1” belonging to “branch2” and save the values in a variable. I tried the following:

TFile file("File.root");
TTree *t = (TTree*) file.Get("tree");
Double_t pin1;
tree->SetBranchAddress("branch2", &branch2);

Then working with "branch1.leaf1" fails! I don’t know how to go forward with this.

NOTE: It is not possible for me right now to use root 6, so I will really appreciate any root 5 specific solution.


Root version and platform info:
ROOT Version 5.34/36
Platform: Ubuntu 16.04.4 LTS, compiler g++ (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0

1 Like

Woow. This is everything. Thank you so much.

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