# How to read out the entries of a branch?

**URL:** <https://root-forum.cern.ch/t/how-to-read-out-the-entries-of-a-branch/53137>\
**Category:** Newbie\
**Tags:** tree\
**Created:** [January 17, 2023, 9:55am UTC](https://root-forum.cern.ch/t/how-to-read-out-the-entries-of-a-branch/53137 "2023-01-17T09:55:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Progressive](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/dfb087/32.png) [@Progressive](https://root-forum.cern.ch/u/Progressive)\
**Post date:** [January 17, 2023, 9:55am UTC](https://root-forum.cern.ch/t/how-to-read-out-the-entries-of-a-branch/53137/1 "2023-01-17T09:55:07Z")

</div>

* * *

_ROOT Version:_ 6.26/02  
_Platform:_ Windows  
_Compiler:_ MSVC 19.31.31104.0

* * *

Hi,  
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.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 17, 2023, 10:08am UTC](https://root-forum.cern.ch/t/how-to-read-out-the-entries-of-a-branch/53137/2 "2023-01-17T10:08:32Z")

</div>

Does it work if you use `GetEntries` instead of `GetEntriesFast` :

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

```

?

---

<div class="post-metadata">

**Author:** ![Progressive](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/dfb087/32.png) [@Progressive](https://root-forum.cern.ch/u/Progressive)\
**Post date:** [January 17, 2023, 10:56am UTC](https://root-forum.cern.ch/t/how-to-read-out-the-entries-of-a-branch/53137/3 "2023-01-17T10:56:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [January 17, 2023, 12:48pm UTC](https://root-forum.cern.ch/t/how-to-read-out-the-entries-of-a-branch/53137/4 "2023-01-17T12:48:25Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Progressive](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/dfb087/32.png) [@Progressive](https://root-forum.cern.ch/u/Progressive)\
**Post date:** [January 17, 2023, 1:07pm UTC](https://root-forum.cern.ch/t/how-to-read-out-the-entries-of-a-branch/53137/5 "2023-01-17T13:07:31Z")

</div>

Thanks a lot! Well, if this is the case then I don’t need to track this issue down any further… 😃  
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.
