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