Belle II Software  release-06-02-00
AllParticleCombinerModule.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/modules/AllParticleCombiner/AllParticleCombinerModule.h>
10 #include <analysis/DecayDescriptor/ParticleListName.h>
11 
12 using namespace Belle2;
13 
14 //-----------------------------------------------------------------
15 // Register the Module
16 //-----------------------------------------------------------------
17 REG_MODULE(AllParticleCombiner)
18 
19 //-----------------------------------------------------------------
20 // Implementation
21 //-----------------------------------------------------------------
22 
24 {
25  // Set module properties
26  setDescription(R"DOC("This module combines all particles of the provided list to one mother particle.
27  )DOC");
28 
29  // Parameter definitions
30  addParam("inputListNames", m_inputListNames, "List of ParticleLists which are supposed to be combined", std::vector<std::string>());
31  addParam("cut", m_cutString, "Selection criteria for the output ParticleList", std::string(""));
32  addParam("writeOut", m_writeOut,
33  "If true, the output ParticleList will be saved by RootOutput. If false, it will be ignored when writing the file.", false);
34  addParam("outputListName", m_outputListName,
35  "Name of the output list created by the combination of all particles in the input lists.", std::string(""));
36 
37  // initializing the rest of private members
38  m_pdgCode = 0;
39  m_isSelfConjugatedParticle = 0;
40 }
41 
43 {
44  m_particles.isRequired();
45 
47  if (!valid)
48  B2ERROR("Invalid output ListName: " << m_outputListName);
49 
50  // Mother particle
52 
53  m_pdgCode = mother->getPDGCode();
56 
58  m_outputList.registerInDataStore(m_outputListName, flags);
60  m_outputAntiList.registerInDataStore(m_antiListName, flags);
61  }
62 
64 }
65 
67 {
68  m_outputList.create();
70 
72  m_outputAntiList.create();
73  m_outputAntiList->initialize(-1 * m_pdgCode, m_antiListName);
74 
75  m_outputList->bindAntiParticleList(*(m_outputAntiList));
76  }
77 
78  unsigned short nParticleLists = m_inputListNames.size();
79  if (nParticleLists == 0)
80  B2ERROR("No particle lists found for AllParticleCombinerModule.");
81 
82  double px = 0;
83  double py = 0;
84  double pz = 0;
85  double E = 0;
86  std::vector<int> daughterIndices;
87 
88  for (unsigned short iList = 0; iList < nParticleLists; ++iList) {
89 
91  for (unsigned int i = 0; i < plist->getListSize(); ++i) {
92  bool addParticle = true;
93  Particle* particle = plist->getParticle(i, true);
94  for (auto* daughter : particle->getFinalStateDaughters()) {
95  int particleArrayIndex = daughter->getArrayIndex();
96  if (std::find(daughterIndices.begin(), daughterIndices.end(), particleArrayIndex) != daughterIndices.end()) {
97  addParticle = false;
98  break;
99  }
100  }
101  if (addParticle) {
102  for (auto* daughter : particle->getFinalStateDaughters()) {
103  int particleArrayIndex = daughter->getArrayIndex();
104  daughterIndices.push_back(particleArrayIndex);
105  }
106  px += particle->getPx();
107  py += particle->getPy();
108  pz += particle->getPz();
109  E += particle->getEnergy();
110  }
111  }
112  }
113 
114  const TLorentzVector vec(px, py, pz, E);
115 
117  daughterIndices, m_particles.getPtr());
118 
119  Particle* newParticle = m_particles.appendNew(combinedParticle);
120  if (m_cut->check(newParticle)) {
121  m_outputList->addParticle(newParticle);
122  }
123 }
This module combines all particles of the provided list to one mother particle.
bool m_isSelfConjugatedParticle
flag that indicates whether an anti-particle mother does not exist and should not be reconstructed as...
std::string m_antiListName
output anti-particle list name
std::vector< std::string > m_inputListNames
List of ParticleLists which are supposed to be combined.
StoreObjPtr< ParticleList > m_outputAntiList
output anti-particle list
StoreArray< Particle > m_particles
StoreArray of Particle objects.
StoreObjPtr< ParticleList > m_outputList
output particle list
std::string m_cutString
Selection criteria.
std::unique_ptr< Variable::Cut > m_cut
cut object which performs the cuts
virtual void event() override
process event
virtual void initialize() override
Register input and output data.
DecayDescriptor m_decaydescriptor
Decay descriptor of the decay being reconstructed.
bool m_writeOut
If true, the output ParticleList will be saved by RootOutput.
int m_pdgCode
PDG code of the combined mother particle.
std::string m_outputListName
Name of the output list created by the combination of all particles in the input list.
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.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
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:104
Base class for Modules.
Definition: Module.h:72
Class to store reconstructed particles.
Definition: Particle.h:74
@ c_Unflavored
Is its own antiparticle or we don't know whether it is a particle/antiparticle.
Definition: Particle.h:93
@ c_Flavored
Is either particle or antiparticle.
Definition: Particle.h:94
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
std::string antiParticleListName(const std::string &listName)
Returns name of anti-particle-list corresponding to listName.
Abstract base class for different kinds of events.