Accessing leaf entries within a branch in PyROOT

Hi!

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
    tree.GetLeaf("eta")
    heta = event.eta
    
    #ptfi= event.pt
    hstar.Fill(heta)
c = ROOT.TCanvas()

#hpt.Draw("same")
hstar.Draw("same")
c.Draw()

Any suggestion would be appreciated!

Try the following:

tree.GetLeaf("branchName.LeafName");

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…

Cheers,
Uzzie

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