Belle II Software development
ParticleListHelper Class Reference

Class to help managing creation and adding to ParticleLists. More...

#include <ParticleListHelper.h>

Public Member Functions

 ParticleListHelper ()=default
 Default constructor, does nothing.
 
 ParticleListHelper (const std::string &listname, bool save=true)
 Construct and initialize right away.
 
void registerList (const std::string &listname, bool save=true)
 Register a list by name.
 
void registerList (const DecayDescriptor &decay, bool save=true)
 Register a list using a decay descriptor.
 
int getPDGCode () const
 Return the pdg code of the main list.
 
bool isSelfConjugated () const
 Return whether or not this list is self conjugated.
 
void create ()
 Create the list objects.
 
template<class ... Args>
Particleadd (Args &&... args)
 Add a particle to the list by forwarding all arguments to the constructor of the Particle object: Any valid arguments to construct a Belle2::Particle work here.
 
ParticleaddParticle (const Particle &particle)
 Non-templated convenience function to add a particle from an existing particle object.
 
ParticleaddParticle (const ROOT::Math::PxPyPzEVector &momentum, bool conjugated=false)
 Non-templated convenience function to add a particle from simple four momentum and an indicator whether it's particle or anti particle.
 

Private Attributes

StoreArray< Particlem_particles
 Store array for the particles.
 
StoreObjPtr< ParticleListm_list
 Store object for the list.
 
std::optional< StoreObjPtr< ParticleList > > m_antiList
 Optional store object for the conjugated list if that exists.
 
int m_pdg
 PDG code of the list.
 

Detailed Description

Class to help managing creation and adding to ParticleLists.

There's a bit of management involved when trying to create a new particle list

  • the list needs to be registered in the datastore
  • the conjugated list needs to be registered in the datastore unless the particle is self conjugated
  • the particles array needs to be registered in the datastore
  • in each event the lists need to be initialized
  • when adding a particle it needs to be added to the particles array and then with the index it has in the array it is added to the particle list

This class is managing all this in a clean interface

  1. Add one instance as member to your class
  2. in the initialize() function call registerList() with the full list name (or the DecayDescriptor)
  3. in the beginning of the event() function call create()
  4. Fill particles with add() or addParticle (the second one is for the benefit of python as currently ROOT has problems with variadic template functions forwarding arguments)

Definition at line 48 of file ParticleListHelper.h.

Constructor & Destructor Documentation

◆ ParticleListHelper()

ParticleListHelper ( const std::string &  listname,
bool  save = true 
)
inlineexplicit

Construct and initialize right away.

Useful in cases where you create these objects directly in the initialize() function of a module

Definition at line 55 of file ParticleListHelper.h.

56 {
57 registerList(listname, save);
58 }
ParticleListHelper()=default
Default constructor, does nothing.
void registerList(const std::string &listname, bool save=true)
Register a list by name.

Member Function Documentation

◆ add()

Particle & add ( Args &&...  args)
inline

Add a particle to the list by forwarding all arguments to the constructor of the Particle object: Any valid arguments to construct a Belle2::Particle work here.

It will return a reference to the created particle for further modification.

Definition at line 89 of file ParticleListHelper.h.

90 {
91 auto index = m_particles.getEntries();
92 // cppcheck doesn't seem to understand the forwarding of arguments and
93 // throws an erroneous warning about reassigning appendNew
94 //
95 // cppcheck-suppress redundantAssignment
96 // cppcheck-suppress redundantInitialization
97 auto particle = m_particles.appendNew(std::forward<Args>(args)...);
98 m_list->addParticle(index, particle->getPDGCode(), particle->getFlavorType());
99 return *particle;
100 }
StoreObjPtr< ParticleList > m_list
Store object for the list.
StoreArray< Particle > m_particles
Store array for the particles.
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216

◆ addParticle() [1/2]

Particle & addParticle ( const Particle particle)
inline

Non-templated convenience function to add a particle from an existing particle object.

Definition at line 103 of file ParticleListHelper.h.

103{ return add(particle); }
Particle & add(Args &&... args)
Add a particle to the list by forwarding all arguments to the constructor of the Particle object: Any...

◆ addParticle() [2/2]

Particle & addParticle ( const ROOT::Math::PxPyPzEVector &  momentum,
bool  conjugated = false 
)
inline

Non-templated convenience function to add a particle from simple four momentum and an indicator whether it's particle or anti particle.

Warning
particle/conjugates particle is based on what name was given when creating the list. If you created the list as 'anti-B0' than supplying 'conjugated=true' will create a 'B0'

Definition at line 110 of file ParticleListHelper.h.

111 {
112 return add(momentum, m_pdg * ((conjugated and not isSelfConjugated()) ? -1 : 1));
113 }
bool isSelfConjugated() const
Return whether or not this list is self conjugated.
int m_pdg
PDG code of the list.

◆ getPDGCode()

int getPDGCode ( ) const
inline

Return the pdg code of the main list.

If it's not a self conjugated list there is also a list with the negative pdg value

Definition at line 77 of file ParticleListHelper.h.

77{ return m_pdg; }

◆ isSelfConjugated()

bool isSelfConjugated ( ) const
inline

Return whether or not this list is self conjugated.

Definition at line 79 of file ParticleListHelper.h.

79{ return not m_antiList.has_value(); }
std::optional< StoreObjPtr< ParticleList > > m_antiList
Optional store object for the conjugated list if that exists.

Member Data Documentation

◆ m_antiList

std::optional<StoreObjPtr<ParticleList> > m_antiList
private

Optional store object for the conjugated list if that exists.

Definition at line 121 of file ParticleListHelper.h.

◆ m_list

StoreObjPtr<ParticleList> m_list
private

Store object for the list.

Definition at line 119 of file ParticleListHelper.h.

◆ m_particles

StoreArray<Particle> m_particles
private

Store array for the particles.

Definition at line 117 of file ParticleListHelper.h.

◆ m_pdg

int m_pdg
private

PDG code of the list.

Definition at line 123 of file ParticleListHelper.h.


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