3 from GeneratorModules.EvgenAlg
import EvgenAlg
6 from AthenaPython.PyAthena
import StatusCode
8 from cppyy.gbl
import std
as std
10 from AthenaPython.PyAthena
import HepMC3
as HepMC
13 from AthenaPython.PyAthena
import HepMC
as HepMC
15 __author__ =
"Andy Buckley <andy.buckley@cern.ch>, Andrii Verbytskyi <andrii.verbytskyi@cern.ch>"
19 A simple but flexible algorithm for generating events from simple distributions.
22 def __init__(self, name="ParticleGun", randomStream="ParticleGun", randomSeed=None):
23 super(ParticleGun, self).
__init__(name=name)
30 "Get the first (and presumed only) sampler"
34 "Set the samplers list to include only a single sampler, s"
39 return StatusCode.Success
44 Sample a list of particle properties, which are then used to create a new GenEvent in StoreGate.
48 seed = ROOT.ATHRNG.calculateSeedsPython(self.
randomStream, self._ctx.eventID().event_number(), self._ctx.eventID().
run_number(), offset)
51 self.msg.warning(
"Failed to find a seed for the random stream named '%s'.", self.
randomStream)
54 self.msg.
debug(
"Set random seed to %s.",
str(seed))
57 self.msg.
error(
"Failed to set random seed.")
58 return StatusCode.Failure
61 evt.weights().push_back(1.0)
67 pos = HepMC.FourVector(p.pos.X(), p.pos.Y(), p.pos.Z(), p.pos.T())
68 gv = HepMC.GenVertex(pos)
69 ROOT.SetOwnership(gv,
False)
73 mom = HepMC.FourVector(p.mom.Px(), p.mom.Py(), p.mom.Pz(), p.mom.E())
74 gp = HepMC.GenParticle()
78 if p.mass
is not None:
79 gp.set_generated_mass(p.mass)
80 ROOT.SetOwnership(gp,
False)
81 gv.add_particle_out(gp)
84 evt.set_units(HepMC.Units.MEV, HepMC.Units.MM)
85 evt.weights().push_back(1.0)
86 beamparticle1 = std.shared_ptr[
'HepMC3::GenParticle'](HepMC.GenParticle(HepMC.FourVector(0,0,-7000,7000),2212,4))
87 ROOT.SetOwnership(beamparticle1,
False)
88 beamparticle2 = std.shared_ptr[
'HepMC3::GenParticle'](HepMC.GenParticle(HepMC.FourVector(0,0,7000,7000),2212,4))
89 ROOT.SetOwnership(beamparticle2,
False)
90 primary = std.shared_ptr[
'HepMC3::GenVertex'](HepMC.GenVertex())
91 ROOT.SetOwnership(primary,
False)
92 primary.add_particle_in(beamparticle1)
93 primary.add_particle_in(beamparticle2)
94 evt.add_vertex(primary)
95 evt.add_beam_particle(beamparticle1)
96 evt.add_beam_particle(beamparticle2)
102 gv = std.shared_ptr[
'HepMC3::GenVertex'](HepMC.GenVertex(HepMC.FourVector(p.pos.X(), p.pos.Y(), p.pos.Z(), p.pos.T())))
103 ROOT.SetOwnership(gv,
False)
106 fakeparticle = std.shared_ptr[
'HepMC3::GenParticle'](HepMC.GenParticle(HepMC.FourVector(p.mom.Px(), p.mom.Py(), p.mom.Pz(), p.mom.E()),p.pid,11))
107 ROOT.SetOwnership(fakeparticle,
False)
108 gv.add_particle_in(fakeparticle)
109 primary.add_particle_out(fakeparticle)
111 gp = std.shared_ptr[
'HepMC3::GenParticle'](HepMC.GenParticle(HepMC.FourVector(p.mom.Px(), p.mom.Py(), p.mom.Pz(), p.mom.E()),p.pid,1))
112 ROOT.SetOwnership(gp,
False)
113 if p.mass
is not None:
114 gp.set_generated_mass(p.mass)
115 gv.add_particle_out(gp)
116 for p
in evt.particles():
117 att = std.shared_ptr[
'HepMC3::IntAttribute'](HepMC.IntAttribute(p.id()))
118 p.add_attribute(
"barcode",att)
119 for v
in evt.vertices():
120 att = std.shared_ptr[
'HepMC3::IntAttribute'](HepMC.IntAttribute(v.id()))
121 v.add_attribute(
"barcode",att)
122 return StatusCode.Success