Hello ROOT community,
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:
My attempt so far is this:
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…
Thanks in advance
shouldn’t it be
z.GenJet rather than
I just tried that out too and I get the same error sadly.
can you provide a bit of data (even one event is enough) that I can try things on?
Thanks again for helping me here is a screenshot of the root file I am trying to access.
shouldn’t this be
File = ROOT.TFile(directory)
DelphesEvents = File.Delphes # This is your tree
for event in DelphesEvents:
jets = event.Jet
for jet in jets:
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.
are you sure the delphes libraries are available to ROOT?
What happens if you try the same loop in a C++ macro?
I havnt attempted it using C++ but I got it to work so here is the code:
#================ Extracting Data from Delphes root =====================#
File = ROOT.TChain("Delphes;1")
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)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.