Belle II Software development
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
273 {
274 return m_antiListName;
275 }
276
280 std::string getParticleListName() const
281 {
282 return m_thisListName;
283 }
284
291 unsigned getListSize(bool includingAntiList = true) const;
292
299 Particle* getParticle(unsigned i, bool includingAntiList = true) const;
300
308 Particle* getParticleWithMdstIdx(unsigned int mdstIdx, bool includingAntiList = true) const;
309
316 Particle* getParticleWithMdstSource(int mdstSource, bool includingAntiList = true) const;
317
325 unsigned getNParticlesOfType(EParticleType K, bool forAntiParticle = false) const
326 {
327 return getList(K, forAntiParticle).size();
328 }
329
334 bool contains(const Particle* p, bool includingAntiList = true) const;
335
341 int getIndex(const Particle* p, bool includingAntiList = true) const;
342
346 void print() const;
347
351 void setEditable(bool editable, bool includingAntiList = true)
352 {
353 m_isReserved = !editable;
354 if (includingAntiList and !m_antiListName.empty())
355 getAntiParticleList().setEditable(editable, false);
356 };
357
361 bool getIsReserved() const { return m_isReserved; };
362
363
365 std::string getInfoHTML() const;
366
368 iterator begin() { return iterator(this, 0); }
370 iterator end() { return iterator(this, getListSize()); }
371
373 const_iterator begin() const { return const_iterator(this, 0); }
375 const_iterator end() const { return const_iterator(this, getListSize()); }
376
378 Particle* operator[](int index) const {return getParticle(index);}
379
380 private:
387
388 int m_pdg;
395 std::vector<int> m_fsList;
396
401 std::vector<int> m_scList;
402
403 std::string m_particleStore;
405 std::string m_thisListName;
406 std::string m_antiListName;
410
411 bool m_isReserved = false;
415 friend class ParticleSubset;
416 };
417
419} // end namespace Belle2
#define K(x)
macro autogenerated by FFTW
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:73
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
Particle * getParticleWithMdstSource(int mdstSource, bool includingAntiList=true) const
Returns the particle from the list matching the given mdst source, if any is found.
std::string m_antiListName
name of ParticleList for anti-particles
Definition: ParticleList.h:406
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:373
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:51
bool getIsReserved() const
Returns m_isReserved.
Definition: ParticleList.h:361
bool m_isReserved
transient
Definition: ParticleList.h:411
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:351
void setParticleCollectionName(const std::string &name, bool forAntiParticle=true)
Sets Particle store array name to which particle list refers.
Definition: ParticleList.cc:43
int m_pdg
PDG code of Particle.
Definition: ParticleList.h:388
std::string m_particleStore
name of Particle store array
Definition: ParticleList.h:403
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:405
Particle * operator[](int index) const
Convenience function to get particle with index.
Definition: ParticleList.h:378
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:409
std::vector< int > m_fsList
List of 0-based indices of flavor-specific Particles (particles that have an anti-particle).
Definition: ParticleList.h:395
std::string getParticleListName() const
Returns the name this ParticleList.
Definition: ParticleList.h:280
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:325
int m_pdgbar
PDG code of antiparticle.
Definition: ParticleList.h:389
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:370
const_iterator end() const
Return const_iterator to last entry +1.
Definition: ParticleList.h:375
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:368
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:401
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:29
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:76
EFlavorType
describes flavor type, see getFlavorType().
Definition: Particle.h:96
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
Abstract base class for different kinds of events.