ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.ParticleGun Class Reference
Inheritance diagram for python.ParticleGun:
Collaboration diagram for python.ParticleGun:

Public Member Functions

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

Public Attributes

 samplers
 
 randomStream
 
 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__()

def 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()

def 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  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)
97  #Create all the needed particles
98  for s in self.samplers:
99  particles = s.shoot()
100  for p in particles:
101  # Create the production vertex of the particle
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)
104  evt.add_vertex(gv)
105  # Create a fake particle to connect the production vertex of the particle of interest to the primary
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)
110  # Create the particle
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

◆ initialize()

def 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 

◆ sampler() [1/2]

def 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]

def 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

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

◆ randomStream

python.ParticleGun.randomStream

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

◆ samplers

python.ParticleGun.samplers

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


The documentation for this class was generated from the following file:
plotting.plot_kinematics.run_number
run_number
Definition: plot_kinematics.py:29
initialize
void initialize()
Definition: run_EoverP.cxx:894
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
ParticleGun_FastCalo_ChargeFlip_Config.sampler
sampler
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
str
Definition: BTagTrackIpAccessor.cxx:11
error
Definition: IImpactPoint3dEstimator.h:70