Belle II Software light-2406-ragdoll
RestOfEventBuilderModule.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/RestOfEventBuilder/RestOfEventBuilderModule.h>
10
11#include <mdst/dataobjects/MCParticle.h>
12
13#include <framework/logging/Logger.h>
14
15using namespace Belle2;
16
17//-----------------------------------------------------------------
18// Register the Module
19//-----------------------------------------------------------------
20REG_MODULE(RestOfEventBuilder);
21
22//-----------------------------------------------------------------
23// Implementation
24//-----------------------------------------------------------------
25
27{
28 // Set module properties
29 setDescription("Creates for each Particle in the given ParticleList a RestOfEvent dataobject and makes basf2 relation between them.");
31
32 // Parameter definitions
33 std::vector<std::string> emptyList;
34 addParam("particleList", m_particleListName, "Name of the ParticleList");
35 addParam("particleListsInput", m_particleListsInput, "List of the particle lists, which serve as a source of particles", emptyList);
36 addParam("createNestedROE", m_createNestedROE, "A switch to create nested ROE", false);
37 addParam("nestedROEMask", m_nestedMask, "A switch to create nested ROE", std::string(""));
38 addParam("fromMC", m_fromMC, "A switch to create MC ROE", false);
39 addParam("useKLMEnergy", m_useKLMEnergy, "A switch to create ROE with KLM energy included", false);
40 addParam("mostLikely", m_builtWithMostLikely, "whether input particle lists contain most-likely lists", true);
41 m_nestedROEArrayName = "NestedRestOfEvents";
42}
43
45{
46 // input
49
50 // output
51 m_roeArray.registerInDataStore();
54 m_nestedROEArray.registerInDataStore(m_nestedROEArrayName);
56 m_roeArray.registerRelationTo(m_nestedROEArray);
57 }
58 if (m_useKLMEnergy) {
59 B2WARNING("*** The ROE for " << m_particleListName << " list will have KLM energy included into its 4-momentum. ***");
60 }
61}
62
64{
65 if (!m_createNestedROE) {
66 createROE();
67 } else {
69 }
70
71}
72
74{
75 // input target Particle
76 StoreObjPtr<RestOfEvent> hostROE("RestOfEvent");
77 if (!hostROE.isValid()) {
78 B2WARNING("ROE list is not valid somehow, nested ROE is not created!");
79 return;
80 }
81 auto outerROEParticles = hostROE->getParticles(m_nestedMask);
82 unsigned int nParticles = m_particleList->getListSize();
83 for (unsigned i = 0; i < nParticles; i++) {
84 const Particle* particle = m_particleList->getParticle(i);
85 // check if a Particle object is already related to a RestOfEvent object
86 auto* check_roe = particle->getRelated<RestOfEvent>();
87 if (check_roe != nullptr) {
88 return;
89 }
90 // create nested RestOfEvent object:
91 RestOfEvent* nestedROE = m_nestedROEArray.appendNew(particle->getPDGCode(), true);
92 // create relation: Particle <-> RestOfEvent
93 particle->addRelationTo(nestedROE);
94 // create relation: host ROE <-> nested ROE
95 hostROE->addRelationTo(nestedROE);
96 auto fsdaughters = particle->getFinalStateDaughters();
97 std::vector<const Particle* > particlesToAdd;
98 for (auto* outerROEParticle : outerROEParticles) {
99 bool toAdd = true;
100 for (auto* daughter : fsdaughters) {
101 if (outerROEParticle->isCopyOf(daughter, true)) {
102 toAdd = false;
103 break;
104 }
105 }
106 if (toAdd) {
107 particlesToAdd.push_back(outerROEParticle);
108 }
109 }
110 nestedROE->addParticles(particlesToAdd);
111 }
112}
113
115{
116 unsigned int nParts = m_particleList->getListSize();
117 for (unsigned i = 0; i < nParts; i++) {
118 const Particle* particle = m_particleList->getParticle(i);
119
120 // check if a Particle object is already related to a RestOfEvent object
121 auto* check_roe = particle->getRelated<RestOfEvent>();
122 if (check_roe != nullptr)
123 return;
124
125 // create RestOfEvent object
126 RestOfEvent* roe = m_roeArray.appendNew(particle->getPDGCode(), false, m_fromMC, m_useKLMEnergy, m_builtWithMostLikely);
127
128 // create relation: Particle <-> RestOfEvent
129 particle->addRelationTo(roe);
130
131 // fill RestOfEvent with content
132 addRemainingParticles(particle, roe);
133 }
134}
135
137{
138 auto fsdaughters = particle->getFinalStateDaughters();
139 int nParticleLists = m_particleListsInput.size();
140 B2DEBUG(10, "Particle has " + std::to_string(fsdaughters.size()) + " daughters");
141 for (auto* daughter : fsdaughters) {
142 B2DEBUG(10, "\t" << daughter->getArrayIndex() << ": pdg " << daughter->getPDGCode());
143 B2DEBUG(10, "\t\t Store array particle: " << m_particles[daughter->getArrayIndex()]->getPDGCode());
144 }
145 unsigned int nExcludedParticles = 0;
146 std::vector<const Particle* > particlesToAdd;
147 B2DEBUG(10, "nLists: " << nParticleLists);
148 for (int i_pl = 0; i_pl != nParticleLists; ++i_pl) {
149
150 std::string particleListName = m_particleListsInput[i_pl];
151 B2DEBUG(10, "ParticleList: " << particleListName);
152 StoreObjPtr<ParticleList> plist(particleListName);
153 int m_part = plist->getListSize();
154 for (int i = 0; i < m_part; i++) {
155 Particle* storedParticle = plist->getParticle(i);
156
157 std::vector<const Particle*> storedParticleDaughters = storedParticle->getFinalStateDaughters();
158 for (auto* storedParticleDaughter : storedParticleDaughters) {
159 bool toAdd = true;
160 if ((m_fromMC and storedParticleDaughter->getParticleSource() != Particle::EParticleSourceObject::c_MCParticle)
161 or (!m_fromMC and storedParticleDaughter->getParticleSource() == Particle::EParticleSourceObject::c_MCParticle)) {
162 B2FATAL("The value of fromMC parameter is not consisted with the type of provided particles, MC vs Reco");
163 }
164 // Remove non primary MCParticles
165 if (m_fromMC and !storedParticleDaughter->getMCParticle()->hasStatus(MCParticle::c_PrimaryParticle)) {
166 nExcludedParticles++;
167 continue;
168 }
169 for (auto* daughter : fsdaughters) {
170 if (storedParticleDaughter->isCopyOf(daughter, true)) {
171 B2DEBUG(10, "Ignoring Particle with PDG " << daughter->getPDGCode() << " index " <<
172 storedParticleDaughter->getArrayIndex() << " to " << daughter->getArrayIndex());
173 B2DEBUG(10, "Is copy " << storedParticleDaughter->isCopyOf(daughter));
174 toAdd = false;
175 nExcludedParticles++;
176 break;
177 }
178 }
179 if (toAdd) {
180 particlesToAdd.push_back(storedParticleDaughter);
181 }
182 }
183 }
184 }
185 if (fsdaughters.size() > nExcludedParticles) {
186 B2WARNING("Number of excluded particles do not coincide with the number of target FSP daughters! Provided lists must be incomplete");
187 }
188 roe->addParticles(particlesToAdd);
189}
190
192{
193 B2INFO("[RestOfEventBuilderModule] *** Print Event ***");
194 B2INFO("[RestOfEventBuilderModule] Tracks: " << m_tracks.getEntries());
195 for (int i = 0; i < m_tracks.getEntries(); i++) {
196 const Track* track = m_tracks[i];
197 const ECLCluster* trackECLCluster = track->getRelated<ECLCluster>();
198 const KLMCluster* trackKLMCluster = track->getRelated<KLMCluster>();
199 if (trackECLCluster) {
200 B2INFO("[RestOfEventBuilderModule] -> track " << track->getArrayIndex() << " -> ECLCluster " << trackECLCluster->getArrayIndex());
201 } else {
202 B2INFO("[RestOfEventBuilderModule] -> track " << track->getArrayIndex() << " -> ECLCluster (NO RELATION)");
203 }
204 if (trackKLMCluster) {
205 B2INFO("[RestOfEventBuilderModule] -> track " << track->getArrayIndex() << " -> KLMCluster " << trackKLMCluster->getArrayIndex());
206 } else {
207 B2INFO("[RestOfEventBuilderModule] -> track " << track->getArrayIndex() << " -> KLMCluster (NO RELATION)");
208 }
209 }
210
211 B2INFO("[RestOfEventBuilderModule] ECLCluster: " << m_eclClusters.getEntries());
212 for (int i = 0; i < m_eclClusters.getEntries(); i++) {
213 const ECLCluster* eclCluster = m_eclClusters[i];
214
215 B2INFO("[RestOfEventBuilderModule] -> cluster " << eclCluster->getArrayIndex());
216 }
217
218 B2INFO("[RestOfEventBuilderModule] KLMCluster: " << m_klmClusters.getEntries());
219 for (int i = 0; i < m_klmClusters.getEntries(); i++) {
220 const KLMCluster* klmCluster = m_klmClusters[i];
221
222 B2INFO("[RestOfEventBuilderModule] -> cluster " << klmCluster->getArrayIndex());
223 }
224}
225
227{
228 std::vector<int> eclFSPs = particle->getMdstArrayIndices(Particle::EParticleSourceObject::c_ECLCluster);
229 std::vector<int> klmFSPs = particle->getMdstArrayIndices(Particle::EParticleSourceObject::c_KLMCluster);
230 std::vector<int> trackFSPs = particle->getMdstArrayIndices(Particle::EParticleSourceObject::c_Track);
231
232 B2INFO("[RestOfEventBuilderModule] tracks : ");
233
234 std::string printout;
235 for (int trackFSP : trackFSPs)
236 printout += std::to_string(trackFSP) + " ";
237 B2INFO(printout);
238
239 printout.clear();
240
241 B2INFO("[RestOfEventBuilderModule] eclFSPs : ");
242 for (int eclFSP : eclFSPs)
243 printout += std::to_string(eclFSP) + " ";
244 B2INFO(printout);
245
246 printout.clear();
247
248 B2INFO("[RestOfEventBuilderModule] klmFSPs : ");
249 for (int klmFSP : klmFSPs)
250 printout += std::to_string(klmFSP) + " ";
251 B2INFO(printout);
252
253}
ECL cluster data.
Definition: ECLCluster.h:27
KLM cluster data.
Definition: KLMCluster.h:28
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:47
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 store reconstructed particles.
Definition: Particle.h:75
std::vector< const Belle2::Particle * > getFinalStateDaughters() const
Returns a vector of pointers to Final State daughter particles.
Definition: Particle.cc:649
std::vector< int > getMdstArrayIndices(EParticleSourceObject type) const
Returns a vector of StoreArray indices of given MDST dataobjects.
Definition: Particle.cc:665
int getPDGCode(void) const
Returns PDG code.
Definition: Particle.h:454
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).
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
StoreArray< RestOfEvent > m_roeArray
StoreArray of ROEs.
void addRemainingParticles(const Particle *particle, RestOfEvent *roe)
Adds all particles from input particle lists that are not used in reconstruction of given particle.
void createROE()
create usual (host) ROE
std::string m_particleListName
Name of the ParticleList.
StoreArray< KLMCluster > m_klmClusters
StoreArray of KLMCluster.
virtual void initialize() override
Overridden initialize method.
bool m_createNestedROE
Should we create nested ROE?
RestOfEventBuilderModule()
Constructor: Sets the description, the properties and the parameters of the module.
virtual void event() override
Overridden event method.
bool m_builtWithMostLikely
Is the ROE built with most-likely particle lists?
StoreArray< Particle > m_particles
StoreArray of Particles.
bool m_fromMC
Should we create MC ROE?
std::string m_nestedROEArrayName
Name of the nested ROE.
void printEvent()
for debugging purposes
StoreArray< Track > m_tracks
StoreArray of Tracks.
std::vector< std::string > m_particleListsInput
Name of the input particle lists of pi+ gamma and Klongs.
void printParticle(const Particle *particle)
for debugging purposes
StoreArray< ECLCluster > m_eclClusters
StoreArray of ECLCluster.
bool m_useKLMEnergy
Should we use KLM energy in ROE?
StoreObjPtr< ParticleList > m_particleList
input particle list
StoreArray< RestOfEvent > m_nestedROEArray
StoreArray of nested ROEs.
std::string m_nestedMask
Name of the ParticleList.
This is a general purpose class for collecting reconstructed MDST data objects that are not used in r...
Definition: RestOfEvent.h:57
void addParticles(const std::vector< const Particle * > &particle)
Add StoreArray indices of given Particles to the list of unused particles in the event.
Definition: RestOfEvent.cc:24
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:140
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
Class that bundles various TrackFitResults.
Definition: Track.h:25
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
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24