Belle II Software  release-05-01-25
KlongDecayReconstructorExpertModule.cc
1 /*************************************************************************
2 * BASF2 (Belle Analysis Framework 2) *
3 * Copyright(C) 2018 - Belle II Collaboration *
4 * *
5 * Author: The Belle II Collaboration *
6 * Contributors: B.Oberhof, benjamin.oberhof@lnf.infn.it *
7 * *
8 * This software is provided "as is" without any warranty. *
9 **************************************************************************/
10 
11 // Own include
12 #include <analysis/modules/KlongDecayReconstructor/KlongDecayReconstructorExpertModule.h>
13 
14 // framework aux
15 #include <framework/logging/Logger.h>
16 
17 // dataobjects
18 #include <analysis/dataobjects/Particle.h>
19 
20 // decay descriptor
21 #include <analysis/DecayDescriptor/DecayDescriptorParticle.h>
22 
23 // utilities
24 #include <analysis/DecayDescriptor/ParticleListName.h>
25 
26 #include <memory>
27 
28 using namespace std;
29 
30 namespace Belle2 {
36 //-----------------------------------------------------------------
37 // Register module
38 //-----------------------------------------------------------------
39 
40  REG_MODULE(KlongDecayReconstructorExpert)
41 
42 //-----------------------------------------------------------------
43 // Implementation
44 //-----------------------------------------------------------------
45 
47  Module(), m_pdgCode(0), m_isSelfConjugatedParticle(false)
48 
49  {
50  // set module description (e.g. insert text)
51  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 intial state.");
52  setPropertyFlags(c_ParallelProcessingCertified);
53 
54  // Add parameters
55  addParam("decayString", m_decayString,
56  "Input DecayDescriptor string.");
57  addParam("cut", m_cutParameter, "Selection criteria to be applied", std::string(""));
58  addParam("maximumNumberOfCandidates", m_maximumNumberOfCandidates,
59  "Don't reconstruct channel if more candidates than given are produced.", -1);
60  addParam("decayMode", m_decayModeID, "User-specified decay mode identifier (saved in 'decayModeID' extra-info for each Particle)",
61  0);
62  addParam("writeOut", m_writeOut,
63  "If true, the output ParticleList will be saved by RootOutput. If false, it will be ignored when writing the file.", false);
64  addParam("recoList", m_recoList,
65  "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",
66  std::string("_reco"));
67 
68  }
69 
70  void KlongDecayReconstructorExpertModule::initialize()
71  {
72  // clear everything, initialize private members
73  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
82  const DecayDescriptorParticle* mother = m_decaydescriptor.getMother();
83 
84  m_pdgCode = mother->getPDGCode();
85  m_listName = mother->getFullName();
86 
87  m_antiListName = ParticleListName::antiParticleListName(m_listName);
88  m_isSelfConjugatedParticle = (m_listName == m_antiListName);
89 
90  std::string newDecayString;
91  std::string kListName;
92  newDecayString = m_listName + " -> ";
93 
94  bool k_check = false;
95 
96  // Daughters
97  int nProducts = m_decaydescriptor.getNDaughters();
98  for (int i = 0; i < nProducts; ++i) {
99  const DecayDescriptorParticle* daughter = m_decaydescriptor.getDaughter(i)->getMother();
100  if (daughter->getPDGCode() != Const::Klong.getPDGCode()) {
101  StoreObjPtr<ParticleList>().isRequired(daughter->getFullName());
102  newDecayString = newDecayString + daughter->getFullName() + " ";
103  } else {
104  StoreObjPtr<ParticleList>().isRequired(daughter->getFullName() + m_recoList);
105  kListName = daughter->getFullName() + m_recoList;
106  k_check = true;
107  }
108  }
109 
110  if (!k_check)
111  B2FATAL("This module is meant to reconstruct decays with a K_L0 in the final state. There is no K_L0 in this decay!");
112  newDecayString = newDecayString + kListName;
113 
114  m_generator = std::make_unique<ParticleGenerator>(newDecayString, m_cutParameter);
115 
116  StoreObjPtr<ParticleList> particleList(m_listName);
117  DataStore::EStoreFlags flags = m_writeOut ? DataStore::c_WriteOut : DataStore::c_DontWriteOut;
118  particleList.registerInDataStore(flags);
119  if (!m_isSelfConjugatedParticle) {
120  StoreObjPtr<ParticleList> antiParticleList(m_antiListName);
121  antiParticleList.registerInDataStore(flags);
122  }
123 
124  m_cut = Variable::Cut::compile(m_cutParameter);
125 
126  }
127 
128  void KlongDecayReconstructorExpertModule::event()
129  {
130  StoreArray<Particle> particles;
131 
132  StoreObjPtr<ParticleList> outputList(m_listName);
133  outputList.create();
134  outputList->initialize(m_pdgCode, m_listName);
135 
136  if (!m_isSelfConjugatedParticle) {
137  StoreObjPtr<ParticleList> outputAntiList(m_antiListName);
138  outputAntiList.create();
139  outputAntiList->initialize(-1 * m_pdgCode, m_antiListName);
140 
141  outputList->bindAntiParticleList(*(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  TLorentzVector 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  TLorentzVector 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  TLorentzVector mom = pDaughters + klDaughters;
183  mom.SetE(TMath::Sqrt(mom.Vect().Mag2() + m_b * m_b));
184  if ((!isnan(mom.Vect().Mag())) && is_physical)
185  particle.set4Vector(mom);
186  if (isnan(mom.Vect().Mag()))
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  outputList->clear();
199  break;
200  }
201 
202  Particle* newParticle = particles.appendNew(particle);
203 
204  outputList->addParticle(newParticle);
205  newParticle->addExtraInfo("decayModeID", m_decayModeID);
206 
207  } //while
208 
209  } //event
210 
212 } // end Belle2 namespace
213 
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Particle::addExtraInfo
void addExtraInfo(const std::string &name, float value)
Sets the user-defined data of given name to the given value.
Definition: Particle.cc:1224
Belle2::DataStore::EStoreFlags
EStoreFlags
Flags describing behaviours of objects etc.
Definition: DataStore.h:71
Belle2::KlongDecayReconstructorExpertModule
reco missing module
Definition: KlongDecayReconstructorExpertModule.h:40
Belle2::DecayDescriptorParticle
Represents a particle in the DecayDescriptor.
Definition: DecayDescriptorParticle.h:37
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::Particle
Class to store reconstructed particles.
Definition: Particle.h:77
Belle2::StoreArray< Particle >