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:

Public Types

enum  EParticleType {
  c_FlavorSpecificParticle = 0 ,
  c_SelfConjugatedParticle
}
 Type of Particle (determines in which of the two internal lists the particle is stored). More...
 
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.
 
void bindAntiParticleList (ParticleList &antiList, bool includingAntiList=true)
 Binds particle and anti-particle ParticleLists.
 
void setParticleCollectionName (const std::string &name, bool forAntiParticle=true)
 Sets Particle store array name to which particle list refers.
 
void addParticle (const Particle *particle)
 Adds a new particle to the list (safe method)
 
void addParticle (unsigned iparticle, int pdg, Particle::EFlavorType flavorType, bool includingAntiList=true)
 Adds a new particle to the list (almost safe method)
 
void removeParticles (const std::vector< unsigned int > &toRemove, bool removeFromAntiList=true)
 Remove given elements from list.
 
void clear (bool includingAntiList=true)
 Remove all elements from list, afterwards getListSize() will be 0.
 
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.
 
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.
 
ParticlegetParticle (unsigned i, bool includingAntiList=true) const
 Returns i-th particle from the list and anti list if requested.
 
ParticlegetParticleWithMdstIdx (unsigned int mdstIdx, bool includingAntiList=true) const
 Returns the particle from the list matching the given mdst array index, if any is found.
 
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.
 
bool contains (const Particle *p, bool includingAntiList=true) const
 Returns true if and only if 'p' is already in this list.
 
int getIndex (const Particle *p, bool includingAntiList=true) const
 Returns index of the given particle 'p' in this list.
 
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.
 
 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
 

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
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:74
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
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96

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->....
}
Class to store reconstructed particles.
Definition: Particle.h:75

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);
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
STL namespace.

Definition at line 140 of file ParticleList.h.

Member Typedef Documentation

◆ const_iterator

STL-like const_iterator over the particles (not Particle*).

Definition at line 146 of file ParticleList.h.

◆ iterator

STL-like iterator over the particles (not Particle*).

Definition at line 144 of file ParticleList.h.

Member Enumeration Documentation

◆ EParticleType

Type of Particle (determines in which of the two internal lists the particle is stored).

Definition at line 149 of file ParticleList.h.

149 {
150 c_FlavorSpecificParticle = 0,
151 c_SelfConjugatedParticle
152 };

Constructor & Destructor Documentation

◆ ParticleList()

ParticleList ( )
inline

Default constructor.

Definition at line 157 of file ParticleList.h.

157 :
158 m_pdg(0),
159 m_pdgbar(0),
160 m_particleStore("Particles"),
163 m_antiList(nullptr),
164 m_isReserved(false)
165 {
166 }
std::string m_antiListName
name of ParticleList for anti-particles
Definition: ParticleList.h:382
bool m_isReserved
transient
Definition: ParticleList.h:387
int m_pdg
PDG code of Particle.
Definition: ParticleList.h:373
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
StoreObjPtr< ParticleList > * m_antiList
keep anti-list around for performance.
Definition: ParticleList.h:385
int m_pdgbar
PDG code of antiparticle.
Definition: ParticleList.h:374

◆ ~ParticleList()

Definition at line 25 of file ParticleList.cc.

26{
27 delete m_antiList;
28}

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
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.

87{
88 if (m_isReserved)
89 B2FATAL("ParticleList::addParticle The ParticleList " << m_thisListName <<
90 " is reserved and forbidden to be manipulated.");
91
92 if (abs(pdg) != abs(getPDGCode())) {
93 B2ERROR("ParticleList::addParticle PDG codes do not match, not added");
94 return;
95 }
96
97 if (type == Particle::c_Unflavored) {
98 // this is self-conjugated particle
99 // add it to the self-conjugated list of this (and anti-particle list if exists)
100
101 // check if the particle is already in this list
102 if (std::find(m_scList.begin(), m_scList.end(), iparticle) == m_scList.end()) {
103 m_scList.push_back(iparticle);
104 } else {
105 B2WARNING("ParticleList::addParticle Trying to add Particle with index=" << iparticle
106 << " to the ParticleList=" << m_thisListName << " that is already included!");
107 return;
108 }
109
110 // add it to the self-conjugated list
111 if (includingAntiList and !m_antiListName.empty())
112 getAntiParticleList().addParticle(iparticle, pdg, type, false);
113 } else if (type == Particle::c_Flavored) {
114 unsigned antiParticle = (pdg == getPDGCode()) ? 0 : 1;
115
116 if (antiParticle)
117 getAntiParticleList().addParticle(iparticle, pdg, type, false);
118 else {
119 if (std::find(m_fsList.begin(), m_fsList.end(), iparticle) == m_fsList.end()) {
120 m_fsList.push_back(iparticle);
121 } else {
122 B2WARNING("ParticleList::addParticle Trying to add Particle with index=" << iparticle
123 << " to the ParticleList=" << m_thisListName << "that is already included! Particle not added");
124 }
125 }
126 } else {
127 B2ERROR("ParticleList::addParticle invalid flavor type, not added");
128 }
129}
int getPDGCode() const
Returns PDG code.
Definition: ParticleList.h:239
ParticleList & getAntiParticleList() const
Returns bound anti-particle list.
std::vector< int > m_fsList
list of 0-based indices of flavor-specific Particles (particles that have an anti-particle)
Definition: ParticleList.h:375
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:377
@ c_Unflavored
Is its own antiparticle or we don't know whether it is a particle/antiparticle.
Definition: Particle.h:95
@ c_Flavored
Is either particle or antiparticle.
Definition: Particle.h:96

◆ begin() [1/2]

iterator begin ( )
inline

Return iterator to first entry.

Definition at line 353 of file ParticleList.h.

353{ return iterator(this, 0); }
ArrayIterator< ParticleList, Particle > iterator
STL-like iterator over the particles (not Particle*).
Definition: ParticleList.h:144

◆ begin() [2/2]

const_iterator begin ( ) const
inline

Return const_iterator to first entry.

Definition at line 358 of file ParticleList.h.

358{ return const_iterator(this, 0); }
ArrayIterator< ParticleList, const Particle > const_iterator
STL-like const_iterator over the particles (not Particle*).
Definition: ParticleList.h:146

◆ 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.

75{
76 m_pdgbar = antiList.getPDGCode();
78
79 if (abs(m_pdgbar) != abs(m_pdg))
80 B2ERROR("ParticleList::bindAntiParticleList invalid (inconsistent) PDG codes!");
81
82 if (includingAntiList)
83 antiList.bindAntiParticleList(*this, false);
84}
std::string getParticleListName() const
Returns the name this ParticleList.
Definition: ParticleList.h:277

◆ clear()

void clear ( bool  includingAntiList = true)

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


Definition at line 158 of file ParticleList.cc.

159{
160 if (m_isReserved)
161 B2FATAL("ParticleList::clear The ParticleList " << m_thisListName <<
162 " is reserved and forbidden to be manipulated.");
163
164 m_fsList.clear();
165 m_scList.clear();
166
167 if (includingAntiList and !m_antiListName.empty()) {
168 getAntiParticleList().clear(false);
169 }
170}
void clear(bool includingAntiList=true)
Remove all elements from list, afterwards getListSize() will be 0.

◆ 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.

237{
238 const int index = p->getArrayIndex();
239 for (int i = 0; i < 3; i++) {
240 if (i == 1 && !includingAntiList)
241 continue;
242
243 const std::vector<int>& currentList = getList((i < 2) ? c_FlavorSpecificParticle : c_SelfConjugatedParticle, i == 1);
244 if (std::find(currentList.begin(), currentList.end(), index) != currentList.end())
245 return true;
246 }
247 return false;
248}
const std::vector< int > & getList(EParticleType K, bool forAntiParticle=false) const
Returns list of StoreArray<Particle> indices.

◆ end() [1/2]

iterator end ( )
inline

Return iterator to last entry +1.

Definition at line 355 of file ParticleList.h.

355{ return iterator(this, getListSize()); }
unsigned getListSize(bool includingAntiList=true) const
Returns total number of particles in this list and anti list if requested.

◆ end() [2/2]

const_iterator end ( ) const
inline

Return const_iterator to last entry +1.

Definition at line 360 of file ParticleList.h.

360{ return const_iterator(this, getListSize()); }

◆ 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.

296{
297 if (!m_antiList) {
299 if (!m_antiList->isValid()) {
300 B2FATAL("Anti-particle list " << m_antiListName << " for " << m_thisListName <<
301 " not found, even though one was set via bindAntiParticleList(). Maybe you only saved one list into a .root file?");
302 }
303 }
304 return **m_antiList;
305}

◆ getAntiParticleListName()

std::string getAntiParticleListName ( ) const
inline

Returns the name the anti-particle ParticleList.

Definition at line 272 of file ParticleList.h.

272{ return m_antiListName; }

◆ getAntiParticlePDGCode()

int getAntiParticlePDGCode ( ) const
inline

Returns PDG code of anti-particle.

Definition at line 244 of file ParticleList.h.

244{ return m_pdgbar; }

◆ 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.

251{
252 const int index = p->getArrayIndex();
253
254 auto it_fs = std::find(m_fsList.begin(), m_fsList.end(), index);
255 if (it_fs != m_fsList.end()) {
256 return std::distance(m_fsList.begin(), it_fs);
257 }
258
259 auto it_sc = std::find(m_scList.begin(), m_scList.end(), index);
260 if (it_sc != m_scList.end()) {
261 return std::distance(m_scList.begin(), it_sc) + m_fsList.size();
262 }
263
264 if (includingAntiList and !m_antiListName.empty()) {
265 int indexAnti = getAntiParticleList().getIndex(p, false);
266 if (indexAnti != -1)
267 return indexAnti + m_fsList.size() + m_scList.size();
268 }
269
270 return -1;
271}
int getIndex(const Particle *p, bool includingAntiList=true) const
Returns index of the given particle 'p' in this list.

◆ getInfoHTML()

std::string getInfoHTML ( ) const

Return a short summary of this object's contents in HTML format.

Definition at line 278 of file ParticleList.cc.

279{
280 std::stringstream stream;
281 unsigned thisFSCount = getNParticlesOfType(c_FlavorSpecificParticle);
282 unsigned thisSCCount = getNParticlesOfType(c_SelfConjugatedParticle);
283 unsigned antiFSCount = getNParticlesOfType(c_FlavorSpecificParticle, true);
284 unsigned antiSCCount = getNParticlesOfType(c_SelfConjugatedParticle, true);
285
286 if (!m_antiListName.empty()) {
287 stream << " ParticleLists: " << m_thisListName << " (" << thisFSCount << "+" << thisSCCount << ")"
288 << " + " << m_antiListName << " (" << antiFSCount << "+" << antiSCCount << ")";
289 } else {
290 stream << " ParticleList : " << m_thisListName << " (" << thisFSCount << "+" << thisSCCount << ")";
291 }
292 return HTML::escape(stream.str());
293}
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:310
std::string escape(const std::string &str)
Convert &, <, > etc.
Definition: HTML.cc:159

◆ getIsReserved()

bool getIsReserved ( ) const
inline

Returns m_isReserved.

Definition at line 346 of file ParticleList.h.

346{ return m_isReserved; };

◆ 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.

221{
222 if (!forAntiParticle) {
223 if (K == c_FlavorSpecificParticle)
224 return m_fsList;
225 else
226 return m_scList;
227 } else {
228 const static std::vector<int> emptyList;
229 if (m_antiListName.empty())
230 return emptyList;
231
232 return getAntiParticleList().getList(K);
233 }
234}

◆ 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.

204{
205 unsigned size = 0;
206
207 // FlavorSpecific particles of this list
208 size += m_fsList.size();
209 // SelfConjugated particles of this list = SelfConjugated particles of anti-particle list
210 size += m_scList.size();
211
212 if (includingAntiList) {
213 // FlavorSpecific particles of anti-particle list
214 size += getNParticlesOfType(EParticleType::c_FlavorSpecificParticle, true);
215 }
216
217 return size;
218}

◆ 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 }

◆ 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.

173{
175
176 if (i < m_fsList.size()) {
177 return Particles[m_fsList[i]];
178 } else if (i < m_fsList.size() + m_scList.size()) {
179 i -= m_fsList.size();
180 return Particles[m_scList[i]];
181 }
182
183 if (includingAntiList and !m_antiListName.empty())
184 return getAntiParticleList().getParticle(i - m_fsList.size() - m_scList.size(), false);
185
186 return nullptr;
187}
Particle * getParticle(unsigned i, bool includingAntiList=true) const
Returns i-th particle from the list and anti list if requested.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113

◆ getParticleCollectionName()

std::string getParticleCollectionName ( ) const
inline

Returns Particle store array name to which particle list refers.

Definition at line 234 of file ParticleList.h.

234{return m_particleStore;}

◆ getParticleListName()

std::string getParticleListName ( ) const
inline

Returns the name this ParticleList.

Definition at line 277 of file ParticleList.h.

277{ return m_thisListName; }

◆ 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.

190{
191 const unsigned int n = this->getListSize(includingAntiList);
192 for (unsigned i = 0; i < n; i++) {
193
194 auto particle = this->getParticle(i, includingAntiList);
195
196 if (particle->getMdstArrayIndex() == mdstIdx) {
197 return particle;
198 }
199 }
200 return nullptr;
201}

◆ getPDGCode()

int getPDGCode ( ) const
inline

Returns PDG code.

Definition at line 239 of file ParticleList.h.

239{return m_pdg; }

◆ 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.

31{
32 m_pdg = pdg;
33 m_pdgbar = pdg;
34 m_particleStore = particleStoreName;
35
36 m_thisListName = name;
37 m_antiListName.clear();
38
39 std::string label = m_thisListName.substr(m_thisListName.find_first_of(':') + 1);
40 if ((Const::finalStateParticlesSet.contains(Const::ParticleType(abs(m_pdg))) and label == "all") or label == "V0")
41 m_isReserved = true;
42}
The ParticleType class for identifying different particle types.
Definition: Const.h:408
static const ParticleSet finalStateParticlesSet
set of final set particles that can be created by the ParticleLoader
Definition: Const.h:657
bool contains(const Particle *p, bool includingAntiList=true) const
Returns true if and only if 'p' is already in this list.

◆ operator[]()

Particle * operator[] ( int  index) const
inline

Convenience function to get particle with index.

Definition at line 363 of file ParticleList.h.

363{return getParticle(index);}

◆ print()

void print ( ) const

Prints the list.

Definition at line 273 of file ParticleList.cc.

274{
276}
std::string getInfoHTML() const
Return a short summary of this object's contents in HTML format.
std::string htmlToPlainText(const std::string &html)
Reformat given HTML string into terminal-friendly plain text.
Definition: HTML.cc:138

◆ 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.

132{
133 if (m_isReserved)
134 B2FATAL("ParticleList::removeParticles The ParticleList " << m_thisListName <<
135 " is reserved and forbidden to be manipulated.");
136
137 std::vector<int> newList;
138 // remove Particles from flavor-specific list of this Particle List
139 for (int i : m_fsList) {
140 if (std::find(toRemove.begin(), toRemove.end(), i) == toRemove.end())
141 newList.push_back(i);
142 }
143 m_fsList = newList;
144
145 // remove Particles from self-conjugated list of this Particle List
146 newList.clear();
147 for (int i : m_scList) {
148 if (std::find(toRemove.begin(), toRemove.end(), i) == toRemove.end())
149 newList.push_back(i);
150 }
151 m_scList = newList;
152
153 if (removeFromAntiList and !m_antiListName.empty()) {
154 getAntiParticleList().removeParticles(toRemove, false);
155 }
156}
void removeParticles(const std::vector< unsigned int > &toRemove, bool removeFromAntiList=true)
Remove given elements from list.

◆ setEditable()

void setEditable ( bool  editable,
bool  includingAntiList = true 
)
inline

Sets m_isReserved so that the reserved list can be edited.

Definition at line 336 of file ParticleList.h.

337 {
338 m_isReserved = !editable;
339 if (includingAntiList and !m_antiListName.empty())
340 getAntiParticleList().setEditable(editable, false);
341 };
void setEditable(bool editable, bool includingAntiList=true)
Sets m_isReserved so that the reserved list can be edited.
Definition: ParticleList.h:336

◆ 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.

45{
46 m_particleStore = name;
47
48 if (forAntiParticle and !m_antiListName.empty())
50}
void setParticleCollectionName(const std::string &name, bool forAntiParticle=true)
Sets Particle store array name to which particle list refers.
Definition: ParticleList.cc:44

Friends And Related Function Documentation

◆ ParticleSubset

friend class ParticleSubset
friend

Definition at line 391 of file ParticleList.h.

Member Data Documentation

◆ m_antiList

StoreObjPtr<ParticleList>* m_antiList
mutableprivate

keep anti-list around for performance.

Definition at line 385 of file ParticleList.h.

◆ m_antiListName

std::string m_antiListName
private

name of ParticleList for anti-particles

Definition at line 382 of file ParticleList.h.

◆ m_fsList

std::vector<int> m_fsList
private

list of 0-based indices of flavor-specific Particles (particles that have an anti-particle)

Definition at line 375 of file ParticleList.h.

◆ m_isReserved

bool m_isReserved = false
private

transient

True if the list name is reserved

Definition at line 387 of file ParticleList.h.

◆ m_particleStore

std::string m_particleStore
private

name of Particle store array

Definition at line 379 of file ParticleList.h.

◆ m_pdg

int m_pdg
private

PDG code of Particle.

Definition at line 373 of file ParticleList.h.

◆ m_pdgbar

int m_pdgbar
private

PDG code of antiparticle.

Definition at line 374 of file ParticleList.h.

◆ m_scList

std::vector<int> m_scList
private

list of 0-based indices of self-conjugated Particles (particles that do not have an anti-particle)

Definition at line 377 of file ParticleList.h.

◆ m_thisListName

std::string m_thisListName
private

name of this ParticleList

Definition at line 381 of file ParticleList.h.


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