Belle II Software  release-06-02-00
ParticleList.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 
11 #include <analysis/dataobjects/Particle.h>
12 #include <framework/utilities/ArrayIterator.h>
13 
14 #include <TObject.h>
15 #include <vector>
16 
17 
18 namespace Belle2 {
23  template <class T> class StoreObjPtr;
24 
140  class ParticleList : public TObject {
141  public:
142 
147 
150  c_FlavorSpecificParticle = 0,
151  c_SelfConjugatedParticle
152  };
153 
158  m_pdg(0),
159  m_pdgbar(0),
160  m_particleStore("Particles"),
161  m_thisListName(),
162  m_antiListName(),
163  m_antiList(nullptr)
164  {
165  }
166 
167  ~ParticleList();
168 
179  void initialize(int pdg, const std::string& name, const std::string& particleStoreName = "Particles");
180 
188  void bindAntiParticleList(ParticleList& antiList, bool includingAntiList = true);
189 
196  void setParticleCollectionName(const std::string& name, bool forAntiParticle = true);
197 
207  void addParticle(const Particle* particle);
208 
217  void addParticle(unsigned iparticle, int pdg, Particle::EFlavorType flavorType, bool includingAntiList = true);
218 
225  void removeParticles(const std::vector<unsigned int>& toRemove, bool removeFromAntiList = true);
226 
228  void clear(bool includingAntiList = true);
229 
233  std::string getParticleCollectionName() const {return m_particleStore;}
234 
238  int getPDGCode() const {return m_pdg; }
239 
243  int getAntiParticlePDGCode() const { return m_pdgbar; }
244 
266  const std::vector<int>& getList(EParticleType K, bool forAntiParticle = false) const;
267 
271  std::string getAntiParticleListName() const { return m_antiListName; }
272 
276  std::string getParticleListName() const { return m_thisListName; }
277 
284  unsigned getListSize(bool includingAntiList = true) const;
285 
292  Particle* getParticle(unsigned i, bool includingAntiList = true) const;
293 
301  unsigned getNParticlesOfType(EParticleType K, bool forAntiParticle = false) const
302  {
303  return getList(K, forAntiParticle).size();
304  }
305 
310  bool contains(const Particle* p, bool includingAntiList = true) const;
311 
315  void print() const;
316 
318  std::string getInfoHTML() const;
319 
321  iterator begin() { return iterator(this, 0); }
323  iterator end() { return iterator(this, getListSize()); }
324 
326  const_iterator begin() const { return const_iterator(this, 0); }
328  const_iterator end() const { return const_iterator(this, getListSize()); }
329 
331  Particle* operator[](int index) const {return getParticle(index);}
332 
333  private:
340 
341  int m_pdg;
342  int m_pdgbar;
343  std::vector<int> m_fsList;
344  std::vector<int>
347  std::string m_particleStore;
349  std::string m_thisListName;
350  std::string m_antiListName;
354 
357  friend class ParticleSubset;
358  };
359 
361 } // end namespace Belle2
Generic iterator class for arrays, allowing use of STL algorithms, range-based for etc.
Definition: ArrayIterator.h:86
ParticleList is a container class that stores a collection of Particle objects.
Definition: ParticleList.h:140
void bindAntiParticleList(ParticleList &antiList, bool includingAntiList=true)
Binds particle and anti-particle ParticleLists.
Definition: ParticleList.cc:66
ArrayIterator< ParticleList, Particle > iterator
STL-like iterator over the particles (not Particle*).
Definition: ParticleList.h:144
int getPDGCode() const
Returns PDG code.
Definition: ParticleList.h:238
Particle * operator[](int index) const
Convenience function to get particle with index.
Definition: ParticleList.h:331
std::string m_antiListName
name of ParticleList for anti-particles
Definition: ParticleList.h:350
Particle * getParticle(unsigned i, bool includingAntiList=true) const
Returns i-th particle from the list and anti list if requested.
const_iterator begin() const
Return const_iterator to first entry.
Definition: ParticleList.h:326
int getAntiParticlePDGCode() const
Returns PDG code of anti-particle.
Definition: ParticleList.h:243
void addParticle(const Particle *particle)
Adds a new particle to the list (safe method)
Definition: ParticleList.cc:48
bool contains(const Particle *p, bool includingAntiList=true) const
Returns true if and only if 'p' is already in this list.
std::string getParticleCollectionName() const
Returns Particle store array name to which particle list refers.
Definition: ParticleList.h:233
const std::vector< int > & getList(EParticleType K, bool forAntiParticle=false) const
Returns list of StoreArray<Particle> indices.
ParticleList & getAntiParticleList() const
Returns bound anti-particle list.
unsigned getListSize(bool includingAntiList=true) const
Returns total number of particles in this list and anti list if requested.
ParticleList()
Default constructor.
Definition: ParticleList.h:157
void setParticleCollectionName(const std::string &name, bool forAntiParticle=true)
Sets Particle store array name to which particle list refers.
Definition: ParticleList.cc:40
int m_pdg
PDG code of Particle.
Definition: ParticleList.h:341
std::string m_particleStore
name of Particle store array
Definition: ParticleList.h:347
std::string getAntiParticleListName() const
Returns the name the anti-particle ParticleList.
Definition: ParticleList.h:271
std::string m_thisListName
name of this ParticleList
Definition: ParticleList.h:349
void clear(bool includingAntiList=true)
Remove all elements from list, afterwards getListSize() will be 0.
StoreObjPtr< ParticleList > * m_antiList
keep anti-list around for performance.
Definition: ParticleList.h:353
std::vector< int > m_fsList
list of 0-based indices of flavor-specific Particles (particles that have an anti-particle)
Definition: ParticleList.h:343
std::string getParticleListName() const
Returns the name this ParticleList.
Definition: ParticleList.h:276
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:301
ClassDef(ParticleList, 3)
transient
int m_pdgbar
PDG code of antiparticle.
Definition: ParticleList.h:342
EParticleType
Type of Particle (determines in which of the two internal lists the particle is stored).
Definition: ParticleList.h:149
iterator end()
Return iterator to last entry +1.
Definition: ParticleList.h:323
const_iterator end() const
Return const_iterator to last entry +1.
Definition: ParticleList.h:328
void print() const
Prints the list.
std::string getInfoHTML() const
Return a short summary of this object's contents in HTML format.
iterator begin()
Return iterator to first entry.
Definition: ParticleList.h:321
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:345
ArrayIterator< ParticleList, const Particle > const_iterator
STL-like const_iterator over the particles (not Particle*).
Definition: ParticleList.h:146
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:30
void removeParticles(const std::vector< unsigned int > &toRemove, bool removeFromAntiList=true)
Remove given elements from list.
Specialised SelectSubset<Particle> that also fixes daughter indices and all ParticleLists.
Class to store reconstructed particles.
Definition: Particle.h:74
EFlavorType
describes flavor type, see getFlavorType().
Definition: Particle.h:92
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
Abstract base class for different kinds of events.