Belle II Software development
RestOfEvent.h
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#pragma once
10#include <framework/datastore/RelationsObject.h>
11#include <analysis/VariableManager/Utility.h>
12#include <analysis/dataobjects/Particle.h>
13
14#include <framework/logging/Logger.h>
15
16#include <Math/Vector4D.h>
17
18#include <vector>
19#include <string>
20#include <set>
21
22namespace Belle2 {
27
28 // forward declarations
29 class ECLCluster;
30 class KLMCluster;
31 class Track;
32
33 // TODO: Add support for the MdstVee dataobjects when they become available.
34
35
54
56
57 public:
58 static constexpr const char* c_defaultMaskName = "all";
66 struct Mask {
67 public:
74 Mask(const std::string& name = c_defaultMaskName, const std::string& origin = "unknown"): m_name(name),
75 m_origin(origin)
76 {
77 B2DEBUG(10, "Mask " << name << " is being initialized by " << origin);
78 m_isValid = false;
79 };
80
83 std::string getName() const
84 {
85 return m_name;
86 }
87
90 bool isValid() const
91 {
92 return m_isValid;
93 }
94
97 void addParticles(const std::vector<const Particle*>& particles)
98 {
99 if (isValid()) {
100 B2INFO("Mask " + m_name + " originating from " + m_origin + " is valid, cannot write to it!");
101 return;
102 } else {
103 for (auto* particle : particles) {
104 m_maskedParticleIndices.insert(particle->getArrayIndex());
105 }
106 m_isValid = true;
107 }
108 }
109
112 std::set<int> getParticles() const
113 {
115 }
116
119 std::set<int> getV0s() const
120 {
121 return m_maskedV0Indices;
122 }
123
126 void addV0(const Particle* v0, std::vector<int>& toErase)
127 {
128 m_maskedV0Indices.insert(v0->getArrayIndex());
129 for (int& i : toErase) {
131 }
133 }
134
137 bool hasV0(const Particle* v0) const
138 {
139 return m_maskedV0Indices.count(v0->getArrayIndex()) > 0;
140 }
141
144
146 {
148 m_maskedV0Indices.clear();
149 m_isValid = false;
150 }
151
154 void print() const
155 {
156 B2INFO("Mask name: " + m_name + " originating from " + m_origin);
157 if (!m_isValid) {
158 B2INFO("\tNot valid!");
159 }
160 std::string printout = "\tIndices: ";
161 for (const int index : m_maskedParticleIndices) {
162 printout += std::to_string(index) + ", ";
163 }
164 B2INFO(printout);
165 }
166 private:
167 std::string m_name;
168 std::string m_origin;
171 std::set<int> m_maskedV0Indices;
172 };
173
177 explicit RestOfEvent(int pdgCode = 0,
178 bool isNested = false,
179 bool isFromMC = false,
180 bool useKLMEnergy = false,
181 bool builtWithMostLikely = false):
182 m_pdgCode(pdgCode), m_isNested(isNested), m_isFromMC(isFromMC), m_useKLMEnergy(useKLMEnergy),
183 m_builtWithMostLikely(builtWithMostLikely) { };
184 // setters
190 void addParticles(const std::vector<const Particle*>& particle);
194 void setPDGCode(int pdgCode)
195 {
196 m_pdgCode = pdgCode;
197 }
198
205 Particle* convertToParticle(const std::string& maskName = c_defaultMaskName, int pdgCode = 0, bool isSelfConjugated = true);
209 int getPDGCode() const
210 {
211 return m_pdgCode;
212 }
213
218 bool hasParticle(const Particle* particle, const std::string& maskName = c_defaultMaskName) const;
224 void initializeMask(const std::string& name, const std::string& origin = "unknown");
233 void updateMaskWithCuts(const std::string& name, const std::shared_ptr<Variable::Cut>& trackCut = nullptr,
234 const std::shared_ptr<Variable::Cut>& eclCut = nullptr, const std::shared_ptr<Variable::Cut>& klmCut = nullptr,
235 bool updateExisting = false);
243 void excludeParticlesFromMask(const std::string& maskName, const std::vector<const Particle*>& particles,
245 bool discard);
250 bool hasMask(const std::string& name) const;
256 void updateMaskWithV0(const std::string& name, const Particle* particleV0);
260 bool checkCompatibilityOfMaskAndV0(const std::string& name, const Particle* particleV0);
264 bool getIsNested() const {return m_isNested;}
265
270 // getters
278 std::vector<const Particle*> getParticles(const std::string& maskName = c_defaultMaskName, bool unpackComposite = true) const;
286 std::vector<const Particle*> getPhotons(const std::string& maskName = c_defaultMaskName, bool unpackComposite = true) const;
294 std::vector<const Particle*> getHadrons(const std::string& maskName = c_defaultMaskName, bool unpackComposite = true) const;
303 std::vector<const Particle*> getChargedParticles(const std::string& maskName = c_defaultMaskName, unsigned int pdg = 0,
304 bool unpackComposite = true) const;
305
312 ROOT::Math::PxPyPzEVector get4Vector(const std::string& maskName = c_defaultMaskName) const;
313
320 ROOT::Math::PxPyPzEVector get4VectorNeutralECLClusters(const std::string& maskName = c_defaultMaskName) const;
321
328 int getNTracks(const std::string& maskName = c_defaultMaskName) const;
329
336 int getNECLClusters(const std::string& maskName = c_defaultMaskName) const;
337
344 int getNKLMClusters(const std::string& maskName = c_defaultMaskName) const;
345
350 std::vector<std::string> getMaskNames() const;
351
355 void print(const std::string& maskName = c_defaultMaskName, bool unpackComposite = true) const;
356
357 private:
358
359 // persistent data members
360 std::set<int> m_particleIndices;
361 std::vector<Mask> m_masks;
367
368 // Private methods
372 bool isInParticleList(const Particle* roeParticle, const std::vector<const Particle*>& particlesToUpdate) const;
373
377 Mask* findMask(const std::string& name);
381 void printIndices(const std::string& maskName = c_defaultMaskName, bool unpackComposite = true,
382 const std::string& tab = " - ") const;
383
385 // v8: added default mask name
386 // v7: added m_builtWithMostLikely
387
388 };
389
390
392} // end namespace Belle2
ECL cluster data.
Definition ECLCluster.h:27
KLM cluster data.
Definition KLMCluster.h:29
Class to store reconstructed particles.
Definition Particle.h:76
EParticleSourceObject
particle source enumerators
Definition Particle.h:83
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
ROOT::Math::PxPyPzEVector get4Vector(const std::string &maskName=c_defaultMaskName) const
Get 4-momentum vector all (no mask) or a subset (use mask) of all Tracks and ECLClusters in ROE.
int getPDGCode() const
Gets the PDG code of the rest of event.
int getNECLClusters(const std::string &maskName=c_defaultMaskName) const
Get number of all (no mask) or a subset (use mask) of all ECLclusters in ROE.
std::set< int > m_particleIndices
StoreArray indices to unused particles.
std::vector< const Particle * > getParticles(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true) const
Get all Particles from ROE mask.
std::vector< const Particle * > getChargedParticles(const std::string &maskName=c_defaultMaskName, unsigned int pdg=0, bool unpackComposite=true) const
Get charged particles from ROE mask.
RestOfEvent(int pdgCode=0, bool isNested=false, bool isFromMC=false, bool useKLMEnergy=false, bool builtWithMostLikely=false)
Default constructor.
void print(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true) const
Prints the contents of a RestOfEvent object to screen.
void initializeMask(const std::string &name, const std::string &origin="unknown")
Initialize new mask.
bool checkCompatibilityOfMaskAndV0(const std::string &name, const Particle *particleV0)
Check if V0 can be added, maybe should be moved to private.
static constexpr const char * c_defaultMaskName
Default mask name.
Definition RestOfEvent.h:58
bool getIsNested() const
Returns true if the ROE is nested.
ROOT::Math::PxPyPzEVector get4VectorNeutralECLClusters(const std::string &maskName=c_defaultMaskName) const
Get 4-momentum vector all (no mask) or a subset (use mask) of all ECLClusters in ROE.
bool m_builtWithMostLikely
indicates whether most-likely particle lists were used in build of ROE
void printIndices(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true, const std::string &tab=" - ") const
Prints indices in the given set in a single line.
void updateMaskWithCuts(const std::string &name, const std::shared_ptr< Variable::Cut > &trackCut=nullptr, const std::shared_ptr< Variable::Cut > &eclCut=nullptr, const std::shared_ptr< Variable::Cut > &klmCut=nullptr, bool updateExisting=false)
Update mask with cuts.
int getNTracks(const std::string &maskName=c_defaultMaskName) const
Get number of all (no mask) or a subset (use mask) of all Tracks in ROE.
bool hasMask(const std::string &name) const
True if this ROE object has mask.
void setPDGCode(int pdgCode)
Sets the PDG code of the rest of event.
std::vector< const Particle * > getPhotons(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true) const
Get photons from ROE mask.
bool m_isFromMC
MC ROE indicator.
bool hasParticle(const Particle *particle, const std::string &maskName=c_defaultMaskName) const
Check if ROE has StoreArray index of given to the list of unused tracks in the event.
Mask * findMask(const std::string &name)
Helper method to find ROE mask.
Particle * convertToParticle(const std::string &maskName=c_defaultMaskName, int pdgCode=0, bool isSelfConjugated=true)
Converts ROE to Particle and adds it to StoreArray.
void addParticles(const std::vector< const Particle * > &particle)
Add StoreArray indices of given Particles to the list of unused particles in the event.
int getNKLMClusters(const std::string &maskName=c_defaultMaskName) const
Get number of all remaining KLM clusters.
std::vector< std::string > getMaskNames() const
Get vector of all mask names of the ROE object.
void updateMaskWithV0(const std::string &name, const Particle *particleV0)
Update mask with composite particle.
bool m_useKLMEnergy
Include KLM energy into ROE 4-vector.
std::vector< const Particle * > getHadrons(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true) const
Get hadrons from ROE mask.
bool isBuiltWithMostLikely() const
Returns true if the ROE was built with most-likely particle lists.
std::vector< Mask > m_masks
List of the ROE masks.
int m_pdgCode
PDG code of the 'ROE particle' if we are going to create one.
void excludeParticlesFromMask(const std::string &maskName, const std::vector< const Particle * > &particles, Particle::EParticleSourceObject listType, bool discard)
Update mask by keeping or excluding particles.
bool isInParticleList(const Particle *roeParticle, const std::vector< const Particle * > &particlesToUpdate) const
Checks if a particle has its copy in the provided list.
bool m_isNested
Nested ROE indicator.
Class that bundles various TrackFitResults.
Definition Track.h:25
RelationsInterface< TObject > RelationsObject
Provides interface for getting/adding relations to objects in StoreArrays.
Abstract base class for different kinds of events.
Structure of Rest of Event mask.
Definition RestOfEvent.h:66
std::set< int > m_maskedV0Indices
StoreArray indices for masked V0 ROE particles.
void clearParticles()
Clear selected particles associated to the mask.
bool isValid() const
Get mask validity.
Definition RestOfEvent.h:90
std::set< int > getV0s() const
Get selected particles associated to the V0 of mask.
std::string getName() const
Get mask name.
Definition RestOfEvent.h:83
std::string m_origin
Mask origin for debug.
Mask(const std::string &name=c_defaultMaskName, const std::string &origin="unknown")
Default constructor.
Definition RestOfEvent.h:74
void addParticles(const std::vector< const Particle * > &particles)
Add selected particles to the mask.
Definition RestOfEvent.h:97
bool hasV0(const Particle *v0) const
Has selected particles associated to the mask.
void print() const
Print mask and selected particles associated to the mask.
std::set< int > getParticles() const
Get selected particles associated to the mask.
void addV0(const Particle *v0, std::vector< int > &toErase)
Get selected particles associated to the V0 of mask.
bool m_isValid
Check if mask has elements or correctly initialized.
std::string m_name
Mask name.
std::set< int > m_maskedParticleIndices
StoreArray indices for masked ROE particles.