Belle II Software  release-05-01-25
ParticleGun Class Reference

Class to generate tracks in the particle gun and store them in a MCParticle graph. More...

#include <ParticleGun.h>

Collaboration diagram for ParticleGun:

Classes

struct  Parameters
 Struct to keep all necessary parameters for the particle gun. More...
 

Public Types

enum  EDistribution {
  c_fixedValue,
  c_uniformDistribution,
  c_uniformPtDistribution,
  c_uniformCosDistribution,
  c_uniformLogDistribution,
  c_uniformLogPtDistribution,
  c_normalDistribution,
  c_normalPtDistribution,
  c_normalCosDistribution,
  c_discreteSpectrum,
  c_discretePtSpectrum,
  c_inversePtDistribution,
  c_polylineDistribution,
  c_polylinePtDistribution,
  c_polylineCosDistribution
}
 enum containing all known distributions available for generation of values More...
 

Public Member Functions

 ParticleGun ()
 Default constructor.
 
 ~ParticleGun ()
 Default destructor.
 
bool generateEvent (MCParticleGraph &graph)
 Generate the next event and store the result in the given MCParticle graph. More...
 
bool setParameters (const Parameters &parameters)
 Set the parameters for generating the Particles.
 

Protected Member Functions

double generateValue (EDistribution dist, const std::vector< double > &params)
 Generate a value according to the given distribution with the given parameters.
 

Protected Attributes

Parameters m_params
 All relevant parameters.
 

Detailed Description

Class to generate tracks in the particle gun and store them in a MCParticle graph.

The class supports multiple tracks per event, different PDGcodes and the range for track momenta, track angle and track origin is configurable.

Definition at line 36 of file ParticleGun.h.

Member Enumeration Documentation

◆ EDistribution

enum containing all known distributions available for generation of values

Enumerator
c_fixedValue 

Fixed value, no random generation at all, 1 parameter.

c_uniformDistribution 

Uniform distribution, parameters are min and max value.

c_uniformPtDistribution 

Uniform distribution of Pt, parameters are min and max value.

c_uniformCosDistribution 

Uniform distribution of the cosine of the values, parameters are min and max value.

c_uniformLogDistribution 

Uniform distribution of the logarithm of the values, parameters are min and max value.

c_uniformLogPtDistribution 

Uniform distribution of the logarithm of the Pt, parameters are min and max value.

c_normalDistribution 

Normal distribution, parameters are mean and sigma.

c_normalPtDistribution 

Normal distribution of Pt, parameters are mean and sigma.

c_normalCosDistribution 

Normal distribution of the cosinge, parameters are mean and sigma.

c_discreteSpectrum 

Discrete spectrum, parameters are first the values and then the weights (non-negative) for each value.

c_discretePtSpectrum 

Discrete pt spectrum, parameters are first the values and then the weights (non-negative) for each value.

c_inversePtDistribution 

Distribution uniform in the inverse pt distribution, that is uniform in track curvature.

c_polylineDistribution 

Distribution given as list of (x,y) points.

The Distribution will follow the line connection all points. Parameters are first the x coordinates (sorted) and then the y coordinates (non-negative)

c_polylinePtDistribution 

Same as polylineDistribution but for the transverse momentum.

c_polylineCosDistribution 

Same as polylineDistribution but for the cosine of the angle.

Definition at line 39 of file ParticleGun.h.

67  {
69  EDistribution momentumDist = c_fixedValue;
71  EDistribution phiDist = c_fixedValue;

Member Function Documentation

◆ generateEvent()

bool generateEvent ( MCParticleGraph graph)

Generate the next event and store the result in the given MCParticle graph.

Returns
true if the event was generated.

Definition at line 121 of file ParticleGun.cc.

122 {
123  //generate the event vertex (possible the same for all particles in event)
127 
128  // Time offset
129  double timeOffset = generateValue(m_params.timeDist, m_params.timeParams);
130 
131  //Determine number of tracks
132  int nTracks = static_cast<int>(m_params.nTracks);
133  if (m_params.nTracks <= 0) {
134  nTracks = m_params.pdgCodes.size();
135  } else if (m_params.varyNumberOfTracks) {
136  nTracks = gRandom->Poisson(m_params.nTracks);
137  }
138 
139  //Make list of particles
140  double firstMomentum;
141  for (int i = 0; i < nTracks; ++i) {
143  p.setStatus(MCParticle::c_PrimaryParticle);
144  if (m_params.pdgCodes.size() == 1) {
145  //only one PDGcode available, always take this one
146  p.setPDG(m_params.pdgCodes[0]);
147  } else if (m_params.nTracks <= 0) {
148  //0 or negative nTracks, take the ids sequentially
149  p.setPDG(m_params.pdgCodes[i]);
150  } else {
151  //else choose randomly one of the available codes
152  int index = static_cast<int>(gRandom->Uniform(m_params.pdgCodes.size()));
153  p.setPDG(m_params.pdgCodes[index]);
154  }
155  p.setMassFromPDG();
156  p.setFirstDaughter(0);
157  p.setLastDaughter(0);
158 
159  //lets generate the momentum vector:
161  // if the fixed momentum option enabled, either store the generated momentum for the first
162  // particle or reuse for all others
164  i == 0 ? firstMomentum = momentum : momentum = firstMomentum;
165  }
168 
169  double pt = momentum * sin(theta);
173  //this means we are actually generating the Pt and not the P, so exchange values
174  pt = momentum;
175  momentum = (sin(theta) > 0) ? (pt / sin(theta)) : numeric_limits<double>::max();
176  }
177 
178  double pz = momentum * cos(theta);
179  double px = pt * cos(phi);
180  double py = pt * sin(phi);
181  double m = p.getMass();
182  double e = sqrt(momentum * momentum + m * m);
183 
184  p.setMomentum(px, py, pz);
185  p.setEnergy(e);
186  p.setProductionVertex(vx, vy, vz);
187  p.addStatus(MCParticle::c_StableInGenerator);
188  //Particle is stable in generator. We could use MCParticleGraph options to
189  //do this automatically but setting it here makes the particle correct
190  //independent of the options
191  p.setDecayTime(numeric_limits<double>::infinity());
192 
193  // set time offset to check fit bias in e.g. the ECL waveform fits
194  p.setProductionTime(timeOffset);
195 
197  //If we have independent vertices, generate new vertex for next particle
201  }
202  }// end loop over particles in event
203 
204  return true;
205 }

The documentation for this class was generated from the following files:
Belle2::ParticleGun::c_inversePtDistribution
@ c_inversePtDistribution
Distribution uniform in the inverse pt distribution, that is uniform in track curvature.
Definition: ParticleGun.h:63
Belle2::ParticleGun::c_fixedValue
@ c_fixedValue
Fixed value, no random generation at all, 1 parameter.
Definition: ParticleGun.h:41
Belle2::ParticleGun::Parameters::phiDist
EDistribution phiDist
Distribution to use for azimuth angle generation.
Definition: ParticleGun.h:79
Belle2::ParticleGun::Parameters::thetaDist
EDistribution thetaDist
Distribution to use for polar angle generation.
Definition: ParticleGun.h:81
Belle2::ParticleGun::Parameters::zVertexParams
std::vector< double > zVertexParams
Parameters for the z vertex generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:105
prepareAsicCrosstalkSimDB.e
e
aux.
Definition: prepareAsicCrosstalkSimDB.py:53
Belle2::ParticleGun::Parameters::momentumParams
std::vector< double > momentumParams
Parameters for the momentum generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:95
Belle2::ParticleGun::Parameters::independentVertices
bool independentVertices
If false, all particles of one event will have the same vertex, if true the vertex of each particle w...
Definition: ParticleGun.h:112
Belle2::ParticleGun::Parameters::pdgCodes
std::vector< int > pdgCodes
List of PDG particle codes to pick from when generating particles.
Definition: ParticleGun.h:93
Belle2::ParticleGun::Parameters::varyNumberOfTracks
bool varyNumberOfTracks
If true, the number of tracks per event will fluctuate according to Poisson distribution.
Definition: ParticleGun.h:115
Belle2::ParticleGun::c_uniformLogPtDistribution
@ c_uniformLogPtDistribution
Uniform distribution of the logarithm of the Pt, parameters are min and max value.
Definition: ParticleGun.h:51
Belle2::ParticleGun::c_discretePtSpectrum
@ c_discretePtSpectrum
Discrete pt spectrum, parameters are first the values and then the weights (non-negative) for each va...
Definition: ParticleGun.h:61
Belle2::ParticleGun::c_normalPtDistribution
@ c_normalPtDistribution
Normal distribution of Pt, parameters are mean and sigma.
Definition: ParticleGun.h:55
Belle2::ParticleGun::Parameters::xVertexDist
EDistribution xVertexDist
Distribution to use for x vertex generation.
Definition: ParticleGun.h:83
Belle2::ParticleGun::Parameters::thetaParams
std::vector< double > thetaParams
Parameters for the polar angle generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:99
Belle2::ParticleGun::c_polylinePtDistribution
@ c_polylinePtDistribution
Same as polylineDistribution but for the transverse momentum.
Definition: ParticleGun.h:69
Belle2::ParticleGun::Parameters::yVertexParams
std::vector< double > yVertexParams
Parameters for the y vertex generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:103
Belle2::ParticleGun::Parameters::timeDist
EDistribution timeDist
Distribution to use for time generation.
Definition: ParticleGun.h:89
Belle2::ParticleGun::Parameters::nTracks
double nTracks
Number of tracks to generate per event.
Definition: ParticleGun.h:91
Belle2::MCParticleGraph::addParticle
GraphParticle & addParticle()
Add new particle to the graph.
Definition: MCParticleGraph.h:305
Belle2::ParticleGun::Parameters::xVertexParams
std::vector< double > xVertexParams
Parameters for the x vertex generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:101
Belle2::ParticleGun::Parameters::zVertexDist
EDistribution zVertexDist
Distribution to use for z vertex generation.
Definition: ParticleGun.h:87
Belle2::ParticleGun::Parameters::yVertexDist
EDistribution yVertexDist
Distribution to use for y vertex generation.
Definition: ParticleGun.h:85
Belle2::MCParticle::c_StableInGenerator
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
Definition: MCParticle.h:60
Belle2::ParticleGun::m_params
Parameters m_params
All relevant parameters.
Definition: ParticleGun.h:143
Belle2::ParticleGun::Parameters::phiParams
std::vector< double > phiParams
Parameters for the azimuth angle generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:97
Belle2::ParticleGun::EDistribution
EDistribution
enum containing all known distributions available for generation of values
Definition: ParticleGun.h:39
Belle2::ParticleGun::generateValue
double generateValue(EDistribution dist, const std::vector< double > &params)
Generate a value according to the given distribution with the given parameters.
Definition: ParticleGun.cc:75
Belle2::ParticleGun::Parameters::timeParams
std::vector< double > timeParams
Parameters for the time generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:107
Belle2::MCParticleGraph::GraphParticle
Class to represent Particle data in graph.
Definition: MCParticleGraph.h:86
Belle2::ParticleGun::Parameters::fixedMomentumPerEvent
bool fixedMomentumPerEvent
generates particle momentum according to the specified distribution and assigns this momentum to all ...
Definition: ParticleGun.h:119
Belle2::MCParticle::c_PrimaryParticle
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:58
Belle2::ParticleGun::Parameters::momentumDist
EDistribution momentumDist
Distribution to use for momentum generation.
Definition: ParticleGun.h:77
Belle2::ParticleGun::c_uniformPtDistribution
@ c_uniformPtDistribution
Uniform distribution of Pt, parameters are min and max value.
Definition: ParticleGun.h:45