Belle II Software  release-06-02-00
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 <vector>
18 #include <string>
19 #include <set>
20 
21 class TLorentzVector;
22 
23 namespace 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 
57  class RestOfEvent : public RelationsObject {
58 
59  public:
67  struct Mask {
68  public:
75  Mask(const std::string& name = "", const std::string& origin = "unknown"): m_name(name),
76  m_origin(origin)
77  {
78  B2DEBUG(10, "Mask " << name << " is being initialized by " << origin);
79  m_isValid = false;
80  };
84  std::string getName() const
85  {
86  return m_name;
87  }
91  bool isValid() const
92  {
93  return m_isValid;
94  }
98  void addParticles(const std::vector<const Particle*>& particles)
99  {
100  if (isValid()) {
101  B2INFO("Mask " + m_name + " originating from " + m_origin + " is valid, cannot write to it!");
102  return;
103  } else {
104  for (auto* particle : particles) {
105  m_maskedParticleIndices.insert(particle->getArrayIndex());
106  }
107  m_isValid = true;
108  }
109  }
113  std::set<int> getParticles() const
114  {
116  }
120  std::set<int> getV0s() const
121  {
122  return m_maskedV0Indices;
123  }
127  void addV0(const Particle* v0, std::vector<int>& toErase)
128  {
129  m_maskedV0Indices.insert(v0->getArrayIndex());
130  for (int& i : toErase) {
131  m_maskedParticleIndices.erase(i);
132  }
134  }
138  bool hasV0(const Particle* v0) const
139  {
140  return m_maskedV0Indices.count(v0->getArrayIndex()) > 0;
141  }
147  {
148  m_maskedParticleIndices.clear();
149  m_maskedV0Indices.clear();
150  m_isValid = false;
151  }
155  void print() const
156  {
157  B2INFO("Mask name: " + m_name + " originating from " + m_origin);
158  if (!m_isValid) {
159  B2INFO("\tNot valid!");
160  }
161  std::string printout = "\tIndices: ";
162  for (const int index : m_maskedParticleIndices) {
163  printout += std::to_string(index) + ", ";
164  }
165  B2INFO(printout);
166  }
167  private:
168  std::string m_name;
169  std::string m_origin;
170  bool m_isValid;
171  std::set<int> m_maskedParticleIndices;
172  std::set<int> m_maskedV0Indices;
173  };
178  explicit RestOfEvent(int pdgCode = 0,
179  bool isNested = false,
180  bool isFromMC = false,
181  bool useKLMEnergy = false,
182  bool builtWithMostLikely = false):
183  m_pdgCode(pdgCode), m_isNested(isNested), m_isFromMC(isFromMC), m_useKLMEnergy(useKLMEnergy),
184  m_builtWithMostLikely(builtWithMostLikely) { };
185  // setters
191  void addParticles(const std::vector<const Particle*>& particle);
195  void setPDGCode(int pdgCode)
196  {
197  m_pdgCode = pdgCode;
198  }
206  Particle* convertToParticle(const std::string& maskName = "", int pdgCode = 0, bool isSelfConjugated = true);
210  int getPDGCode() const
211  {
212  return m_pdgCode;
213  }
219  bool hasParticle(const Particle* particle, const std::string& maskName = "") const;
225  void initializeMask(const std::string& name, const std::string& origin = "unknown");
234  void updateMaskWithCuts(const std::string& name, const std::shared_ptr<Variable::Cut>& trackCut = nullptr,
235  const std::shared_ptr<Variable::Cut>& eclCut = nullptr, const std::shared_ptr<Variable::Cut>& klmCut = nullptr,
236  bool updateExisting = false);
244  void excludeParticlesFromMask(const std::string& maskName, const std::vector<const Particle*>& particles,
246  bool discard);
251  bool hasMask(const std::string& name) const;
257  void updateMaskWithV0(const std::string& name, const Particle* particleV0);
261  bool checkCompatibilityOfMaskAndV0(const std::string& name, const Particle* particleV0);
265  bool getIsNested() const {return m_isNested;}
266 
271  // getters
279  std::vector<const Particle*> getParticles(const std::string& maskName = "", bool unpackComposite = true) const;
287  std::vector<const Particle*> getPhotons(const std::string& maskName = "", bool unpackComposite = true) const;
295  std::vector<const Particle*> getHadrons(const std::string& maskName = "", bool unpackComposite = true) const;
304  std::vector<const Particle*> getChargedParticles(const std::string& maskName = "", unsigned int pdg = 0,
305  bool unpackComposite = true) const;
306 
313  TLorentzVector get4Vector(const std::string& maskName = "") const;
314 
321  TLorentzVector get4VectorNeutralECLClusters(const std::string& maskName = "") const;
322 
329  int getNTracks(const std::string& maskName = "") const;
330 
337  int getNECLClusters(const std::string& maskName = "") const;
338 
345  int getNKLMClusters(const std::string& maskName = "") const;
346 
351  std::vector<std::string> getMaskNames() const;
352 
356  void print(const std::string& maskName = "", bool unpackComposite = true) const;
357 
358  private:
359 
360  // persistent data members
361  std::set<int> m_particleIndices;
362  std::vector<Mask> m_masks;
363  int m_pdgCode;
364  bool m_isNested;
365  bool m_isFromMC;
369  // Private methods
373  bool isInParticleList(const Particle* roeParticle, const std::vector<const Particle*>& particlesToUpdate) const;
374 
378  Mask* findMask(const std::string& name);
382  void printIndices(const std::string& maskName = "", bool unpackComposite = true, const std::string& tab = " - ") const;
383 
384  ClassDef(RestOfEvent, 7)
385  // v7: added m_builtWithMostLikely
386 
387  };
388 
389 
391 } // end namespace Belle2
Class to store reconstructed particles.
Definition: Particle.h:74
EParticleSourceObject
particle source enumerators
Definition: Particle.h:81
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
int getPDGCode() const
Gets the PDG code of the rest of event.
Definition: RestOfEvent.h:210
std::set< int > m_particleIndices
StoreArray indices to unused particles.
Definition: RestOfEvent.h:361
RestOfEvent(int pdgCode=0, bool isNested=false, bool isFromMC=false, bool useKLMEnergy=false, bool builtWithMostLikely=false)
Default constructor.
Definition: RestOfEvent.h:178
TLorentzVector get4Vector(const std::string &maskName="") const
Get 4-momentum vector all (no mask) or a subset (use mask) of all Tracks and ECLClusters in ROE.
Definition: RestOfEvent.cc:283
int getNTracks(const std::string &maskName="") const
Get number of all (no mask) or a subset (use mask) of all Tracks in ROE.
Definition: RestOfEvent.cc:310
void initializeMask(const std::string &name, const std::string &origin="unknown")
Initialize new mask.
Definition: RestOfEvent.cc:135
bool checkCompatibilityOfMaskAndV0(const std::string &name, const Particle *particleV0)
Check if V0 can be added, maybe should be moved to private.
Definition: RestOfEvent.cc:249
bool hasParticle(const Particle *particle, const std::string &maskName="") const
Check if ROE has StoreArray index of given to the list of unused tracks in the event.
Definition: RestOfEvent.cc:125
bool getIsNested() const
Returns true if the ROE is nested.
Definition: RestOfEvent.h:265
bool m_builtWithMostLikely
indicates whether most-likely particle lists were used in build of ROE
Definition: RestOfEvent.h:367
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:180
void print(const std::string &maskName="", bool unpackComposite=true) const
Prints the contents of a RestOfEvent object to screen.
Definition: RestOfEvent.cc:368
bool hasMask(const std::string &name) const
True if this ROE object has mask.
Definition: RestOfEvent.cc:274
void setPDGCode(int pdgCode)
Sets the PDG code of the rest of event.
Definition: RestOfEvent.h:195
bool m_isFromMC
MC ROE indicator.
Definition: RestOfEvent.h:365
std::vector< const Particle * > getChargedParticles(const std::string &maskName="", unsigned int pdg=0, bool unpackComposite=true) const
Get charged particles from ROE mask.
Definition: RestOfEvent.cc:109
int getNECLClusters(const std::string &maskName="") const
Get number of all (no mask) or a subset (use mask) of all ECLclusters in ROE.
Definition: RestOfEvent.cc:316
std::vector< const Particle * > getHadrons(const std::string &maskName="", bool unpackComposite=true) const
Get hadrons from ROE mask.
Definition: RestOfEvent.cc:97
std::vector< const Particle * > getParticles(const std::string &maskName="", bool unpackComposite=true) const
Get all Particles from ROE mask.
Definition: RestOfEvent.cc:46
void printIndices(const std::string &maskName="", bool unpackComposite=true, const std::string &tab=" - ") const
Prints indices in the given set in a single line.
Definition: RestOfEvent.cc:403
Mask * findMask(const std::string &name)
Helper method to find ROE mask.
Definition: RestOfEvent.cc:299
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:25
std::vector< std::string > getMaskNames() const
Get vector of all mask names of the ROE object.
Definition: RestOfEvent.cc:357
int getNKLMClusters(const std::string &maskName="") const
Get number of all remaining KLM clusters.
Definition: RestOfEvent.cc:327
void updateMaskWithV0(const std::string &name, const Particle *particleV0)
Update mask with composite particle.
Definition: RestOfEvent.cc:216
bool m_useKLMEnergy
Include KLM energy into ROE 4-vector.
Definition: RestOfEvent.h:366
Particle * convertToParticle(const std::string &maskName="", int pdgCode=0, bool isSelfConjugated=true)
Converts ROE to Particle and adds it to StoreArray.
Definition: RestOfEvent.cc:420
TLorentzVector get4VectorNeutralECLClusters(const std::string &maskName="") const
Get 4-momentum vector all (no mask) or a subset (use mask) of all ECLClusters in ROE.
Definition: RestOfEvent.cc:333
bool isBuiltWithMostLikely() const
Returns true if the ROE was built with most-likely particle lists.
Definition: RestOfEvent.h:270
std::vector< Mask > m_masks
List of the ROE masks.
Definition: RestOfEvent.h:362
int m_pdgCode
PDG code of the 'ROE particle' if we are going to create one.
Definition: RestOfEvent.h:363
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:147
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:347
bool m_isNested
Nested ROE indicator.
Definition: RestOfEvent.h:364
std::vector< const Particle * > getPhotons(const std::string &maskName="", bool unpackComposite=true) const
Get photons from ROE mask.
Definition: RestOfEvent.cc:85
Abstract base class for different kinds of events.
Structure of Rest of Event mask.
Definition: RestOfEvent.h:67
std::set< int > m_maskedV0Indices
StoreArray indices for masked V0 ROE particles.
Definition: RestOfEvent.h:172
void clearParticles()
Clear selected particles associated to the mask.
Definition: RestOfEvent.h:146
bool isValid() const
Get mask validity.
Definition: RestOfEvent.h:91
std::set< int > getV0s() const
Get selected particles associated to the V0 of mask.
Definition: RestOfEvent.h:120
std::string getName() const
Get mask name.
Definition: RestOfEvent.h:84
Mask(const std::string &name="", const std::string &origin="unknown")
Default constructor.
Definition: RestOfEvent.h:75
std::string m_origin
Mask origin for debug.
Definition: RestOfEvent.h:169
void addParticles(const std::vector< const Particle * > &particles)
Add selected particles to the mask.
Definition: RestOfEvent.h:98
bool hasV0(const Particle *v0) const
Has selected particles associated to the mask.
Definition: RestOfEvent.h:138
void print() const
Print mask and selected particles associated to the mask.
Definition: RestOfEvent.h:155
void addV0(const Particle *v0, std::vector< int > &toErase)
Get selected particles associated to the V0 of mask.
Definition: RestOfEvent.h:127
bool m_isValid
Check if mask has elements or correctly initialized.
Definition: RestOfEvent.h:170
std::string m_name
Mask name.
Definition: RestOfEvent.h:168
std::set< int > m_maskedParticleIndices
StoreArray indices for masked ROE particles.
Definition: RestOfEvent.h:171
std::set< int > getParticles() const
Get selected particles associated to the mask.
Definition: RestOfEvent.h:113