Belle II Software  release-08-01-10
KlongMomentumCalculatorExpertModule.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 // Own header.
10 #include <analysis/modules/KlongDecayReconstructor/KlongMomentumCalculatorExpertModule.h>
11 
12 // framework aux
13 #include <framework/logging/Logger.h>
14 
15 // dataobjects
16 #include <analysis/dataobjects/Particle.h>
17 
18 // decay descriptor
19 #include <analysis/DecayDescriptor/DecayDescriptorParticle.h>
20 
21 // utilities
22 #include <analysis/DecayDescriptor/ParticleListName.h>
23 #include <analysis/utility/ParticleCopy.h>
24 #include <analysis/utility/KlongCalculatorUtils.h>
25 
26 #include <Math/Vector4D.h>
27 
28 #include <memory>
29 
30 using namespace std;
31 using namespace Belle2;
32 
33 //-----------------------------------------------------------------
34 // Register module
35 //-----------------------------------------------------------------
36 
37 REG_MODULE(KlongMomentumCalculatorExpert);
38 
39 //-----------------------------------------------------------------
40 // Implementation
41 //-----------------------------------------------------------------
42 
43 KlongMomentumCalculatorExpertModule::KlongMomentumCalculatorExpertModule() :
44  Module(), m_pdgCode(0)
45 
46 {
47  // set module description (e.g. insert text)
48  setDescription("This module is used to employ kinematic constraints to determine the momentum of Klongs for two body B decays containing a K_L0 and something else. The module creates a list of K_L0 candidates whose K_L0 momentum is reconstructed by combining the reconstructed direction (from either the ECL or KLM) of the K_L0 and kinematic constraints of the initial state.");
50 
51  // Add parameters
52  addParam("decayString", m_decayString,
53  "Input DecayDescriptor string.");
54  addParam("cut", m_cutParameter, "Selection criteria to be applied", std::string(""));
55  addParam("maximumNumberOfCandidates", m_maximumNumberOfCandidates,
56  "Don't reconstruct channel if more candidates than given are produced.", -1);
57  addParam("decayMode", m_decayModeID, "User-specified decay mode identifier (saved in 'decayModeID' extra-info for each Particle)",
58  0);
59  addParam("writeOut", m_writeOut,
60  "If true, the output ParticleList will be saved by RootOutput. If false, it will be ignored when writing the file.", false);
61  addParam("recoList", m_recoList,
62  "Suffix attached to the output K_L list, if not defined it is set to '_reco' \n", std::string("_reco"));
63 
64 }
65 
67 {
69 
70  // clear everything, initialize private members
71  m_pdgCode = 0;
72  m_listName = "";
74  m_generator = nullptr;
75 
76  // obtain the input and output particle lists from the decay string
77  bool valid = m_decaydescriptor.init(m_decayString);
78  if (!valid)
79  B2ERROR("Invalid input DecayString: " << m_decayString);
80 
81  // Mother particle
83 
84  m_pdgCode = mother->getPDGCode();
85  m_listName = mother->getFullName();
86 
89 
91 
92  // Daughters
93  bool k_check = false;
94  int nProducts = m_decaydescriptor.getNDaughters();
95  for (int i = 0; i < nProducts; ++i) {
96  const DecayDescriptorParticle* daughter =
98  StoreObjPtr<ParticleList>().isRequired(daughter->getFullName());
99  if (daughter->getPDGCode() == Const::Klong.getPDGCode()) {
100  if (k_check)
101  B2FATAL("More than one K_L is detected! This module accepts only one K_L in the final state.");
102 
103  m_klistName = daughter->getFullName() + m_klistName;
104  k_check = true;
105  }
106  }
107 
108  if (!k_check)
109  B2FATAL("This module is meant to reconstruct decays with a K_L0 in the final state. There is no K_L0 in this decay!");
110 
111  m_generator = std::make_unique<ParticleGenerator>(m_decayString, m_cutParameter);
112 
114  m_koutputList.registerInDataStore(m_klistName, flags);
115 
117 
118 }
119 
120 
122 {
123  m_koutputList.create();
124  m_koutputList->initialize(Const::Klong.getPDGCode(), m_klistName);
125 
126  m_generator->init();
127 
128  int numberOfCandidates = 0;
129  while (m_generator->loadNext()) {
130 
131  Particle particle = m_generator->getCurrentParticle();
132  const double m_b = particle.getPDGMass();
133  const std::vector<Particle*> daughters = particle.getDaughters();
134 
135  if (daughters.size() < 2)
136  B2FATAL("Reconstructing particle as a daughter of a decay with less then 2 daughters!");
137 
138  if (daughters.size() > 3)
139  B2FATAL("Higher multiplicity (>2) missing momentum decays not implemented yet!");
140 
141  ROOT::Math::PxPyPzEVector BMomentum;
142  ROOT::Math::PxPyPzEVector KMomentum;
143  int idx = 0;
144  bool is_physical = KlongCalculatorUtils::calculateBtoKlongX(BMomentum, KMomentum, daughters, m_b, idx);
145 
146  if (!is_physical)
147  continue;
148 
149  particle.set4Vector(BMomentum);
150 
151  if (!m_cut->check(&particle))
152  continue;
153 
154  numberOfCandidates++;
155 
156  if (m_maximumNumberOfCandidates > 0 and numberOfCandidates > m_maximumNumberOfCandidates) {
157  m_koutputList->clear();
158  break;
159  }
160 
161  for (auto daughter : daughters) {
162  if (daughter->getPDGCode() == Const::Klong.getPDGCode()) {
163  Particle* kparticle = ParticleCopy::copyParticle(daughter);
164  kparticle->set4Vector(KMomentum);
165  m_koutputList->addParticle(kparticle);
166  kparticle->addExtraInfo("permID", idx);
167  break;
168  }
169  }
170 
171  } //while
172 
173 } //event
int getPDGCode() const
PDG code.
Definition: Const.h:464
static const ParticleType Klong
K^0_L particle.
Definition: Const.h:669
EStoreFlags
Flags describing behaviours of objects etc.
Definition: DataStore.h:69
@ c_WriteOut
Object/array should be saved by output modules.
Definition: DataStore.h:70
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:71
Represents a particle in the DecayDescriptor.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
const DecayDescriptorParticle * getMother() const
return mother.
int getNDaughters() const
return number of direct daughters.
const DecayDescriptor * getDaughter(int i) const
return i-th daughter (0 based index).
static std::unique_ptr< GeneralCut > compile(const std::string &cut)
Creates an instance of a cut and returns a unique_ptr to it, if you need a copy-able object instead y...
Definition: GeneralCut.h:84
bool m_isSelfConjugatedParticle
flag that indicates whether an anti-particle mother does not exist and should not be reconstructed as...
StoreObjPtr< ParticleList > m_koutputList
Klong output particle list.
int m_maximumNumberOfCandidates
drop all candidates if more candidates than this parameter are produced
std::string m_antiListName
output anti-particle list name
virtual void initialize() override
Initialize the Module.
std::string m_decayString
Input DecayString specifying the decay being reconstructed.
std::string m_recoList
Suffix attached to the output K_L list, if not defined it is set to '_reco'
std::unique_ptr< ParticleGenerator > m_generator
Generates the combinations.
std::unique_ptr< Variable::Cut > m_cut
cut object which performs the cuts
DecayDescriptor m_decaydescriptor
Decay descriptor of the decay being reconstructed.
int m_pdgCode
PDG code of the combined mother particle.
std::string m_klistName
output K_L0 particle list name
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
@ 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
Class to store reconstructed particles.
Definition: Particle.h:75
void addExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
Definition: Particle.cc:1337
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets Lorentz vector.
Definition: Particle.h:271
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
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
Particle * copyParticle(const Particle *original)
Function takes argument Particle and creates a copy of it and copies of all its (grand-)^n-daughters.
Definition: ParticleCopy.cc:18
std::string antiParticleListName(const std::string &listName)
Returns name of anti-particle-list corresponding to listName.
Abstract base class for different kinds of events.
static bool calculateBtoKlongX(ROOT::Math::PxPyPzEVector &BMomentum, ROOT::Math::PxPyPzEVector &KMomentum, const std::vector< Particle * > daughters, const double m_b, int &idx)
Calculate kinematics of two body B decays containing a K_L0.