11 #include <analysis/modules/RestOfEventBuilder/RestOfEventBuilderModule.h>
13 #include <analysis/dataobjects/ParticleList.h>
14 #include <analysis/dataobjects/Particle.h>
15 #include <mdst/dataobjects/MCParticle.h>
17 #include <mdst/dataobjects/Track.h>
18 #include <mdst/dataobjects/ECLCluster.h>
19 #include <mdst/dataobjects/KLMCluster.h>
21 #include <framework/datastore/StoreArray.h>
22 #include <framework/datastore/StoreObjPtr.h>
24 #include <framework/logging/Logger.h>
40 setDescription(
"Creates for each Particle in the given ParticleList a RestOfEvent dataobject and makes BASF2 relation between them.");
41 setPropertyFlags(c_ParallelProcessingCertified);
44 std::vector<std::string> emptyList;
45 addParam(
"particleList", m_particleList,
"Name of the ParticleList");
46 addParam(
"particleListsInput", m_particleListsInput,
"List of the particle lists, which serve as a source of particles", emptyList);
47 addParam(
"createNestedROE", m_createNestedROE,
"A switch to create nested ROE",
false);
48 addParam(
"nestedROEMask", m_nestedMask,
"A switch to create nested ROE", std::string(
""));
49 addParam(
"fromMC", m_fromMC,
"A switch to create MC ROE",
false);
50 m_nestedROEArrayName =
"NestedRestOfEvents";
58 particles.isRequired();
62 roeArray.registerInDataStore();
63 particles.registerRelationTo(roeArray);
66 nestedROEArray.registerInDataStore();
67 particles.registerRelationTo(nestedROEArray);
89 B2WARNING(
"ROE list is not valid somehow, nested ROE is not created!");
92 auto outerROEParticles = hostROE->getParticles(
m_nestedMask);
93 unsigned int nParticles = plist->getListSize();
94 for (
unsigned i = 0; i < nParticles; i++) {
95 const Particle* particle = plist->getParticle(i);
97 auto* check_roe = particle->getRelated<
RestOfEvent>();
98 if (check_roe !=
nullptr) {
104 particle->addRelationTo(nestedROE);
106 hostROE->addRelationTo(nestedROE);
107 auto fsdaughters = particle->getFinalStateDaughters();
108 std::vector<const Particle* > particlesToAdd;
109 for (
auto* outerROEParticle : outerROEParticles) {
111 for (
auto* daughter : fsdaughters) {
112 if (outerROEParticle->isCopyOf(daughter,
true)) {
118 particlesToAdd.push_back(outerROEParticle);
132 unsigned int nParts = plist->getListSize();
133 for (
unsigned i = 0; i < nParts; i++) {
134 const Particle* particle = plist->getParticle(i);
137 auto* check_roe = particle->getRelated<
RestOfEvent>();
138 if (check_roe !=
nullptr)
145 particle->addRelationTo(roe);
155 auto fsdaughters = particle->getFinalStateDaughters();
157 B2DEBUG(10,
"Particle has " + std::to_string(fsdaughters.size()) +
" daughters");
158 for (
auto* daughter : fsdaughters) {
159 B2DEBUG(10,
"\t" << daughter->getArrayIndex() <<
": pdg " << daughter->getPDGCode());
160 B2DEBUG(10,
"\t\t Store array particle: " << particlesArray[daughter->getArrayIndex()]->getPDGCode());
162 unsigned int nExcludedParticles = 0;
163 std::vector<const Particle* > particlesToAdd;
164 B2DEBUG(10,
"nLists: " << nParticleLists);
165 for (
int i_pl = 0; i_pl != nParticleLists; ++i_pl) {
168 B2DEBUG(10,
"ParticleList: " << particleListName);
170 int m_part = plist->getListSize();
171 for (
int i = 0; i < m_part; i++) {
172 Particle* storedParticle = plist->getParticle(i);
175 for (
auto* storedParticleDaughter : storedParticleDaughters) {
177 if ((
m_fromMC and storedParticleDaughter->getParticleSource() != Particle::EParticleSourceObject::c_MCParticle)
178 or (!
m_fromMC and storedParticleDaughter->getParticleSource() == Particle::EParticleSourceObject::c_MCParticle)) {
179 B2FATAL(
"The value of fromMC parameter is not consisted with the type of provided particles, MC vs Reco");
183 nExcludedParticles++;
186 for (
auto* daughter : fsdaughters) {
187 if (storedParticleDaughter->isCopyOf(daughter,
true)) {
188 B2DEBUG(10,
"Ignoring Particle with PDG " << daughter->getPDGCode() <<
" index " <<
189 storedParticleDaughter->getArrayIndex() <<
" to " << daughter->getArrayIndex());
190 B2DEBUG(10,
"Is copy " << storedParticleDaughter->isCopyOf(daughter));
192 nExcludedParticles++;
197 particlesToAdd.push_back(storedParticleDaughter);
202 if (fsdaughters.size() > nExcludedParticles) {
203 B2WARNING(
"Number of excluded particles do not coincide with the number of target FSP daughters! Provided lists must be incomplete");
213 B2INFO(
"[RestOfEventBuilderModule] *** Print Event ***");
214 B2INFO(
"[RestOfEventBuilderModule] Tracks: " << tracks.getEntries());
215 for (
int i = 0; i < tracks.getEntries(); i++) {
216 const Track* track = tracks[i];
219 if (trackECLCluster) {
220 B2INFO(
"[RestOfEventBuilderModule] -> track " << track->getArrayIndex() <<
" -> ECLCluster " << trackECLCluster->
getArrayIndex());
222 B2INFO(
"[RestOfEventBuilderModule] -> track " << track->getArrayIndex() <<
" -> ECLCluster (NO RELATION)");
224 if (trackKLMCluster) {
225 B2INFO(
"[RestOfEventBuilderModule] -> track " << track->getArrayIndex() <<
" -> KLMCluster " << trackKLMCluster->getArrayIndex());
227 B2INFO(
"[RestOfEventBuilderModule] -> track " << track->getArrayIndex() <<
" -> KLMCluster (NO RELATION)");
231 B2INFO(
"[RestOfEventBuilderModule] ECLCluster: " << eclClusters.
getEntries());
232 for (
int i = 0; i < eclClusters.
getEntries(); i++) {
233 const ECLCluster* eclCluster = eclClusters[i];
235 B2INFO(
"[RestOfEventBuilderModule] -> cluster " << eclCluster->
getArrayIndex());
238 B2INFO(
"[RestOfEventBuilderModule] KLMCluster: " << klmClusters.
getEntries());
239 for (
int i = 0; i < klmClusters.
getEntries(); i++) {
240 const KLMCluster* klmCluster = klmClusters[i];
242 B2INFO(
"[RestOfEventBuilderModule] -> cluster " << klmCluster->
getArrayIndex());
248 std::vector<int> eclFSPs = particle->getMdstArrayIndices(Particle::EParticleSourceObject::c_ECLCluster);
249 std::vector<int> klmFSPs = particle->getMdstArrayIndices(Particle::EParticleSourceObject::c_KLMCluster);
250 std::vector<int> trackFSPs = particle->getMdstArrayIndices(Particle::EParticleSourceObject::c_Track);
252 B2INFO(
"[RestOfEventBuilderModule] tracks : ");
254 std::string printout;
255 for (
int trackFSP : trackFSPs)
256 printout += std::to_string(trackFSP) +
" ";
261 B2INFO(
"[RestOfEventBuilderModule] eclFSPs : ");
262 for (
int eclFSP : eclFSPs)
263 printout += std::to_string(eclFSP) +
" ";
268 B2INFO(
"[RestOfEventBuilderModule] klmFSPs : ");
269 for (
int klmFSP : klmFSPs)
270 printout += std::to_string(klmFSP) +
" ";