Belle II Software light-2607-kasei
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,
61 c_setDecayVertex = 1,
62 c_setDecayTime = 2,
63 c_setDecayInfo = c_setDecayVertex | c_setDecayTime,
64 c_checkCyclic = 4,
65 c_clearParticles = 8
66 };

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(); }

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 210 of file MCParticleGraph.cc.

211{
212 StoreArray<MCParticle> MCParticles(name);
213
214 //Make Graph and connect all primary vertices (particles without mother)
215 //to an artificial 0ths vertex to be able to find them easily
216 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> Graph;
217 int num_particles(0);
218 //Determine number of not ignored particles and add an edge from 0ths vertex to any primary
219 //particle
220 for (unsigned int i = 0; i < m_particles.size(); ++i) {
221 if (!m_particles[i]->m_ignore) ++num_particles;
222 if (m_particles[i]->m_primary) m_decays.insert(DecayLine(0, i + 1));
223 }
224 Graph g(m_decays.begin(), m_decays.end(), m_particles.size() + 1);
225
226 //Check for cyclic dependency
227 if (options & c_checkCyclic) {
228 cycle_detector vis;
229 depth_first_search(g, visitor(vis));
230 }
231
232 //Fill TClonesArray in correct order
233 if (options & c_clearParticles) MCParticles.getPtr()->Clear();
234 MCParticles.getPtr()->Expand(num_particles + MCParticles.getEntries());
235 MCParticleGraph::ParticleSorter psorter(m_particles, MCParticles.getPtr(), options & c_setDecayVertex, options & c_setDecayTime);
236 psorter.setStartIndex(MCParticles.getEntries());
237 psorter.sort(g);
238}
@ 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_checkCyclic
Check for cyclic dependencies.
@ c_clearParticles
Clear the particle list before adding the graph.
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

◆ 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 240 of file MCParticleGraph.cc.

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