Belle II Software light-2405-quaxo
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:580
A set of ParticleType objects, with defined order.
Definition: Const.h:508
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:609

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

static const ChargedStable muon
muon particle
Definition: Const.h:651
static const ParticleType photon
photon particle
Definition: Const.h:664
static const ChargedStable electron
electron particle
Definition: Const.h:650

Definition at line 508 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 514 of file Const.h.

515 {
516 for (const ParticleType& pdgIter : other) add(pdgIter);
517 }
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:572

◆ at()

const ParticleType & at ( unsigned int  index) const
inline

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

Definition at line 540 of file Const.h.

541 {
542 if (index < m_particles.size())
543 return m_particles[index];
544 return invalidParticle;
545 }
static const ParticleType invalidParticle
Invalid particle, used internally.
Definition: Const.h:672

◆ begin()

ParticleType begin ( ) const
inline

Returns first particle.

Definition at line 548 of file Const.h.

549 {
550 if (m_particles.empty())
551 return end();
552 return m_particles[0];
553 }
ParticleType end() const
Returns an invalid particle to check if iteration should be stopped.
Definition: Const.h:556

◆ 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 556 of file Const.h.

557 {
558 return invalidParticle;
559 }

◆ find()

const ParticleType & find ( int  pdg) const
inline

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

Definition at line 562 of file Const.h.

563 {
564 for (ParticleType pdgIter : *this) {
565 if (pdgIter.getPDGCode() == pdg)
566 return m_particles[pdgIter.getIndex()];
567 }
568
569 return invalidParticle;
570 }

◆ operator=()

ParticleSet & operator= ( const ParticleSet other)
inline

Assignment operator.

Definition at line 520 of file Const.h.

521 {
522 m_particles.clear();
523 for (const ParticleType& pdgIter : other) add(pdgIter);
524 return *this;
525 }

◆ size()

unsigned int size ( ) const
inline

Returns number of particles in this set.

Definition at line 537 of file Const.h.

537{ return m_particles.size(); }

Member Data Documentation

◆ m_particles

std::vector<ParticleType> m_particles
private

Actual particles.

Definition at line 572 of file Const.h.


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