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