just a quick question about the GetEntries object. In the root file I attached, I have two trees. The tree “sim” has multiple branches, including one called “particles.”. I’d like to get the number of entries from that branch (all leaves withing are histograms with the same number of events). The algorithm I have so far is:
TFile *file = new TFile("DAT000001.root", "READ");
TTree *tree =(TTree*) file->Get("sim");
int id;
tree->SetBranchAddress("particle..ParticleID",&id);
int NEntries = tree->GetEntries();
When printing NEntries, I get “1” instead of the expected number of events contained in these histograms. I suspect that the fact that the “sim” tree has multiple branches, it read the number of events in the first one “shower” and returns its number of entries, which is indeed 1. So my question is, in this particular case, how do I get the number of trees in the second branch?
Hi,
indeed that file contains one entry. In other words, the TTree seen as a table contains one row (and multiple columns/branches).
For that one entry, the value of "particle..ParticleID" is an array of several thousand elements: those are the ones you see in the histogram.
There is something else that’s weird with that file, I am not able to load the contents of particle..ParticleID without getting a crash.
Cheers,
Enrico
EDIT: it looks like the file was written with ROOT v5.34. @pcanal might be able to say why I can’t read the "particle..ParticleID" branch in TTree "sim" with a recent ROOT version.
EDIT 2:
managed to find a way to read that branch that does not crash:
Thanks a lot Enrico, I didn’t think about using TTreeReader instead, that’s much better indeed. The advantage of using it is also that I directly create an array with the data contained in these each leaf.