ATLAS Offline Software
Loading...
Searching...
No Matches
ReOrderMcEventCollection.py
Go to the documentation of this file.
1# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3# @file: McParticleAlgs/python/FixMcEventCollection.py
4# @purpose: <put some purpose here>
5# @author: P-A Delsart
6
7__doc__ = '''Re-order the McEventCollection so the first GenEvent is the signal event.
8IMPORTANT : this alg must be run before any other algs invoking TruthParticleCnvToolContainer.
9'''
10
11__version__ = '$Revision: 1.5 $'
12__author__ = 'P-A Delsart'
13
14import AthenaPython.PyAthena as PyAthena
15from AthenaPython.PyAthena import StatusCode
16
17import ROOT
18
20 def __init__(self, name='FixMcEventCollection', **kw):
21
22 kw['name'] = name
23 super(FixMcEventCollection, self).__init__(**kw)
24
25
27 return
28
29 def initialize(self):
30 self.msg.info('==> initialize...')
31 self.sg = PyAthena.py_svc ('StoreGateSvc')
32 return StatusCode.Success
33
34
35 def execute(self):
36 #self.msg.info('==> execute...')
37 sg = self.sg
38 mcevt0 = sg.retrieve('McEventCollection',"GEN_AOD")
39
40 # if 1st event is populated, the collection is correct
41 genEvt = mcevt0[0]
42 if genEvt.particles_size()>1:
43 return StatusCode.Success
44
45 sigEvt = None
46 puEvts = []
47 for evt in mcevt0:
48 if evt.particles_size()>1:
49 sigEvt = evt
50 else:
51 puEvts.append(evt)
52
53 etmp = ROOT.HepMC.GenEvent() # temporary only used for swapping
54 correctOrder = [sigEvt] + puEvts
55 for i, e in enumerate(correctOrder):
56 mcevt0.swapElement(i,e,etmp)
57
58 return StatusCode.Success
59
60 def finalize(self):
61 self.msg.info('==> finalize...')
62 return StatusCode.Success
63
MsgStream & msg() const
virtual StatusCode execute() override
virtual StatusCode finalize() override
virtual StatusCode initialize() override