Accessing leaf entries within a branch in PyROOT


I have a complicated tree where. As you can see in the photo, there are a bunch of leaves in each branch. I want to create histograms from the events in a particular leaf from a particular branch, let’s say branch: Photon1, and leaf: eta.

I tried to write the following code to access that branch. But it doesn’t return the right plot when I compare to the plot in TBrowser.

br = tree.GetBranch("Photon1")
print br

#hpt = TH1D("pt", "Histogram of pt", 100, -1000, 2500)
heta = TH1D("Photon1_eta", "Histogram of eta", 100, -11000, 0)
for event in tree:
   #print event.eta #prints out but i don't know which branch it comes from
    heta = event.eta
c = ROOT.TCanvas()


Any suggestion would be appreciated!

Try the following:


Hi! I tried that one but it tells me TBranch is not iterable.
photontree.root (5.9 KB)

My goal is to draw out the histograms of each leaf in this root file for example. I’m doing it in Jupyter notebook…


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.