ATLAS Offline Software
Generators
GeneratorModules
python
EvgenAlg.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3
from
AthenaPython
import
PyAthena
4
from
AthenaPython.PyAthena
import
StatusCode
5
import
ROOT
6
7
8
class
EvgenAlg
(
PyAthena.Alg
):
9
"""\
10
Base class for implementing event generator interfaces in Python.
11
Author: Andy Buckley
12
"""
13
14
def
__init__
(self, name="EvgenAlg"):
15
super(EvgenAlg, self).
__init__
(name=name)
16
self.
McEventKey
=
"GEN_EVENT"
17
18
19
def
genInitialize
(self):
20
return
StatusCode.Success
21
22
def
fillEvent
(self, evt):
23
return
StatusCode.Success
24
25
def
genFinalize
(self):
26
return
StatusCode.Success
27
28
29
def
initialize
(self):
30
self.
msg
.
debug
(
"Initializing [%s]"
, self.getName())
31
32
return
self.
genInitialize
()
33
34
35
def
execute
(self):
36
from
AthenaPython.PyAthena
import
McEventCollection
37
try
:
38
from
AthenaPython.PyAthena
import
HepMC3
as
HepMC
39
except
ImportError:
40
from
AthenaPython.PyAthena
import
HepMC
as
HepMC
41
self.
msg
.
debug
(
"Executing [%s]"
, self.getName())
42
43
44
mcevts =
None
45
if
self.
evtStore
.
contains
(McEventCollection, self.
McEventKey
):
46
self.
msg
.
debug
(
"%s found before alg execution!"
, self.
McEventKey
)
47
mcevts = self.
evtStore
[self.
McEventKey
]
48
else
:
49
self.
msg
.
debug
(
"Creating %s before alg execution!"
, self.
McEventKey
)
50
mcevts =
McEventCollection
()
51
self.
evtStore
.record(mcevts, self.
McEventKey
,
True
,
False
)
52
ROOT.SetOwnership(mcevts,
False
)
53
54
if
self.
evtStore
.
contains
(McEventCollection, self.
McEventKey
):
55
self.
msg
.
debug
(
"%s found after alg execution!"
, self.
McEventKey
)
56
57
58
evt =
None
59
if
mcevts.size() == 0:
60
evt = HepMC.GenEvent()
61
mcevts.push_back(evt)
62
else
:
63
evt = mcevts[0]
64
ROOT.SetOwnership(evt,
False
)
65
66
67
st = self.
fillEvent
(evt)
68
PyAthena.HepMC.fillBarcodesAttribute(evt)
69
#print "FILLEVENT RESULT:"
70
#getattr(evt, 'print')()
71
return
st
72
73
74
def
finalize
(self):
75
return
self.
genFinalize
()
python.EvgenAlg.EvgenAlg.genFinalize
def genFinalize(self)
Definition:
EvgenAlg.py:25
PyAthena::Alg::initialize
virtual StatusCode initialize() override
Definition:
PyAthenaAlg.cxx:60
python.EvgenAlg.EvgenAlg.McEventKey
McEventKey
Definition:
EvgenAlg.py:16
PyAthena::Alg::execute
virtual StatusCode execute() override
Definition:
PyAthenaAlg.cxx:93
PyAthena::Alg::finalize
virtual StatusCode finalize() override
Definition:
PyAthenaAlg.cxx:86
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition:
AthCommonDataStore.h:85
python.EvgenAlg.EvgenAlg
Definition:
EvgenAlg.py:8
python.EvgenAlg.EvgenAlg.genInitialize
def genInitialize(self)
Definition:
EvgenAlg.py:19
contains
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
Definition:
hcg.cxx:111
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition:
McEventCollection.h:33
debug
const bool debug
Definition:
MakeUncertaintyPlots.cxx:53
python.EvgenAlg.EvgenAlg.fillEvent
def fillEvent(self, evt)
Definition:
EvgenAlg.py:22
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition:
AthCommonMsg.h:24
PyAthena::Alg
Definition:
PyAthenaAlg.h:33
python.EvgenAlg.EvgenAlg.__init__
def __init__(self, name="EvgenAlg")
Definition:
EvgenAlg.py:14
Generated on Sun Dec 22 2024 21:10:20 for ATLAS Offline Software by
1.8.18