# Issue extracting data from nested TBranchElement

**URL:** <https://root-forum.cern.ch/t/issue-extracting-data-from-nested-tbranchelement/58000>\
**Category:** Newbie\
**Created:** [January 29, 2024, 11:23pm UTC](https://root-forum.cern.ch/t/issue-extracting-data-from-nested-tbranchelement/58000 "2024-01-29T23:23:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbutalla](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/c4cdca/32.png) [@sbutalla](https://root-forum.cern.ch/u/sbutalla)\
**Post date:** [January 29, 2024, 11:23pm UTC](https://root-forum.cern.ch/t/issue-extracting-data-from-nested-tbranchelement/58000/1 "2024-01-29T23:23:34Z")

</div>

Hi Everyone,

I am trying to extract data from a ROOT file and I am unable to retrieve the data contained in the leaves of one of the subbranches. For reference, here is screen shot of the TBrowser output of the branch/leaf structure of the `Events` tree:

 ![aod_file_zz-4l_tbrowser_tree_structure_annotated](https://root-forum.cern.ch/uploads/default/original/3X/2/8/288f900bc19958e2f546104eace2022badee5f34.png)

Specifically, I need to extract the data in the leaves contained on the `p4Polar_` branch, which is nested in the following structure of the `Events` tree:

`recoGenParticles_genParticles __HLT./recoGenParticles_genParticles__ HLT.obj/m_state/p4Polar_`

Here is an example of my current code in Python:

```auto
file_name = 'C89598B9-A372-9643-AB96-A5B71DED9151.root'
file = ROOT.TFile.Open(file_name, "READ")
tree = file.Events
reco_gen = tree.GetBranch("recoGenParticles_genParticles__HLT.obj") 

```

(The main branch,`recoGenParticles_genParticles__HLT`, cannot be accessed using `tree.GetBranch("recoGenParticles_genParticles__HLT")`, but the above code works.) When printing the `reco_gen` branch, I receive the following output:

```auto
*Br 2 :recoGenParticles_genParticles__HLT.obj : vector<reco::GenParticle> *
*Entries :9800 : Total Size= 2676780697 bytes File Size = 237433712 *
*Baskets : 3985 : Basket Size= 822272 bytes Compression= 11.27 *
*............................................................................*

```

Through trying different solutions of extracting the data, I’ve determined that the `reco_gen` branch is an instance of the `TBranchElement` class, so I can’t use `GetEntries()` in a `for` loop to iterate through the data.

I’m unsure how to access the data in the leaves on the `recoGenParticles_genParticles __HLT./recoGenParticles_genParticles__ HLT.obj/m_state/p4Polar_` branch. Any information or suggestions are greatly appreciated. Please let me know if you need any more information or have any questions.

Thank you,

Stephen

* * *

_ROOT Version:_ 6.30/02  
_Platform:_ macOS 11.7.10  
_Compiler:_ Apple clang version 13.0.0 (clang-1300.0.29.30)

* * *

---

<div class="post-metadata">

**Author:** ![mdessole](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mdessole/32/34021_2.png) [@mdessole](https://root-forum.cern.ch/u/mdessole)\
**Post date:** [January 30, 2024, 11:59am UTC](https://root-forum.cern.ch/t/issue-extracting-data-from-nested-tbranchelement/58000/2 "2024-01-30T11:59:41Z")

</div>

Hi @sbutalla,  
thank you for posting on the ROOT forum!  
Have you tried to access the leaf with `.Get`, i.e. `file.Get('path/to/leaf')`?

Cheers,  
Monica
