Belle II Software light-2607-kasei
MCParticleGraph::ParticleSorter Class Reference

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

Collaboration diagram for MCParticleGraph::ParticleSorter:

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

template<class Vertex, class Graph>
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 // writes through this reference modify mother.m_lastDaughter, which cppcheck does not track
133 // cppcheck-suppress unreadVariable
134 int& d2 = mother.m_lastDaughter;
135
136 typename boost::graph_traits<Graph>::out_edge_iterator j, j_end;
137 for (tie(j, j_end) = out_edges(v, g); j != j_end; ++j) {
138 //Get daughter particle from list
139 Vertex nv = target(*j, g);
140 MCParticleGraph::GraphParticle& daughter = *m_particles[nv - 1];
141
142 if (daughter.m_ignore) {
143 //daughter ignored, search its children and treat them as direct children of mother
144 //if we haven't seen this particle yet, set its index to that of its last unignored parent
145 if (!m_seen[nv]) daughter.setIndex(mother.getIndex());
146 find_daughters(nv, g, mother);
147 } else {
148 //If we didn't see this particle already, set its index and add it to the queue for writing out
149 if (!m_seen[nv]) {
150 daughter.setIndex(++m_index);
151 m_vqueue.push(nv);
152 }
153 //Set daughter information of mother. If 0, no daughters yet so just take current daughter as only
154 //daughter. Otherwise allow extension of daughter information in both directions.
155 if (d1 == 0) {
156 d1 = daughter.getIndex();
157 d2 = d1;
158 } else if ((d2 + 1) == daughter.getIndex()) {
159 ++d2;
160 } else if ((d1 - 1) == daughter.getIndex()) {
161 --d1;
162 } else {
163 //Daughter indices are not continuous, cannot continue
164 throw MCParticleGraph::NonContinousDaughtersError();
165 }
166 //Set Vertex and time information if requested
167 setVertexTime(mother, daughter);
168 daughter.m_mother = mother.getIndex();
169 }
170 //Mark particle as seen
171 m_seen[nv] = true;
172 }
173 }
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:549
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:548

◆ finish_vertex()

template<class Vertex, class Graph>
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 {
103 MCParticleGraph::GraphParticle& p = *m_particles[v - 1];
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 }

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

182 {
183 //Only set vertex information if both particles have a valid vertex set
184 m.setValidVertex(m.hasValidVertex() && d.hasValidVertex());
185 if (m.hasValidVertex() && d.getProductionTime() >= m.getDecayTime()) {
186 if (m_setVertex) {
187 m.setDecayVertex(d.getProductionVertex());
188 }
189 if (m_setTime) {
190 m.setDecayTime(d.getProductionTime());
191 }
192 }
193 }
ROOT::Math::XYZVector getProductionVertex() const
Return production vertex position.
Definition MCParticle.h:178
bool hasValidVertex() const
Indication whether vertex and time information is useful or just default.
Definition MCParticle.h:142
float getProductionTime() const
Return production time in ns.
Definition MCParticle.h:148

◆ sort()

template<class Graph>
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
80 MCParticleGraph::GraphParticle dummy(0, 0);
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 198 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 199 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 201 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 205 of file MCParticleGraph.cc.

◆ m_setTime

bool m_setTime
protected

True if the production time information should be saved.

Definition at line 203 of file MCParticleGraph.cc.

◆ m_setVertex

bool m_setVertex
protected

True if the vertex information should be saved.

Definition at line 202 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 206 of file MCParticleGraph.cc.


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