Belle II Software  release-06-02-00
EventKinematicsModule.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 <analysis/utility/PCmsLabTransform.h>
10 
11 #include <analysis/modules/EventKinematics/EventKinematicsModule.h>
12 
13 #include <analysis/dataobjects/ParticleList.h>
14 #include <analysis/dataobjects/Particle.h>
15 
16 #include <framework/logging/Logger.h>
17 #include <framework/gearbox/Const.h>
18 
19 #include <iostream>
20 
21 using namespace std;
22 using namespace Belle2;
23 
24 //-----------------------------------------------------------------
25 // Register the Module
26 //-----------------------------------------------------------------
28 
29 //-----------------------------------------------------------------
30 // Implementation
31 //-----------------------------------------------------------------
32 
34 {
35  // Set module properties
36  setDescription("Module to compute global event kinematic attributes like missing momentum and energy.");
37 
38  // Parameter definitions
39  addParam("particleLists", m_particleLists, "List of the ParticleLists", vector<string>());
40  addParam("usingMC", m_usingMC, "is built using generated particles", false);
41 
42 }
43 
44 EventKinematicsModule::~EventKinematicsModule() = default;
45 
46 void EventKinematicsModule::initialize()
47 {
48  auto arrayName = (!m_usingMC) ? "EventKinematics" : "EventKinematicsFromMC";
49  m_eventKinematics.registerInDataStore(arrayName);
50 
51 }
52 
53 void EventKinematicsModule::event()
54 {
55  if (!m_eventKinematics) m_eventKinematics.construct(m_usingMC);
56  EventKinematicsModule::getParticleMomentumLists(m_particleLists);
57 
58  TVector3 missingMomentum = EventKinematicsModule::getMissingMomentum();
59  m_eventKinematics->addMissingMomentum(missingMomentum);
60 
61  TVector3 missingMomentumCMS = EventKinematicsModule::getMissingMomentumCMS();
62  m_eventKinematics->addMissingMomentumCMS(missingMomentumCMS);
63 
64  float missingEnergyCMS = EventKinematicsModule::getMissingEnergyCMS();
65  m_eventKinematics->addMissingEnergyCMS(missingEnergyCMS);
66 
67  float missingMass2 = missingEnergyCMS * missingEnergyCMS - missingMomentumCMS.Mag() * missingMomentumCMS.Mag();
68  m_eventKinematics->addMissingMass2(missingMass2);
69 
70  float visibleEnergyCMS = EventKinematicsModule::getVisibleEnergyCMS();
71  m_eventKinematics->addVisibleEnergyCMS(visibleEnergyCMS);
72 
73  float totalPhotonsEnergy = EventKinematicsModule::getTotalPhotonsEnergy();
74  m_eventKinematics->addTotalPhotonsEnergy(totalPhotonsEnergy);
75 }
76 
77 void EventKinematicsModule::terminate()
78 {
79 }
80 
81 void EventKinematicsModule::getParticleMomentumLists(vector<string> particleLists)
82 {
84 
85  m_particleMomentumList.clear();
86  m_photonsMomentumList.clear();
87  m_particleMomentumListCMS.clear();
88 
89  int nParticleLists = particleLists.size();
90  B2DEBUG(10, "Number of ParticleLists to calculate Event Kinematics variables: " << nParticleLists);
91 
92  for (int i_pl = 0; i_pl != nParticleLists; ++i_pl) {
93  string particleListName = particleLists[i_pl];
94  B2DEBUG(10, "ParticleList: " << particleListName);
95  StoreObjPtr<ParticleList> plist(particleListName);
96  int m_part = plist->getListSize();
97  for (int i = 0; i < m_part; i++) {
98  const Particle* part = plist->getParticle(i);
99  if (part->getParticleSource() == Particle::EParticleSourceObject::c_MCParticle and !m_usingMC) {
100  B2FATAL("EventKinematics received MCParticles as an input, but usingMC flag is false");
101  }
102  if (part->getParticleSource() != Particle::EParticleSourceObject::c_MCParticle and m_usingMC) {
103  B2FATAL("EventKinematics received reconstructed Particles as an input, but usingMC flag is true");
104  }
105 
106  TLorentzVector p_lab = part->get4Vector();
107  m_particleMomentumList.push_back(p_lab);
108 
109  if ((part->getParticleSource() == Particle::EParticleSourceObject::c_ECLCluster or
110  part->getParticleSource() == Particle::EParticleSourceObject::c_MCParticle)
111  and (part->getPDGCode() == Const::photon.getPDGCode()))
112  m_photonsMomentumList.push_back(p_lab);
113 
114  TLorentzVector p_cms = T.rotateLabToCms() * p_lab;
115  m_particleMomentumListCMS.push_back(p_cms);
116  }
117  }
118  return;
119 }
120 
121 
122 TVector3 EventKinematicsModule::getMissingMomentum()
123 {
125  TLorentzVector beam = T.getBeamFourMomentum();
126  TVector3 p = beam.Vect();
127  int nParticles = m_particleMomentumList.size();
128  for (int i = 0; i < nParticles; ++i) {
129  p -= m_particleMomentumList.at(i).Vect();
130  }
131  return p;
132 }
133 
134 TVector3 EventKinematicsModule::getMissingMomentumCMS()
135 {
136  TVector3 p(0., 0., 0.);
137  int nParticles = m_particleMomentumListCMS.size();
138  for (int i = 0; i < nParticles; ++i) {
139  p -= m_particleMomentumListCMS.at(i).Vect();
140  }
141  return p;
142 }
143 
144 float EventKinematicsModule::getMissingEnergyCMS()
145 {
147  float ECMS = T.getCMSEnergy();
148  int nParticles = m_particleMomentumListCMS.size();
149  for (int i = 0; i < nParticles; ++i) {
150  ECMS -= m_particleMomentumListCMS.at(i).E();
151  }
152  return ECMS;
153 }
154 
155 float EventKinematicsModule::getVisibleEnergyCMS()
156 {
157  float visibleE = 0.0;
158  int nParticles = m_particleMomentumListCMS.size();
159  for (int i = 0; i < nParticles; ++i) {
160  visibleE += m_particleMomentumListCMS.at(i).E();
161  }
162  return visibleE;
163 }
164 
165 float EventKinematicsModule::getTotalPhotonsEnergy()
166 {
167  float photonsEnergy = 0.0;
168  int nParticles = m_photonsMomentumList.size();
169  for (int i = 0; i < nParticles; ++i) {
170  photonsEnergy += m_photonsMomentumList.at(i).E();
171  }
172  return photonsEnergy;
173 }
Module to compute global quantities related to the event kinematics, like total missing energy and ma...
Class for collecting variables related to the global kinematics of the event.
Base class for Modules.
Definition: Module.h:72
Class to hold Lorentz transformations from/to CMS and boost vector.
double getCMSEnergy() const
Returns CMS energy of e+e- (aka.
const TLorentzRotation rotateLabToCms() const
Returns Lorentz transformation from Lab to CMS.
TLorentzVector getBeamFourMomentum() const
Returns LAB four-momentum of e+e-.
Class to store reconstructed particles.
Definition: Particle.h:74
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.