Belle II Software light-2406-ragdoll
ParticleCombinerModule.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/ParticleCombiner/ParticleCombinerModule.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#include <analysis/utility/EvtPDLUtil.h>
21#include <analysis/utility/PCmsLabTransform.h>
22
23using namespace std;
24using namespace Belle2;
25
26//-----------------------------------------------------------------
27// Register module
28//-----------------------------------------------------------------
29
30REG_MODULE(ParticleCombiner);
31
32//-----------------------------------------------------------------
33// Implementation
34//-----------------------------------------------------------------
35
37 Module()
38
39{
40 // set module description (e.g. insert text)
41 setDescription("Makes particle combinations");
43
44 // Add parameters
45 addParam("decayString", m_decayString,
46 "Input DecayDescriptor string (see :ref:`DecayString`).");
47 addParam("cut", m_cutParameter, "Selection criteria to be applied", std::string(""));
48 addParam("maximumNumberOfCandidates", m_maximumNumberOfCandidates,
49 "Max. number of candidates reconstructed. By default, if the limit is reached no candidates will be produced.\n"
50 "This behaviour can be changed by \'ignoreIfTooManyCandidates\' flag.", 10000);
51
52 addParam("ignoreIfTooManyCandidates", m_ignoreIfTooManyCandidates,
53 "Don't reconstruct channel if more candidates than given by \'maximumNumberOfCandidates\' are produced.", true);
54
55 addParam("decayMode", m_decayModeID, "User-specified decay mode identifier (saved in 'decayModeID' extra-info for each Particle)",
56 0);
57 addParam("writeOut", m_writeOut,
58 "If true, the output ParticleList will be saved by RootOutput. If false, it will be ignored when writing the file.", false);
59 addParam("recoilParticleType", m_recoilParticleType, R"DOC(If not equal 0,
60the mother Particle is reconstructed in the recoil against the daughter particles.
61In the case of the following decay chain M -> D1 D2 ... Dn and
62
63- recoilParticleType = 1:
64 - the mother momentum is given by: p(M) = p(e+e-) - p(D1) - p(D2) - ... - p(DN)
65 - D1, D2, ..., DN are attached as daughters of M
66- recoilParticleType = 2:
67 - the mother momentum is given by: p(M) = p(D1) - p(D2) - ... - p(DN)
68 - D1, D2, ..., DN are attached as daughters of M
69 )DOC", 0);
70 addParam("chargeConjugation", m_chargeConjugation,
71 "If true, the charge-conjugated mode will be reconstructed as well", true);
72 addParam("allowChargeViolation", m_allowChargeViolation,
73 "If true the decay string does not have to conserve electric charge", false);
74
75 // initializing the rest of private members
76 m_pdgCode = 0;
78 m_generator = nullptr;
79}
80
82{
83 // clear everything
84 m_pdgCode = 0;
85 m_listName = "";
86
87 // obtain the input and output particle lists from the decay string
89 if (!valid)
90 B2ERROR("Invalid input DecayString: " << m_decayString);
91
92 // Mother particle
94
95 m_pdgCode = mother->getPDGCode();
96 m_listName = mother->getFullName();
97
100
101 // Daughters
102 int nProducts = m_decaydescriptor.getNDaughters();
103 int daughtersNetCharge = 0;
104 for (int i = 0; i < nProducts; ++i) {
105 const DecayDescriptorParticle* daughter =
107 StoreObjPtr<ParticleList>().isRequired(daughter->getFullName());
108 int daughterPDGCode = daughter->getPDGCode();
109 if (m_recoilParticleType == 2 && i == 0) {
110 daughtersNetCharge -= EvtPDLUtil::charge(daughterPDGCode);
111 } else {
112 daughtersNetCharge += EvtPDLUtil::charge(daughterPDGCode);
113 }
114 }
115
116 // The electric charge check makes no sense for an inclusive decay
117 if (!m_decaydescriptor.isIgnoreMassive() and daughtersNetCharge != EvtPDLUtil::charge(m_pdgCode)) {
119 B2FATAL("Your decay string " << m_decayString << " violates electric charge conservation!\n"
120 "If you want to allow this you can set the argument 'allowChargeViolation' to True. Something like:\n"
121 "modularAnalysis.reconstructDecay(" << m_decayString << ", your_cuts, allowChargeViolation=True, path=mypath)");
122 }
123 B2WARNING("Your decay string " << m_decayString << " violates electric charge conservation!\n"
124 "Processing is continued assuming that you allowed this deliberately, e.g. for systematic studies etc.");
125 }
126
127 if (m_recoilParticleType == 0) {
128 m_generator = std::make_unique<ParticleGenerator>(m_decayString, m_cutParameter);
129 } else {
130 string noCutInParticleCombiner = "";
131 m_generator = std::make_unique<ParticleGenerator>(m_decayString, noCutInParticleCombiner);
133 }
134
136 m_outputList.registerInDataStore(m_listName, flags);
138 m_outputAntiList.registerInDataStore(m_antiListName, flags);
139 }
140
142 B2FATAL("Invalid recoil particle type = " << m_recoilParticleType <<
143 "! Valid values are 0 (not a recoil), 1 (recoiling against e+e- and daughters), 2 (daughter of a recoil)");
144}
145
147{
148 m_outputList.create();
149 m_outputList->initialize(m_pdgCode, m_listName);
150
152 m_outputAntiList.create();
153 m_outputAntiList->initialize(-1 * m_pdgCode, m_antiListName);
154
155 m_outputList->bindAntiParticleList(*(m_outputAntiList));
156 }
157
158 m_generator->init();
159
160 int numberOfCandidates = 0;
161 while (m_generator->loadNext(m_chargeConjugation)) {
162
163 Particle&& particle = m_generator->getCurrentParticle();
164
165 // if particle is reconstructed in the recoil,
166 // its 4-momentum vector needs to be fixed
167 // at this stage its 4 momentum is:
168 // p(mother) = Sum_i p(daughter_i)
169 // but it needs to be
170 // a) in the case of recoilParticleType == 1
171 // - p(mother) = p(e-) + p(e+) - Sum_i p(daughter_i)
172 // b) in the case of recoilParticleType == 2
173 // - p(mother) = p(daughter_0) - Sum_i p(daughter_i) (where i > 0)
174 if (m_recoilParticleType == 1) {
176 ROOT::Math::PxPyPzEVector recoilMomentum = T.getBeamFourMomentum() - particle.get4Vector();
177 particle.set4Vector(recoilMomentum);
178 } else if (m_recoilParticleType == 2) {
179 const std::vector<Particle*> daughters = particle.getDaughters();
180
181 if (daughters.size() < 2)
182 B2FATAL("Reconstructing particle as a daughter of a recoil with less then 2 daughters!");
183
184 ROOT::Math::PxPyPzEVector pDaughters;
185 for (unsigned i = 1; i < daughters.size(); i++) {
186 pDaughters += daughters[i]->get4Vector();
187 }
188
189 ROOT::Math::PxPyPzEVector mom = daughters[0]->get4Vector() - pDaughters;
190 particle.set4Vector(mom);
191 }
192 if (m_recoilParticleType > 0) {
193 if (!m_cut->check(&particle)) {
194 continue;
195 }
196 }
197
198 numberOfCandidates++;
199
200 if (m_maximumNumberOfCandidates > 0 and numberOfCandidates > m_maximumNumberOfCandidates) {
202 B2WARNING("Maximum number of " << m_maximumNumberOfCandidates << " candidates reached, skipping event");
203 m_outputList->clear();
204 } else {
205 B2WARNING("Maximum number of " << m_maximumNumberOfCandidates << " candidates reached. Ignoring others");
206 }
207 break;
208 }
209
210 Particle* newParticle = m_particles.appendNew(particle);
211
212 m_outputList->addParticle(newParticle);
213
214 // append to the created particle the user specified decay mode ID
215 newParticle->addExtraInfo("decayModeID", m_decayModeID);
216 }
217}
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.
bool isIgnoreMassive() const
Check if missing massive final state particles shall be ignored.
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
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 hold Lorentz transformations from/to CMS and boost vector.
ROOT::Math::PxPyPzEVector getBeamFourMomentum() const
Returns LAB four-momentum of e+e-, i.e.
int m_recoilParticleType
type of recoil particle: 0 - not recoil (normal reconstruction); 1 - recoil against e+e- and all daug...
bool m_isSelfConjugatedParticle
flag that indicates whether an anti-particle mother does not exist and should not be reconstructed as...
int m_maximumNumberOfCandidates
maximum number of reconstructed candidates
std::string m_antiListName
output anti-particle list name
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
std::string m_decayString
Input DecayString specifying the decay being reconstructed.
std::string m_listName
output particle list name
StoreObjPtr< ParticleList > m_outputAntiList
output anti-particle list
StoreArray< Particle > m_particles
StoreArray of Particles.
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
int m_decayModeID
user specified decay mode identifier
bool m_allowChargeViolation
switch to turn on and off the requirement of electric charge conservation
std::string m_cutParameter
selection criteria
DecayDescriptor m_decaydescriptor
Decay descriptor of the decay being reconstructed.
bool m_writeOut
toggle output particle list btw.
bool m_ignoreIfTooManyCandidates
drop all candidates if max.
int m_pdgCode
PDG code of the combined mother particle.
bool m_chargeConjugation
boolean to control whether charge conjugated decay should be reconstructed as well
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
ROOT::Math::PxPyPzEVector get4Vector() const
Returns Lorentz vector.
Definition: Particle.h:547
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
double charge(int pdgCode)
Returns electric charge of a particle with given pdg code.
Definition: EvtPDLUtil.cc:44
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.