Belle II Software development
PairGenModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <generators/modules/pairgen/PairGenModule.h>
10#include <framework/dataobjects/MCInitialParticles.h>
11
12#include <TMath.h>
13#include <TRandom3.h>
14#include <Math/Vector4D.h>
15#include <Math/LorentzRotation.h>
16
17using namespace TMath;
18using namespace std;
19using namespace Belle2;
20
21//-----------------------------------------------------------------
22// Register the Module
23//-----------------------------------------------------------------
24REG_MODULE(PairGen);
25
26//-----------------------------------------------------------------
27// Implementation
28//-----------------------------------------------------------------
29
31{
32 //Set module properties
34 "Simple module to generate tracks of given PDG back to back in CMS.\n"
35 );
37
38 //Set default values for parameters
39 m_PDG = 11;
40
41 //Parameter definition
42 addParam("pdgCode", m_PDG,
43 "PDG code for generated particles", 11);
44 addParam("saveBoth", m_saveBoth,
45 "Store both particles if true, one if false", true);
46}
47
49{
51}
52
54{
55 try {
58
59 //Distribution values:
60 //generate phi uniformly in CMS and theta with 1 + Cos(Theta)^2 :
61 double phi = gRandom->Uniform(0, 2.0 * Pi());
62 double theta = 1.57;
63 double value = 2;
64 while (1 + Cos(theta)*Cos(theta) < value) {
65 theta = gRandom->Uniform(0, 1.0 * Pi());
66 value = gRandom->Uniform(0, 2.0);
67 }
68 double CMSEnergy = initial.getMass();
69 ROOT::Math::LorentzRotation boostCMSToLab = initial.getCMSToLab();
70
71 int nParticles = 1;
72 if (m_saveBoth) {
73 nParticles = 2;
74 }
75 for (int n = 1; n <= nParticles; n++) {
76 //Make list of particles
78 int sign = (n % 2) * 2 - 1;
80 p.setPDG(sign * m_PDG);
81 p.setMassFromPDG();
82 p.setFirstDaughter(0);
83 p.setLastDaughter(0);
84
85 double m = p.getMass();
86 double momentum = Sqrt(CMSEnergy * CMSEnergy / 4 - m * m);
87
88 double pz = momentum * Cos(theta);
89 double px = momentum * Sin(theta) * Cos(phi);
90 double py = momentum * Sin(theta) * Sin(phi);
91 double e = Sqrt(momentum * momentum + m * m);
92
93 ROOT::Math::PxPyPzEVector vp(sign * px, sign * py, sign * pz, e);
94 vp = boostCMSToLab * vp;
95
96 p.setMomentum(vp.px(), vp.py(), vp.pz());
97 p.setEnergy(vp.E());
98 p.setProductionVertex(initial.getVertex());
100 //Particle is stable in generator. We could use MCParticleGraph options to
101 //do this automatically but setting it here makes the particle correct
102 //independent of the options
103 p.setDecayTime(numeric_limits<double>::infinity());
104
105 // set time offset to check fit bias in e.g. the ECL waveform fits
106 p.setProductionTime(initial.getTime());
107 }
108
110 } catch (runtime_error& e) {
111 B2ERROR(e.what());
112 }
113}
114
This class contains the initial state for the given event.
const ROOT::Math::LorentzRotation & getCMSToLab() const
Return the LorentzRotation to convert from CMS to lab frame.
const ROOT::Math::XYZVector & getVertex() const
Get the position of the collision.
double getMass() const
Get the invariant mass of the collision (= energy in CMS)
double getTime() const
Get collision time.
Class to represent Particle data in graph.
void generateList(const std::string &name="", int options=c_setNothing)
Generates the MCParticle list and stores it in the StoreArray with the given name.
@ 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
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_Input
This module is an input module (reads data).
Definition: Module.h:78
MCParticleGraph m_particleGraph
Particle graph to generate MCParticle list.
Definition: PairGenModule.h:53
PairGenModule()
Constructor.
int m_PDG
Particles PDG code.
Definition: PairGenModule.h:43
void initialize() override
Initializes the module.
void event() override
Method is called for each event.
InitialParticleGeneration m_initialParticleGeneration
Particle generator to generate initial beam energy, vertex and time.
Definition: PairGenModule.h:52
bool m_saveBoth
Store both particles.
Definition: PairGenModule.h:49
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
void initialize()
function to be executed on initialize()
MCInitialParticles & generate()
Generate a new event.
void clear()
Reset particles and decay information to make the class reusable.
GraphParticle & addParticle()
Add new particle to the graph.
Abstract base class for different kinds of events.
STL namespace.