Belle II Software  development
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...
 
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.
 
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, 3)
 transient More...
 

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.
 

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);
void bindAntiParticleList(ParticleList &antiList, bool includingAntiList=true)
Binds particle and anti-particle ParticleLists.
Definition: ParticleList.cc:66
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 48 of file ParticleList.cc.

49 {
50  if (particle->getArrayName() != m_particleStore) {
51  B2ERROR("ParticleList::addParticle particle is from different store array, not added");
52  return;
53  }
54 
55  int iparticle = particle->getArrayIndex();
56  if (iparticle < 0) {
57  B2ERROR("ParticleList::addParticle particle is not in a store array, not added");
58  return;
59  }
60 
61  int pdg = particle->getPDGCode();
62  Particle::EFlavorType type = particle->getFlavorType();
63  addParticle((unsigned) iparticle, pdg, type, true);
64 }
void addParticle(const Particle *particle)
Adds a new particle to the list (safe method)
Definition: ParticleList.cc:48
std::string m_particleStore
name of Particle store array
Definition: ParticleList.h:354
EFlavorType
describes flavor type, see getFlavorType().
Definition: Particle.h:92

◆ 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 78 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 66 of file ParticleList.cc.

◆ ClassDef()

ClassDef ( ParticleList  ,
 
)
private

transient

Class to hold a list of particles, anti-particles and self-conjugated particles.

◆ clear()

void clear ( bool  includingAntiList = true)

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


Definition at line 142 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 202 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 261 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 216 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 186 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 169 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 301 of file ParticleList.h.

302  {
303  return getList(K, forAntiParticle).size();
304  }
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 152 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 119 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 40 of file ParticleList.cc.


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