Belle II Software  release-05-02-19
RestOfEvent.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Anze Zupanc, Matic Lubej, Sviatoslav Bilokin *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 #include <framework/datastore/RelationsObject.h>
13 #include <mdst/dataobjects/PIDLikelihood.h>
14 #include <analysis/VariableManager/Utility.h>
15 #include <analysis/dataobjects/Particle.h>
16 
17 #include <framework/logging/Logger.h>
18 
19 #include <vector>
20 #include <string>
21 #include <set>
22 
23 class TLorentzVector;
24 
25 namespace Belle2 {
31  // forward declarations
32  class Particle;
33  class ECLCluster;
34  class KLMCluster;
35  class Track;
36 
37  // TODO: Add support for the MdstVee dataobjects when they become available.
38 
39 
59  class RestOfEvent : public RelationsObject {
60 
61  public:
69  struct Mask {
70  public:
77  Mask(const std::string& name = "", const std::string& origin = "unknown"): m_name(name),
78  m_origin(origin)
79  {
80  B2DEBUG(10, "Mask " << name << " is being initialized by " << origin);
81  m_isValid = false;
82  };
86  std::string getName() const
87  {
88  return m_name;
89  }
93  bool isValid() const
94  {
95  return m_isValid;
96  }
100  void addParticles(const std::vector<const Particle*>& particles)
101  {
102  if (isValid()) {
103  B2INFO("Mask " + m_name + " originating from " + m_origin + " is valid, cannot write to it!");
104  return;
105  } else {
106  for (auto* particle : particles) {
107  m_maskedParticleIndices.insert(particle->getArrayIndex());
108  }
109  m_isValid = true;
110  }
111  }
115  std::set<int> getParticles() const
116  {
118  }
122  std::set<int> getV0s() const
123  {
124  return m_maskedV0Indices;
125  }
129  void addV0(const Particle* v0, std::vector<int>& toErase)
130  {
131  m_maskedV0Indices.insert(v0->getArrayIndex());
132  for (int& i : toErase) {
133  m_maskedParticleIndices.erase(i);
134  }
136  }
140  bool hasV0(const Particle* v0) const
141  {
142  return m_maskedV0Indices.count(v0->getArrayIndex()) > 0;
143  }
149  {
150  m_maskedParticleIndices.clear();
151  m_maskedV0Indices.clear();
152  m_isValid = false;
153  }
157  void print()
158  {
159  B2INFO("Mask name: " + m_name + " originating from " + m_origin);
160  if (!m_isValid) {
161  B2INFO("\tNot valid!");
162  }
163  std::string printout = "\tIndices: ";
164  for (const int index : m_maskedParticleIndices) {
165  printout += std::to_string(index) + ", ";
166  }
167  B2INFO(printout);
168  }
169  private:
170  std::string m_name;
171  std::string m_origin;
172  bool m_isValid;
173  std::set<int> m_maskedParticleIndices;
174  std::set<int> m_maskedV0Indices;
175  };
180  explicit RestOfEvent(int pdgCode = 0, bool isNested = false, bool isFromMC = false):
181  m_pdgCode(pdgCode), m_isNested(isNested), m_isFromMC(isFromMC) { };
182  // setters
188  void addParticles(const std::vector<const Particle*>& particle);
192  void setPDGCode(int pdgCode)
193  {
194  m_pdgCode = pdgCode;
195  }
203  Particle* convertToParticle(const std::string& maskName = "", int pdgCode = 0, bool isSelfConjugated = true);
207  int getPDGCode() const
208  {
209  return m_pdgCode;
210  }
216  bool hasParticle(const Particle* particle, const std::string& maskName = "") const;
222  void initializeMask(const std::string& name, const std::string& origin = "unknown");
231  void updateMaskWithCuts(const std::string& name, const std::shared_ptr<Variable::Cut>& trackCut = nullptr,
232  const std::shared_ptr<Variable::Cut>& eclCut = nullptr, const std::shared_ptr<Variable::Cut>& klmCut = nullptr,
233  bool updateExisting = false);
241  void excludeParticlesFromMask(const std::string& maskName, const std::vector<const Particle*>& particles,
243  bool discard);
248  bool hasMask(const std::string& name) const;
254  void updateMaskWithV0(const std::string& name, const Particle* particleV0);
258  bool checkCompatibilityOfMaskAndV0(const std::string& name, const Particle* particleV0);
262  bool getIsNested() const {return m_isNested;}
263  // getters
271  std::vector<const Particle*> getParticles(const std::string& maskName = "", bool unpackComposite = true) const;
279  std::vector<const Particle*> getPhotons(const std::string& maskName = "", bool unpackComposite = true) const;
287  std::vector<const Particle*> getHadrons(const std::string& maskName = "", bool unpackComposite = true) const;
296  std::vector<const Particle*> getChargedParticles(const std::string& maskName = "", unsigned int pdg = 0,
297  bool unpackComposite = true) const;
298 
305  std::vector<const Track*> getTracks(const std::string& maskName = "") const;
306 
313  std::vector<const ECLCluster*> getECLClusters(const std::string& maskName = "") const;
314 
321  std::vector<const KLMCluster*> getKLMClusters(const std::string& maskName = "") const;
322 
329  TLorentzVector get4Vector(const std::string& maskName = "") const;
330 
338  TLorentzVector get4VectorTracks(const std::string& maskName = "") const;
339 
346  TLorentzVector get4VectorNeutralECLClusters(const std::string& maskName = "") const;
347 
354  int getNTracks(const std::string& maskName = "") const;
355 
362  int getNECLClusters(const std::string& maskName = "") const;
363 
370  int getNKLMClusters(const std::string& maskName = "") const;
371 
376  std::vector<std::string> getMaskNames() const;
377 
382  double atcPIDBelleKpiFromPID(const PIDLikelihood* pid) const;
383 
387  void print() const;
388 
389  private:
390 
391  // persistent data members
392  std::set<int> m_particleIndices;
393  std::vector<Mask> m_masks;
394  int m_pdgCode;
395  bool m_isNested;
396  bool m_isFromMC;
397  // Private methods
401  bool isInParticleList(const Particle* roeParticle, const std::vector<const Particle*>& particlesToUpdate) const;
402 
406  Mask* findMask(const std::string& name);
410  void printIndices(const std::set<int>& indices) const;
411  ClassDef(RestOfEvent, 5)
413  };
414 
415 
417 } // end namespace Belle2
Belle2::RestOfEvent::RestOfEvent
RestOfEvent(int pdgCode=0, bool isNested=false, bool isFromMC=false)
Default constructor.
Definition: RestOfEvent.h:180
Belle2::RestOfEvent::m_masks
std::vector< Mask > m_masks
List of the ROE masks.
Definition: RestOfEvent.h:393
Belle2::RestOfEvent::printIndices
void printIndices(const std::set< int > &indices) const
Prints indices in the given set in a single line.
Definition: RestOfEvent.cc:504
Belle2::RestOfEvent::getNTracks
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:343
Belle2::RestOfEvent::Mask::hasV0
bool hasV0(const Particle *v0) const
Has selected particles associated to the mask.
Definition: RestOfEvent.h:140
Belle2::RestOfEvent::excludeParticlesFromMask
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
Belle2::RestOfEvent::get4Vector
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
Belle2::RestOfEvent::getNECLClusters
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:348
Belle2::RestOfEvent::updateMaskWithCuts
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
Belle2::RestOfEvent::getMaskNames
std::vector< std::string > getMaskNames() const
Get vector of all mask names of the ROE object.
Definition: RestOfEvent.cc:481
Belle2::RestOfEvent::getPhotons
std::vector< const Particle * > getPhotons(const std::string &maskName="", bool unpackComposite=true) const
Get photons from ROE mask.
Definition: RestOfEvent.cc:86
Belle2::RestOfEvent::Mask::m_isValid
bool m_isValid
Check if mask has elements or correctly initialized.
Definition: RestOfEvent.h:172
Belle2::RelationsInterface::ClassDef
ClassDef(RelationsInterface, 0)
defines interface for accessing relations of objects in StoreArray.
Belle2::RestOfEvent::m_isNested
bool m_isNested
Nested ROE indicator.
Definition: RestOfEvent.h:395
Belle2::RestOfEvent::getIsNested
bool getIsNested() const
Returns true if the ROE is nested.
Definition: RestOfEvent.h:262
Belle2::RestOfEvent
This is a general purpose class for collecting reconstructed MDST data objects that are not used in r...
Definition: RestOfEvent.h:59
Belle2::RestOfEvent::atcPIDBelleKpiFromPID
double atcPIDBelleKpiFromPID(const PIDLikelihood *pid) const
OBSOLETE: Added helper function so creation of temporary particles and setting pid relations is not n...
Definition: RestOfEvent.cc:542
Belle2::PIDLikelihood
Class to collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes...
Definition: PIDLikelihood.h:37
Belle2::RestOfEvent::hasParticle
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
Belle2::RestOfEvent::Mask::print
void print()
Print mask and selected particles associated to the mask.
Definition: RestOfEvent.h:157
Belle2::RestOfEvent::get4VectorTracks
TLorentzVector get4VectorTracks(const std::string &maskName="") const
OBSOLETE: Get 4-momentum vector all (no mask) or a subset (use mask) of all Tracks in ROE.
Definition: RestOfEvent.cc:361
Belle2::RestOfEvent::setPDGCode
void setPDGCode(int pdgCode)
Sets the PDG code of the rest of event.
Definition: RestOfEvent.h:192
Belle2::RestOfEvent::Mask::getParticles
std::set< int > getParticles() const
Get selected particles associated to the mask.
Definition: RestOfEvent.h:115
Belle2::RestOfEvent::convertToParticle
Particle * convertToParticle(const std::string &maskName="", int pdgCode=0, bool isSelfConjugated=true)
Converts ROE to Particle and adds it to StoreArray.
Definition: RestOfEvent.cc:516
Belle2::RestOfEvent::getHadrons
std::vector< const Particle * > getHadrons(const std::string &maskName="", bool unpackComposite=true) const
Get hadrons from ROE mask.
Definition: RestOfEvent.cc:97
Belle2::RestOfEvent::Mask::clearParticles
void clearParticles()
Clear selected particles associated to the mask.
Definition: RestOfEvent.h:148
Belle2::RestOfEvent::Mask::addParticles
void addParticles(const std::vector< const Particle * > &particles)
Add selected particles to the mask.
Definition: RestOfEvent.h:100
Belle2::RestOfEvent::getPDGCode
int getPDGCode() const
Gets the PDG code of the rest of event.
Definition: RestOfEvent.h:207
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::RestOfEvent::get4VectorNeutralECLClusters
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:455
Belle2::RestOfEvent::getParticles
std::vector< const Particle * > getParticles(const std::string &maskName="", bool unpackComposite=true) const
Get all Particles from ROE mask.
Definition: RestOfEvent.cc:48
Belle2::RestOfEvent::getKLMClusters
std::vector< const KLMCluster * > getKLMClusters(const std::string &maskName="") const
Get vector of all unused KLMClusters.
Definition: RestOfEvent.cc:332
Belle2::RestOfEvent::Mask::Mask
Mask(const std::string &name="", const std::string &origin="unknown")
Default constructor.
Definition: RestOfEvent.h:77
Belle2::RestOfEvent::Mask::getV0s
std::set< int > getV0s() const
Get selected particles associated to the V0 of mask.
Definition: RestOfEvent.h:122
Belle2::RelationsInterface::getArrayIndex
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
Definition: RelationsObject.h:387
Belle2::Particle::EParticleSourceObject
EParticleSourceObject
particle source enumerators
Definition: Particle.h:84
Belle2::RestOfEvent::m_pdgCode
int m_pdgCode
PDG code of the 'ROE particle' if we are going to create one.
Definition: RestOfEvent.h:394
Belle2::RestOfEvent::Mask::m_name
std::string m_name
Mask name.
Definition: RestOfEvent.h:170
Belle2::RestOfEvent::Mask::m_maskedV0Indices
std::set< int > m_maskedV0Indices
StoreArray indices for masked V0 ROE particles.
Definition: RestOfEvent.h:174
Belle2::RestOfEvent::m_isFromMC
bool m_isFromMC
MC ROE indicator.
Definition: RestOfEvent.h:396
Belle2::RestOfEvent::Mask::isValid
bool isValid() const
Get mask validity.
Definition: RestOfEvent.h:93
Belle2::RestOfEvent::hasMask
bool hasMask(const std::string &name) const
True if this ROE object has mask.
Definition: RestOfEvent.cc:274
Belle2::RestOfEvent::Mask::getName
std::string getName() const
Get mask name.
Definition: RestOfEvent.h:86
Belle2::RestOfEvent::checkCompatibilityOfMaskAndV0
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
Belle2::RestOfEvent::initializeMask
void initializeMask(const std::string &name, const std::string &origin="unknown")
Initialize new mask.
Definition: RestOfEvent.cc:135
Belle2::Particle
Class to store reconstructed particles.
Definition: Particle.h:77
Belle2::RestOfEvent::getTracks
std::vector< const Track * > getTracks(const std::string &maskName="") const
Get vector of all (no mask) or a subset (use mask) of all Tracks in ROE.
Definition: RestOfEvent.cc:308
Belle2::RestOfEvent::Mask::m_maskedParticleIndices
std::set< int > m_maskedParticleIndices
StoreArray indices for masked ROE particles.
Definition: RestOfEvent.h:173
Belle2::RestOfEvent::isInParticleList
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:471
Belle2::RestOfEvent::getECLClusters
std::vector< const ECLCluster * > getECLClusters(const std::string &maskName="") const
Get vector of all (no mask) or a subset (use mask) of all ECLClusters in ROE.
Definition: RestOfEvent.cc:319
Belle2::RestOfEvent::m_particleIndices
std::set< int > m_particleIndices
StoreArray indices to unused particles.
Definition: RestOfEvent.h:392
Belle2::RestOfEvent::print
void print() const
Prints the contents of a RestOfEvent object to screen.
Definition: RestOfEvent.cc:492
Belle2::RestOfEvent::addParticles
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:27
Belle2::RestOfEvent::Mask::addV0
void addV0(const Particle *v0, std::vector< int > &toErase)
Get selected particles associated to the V0 of mask.
Definition: RestOfEvent.h:129
Belle2::RestOfEvent::updateMaskWithV0
void updateMaskWithV0(const std::string &name, const Particle *particleV0)
Update mask with composite particle.
Definition: RestOfEvent.cc:216
Belle2::RestOfEvent::Mask::m_origin
std::string m_origin
Mask origin for debug.
Definition: RestOfEvent.h:171
Belle2::RestOfEvent::findMask
Mask * findMask(const std::string &name)
Helper method to find ROE mask.
Definition: RestOfEvent.cc:298
Belle2::RestOfEvent::getChargedParticles
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
Belle2::RelationsInterface
Defines interface for accessing relations of objects in StoreArray.
Definition: RelationsObject.h:102
Belle2::RestOfEvent::getNKLMClusters
int getNKLMClusters(const std::string &maskName="") const
Get number of all remaining KLM clusters.
Definition: RestOfEvent.cc:353
Belle2::RestOfEvent::Mask
Structure of Rest of Event mask.
Definition: RestOfEvent.h:69