Ways of accessing and operating between different entries of a branch

Hi,

I have a couple of questions. If I want to access the values of a branch “branch” at certain entries “entry1” and “entry2”, I commonly do:

TChain *chain = new TChain(“tree”);
chain->Add(filepath);
double p_branch;
chain->SetBranchAddress(“branch”,&p_branch);
chain->GetEntry(entry1); double value1 = p_branch;
chain->GetEntry(entry2); double value2 = p_branch;
cout << value1 << endl; cout << value2 << endl;

But I’ve notices this also works:

TChain *chain = new TChain(“tree”);
chain->Add(filepath);
TLeaf *p_branch = chain->GetLeaf(“branch”);
p_branch->GetBranch()->GetEntry(entry1); double value1 = p_branch->GetValue();
p_branch->GetBranch()->GetEntry(entry2); double value2 = p_branch->GetValue();
cout << value1 << endl; cout << value2 << endl;

My first question is, is there some important difference between these two ways? And also, as can be seen, why branches and leaves sometimes seem to have not a clear difference?

My second question is, I did all this because I want to Draw not one branch vs another but some calculation done in one branch vs another, for this I’m going to create two arrays (filling it with calculated values from the values of the branches) and then plot one vs another. Is there a better way?

Thanks!

But I’ve notices this also works:

The second works if there is only one file in the TChain.

My second question is, I did all this because I want to Draw

Depending on the type of calculation both TTree::Draw and RDataFrame might be able to do it easier.

Thanks, then I’ll use the first one only.

I want to Draw something like branch(entry+1)-branch(entry) vs anotherbranch. I couldn’t get it done similarly to chain->Draw(“branch:anotherbranch)” so at the end I did it with vectors since a priori I don’t know the size of them because there is also conditional while making them. I hope this is not too bad practice.

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