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 <mdst/dataobjects/PIDLikelihood.h>
12#include <analysis/VariableManager/Utility.h>
13#include <analysis/dataobjects/Particle.h>
14
15#include <framework/logging/Logger.h>
16
17#include <Math/Vector4D.h>
18
19#include <vector>
20#include <string>
21#include <set>
22
23namespace Belle2 {
29 // forward declarations
30 class Particle;
31 class ECLCluster;
32 class KLMCluster;
33 class Track;
34
35 // TODO: Add support for the MdstVee dataobjects when they become available.
36
37
58
59 public:
60 static constexpr const char* c_defaultMaskName = "all";
68 struct Mask {
69 public:
76 Mask(const std::string& name = c_defaultMaskName, const std::string& origin = "unknown"): m_name(name),
77 m_origin(origin)
78 {
79 B2DEBUG(10, "Mask " << name << " is being initialized by " << origin);
80 m_isValid = false;
81 };
85 std::string getName() const
86 {
87 return m_name;
88 }
92 bool isValid() const
93 {
94 return m_isValid;
95 }
99 void addParticles(const std::vector<const Particle*>& particles)
100 {
101 if (isValid()) {
102 B2INFO("Mask " + m_name + " originating from " + m_origin + " is valid, cannot write to it!");
103 return;
104 } else {
105 for (auto* particle : particles) {
106 m_maskedParticleIndices.insert(particle->getArrayIndex());
107 }
108 m_isValid = true;
109 }
110 }
114 std::set<int> getParticles() const
115 {
117 }
121 std::set<int> getV0s() const
122 {
123 return m_maskedV0Indices;
124 }
128 void addV0(const Particle* v0, std::vector<int>& toErase)
129 {
130 m_maskedV0Indices.insert(v0->getArrayIndex());
131 for (int& i : toErase) {
133 }
135 }
139 bool hasV0(const Particle* v0) const
140 {
141 return m_maskedV0Indices.count(v0->getArrayIndex()) > 0;
142 }
148 {
150 m_maskedV0Indices.clear();
151 m_isValid = false;
152 }
156 void print() const
157 {
158 B2INFO("Mask name: " + m_name + " originating from " + m_origin);
159 if (!m_isValid) {
160 B2INFO("\tNot valid!");
161 }
162 std::string printout = "\tIndices: ";
163 for (const int index : m_maskedParticleIndices) {
164 printout += std::to_string(index) + ", ";
165 }
166 B2INFO(printout);
167 }
168 private:
169 std::string m_name;
170 std::string m_origin;
173 std::set<int> m_maskedV0Indices;
174 };
179 explicit RestOfEvent(int pdgCode = 0,
180 bool isNested = false,
181 bool isFromMC = false,
182 bool useKLMEnergy = false,
183 bool builtWithMostLikely = false):
184 m_pdgCode(pdgCode), m_isNested(isNested), m_isFromMC(isFromMC), m_useKLMEnergy(useKLMEnergy),
185 m_builtWithMostLikely(builtWithMostLikely) { };
186 // setters
192 void addParticles(const std::vector<const Particle*>& particle);
196 void setPDGCode(int pdgCode)
197 {
198 m_pdgCode = pdgCode;
199 }
207 Particle* convertToParticle(const std::string& maskName = c_defaultMaskName, int pdgCode = 0, bool isSelfConjugated = true);
211 int getPDGCode() const
212 {
213 return m_pdgCode;
214 }
220 bool hasParticle(const Particle* particle, const std::string& maskName = c_defaultMaskName) const;
226 void initializeMask(const std::string& name, const std::string& origin = "unknown");
235 void updateMaskWithCuts(const std::string& name, const std::shared_ptr<Variable::Cut>& trackCut = nullptr,
236 const std::shared_ptr<Variable::Cut>& eclCut = nullptr, const std::shared_ptr<Variable::Cut>& klmCut = nullptr,
237 bool updateExisting = false);
245 void excludeParticlesFromMask(const std::string& maskName, const std::vector<const Particle*>& particles,
247 bool discard);
252 bool hasMask(const std::string& name) const;
258 void updateMaskWithV0(const std::string& name, const Particle* particleV0);
262 bool checkCompatibilityOfMaskAndV0(const std::string& name, const Particle* particleV0);
266 bool getIsNested() const {return m_isNested;}
267
272 // getters
280 std::vector<const Particle*> getParticles(const std::string& maskName = c_defaultMaskName, bool unpackComposite = true) const;
288 std::vector<const Particle*> getPhotons(const std::string& maskName = c_defaultMaskName, bool unpackComposite = true) const;
296 std::vector<const Particle*> getHadrons(const std::string& maskName = c_defaultMaskName, bool unpackComposite = true) const;
305 std::vector<const Particle*> getChargedParticles(const std::string& maskName = c_defaultMaskName, unsigned int pdg = 0,
306 bool unpackComposite = true) const;
307
314 ROOT::Math::PxPyPzEVector get4Vector(const std::string& maskName = c_defaultMaskName) const;
315
322 ROOT::Math::PxPyPzEVector get4VectorNeutralECLClusters(const std::string& maskName = c_defaultMaskName) const;
323
330 int getNTracks(const std::string& maskName = c_defaultMaskName) const;
331
338 int getNECLClusters(const std::string& maskName = c_defaultMaskName) const;
339
346 int getNKLMClusters(const std::string& maskName = c_defaultMaskName) const;
347
352 std::vector<std::string> getMaskNames() const;
353
357 void print(const std::string& maskName = c_defaultMaskName, bool unpackComposite = true) const;
358
359 private:
360
361 // persistent data members
362 std::set<int> m_particleIndices;
363 std::vector<Mask> m_masks;
370 // Private methods
374 bool isInParticleList(const Particle* roeParticle, const std::vector<const Particle*>& particlesToUpdate) const;
375
379 Mask* findMask(const std::string& name);
383 void printIndices(const std::string& maskName = c_defaultMaskName, bool unpackComposite = true,
384 const std::string& tab = " - ") const;
385
387 // v8: added default mask name
388 // v7: added m_builtWithMostLikely
389
390 };
391
392
394} // end namespace Belle2
Class to store reconstructed particles.
Definition: Particle.h:75
EParticleSourceObject
particle source enumerators
Definition: Particle.h:82
Defines interface for accessing relations of objects in StoreArray.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
ClassDef(RelationsInterface, 0)
defines interface for accessing relations of objects in StoreArray.
This is a general purpose class for collecting reconstructed MDST data objects that are not used in r...
Definition: RestOfEvent.h:57
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.
Definition: RestOfEvent.cc:306
int getPDGCode() const
Gets the PDG code of the rest of event.
Definition: RestOfEvent.h:211
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.
Definition: RestOfEvent.cc:339
std::set< int > m_particleIndices
StoreArray indices to unused particles.
Definition: RestOfEvent.h:362
std::vector< const Particle * > getParticles(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true) const
Get all Particles from ROE mask.
Definition: RestOfEvent.cc:45
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.
Definition: RestOfEvent.cc:108
RestOfEvent(int pdgCode=0, bool isNested=false, bool isFromMC=false, bool useKLMEnergy=false, bool builtWithMostLikely=false)
Default constructor.
Definition: RestOfEvent.h:179
void print(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true) const
Prints the contents of a RestOfEvent object to screen.
Definition: RestOfEvent.cc:391
void initializeMask(const std::string &name, const std::string &origin="unknown")
Initialize new mask.
Definition: RestOfEvent.cc:134
bool checkCompatibilityOfMaskAndV0(const std::string &name, const Particle *particleV0)
Check if V0 can be added, maybe should be moved to private.
Definition: RestOfEvent.cc:268
static constexpr const char * c_defaultMaskName
Default mask name.
Definition: RestOfEvent.h:60
bool getIsNested() const
Returns true if the ROE is nested.
Definition: RestOfEvent.h:266
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.
Definition: RestOfEvent.cc:356
bool m_builtWithMostLikely
indicates whether most-likely particle lists were used in build of ROE
Definition: RestOfEvent.h:368
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.
Definition: RestOfEvent.cc:426
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.
Definition: RestOfEvent.cc:191
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.
Definition: RestOfEvent.cc:333
bool hasMask(const std::string &name) const
True if this ROE object has mask.
Definition: RestOfEvent.cc:297
void setPDGCode(int pdgCode)
Sets the PDG code of the rest of event.
Definition: RestOfEvent.h:196
std::vector< const Particle * > getPhotons(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true) const
Get photons from ROE mask.
Definition: RestOfEvent.cc:84
bool m_isFromMC
MC ROE indicator.
Definition: RestOfEvent.h:366
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.
Definition: RestOfEvent.cc:124
Mask * findMask(const std::string &name)
Helper method to find ROE mask.
Definition: RestOfEvent.cc:322
Particle * convertToParticle(const std::string &maskName=c_defaultMaskName, int pdgCode=0, bool isSelfConjugated=true)
Converts ROE to Particle and adds it to StoreArray.
Definition: RestOfEvent.cc:443
void addParticles(const std::vector< const Particle * > &particle)
Add StoreArray indices of given Particles to the list of unused particles in the event.
Definition: RestOfEvent.cc:24
int getNKLMClusters(const std::string &maskName=c_defaultMaskName) const
Get number of all remaining KLM clusters.
Definition: RestOfEvent.cc:350
std::vector< std::string > getMaskNames() const
Get vector of all mask names of the ROE object.
Definition: RestOfEvent.cc:380
void updateMaskWithV0(const std::string &name, const Particle *particleV0)
Update mask with composite particle.
Definition: RestOfEvent.cc:231
bool m_useKLMEnergy
Include KLM energy into ROE 4-vector.
Definition: RestOfEvent.h:367
std::vector< const Particle * > getHadrons(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true) const
Get hadrons from ROE mask.
Definition: RestOfEvent.cc:96
bool isBuiltWithMostLikely() const
Returns true if the ROE was built with most-likely particle lists.
Definition: RestOfEvent.h:271
std::vector< Mask > m_masks
List of the ROE masks.
Definition: RestOfEvent.h:363
int m_pdgCode
PDG code of the 'ROE particle' if we are going to create one.
Definition: RestOfEvent.h:364
void excludeParticlesFromMask(const std::string &maskName, const std::vector< const Particle * > &particles, Particle::EParticleSourceObject listType, bool discard)
Update mask by keeping or excluding particles.
Definition: RestOfEvent.cc:154
bool isInParticleList(const Particle *roeParticle, const std::vector< const Particle * > &particlesToUpdate) const
Checks if a particle has its copy in the provided list.
Definition: RestOfEvent.cc:370
bool m_isNested
Nested ROE indicator.
Definition: RestOfEvent.h:365
Abstract base class for different kinds of events.
Structure of Rest of Event mask.
Definition: RestOfEvent.h:68
std::set< int > m_maskedV0Indices
StoreArray indices for masked V0 ROE particles.
Definition: RestOfEvent.h:173
void clearParticles()
Clear selected particles associated to the mask.
Definition: RestOfEvent.h:147
bool isValid() const
Get mask validity.
Definition: RestOfEvent.h:92
std::set< int > getV0s() const
Get selected particles associated to the V0 of mask.
Definition: RestOfEvent.h:121
std::string getName() const
Get mask name.
Definition: RestOfEvent.h:85
std::string m_origin
Mask origin for debug.
Definition: RestOfEvent.h:170
Mask(const std::string &name=c_defaultMaskName, const std::string &origin="unknown")
Default constructor.
Definition: RestOfEvent.h:76
void addParticles(const std::vector< const Particle * > &particles)
Add selected particles to the mask.
Definition: RestOfEvent.h:99
bool hasV0(const Particle *v0) const
Has selected particles associated to the mask.
Definition: RestOfEvent.h:139
void print() const
Print mask and selected particles associated to the mask.
Definition: RestOfEvent.h:156
std::set< int > getParticles() const
Get selected particles associated to the mask.
Definition: RestOfEvent.h:114
void addV0(const Particle *v0, std::vector< int > &toErase)
Get selected particles associated to the V0 of mask.
Definition: RestOfEvent.h:128
bool m_isValid
Check if mask has elements or correctly initialized.
Definition: RestOfEvent.h:171
std::string m_name
Mask name.
Definition: RestOfEvent.h:169
std::set< int > m_maskedParticleIndices
StoreArray indices for masked ROE particles.
Definition: RestOfEvent.h:172