ATLAS Offline Software
Loading...
Searching...
No Matches
EvgenAlg.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3from AthenaPython import PyAthena
4from AthenaPython.PyAthena import StatusCode
5import ROOT
6
7
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()
const bool debug
MsgStream & msg() const
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
virtual StatusCode execute() override
virtual StatusCode finalize() override
virtual StatusCode initialize() override
__init__(self, name="EvgenAlg")
Definition EvgenAlg.py:14
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114