Belle II Software  release-06-01-15
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  m_tauLeptonPVecs.clear();
56  m_tauLeptonZs.clear();
57  m_nSignalLepton = 0;
58  m_nTauLepton = 0;
59  m_missingPx = 0.0;
60  m_missingPy = 0.0;
61  m_missingPz = 0.0;
62  m_missingE = 0.0;
63 
64  for (int i = 0; i < m_mcparticles.getEntries(); i++) {
65  MCParticle& mc = *m_mcparticles[i];
66  checkParticle(mc);
67  }
68 
69  double missingP = pow(pow(m_missingPx, 2) + pow(m_missingPy, 2) + pow(m_missingPz, 2), 0.5);
70  double U = m_missingE - missingP;
71 
72  int returnValue = 0;
73 
74  if (m_nSignalLepton == 1 && m_nTauLepton > 0 && U > m_UMin && U < m_UMax) {
75  for (int i = 0; i < m_nTauLepton; i++) {
76  double dotProduct = m_signalLeptonPVec.Dot(m_tauLeptonPVecs[i]);
77  double signalLeptonPCMS = sqrt(m_signalLeptonPVec.Mag2());
78  double tauLeptonPCMS = sqrt(m_tauLeptonPVecs[i].Mag2());
79  double angle = dotProduct / (signalLeptonPCMS * tauLeptonPCMS);
80  double projection = dotProduct / signalLeptonPCMS;
81  double zDiff = m_signalLeptonZ - m_tauLeptonZs[i];
82  if (angle > m_angleMin && angle < m_angleMax && projection > m_projectionMin && projection < m_projectionMax && zDiff > m_zDiffMin
83  && zDiff < m_zDiffMax) {
84  returnValue = 1;
85  break;
86  }
87  }
88  }
89 
90  setReturnValue(returnValue);
91 
92 }
93 
95 {
96  if (!mc.hasStatus(MCParticle::c_PrimaryParticle)) return;
97  if (mc.hasStatus(MCParticle::c_Initial) or mc.hasStatus(MCParticle::c_IsVirtual)) return;
98 
99  int pdg = mc.getPDG();
100  const auto vec = m_initial->getLabToCMS() * mc.get4Vector();
101  double p = vec.P();
102 
103  if ((abs(pdg) == Const::muon.getPDGCode() || abs(pdg) == Const::electron.getPDGCode()) && p > m_tauLeptonPMin
104  && p < m_tauLeptonPMax) {
105  m_nTauLepton++;
106  ROOT::Math::XYZVector temp(vec.Px(), vec.Py(), vec.Pz());
107  m_tauLeptonPVecs.push_back(temp);
108  m_tauLeptonZs.push_back(mc.getVertex().Z());
109  }
110 
111  if (abs(pdg) == m_signalLeptonPDG && p > m_signalLeptonPMin && p < m_signalLeptonPMax) {
112  m_nSignalLepton++;
113  ROOT::Math::XYZVector temp(vec.Px(), vec.Py(), vec.Pz());
114  m_signalLeptonPVec = temp;
115  m_signalLeptonZ = mc.getVertex().Z();
116  }
117 
118  if (abs(pdg) == 12 || abs(pdg) == 14 || abs(pdg) == 16) {
119  m_missingPx += vec.Px();
120  m_missingPy += vec.Py();
121  m_missingPz += vec.Pz();
122  m_missingE += vec.E();
123  }
124 
125 }
126 
static const ChargedStable muon
muon particle
Definition: Const.h:541
static const ChargedStable electron
electron particle
Definition: Const.h:540
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
Abstract base class for different kinds of events.