Belle II Software light-2406-ragdoll
Const::ParticleSet Class Reference

A set of ParticleType objects, with defined order. More...

#include <Const.h>

Collaboration diagram for Const::ParticleSet:

Public Member Functions

 ParticleSet ()=default
 Emtpy constructor.
 
 ParticleSet (const ParticleSet &other)
 Copy constructor to make sure particles belong to correct set.
 
ParticleSetoperator= (const ParticleSet &other)
 Assignment operator.
 
void add (const ParticleType &p)
 Add a copy of the given ParticleType to this set.
 
bool contains (const ParticleType &p) const
 Returns true if and only if the set contains 'p'.
 
unsigned int size () const
 Returns number of particles in this set.
 
const ParticleTypeat (unsigned int index) const
 Return particle at given index, or end() if out of range.
 
ParticleType begin () const
 Returns first particle.
 
ParticleType end () const
 Returns an invalid particle to check if iteration should be stopped.
 
const ParticleTypefind (int pdg) const
 Returns particle in set with given PDG code, or invalidParticle if not found.
 

Private Attributes

std::vector< ParticleTypem_particles
 Actual particles.
 

Detailed Description

A set of ParticleType objects, with defined order.

Allows easy iteration over a set of particles, e.g. to print indices and PDG codes:

B2INFO("index -> PDG code");
//via range-based for
for(const Const::ChargedStable& pdgIter : set) {
B2INFO(pdgIter.getIndex() << " -> " << pdgIter.getPDGCode());
}
//or, using iterator syntax:
for(Const::ChargedStable pdgIter = set.begin(); pdgIter != set.end(); ++pdgIter) {
B2INFO(pdgIter.getIndex() << " -> " << pdgIter.getPDGCode());
}
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:589
A set of ParticleType objects, with defined order.
Definition: Const.h:517
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:618

ParticleSets can be created by merging ParticleType objects or other ParticleSets:

static const ChargedStable muon
muon particle
Definition: Const.h:660
static const ParticleType photon
photon particle
Definition: Const.h:673
static const ChargedStable electron
electron particle
Definition: Const.h:659

Definition at line 517 of file Const.h.

Constructor & Destructor Documentation

◆ ParticleSet()

ParticleSet ( const ParticleSet other)
inline

Copy constructor to make sure particles belong to correct set.

Definition at line 523 of file Const.h.

524 {
525 for (const ParticleType& pdgIter : other) add(pdgIter);
526 }
void add(const ParticleType &p)
Add a copy of the given ParticleType to this set.
Definition: UnitConst.cc:417

Member Function Documentation

◆ add()

void add ( const ParticleType p)

Add a copy of the given ParticleType to this set.

If the set already contains the given particle, it remains unchanged.

Definition at line 417 of file UnitConst.cc.

418{
419 if (contains(p))
420 return;
421 m_particles.emplace_back(p.getPDGCode(), this, m_particles.size());
422}
bool contains(const ParticleType &p) const
Returns true if and only if the set contains 'p'.
Definition: UnitConst.cc:424
std::vector< ParticleType > m_particles
Actual particles.
Definition: Const.h:581

◆ at()

const ParticleType & at ( unsigned int  index) const
inline

Return particle at given index, or end() if out of range.

Definition at line 549 of file Const.h.

550 {
551 if (index < m_particles.size())
552 return m_particles[index];
553 return invalidParticle;
554 }
static const ParticleType invalidParticle
Invalid particle, used internally.
Definition: Const.h:681

◆ begin()

ParticleType begin ( ) const
inline

Returns first particle.

Definition at line 557 of file Const.h.

558 {
559 if (m_particles.empty())
560 return end();
561 return m_particles[0];
562 }
ParticleType end() const
Returns an invalid particle to check if iteration should be stopped.
Definition: Const.h:565

◆ contains()

bool contains ( const ParticleType p) const

Returns true if and only if the set contains 'p'.

Definition at line 424 of file UnitConst.cc.

425{
426 return (std::find(m_particles.begin(), m_particles.end(), p) != m_particles.end());
427}

◆ end()

ParticleType end ( ) const
inline

Returns an invalid particle to check if iteration should be stopped.

Definition at line 565 of file Const.h.

566 {
567 return invalidParticle;
568 }

◆ find()

const ParticleType & find ( int  pdg) const
inline

Returns particle in set with given PDG code, or invalidParticle if not found.

Definition at line 571 of file Const.h.

572 {
573 for (ParticleType pdgIter : *this) {
574 if (pdgIter.getPDGCode() == pdg)
575 return m_particles[pdgIter.getIndex()];
576 }
577
578 return invalidParticle;
579 }

◆ operator=()

ParticleSet & operator= ( const ParticleSet other)
inline

Assignment operator.

Definition at line 529 of file Const.h.

530 {
531 m_particles.clear();
532 for (const ParticleType& pdgIter : other) add(pdgIter);
533 return *this;
534 }

◆ size()

unsigned int size ( ) const
inline

Returns number of particles in this set.

Definition at line 546 of file Const.h.

546{ return m_particles.size(); }

Member Data Documentation

◆ m_particles

std::vector<ParticleType> m_particles
private

Actual particles.

Definition at line 581 of file Const.h.


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