Belle II Software  release-08-01-10
FixMergedObjectsModule.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 <mdst/modules/EventMerging/FixMergedObjectsModule.h>
10 
11 #include <analysis/dataobjects/Particle.h>
12 #include <analysis/dataobjects/ParticleList.h>
13 #include <framework/gearbox/Const.h>
14 #include <framework/logging/Logger.h>
15 
16 #include <boost/algorithm/string.hpp>
17 
18 using namespace Belle2;
19 
20 //-----------------------------------------------------------------
21 // Register module
22 //-----------------------------------------------------------------
23 
24 REG_MODULE(FixMergedObjects);
25 
26 //-----------------------------------------------------------------
27 // Implementation
28 //-----------------------------------------------------------------
29 
31 {
32  setDescription("Fix indices of mdst objects (Tracks, V0s, MCParticles) after DataStores were merged using an independent path.");
33 
35 }
36 
38 {
39  m_mergedArrayIndices.isRequired("MergedArrayIndices");
40  m_tracks.isOptional();
41  m_v0s.isOptional();
43  // Throw a warning if Particles and ParticleList are found in the DataStore: they are likely "broken" after the
44  // event embedding
45  const auto particleArrays{DataStore::Instance().getListOfArrays(Particle::Class(), DataStore::c_Event)};
46  if (particleArrays.size() > 0)
47  B2WARNING("Some Particle arrays are found in the DataStore: they are likely invalid/broken after having used the event embedding!"
48  << LogVar("Particle array names", boost::algorithm::join(particleArrays, " ")));
49  const auto particleListObjects{DataStore::Instance().getListOfObjects(ParticleList::Class(), DataStore::c_Event)};
50  if (particleListObjects.size() > 0)
51  B2WARNING("Some ParticleList objects are found in the DataStore: they are likely invalid/broken after having used the event embedding!"
52  << LogVar("ParticleList object names", boost::algorithm::join(particleListObjects, " ")));
53 }
54 
56 {
57  // This is quite easy, it is all just constant offsets (corresponding to length of StoreArray before Merge)
58 
59  if (m_tracks.isValid() && m_mergedArrayIndices->hasExtraInfo("Tracks") && m_mergedArrayIndices->hasExtraInfo("TrackFitResults")) {
60  for (int t_idx = m_mergedArrayIndices->getExtraInfo("Tracks"); t_idx < m_tracks.getEntries(); t_idx++) {
61  for (unsigned int i = 0; i < Const::ChargedStable::c_SetSize; i++) {
62  // hypothesis not fitted
63  if (m_tracks[t_idx]->m_trackFitIndices[i] == -1) {
64  continue;
65  }
66  // declared friends class, so this can be done
67  m_tracks[t_idx]->m_trackFitIndices[i] += m_mergedArrayIndices->getExtraInfo("TrackFitResults");
68  }
69  }
70  }
71 
72  if (m_v0s.isValid() && m_mergedArrayIndices->hasExtraInfo("V0s")) {
73  for (int v_idx = m_mergedArrayIndices->getExtraInfo("V0s"); v_idx < m_v0s.getEntries(); v_idx++) {
74  // declared friends class, so this can be done
75  m_v0s[v_idx]->m_trackIndexPositive += m_mergedArrayIndices->getExtraInfo("Tracks");
76  m_v0s[v_idx]->m_trackIndexNegative += m_mergedArrayIndices->getExtraInfo("Tracks");
77  m_v0s[v_idx]->m_trackFitResultIndexPositive += m_mergedArrayIndices->getExtraInfo("TrackFitResults");
78  m_v0s[v_idx]->m_trackFitResultIndexNegative += m_mergedArrayIndices->getExtraInfo("TrackFitResults");
79  }
80  }
81 
82  if (m_mcParticles.isValid() && m_mergedArrayIndices->hasExtraInfo("MCParticles")) {
83  for (int p_idx = m_mergedArrayIndices->getExtraInfo("MCParticles"); p_idx < m_mcParticles.getEntries(); p_idx++) {
84  // declared friends class, so this can be done
85  m_mcParticles[p_idx]->m_index += m_mergedArrayIndices->getExtraInfo("MCParticles");
86  m_mcParticles[p_idx]->m_mother += m_mergedArrayIndices->getExtraInfo("MCParticles");
87  m_mcParticles[p_idx]->m_firstDaughter += m_mergedArrayIndices->getExtraInfo("MCParticles");
88  m_mcParticles[p_idx]->m_lastDaughter += m_mergedArrayIndices->getExtraInfo("MCParticles");
89  }
90  }
91 }
92 
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition: Const.h:606
std::vector< std::string > getListOfArrays(const TClass *arrayClass, EDurability durability) const
Returns a list of names of arrays which are of type (or inherit from) arrayClass.
Definition: DataStore.cc:666
std::vector< std::string > getListOfObjects(const TClass *objClass, EDurability durability) const
Returns a list of names of StoreObjPtr-objects whose class is (or inherits from) objClass.
Definition: DataStore.cc:671
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition: DataStore.h:59
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
StoreArray< Track > m_tracks
tracks
StoreObjPtr< EventExtraInfo > m_mergedArrayIndices
indices where the StoreArrays were merged
StoreArray< MCParticle > m_mcParticles
mcparticles
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
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
bool isValid() const
Check wether the array was registered.
Definition: StoreArray.h:288
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Class to store variables with their name which were sent to the logging service.
REG_MODULE(arichBtest)
Register the Module.
Abstract base class for different kinds of events.