Belle II Software  release-08-01-10
ParticleList Class Reference

ParticleList is a container class that stores a collection of Particle objects. More...

#include <ParticleList.h>

Inheritance diagram for ParticleList:
Collaboration diagram for ParticleList:

Public Types

enum  EParticleType {
  c_FlavorSpecificParticle = 0 ,
  c_SelfConjugatedParticle
}
 Type of Particle (determines in which of the two internal lists the particle is stored).
 
typedef ArrayIterator< ParticleList, Particleiterator
 STL-like iterator over the particles (not Particle*).
 
typedef ArrayIterator< ParticleList, const Particleconst_iterator
 STL-like const_iterator over the particles (not Particle*).
 

Public Member Functions

 ParticleList ()
 Default constructor.
 
void initialize (int pdg, const std::string &name, const std::string &particleStoreName="Particles")
 Sets the PDG code and name of this ParticleList. More...
 
void bindAntiParticleList (ParticleList &antiList, bool includingAntiList=true)
 Binds particle and anti-particle ParticleLists. More...
 
void setParticleCollectionName (const std::string &name, bool forAntiParticle=true)
 Sets Particle store array name to which particle list refers. More...
 
void addParticle (const Particle *particle)
 Adds a new particle to the list (safe method) More...
 
void addParticle (unsigned iparticle, int pdg, Particle::EFlavorType flavorType, bool includingAntiList=true)
 Adds a new particle to the list (almost safe method) More...
 
void removeParticles (const std::vector< unsigned int > &toRemove, bool removeFromAntiList=true)
 Remove given elements from list. More...
 
void clear (bool includingAntiList=true)
 Remove all elements from list, afterwards getListSize() will be 0. More...
 
std::string getParticleCollectionName () const
 Returns Particle store array name to which particle list refers.
 
int getPDGCode () const
 Returns PDG code.
 
int getAntiParticlePDGCode () const
 Returns PDG code of anti-particle.
 
const std::vector< int > & getList (EParticleType K, bool forAntiParticle=false) const
 Returns list of StoreArray<Particle> indices. More...
 
std::string getAntiParticleListName () const
 Returns the name the anti-particle ParticleList.
 
std::string getParticleListName () const
 Returns the name this ParticleList.
 
unsigned getListSize (bool includingAntiList=true) const
 Returns total number of particles in this list and anti list if requested. More...
 
ParticlegetParticle (unsigned i, bool includingAntiList=true) const
 Returns i-th particle from the list and anti list if requested. More...
 
ParticlegetParticleWithMdstIdx (unsigned int mdstIdx, bool includingAntiList=true) const
 Returns the particle from the list matching the given mdst array index, if any is found. More...
 
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-particle list. More...
 
bool contains (const Particle *p, bool includingAntiList=true) const
 Returns true if and only if 'p' is already in this list. More...
 
int getIndex (const Particle *p, bool includingAntiList=true) const
 Returns index of the given particle 'p' in this list. More...
 
void print () const
 Prints the list.
 
void setEditable (bool editable, bool includingAntiList=true)
 Sets m_isReserved so that the reserved list can be edited.
 
bool getIsReserved () const
 Returns m_isReserved.
 
std::string getInfoHTML () const
 Return a short summary of this object's contents in HTML format.
 
iterator begin ()
 Return iterator to first entry.
 
iterator end ()
 Return iterator to last entry +1.
 
const_iterator begin () const
 Return const_iterator to first entry.
 
const_iterator end () const
 Return const_iterator to last entry +1.
 
Particleoperator[] (int index) const
 Convenience function to get particle with index.
 

Private Member Functions

ParticleListgetAntiParticleList () const
 Returns bound anti-particle list. More...
 
 ClassDef (ParticleList, 4)
 Class to hold a list of particles, anti-particles and self-conjugated particles.
 

Private Attributes

int m_pdg
 PDG code of Particle.
 
int m_pdgbar
 PDG code of antiparticle.
 
std::vector< int > m_fsList
 list of 0-based indices of flavor-specific Particles (particles that have an anti-particle)
 
std::vector< int > m_scList
 list of 0-based indices of self-conjugated Particles (particles that do not have an anti-particle)
 
std::string m_particleStore
 name of Particle store array
 
std::string m_thisListName
 name of this ParticleList
 
std::string m_antiListName
 name of ParticleList for anti-particles
 
StoreObjPtr< ParticleList > * m_antiList
 keep anti-list around for performance.
 
bool m_isReserved = false
 transient More...
 

Friends

class ParticleSubset
 

Detailed Description

ParticleList is a container class that stores a collection of Particle objects.

The particles are internally stored in two std::vector<int> holding the indices of particles in StoreArray<Particle>: o) flavor specific particles (particles that have an anti-particle, e.g. pi-, K-, D+, D0) o) self-conjugated particles (particles that do not have an anti-particle, e.g. pi0, phi, or particles that have an anti-particle but are reconstructed in self-conjugated decay mode, e.g. K*0 -> K0s pi0, or D0 -> K- K+, ...) ParticleList can store only particles with same PDG code (which however can be reconstructed in different decay modes).

Each ParticleList can and should be bound with its anti-ParticleList at the time of creation of the lists. This bond for example enables automatic reconstruction of charged conjugated decays in ParticleCombiner module for example.

The unique identifier of the ParticleList is its name. According to the naming convention the ParticleList's name has to be of the form:

listName = particle_name:label,

where particle_name is the name of the particle as given in the evt.pdl and the label can be any string indicating the selection criteria or decay mode (or anything else) used to reconstruct the particles. Examples are: o) pi+:loose - pi+ candidates passing loose PID requirements o) D0:kpi - D0 candidates reconstructed in D0->Kpi decays

Creating new ParticleList

Particles and their anti-particles are stored in their own ParticleLists. Creation and connection of particle and anti-particle lists is performed in the following way (example for K- and K+ lists):

\\ create ParticleList for particles (K+)
StoreObjPtr<ParticleList> pList("K+:all");
pList.create();
pList->initialize( 321, pList.getName());
\\ create ParticleList for anti-particles (K-)
StoreObjPtr<ParticleList> antipList("K-:all");
antipList.create();
antipList->initialize(-321, antipList.getName());
\\ bind the two lists together
pList->bindAntiParticleList(*antipList);
#define K(x)
macro autogenerated by FFTW
void bindAntiParticleList(ParticleList &antiList, bool includingAntiList=true)
Binds particle and anti-particle ParticleLists.
Definition: ParticleList.cc:74
ParticleList()
Default constructor.
Definition: ParticleList.h:157
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

Adding Particle to ParticleList

The following rules apply: o) ParticleList can contain only particles with same absolute value of the PDG code (e.g. only charged kaons, neutral D mesons, ...) o) All particles have to be stored in the same StoreArray<Particle>

Example:

pList->addParticle(particle);

where particle is a pointer to a Particle object. Note, if one adds anti-particle to ParticleLists for particles the particle will be actually added to the ParticleList for anti-particles. The following two lines of code give same result

// adding anti-particle Particle object to ParticleList for particles
pList->addParticle(antiParticle);
// is the same as if the anti-particle Particle object is added to the ParticleList for anti-particles
antiPlist->addParticle(antiParticle);

Accessing elements of ParticleList

To loop over all particles (as well as their anti-particles) do the following

const unsigned int n = pList->getListSize();
for (unsigned i = 0; i < n; i++) {
const Particle* particle = pList->getParticle(i);
// do something with the particle
particle->....
}

If you would like to loop over the particles stored in a particular ParticleList without including the anti-particles as well, do the following (set the boolean parameter in the relevant functions to false)

const unsigned int n = pList->getListSize(false);
for (unsigned i = 0; i < n; i++) {
const Particle* particle = pList->getParticle(i, false);
// do something with the particle
particle->....
}

You can also use C++11 range-based for loops to loop over all particles (and anti-particles):

for(const Particle& particle : *pList) {
// do something with the particle
}
Remember to dereference the StoreObjPtr<ParticleList> before you can use it in the range based for loop.
<h1>Remove Particles from ParticleList</h1>
Particles can be removed in the following way (as above, this action will by default be applied to list of
particles as well as to list for anti-particles):
\code
std::vector<unsigned int> toRemove;
const unsigned int n = pList->getListSize();
for (unsigned i = 0; i < n; i++) {
const Particle* part = pList->getParticle(i);
if (...particle should be removed...) toRemove.push_back(part->getArrayIndex());
}
pList->removeParticles(toRemove);

Definition at line 140 of file ParticleList.h.

Member Function Documentation

◆ addParticle() [1/2]

void addParticle ( const Particle particle)

Adds a new particle to the list (safe method)

The method determines based on the particle's properties (PDGcode, flavorType) to which particular list this particle belongs (flavor-specific or self-conjugated particle or anti-particle list)

Parameters
particlepointer to particle in the StoreArray<Particle>

Definition at line 52 of file ParticleList.cc.

53 {
54  if (m_isReserved)
55  B2FATAL("ParticleList::addParticle The ParticleList " << m_thisListName <<
56  " is reserved and forbidden to be manipulated.");
57 
58  if (particle->getArrayName() != m_particleStore) {
59  B2ERROR("ParticleList::addParticle particle is from different store array, not added");
60  return;
61  }
62 
63  int iparticle = particle->getArrayIndex();
64  if (iparticle < 0) {
65  B2ERROR("ParticleList::addParticle particle is not in a store array, not added");
66  return;
67  }
68 
69  int pdg = particle->getPDGCode();
70  Particle::EFlavorType type = particle->getFlavorType();
71  addParticle((unsigned) iparticle, pdg, type, true);
72 }
void addParticle(const Particle *particle)
Adds a new particle to the list (safe method)
Definition: ParticleList.cc:52
bool m_isReserved
transient
Definition: ParticleList.h:387
std::string m_particleStore
name of Particle store array
Definition: ParticleList.h:379
std::string m_thisListName
name of this ParticleList
Definition: ParticleList.h:381
EFlavorType
describes flavor type, see getFlavorType().
Definition: Particle.h:94

◆ addParticle() [2/2]

void addParticle ( unsigned  iparticle,
int  pdg,
Particle::EFlavorType  flavorType,
bool  includingAntiList = true 
)

Adds a new particle to the list (almost safe method)

Parameters
iparticleindex of the particle in the StoreArray<Particle>
pdgparticle PDG code
flavorTypeparticle flavor type
includingAntiListinclude anti-particle list?

Definition at line 86 of file ParticleList.cc.

◆ bindAntiParticleList()

void bindAntiParticleList ( ParticleList antiList,
bool  includingAntiList = true 
)

Binds particle and anti-particle ParticleLists.

After the lists are bound any action performed on ParticleList for particles will be performed by default also on ParticleList for anti-particles.

Parameters
antiList- anti-particle ParticleList of this ParticleList
includingAntiList- the "anti"-anti-particle list has to be set also for the anti-particle list

Definition at line 74 of file ParticleList.cc.

◆ clear()

void clear ( bool  includingAntiList = true)

Remove all elements from list, afterwards getListSize() will be 0.


Definition at line 158 of file ParticleList.cc.

◆ contains()

bool contains ( const Particle p,
bool  includingAntiList = true 
) const

Returns true if and only if 'p' is already in this list.

Will check flavour-specific and self-conjugated list, and optionally (with includingAntiList=true) also the anti-particle list.

Definition at line 236 of file ParticleList.cc.

◆ getAntiParticleList()

ParticleList & getAntiParticleList ( ) const
private

Returns bound anti-particle list.

Aborts if no list is present (might occur with I/O problems). Please check m_antiListName is not empty() before calling this.

Definition at line 295 of file ParticleList.cc.

◆ getIndex()

int getIndex ( const Particle p,
bool  includingAntiList = true 
) const

Returns index of the given particle 'p' in this list.

If 'p' is not in this list, return -1. Will check flavour-specific and self-conjugated list, and optionally (with includingAntiList=true) also the anti-particle list.

Definition at line 250 of file ParticleList.cc.

◆ getList()

const std::vector< int > & getList ( EParticleType  K,
bool  forAntiParticle = false 
) const

Returns list of StoreArray<Particle> indices.

Possible options are:

o) getList(ParticleList::c_FlavorSpecificParticle)

  • returns the vector of flavor-specific particles stored in this list

o) getList(ParticleList::c_SelfConjugatedParticle)

  • returns the vector of self-conjugated particles stored in this list

o) getList(ParticleList::c_FlavorSpecificParticle, true)

  • returns the vector of flavor-specific anti-particles stored in the anti-particle ParticleList of this list

o) getList(ParticleList::c_SelfConjugatedParticle, true)

  • this is equivalent to getList(ParticleList::c_SelfConjugatedParticle)
Parameters
KParticleType - Particle, SelfConjugatedParticle
forAntiParticle- whether the Particle or SelfConjugatedParticle should be returned for this (false) or anti-particle list (true)
Returns
const reference to vector of indices

Definition at line 220 of file ParticleList.cc.

◆ getListSize()

unsigned getListSize ( bool  includingAntiList = true) const

Returns total number of particles in this list and anti list if requested.

Parameters
includingAntiList
Returns
size of the this (+ anti-particle) list

Definition at line 203 of file ParticleList.cc.

◆ getNParticlesOfType()

unsigned getNParticlesOfType ( EParticleType  K,
bool  forAntiParticle = false 
) const
inline

Returns the number of flavor-specific particles or self-conjugated particles in this list or its anti-particle list.

Parameters
KParticleType - Particle or SelfConjugatedParticle
forAntiParticle- whether the Particle or SelfConjugatedParticle should be returned for this (false) or anti-particle list (true)
Returns
number of particles or self-conjugated particles in the list or anti-particle list

Definition at line 310 of file ParticleList.h.

311  {
312  return getList(K, forAntiParticle).size();
313  }
const std::vector< int > & getList(EParticleType K, bool forAntiParticle=false) const
Returns list of StoreArray<Particle> indices.

◆ getParticle()

Particle * getParticle ( unsigned  i,
bool  includingAntiList = true 
) const

Returns i-th particle from the list and anti list if requested.

Parameters
ilist index (i < getListSize())
includingAntiListconsider anti-particle list as well?
Returns
pointer to Particle or NULL

Definition at line 172 of file ParticleList.cc.

◆ getParticleWithMdstIdx()

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.

Parameters
mdstIdxmdst array index
includingAntiListconsider anti-particle list as well?
Returns
pointer to Particle or NULL if no match is found.

Definition at line 189 of file ParticleList.cc.

◆ initialize()

void initialize ( int  pdg,
const std::string &  name,
const std::string &  particleStoreName = "Particles" 
)

Sets the PDG code and name of this ParticleList.

At this point it is assumed that this is self-conjugated list (PDG code = anti-PDG code). To bind the particle and anti-particle ParticleLists use bindAntiParticleList(ParticleList &antiList) method.

Parameters
pdgPDG code of particles to be hold in this list
nameof the particle list
particleStoreNamename of the Particle StoreArray

Definition at line 30 of file ParticleList.cc.

◆ removeParticles()

void removeParticles ( const std::vector< unsigned int > &  toRemove,
bool  removeFromAntiList = true 
)

Remove given elements from list.

Parameters
toRemovevector of Particle array indices to be removed
removeFromAntiListflag indicating whether to remove particle also from anti-particle list (default is true)

Definition at line 131 of file ParticleList.cc.

◆ setParticleCollectionName()

void setParticleCollectionName ( const std::string &  name,
bool  forAntiParticle = true 
)

Sets Particle store array name to which particle list refers.

By default this parameter is set to "Particles".

Parameters
namename of the Particle store array
forAntiParticleif true the name is set also for the anti-particle list

Definition at line 44 of file ParticleList.cc.

Member Data Documentation

◆ m_isReserved

bool m_isReserved = false
private

transient

True if the list name is reserved

Definition at line 387 of file ParticleList.h.


The documentation for this class was generated from the following files: