9 #include <analysis/modules/MCDecayFinder/MCDecayFinderModule.h>
10 #include <framework/gearbox/Const.h>
11 #include <analysis/DecayDescriptor/ParticleListName.h>
12 #include <analysis/utility/EvtPDLUtil.h>
13 #include <analysis/utility/MCMatching.h>
24 MCDecayFinderModule::MCDecayFinderModule() :
Module(), m_isSelfConjugatedParticle(false)
27 setDescription(
"Find decays in MCParticle list matching a given DecayString and create Particles from them.");
32 "If true, the output ParticleList will be saved by RootOutput. If false, it will be ignored when writing the file.",
false);
42 B2DEBUG(10,
"particle list name: " <<
m_listName);
74 for (
int i = 0; i < nMCParticles; i++) {
75 for (
int iCC = 0; iCC < 2; iCC++) {
77 if (decay->getObj()) {
78 B2DEBUG(19,
"Match!");
79 int iIndex =
write(decay.get());
101 if (!isCC && iPDGD != iPDGP)
return decay;
102 else if (isCC && (iPDGD != -iPDGP && !isSelfConjugatedParticle))
return decay;
103 else if (isCC && (iPDGD != iPDGP && isSelfConjugatedParticle))
return decay;
104 B2DEBUG(19,
"PDG code matched: " << iPDGP);
109 if (nDaughtersD == 0) {
110 B2DEBUG(19,
"DecayDescriptor has no Daughters, everything OK!");
115 int nDaughtersRecursiveD = nDaughtersD;
121 vector<const MCParticle*> daughtersP;
125 const vector<MCParticle*>& tmpDaughtersP = mcp->
getDaughters();
126 for (
auto daug : tmpDaughtersP)
127 daughtersP.push_back(daug);
131 int nDaughtersP = daughtersP.size();
132 if (nDaughtersRecursiveD > nDaughtersP) {
133 B2DEBUG(10,
"DecayDescriptor has more daughters than MCParticle!");
138 for (
int iDD = 0; iDD < nDaughtersD; iDD++) {
140 bool isMatchDaughter =
false;
141 auto itDP = daughtersP.begin();
142 while (itDP != daughtersP.end()) {
145 if (!daughter->getObj()) {
150 decay->append(daughter);
151 isMatchDaughter =
true;
152 itDP = daughtersP.erase(itDP);
156 vector<const MCParticle*> grandDaughtersP;
160 const vector<MCParticle*>& tmpGrandDaughtersP = daugP->
getDaughters();
161 for (
auto grandDaugP : tmpGrandDaughtersP)
162 grandDaughtersP.push_back(grandDaugP);
165 for (
auto grandDaugP : grandDaughtersP) {
167 while (jtDP != daughtersP.end()) {
170 if (grandDaugP == daugP_j)
171 jtDP = daughtersP.erase(jtDP);
180 if (!isMatchDaughter) {
189 B2DEBUG(10,
"Check for left over MCParticles!\n");
190 for (
auto daugP : daughtersP) {
199 }
else if ((abs(daugP->getPDG()) == 12 or abs(daugP->getPDG()) == 14 or abs(daugP->getPDG()) == 16)) {
206 B2DEBUG(10,
"There was an additional particle left. Found " << daugP->getPDG());
211 B2DEBUG(19,
"Match found!");
225 vector< DecayTree<MCParticle>* > daughters = decay->
getDaughters();
226 int nDaughers = daughters.size();
227 for (
int i = 0; i < nDaughers; ++i) {
228 int iIndexDaughter =
write(daughters[i]);
239 const vector<MCParticle*>& genDaughters = gen->
getDaughters();
240 for (
auto daug : genDaughters) {
241 children.push_back(daug);
249 if (nDaughter == 0)
return nDaughter;
251 int nDaughterRecursive = nDaughter;
252 for (
int iDaug = 0; iDaug < nDaughter; iDaug++) {
258 return nDaughterRecursive;
int getPDGCode() const
PDG code.
static const ParticleType photon
photon particle
EStoreFlags
Flags describing behaviours of objects etc.
@ c_WriteOut
Object/array should be saved by output modules.
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
int getPDGCode() const
Return PDG code.
The DecayDescriptor stores information about a decay tree or parts of a decay tree.
bool isIgnoreRadiatedPhotons() const
Check if additional radiated photons shall be ignored.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
const DecayDescriptorParticle * getMother() const
return mother.
bool isIgnoreNeutrino() const
Check if missing neutrinos shall be ignored.
int getNDaughters() const
return number of direct daughters.
bool isIgnoreMassive() const
Check if missing massive final state particles shall be ignored.
const DecayDescriptor * getDaughter(int i) const
return i-th daughter (0 based index).
bool isIgnoreGamma() const
Check if missing gammas shall be ignored.
bool isIgnoreIntermediate() const
Check if intermediate resonances/particles shall be ignored.
This is a helper class for the MCDecayFinderModule.
bool m_isSelfConjugatedParticle
Is the particle list for a self-conjugated particle.
std::string m_antiListName
Name of output anti-particle list.
int getNDaughtersRecursive(const DecayDescriptor *d)
Recursively get number of daughters of given DecayDescriptor.
virtual void initialize() override
Initialises the module.
virtual void event() override
Method called for each event.
StoreArray< MCParticle > m_mcparticles
StoreArray of MCParticles.
std::string m_listName
Name of output particle list.
StoreArray< Particle > m_particles
StoreArray of Particles.
int write(DecayTree< MCParticle > *decay)
Create Particle from matched MCParticle and write to Particle list.
StoreObjPtr< ParticleList > m_outputList
output particle list
std::string m_strDecay
Decay string to build the decay descriptor.
void appendParticles(const MCParticle *gen, std::vector< const MCParticle * > &children)
Recursively gather all MC daughters of gen.
DecayTree< MCParticle > * match(const MCParticle *mcp, const DecayDescriptor *d, bool isCC)
Search for MCParticles matching the given DecayString.
StoreObjPtr< ParticleList > m_antiOutputList
output anti-particle list
DecayDescriptor m_decaydescriptor
Decay descriptor of decays to look for.
bool m_writeOut
toggle output particle list btw.
StoreObjPtr< ParticleExtraInfoMap > m_extraInfoMap
object pointer to ParticleExtraInfoMaps
A Class to store the Monte Carlo particle information.
@ c_IsPHOTOSPhoton
bit 8: Particle is an radiative photon from PHOTOS
std::vector< Belle2::MCParticle * > getDaughters() const
Get vector of all daughter particles, empty vector if none.
int getPDG() const
Return PDG code of particle.
void setDescription(const std::string &description)
Sets the description of the module.
Class to store reconstructed particles.
void appendDaughter(const Particle *daughter, const bool updateType=true)
Appends index of daughter to daughters index array.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
T * getObj()
Return the decaying object itself, e.g.
std::vector< DecayTree< T > * > getDaughters()
Return list of decay daughters.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
bool hasAntiParticle(int pdgCode)
Checks if the particle with given pdg code has an anti-particle or not.
std::string antiParticleListName(const std::string &listName)
Returns name of anti-particle-list corresponding to listName.
Abstract base class for different kinds of events.
static bool isFSR(const Belle2::MCParticle *p)
Returns true if given MCParticle is a final state radiation (FSR) photon based on MCParticle::c_IsFSR...
static bool isFSP(int pdg)
Returns true if given PDG code indicates a FSP.