Belle II Software  release-08-01-10
GeneratorPreselectionLeptonicModule.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 
10 #include <generators/modules/GeneratorPreselectionLeptonicModule.h>
11 #include <framework/gearbox/Unit.h>
12 #include <numeric>
13 
14 using namespace std;
15 using namespace Belle2;
16 
17 REG_MODULE(GeneratorPreselectionLeptonic);
18 
19 GeneratorPreselectionLeptonicModule::GeneratorPreselectionLeptonicModule() : Module()
20 {
21  // Set module properties
22  setDescription("Filtering based on generator truth information. Returns 0 if cuts have not been passed, 1 only if all cuts are passed.");
24 
25  addParam("signalLeptonPDG", m_signalLeptonPDG, "PDG code for the signal lepton", 11.0);
26  addParam("signalLeptonPMin", m_signalLeptonPMin, "minimum momentum (CMS) for signal lepton", 0.0);
27  addParam("signalLeptonPMax", m_signalLeptonPMax, "maximum momentum (CMS) for signal lepton", 5.0);
28  addParam("tauLeptonPMin", m_tauLeptonPMin, "minimum momentum (CMS) for tau daughter lepton", 0.0);
29  addParam("tauLeptonPMax", m_tauLeptonPMax, "maximum momentum (CMS) for tau daughter lepton", 5.0);
30  addParam("projectionMin", m_projectionMin, "minimum value for projection of tau lepton onto signal lepton momentum (in CMS)",
31  -10.0);
32  addParam("projectionMax", m_projectionMax, "maximum value for projection of tau lepton onto signal lepton momentum (in CMS)", 10.0);
33  addParam("angleMin", m_angleMin,
34  "minimum value for the cosine of the angle between the tau and signal lepton momentum vectors (in CMS)", -1.0);
35  addParam("angleMax", m_angleMax,
36  "maximum value for the cosine of the angle between the tau and signal lepton momentum vectors (in CMS)", 1.0);
37  addParam("zDiffMin", m_zDiffMin, "minimum value for difference between production vertex z-component for signal and tau leptons",
38  -5.0);
39  addParam("zDiffMax", m_zDiffMax, "maximum value for difference between production vertex z-component for signal and tau leptons",
40  5.0);
41  addParam("UMin", m_UMin, "minimum value of U = E - p (calculated using vector sum of momenta and energy for neutrinos in CMS)",
42  -10.0);
43  addParam("UMax", m_UMax, "maximum value of U = E - p (calculated using vector sum of momenta and energy for neutrinos in CMS)",
44  10.0);
45 }
46 
48 {
50  m_initial.isRequired();
51 }
52 
54 {
55 
56  m_tauLeptonPVecs.clear();
57  m_tauLeptonZs.clear();
58  m_nSignalLepton = 0;
59  m_nTauLepton = 0;
60  m_missingPx = 0.0;
61  m_missingPy = 0.0;
62  m_missingPz = 0.0;
63  m_missingE = 0.0;
64 
65  for (int i = 0; i < m_mcparticles.getEntries(); i++) {
66  MCParticle& mc = *m_mcparticles[i];
67  checkParticle(mc);
68  }
69 
70  double missingP = pow(pow(m_missingPx, 2) + pow(m_missingPy, 2) + pow(m_missingPz, 2), 0.5);
71  double U = m_missingE - missingP;
72 
73  int returnValue = 0;
74 
75  if (m_nSignalLepton == 1 && m_nTauLepton > 0 && U > m_UMin && U < m_UMax) {
76  for (int i = 0; i < m_nTauLepton; i++) {
77  double dotProduct = m_signalLeptonPVec.Dot(m_tauLeptonPVecs[i]);
78  double signalLeptonPCMS = sqrt(m_signalLeptonPVec.Mag2());
79  double tauLeptonPCMS = sqrt(m_tauLeptonPVecs[i].Mag2());
80  double angle = dotProduct / (signalLeptonPCMS * tauLeptonPCMS);
81  double projection = dotProduct / signalLeptonPCMS;
82  double zDiff = m_signalLeptonZ - m_tauLeptonZs[i];
83  if (angle > m_angleMin && angle < m_angleMax && projection > m_projectionMin && projection < m_projectionMax && zDiff > m_zDiffMin
84  && zDiff < m_zDiffMax) {
85  returnValue = 1;
86  break;
87  }
88  }
89  }
90 
91  setReturnValue(returnValue);
92 
93 }
94 
96 {
97  if (!mc.hasStatus(MCParticle::c_PrimaryParticle)) return;
98  if (mc.hasStatus(MCParticle::c_Initial) or mc.hasStatus(MCParticle::c_IsVirtual)) return;
99 
100  int pdg = mc.getPDG();
101  const auto vec = m_initial->getLabToCMS() * mc.get4Vector();
102  double p = vec.P();
103 
104  if ((abs(pdg) == Const::muon.getPDGCode() || abs(pdg) == Const::electron.getPDGCode()) && p > m_tauLeptonPMin
105  && p < m_tauLeptonPMax) {
106  m_nTauLepton++;
107  ROOT::Math::XYZVector temp(vec.Px(), vec.Py(), vec.Pz());
108  m_tauLeptonPVecs.push_back(temp);
109  m_tauLeptonZs.push_back(mc.getVertex().Z());
110  }
111 
112  if (abs(pdg) == m_signalLeptonPDG && p > m_signalLeptonPMin && p < m_signalLeptonPMax) {
113  m_nSignalLepton++;
114  ROOT::Math::XYZVector temp(vec.Px(), vec.Py(), vec.Pz());
115  m_signalLeptonPVec = temp;
116  m_signalLeptonZ = mc.getVertex().Z();
117  }
118 
119  if (abs(pdg) == 12 || abs(pdg) == 14 || abs(pdg) == 16) {
120  m_missingPx += vec.Px();
121  m_missingPy += vec.Py();
122  m_missingPz += vec.Pz();
123  m_missingE += vec.E();
124  }
125 
126 }
static const ChargedStable muon
muon particle
Definition: Const.h:651
static const ChargedStable electron
electron particle
Definition: Const.h:650
double m_projectionMin
Minimum value for projection of tau lepton onto signal lepton momentum (in CMS)
double m_signalLeptonPMax
Maximum momentum (CMS) for signal lepton.
double m_zDiffMax
Maximum value for difference between production vertex z-component for signal and tau leptons.
double m_tauLeptonPMin
Minimum momentum (CMS) for tau lepton.
void initialize() override
Initialise the parameters.
std::vector< ROOT::Math::XYZVector > m_tauLeptonPVecs
Vector of momentum vectors for tau leptons.
double m_signalLeptonZ
Storing the production vertex z-component for signal lepton.
StoreArray< MCParticle > m_mcparticles
Store array for the MCParticles.
double m_missingPz
Sum of pz components for neutrinos in event.
double m_UMin
Minimum value of U = E - p (calculated using vector sum of momenta and energy for neutrinos in CMS)
double m_UMax
Maximum value of U = E - p (calculated using vector sum of momenta and energy for neutrinos in CMS)
double m_angleMax
Maximum value for the cosine of the angle between the tau and signal lepton momentum vectors (in CMS)
std::vector< double > m_tauLeptonZs
Vector of production vertex z-components for tau leptons.
double m_missingE
Sum of energy for neutrinos in event.
void checkParticle(const MCParticle &mc)
Called for each particle, performs basic cut checks.
double m_missingPx
Sum of px components for neutrinos in event.
StoreObjPtr< MCInitialParticles > m_initial
Pointer to the actual beam parameters.
std::string m_particleList
The name of the MCParticle collection.
double m_tauLeptonPMax
Maximum momentum (CMS) for tau lepton.
double m_missingPy
Sum of py components for neutrinos in event.
double m_projectionMax
Maximum value for projection of tau lepton onto signal lepton momentum (in CMS)
double m_angleMin
Minimum value for the cosine of the angle between the tau and signal lepton momentum vectors (in CMS)
double m_zDiffMin
Minimum value for difference between production vertex z-component for signal and tau leptons.
ROOT::Math::XYZVector m_signalLeptonPVec
Vector storing momentum components of signal lepton.
double m_signalLeptonPMin
Minimum momentum (CMS) for signal lepton.
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
Definition: MCParticle.h:57
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:47
@ c_IsVirtual
bit 4: Particle is virtual and not going to Geant4.
Definition: MCParticle.h:55
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
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:220
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
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
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.