Belle II Software development
MCParticleGraph.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/core/FrameworkExceptions.h>
12#include <framework/core/MemoryPool.h>
13#include <mdst/dataobjects/MCParticle.h>
14
15#include <set>
16#include <string>
17
18
19namespace Belle2 {
38
39 public:
40
41 //Exception definition
42
44 BELLE2_DEFINE_EXCEPTION(CyclicReferenceError, "Cyclic decay, cannot continue");
46 BELLE2_DEFINE_EXCEPTION(NotSameGraphError, "Particles not from same graph");
48 BELLE2_DEFINE_EXCEPTION(NonContinousDaughtersError, "Can not represent decay graph, non continuous indices for daughters");
50 BELLE2_DEFINE_EXCEPTION(DaughterHasMotherError,
51 "A daughter particle was already assigned to a mother. A particle can't have two mothers!");
53 BELLE2_DEFINE_EXCEPTION(OutOfRangeError, "Index out of range");
54
56 typedef std::pair<unsigned int, unsigned int> DecayLine;
57
66 };
67
75 class GraphParticle: public MCParticle {
76
77 public:
86 {
87 MCParticle::operator=(particle);
88 //The pointer to the TClonesArray the MCParticle is stored in makes no
89 //sense inside the Graph so we set it to some invalid value to avoid
90 //the MCParticle::fixParticleList() to complain
91 m_plist = (TClonesArray*) - 1;
92 return *this;
93 }
94
99 void decaysInto(GraphParticle& daughter) { m_graph->addDecay(*this, daughter); }
100
105 void comesFrom(GraphParticle& mother) { m_graph->addDecay(mother, *this); }
106
114 void setFirstDaughter(int daughter) { m_firstDaughter = daughter; }
115
122 void setLastDaughter(int daughter) { m_lastDaughter = daughter; }
123
132 void setIgnore(bool ignore = true) { m_ignore = ignore; }
133
139 bool getIgnore() const { return m_ignore; }
140
147 void setTrackID(int trackID) { m_trackID = trackID; }
148
154 int getTrackID() const { return m_trackID; }
155
156
157 private:
158
162 GraphParticle() = delete;
163
167 GraphParticle(const GraphParticle&) = delete;
168
172 GraphParticle(TClonesArray*, const MCParticle&) {}
173
180 GraphParticle(MCParticleGraph* graph, unsigned int vertexId): MCParticle(),
181 m_graph(graph), m_vertexId(vertexId)
182 {
183 //The pointer to the TClonesArray the MCParticle is stored in makes no
184 //sense inside the Graph so we set it to some invalid value to avoid
185 //the MCParticle::fixParticleList() to complain
186 m_plist = (TClonesArray*) - 1;
187 }
188
193 void setIndex(int index) { m_index = index; }
194
196 unsigned int m_vertexId{0};
197 bool m_ignore{false};
198 bool m_primary{true};
199 int m_trackID{0};
201 friend class MCParticleGraph;
202 friend class ParticleSorter;
203 };
204
209
214 virtual ~MCParticleGraph() { clear(); }
215
221 GraphParticle& addParticle();
222
230 void addDecay(GraphParticle& mother, GraphParticle& daughter);
231
236 GraphParticle& operator[](size_t i) { if (i >= m_particles.size()) throw OutOfRangeError(); return *m_particles[i]; }
237
242 size_t size() const { return m_particles.size(); }
243
256 void generateList(const std::string& name = "", int options = c_setNothing);
257
258
264 void loadList(const std::string& name = "");
265
271 void clear();
272
273
274 protected:
275
280 class ParticleSorter;
281
283 std::set<DecayLine> m_decays;
284 };
285
286
288 {
289 m_particles.clear();
290 m_decays.clear();
291 }
292
293
295 {
296 unsigned int index = m_particles.size() + 1;
298 return *p;
299 }
300
301
303 {
304 if (this != mother.m_graph || this != daughter.m_graph) throw NotSameGraphError();
305 //if (daughter.getMother() != NULL) throw DaughterHasMotherError();
306 m_decays.insert(DecayLine(mother.m_vertexId, daughter.m_vertexId));
307 daughter.m_primary = false;
308 }
309
311} // end namespace Belle2
Class to represent Particle data in graph.
unsigned int m_vertexId
vertex id in the graph
GraphParticle & operator=(const MCParticle &particle)
Assign the values of an existing MCParticle to this GraphParticle.
int m_trackID
The track ID from geant4 that created this particle.
void comesFrom(GraphParticle &mother)
Tells the graph that this particle is a decay product of mother.
void setIndex(int index)
Set the 1-based index of the particle.
void decaysInto(GraphParticle &daughter)
Tells the graph that this particle decays into daughter.
GraphParticle(TClonesArray *, const MCParticle &)
Hide MCParticle "almost copy" constructor.
void setTrackID(int trackID)
Set the track ID for the particle.
GraphParticle()=delete
No default constructor.
void setFirstDaughter(int daughter)
Set the 1-based index of the first daughter, 0 means no daughters.
int getTrackID() const
Returns the track ID assigned to this MCParticle.
void setLastDaughter(int daughter)
Set the 1-based index of the last daughter, 0 means no daughters.
void setIgnore(bool ignore=true)
Set or remove the ignore flag.
bool getIgnore() const
Get the ignore flag.
MCParticleGraph * m_graph
internal pointer to the graph this particle belongs to
GraphParticle(MCParticleGraph *graph, unsigned int vertexId)
Internally used constructor.
bool m_primary
Is this a primary particle ?
GraphParticle(const GraphParticle &)=delete
No copy constructor.
bool m_ignore
ignore particle when writing MCParticle list ?
Class to go over all the particles in the Graph an sort them in a sensible way.
Class to build, validate and sort a particle decay chain.
BELLE2_DEFINE_EXCEPTION(OutOfRangeError, "Index out of range")
The exception is thrown if the specified index is out of range.
BELLE2_DEFINE_EXCEPTION(NotSameGraphError, "Particles not from same graph")
The exception is thrown if two particles do not belong to the same graph.
virtual ~MCParticleGraph()
Destructor.
GraphOptions
Possible options for generating the 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_setNothing
Do nothing special.
@ c_checkCyclic
Check for cyclic dependencies.
@ c_clearParticles
Clear the particle list before adding the graph.
@ c_setDecayInfo
Set decay time and vertex.
BELLE2_DEFINE_EXCEPTION(NonContinousDaughtersError, "Can not represent decay graph, non continuous indices for daughters")
The exception is thrown if a non-physical decay was detected in the graph.
size_t size() const
Return the number of particles in the graph.
GraphParticle & operator[](size_t i)
Return reference to added particle with range check.
BELLE2_DEFINE_EXCEPTION(DaughterHasMotherError, "A daughter particle was already assigned to a mother. A particle can't have two mothers!")
The exception is thrown if a daughter already has a mother assigned to it.
std::pair< unsigned int, unsigned int > DecayLine
Type representing a decay in the graph.
BELLE2_DEFINE_EXCEPTION(CyclicReferenceError, "Cyclic decay, cannot continue")
The exception is thrown if a cyclic reference in the graph was detected.
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.
MCParticleGraph()
Constructor.
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
int m_lastDaughter
1-based index of last daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:562
int m_firstDaughter
1-based index of first daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:561
int m_index
transient pointer to particle list
Definition: MCParticle.h:538
TClonesArray * m_plist
Internal pointer to DataStore Array containing particles belonging to this collection.
Definition: MCParticle.h:532
Class to provide a constant access time memory pool for one kind of objects.
Definition: MemoryPool.h:33
RelationsInterface & operator=(const RelationsInterface &relationsInterface)
Assignment operator.
void addDecay(GraphParticle &mother, GraphParticle &daughter)
Add decay information between two particles.
void clear()
Reset particles and decay information to make the class reusable.
GraphParticle & addParticle()
Add new particle to the graph.
Abstract base class for different kinds of events.