Belle II Software light-2406-ragdoll
KlongDecayReconstructorExpertModule.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/KlongDecayReconstructorExpertModule.h>
11
12// framework aux
13#include <framework/logging/Logger.h>
14
15// decay descriptor
16#include <analysis/DecayDescriptor/DecayDescriptorParticle.h>
17
18// utilities
19#include <analysis/DecayDescriptor/ParticleListName.h>
20
21#include <Math/Vector4D.h>
22#include <TMath.h>
23
24#include <memory>
25
26using namespace std;
27using namespace Belle2;
28
29//-----------------------------------------------------------------
30// Register module
31//-----------------------------------------------------------------
32
33REG_MODULE(KlongDecayReconstructorExpert);
34
35//-----------------------------------------------------------------
36// Implementation
37//-----------------------------------------------------------------
38
40 Module(), m_pdgCode(0), m_isSelfConjugatedParticle(false)
41
42{
43 // set module description (e.g. insert text)
44 setDescription(R"DOC(
45This module is used to employ kinematic constraints to determine the momentum
46of Klongs for two body B decays containing a K_L0 and something else. The
47module creates a list of K_L0 candidates whose K_L0 momentum is reconstructed
48by combining the reconstructed direction (from either the ECL or KLM) of the
49K_L0 and kinematic constraints of the initial state.
50 )DOC");
52
53 // Add parameters
54 addParam("decayString", m_decayString,
55 "Input DecayDescriptor string.");
56 addParam("cut", m_cutParameter, "Selection criteria to be applied", std::string(""));
57 addParam("maximumNumberOfCandidates", m_maximumNumberOfCandidates,
58 "Don't reconstruct channel if more candidates than given are produced.", -1);
59 addParam("decayMode", m_decayModeID, "User-specified decay mode identifier (saved in 'decayModeID' extra-info for each Particle)",
60 0);
61 addParam("writeOut", m_writeOut,
62 "If true, the output ParticleList will be saved by RootOutput. If false, it will be ignored when writing the file.", false);
63 addParam("recoList", m_recoList,
64 "Suffix attached to the original K_L input list to identify the output list of the FindKlongMomentum module; this is the input for this module, if not defined it is set to '_reco' \n",
65 std::string("_reco"));
66
67}
68
70{
72
73 // clear everything, initialize private members
74 m_listName = "";
75 m_generator = nullptr;
76
77 // obtain the input and output particle lists from the decay string
79 if (!valid)
80 B2ERROR("Invalid input DecayString: " << m_decayString);
81
82 // Mother particle
84
85 m_pdgCode = mother->getPDGCode();
86 m_listName = mother->getFullName();
87
90
91 std::string newDecayString;
92 std::string kListName;
93 newDecayString = m_listName + " -> ";
94
95 // Daughters
96 bool k_check = false;
97 int nProducts = m_decaydescriptor.getNDaughters();
98 for (int i = 0; i < nProducts; ++i) {
100 if (daughter->getPDGCode() == Const::Klong.getPDGCode()) {
101 if (k_check)
102 B2FATAL("More than one K_L is detected! This module accepts only one K_L in the final state.");
103
104 StoreObjPtr<ParticleList>().isRequired(daughter->getFullName() + m_recoList);
105 kListName = daughter->getFullName() + m_recoList;
106 k_check = true;
107 } else {
108 StoreObjPtr<ParticleList>().isRequired(daughter->getFullName());
109 newDecayString = newDecayString + daughter->getFullName() + " ";
110 }
111 }
112
113 if (!k_check)
114 B2FATAL("This module is meant to reconstruct decays with a K_L0 in the final state. There is no K_L0 in this decay!");
115
116 newDecayString = newDecayString + kListName;
117
118 m_generator = std::make_unique<ParticleGenerator>(newDecayString, m_cutParameter);
119
121 m_outputList.registerInDataStore(m_listName, flags);
123 m_outputAntiList.registerInDataStore(m_antiListName, flags);
124 }
125
127
128}
129
131{
132 m_outputList.create();
133 m_outputList->initialize(m_pdgCode, m_listName);
134
136 m_outputAntiList.create();
137 m_outputAntiList->initialize(-1 * m_pdgCode, m_antiListName);
138
139 m_outputList->bindAntiParticleList(*(m_outputAntiList));
140 }
141
142 m_generator->init();
143
144 int numberOfCandidates = 0;
145 while (m_generator->loadNext()) {
146
147 Particle particle = m_generator->getCurrentParticle();
148
149 bool is_physical = true;
150
151 const std::vector<Particle*> daughters = particle.getDaughters();
152
153 if (daughters.size() < 2)
154 B2FATAL("Reconstructing particle as a daughter of a decay with less than 2 daughters!");
155
156 if (daughters.size() > 3)
157 B2FATAL("Higher multiplicity (>2) missing momentum decays not implemented yet!");
158
159 int e_check = 0;
160 ROOT::Math::PxPyPzEVector pDaughters;
161 for (auto daughter : daughters) {
162 if (daughter->getPDGCode() != Const::Klong.getPDGCode()) {
163 pDaughters += daughter->get4Vector();
164 e_check = daughter->getArrayIndex() + e_check * 100;
165 }
166 }
167
168
169 ROOT::Math::PxPyPzEVector klDaughters;
170 for (auto daughter : daughters) {
171 if (daughter->getPDGCode() == Const::Klong.getPDGCode()) {
172 klDaughters += daughter->get4Vector();
173 if (e_check != daughter->getExtraInfo("permID")) {
174 is_physical = false;
175 }
176 }
177 }
178 double m_b = particle.getPDGMass();
179
180 ROOT::Math::PxPyPzEVector mom = pDaughters + klDaughters;
181 mom.SetE(TMath::Sqrt(mom.P2() + m_b * m_b));
182 if ((!isnan(mom.P())) && is_physical)
183 particle.set4Vector(mom);
184 if (isnan(mom.P()))
185 is_physical = false;
186
187 if (!m_cut->check(&particle))
188 continue;
189
190 if (!is_physical)
191 continue;
192
193 numberOfCandidates++;
194
195 if (m_maximumNumberOfCandidates > 0 and numberOfCandidates > m_maximumNumberOfCandidates) {
196 m_outputList->clear();
197 break;
198 }
199
200 Particle* newParticle = m_particles.appendNew(particle);
201
202 m_outputList->addParticle(newParticle);
203 newParticle->addExtraInfo("decayModeID", m_decayModeID);
204
205 } //while
206
207} //event
int getPDGCode() const
PDG code.
Definition: Const.h:473
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.
int getPDGCode() const
Return PDG code.
std::string getFullName() const
returns the full name of the particle full_name = name:label
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
const DecayDescriptor * getDaughter(int i) const
return i-th daughter (0 based index).
int getNDaughters() const
return number of direct daughters.
const DecayDescriptorParticle * getMother() const
return mother.
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...
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.
StoreObjPtr< ParticleList > m_outputAntiList
output anti-particle list
StoreArray< Particle > m_particles
StoreArray of Particles.
std::string m_recoList
suffix for input K_L0 list name
StoreObjPtr< ParticleList > m_outputList
output particle list
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.
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
std::vector< Belle2::Particle * > getDaughters() const
Returns a vector of pointers to daughter particles.
Definition: Particle.cc:637
double getPDGMass(void) const
Returns uncertainty on the invariant mass (requires valid momentum error matrix)
Definition: Particle.cc:604
void addExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
Definition: Particle.cc:1336
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.
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
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
std::string antiParticleListName(const std::string &listName)
Returns name of anti-particle-list corresponding to listName.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.