ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Generators
Superchic_i
python
Superchic_i/python/EventFiller.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
3
4
from
GeneratorModules.EvgenAlg
import
EvgenAlg
5
from
AthenaPython.PyAthena
import
StatusCode
6
try
:
7
from
AthenaPython.PyAthena
import
HepMC3
as
HepMC
8
except
ImportError:
9
from
AthenaPython.PyAthena
import
HepMC
as
HepMC
10
11
import
os
12
import
math
13
import
ROOT
14
15
16
def
init_pz(energy):
17
return
math.sqrt(energy**2 - 938.272046**2)
18
19
20
class
LheEVNTFiller(EvgenAlg):
21
22
def
__init__
(self, ecmEnergy, name="LheEVNTFiller"):
23
super(LheEVNTFiller, self).
__init__
(name=name)
24
self.
beamEnergyMeV
= ecmEnergy * 1000. / 2.
25
26
fileName =
"evrecs/evrecout.dat"
27
outputFileName =
"outputs/outputout.dat"
28
eventsProcessed = 0
29
30
def
initialize
(self):
31
32
if
(os.path.isfile(self.
fileName
)
and
os.path.isfile(self.
outputFileName
)):
33
print
(self.
fileName
)
34
return
StatusCode.Success
35
else
:
36
return
StatusCode.Failure
37
38
39
def
fillEvent
(self, evt):
40
41
eventsSeen = 0
42
firstLine =
True
43
44
with
open(self.
outputFileName
,
'r'
)
as
inputOutputFile:
45
if
self.
eventsProcessed
== 0:
46
for
line
in
inputOutputFile:
47
if
'Cross section ='
in
line:
48
splitLine = line.split()
49
factor = 1.
50
if
(splitLine[-1] ==
"pb"
):
51
factor = 0.001
52
if
(splitLine[-1] ==
"fb"
):
53
factor = 0.000001
54
if
(splitLine[-1] ==
"ub"
):
55
factor = 1000.
56
if
(splitLine[-1] ==
"mb"
):
57
factor = 1000000.
58
print
(
"MetaData: cross-section (nb)= "
+str(float(splitLine[3])*factor))
59
60
break
61
62
with
open(self.
fileName
,
'r'
)
as
inputfile:
63
event =
False
64
for
line
in
inputfile:
65
if
not
event
and
'<event>'
not
in
line:
66
continue
67
# Check if we are just starting an event
68
if
not
event
and
'<event>'
in
line
and
eventsSeen == self.
eventsProcessed
:
69
event =
True
70
continue
71
# Check if we have finished and are doing something else
72
if
'<'
in
line
or
'>'
in
line:
73
event =
False
74
eventsSeen += 1
75
firstLine =
True
76
continue
77
if
event
and
firstLine:
78
firstLine =
False
79
evt.weights().push_back(float(line.split()[2]))
80
81
# Add the initial state protons
82
pos =
HepMC.FourVector
(0.0, 0.0, 0.0, 0.0)
83
gv = HepMC.GenVertex(pos)
84
ROOT.SetOwnership(gv,
False
)
85
evt.add_vertex(gv)
86
mom =
HepMC.FourVector
(0., 0.,
init_pz
(self.
beamEnergyMeV
), self.
beamEnergyMeV
)
87
gp = HepMC.GenParticle()
88
gp.set_status( 4 )
89
gp.set_pdg_id( 2212 )
90
gp.set_momentum(mom)
91
gp.set_generated_mass(938.272046)
92
ROOT.SetOwnership(gp,
False
)
93
gv.add_particle_out(gp)
94
95
pos =
HepMC.FourVector
(0.0, 0.0, 0.0, 0.0)
96
gv = HepMC.GenVertex(pos)
97
ROOT.SetOwnership(gv,
False
)
98
evt.add_vertex(gv)
99
mom =
HepMC.FourVector
(0., 0., -
init_pz
(self.
beamEnergyMeV
), self.
beamEnergyMeV
)
100
gp = HepMC.GenParticle()
101
gp.set_status( 4 )
102
gp.set_pdg_id( 2212 )
103
gp.set_momentum(mom)
104
gp.set_generated_mass(938.272046)
105
ROOT.SetOwnership(gp,
False
)
106
gv.add_particle_out(gp)
107
108
continue
109
if
event:
110
pos =
HepMC.FourVector
(0.0, 0.0, 0.0, 0.0)
111
gv = HepMC.GenVertex(pos)
112
ROOT.SetOwnership(gv,
False
)
113
evt.add_vertex(gv)
114
mom =
HepMC.FourVector
( float(line.split()[6])*1000. , float(line.split()[7])*1000. , float(line.split()[8])*1000. , float(line.split()[9])*1000. )
115
gp = HepMC.GenParticle()
116
gp.set_status(int(line.split()[1]) )
117
gp.set_pdg_id(int(line.split()[0]) )
118
gp.set_momentum(mom)
119
gp.set_generated_mass(float(line.split()[10]) * 1000.)
120
ROOT.SetOwnership(gp,
False
)
121
gv.add_particle_out(gp)
122
123
self.
eventsProcessed
+= 1
124
125
return
StatusCode.Success
126
if
if(pathvar)
Definition
SealSharedLib.cxx:168
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
EventFiller.LheEVNTFiller.fileName
str fileName
Definition
SFGen_i/python/EventFiller.py:29
EventFiller.LheEVNTFiller.fillEvent
fillEvent(self, evt)
Definition
SFGen_i/python/EventFiller.py:45
EventFiller.LheEVNTFiller.outputFileName
str outputFileName
Definition
SFGen_i/python/EventFiller.py:30
EventFiller.LheEVNTFiller.__init__
__init__(self, ecmEnergy, name="LheEVNTFiller")
Definition
SFGen_i/python/EventFiller.py:25
EventFiller.LheEVNTFiller.beamEnergyMeV
int beamEnergyMeV
Definition
SFGen_i/python/EventFiller.py:27
EventFiller.LheEVNTFiller.eventsProcessed
int eventsProcessed
Definition
SFGen_i/python/EventFiller.py:31
EventFiller.init_pz
init_pz(energy)
Definition
SFGen_i/python/EventFiller.py:18
HepMC::FourVector
HepMC3::FourVector FourVector
Definition
SimpleVector.h:11
initialize
void initialize()
Definition
run_EoverP.cxx:894
Generated on
for ATLAS Offline Software by
1.17.0