Belle II Software development
RestOfEventUpdaterModule.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/RestOfEventUpdater/RestOfEventUpdaterModule.h>
10
11#include <framework/datastore/StoreArray.h>
12#include <framework/datastore/StoreObjPtr.h>
13
14#include <framework/logging/Logger.h>
15
16using namespace std;
17
18using namespace Belle2;
19
20//-----------------------------------------------------------------
21// Register the Module
22//-----------------------------------------------------------------
23REG_MODULE(RestOfEventUpdater);
24
25//-----------------------------------------------------------------
26// Implementation
27//-----------------------------------------------------------------
28
30{
31 // Set module properties
32 setDescription("Updates an existing mask (map of boolean values) for tracks or eclClusters in RestOfEvent with an available property (e.g. after performing training).");
34
35 // Add parameters
36 std::vector<std::string> emptyMaskVector;
37 std::string emptyCutString;
38
39 addParam("particleList", m_inputListName, "Name of the ParticleList which contains information that will be used for updating");
40 addParam("updateMasks", m_maskNamesForUpdating, "List of all mask names which will be updated", emptyMaskVector);
41 addParam("cutString", m_selection, "Cut string which will be used for updating masks", emptyCutString);
42 addParam("discard", m_discard,
43 "Update the ROE mask by passing or discarding particles in the provided particle list, default is to pass", false);
44}
45
47{
49 m_inputList.isRequired(m_inputListName);
50
52
53 B2INFO("RestOfEventUpdater updated track/eclCluster ROEMask(s) with infoList: " << m_inputListName << " and cut: " << m_selection);
54}
55
57{
58 if (!m_inputList) {
59 B2WARNING("Input list " << m_inputList.getName() << " was not created?");
60 return;
61 }
62 StoreObjPtr<RestOfEvent> roe("RestOfEvent");
63 if (!roe.isValid()) {
64 B2WARNING("ROE list is not valid somehow, ROE masks are not updated!");
65 return;
66 }
67 std::set<Particle::EParticleSourceObject> encounteredSources;
68 // Particle lists can contain Particles from different mdst sources
69 // Thus, we split them based on their mdst source
70 // Only particles surviving the provided cut are considered
71 std::vector<const Particle*> particlesFromTracksToUpdate;
72 std::vector<const Particle*> particlesFromECLClustersToUpdate;
73 std::vector<const Particle*> particlesFromKLMClustersToUpdate;
74 std::vector<const Particle*> compositeParticlesToUpdate;
75 for (unsigned j = 0; j < m_inputList->getListSize(); j++) {
76 const Particle* partWithInfo = m_inputList->getParticle(j);
77 Particle::EParticleSourceObject mdstSource = partWithInfo->getParticleSource();
78 encounteredSources.insert(mdstSource);
79 if (m_cut->check(partWithInfo)) {
80 if (mdstSource == Particle::EParticleSourceObject::c_Track) {
81 particlesFromTracksToUpdate.push_back(partWithInfo);
82 } else if (mdstSource == Particle::EParticleSourceObject::c_ECLCluster) {
83 particlesFromECLClustersToUpdate.push_back(partWithInfo);
84 } else if (mdstSource == Particle::EParticleSourceObject::c_KLMCluster) {
85 particlesFromKLMClustersToUpdate.push_back(partWithInfo);
86 } else if (mdstSource == Particle::EParticleSourceObject::c_Composite or
87 mdstSource == Particle::EParticleSourceObject::c_V0) {
88 compositeParticlesToUpdate.push_back(partWithInfo);
89 }
90 }
91 }
92 if (encounteredSources.count(Particle::EParticleSourceObject::c_Track) > 0) {
93 updateMasksWithParticles(roe, particlesFromTracksToUpdate, Particle::EParticleSourceObject::c_Track);
94 } else { // If we have a track-based particle in the particle list there can not be any other mdst source
95 if (encounteredSources.count(Particle::EParticleSourceObject::c_ECLCluster) > 0) {
96 updateMasksWithParticles(roe, particlesFromECLClustersToUpdate, Particle::EParticleSourceObject::c_ECLCluster);
97 }
98 if (encounteredSources.count(Particle::EParticleSourceObject::c_KLMCluster) > 0) {
99 updateMasksWithParticles(roe, particlesFromKLMClustersToUpdate, Particle::EParticleSourceObject::c_KLMCluster);
100 }
101 updateMasksWithV0(roe, compositeParticlesToUpdate); // in updateMasksWithV0 it is checked whether the vector is empty
102 }
103}
104
106 const std::vector<const Particle*>& particlesToUpdate)
107{
108 if (particlesToUpdate.size() == 0) {
109 B2DEBUG(10, "No particles in list provided, nothing to do");
110 return;
111 }
112 for (auto& maskToUpdate : m_maskNamesForUpdating) {
113 if (maskToUpdate == "") {
114 B2FATAL("Cannot update ROE mask with no name!");
115 }
116 for (auto* particleV0 : particlesToUpdate) {
117 if (!roe->checkCompatibilityOfMaskAndV0(maskToUpdate, particleV0)) {
118 continue;
119 }
120 roe->updateMaskWithV0(maskToUpdate, particleV0);
121 }
122 }
123}
124
126 std::vector<const Particle*>& particlesToUpdate, Particle::EParticleSourceObject listType)
127{
128 for (auto& maskToUpdate : m_maskNamesForUpdating) {
129 if (maskToUpdate == "") {
130 B2FATAL("Cannot update ROE mask with no name!");
131 }
132 if (!roe->hasMask(maskToUpdate)) {
133 // Change name to get all ROE particles in case of new mask
134 roe->initializeMask(maskToUpdate, "ROEUpdaterModule");
135 }
136 roe->excludeParticlesFromMask(maskToUpdate, particlesToUpdate, listType, m_discard);
137
138 }
139}
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:84
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:76
EParticleSourceObject
particle source enumerators
Definition: Particle.h:83
EParticleSourceObject getParticleSource() const
Returns particle source as defined with enum EParticleSourceObject.
Definition: Particle.h:489
std::string m_selection
Cut string which will be used for updating masks.
virtual void initialize() override
Overridden initialize method.
virtual void event() override
Overridden event method.
std::shared_ptr< Variable::Cut > m_cut
Cut object which performs the cuts.
std::vector< std::string > m_maskNamesForUpdating
Container for all mask names which will be updated.
StoreObjPtr< ParticleList > m_inputList
ParticleList which contains information that will be used for updating.
void updateMasksWithParticles(const StoreObjPtr< RestOfEvent > &roe, std::vector< const Particle * > &particlesToUpdate, Particle::EParticleSourceObject listType)
Update ROE masks by excluding or keeping particles.
void updateMasksWithV0(const StoreObjPtr< RestOfEvent > &roe, const std::vector< const Particle * > &particlesToUpdate)
Update ROE masks with provided composite particle collection.
RestOfEventUpdaterModule()
Constructor: Sets the description, the properties and the parameters of the module.
std::string m_inputListName
Name of the ParticleList which contains information that will be used for updating.
bool m_discard
Update the ROE mask by passing or discarding particles in the provided particle list.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:110
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
Abstract base class for different kinds of events.
STL namespace.