Belle II Software light-2406-ragdoll
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
18namespace 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"),
163 m_antiList(nullptr),
164 m_isReserved(false)
165 {
166 }
167
169
180 void initialize(int pdg, const std::string& name, const std::string& particleStoreName = "Particles");
181
189 void bindAntiParticleList(ParticleList& antiList, bool includingAntiList = true);
190
197 void setParticleCollectionName(const std::string& name, bool forAntiParticle = true);
198
208 void addParticle(const Particle* particle);
209
218 void addParticle(unsigned iparticle, int pdg, Particle::EFlavorType flavorType, bool includingAntiList = true);
219
226 void removeParticles(const std::vector<unsigned int>& toRemove, bool removeFromAntiList = true);
227
229 void clear(bool includingAntiList = true);
230
234 std::string getParticleCollectionName() const {return m_particleStore;}
235
239 int getPDGCode() const {return m_pdg; }
240
244 int getAntiParticlePDGCode() const { return m_pdgbar; }
245
267 const std::vector<int>& getList(EParticleType K, bool forAntiParticle = false) const;
268
272 std::string getAntiParticleListName() const { return m_antiListName; }
273
277 std::string getParticleListName() const { return m_thisListName; }
278
285 unsigned getListSize(bool includingAntiList = true) const;
286
293 Particle* getParticle(unsigned i, bool includingAntiList = true) const;
294
301 Particle* getParticleWithMdstIdx(unsigned int mdstIdx, bool includingAntiList = true) const;
302
310 unsigned getNParticlesOfType(EParticleType K, bool forAntiParticle = false) const
311 {
312 return getList(K, forAntiParticle).size();
313 }
314
319 bool contains(const Particle* p, bool includingAntiList = true) const;
320
326 int getIndex(const Particle* p, bool includingAntiList = true) const;
327
331 void print() const;
332
336 void setEditable(bool editable, bool includingAntiList = true)
337 {
338 m_isReserved = !editable;
339 if (includingAntiList and !m_antiListName.empty())
340 getAntiParticleList().setEditable(editable, false);
341 };
342
346 bool getIsReserved() const { return m_isReserved; };
347
348
350 std::string getInfoHTML() const;
351
353 iterator begin() { return iterator(this, 0); }
355 iterator end() { return iterator(this, getListSize()); }
356
358 const_iterator begin() const { return const_iterator(this, 0); }
360 const_iterator end() const { return const_iterator(this, getListSize()); }
361
363 Particle* operator[](int index) const {return getParticle(index);}
364
365 private:
372
373 int m_pdg;
375 std::vector<int> m_fsList;
376 std::vector<int>
379 std::string m_particleStore;
381 std::string m_thisListName;
382 std::string m_antiListName;
386
387 bool m_isReserved = false;
391 friend class ParticleSubset;
392 };
393
395} // end namespace Belle2
Generic iterator class for arrays, allowing use of STL algorithms, range-based for etc.
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:74
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:239
std::string m_antiListName
name of ParticleList for anti-particles
Definition: ParticleList.h:382
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:358
int getAntiParticlePDGCode() const
Returns PDG code of anti-particle.
Definition: ParticleList.h:244
void addParticle(const Particle *particle)
Adds a new particle to the list (safe method)
Definition: ParticleList.cc:52
bool getIsReserved() const
Returns m_isReserved.
Definition: ParticleList.h:346
bool m_isReserved
transient
Definition: ParticleList.h:387
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:234
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.
ClassDef(ParticleList, 4)
Class to hold a list of particles, anti-particles and self-conjugated particles.
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 setEditable(bool editable, bool includingAntiList=true)
Sets m_isReserved so that the reserved list can be edited.
Definition: ParticleList.h:336
void setParticleCollectionName(const std::string &name, bool forAntiParticle=true)
Sets Particle store array name to which particle list refers.
Definition: ParticleList.cc:44
int m_pdg
PDG code of Particle.
Definition: ParticleList.h:373
std::string m_particleStore
name of Particle store array
Definition: ParticleList.h:379
std::string getAntiParticleListName() const
Returns the name the anti-particle ParticleList.
Definition: ParticleList.h:272
int getIndex(const Particle *p, bool includingAntiList=true) const
Returns index of the given particle 'p' in this list.
std::string m_thisListName
name of this ParticleList
Definition: ParticleList.h:381
Particle * operator[](int index) const
Convenience function to get particle with index.
Definition: ParticleList.h:363
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:385
std::vector< int > m_fsList
list of 0-based indices of flavor-specific Particles (particles that have an anti-particle)
Definition: ParticleList.h:375
std::string getParticleListName() const
Returns the name this ParticleList.
Definition: ParticleList.h:277
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:310
int m_pdgbar
PDG code of antiparticle.
Definition: ParticleList.h:374
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:355
const_iterator end() const
Return const_iterator to last entry +1.
Definition: ParticleList.h:360
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:353
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:377
Particle * getParticleWithMdstIdx(unsigned int mdstIdx, bool includingAntiList=true) const
Returns the particle from the list matching the given mdst array index, if any is found.
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:75
EFlavorType
describes flavor type, see getFlavorType().
Definition: Particle.h:94
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24