Belle II Software development
MCParticleGraph::ParticleSorter Class Reference

Class to go over all the particles in the Graph an sort them in a sensible way. More...

Public Member Functions

 ParticleSorter (MemoryPool< MCParticleGraph::GraphParticle > &particles, TClonesArray *plist, bool setVertex, bool setTime)
 ParticleSorter constructor.
 
void setStartIndex (int index)
 Set the starting index for the particle graph.
 
template<class Graph >
void sort (Graph &g)
 Sort the particles and generate MCParticle list.
 
template<class Vertex , class Graph >
void finish_vertex (Vertex v, Graph &g)
 Go through the daughters of the vertex.
 
template<class Vertex , class Graph >
void find_daughters (Vertex v, Graph &g, MCParticleGraph::GraphParticle &mother)
 Find the daughters of the given vertex.
 
void setVertexTime (MCParticleGraph::GraphParticle &m, const MCParticleGraph::GraphParticle &d)
 Set the vertex and time information of the mother particle.
 

Protected Attributes

int m_index
 The latest index given to a particle.
 
MemoryPool< MCParticleGraph::GraphParticle > & m_particles
 Reference to the list of particles which should be sorted.
 
TClonesArray * m_plist
 The final array of sorted particles which is stored in the DataStore.
 
bool m_setVertex
 True if the vertex information should be saved.
 
bool m_setTime
 True if the production time information should be saved.
 
vector< bool > m_seen
 Vector of the particles that were already seen while sorting the graph.
 
std::queue< unsigned int > m_vqueue
 The list of the vertices that will be visited.
 

Detailed Description

Class to go over all the particles in the Graph an sort them in a sensible way.

All particles will be assigned an index, starting at 1. If an particle has its ignore flag set, then it will get assigned the index of its last, unignored parent. The particles will be sorted by depth: First all primary particles, then all direct daughters of the first primary particle, all direct daughters of the second primary particle and so forth.

Definition at line 48 of file MCParticleGraph.cc.

Constructor & Destructor Documentation

◆ ParticleSorter()

ParticleSorter ( MemoryPool< MCParticleGraph::GraphParticle > &  particles,
TClonesArray *  plist,
bool  setVertex,
bool  setTime 
)
inline

ParticleSorter constructor.

Parameters
particlesReference to the list of particles which should be sorted.
plistThe final array of sorted particles which is stored in the DataStore.
setVertexSet to true if the vertex information should be saved.
setTimeSet to true if the production time information should be saved.

Definition at line 59 of file MCParticleGraph.cc.

59 :
60 m_index(0), m_particles(particles), m_plist(plist), m_setVertex(setVertex), m_setTime(setTime) {}
MemoryPool< MCParticleGraph::GraphParticle > & m_particles
Reference to the list of particles which should be sorted.
bool m_setTime
True if the production time information should be saved.
int m_index
The latest index given to a particle.
bool m_setVertex
True if the vertex information should be saved.
TClonesArray * m_plist
The final array of sorted particles which is stored in the DataStore.

Member Function Documentation

◆ find_daughters()

void find_daughters ( Vertex  v,
Graph &  g,
MCParticleGraph::GraphParticle mother 
)
inline

Find the daughters of the given vertex.

Parameters
vThe vertex whose daughters are investigated.
gThe graph in which the vertex lives.
motherReference to the mother particle.

Definition at line 128 of file MCParticleGraph.cc.

129 {
130 //References to the daughter information of the mother for easier access
131 int& d1 = mother.m_firstDaughter;
132 int& d2 = mother.m_lastDaughter;
133
134 typename boost::graph_traits<Graph>::out_edge_iterator j, j_end;
135 for (tie(j, j_end) = out_edges(v, g); j != j_end; ++j) {
136 //Get daughter particle from list
137 Vertex nv = target(*j, g);
138 MCParticleGraph::GraphParticle& daughter = *m_particles[nv - 1];
139
140 if (daughter.m_ignore) {
141 //daughter ignored, search its children and treat them as direct children of mother
142 //if we haven't seen this particle yet, set its index to that of its last unignored parent
143 if (!m_seen[nv]) daughter.setIndex(mother.getIndex());
144 find_daughters(nv, g, mother);
145 } else {
146 //If we didn't see this particle already, set its index and add it to the queue for writing out
147 if (!m_seen[nv]) {
148 daughter.setIndex(++m_index);
149 m_vqueue.push(nv);
150 }
151 //Set daughter information of mother. If 0, no daughters yet so just take current daughter as only
152 //daughter. Otherwise allow extension of daughter information in both directions.
153 if (d1 == 0) {
154 d1 = daughter.getIndex();
155 d2 = d1;
156 } else if ((d2 + 1) == daughter.getIndex()) {
157 ++d2;
158 } else if ((d1 - 1) == daughter.getIndex()) {
159 --d1;
160 } else {
161 //Daughter indices are not continuous, cannot continue
162 throw MCParticleGraph::NonContinousDaughtersError();
163 }
164 //Set Vertex and time information if requested
165 setVertexTime(mother, daughter);
166 daughter.m_mother = mother.getIndex();
167 }
168 //Mark particle as seen
169 m_seen[nv] = true;
170 }
171 }
Class to represent Particle data in graph.
void setVertexTime(MCParticleGraph::GraphParticle &m, const MCParticleGraph::GraphParticle &d)
Set the vertex and time information of the mother particle.
void find_daughters(Vertex v, Graph &g, MCParticleGraph::GraphParticle &mother)
Find the daughters of the given vertex.
std::queue< unsigned int > m_vqueue
The list of the vertices that will be visited.
vector< bool > m_seen
Vector of the particles that were already seen while sorting the graph.
int m_lastDaughter
1-based index of last daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:548
int getIndex() const
Get 1-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:219
int m_firstDaughter
1-based index of first daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:547

◆ finish_vertex()

void finish_vertex ( Vertex  v,
Graph &  g 
)
inline

Go through the daughters of the vertex.

Add the found particles to the final particle list.

Parameters
vThe vertex whose daughters are investigated.
gThe graph in which the vertex lives.

Definition at line 101 of file MCParticleGraph.cc.

102 {
104
105 //Reset daughter information, will be filled by find_daughters
106 p.setFirstDaughter(0);
107 p.setLastDaughter(0);
108 //Find all direct daughters
109 find_daughters(v, g, p);
110
111 //If stable particle, set decaytime to infinity
112 if (out_degree(v, g) == 0 && m_setTime) {
113 p.setDecayTime(numeric_limits<double>::infinity());
114 }
115 //If given a pointer to a TClonesArray, create MCParticle at the appropriate index position
116 if (m_plist) {
117 new (m_plist->AddrAt(p.getIndex() - 1)) MCParticle(m_plist, p);
118 }
119 }
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32

◆ setStartIndex()

void setStartIndex ( int  index)
inline

Set the starting index for the particle graph.

Normally this is 0 so the first real particle has an id of 1 but this can be used if there are already particles present so the first particle will have id N+1

Parameters
indexnumber of particles already present

Definition at line 67 of file MCParticleGraph.cc.

67{ m_index = index; }

◆ setVertexTime()

void setVertexTime ( MCParticleGraph::GraphParticle m,
const MCParticleGraph::GraphParticle d 
)
inline

Set the vertex and time information of the mother particle.

Parameters
mReference to the mother particle whose vertex and time information should be set.
dReference to the daughter particle.

Definition at line 179 of file MCParticleGraph.cc.

180 {
181 //Only set vertex information if both particles have a valid vertex set
182 m.setValidVertex(m.hasValidVertex() && d.hasValidVertex());
183 if (m.hasValidVertex() && d.getProductionTime() >= m.getDecayTime()) {
184 if (m_setVertex) {
185 m.setDecayVertex(d.getProductionVertex());
186 }
187 if (m_setTime) {
188 m.setDecayTime(d.getProductionTime());
189 }
190 }
191 }

◆ sort()

void sort ( Graph &  g)
inline

Sort the particles and generate MCParticle list.

Parameters
gThe graph which should be sorted and transformed to a list of particles.

Definition at line 73 of file MCParticleGraph.cc.

74 {
75 //Set seen flag for all vertices to false
76 m_seen.clear();
77 m_seen.resize(num_vertices(g), false);
78
79 //Create a dummy GraphParticle, needed only to find all primary particles
81
82 //Add all direct children of the 0th vertex to the queue.
83 //This are the primary particles
84 find_daughters(0, g, dummy);
85
86 //Go through the queue and write out each particle.
87 //Daughters of particles will be added to the queue by find_daughters
88 while (!m_vqueue.empty()) {
89 unsigned int cur = m_vqueue.front();
90 m_vqueue.pop();
91 finish_vertex(cur, g);
92 }
93 }
void finish_vertex(Vertex v, Graph &g)
Go through the daughters of the vertex.

Member Data Documentation

◆ m_index

int m_index
protected

The latest index given to a particle.

Definition at line 196 of file MCParticleGraph.cc.

◆ m_particles

MemoryPool<MCParticleGraph::GraphParticle>& m_particles
protected

Reference to the list of particles which should be sorted.

Definition at line 197 of file MCParticleGraph.cc.

◆ m_plist

TClonesArray* m_plist
protected

The final array of sorted particles which is stored in the DataStore.

Definition at line 199 of file MCParticleGraph.cc.

◆ m_seen

vector<bool> m_seen
protected

Vector of the particles that were already seen while sorting the graph.

Definition at line 203 of file MCParticleGraph.cc.

◆ m_setTime

bool m_setTime
protected

True if the production time information should be saved.

Definition at line 201 of file MCParticleGraph.cc.

◆ m_setVertex

bool m_setVertex
protected

True if the vertex information should be saved.

Definition at line 200 of file MCParticleGraph.cc.

◆ m_vqueue

std::queue<unsigned int> m_vqueue
protected

The list of the vertices that will be visited.

Definition at line 204 of file MCParticleGraph.cc.


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