Belle II Software light-2406-ragdoll
ParticleMassHypothesesUpdaterModule.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#include <analysis/DecayDescriptor/DecayDescriptor.h>
10#include <analysis/DecayDescriptor/ParticleListName.h>
11#include <analysis/dataobjects/ParticleList.h>
12#include <analysis/modules/ParticleMassHypothesesUpdater/ParticleMassHypothesesUpdaterModule.h>
13#include <analysis/utility/ParticleCopy.h>
14#include <framework/datastore/StoreObjPtr.h>
15#include <framework/gearbox/Const.h>
16#include <TDatabasePDG.h>
17
18#include <map>
19
20using namespace std;
21using namespace Belle2;
22
23// Register module in the framework
24REG_MODULE(ParticleMassHypothesesUpdater);
25
27{
28 // Set module properties
29 setDescription("This module updates the mass hypothesis of particleList to pdgCode. "
30 "The module creates a new particle list containing copies of the original particles, with updated mass hypotheses. "
31 "The newly created particle list is named after the input one plus the suffix ``_converted_from_`` and the old mass hypothesis, "
32 "e.g. ``e+:mylist`` to pdgCode = 13 becomes ``mu+:mylist_converted_from_e``. "
33 "The only supported mass hypotheses are electrons, muons, kaons, pions and protons (for both input and output lists).");
35 // Parameter definition
36 addParam("particleList", m_particleList, "Input ParticleList", string());
37 addParam("pdgCode", m_newPdgCode, "Target PDG code for mass reference.", Const::electron.getPDGCode());
38 addParam("writeOut", m_writeOut,
39 "If true, the output ParticleList will be saved by RootOutput. If false, it will be ignored when writing the file.", false);
40}
41
43{
45
46 DecayDescriptor decayDescriptor;
47 const bool valid = decayDescriptor.init(m_particleList);
48 if (!valid)
49 B2FATAL("ParticleMassHypothesesUpdaterModule::initialize Invalid input DecayString: " << m_particleList);
50
51 map<int, string> allowedPDGs = {
52 {11, "e"}, {13, "mu"}, {211, "pi"}, {321, "K"}, {2212, "p"}
53 };
54
55 const DecayDescriptorParticle* mother = decayDescriptor.getMother();
56 int pdgCode = mother->getPDGCode();
57 if (allowedPDGs.find(abs(pdgCode)) == allowedPDGs.end())
58 B2FATAL("ParticleMassHypothesesUpdaterModule::initialize Chosen particle list contains unsupported particles with PDG code " <<
59 pdgCode);
60 if (allowedPDGs.find(m_newPdgCode) == allowedPDGs.end())
61 B2FATAL("ParticleMassHypothesesUpdaterModule::initialize Chosen target PDG code " << m_newPdgCode << " not supported.");
62
63 string label = mother->getLabel();
64 string pName = mother->getName();
65 pName.pop_back();
66 m_newParticleList = allowedPDGs[m_newPdgCode] + "+:" + label + "_converted_from_" + pName;
67
69
71 newList.registerInDataStore(flags);
72
75 antiParticleList.registerInDataStore(flags);
76}
77
79{
81 if (!originalList) {
82 B2ERROR("ParticleList " << m_particleList << " not found");
83 return;
84 }
85 if (originalList->getListSize() == 0) // Do nothing if empty
86 return;
87
88 DecayDescriptor newDecayDescriptor;
89 const bool valid = newDecayDescriptor.init(m_newParticleList);
90 if (!valid)
91 B2FATAL("ParticleMassHypothesesUpdaterModule::initialize Invalid input DecayString: " << m_newParticleList);
92
93 const DecayDescriptorParticle* newMother = newDecayDescriptor.getMother();
94 m_newPdgCode = newMother->getPDGCode(); // Get the right sign
95
97 if (newList.isValid()) { // Check whether it already exists in this path
98 B2WARNING("The new particle list already exists, and it should not. Did you call the module twice?");
99 return;
100 }
101
102 newList.create(); // Create and initialize the list
103 newList->initialize(m_newPdgCode, m_newParticleList);
104
106 if (newAntiList.isValid()) // Check whether it already exists in this path
107 B2ERROR("The particle list did not exist but the anti-list did. Something fishy is happening.");
108
109 newAntiList.create(); // Create and initialize the list
110 newAntiList->initialize(-1 * m_newPdgCode, m_newAntiParticleList);
111 newAntiList->bindAntiParticleList(*(newList));
112
113 for (unsigned int i = 0; i < originalList->getListSize(); ++i) {
114 const Particle* originalParticle = originalList->getParticle(i); // Get particle and check it comes from a track
115 if (originalParticle->getParticleSource() != Particle::c_Track) {
116 B2WARNING("Particle not built from a track. Skipping.");
117 continue;
118 }
119
120 Particle* newPart = ParticleCopy::copyParticle(originalParticle);
121 newPart->updateMass(m_newPdgCode);
122 const int charge = newPart->getCharge();
123 if (TDatabasePDG::Instance()->GetParticle(m_newPdgCode)->Charge() / 3.0 == charge)
124 newPart->setPDGCode(m_newPdgCode);
125 else
126 newPart->setPDGCode(-1 * m_newPdgCode);
127
128 newList->addParticle(newPart); // Add particle to list
129 } // Close loop over tracks
130}
131
static const ChargedStable electron
electron particle
Definition: Const.h:659
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 getName() const
evt.pdl name of the particle.
std::string getLabel() const
The label of this particle, "default" returned, when no label set.
The DecayDescriptor stores information about a decay tree or parts of a decay tree.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
const DecayDescriptorParticle * getMother() const
return mother.
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
virtual void initialize() override
Initialises the module.
virtual void event() override
Method called for each event.
virtual void terminate() override
Write TTree to file, and close file if necessary.
std::string m_newAntiParticleList
Name of the new created anti-list.
std::string m_newParticleList
Name of the new created list.
Class to store reconstructed particles.
Definition: Particle.h:75
double getCharge(void) const
Returns particle charge.
Definition: Particle.cc:622
void updateMass(const int pdgCode)
Updates particle mass with the mass of the particle corresponding to the given PDG.
Definition: Particle.cc:597
void setPDGCode(const int pdg)
Sets PDG code.
Definition: Particle.h:262
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:111
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
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:18
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.