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