Belle II Software  release-05-02-19
AllParticleCombinerModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Frank Meier *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <analysis/modules/AllParticleCombiner/AllParticleCombinerModule.h>
12 #include <analysis/dataobjects/Particle.h>
13 #include <analysis/dataobjects/ParticleList.h>
14 #include <analysis/DecayDescriptor/ParticleListName.h>
15 #include <framework/datastore/StoreArray.h>
16 #include <framework/datastore/StoreObjPtr.h>
17 
18 using namespace Belle2;
19 
20 //-----------------------------------------------------------------
21 // Register the Module
22 //-----------------------------------------------------------------
23 REG_MODULE(AllParticleCombiner)
24 
25 //-----------------------------------------------------------------
26 // Implementation
27 //-----------------------------------------------------------------
28 
30 {
31  // Set module properties
32  setDescription(R"DOC("This module combines all particles of the provided list to one mother particle.
33  )DOC");
34 
35  // Parameter definitions
36  addParam("inputListNames", m_inputListNames, "List of ParticleLists which are supposed to be combined", std::vector<std::string>());
37  addParam("cut", m_cutString, "Selection criteria for the output ParticleList", std::string(""));
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  addParam("outputListName", m_outputListName,
41  "Name of the output list created by the combination of all particles in the input lists.", std::string(""));
42 
43  // initializing the rest of private members
44  m_pdgCode = 0;
45  m_isSelfConjugatedParticle = 0;
46 }
47 
49 {
50  StoreArray<Particle>().isRequired();
51 
53  if (!valid)
54  B2ERROR("Invalid output ListName: " << m_outputListName);
55 
56  // Mother particle
58 
59  m_pdgCode = mother->getPDGCode();
62 
65  particleList.registerInDataStore(flags);
67  StoreObjPtr<ParticleList> antiParticleList(m_antiListName);
68  antiParticleList.registerInDataStore(flags);
69  }
70 
72 }
73 
75 {
76  StoreArray<Particle> particles;
77 
79  outputList.create();
80  outputList->initialize(m_pdgCode, m_outputListName);
81 
84  outputAntiList.create();
85  outputAntiList->initialize(-1 * m_pdgCode, m_antiListName);
86 
87  outputList->bindAntiParticleList(*(outputAntiList));
88  }
89 
90  unsigned short nParticleLists = m_inputListNames.size();
91  if (nParticleLists == 0)
92  B2ERROR("No particle lists found for AllParticleCombinerModule.");
93 
94  double px = 0;
95  double py = 0;
96  double pz = 0;
97  double E = 0;
98  std::vector<int> daughterIndices;
99 
100  for (unsigned short iList = 0; iList < nParticleLists; ++iList) {
101 
103  for (unsigned int i = 0; i < plist->getListSize(); ++i) {
104  bool addParticle = true;
105  Particle* particle = plist->getParticle(i, true);
106  for (auto* daughter : particle->getFinalStateDaughters()) {
107  int particleArrayIndex = daughter->getArrayIndex();
108  if (std::find(daughterIndices.begin(), daughterIndices.end(), particleArrayIndex) != daughterIndices.end()) {
109  addParticle = false;
110  break;
111  }
112  }
113  if (addParticle) {
114  for (auto* daughter : particle->getFinalStateDaughters()) {
115  int particleArrayIndex = daughter->getArrayIndex();
116  daughterIndices.push_back(particleArrayIndex);
117  }
118  px += particle->getPx();
119  py += particle->getPy();
120  pz += particle->getPz();
121  E += particle->getEnergy();
122  }
123  }
124  }
125 
126  const TLorentzVector vec(px, py, pz, E);
127 
129  daughterIndices, particles.getPtr());
130 
131  Particle* newParticle = particles.appendNew(combinedParticle);
132  if (m_cut->check(newParticle)) {
133  outputList->addParticle(newParticle);
134  }
135 }
Belle2::GeneralCut::compile
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:114
Belle2::AllParticleCombinerModule::m_decaydescriptor
DecayDescriptor m_decaydescriptor
Decay descriptor of the decay being reconstructed.
Definition: AllParticleCombinerModule.h:64
Belle2::AllParticleCombinerModule::m_inputListNames
std::vector< std::string > m_inputListNames
List of ParticleLists which are supposed to be combined.
Definition: AllParticleCombinerModule.h:54
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::AllParticleCombinerModule
This module combines all particles of the provided list to one mother particle.
Definition: AllParticleCombinerModule.h:36
Belle2::DataStore::EStoreFlags
EStoreFlags
Flags describing behaviours of objects etc.
Definition: DataStore.h:71
Belle2::AllParticleCombinerModule::m_writeOut
bool m_writeOut
If true, the output ParticleList will be saved by RootOutput.
Definition: AllParticleCombinerModule.h:60
Belle2::DecayDescriptorParticle
Represents a particle in the DecayDescriptor.
Definition: DecayDescriptorParticle.h:37
Belle2::DataStore::c_DontWriteOut
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:73
Belle2::DecayDescriptor::init
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
Definition: DecayDescriptor.cc:47
Belle2::AllParticleCombinerModule::m_outputListName
std::string m_outputListName
Name of the output list created by the combination of all particles in the input list.
Definition: AllParticleCombinerModule.h:62
Belle2::ParticleListName::antiParticleListName
std::string antiParticleListName(const std::string &listName)
Returns name of anti-particle-list corresponding to listName.
Definition: ParticleListName.cc:10
Belle2::AllParticleCombinerModule::m_isSelfConjugatedParticle
bool m_isSelfConjugatedParticle
flag that indicates whether an anti-particle mother does not exist and should not be reconstructed as...
Definition: AllParticleCombinerModule.h:56
Belle2::Particle::c_Flavored
@ c_Flavored
Is either particle or antiparticle.
Definition: Particle.h:97
Belle2::DataStore::c_WriteOut
@ c_WriteOut
Object/array should be saved by output modules.
Definition: DataStore.h:72
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::AllParticleCombinerModule::event
virtual void event() override
process event
Belle2::AllParticleCombinerModule::m_cutString
std::string m_cutString
Selection criteria.
Definition: AllParticleCombinerModule.h:58
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::c_Unflavored
@ c_Unflavored
Is its own antiparticle or we don't know whether it is a particle/antiparticle.
Definition: Particle.h:96
Belle2::Particle
Class to store reconstructed particles.
Definition: Particle.h:77
Belle2::AllParticleCombinerModule::initialize
virtual void initialize() override
Register input and output data.
Belle2::AllParticleCombinerModule::m_antiListName
std::string m_antiListName
output anti-particle list name
Definition: AllParticleCombinerModule.h:63
Belle2::StoreArray< Particle >
Belle2::DecayDescriptor::getMother
const DecayDescriptorParticle * getMother() const
return mother.
Definition: DecayDescriptor.h:136
Belle2::AllParticleCombinerModule::m_cut
std::unique_ptr< Variable::Cut > m_cut
cut object which performs the cuts
Definition: AllParticleCombinerModule.h:59
Belle2::AllParticleCombinerModule::m_pdgCode
int m_pdgCode
PDG code of the combined mother particle.
Definition: AllParticleCombinerModule.h:65