# How to get PyROOT to recognize my TFile's TBranches?

**URL:** <https://root-forum.cern.ch/t/how-to-get-pyroot-to-recognize-my-tfiles-tbranches/35948>\
**Category:** Newbie\
**Created:** [September 9, 2019, 7:03pm UTC](https://root-forum.cern.ch/t/how-to-get-pyroot-to-recognize-my-tfiles-tbranches/35948 "2019-09-09T19:03:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hilary](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/hilary/32/19751_2.png) [@Hilary](https://root-forum.cern.ch/u/Hilary)\
**Post date:** [September 9, 2019, 7:03pm UTC](https://root-forum.cern.ch/t/how-to-get-pyroot-to-recognize-my-tfiles-tbranches/35948/1 "2019-09-09T19:03:00Z")

</div>

_ROOT Version:_ Not Provided  
_Platform:_ Linux  
_Compiler:_ Not Provided

Hello, I am attempting to iterate over the values of one TBranch in a TTree that is located in a TDirectory under a TFile. I am fairly new to ROOT, though I have history with Python, so I thought it best to use PyROOT to complete the iteration. However, if anyone can help me get this to work in either PyROOT or ROOT, it would be very helpful.

so far I have this:  
"  
myfile = ROOT.TFile("/home/hilary/root/compile/Research/GENIE\_atm.root")  
mytree = ROOT.TDirectory(myfile.GENIE/Event) # this is the name of the tree in the file  
for e in mytree:  
print (e.mc\_Momentum) # mc\_Momentum is the name of branch of the tree  
)  
"  
I know this does not work and the issue is mainly to do with my lack of understanding of how to tell PyROOT that I want to values of the TBranch named mc\_Momentum. The location of the TBranch (mc\_Momentum) I am interested in is: GENIE\_atm.root/GENIE/Event/mc\_Momentum

I am not sure how I need to write the code such that PyROOT knows that I am interested in the values of mc\_Momentum. Any ideas?

For clarification, the TFile is is GENIE\_atm.root, the TDirectory is GENIE, the TTree is Event, and the TBranch is mc\_Momentum.

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [September 12, 2019, 9:29am UTC](https://root-forum.cern.ch/t/how-to-get-pyroot-to-recognize-my-tfiles-tbranches/35948/2 "2019-09-12T09:29:51Z")

</div>

Dear @Hilary,

Please see my answer here:

> [@Obtain every nth value from a TBranch array in PyRoot](https://root-forum.cern.ch/t/obtain-every-nth-value-from-a-tbranch-array-in-pyroot/35946):
>
> ROOT Version: Not Provided Platform: Linux Compiler: Not Provided Hello, I am attempting to iterate over the values of one TBranch in a TTree that is located in a TDirectory under a TFile. I am fairly new to ROOT, though I have history with Python, so I thought it best to use PyROOT to complete the iteration. However, if anyone can help me get this to work in either PyROOT or ROOT, it would be very helpful. so far I have this: " myfile = ROOT.TFile("/home/hilary/root/compile/Research/GEN…
