I have some questions about the truth parent particle, I have used a root file for Higgs decaying to 2 gammas, there are some kinematic parameters and I would like to produce the gamma that comes from Higgs, and as I understood that I should look at the parent particles for that. but the problem for me is when I open the root file and I look at this photon truth parent I haven’t found the kinematic parameters that I want, please find attached the screen of the TBrowser:
Knowing that the print of this branch is:
…*
*Br 232 :TruthPhotonsAuxDyn.parentLinks : *
Are you trying to access this within C++? Or python code? I’m not sure you can get what you want from a TBrowser but truth particles have a particle->parent(i) method that accesses the parent.
Maybe not precisely what you want, but the best example I could find to set up a simple loop over some events might be this tutorial on using ATLAS CMake. Maybe @damacdon knows if this has been updated since (or if there’s another simple example somewhere)?
Maybe simpler would be to use pyroot. First set up a release:
setupATLAS
asetup AnalysisBase,master,latest
Then run some python script like this:
#!/usr/bin/env python
import ROOT
if(not ROOT.xAOD.Init().isSuccess()): print('Failed xAOD.Init()')
f = ROOT.TFile('some_file.pool.root')
t = ROOT.xAOD.MakeTransientTree(f, 'CollectionTree')
print(t.GetEntries())
for i in range(10):
t.GetEntry(i)
# Loop over every photon
for photon in t.TruthPhotons:
# access the photon parents here
Thanks @biliu for the rough script, which he stole from @rnewhous. I don’t personally use pyroot much but it’s nice for simple things like this.
It’s probably worth writing how you would loop over an event with TEvent and python:
#!/usr/bin/env python
import ROOT
import sys
evt = ROOT.POOL.TEvent(ROOT.POOL.TEvent.kClassAccess)
evt.readFrom(sys.argv[1])
for eventn in range(evt.getEntries()):
evt.getEntry(eventn)
for part in evt.retrieve('xAOD::TruthParticleContainer', 'TruthParticles'):
# skip anything that isn't a photon
if part.pdgId() != 22:
continue
for pn in range(part.nParents()):
parent = part.parent(pn)
print(parent.pdgId())