Belle II Software  release-05-02-19
ParticleList.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric, Anze Zupanc *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <analysis/dataobjects/Particle.h>
14 #include <framework/utilities/ArrayIterator.h>
15 
16 #include <TObject.h>
17 #include <vector>
18 
19 
20 namespace Belle2 {
25  template <class T> class StoreObjPtr;
26 
142  class ParticleList : public TObject {
143  public:
144 
146  typedef ArrayIterator<ParticleList, Particle> iterator;
148  typedef ArrayIterator<ParticleList, const Particle> const_iterator;
149 
151  enum EParticleType {
152  c_FlavorSpecificParticle = 0,
153  c_SelfConjugatedParticle
154  };
155 
160  m_pdg(0),
161  m_pdgbar(0),
162  m_particleStore("Particles"),
163  m_thisListName(),
164  m_antiListName(),
165  m_antiList(nullptr)
166  {
167  }
168 
169  ~ParticleList();
170 
181  void initialize(int pdg, const std::string& name, const std::string& particleStoreName = "Particles");
182 
190  void bindAntiParticleList(ParticleList& antiList, bool includingAntiList = true);
191 
198  void setParticleCollectionName(const std::string& name, bool forAntiParticle = true);
199 
209  void addParticle(const Particle* particle);
210 
219  void addParticle(unsigned iparticle, int pdg, Particle::EFlavorType flavorType, bool includingAntiList = true);
220 
227  void removeParticles(const std::vector<unsigned int>& toRemove, bool removeFromAntiList = true);
228 
230  void clear(bool includingAntiList = true);
231 
235  std::string getParticleCollectionName() const {return m_particleStore;}
236 
240  int getPDGCode() const {return m_pdg; }
241 
245  int getAntiParticlePDGCode() const { return m_pdgbar; }
246 
268  const std::vector<int>& getList(EParticleType K, bool forAntiParticle = false) const;
269 
273  std::string getAntiParticleListName() const { return m_antiListName; }
274 
278  std::string getParticleListName() const { return m_thisListName; }
279 
286  unsigned getListSize(bool includingAntiList = true) const;
287 
294  Particle* getParticle(unsigned i, bool includingAntiList = true) const;
295 
303  unsigned getNParticlesOfType(EParticleType K, bool forAntiParticle = false) const
304  {
305  return getList(K, forAntiParticle).size();
306  }
307 
312  bool contains(const Particle* p, bool includingAntiList = true) const;
313 
317  void print() const;
318 
320  std::string getInfoHTML() const;
321 
323  iterator begin() { return iterator(this, 0); }
325  iterator end() { return iterator(this, getListSize()); }
326 
328  const_iterator begin() const { return const_iterator(this, 0); }
330  const_iterator end() const { return const_iterator(this, getListSize()); }
331 
333  Particle* operator[](int index) const {return getParticle(index);}
334 
335  private:
342 
343  int m_pdg;
344  int m_pdgbar;
345  std::vector<int> m_fsList;
346  std::vector<int>
347  m_scList;
349  std::string m_particleStore;
351  std::string m_thisListName;
352  std::string m_antiListName;
356 
359  friend class ParticleSubset;
360  };
361 
363 } // end namespace Belle2
Belle2::ParticleList::setParticleCollectionName
void setParticleCollectionName(const std::string &name, bool forAntiParticle=true)
Sets Particle store array name to which particle list refers.
Definition: ParticleList.cc:42
Belle2::ParticleList::begin
iterator begin()
Return iterator to first entry.
Definition: ParticleList.h:331
Belle2::ParticleList::m_fsList
std::vector< int > m_fsList
list of 0-based indices of flavor-specific Particles (particles that have an anti-particle)
Definition: ParticleList.h:353
Belle2::ParticleList
ParticleList is a container class that stores a collection of Particle objects.
Definition: ParticleList.h:150
Belle2::ParticleList::contains
bool contains(const Particle *p, bool includingAntiList=true) const
Returns true if and only if 'p' is already in this list.
Definition: ParticleList.cc:204
Belle2::ParticleList::m_thisListName
std::string m_thisListName
name of this ParticleList
Definition: ParticleList.h:359
Belle2::ParticleList::m_pdg
int m_pdg
PDG code of Particle.
Definition: ParticleList.h:351
Belle2::ParticleList::operator[]
Particle * operator[](int index) const
Convenience function to get particle with index.
Definition: ParticleList.h:341
Belle2::ParticleList::print
void print() const
Prints the list.
Definition: ParticleList.cc:218
Belle2::ParticleList::ParticleList
ParticleList()
Default constructor.
Definition: ParticleList.h:167
Belle2::ParticleList::m_antiListName
std::string m_antiListName
name of ParticleList for anti-particles
Definition: ParticleList.h:360
Belle2::ParticleList::iterator
ArrayIterator< ParticleList, Particle > iterator
STL-like iterator over the particles (not Particle*).
Definition: ParticleList.h:154
Belle2::ParticleList::EParticleType
EParticleType
Type of Particle (determines in which of the two internal lists the particle is stored).
Definition: ParticleList.h:159
Belle2::ParticleList::ClassDef
ClassDef(ParticleList, 3)
transient
Belle2::ParticleList::getAntiParticleListName
std::string getAntiParticleListName() const
Returns the name the anti-particle ParticleList.
Definition: ParticleList.h:281
Belle2::ParticleList::end
iterator end()
Return iterator to last entry +1.
Definition: ParticleList.h:333
Belle2::ParticleList::bindAntiParticleList
void bindAntiParticleList(ParticleList &antiList, bool includingAntiList=true)
Binds particle and anti-particle ParticleLists.
Definition: ParticleList.cc:68
Belle2::Particle::EFlavorType
EFlavorType
describes flavor type, see getFlavorType().
Definition: Particle.h:95
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ParticleList::m_antiList
StoreObjPtr< ParticleList > * m_antiList
keep anti-list around for performance.
Definition: ParticleList.h:363
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::ParticleList::const_iterator
ArrayIterator< ParticleList, const Particle > const_iterator
STL-like const_iterator over the particles (not Particle*).
Definition: ParticleList.h:156
Belle2::ParticleList::clear
void clear(bool includingAntiList=true)
Remove all elements from list, afterwards getListSize() will be 0.
Definition: ParticleList.cc:144
Belle2::ParticleSubset
Specialised SelectSubset<Particle> that also fixes daughter indices and all ParticleLists.
Definition: ParticleSubset.h:15
Belle2::ParticleList::getAntiParticlePDGCode
int getAntiParticlePDGCode() const
Returns PDG code of anti-particle.
Definition: ParticleList.h:253
Belle2::ParticleList::initialize
void initialize(int pdg, const std::string &name, const std::string &particleStoreName="Particles")
Sets the PDG code and name of this ParticleList.
Definition: ParticleList.cc:32
Belle2::ParticleList::getListSize
unsigned getListSize(bool includingAntiList=true) const
Returns total number of particles in this list and anti list if requested.
Definition: ParticleList.cc:171
Belle2::ParticleList::m_pdgbar
int m_pdgbar
PDG code of antiparticle.
Definition: ParticleList.h:352
Belle2::ParticleList::getNParticlesOfType
unsigned getNParticlesOfType(EParticleType K, bool forAntiParticle=false) const
Returns the number of flavor-specific particles or self-conjugated particles in this list or its anti...
Definition: ParticleList.h:311
Belle2::Particle
Class to store reconstructed particles.
Definition: Particle.h:77
Belle2::ParticleList::m_scList
std::vector< int > m_scList
list of 0-based indices of self-conjugated Particles (particles that do not have an anti-particle)
Definition: ParticleList.h:355
Belle2::ParticleList::getList
const std::vector< int > & getList(EParticleType K, bool forAntiParticle=false) const
Returns list of StoreArray<Particle> indices.
Definition: ParticleList.cc:188
Belle2::ParticleList::m_particleStore
std::string m_particleStore
name of Particle store array
Definition: ParticleList.h:357
Belle2::ParticleList::getParticleListName
std::string getParticleListName() const
Returns the name this ParticleList.
Definition: ParticleList.h:286
Belle2::ParticleList::addParticle
void addParticle(const Particle *particle)
Adds a new particle to the list (safe method)
Definition: ParticleList.cc:50
Belle2::ParticleList::getAntiParticleList
ParticleList & getAntiParticleList() const
Returns bound anti-particle list.
Definition: ParticleList.cc:240
Belle2::ParticleList::getInfoHTML
std::string getInfoHTML() const
Return a short summary of this object's contents in HTML format.
Definition: ParticleList.cc:223
Belle2::ParticleList::getParticleCollectionName
std::string getParticleCollectionName() const
Returns Particle store array name to which particle list refers.
Definition: ParticleList.h:243
Belle2::ParticleList::getParticle
Particle * getParticle(unsigned i, bool includingAntiList=true) const
Returns i-th particle from the list and anti list if requested.
Definition: ParticleList.cc:154
Belle2::ParticleList::removeParticles
void removeParticles(const std::vector< unsigned int > &toRemove, bool removeFromAntiList=true)
Remove given elements from list.
Definition: ParticleList.cc:121
Belle2::ParticleList::getPDGCode
int getPDGCode() const
Returns PDG code.
Definition: ParticleList.h:248