Interactive AOD analysis with Athena

 




1. What is Python ? 



An interactive session in with Athena (following mostly Tadashi Maeno's instructions):


get_files Interactive_topO.py

#
# update AOD input file:
#old EventSelector.InputCollections = [ "AOD.pool.root" ]

#new
EventSelector.InputCollections = [ "/data/etp7/gduckeck/atlas/Romedata/rome.initial.zee.esd1001.aod1001.0001.pool.root" ]

athena -i Interactive_topO.py -l FATAL

           The -i option is crucial for interactive !

etppc15 ~/atlas/Tutorial/10.0.3/TestAnal $ athena.py -i Interactive_topO.py
Mon Aug 1 20:43:38 CEST 2005
Athena INFO including file "AthenaCommon/Compat.py"
Athena INFO including file "AthenaCommon/Bootstrap.py"
ApplicationMgr INFO Successfully loaded modules:
...
athena>
          Start application manager

theApp.initialize()


          Run 1 event

theApp.nextEvent()


econ=PyParticleTools.getElectrons("ElectronCollection")
e=econ[0]
e.pt() # call pt method



dir(e)

['Electron', 'Navigable', 'P4EEtaPhiM', '_C_instance', '_C_metaclass', '__class__', '__del__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', '_empty_instance', '_made_in_Python', 'author', 'begin', 'charge', 'contains', 'cosTh', 'cotTh', 'd0wrtPrimVtx', 'dataType', 'e', 'eg', 'end', 'et', 'eta', 'fillToken', 'getContainer', 'getEgammaWeight', 'getIndex', 'getParameter', 'hasCharge', 'hasPdgId', 'hasTrack', 'hlv', 'iPt', 'isEM', 'm', 'm_author', 'm_charge', 'm_constituents', 'm_dataType', 'm_e', 'm_eta', 'm_hasCharge', 'm_hasPdgId', 'm_hasTrack', 'm_isEM', 'm_m', 'm_origin', 'm_parameters', 'm_pdgId', 'm_phi', 'm_track', 'numberOfBLayerHits', 'numberOfPixelHits', 'numberOfSCTHits', 'numberOfTRTHighThresholdHits', 'numberOfTRTHits', 'origin', 'p', 'parameter', 'pdgId', 'phi', 'pt', 'putElement', 'px', 'py', 'pz', 'remove', 'removeAll', 'set4Mom', 'setE', 'setEta', 'setM', 'setPhi', 'set_all', 'set_charge', 'set_dataType', 'set_eg', 'set_isEM', 'set_origin', 'set_parameter', 'set_pdgId', 'set_track', 'sinTh', 'size', 'track', 'z0wrtPrimVtx', '~Electron', '~I4Momentum', '~INavigable', '~INavigable4Momentum', '~IParticle', '~Navigable', '~P4EEtaPhiM', '~P4EEtaPhiMBase', '~ParticleBase']

 

# print electron pt
econ=PyParticleTools.getElectrons("ElectronCollection")
len(econ)
for e in econ:
    print e.pt()           
                            


#
plot("ElectronContainer#ElectronCollection","$x.pt()",nEvent=5)
#


# print muon pt
mcon=PyParticleTools.getMuons("MuonCollection")
len(mcon)
for m in mcon:
    print m.pt()


# print MCTruth pdg_id
mcc=PyTruthTools.getMcEvents("")
mc=mcc[0]
mcp=mc.particles_begin()
while(mcp!=mc.particles_end()):
    pp=mcp.next()
    print pp.pdg_id()

def invmass(ob1,ob2):
    import math
    mass=(ob1.e()+ob2.e())**2
    mass-=(ob1.px()+ob2.px())**2
    mass-=(ob1.py()+ob2.py())**2
    mass-=(ob1.pz()+ob2.pz())**2
    mass=math.sqrt(mass)
    return mass


iev=0
while ( theApp.nextEvent().isSuccess() ):
    iev+=1
    print "Event ", iev
    mcon=PyParticleTools.
getElectrons("ElectronCollection")
    len(mcon)
    im=0
    for m in mcon:
        im+=1
        print im, m.pt(), m.px(), m.py(), m.pz(), m.e()
    if ( len(mcon)>1 ):
        print "Masse = ", invmass(mcon[0],mcon[1])/1000.




athena> execfile("InvMass2.py")


from PyAnalysisUtils import truth  # load module
truth.dump_truth()
....
205 RHO-  385              0.5 -1.47  0.07   0.7    0.5    0.0   -1.1    1.4
207 PI-                    1.0  2.25 -1.98   0.1   -0.4   -0.9    4.6    4.7
209 PHOT                   0.2  0.29  0.88   0.0    0.1    0.1    0.1    0.2
211 NUM                    1.4  0.82  0.44  -0.0    1.2    0.6    1.3    1.9
212 MU+                    6.3  0.48  0.50   0.1    5.5    3.0    3.1    7.0
....







You might need to restart athena occasionally to get back to the beginning of the collection ...


Play around with interactive usage:
#
#
#new
EventSelector.InputCollections = [ "/data/etp7/gduckeck/atlas/Romedata/rome.initial.zmm.esd1001.aod1001.00001.pool.root"]


There are more sophisticated ways how to write/use Python macros:
            methods



GD, last modified 09/08/2005