Belle II Software light-2406-ragdoll
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 49 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 60 of file MCParticleGraph.cc.

60 :
61 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 129 of file MCParticleGraph.cc.

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

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

103 {
105
106 //Reset daughter information, will be filled by find_daughters
107 p.setFirstDaughter(0);
108 p.setLastDaughter(0);
109 //Find all direct daughters
110 find_daughters(v, g, p);
111
112 //If stable particle, set decaytime to infinity
113 if (out_degree(v, g) == 0 && m_setTime) {
114 p.setDecayTime(numeric_limits<double>::infinity());
115 }
116 //If given a pointer to a TClonesArray, create MCParticle at the appropriate index position
117 if (m_plist) {
118 new (m_plist->AddrAt(p.getIndex() - 1)) MCParticle(m_plist, p);
119 }
120 }
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 68 of file MCParticleGraph.cc.

68{ 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 180 of file MCParticleGraph.cc.

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

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

75 {
76 //Set seen flag for all vertices to false
77 m_seen.clear();
78 m_seen.resize(num_vertices(g), false);
79
80 //Create a dummy GraphParticle, needed only to find all primary particles
82
83 //Add all direct children of the 0th vertex to the queue.
84 //This are the primary particles
85 find_daughters(0, g, dummy);
86
87 //Go through the queue and write out each particle.
88 //Daughters of particles will be added to the queue by find_daughters
89 while (!m_vqueue.empty()) {
90 unsigned int cur = m_vqueue.front();
91 m_vqueue.pop();
92 finish_vertex(cur, g);
93 }
94 }
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 197 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 198 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 200 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 204 of file MCParticleGraph.cc.

◆ m_setTime

bool m_setTime
protected

True if the production time information should be saved.

Definition at line 202 of file MCParticleGraph.cc.

◆ m_setVertex

bool m_setVertex
protected

True if the vertex information should be saved.

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


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