9#include <analysis/modules/RestOfEventBuilder/RestOfEventBuilderModule.h>
11#include <mdst/dataobjects/MCParticle.h>
13#include <framework/logging/Logger.h>
29 setDescription(
"Creates for each Particle in the given ParticleList a RestOfEvent dataobject and makes basf2 relation between them.");
33 std::vector<std::string> emptyList;
59 B2WARNING(
"*** The ROE for " <<
m_particleListName <<
" list will have KLM energy included into its 4-momentum. ***");
78 B2WARNING(
"ROE list is not valid somehow, nested ROE is not created!");
81 auto outerROEParticles = hostROE->getParticles(
m_nestedMask);
83 for (
unsigned i = 0; i < nParticles; i++) {
86 auto* check_roe = particle->getRelated<
RestOfEvent>();
87 if (check_roe !=
nullptr) {
93 particle->addRelationTo(nestedROE);
95 hostROE->addRelationTo(nestedROE);
96 auto fsdaughters = particle->getFinalStateDaughters();
97 std::vector<const Particle* > particlesToAdd;
98 for (
auto* outerROEParticle : outerROEParticles) {
100 for (
auto* daughter : fsdaughters) {
101 if (outerROEParticle->isCopyOf(daughter,
true)) {
107 particlesToAdd.push_back(outerROEParticle);
117 for (
unsigned i = 0; i < nParts; i++) {
121 auto* check_roe = particle->getRelated<
RestOfEvent>();
122 if (check_roe !=
nullptr)
129 particle->addRelationTo(roe);
138 auto fsdaughters = particle->getFinalStateDaughters();
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());
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) {
151 B2DEBUG(10,
"ParticleList: " << particleListName);
153 int m_part = plist->getListSize();
154 for (
int i = 0; i < m_part; i++) {
155 Particle* storedParticle = plist->getParticle(i);
158 for (
auto* storedParticleDaughter : storedParticleDaughters) {
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");
166 nExcludedParticles++;
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));
175 nExcludedParticles++;
180 particlesToAdd.push_back(storedParticleDaughter);
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");
193 B2INFO(
"[RestOfEventBuilderModule] *** Print Event ***");
194 B2INFO(
"[RestOfEventBuilderModule] Tracks: " <<
m_tracks.getEntries());
195 for (
int i = 0; i <
m_tracks.getEntries(); i++) {
199 if (trackECLCluster) {
200 B2INFO(
"[RestOfEventBuilderModule] -> track " << track->getArrayIndex() <<
" -> ECLCluster " << trackECLCluster->
getArrayIndex());
202 B2INFO(
"[RestOfEventBuilderModule] -> track " << track->getArrayIndex() <<
" -> ECLCluster (NO RELATION)");
204 if (trackKLMCluster) {
205 B2INFO(
"[RestOfEventBuilderModule] -> track " << track->getArrayIndex() <<
" -> KLMCluster " << trackKLMCluster->getArrayIndex());
207 B2INFO(
"[RestOfEventBuilderModule] -> track " << track->getArrayIndex() <<
" -> KLMCluster (NO RELATION)");
211 B2INFO(
"[RestOfEventBuilderModule] ECLCluster: " <<
m_eclClusters.getEntries());
215 B2INFO(
"[RestOfEventBuilderModule] -> cluster " << eclCluster->
getArrayIndex());
218 B2INFO(
"[RestOfEventBuilderModule] KLMCluster: " <<
m_klmClusters.getEntries());
222 B2INFO(
"[RestOfEventBuilderModule] -> cluster " << klmCluster->
getArrayIndex());
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);
232 B2INFO(
"[RestOfEventBuilderModule] tracks : ");
234 std::string printout;
235 for (
int trackFSP : trackFSPs)
236 printout += std::to_string(trackFSP) +
" ";
241 B2INFO(
"[RestOfEventBuilderModule] eclFSPs : ");
242 for (
int eclFSP : eclFSPs)
243 printout += std::to_string(eclFSP) +
" ";
248 B2INFO(
"[RestOfEventBuilderModule] klmFSPs : ");
249 for (
int klmFSP : klmFSPs)
250 printout += std::to_string(klmFSP) +
" ";
@ c_PrimaryParticle
bit 0: Particle is primary particle.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Class to store reconstructed particles.
std::vector< const Belle2::Particle * > getFinalStateDaughters() const
Returns a vector of pointers to Final State daughter particles.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
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.
void createNestedROE()
create nested ROE
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...
void addParticles(const std::vector< const Particle * > &particle)
Add StoreArray indices of given Particles to the list of unused particles in the event.
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.
Type-safe access to single objects in the data store.
bool isValid() const
Check whether the object was created.
Class that bundles various TrackFitResults.
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.
Abstract base class for different kinds of events.