Belle II Software development
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#include <framework/datastore/StoreArray.h>
16
17// dataobjects
18#include <analysis/dataobjects/Particle.h>
19
20// decay descriptor
21#include <analysis/DecayDescriptor/DecayDescriptorParticle.h>
22
23// particle combiner
24#include <analysis/ParticleCombiner/ParticleCombiner.h>
25
26// utilities
27#include <analysis/utility/ParticleCopy.h>
28#include <analysis/utility/KlongCalculatorUtils.h>
29
30#include <Math/Vector4D.h>
31
32#include <memory>
33
34using namespace std;
35using namespace Belle2;
36
37//-----------------------------------------------------------------
38// Register module
39//-----------------------------------------------------------------
40
41REG_MODULE(KlongMomentumCalculatorExpert);
42
43//-----------------------------------------------------------------
44// Implementation
45//-----------------------------------------------------------------
46
48 Module()
49
50{
51 // set module description (e.g. insert text)
52 setDescription(R"DOC(
53This module is used to employ kinematic constraints to determine the momentum of Klongs for two
54body decays containing a K_L0 and something else. The module creates a list of K_L0 candidates whose K_L0 momentum is
55reconstructed by combining the reconstructed direction of the K_L0 (either from the ECL or the KLM cluster) and
56kinematic constraints of the initial state.
57)DOC");
59
60 // Add parameters
61 addParam("decayString", m_decayString,
62 "Input DecayDescriptor string.");
63 addParam("maximumNumberOfCandidates", m_maximumNumberOfCandidates,
64 "Don't reconstruct channel if more candidates than given are produced.", 10000);
65 addParam("writeOut", m_writeOut,
66 "If true, the output ParticleList will be saved by RootOutput. If false, it will be ignored when writing the file.", false);
67 addParam("recoList", m_recoList,
68 "Suffix attached to the output K_L list, if not defined it is set to '_reco' \n", std::string("_reco"));
69}
70
72{
74
75 // obtain the input and output particle lists from the decay string
76 bool valid = m_decaydescriptor.init(m_decayString);
77 if (!valid)
78 B2ERROR("Invalid input DecayString: " << m_decayString);
79
81
82 // Daughters
83 bool k_check = false;
84 int nProducts = m_decaydescriptor.getNDaughters();
85 if (nProducts !=2)
86 B2FATAL("The module currently only works for final states with exactly two particles!");
87
88 for (int i = 0; i < nProducts; ++i) {
89 const DecayDescriptorParticle* daughter =
90 m_decaydescriptor.getDaughter(i)->getMother();
91 StoreObjPtr<ParticleList>().isRequired(daughter->getFullName());
92 if (daughter->getPDGCode() == Const::Klong.getPDGCode()) {
93 if (k_check)
94 B2FATAL("More than one K_L is detected! This module accepts only one K_L in the final state.");
95
96 m_klistName = daughter->getFullName() + m_klistName;
97 k_check = true;
98 }
99 }
100
101 if (!k_check)
102 B2FATAL("This module is meant to reconstruct decays with a K_L0 in the final state. There is no K_L0 in this decay!");
103
104 m_generator = std::make_unique<ParticleGenerator>(m_decayString);
105
107 m_koutputList.registerInDataStore(m_klistName, flags);
108}
109
111{
112 m_koutputList.create();
113 m_koutputList->initialize(Const::Klong.getPDGCode(), m_klistName);
114
115 m_generator->init();
116
117 int numberOfCandidates = 0;
118 while (m_generator->loadNext()) {
119
120 Particle particle = m_generator->getCurrentParticle();
121 const double motherMass = particle.getPDGMass();
122 const std::vector<Particle*> daughters = particle.getDaughters();
123
124 ROOT::Math::PxPyPzEVector MotherMomentum;
125 ROOT::Math::PxPyPzEVector KMomentum;
126 int idx = 0;
127 bool is_physical = KlongCalculatorUtils::calculateBtoKlongX(MotherMomentum, KMomentum, daughters, motherMass, idx);
128
129 if (!is_physical)
130 continue;
131
132 numberOfCandidates++;
133
134 if (m_maximumNumberOfCandidates > 0 and numberOfCandidates > m_maximumNumberOfCandidates) {
135 m_koutputList->clear();
136 break;
137 }
138
139 for (auto daughter : daughters) {
140 if (daughter->getPDGCode() == Const::Klong.getPDGCode()) {
141 Particle* kparticle = ParticleCopy::copyParticle(daughter);
142 kparticle->set4Vector(KMomentum);
143 m_koutputList->addParticle(kparticle);
144 kparticle->addExtraInfo("permID", idx);
145 break;
146 }
147 }
148 } //while
149} //event
static const ParticleType Klong
K^0_L particle.
Definition Const.h:678
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.
StoreObjPtr< ParticleList > m_koutputList
Klong output particle list.
int m_maximumNumberOfCandidates
drop all candidates if more candidates than this parameter are produced
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.
DecayDescriptor m_decaydescriptor
Decay descriptor of the decay being reconstructed.
std::string m_klistName
output K_L0 particle list name
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
Module()
Constructor.
Definition Module.cc:30
@ 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:76
void addExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
Definition Particle.cc:1421
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets Lorentz vector.
Definition Particle.h:282
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Particle * copyParticle(const Particle *original)
Function takes argument Particle and creates a copy of it and copies of all its (grand-)^n-daughters.
Abstract base class for different kinds of events.
STL namespace.
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.