Belle II Software light-2406-ragdoll
MCParticleGraph Class Reference

Class to build, validate and sort a particle decay chain. More...

#include <MCParticleGraph.h>

Collaboration diagram for MCParticleGraph:

Classes

class  GraphParticle
 Class to represent Particle data in graph. More...
 
class  ParticleSorter
 Class to go over all the particles in the Graph an sort them in a sensible way. More...
 

Public Types

enum  GraphOptions {
  c_setNothing = 0 ,
  c_setDecayVertex = 1 ,
  c_setDecayTime = 2 ,
  c_setDecayInfo = c_setDecayVertex | c_setDecayTime ,
  c_checkCyclic = 4 ,
  c_clearParticles = 8
}
 Possible options for generating the MCParticle list. More...
 
typedef std::pair< unsigned int, unsigned int > DecayLine
 Type representing a decay in the graph.
 

Public Member Functions

 BELLE2_DEFINE_EXCEPTION (CyclicReferenceError, "Cyclic decay, cannot continue")
 The exception is thrown if a cyclic reference in the graph was detected.
 
 BELLE2_DEFINE_EXCEPTION (NotSameGraphError, "Particles not from same graph")
 The exception is thrown if two particles do not belong to the same graph.
 
 BELLE2_DEFINE_EXCEPTION (NonContinousDaughtersError, "Can not represent decay graph, non continuous indices for daughters")
 The exception is thrown if a non-physical decay was detected in the graph.
 
 BELLE2_DEFINE_EXCEPTION (DaughterHasMotherError, "A daughter particle was already assigned to a mother. A particle can't have two mothers!")
 The exception is thrown if a daughter already has a mother assigned to it.
 
 BELLE2_DEFINE_EXCEPTION (OutOfRangeError, "Index out of range")
 The exception is thrown if the specified index is out of range.
 
 MCParticleGraph ()
 Constructor.
 
virtual ~MCParticleGraph ()
 Destructor.
 
GraphParticleaddParticle ()
 Add new particle to the graph.
 
void addDecay (GraphParticle &mother, GraphParticle &daughter)
 Add decay information between two particles.
 
GraphParticleoperator[] (size_t i)
 Return reference to added particle with range check.
 
size_t size () const
 Return the number of particles in the graph.
 
void generateList (const std::string &name="", int options=c_setNothing)
 Generates the MCParticle list and stores it in the StoreArray with the given name.
 
void loadList (const std::string &name="")
 Load the MCParticle list given by name into the Graph.
 
void clear ()
 Reset particles and decay information to make the class reusable.
 

Protected Attributes

MemoryPool< GraphParticlem_particles
 internal list of particles
 
std::set< DecayLinem_decays
 internal set of decay lines
 

Detailed Description

Class to build, validate and sort a particle decay chain.

Several particles can be added with addParticle(). Decay information between these particles can be added using addDecay(), MCParticleGraph::Particle::decaysInto() and MCParticleGraph::Particle::comesFrom().

Once all all particles and decays are added and their parameters set, call generateList() to fill the specified StoreArray with the resulting MCParticle list. The decay chain will be checked for cyclic references and a runtime_error will be thrown in that case. The particle will be sorted breadth first: First all primary particles, then all particles first generation and so on.

Definition at line 37 of file MCParticleGraph.h.

Member Typedef Documentation

◆ DecayLine

typedef std::pair<unsigned int, unsigned int> DecayLine

Type representing a decay in the graph.

Definition at line 56 of file MCParticleGraph.h.

Member Enumeration Documentation

◆ GraphOptions

Possible options for generating the MCParticle list.

Enumerator
c_setNothing 

Do nothing special.

c_setDecayVertex 

Set the decay vertex to the production vertex of the last daughter (ordered by production time)

c_setDecayTime 

Set decay time to the largest production time of the daughters.

c_setDecayInfo 

Set decay time and vertex.

c_checkCyclic 

Check for cyclic dependencies.

c_clearParticles 

Clear the particle list before adding the graph.

Definition at line 59 of file MCParticleGraph.h.

59 {
60 c_setNothing = 0,
62 c_setDecayTime = 2,
64 c_checkCyclic = 4,
66 };
@ c_setDecayVertex
Set the decay vertex to the production vertex of the last daughter (ordered by production time)
@ c_setDecayTime
Set decay time to the largest production time of the daughters.
@ c_setNothing
Do nothing special.
@ c_checkCyclic
Check for cyclic dependencies.
@ c_clearParticles
Clear the particle list before adding the graph.
@ c_setDecayInfo
Set decay time and vertex.

Constructor & Destructor Documentation

◆ MCParticleGraph()

MCParticleGraph ( )
inline

Constructor.

Definition at line 208 of file MCParticleGraph.h.

208{}

◆ ~MCParticleGraph()

virtual ~MCParticleGraph ( )
inlinevirtual

Destructor.

Frees the allocated spaces

Definition at line 214 of file MCParticleGraph.h.

214{ clear(); }
void clear()
Reset particles and decay information to make the class reusable.

Member Function Documentation

◆ generateList()

void generateList ( const std::string &  name = "",
int  options = c_setNothing 
)

Generates the MCParticle list and stores it in the StoreArray with the given name.

The graph will be checked for validity. If a cyclic reference is detected, a runtime_error is thrown. Similar, if the decay chain cannot be represented with continuous daughter indices, a runtime_error is raised. This can happen for artificial kinds of decays (eg: a->b,c,d; b->c,e;) but should not happen in physical cases.

Parameters
nameName of the StoreArray for the MCParticle list
optionsAdditional options which steer the creation of the StoreArray.
See also
class MCParticle

Definition at line 209 of file MCParticleGraph.cc.

210{
211 StoreArray<MCParticle> MCParticles(name);
212
213 //Make Graph and connect all primary vertices (particles without mother)
214 //to an artificial 0ths vertex to be able to find them easily
215 typedef adjacency_list<vecS, vecS, directedS> Graph;
216 int num_particles(0);
217 //Determine number of not ignored particles and add an edge from 0ths vertex to any primary
218 //particle
219 for (unsigned int i = 0; i < m_particles.size(); ++i) {
220 if (!m_particles[i]->m_ignore) ++num_particles;
221 if (m_particles[i]->m_primary) m_decays.insert(DecayLine(0, i + 1));
222 }
223 Graph g(m_decays.begin(), m_decays.end(), m_particles.size() + 1);
224
225 //Check for cyclic dependency
226 if (options & c_checkCyclic) {
227 cycle_detector vis;
228 depth_first_search(g, visitor(vis));
229 }
230
231 //Fill TClonesArray in correct order
232 if (options & c_clearParticles) MCParticles.getPtr()->Clear();
233 MCParticles.getPtr()->Expand(num_particles + MCParticles.getEntries());
234 MCParticleGraph::ParticleSorter psorter(m_particles, MCParticles.getPtr(), options & c_setDecayVertex, options & c_setDecayTime);
235 psorter.setStartIndex(MCParticles.getEntries());
236 psorter.sort(g);
237}
Class to go over all the particles in the Graph an sort them in a sensible way.
std::pair< unsigned int, unsigned int > DecayLine
Type representing a decay in the graph.
std::set< DecayLine > m_decays
internal set of decay lines
MemoryPool< GraphParticle > m_particles
internal list of particles
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Simple struct to check boost graph for cyclic references.

◆ loadList()

void loadList ( const std::string &  name = "")

Load the MCParticle list given by name into the Graph.

Parameters
nameName of the StoreArray for the MCParticle list
See also
class MCParticle

Definition at line 239 of file MCParticleGraph.cc.

240{
241 StoreArray<MCParticle> MCParticles(name);
242 if (!MCParticles) {
243 B2ERROR("MCParticle Collection is not valid, cannot load into Graph");
244 return;
245 }
246
247 unsigned numParticles = MCParticles.getEntries();
248 unsigned particleOffset = size();
249 //Here we assume that the MCParticle collection is somehow ordered: All
250 //particles which are product of a decay come in the list after the mother,
251 //thus having a higher index. This is true for all lists generated by the
252 //MCParticleGraph and also for the standard lists produced by Evtgen and
253 //similiar generators.
254 for (unsigned i = 0; i < numParticles; ++i) {
255 GraphParticle& newParticle = addParticle();
256 const MCParticle& oldParticle = *MCParticles[i];
257 //Copy all values
258 newParticle = oldParticle;
259 //If this particle has a mother we just add the decay to this mother
260 const MCParticle* oldMother = oldParticle.getMother();
261 if (oldMother != nullptr) {
262 unsigned motherIndex = oldMother->getArrayIndex() + particleOffset;
263 if (motherIndex >= size())
264 B2FATAL("MCParticle collection \"" << name << "\" not sorted correctly: mother index larger than daughter. Cannot load into Graph");
265 newParticle.comesFrom((*this)[oldMother->getArrayIndex() + particleOffset]);
266 }
267 }
268}
size_t size() const
Return the number of particles in the graph.
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:244
MCParticle * getMother() const
Returns a pointer to the mother particle.
Definition: MCParticle.h:600
GraphParticle & addParticle()
Add new particle to the graph.

◆ operator[]()

GraphParticle & operator[] ( size_t  i)
inline

Return reference to added particle with range check.

Returns
A reference to the particle given by its index.

Definition at line 236 of file MCParticleGraph.h.

236{ if (i >= m_particles.size()) throw OutOfRangeError(); return *m_particles[i]; }

◆ size()

size_t size ( ) const
inline

Return the number of particles in the graph.

Returns
The number of particles in the graph.

Definition at line 242 of file MCParticleGraph.h.

242{ return m_particles.size(); }

Member Data Documentation

◆ m_decays

std::set<DecayLine> m_decays
protected

internal set of decay lines

Definition at line 283 of file MCParticleGraph.h.

◆ m_particles

MemoryPool<GraphParticle> m_particles
protected

internal list of particles

Definition at line 282 of file MCParticleGraph.h.


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