Belle II Software  release-06-01-15
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 26 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 29 of file ParticleGun.h.

29  {
62  };
@ c_polylineDistribution
Distribution given as list of (x,y) points.
Definition: ParticleGun.h:57
@ c_uniformLogPtDistribution
Uniform distribution of the logarithm of the Pt, parameters are min and max value.
Definition: ParticleGun.h:41
@ c_normalDistribution
Normal distribution, parameters are mean and sigma.
Definition: ParticleGun.h:43
@ c_normalCosDistribution
Normal distribution of the cosinge, parameters are mean and sigma.
Definition: ParticleGun.h:47
@ c_uniformPtDistribution
Uniform distribution of Pt, parameters are min and max value.
Definition: ParticleGun.h:35
@ c_polylinePtDistribution
Same as polylineDistribution but for the transverse momentum.
Definition: ParticleGun.h:59
@ c_discretePtSpectrum
Discrete pt spectrum, parameters are first the values and then the weights (non-negative) for each va...
Definition: ParticleGun.h:51
@ c_uniformDistribution
Uniform distribution, parameters are min and max value.
Definition: ParticleGun.h:33
@ c_discreteSpectrum
Discrete spectrum, parameters are first the values and then the weights (non-negative) for each value...
Definition: ParticleGun.h:49
@ c_fixedValue
Fixed value, no random generation at all, 1 parameter.
Definition: ParticleGun.h:31
@ c_normalPtDistribution
Normal distribution of Pt, parameters are mean and sigma.
Definition: ParticleGun.h:45
@ c_uniformCosDistribution
Uniform distribution of the cosine of the values, parameters are min and max value.
Definition: ParticleGun.h:37
@ c_inversePtDistribution
Distribution uniform in the inverse pt distribution, that is uniform in track curvature.
Definition: ParticleGun.h:53
@ c_polylineCosDistribution
Same as polylineDistribution but for the cosine of the angle.
Definition: ParticleGun.h:61
@ c_uniformLogDistribution
Uniform distribution of the logarithm of the values, parameters are min and max value.
Definition: ParticleGun.h:39

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 119 of file ParticleGun.cc.

120 {
121  //generate the event vertex (possible the same for all particles in event)
125 
126  // Time offset
127  double timeOffset = generateValue(m_params.timeDist, m_params.timeParams);
128 
129  //Determine number of tracks
130  int nTracks = static_cast<int>(m_params.nTracks);
131  if (m_params.nTracks <= 0) {
132  nTracks = m_params.pdgCodes.size();
133  } else if (m_params.varyNumberOfTracks) {
134  nTracks = gRandom->Poisson(m_params.nTracks);
135  }
136 
137  //Make list of particles
138  double firstMomentum;
139  for (int i = 0; i < nTracks; ++i) {
141  p.setStatus(MCParticle::c_PrimaryParticle);
142  if (m_params.pdgCodes.size() == 1) {
143  //only one PDGcode available, always take this one
144  p.setPDG(m_params.pdgCodes[0]);
145  } else if (m_params.nTracks <= 0) {
146  //0 or negative nTracks, take the ids sequentially
147  p.setPDG(m_params.pdgCodes[i]);
148  } else {
149  //else choose randomly one of the available codes
150  int index = static_cast<int>(gRandom->Uniform(m_params.pdgCodes.size()));
151  p.setPDG(m_params.pdgCodes[index]);
152  }
153  p.setMassFromPDG();
154  p.setFirstDaughter(0);
155  p.setLastDaughter(0);
156 
157  //lets generate the momentum vector:
159  // if the fixed momentum option enabled, either store the generated momentum for the first
160  // particle or reuse for all others
162  i == 0 ? firstMomentum = momentum : momentum = firstMomentum;
163  }
166 
167  double pt = momentum * sin(theta);
171  //this means we are actually generating the Pt and not the P, so exchange values
172  pt = momentum;
173  momentum = (sin(theta) > 0) ? (pt / sin(theta)) : numeric_limits<double>::max();
174  }
175 
176  double pz = momentum * cos(theta);
177  double px = pt * cos(phi);
178  double py = pt * sin(phi);
179  double m = p.getMass();
180  double e = sqrt(momentum * momentum + m * m);
181 
182  p.setMomentum(px, py, pz);
183  p.setEnergy(e);
184  p.setProductionVertex(vx, vy, vz);
185  p.addStatus(MCParticle::c_StableInGenerator);
186  //Particle is stable in generator. We could use MCParticleGraph options to
187  //do this automatically but setting it here makes the particle correct
188  //independent of the options
189  p.setDecayTime(numeric_limits<double>::infinity());
190 
191  // set time offset to check fit bias in e.g. the ECL waveform fits
192  p.setProductionTime(timeOffset);
193 
195  //If we have independent vertices, generate new vertex for next particle
199  }
200  }// end loop over particles in event
201 
202  return true;
203 }
Class to represent Particle data in graph.
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:47
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
Definition: MCParticle.h:49
Parameters m_params
All relevant parameters.
Definition: ParticleGun.h:133
double generateValue(EDistribution dist, const std::vector< double > &params)
Generate a value according to the given distribution with the given parameters.
Definition: ParticleGun.cc:73
GraphParticle & addParticle()
Add new particle to the graph.
std::vector< int > pdgCodes
List of PDG particle codes to pick from when generating particles.
Definition: ParticleGun.h:83
EDistribution xVertexDist
Distribution to use for x vertex generation.
Definition: ParticleGun.h:73
std::vector< double > thetaParams
Parameters for the polar angle generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:89
std::vector< double > momentumParams
Parameters for the momentum generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:85
EDistribution yVertexDist
Distribution to use for y vertex generation.
Definition: ParticleGun.h:75
std::vector< double > xVertexParams
Parameters for the x vertex generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:91
EDistribution thetaDist
Distribution to use for polar angle generation.
Definition: ParticleGun.h:71
EDistribution zVertexDist
Distribution to use for z vertex generation.
Definition: ParticleGun.h:77
EDistribution timeDist
Distribution to use for time generation.
Definition: ParticleGun.h:79
EDistribution momentumDist
Distribution to use for momentum generation.
Definition: ParticleGun.h:67
EDistribution phiDist
Distribution to use for azimuth angle generation.
Definition: ParticleGun.h:69
double nTracks
Number of tracks to generate per event.
Definition: ParticleGun.h:81
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:102
std::vector< double > zVertexParams
Parameters for the z vertex generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:95
std::vector< double > phiParams
Parameters for the azimuth angle generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:87
bool varyNumberOfTracks
If true, the number of tracks per event will fluctuate according to Poisson distribution.
Definition: ParticleGun.h:105
std::vector< double > timeParams
Parameters for the time generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:97
bool fixedMomentumPerEvent
generates particle momentum according to the specified distribution and assigns this momentum to all ...
Definition: ParticleGun.h:109
std::vector< double > yVertexParams
Parameters for the y vertex generation, meaning depends on chosen distribution.
Definition: ParticleGun.h:93

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