Access particle parent

Hello Expert,

I hope I’m writing the right forum!

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:

truthphotonparent

Knowing that the print of this branch is:
…*
*Br 232 :TruthPhotonsAuxDyn.parentLinks : *

| vector<vector<ElementLink<DataVector<xAOD::TruthParticle_v1> > > >                                         *

*Entries : 10000 : Total Size= 608577 bytes File Size = 70072 *
*Baskets : 64 : Basket Size= 329728 bytes Compression= 8.66 *

Your help is very appriciated!

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.

Thanks a lot for your answer!
No I didn’t try neither C++ or python, can you please give me an examples to follow it.

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)?

Ok I will try with this example
thanks

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.

Thanks a lot @dguest I will try with pyroot it seems clear

I did not steal it. I got a license from @rnewhous

3 Likes

Hi @dguest,

Still I can’t access to the parent object of photon, I think I should to access to the following banch of parent objects:

*Br 232 :TruthPhotonsAuxDyn.parentLinks : *

  •     | vector<vector<ElementLink<DataVector<xAOD:                       *
    
  •     | :TruthParticle_v1> > > >                                         *
    

*Entries : 10000 : Total Size= 608577 bytes File Size = 70072 *
*Baskets : 64 : Basket Size= 329728 bytes Compression= 8.66 *

my question is how can I access <xAOD: : TruthParticle_v1> vector by using pyroot .

Your help is very helpful

Thanks,
Souad

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())