11 #include <mdst/dataobjects/MCParticleGraph.h>
13 #include <framework/datastore/StoreArray.h>
14 #include <framework/logging/Logger.h>
16 #include <boost/graph/graph_traits.hpp>
17 #include <boost/graph/adjacency_list.hpp>
18 #include <boost/graph/depth_first_search.hpp>
26 using namespace boost;
38 template <
class Edge,
class Graph>
void back_edge(Edge, Graph&) {
throw MCParticleGraph::CyclicReferenceError(); }
63 m_index(0), m_particles(particles), m_plist(plist), m_setVertex(setVertex), m_setTime(setTime) {}
76 template <
class Graph>
void sort(Graph& g)
80 m_seen.resize(num_vertices(g),
false);
87 find_daughters(0, g, dummy);
91 while (!m_vqueue.empty()) {
92 unsigned int cur = m_vqueue.front();
94 finish_vertex(cur, g);
109 p.setFirstDaughter(0);
110 p.setLastDaughter(0);
112 find_daughters(v, g, p);
115 if (out_degree(v, g) == 0 && m_setTime) {
116 p.setDecayTime(numeric_limits<double>::infinity());
120 new(m_plist->AddrAt(p.getIndex() - 1))
MCParticle(m_plist, p);
134 int& d1 = mother.m_firstDaughter;
135 int& d2 = mother.m_lastDaughter;
137 typename graph_traits<Graph>::out_edge_iterator j, j_end;
138 for (tie(j, j_end) = out_edges(v, g); j != j_end; ++j) {
140 Vertex nv = target(*j, g);
143 if (daughter.m_ignore) {
146 if (!m_seen[nv]) daughter.setIndex(mother.getIndex());
147 find_daughters(nv, g, mother);
151 daughter.setIndex(++m_index);
157 d1 = daughter.getIndex();
159 }
else if ((d2 + 1) == daughter.getIndex()) {
161 }
else if ((d1 - 1) == daughter.getIndex()) {
165 throw MCParticleGraph::NonContinousDaughtersError();
168 setVertexTime(mother, daughter);
169 daughter.m_mother = mother.getIndex();
185 m.setValidVertex(m.hasValidVertex() && d.hasValidVertex());
186 if (m.hasValidVertex() && d.getProductionTime() >= m.getDecayTime()) {
188 m.setDecayVertex(d.getProductionVertex());
191 m.setDecayTime(d.getProductionTime());
211 void MCParticleGraph::generateList(
const string& name,
int options)
217 typedef adjacency_list<vecS, vecS, directedS> Graph;
218 int num_particles(0);
221 for (
unsigned int i = 0; i < m_particles.size(); ++i) {
222 if (!m_particles[i]->m_ignore) ++num_particles;
223 if (m_particles[i]->m_primary) m_decays.insert(DecayLine(0, i + 1));
225 Graph g(m_decays.begin(), m_decays.end(), m_particles.size() + 1);
228 if (options & c_checkCyclic) {
230 depth_first_search(g, visitor(vis));
234 if (options & c_clearParticles) MCParticles.
getPtr()->Clear();
241 void MCParticleGraph::loadList(
const string& name)
245 B2ERROR(
"MCParticle Collection is not valid, cannot load into Graph");
249 unsigned numParticles = MCParticles.
getEntries();
250 unsigned particleOffset = size();
256 for (
unsigned i = 0; i < numParticles; ++i) {
258 const MCParticle& oldParticle = *MCParticles[i];
260 newParticle = oldParticle;
263 if (oldMother != NULL) {
264 unsigned motherIndex = oldMother->
getArrayIndex() + particleOffset;
265 if (motherIndex >= size())
266 B2FATAL(
"MCParticle collection \"" << name <<
"\" not sorted correctly: mother index larger than daughter. Cannot load into Graph");