I am fairly new to pyroot and this might be an easy question. I have a problem when trying to read events from a root file which has branches. The structure is as such:
Delphes>Jets>leaves
My attempt so far is this:
import ROOT
directory= str("MadGraph5/bin/pp/Events/run_01/tag_1_delphes_events.root")
Tree = ROOT.TFile(directory)
Delphes = ROOT.gROOT.FindObject("Delphes;1")
for i in Delphes:
x = Delphes.Jet
for z in x:
read = x. GenJet.PT
when running this script I get an error "‘TClonesArray’ object has no attribute ‘GenJet’’. When I count the number of events using a simple i = i+1 counter I get the correct number of iterations. The most success I have had receiving adresses…
import ROOT
directory= str("MadGraph5/bin/pp/Events/run_01/tag_1_delphes_events.root")
File = ROOT.TFile(directory)
DelphesEvents = File.Delphes # This is your tree
for event in DelphesEvents:
jets = event.Jet
for jet in jets:
print jet.PT
Thank you for your contribution to this issue. I have tried using your code and actually this is one of the methods I used also and if you count the number of iterations the second for loop it does correspond to the number of events in that branch i.e. Jet. But I am getting the same error as before that ‘TObject’ object has no attribute ‘PT’’. Not sure why this is the case though.
I havnt attempted it using C++ but I got it to work so here is the code:
import ROOT
#================ Extracting Data from Delphes root =====================#
directory= str("MadGraph5/bin/pp/Events/run_01/tag_1_delphes_events.root")
File = ROOT.TChain("Delphes;1")
File.Add(directory)
Number = File.GetEntries()
for i in range(Number):
Entry = File.Get Entry(i)
EntryFromBranch = File.Jet.GetEntries()
for j in range(EntryFromBranch):
PT = File.GetLeaf("Jet.PT").GetValue(j)