9#include <generators/modules/ParticleGunModule.h>
10#include <framework/gearbox/Unit.h>
11#include <framework/datastore/StoreArray.h>
12#include <boost/algorithm/string.hpp>
30Particle gun to generate simple tracks.
31This module allows to generate simple events where all tracks have the same
32momentum, angular and vertex distributions. Several distributions are
33available for momentum, phi, theta and vertex position generation:
36 Fixed value, only one parameter has to be specified
39 Uniform between two given values
42 Generate flat transverse momentum pt
45 Generate uniformly in the cosine, e.g. flat in cos(theta). Parameters are
46 still the minimum and maximum angle (**not the cosine of the angle**)
47 ``[min_theta, max_theta]``
49 Generate uniformly in the logarithm. Parameters are still the normal
53 Like uniformLog but for the transverse momentum.
55 Normal (Gaussian) distributed
58 Generate normal distributed transverse momentum pt
59 ``[mean_pt, width_pt]``
61 Generate normal distributed cosine of the angle
64 Generate according to a pdf given as polyline, first the sorted x
65 coordinates and then the non-negative y coordinates
66 ``[x1, x2, x3, ... xn, y1, y2, y3, ..., yn]``
68 Like polyline but for pt, not p
70 Like polyline, but for the cos(), not the absolute value
72 Generate uniformly in the inverse of pt, that is uniform in track
76 Discrete Spectrum given as a list of weights and values (useful for
78 ``[weight1, value1, weight2, value2, ...]``
80 same as above but for transverse momentum
96 "The number of tracks to be generated per event. If <=0, one particle will "
97 "be created for each entry in 'pdgCodes'. Otherwise N particles will be "
98 "created and the Particle ID for each particle will be picked randomly "
99 "from 'pdgCodes'", 1.0);
103 "If true, the number of tracks per event is varied using a Poisson "
104 "distribution. Only used if 'nTracks'>0",
false);
106 "Momentum distribution: one of fixed, uniform, normal, polyline, uniformLog, uniformPt, "
107 "normalPt, inversePt, polylinePt, uniformLogPt or discrete",
string(
"uniform"));
109 "Phi distribution: one of fixed, uniform, normal, normalCos, polyline, uniformCos, "
110 "polylineCos or discrete",
string(
"uniform"));
112 "Theta distribution: one of fixed, uniform, normal, normalCos, polyline, uniformCos, "
113 "polylineCos or discrete",
string(
"uniform"));
115 "Time distribution: one of fixed, uniform, normal, normalCos, polyline, uniformCos, "
116 "polylineCos or discrete",
string(
"fixed"));
118 "Vertex (x,y,z) distribution: one of fixed, uniform, normal, polyline or "
119 "discrete",
string(
"fixed"));
121 "X vertex distribution: same options as 'vertexGeneration'. If this parameter "
122 "is not specified the value from 'vertexGeneration' is used",
string(
""));
124 "Y vertex distribution: same options as 'vertexGeneration'. If this parameter "
125 "is not specified the value from 'vertexGeneration' is used",
string(
""));
127 "Z vertex distribution: same options as 'vertexGeneration'. If this parameter "
128 "is not specified the value from 'vertexGeneration' is used",
string(
""));
130 "If false, all tracks of one event will start from the same vertex, "
131 "otherwise a new vertex is generated for every particle",
false);
133 "generates particle momentum according to the specified "
134 "distribution and assigns this momentum to all particles generated "
135 "for one event",
false);
137 "Parameters for the momentum generation. Meaning of the parameters "
140 "Parameters for the phi generation in degrees. Meaning of the parameters "
143 "Parameters for the theta generation in degrees. Meaning of the parameters "
146 "Parameters for the x vertex generation. Meaning of the parameters "
149 "Parameters for the y vertex generation. Meaning of the parameters "
152 "Parameters for the z vertex generation. Meaning of the parameters "
160 boost::to_lower(name);
177 B2ERROR(
"Unknown distribution '" << name <<
"', using fixed");
195 if (getParam<std::string>(
"xVertexGeneration").isSetInSteering()) {
198 if (getParam<std::string>(
"yVertexGeneration").isSetInSteering()) {
201 if (getParam<std::string>(
"zVertexGeneration").isSetInSteering()) {
225 }
catch (runtime_error& e) {
void generateList(const std::string &name="", int options=c_setNothing)
Generates the MCParticle list and stores it in the StoreArray with the given name.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_Input
This module is an input module (reads data).
MCParticleGraph m_particleGraph
Particle graph to generate MCParticle list.
std::string m_xVertexDist
String representation of the x vertex distribution.
std::string m_zVertexDist
String representation of the z vertex distribution.
void initialize() override
Initializes the module.
void event() override
Method is called for each event.
std::string m_timeDist
String representation of the time distribution.
ParticleGun::Parameters m_parameters
Parameters of the particle gun.
std::string m_momentumDist
String representation of the momentum distribution.
ParticleGunModule()
Constructor.
std::string m_vertexDist
String representation of the vertex distribution.
std::string m_thetaDist
String representation of the polar angle distribution.
ParticleGun::EDistribution convertDistribution(std::string name)
function to convert the strings the uses sets in the parameter list to the internal encoding
std::string m_phiDist
String representation of the azimuth angle distribution.
ParticleGun m_particleGun
Instance of the particle gun.
std::string m_yVertexDist
String representation of the y vertex distribution.
Class to generate tracks in the particle gun and store them in a MCParticle graph.
EDistribution
enum containing all known distributions available for generation of values
@ c_polylineDistribution
Distribution given as list of (x,y) points.
@ 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_normalCosDistribution
Normal distribution of the cosinge, parameters are mean and sigma.
@ c_uniformPtDistribution
Uniform distribution of Pt, parameters are min and max value.
@ c_polylinePtDistribution
Same as polylineDistribution but for the transverse momentum.
@ c_discretePtSpectrum
Discrete pt spectrum, parameters are first the values and then the weights (non-negative) for each va...
@ c_uniformDistribution
Uniform distribution, parameters are min and max value.
@ c_discreteSpectrum
Discrete spectrum, parameters are first the values and then the weights (non-negative) for each value...
@ c_fixedValue
Fixed value, no random generation at all, 1 parameter.
@ c_normalPtDistribution
Normal distribution of Pt, parameters are mean and sigma.
@ c_uniformCosDistribution
Uniform distribution of the cosine of the values, parameters are min and max value.
@ c_inversePtDistribution
Distribution uniform in the inverse pt distribution, that is uniform in track curvature.
@ c_polylineCosDistribution
Same as polylineDistribution but for the cosine of the angle.
@ c_uniformLogDistribution
Uniform distribution of the logarithm of the values, parameters are min and max value.
bool generateEvent(MCParticleGraph &graph)
Generate the next event and store the result in the given MCParticle graph.
bool setParameters(const Parameters ¶meters)
Set the parameters for generating the Particles.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
static const double deg
degree to radians
static const double nm
[nanometers]
static const double um
[micrometers]
static const double ns
Standard of [time].
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
void clear()
Reset particles and decay information to make the class reusable.
Abstract base class for different kinds of events.
std::vector< int > pdgCodes
List of PDG particle codes to pick from when generating particles.
EDistribution xVertexDist
Distribution to use for x vertex generation.
std::vector< double > thetaParams
Parameters for the polar angle generation, meaning depends on chosen distribution.
std::vector< double > momentumParams
Parameters for the momentum generation, meaning depends on chosen distribution.
EDistribution yVertexDist
Distribution to use for y vertex generation.
std::vector< double > xVertexParams
Parameters for the x vertex generation, meaning depends on chosen distribution.
EDistribution thetaDist
Distribution to use for polar angle generation.
EDistribution zVertexDist
Distribution to use for z vertex generation.
EDistribution timeDist
Distribution to use for time generation.
EDistribution momentumDist
Distribution to use for momentum generation.
EDistribution phiDist
Distribution to use for azimuth angle generation.
double nTracks
Number of tracks to generate per event.
bool independentVertices
If false, all particles of one event will have the same vertex, if true the vertex of each particle w...
std::vector< double > zVertexParams
Parameters for the z vertex generation, meaning depends on chosen distribution.
std::vector< double > phiParams
Parameters for the azimuth angle generation, meaning depends on chosen distribution.
bool varyNumberOfTracks
If true, the number of tracks per event will fluctuate according to Poisson distribution.
std::vector< double > timeParams
Parameters for the time generation, meaning depends on chosen distribution.
bool fixedMomentumPerEvent
generates particle momentum according to the specified distribution and assigns this momentum to all ...
std::vector< double > yVertexParams
Parameters for the y vertex generation, meaning depends on chosen distribution.