Belle II Software  release-05-02-19
PairGenModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Dmitrii Neverov *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <generators/modules/pairgen/PairGenModule.h>
12 #include <framework/dataobjects/MCInitialParticles.h>
13 
14 #include <TMath.h>
15 #include <TRandom3.h>
16 #include <TLorentzVector.h>
17 #include <TLorentzRotation.h>
18 
19 using namespace TMath;
20 using namespace std;
21 using namespace Belle2;
22 
23 //-----------------------------------------------------------------
24 // Register the Module
25 //-----------------------------------------------------------------
26 REG_MODULE(PairGen)
27 
28 //-----------------------------------------------------------------
29 // Implementation
30 //-----------------------------------------------------------------
31 
33 {
34  //Set module properties
35  setDescription(
36  "Simple module to generate tracks of given PDG back to back in CMS.\n"
37  );
38  setPropertyFlags(c_Input);
39 
40  //Set default values for parameters
41  m_PDG = 11;
42 
43  //Parameter definition
44  addParam("pdgCode", m_PDG,
45  "PDG code for generated particles", 11);
46  addParam("saveBoth", m_saveBoth,
47  "Store both particles if true, one if false", true);
48 }
49 
50 void PairGenModule::initialize()
51 {
52  m_initialParticleGeneration.initialize();
53 }
54 
55 void PairGenModule::event()
56 {
57  try {
58  m_particleGraph.clear();
59  MCInitialParticles initial = m_initialParticleGeneration.generate();
60 
61  //Distribution values:
62  //generate phi uniformly in CMS and theta with 1 + Cos(Theta)^2 :
63  double phi = gRandom->Uniform(0, 2.0 * Pi());
64  double theta = 1.57;
65  double value = 2;
66  while (1 + Cos(theta)*Cos(theta) < value) {
67  theta = gRandom->Uniform(0, 1.0 * Pi());
68  value = gRandom->Uniform(0, 2.0);
69  }
70  double CMSEnergy = initial.getMass();
71  TLorentzRotation boostCMSToLab = initial.getCMSToLab();
72 
73  int nParticles = 1;
74  if (m_saveBoth) {
75  nParticles = 2;
76  }
77  for (int n = 1; n <= nParticles; n++) {
78  //Make list of particles
79  MCParticleGraph::GraphParticle& p = m_particleGraph.addParticle();
80  int sign = (n % 2) * 2 - 1;
81  p.setStatus(MCParticle::c_PrimaryParticle);
82  p.setPDG(sign * m_PDG);
83  p.setMassFromPDG();
84  p.setFirstDaughter(0);
85  p.setLastDaughter(0);
86 
87  double m = p.getMass();
88  double momentum = Sqrt(CMSEnergy * CMSEnergy / 4 - m * m);
89 
90  double pz = momentum * Cos(theta);
91  double px = momentum * Sin(theta) * Cos(phi);
92  double py = momentum * Sin(theta) * Sin(phi);
93  double e = Sqrt(momentum * momentum + m * m);
94 
95  TLorentzVector vp(sign * px, sign * py, sign * pz, e);
96  vp.Transform(boostCMSToLab);
97 
98  p.setMomentum(vp(0), vp(1), vp(2));
99  p.setEnergy(vp(3));
100  p.setProductionVertex(initial.getVertex());
101  p.addStatus(MCParticle::c_StableInGenerator);
102  //Particle is stable in generator. We could use MCParticleGraph options to
103  //do this automatically but setting it here makes the particle correct
104  //independent of the options
105  p.setDecayTime(numeric_limits<double>::infinity());
106 
107  // set time offset to check fit bias in e.g. the ECL waveform fits
108  p.setProductionTime(initial.getTime());
109  }
110 
111  m_particleGraph.generateList();
112  } catch (runtime_error& e) {
113  B2ERROR(e.what());
114  }
115 }
116 
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::ProcType::c_Input
@ c_Input
Input Process.
Belle2::MCInitialParticles::getTime
double getTime() const
Get collison time.
Definition: MCInitialParticles.h:146
Belle2::MCInitialParticles
This class contains the initial state for the given event.
Definition: MCInitialParticles.h:35
Belle2::MCInitialParticles::getMass
double getMass() const
Get the invariant mass of the collision (= energy in CMS)
Definition: MCInitialParticles.h:152
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MCInitialParticles::getVertex
const TVector3 & getVertex() const
Get the position of the collision.
Definition: MCInitialParticles.h:143
Belle2::PairGenModule
The PairGen module.
Definition: PairGenModule.h:38
Belle2::MCInitialParticles::getCMSToLab
const TLorentzRotation & getCMSToLab() const
Return the LorentzRotation to convert from CMS to lab frame.
Definition: MCInitialParticles.h:161
Belle2::MCParticleGraph::GraphParticle
Class to represent Particle data in graph.
Definition: MCParticleGraph.h:86