How to read out the entries of a branch?

ROOT Version: 6.26/02
Platform: Windows
Compiler: MSVC 19.31.31104.0

I have a tree called Hits with several branches like ftotEnergy_sum, ftotEnergy_1 and so on. I know I can get the entries of the tree via tree->GetEntriesFast() but how do I do this when I would like to have the entries of the single branches instead?
tree->ftotEnergy_1-GetEntriesFast() didn’t work, also tree->Branch("ftotEnergy_1")->GetEntriesFast() or tree->SetBranchAddress("ftotEnergy_1")->GetEntriesFast() didn’t.
Calling tree->SetBranchAddress("ftotEnergy_sum"); and then tree->GetEntriesFast() does not work as well.

Does it work if you use GetEntries instead of GetEntriesFast :

TBranch* branch = tree->GetBranch("ftotEnergy_1");
Long64_t nentries = branch->GetEntries();


1 Like

Thank you! At least it doesn’t throw an error but I get the same amount of entries.
Now I need to know whether the reading (the tree/branch) is wrong or the writing already.

The number of “entries” (or rows) in a TTree and TBranch in the usual cases (balance trees) is the same. You may have meant to count the total number of element of an array summed over all the entries. If that is the case you should use RDataFrame (@vpadulan can you give a concrete example) or TTree::Draw (by creating an histogram and getting its number of entries).

1 Like

Thanks a lot! Well, if this is the case then I don’t need to track this issue down any further… :smiley:
Tbh, I can’t understand your further input. What could or should I do? Do I have to use a different data structure or is there any way how I can get the… apparently not different entries of a branch?
Shall I create a tree each time instead of using multiple branches at the same tree?

Background: I’m performing a simulation with Geant4 and I want to store the hits in different detectors. For this I created a tree called Hits and the different branches represent(ed) the different detectors.