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>
36 template <
class Edge,
class Graph>
void back_edge(Edge, Graph&) {
throw MCParticleGraph::CyclicReferenceError(); }
74 template <
class Graph>
void sort(Graph& g)
78 m_seen.resize(num_vertices(g),
false);
107 p.setFirstDaughter(0);
108 p.setLastDaughter(0);
113 if (out_degree(v, g) == 0 &&
m_setTime) {
114 p.setDecayTime(numeric_limits<double>::infinity());
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) {
138 Vertex nv = target(*j, g);
141 if (daughter.m_ignore) {
155 d1 = daughter.getIndex();
157 }
else if ((d2 + 1) == daughter.getIndex()) {
159 }
else if ((d1 - 1) == daughter.getIndex()) {
163 throw MCParticleGraph::NonContinousDaughtersError();
167 daughter.m_mother = mother.
getIndex();
215 typedef adjacency_list<vecS, vecS, directedS> Graph;
216 int num_particles(0);
219 for (
unsigned int i = 0; i <
m_particles.size(); ++i) {
228 depth_first_search(g, visitor(vis));
243 B2ERROR(
"MCParticle Collection is not valid, cannot load into Graph");
247 unsigned numParticles = MCParticles.
getEntries();
248 unsigned particleOffset =
size();
254 for (
unsigned i = 0; i < numParticles; ++i) {
256 const MCParticle& oldParticle = *MCParticles[i];
258 newParticle = oldParticle;
261 if (oldMother !=
nullptr) {
262 unsigned motherIndex = oldMother->
getArrayIndex() + particleOffset;
263 if (motherIndex >=
size())
264 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.
ROOT::Math::XYZVector getProductionVertex() const
Return production vertex position.
bool hasValidVertex() const
Indication whether vertex and time information is useful or just default.
float getProductionTime() const
Return production time in ns.
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.