9#include <mdst/dataobjects/MCParticleGraph.h>
11#include <framework/datastore/StoreArray.h>
12#include <framework/logging/Logger.h>
14#include <boost/graph/graph_traits.hpp>
15#include <boost/graph/adjacency_list.hpp>
16#include <boost/graph/depth_first_search.hpp>
35 template <
class Edge,
class Graph>
void back_edge(Edge, Graph&) {
throw MCParticleGraph::CyclicReferenceError(); }
73 template <
class Graph>
void sort(Graph& g)
77 m_seen.resize(num_vertices(g),
false);
106 p.setFirstDaughter(0);
107 p.setLastDaughter(0);
112 if (out_degree(v, g) == 0 &&
m_setTime) {
113 p.setDecayTime(numeric_limits<double>::infinity());
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) {
137 Vertex nv = target(*j, g);
140 if (daughter.m_ignore) {
154 d1 = daughter.getIndex();
156 }
else if ((d2 + 1) == daughter.getIndex()) {
158 }
else if ((d1 - 1) == daughter.getIndex()) {
162 throw MCParticleGraph::NonContinousDaughtersError();
166 daughter.m_mother = mother.
getIndex();
182 m.setValidVertex(m.hasValidVertex() && d.hasValidVertex());
183 if (m.hasValidVertex() && d.getProductionTime() >= m.getDecayTime()) {
185 m.setDecayVertex(d.getProductionVertex());
188 m.setDecayTime(d.getProductionTime());
214 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> Graph;
215 int num_particles(0);
218 for (
unsigned int i = 0; i <
m_particles.size(); ++i) {
227 depth_first_search(g, visitor(vis));
242 B2ERROR(
"MCParticle Collection is not valid, cannot load into Graph");
246 unsigned numParticles = MCParticles.
getEntries();
247 unsigned particleOffset =
size();
253 for (
unsigned i = 0; i < numParticles; ++i) {
255 const MCParticle& oldParticle = *MCParticles[i];
257 newParticle = oldParticle;
260 if (oldMother !=
nullptr) {
261 unsigned motherIndex = oldMother->
getArrayIndex() + particleOffset;
262 if (motherIndex >=
size())
263 B2FATAL(
"MCParticle collection \"" << name <<
"\" not sorted correctly: mother index larger than daughter. Cannot load into Graph");
Class to represent Particle data in graph.
void comesFrom(GraphParticle &mother)
Tells the graph that this particle is a decay product of mother.
Class to go over all the particles in the Graph an sort them in a sensible way.
void setVertexTime(MCParticleGraph::GraphParticle &m, const MCParticleGraph::GraphParticle &d)
Set the vertex and time information of the mother particle.
ParticleSorter(MemoryPool< MCParticleGraph::GraphParticle > &particles, TClonesArray *plist, bool setVertex, bool setTime)
ParticleSorter constructor.
MemoryPool< MCParticleGraph::GraphParticle > & m_particles
Reference to the list of particles which should be sorted.
void find_daughters(Vertex v, Graph &g, MCParticleGraph::GraphParticle &mother)
Find the daughters of the given vertex.
void finish_vertex(Vertex v, Graph &g)
Go through the daughters of the vertex.
bool m_setTime
True if the production time information should be saved.
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.
void setStartIndex(int index)
Set the starting index for the particle graph.
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.
void sort(Graph &g)
Sort the particles and generate MCParticle list.
@ 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.
size_t size() const
Return the number of particles in the graph.
std::pair< unsigned int, unsigned int > DecayLine
Type representing a decay in the graph.
void loadList(const std::string &name="")
Load the MCParticle list given by name into the Graph.
std::set< DecayLine > m_decays
internal set of decay lines
MemoryPool< GraphParticle > m_particles
internal list of particles
void generateList(const std::string &name="", int options=c_setNothing)
Generates the MCParticle list and stores it in the StoreArray with the given name.
A Class to store the Monte Carlo particle information.
int m_lastDaughter
1-based index of last daughter particle in collection, 0 if no daughters
int getIndex() const
Get 1-based index of the particle in the corresponding MCParticle list.
int m_firstDaughter
1-based index of first daughter particle in collection, 0 if no daughters
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Class to provide a constant access time memory pool for one kind of objects.
Accessor to arrays stored in the data store.
TClonesArray * getPtr() const
Raw access to the underlying TClonesArray.
int getEntries() const
Get the number of objects in the array.
MCParticle * getMother() const
Returns a pointer to the mother particle.
GraphParticle & addParticle()
Add new particle to the graph.
Abstract base class for different kinds of events.
Simple struct to check boost graph for cyclic references.
void back_edge(Edge, Graph &)
This method is invoked on back edges in the graph.