ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
TruthParticleID
McParticleAlgs
python
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.
8
IMPORTANT : this alg must be run before any other algs invoking TruthParticleCnvToolContainer.
9
'''
10
11
__version__ =
'$Revision: 1.5 $'
12
__author__ =
'P-A Delsart'
13
14
import
AthenaPython.PyAthena
as
PyAthena
15
from
AthenaPython.PyAthena
import
StatusCode
16
17
import
ROOT
18
19
class
FixMcEventCollection
(
PyAthena.Alg
):
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
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition
AthCommonMsg.h:24
PyAthena::Alg
Definition
PyAthenaAlg.h:33
PyAthena::Alg::finalize
virtual StatusCode finalize() override
Definition
PyAthenaAlg.cxx:86
PyAthena::Alg::initialize
virtual StatusCode initialize() override
Definition
PyAthenaAlg.cxx:60
python.ReOrderMcEventCollection.FixMcEventCollection
Definition
ReOrderMcEventCollection.py:19
python.ReOrderMcEventCollection.FixMcEventCollection.__init__
__init__(self, name='FixMcEventCollection', **kw)
Definition
ReOrderMcEventCollection.py:20
python.ReOrderMcEventCollection.FixMcEventCollection.sg
sg
Definition
ReOrderMcEventCollection.py:31
python.ReOrderMcEventCollection.FixMcEventCollection.execute
execute(self)
Definition
ReOrderMcEventCollection.py:35
Generated on
for ATLAS Offline Software by
1.17.0