Belle II Software  release-06-02-00
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 <TLorentzVector.h>
15 #include <TLorentzRotation.h>
16 
17 using namespace TMath;
18 using namespace std;
19 using namespace Belle2;
20 
21 //-----------------------------------------------------------------
22 // Register the Module
23 //-----------------------------------------------------------------
24 REG_MODULE(PairGen)
25 
26 //-----------------------------------------------------------------
27 // Implementation
28 //-----------------------------------------------------------------
29 
31 {
32  //Set module properties
33  setDescription(
34  "Simple module to generate tracks of given PDG back to back in CMS.\n"
35  );
36  setPropertyFlags(c_Input);
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 
48 void PairGenModule::initialize()
49 {
50  m_initialParticleGeneration.initialize();
51 }
52 
53 void PairGenModule::event()
54 {
55  try {
56  m_particleGraph.clear();
57  MCInitialParticles initial = m_initialParticleGeneration.generate();
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  TLorentzRotation 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
77  MCParticleGraph::GraphParticle& p = m_particleGraph.addParticle();
78  int sign = (n % 2) * 2 - 1;
79  p.setStatus(MCParticle::c_PrimaryParticle);
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  TLorentzVector vp(sign * px, sign * py, sign * pz, e);
94  vp.Transform(boostCMSToLab);
95 
96  p.setMomentum(vp(0), vp(1), vp(2));
97  p.setEnergy(vp(3));
98  p.setProductionVertex(initial.getVertex());
99  p.addStatus(MCParticle::c_StableInGenerator);
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 
109  m_particleGraph.generateList();
110  } catch (runtime_error& e) {
111  B2ERROR(e.what());
112  }
113 }
114 
This class contains the initial state for the given event.
const TLorentzRotation & getCMSToLab() const
Return the LorentzRotation to convert from CMS to lab frame.
const TVector3 & 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 collison time.
Class to represent Particle data in graph.
Base class for Modules.
Definition: Module.h:72
The PairGen module.
Definition: PairGenModule.h:28
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
@ c_Input
Input Process.
Abstract base class for different kinds of events.