ATLAS Offline Software
Loading...
Searching...
No Matches
python.ParticleGun Class Reference
Inheritance diagram for python.ParticleGun:
Collaboration diagram for python.ParticleGun:

Public Member Functions

 __init__ (self, name="ParticleGun", randomStream="ParticleGun", randomSeed=None)
 sampler (self)
 sampler (self, s)
 initialize (self)
 fillEvent (self, evt)

Public Attributes

list samplers = [ParticleSampler()]
 Make and fill particles.
 randomStream = randomStream
 randomSeed = randomSeed

Detailed Description

A simple but flexible algorithm for generating events from simple distributions.

Definition at line 17 of file Generators/ParticleGun/python/__init__.py.

Constructor & Destructor Documentation

◆ __init__()

python.ParticleGun.__init__ ( self,
name = "ParticleGun",
randomStream = "ParticleGun",
randomSeed = None )

Definition at line 22 of file Generators/ParticleGun/python/__init__.py.

22 def __init__(self, name="ParticleGun", randomStream="ParticleGun", randomSeed=None):
23 super(ParticleGun, self).__init__(name=name)
24 self.samplers = [ParticleSampler()]
25 self.randomStream = randomStream
26 self.randomSeed = randomSeed
27

Member Function Documentation

◆ fillEvent()

python.ParticleGun.fillEvent ( self,
evt )
Sample a list of particle properties, which are then used to create a new GenEvent in StoreGate.

Definition at line 42 of file Generators/ParticleGun/python/__init__.py.

42 def fillEvent(self, evt):
43 """
44 Sample a list of particle properties, which are then used to create a new GenEvent in StoreGate.
45 """
46 # set the random seed
47 offset = self.randomSeed if self.randomSeed is not None else 0
48 seed = ROOT.ATHRNG.calculateSeedsPython(self.randomStream, self._ctx.eventID().event_number(), self._ctx.eventID().run_number(), offset)
49
50 if seed is None:
51 self.msg.warning("Failed to find a seed for the random stream named '%s'.", self.randomStream)
52 seed = self.randomSeed
53 if seed is not None:
54 self.msg.debug("Set random seed to %s.", str(seed))
55 random.seed(seed)
56 else:
57 self.msg.error("Failed to set random seed.")
58 return StatusCode.Failure
59
60 if HepMCVersion == 2:
61 evt.weights().push_back(1.0)
62
63 for s in self.samplers:
64 particles = s.shoot()
65 for p in particles:
66
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)
70 evt.add_vertex(gv)
71
72
73 mom = HepMC.FourVector(p.mom.Px(), p.mom.Py(), p.mom.Pz(), p.mom.E())
74 gp = HepMC.GenParticle()
75 gp.set_status(1)
76 gp.set_pdg_id(p.pid)
77 gp.set_momentum(mom)
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)
82
83 if HepMCVersion == 3:
84 evt.set_units(HepMC.Units.MEV, HepMC.Units.MM)
85 evt.weights().push_back(1.0)
86 evt.set_event_number(self._ctx.eventID().event_number())
87 beamparticle1 = std.shared_ptr['HepMC3::GenParticle'](HepMC.GenParticle(HepMC.FourVector(0,0,-7000,7000),2212,4))
88 ROOT.SetOwnership(beamparticle1, False)
89 beamparticle2 = std.shared_ptr['HepMC3::GenParticle'](HepMC.GenParticle(HepMC.FourVector(0,0,7000,7000),2212,4))
90 ROOT.SetOwnership(beamparticle2, False)
91 primary = std.shared_ptr['HepMC3::GenVertex'](HepMC.GenVertex())
92 ROOT.SetOwnership(primary, False)
93 primary.add_particle_in(beamparticle1)
94 primary.add_particle_in(beamparticle2)
95 evt.add_vertex(primary)
96 evt.add_beam_particle(beamparticle1)
97 evt.add_beam_particle(beamparticle2)
98 #Create all the needed particles
99 for s in self.samplers:
100 particles = s.shoot()
101 for p in particles:
102 # Create the production vertex of the particle
103 gv = std.shared_ptr['HepMC3::GenVertex'](HepMC.GenVertex(HepMC.FourVector(p.pos.X(), p.pos.Y(), p.pos.Z(), p.pos.T())))
104 ROOT.SetOwnership(gv, False)
105 evt.add_vertex(gv)
106 # Create a fake particle to connect the production vertex of the particle of interest to the primary
107 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))
108 ROOT.SetOwnership(fakeparticle, False)
109 gv.add_particle_in(fakeparticle)
110 primary.add_particle_out(fakeparticle)
111 # Create the particle
112 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))
113 ROOT.SetOwnership(gp, False)
114 if p.mass is not None:
115 gp.set_generated_mass(p.mass)
116 gv.add_particle_out(gp)
117 for p in evt.particles():
118 att = std.shared_ptr['HepMC3::IntAttribute'](HepMC.IntAttribute(p.id()))
119 p.add_attribute("barcode",att)
120 for v in evt.vertices():
121 att = std.shared_ptr['HepMC3::IntAttribute'](HepMC.IntAttribute(v.id()))
122 v.add_attribute("barcode",att)
123 return StatusCode.Success
const bool debug

◆ initialize()

python.ParticleGun.initialize ( self)

Definition at line 38 of file Generators/ParticleGun/python/__init__.py.

38 def initialize(self):
39 return StatusCode.Success
40
41
void initialize()

◆ sampler() [1/2]

python.ParticleGun.sampler ( self)

Definition at line 29 of file Generators/ParticleGun/python/__init__.py.

29 def sampler(self):
30 "Get the first (and presumed only) sampler"
31 return self.samplers[0] if self.samplers else None

◆ sampler() [2/2]

python.ParticleGun.sampler ( self,
s )

Definition at line 33 of file Generators/ParticleGun/python/__init__.py.

33 def sampler(self, s):
34 "Set the samplers list to include only a single sampler, s"
35 self.samplers = [s]
36
37

Member Data Documentation

◆ randomSeed

python.ParticleGun.randomSeed = randomSeed

Definition at line 26 of file Generators/ParticleGun/python/__init__.py.

◆ randomStream

python.ParticleGun.randomStream = randomStream

Definition at line 25 of file Generators/ParticleGun/python/__init__.py.

◆ samplers

list python.ParticleGun.samplers = [ParticleSampler()]

Make and fill particles.

Definition at line 24 of file Generators/ParticleGun/python/__init__.py.


The documentation for this class was generated from the following file: