Belle II Software development
MCParticleTrajectory Class Reference

Class to save the full simulated trajectory of a particle. More...

#include <MCParticleTrajectory.h>

Inheritance diagram for MCParticleTrajectory:
RelationsInterface< BASE >

Public Types

typedef std::vector< MCTrajectoryPoint >::iterator iterator
 iterator definition to allow iteration
 
typedef std::vector< MCTrajectoryPoint >::const_iterator const_iterator
 const iterator definition to allow iteration
 

Public Member Functions

 MCParticleTrajectory ()
 Default constructor.
 
iterator begin ()
 return iterator to the first point
 
iterator end ()
 return iterator beyond the last point
 
const_iterator begin () const
 return const iterator to the first point
 
const_iterator end () const
 return const iterator beyond the last point
 
size_t size () const
 return number of points
 
bool empty () const
 return true if size()==0
 
const MCTrajectoryPointoperator[] (size_t index) const
 return a point
 
const MCTrajectoryPointfront () const
 return reference to the first point
 
const MCTrajectoryPointback () const
 return reference to the last point
 
void addPoint (float x, float y, float z, float px, float py, float pz)
 Add a point to the trajectory.
 
void simplify (float distanceTolerance)
 Simplify the trajectory using the Ramer-Douglas-Peuker algorithm.
 
void addRelationTo (const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
 Add a relation from this object to another object (with caching).
 
void addRelationTo (const TObject *object, float weight=1.0, const std::string &namedRelation="") const
 Add a relation from this object to another object (no caching, can be quite slow).
 
void copyRelations (const RelationsInterface< BASE > *sourceObj)
 Copies all relations of sourceObj (pointing from or to sourceObj) to this object (including weights).
 
template<class TO >
RelationVector< TO > getRelationsTo (const std::string &name="", const std::string &namedRelation="") const
 Get the relations that point from this object to another store array.
 
template<class FROM >
RelationVector< FROM > getRelationsFrom (const std::string &name="", const std::string &namedRelation="") const
 Get the relations that point from another store array to this object.
 
template<class T >
RelationVector< T > getRelationsWith (const std::string &name="", const std::string &namedRelation="") const
 Get the relations between this object and another store array.
 
template<class TO >
TO * getRelatedTo (const std::string &name="", const std::string &namedRelation="") const
 Get the object to which this object has a relation.
 
template<class FROM >
FROM * getRelatedFrom (const std::string &name="", const std::string &namedRelation="") const
 Get the object from which this object has a relation.
 
template<class T >
T * getRelated (const std::string &name="", const std::string &namedRelation="") const
 Get the object to or from which this object has a relation.
 
template<class TO >
std::pair< TO *, float > getRelatedToWithWeight (const std::string &name="", const std::string &namedRelation="") const
 Get first related object & weight of relation pointing to an array.
 
template<class FROM >
std::pair< FROM *, float > getRelatedFromWithWeight (const std::string &name="", const std::string &namedRelation="") const
 Get first related object & weight of relation pointing from an array.
 
template<class T >
std::pair< T *, float > getRelatedWithWeight (const std::string &name="", const std::string &namedRelation="") const
 Get first related object & weight of relation pointing from/to an array.
 
virtual std::string getName () const
 Return a short name that describes this object, e.g.
 
virtual std::string getInfoHTML () const
 Return a short summary of this object's contents in HTML format.
 
std::string getInfo () const
 Return a short summary of this object's contents in raw text format.
 
std::string getArrayName () const
 Get name of array this object is stored in, or "" if not found.
 
int getArrayIndex () const
 Returns this object's array index (in StoreArray), or -1 if not found.
 

Protected Member Functions

TClonesArray * getArrayPointer () const
 Returns the pointer to the raw DataStore array holding this object (protected since these arrays are easy to misuse).
 

Private Member Functions

 ClassDef (MCParticleTrajectory, 1)
 Needed to make the ROOT object storable.
 

Private Attributes

std::vector< MCTrajectoryPointm_points
 Collection of points along the trajectory.
 
DataStore::StoreEntrym_cacheDataStoreEntry
 Cache of the data store entry to which this object belongs.
 
int m_cacheArrayIndex
 Cache of the index in the TClonesArray to which this object belongs.
 

Detailed Description

Class to save the full simulated trajectory of a particle.

Definition at line 21 of file MCParticleTrajectory.h.

Member Typedef Documentation

◆ const_iterator

typedef std::vector<MCTrajectoryPoint>::const_iterator const_iterator

const iterator definition to allow iteration

Definition at line 29 of file MCParticleTrajectory.h.

◆ iterator

typedef std::vector<MCTrajectoryPoint>::iterator iterator

iterator definition to allow iteration

Definition at line 27 of file MCParticleTrajectory.h.

Constructor & Destructor Documentation

◆ MCParticleTrajectory()

Default constructor.

Definition at line 24 of file MCParticleTrajectory.h.

std::vector< MCTrajectoryPoint > m_points
Collection of points along the trajectory.
RelationsInterface< TObject > RelationsObject
Provides interface for getting/adding relations to objects in StoreArrays.

Member Function Documentation

◆ addPoint()

void addPoint ( float  x,
float  y,
float  z,
float  px,
float  py,
float  pz 
)
inline

Add a point to the trajectory.

Parameters
xx coordinate of position
yy coordinate of position
zz coordinate of position
pxx coordinate of momentum
pyy coordinate of momentum
pzz coordinate of momentum

Definition at line 56 of file MCParticleTrajectory.h.

57 {
58 //Reserve a decent amount of space to avoid lots of relocations
59 m_points.emplace_back(x, y, z, px, py, pz);
60 }

◆ addRelationTo() [1/2]

void addRelationTo ( const RelationsInterface< BASE > *  object,
float  weight = 1.0,
const std::string &  namedRelation = "" 
) const
inlineinherited

Add a relation from this object to another object (with caching).

Parameters
objectThe object to which the relation should point.
weightThe weight of the relation.
namedRelationAdditional name for the relation, or "" for the default naming

Definition at line 142 of file RelationsObject.h.

143 {
144 if (object)
146 object, object->m_cacheDataStoreEntry, object->m_cacheArrayIndex, weight, namedRelation);
147 }
void addRelation(const TObject *fromObject, StoreEntry *&fromEntry, int &fromIndex, const TObject *toObject, StoreEntry *&toEntry, int &toIndex, float weight, const std::string &namedRelation)
Add a relation from an object in a store array to another object in a store array.
Definition: DataStore.cc:492
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
DataStore::StoreEntry * m_cacheDataStoreEntry
Cache of the data store entry to which this object belongs.
int m_cacheArrayIndex
Cache of the index in the TClonesArray to which this object belongs.

◆ addRelationTo() [2/2]

void addRelationTo ( const TObject *  object,
float  weight = 1.0,
const std::string &  namedRelation = "" 
) const
inlineinherited

Add a relation from this object to another object (no caching, can be quite slow).

Parameters
objectThe object to which the relation should point.
weightThe weight of the relation.
namedRelationAdditional name for the relation, or "" for the default naming

Definition at line 155 of file RelationsObject.h.

156 {
157 StoreEntry* toEntry = nullptr;
158 int toIndex = -1;
159 DataStore::Instance().addRelation(this, m_cacheDataStoreEntry, m_cacheArrayIndex, object, toEntry, toIndex, weight, namedRelation);
160 }

◆ back()

const MCTrajectoryPoint & back ( ) const
inline

return reference to the last point

Definition at line 47 of file MCParticleTrajectory.h.

47{ return m_points.back(); }

◆ begin() [1/2]

iterator begin ( )
inline

return iterator to the first point

Definition at line 31 of file MCParticleTrajectory.h.

31{ return m_points.begin(); }

◆ begin() [2/2]

const_iterator begin ( ) const
inline

return const iterator to the first point

Definition at line 35 of file MCParticleTrajectory.h.

35{ return m_points.begin(); }

◆ copyRelations()

void copyRelations ( const RelationsInterface< BASE > *  sourceObj)
inlineinherited

Copies all relations of sourceObj (pointing from or to sourceObj) to this object (including weights).

Useful if you want to make a complete copy of a StoreArray object to make modifications to it, but retain all information on linked objects.

Note: this only works if sourceObj inherits from the same base (e.g. RelationsObject), and only for related objects that also inherit from the same base.

Definition at line 170 of file RelationsObject.h.

171 {
172 if (!sourceObj)
173 return;
174 auto fromRels = sourceObj->getRelationsFrom<RelationsInterface<BASE>>("ALL");
175 for (unsigned int iRel = 0; iRel < fromRels.size(); iRel++) {
176 fromRels.object(iRel)->addRelationTo(this, fromRels.weight(iRel));
177 }
178
179 auto toRels = sourceObj->getRelationsTo<RelationsInterface<BASE>>("ALL");
180 for (unsigned int iRel = 0; iRel < toRels.size(); iRel++) {
181 this->addRelationTo(toRels.object(iRel), toRels.weight(iRel));
182 }
183 }
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).

◆ empty()

bool empty ( ) const
inline

return true if size()==0

Definition at line 41 of file MCParticleTrajectory.h.

41{ return m_points.empty(); }

◆ end() [1/2]

iterator end ( )
inline

return iterator beyond the last point

Definition at line 33 of file MCParticleTrajectory.h.

33{ return m_points.end(); }

◆ end() [2/2]

const_iterator end ( ) const
inline

return const iterator beyond the last point

Definition at line 37 of file MCParticleTrajectory.h.

37{ return m_points.end(); }

◆ front()

const MCTrajectoryPoint & front ( ) const
inline

return reference to the first point

Definition at line 45 of file MCParticleTrajectory.h.

45{ return m_points.front(); }

◆ getArrayIndex()

int getArrayIndex ( ) const
inlineinherited

Returns this object's array index (in StoreArray), or -1 if not found.

Definition at line 385 of file RelationsObject.h.

386 {
388 return m_cacheArrayIndex;
389 }
bool findStoreEntry(const TObject *object, StoreEntry *&entry, int &index)
Find an object in an array in the data store.
Definition: DataStore.cc:398

◆ getArrayName()

std::string getArrayName ( ) const
inlineinherited

Get name of array this object is stored in, or "" if not found.

Definition at line 377 of file RelationsObject.h.

◆ getArrayPointer()

TClonesArray * getArrayPointer ( ) const
inlineprotectedinherited

Returns the pointer to the raw DataStore array holding this object (protected since these arrays are easy to misuse).

Definition at line 418 of file RelationsObject.h.

419 {
422 return nullptr;
424 }
TClonesArray * getPtrAsArray() const
Return ptr cast to TClonesArray.
Definition: StoreEntry.cc:83

◆ getInfo()

std::string getInfo ( ) const
inlineinherited

Return a short summary of this object's contents in raw text format.

Returns the contents of getInfoHTML() while translating line-breaks etc.

Note
: You don't need to implement this function (it's not virtual), getInfoHTML() is enough.

Definition at line 370 of file RelationsObject.h.

371 {
373 }
virtual std::string getInfoHTML() const
Return a short summary of this object's contents in HTML format.
std::string htmlToPlainText(const std::string &html)
See RelationsObject::getInfo()

◆ getInfoHTML()

virtual std::string getInfoHTML ( ) const
inlinevirtualinherited

Return a short summary of this object's contents in HTML format.

Reimplement this in your own class to provide useful output for display or debugging purposes. For example, you might do something like:

std::stringstream out;
out << "<b>PDG</b>: " << m_pdg << "<br>";
out << "<b>Covariance Matrix</b>: " << HTML::getString(getCovariance5()) << "<br>";
return out.str();
std::string getString(const TMatrixFBase &matrix, int precision=2, bool color=true)
get HTML table representing a matrix.
Definition: HTML.cc:24
See also
Particle::getInfoHTML() for a more complex example.
HTML for some utility functions.
Use getInfo() to get a raw text version of this output.

Reimplemented in Particle, Cluster, MCParticle, PIDLikelihood, SoftwareTriggerResult, Track, TrackFitResult, TRGSummary, and RecoTrack.

Definition at line 362 of file RelationsObject.h.

362{ return ""; }

◆ getName()

virtual std::string getName ( ) const
inlinevirtualinherited

Return a short name that describes this object, e.g.

pi+ for an MCParticle.

Reimplemented in Particle, MCParticle, and SpacePoint.

Definition at line 344 of file RelationsObject.h.

344{ return ""; }

◆ getRelated()

T * getRelated ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get the object to or from which this object has a relation.

Template Parameters
TThe class of objects to or from which the relation points.
Parameters
nameThe name of the store array to or from which the relation points. If empty the default store array name for class T will be used. If the special name "ALL" is given all store arrays containing objects of type T are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
The first related object or a null pointer.

Definition at line 278 of file RelationsObject.h.

279 {
281 T::Class(), name, namedRelation).object);
282 }
@ c_BothSides
Combination of c_FromSide and c_ToSide.
Definition: DataStore.h:79
Belle2::RelationEntry getRelationWith(ESearchSide searchSide, const TObject *object, StoreEntry *&entry, int &index, const TClass *withClass, const std::string &withName, const std::string &namedRelation)
Get the first relation between an object and another object in a store array.
Definition: DataStore.cc:597
TObject * object
Pointer to the object.
Definition: RelationEntry.h:32

◆ getRelatedFrom()

FROM * getRelatedFrom ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get the object from which this object has a relation.

Template Parameters
FROMThe class of objects from which the relation points.
Parameters
nameThe name of the store array from which the relation points. If empty the default store array name for class FROM will be used. If the special name "ALL" is given all store arrays containing objects of type FROM are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
The first related object or a null pointer.

Definition at line 263 of file RelationsObject.h.

264 {
266 m_cacheArrayIndex, FROM::Class(), name, namedRelation).object);
267 }
@ c_FromSide
Return relations/objects pointed from (to a given object).
Definition: DataStore.h:77

◆ getRelatedFromWithWeight()

std::pair< FROM *, float > getRelatedFromWithWeight ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get first related object & weight of relation pointing from an array.

Template Parameters
FROMThe class of objects from which the relation points.
Parameters
nameThe name of the store array from which the relation points. If empty the default store array name for class FROM will be used. If the special name "ALL" is given all store arrays containing objects of type FROM are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
Pair of first related object and the relation weight, or (NULL, 1.0) if none found.

Definition at line 314 of file RelationsObject.h.

316 {
318 FROM::Class(), name, namedRelation);
319 return std::make_pair(static_cast<FROM*>(entry.object), entry.weight);
320 }

◆ getRelatedTo()

TO * getRelatedTo ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get the object to which this object has a relation.

Template Parameters
TOThe class of objects to which the relation points.
Parameters
nameThe name of the store array to which the relation points. If empty the default store array name for class TO will be used. If the special name "ALL" is given all store arrays containing objects of type TO are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
The first related object or a null pointer.

Definition at line 248 of file RelationsObject.h.

249 {
251 TO::Class(), name, namedRelation).object);
252 }
@ c_ToSide
Return relations/objects pointed to (from a given object).
Definition: DataStore.h:78

◆ getRelatedToWithWeight()

std::pair< TO *, float > getRelatedToWithWeight ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get first related object & weight of relation pointing to an array.

Template Parameters
TOThe class of objects to which the relation points.
Parameters
nameThe name of the store array to which the relation points. If empty the default store array name for class TO will be used. If the special name "ALL" is given all store arrays containing objects of type TO are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
Pair of first related object and the relation weight, or (NULL, 1.0) if none found.

Definition at line 297 of file RelationsObject.h.

299 {
301 TO::Class(), name, namedRelation);
302 return std::make_pair(static_cast<TO*>(entry.object), entry.weight);
303 }

◆ getRelatedWithWeight()

std::pair< T *, float > getRelatedWithWeight ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get first related object & weight of relation pointing from/to an array.

Template Parameters
TThe class of objects to or from which the relation points.
Parameters
nameThe name of the store array to or from which the relation points. If empty the default store array name for class T will be used. If the special name "ALL" is given all store arrays containing objects of type T are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
Pair of first related object and the relation weight, or (NULL, 1.0) if none found.

Definition at line 331 of file RelationsObject.h.

333 {
335 T::Class(), name, namedRelation);
336 return std::make_pair(static_cast<T*>(entry.object), entry.weight);
337 }

◆ getRelationsFrom()

RelationVector< FROM > getRelationsFrom ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get the relations that point from another store array to this object.

Template Parameters
FROMThe class of objects from which the relations point.
Parameters
nameThe name of the store array from which the relations point. If empty the default store array name for class FROM will be used. If the special name "ALL" is given all store arrays containing objects of type FROM are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
A vector of relations.

Definition at line 212 of file RelationsObject.h.

214 {
216 m_cacheArrayIndex, FROM::Class(), name, namedRelation));
217 }
RelationVector< T > getRelationsWith(const std::string &name="", const std::string &namedRelation="") const
Get the relations between this object and another store array.

◆ getRelationsTo()

RelationVector< TO > getRelationsTo ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get the relations that point from this object to another store array.

Template Parameters
TOThe class of objects to which the relations point.
Parameters
nameThe name of the store array to which the relations point. If empty the default store array name for class TO will be used. If the special name "ALL" is given all store arrays containing objects of type TO are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
A vector of relations.

Definition at line 197 of file RelationsObject.h.

198 {
200 m_cacheArrayIndex, TO::Class(), name, namedRelation));
201 }

◆ getRelationsWith()

RelationVector< T > getRelationsWith ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get the relations between this object and another store array.

Relations in both directions are returned.

Template Parameters
TThe class of objects to or from which the relations point.
Parameters
nameThe name of the store array to or from which the relations point. If empty the default store array name for class T will be used. If the special name "ALL" is given all store arrays containing objects of type T are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
A vector of relations.

Definition at line 230 of file RelationsObject.h.

231 {
233 m_cacheArrayIndex, T::Class(), name, namedRelation));
234 }

◆ operator[]()

const MCTrajectoryPoint & operator[] ( size_t  index) const
inline

return a point

Definition at line 43 of file MCParticleTrajectory.h.

43{ return m_points[index]; }

◆ simplify()

void simplify ( float  distanceTolerance)

Simplify the trajectory using the Ramer-Douglas-Peuker algorithm.

Parameters
distanceTolerancemaximum distance of the simplified path to the points of the original path

Definition at line 33 of file MCParticleTrajectory.cc.

34{
35 // cannot simplify anything, return
36 if (distance_tolerance <= 0 || m_points.size() < 3) return;
37
38 // stack with all segments to be investigated
39 std::stack<std::pair<iterator, iterator>> stack;
40 // push full trajectory on the stack
41 stack.push(make_pair(m_points.begin(), m_points.end() - 1));
42 // next free point: we always want the starting point so start at index 1
43 iterator nextFreePoint = m_points.begin() + 1;
44 // iterators used for the segment inspection
45 iterator firstPoint, splitPoint, finalPoint;
46 // segment direction and vector between segment start and mid point
47 ROOT::Math::XYZVector n, pa;
48 // investigate all segments until all fulfill the distance requirement
49 while (!stack.empty()) {
50 //Get first and last point
51 std::tie(firstPoint, finalPoint) = stack.top();
52 //Remove segment from stack
53 stack.pop();
54 //Direction of the segment
55 setVector(n, *firstPoint, *finalPoint, true);
56 //Calculate maximum distance of all intermediate points to the segment
57 double maxDistance(0);
58 for (auto nextPoint = firstPoint + 1; nextPoint != finalPoint; ++nextPoint) {
59 //vector from segment start (p) to point (a)
60 setVector(pa, *firstPoint, *nextPoint);
61 //3D distance between point a and line p + x*n
62 const double dist = (pa - (pa.Dot(n)) * n).R();
63 //check if this is the maximum distance so far
64 if (dist > maxDistance) {
65 splitPoint = nextPoint;
66 maxDistance = dist;
67 }
68 }
69 //Are all points close enough? if not split the segment at the largest distance
70 if (maxDistance > distance_tolerance) {
71 //If we split in this order, all points will be in correct order since we
72 //use a stack: last thing put in is first thing to get out. So initially
73 //we inspect everything, if we divide we put in the second part and then
74 //the first and in the next round we take out the first and repeat. So
75 //effectively we look at all segments in an ordered way.
76 stack.push(make_pair(splitPoint, finalPoint));
77 stack.push(make_pair(firstPoint, splitPoint));
78 continue;
79 }
80 //Ok, all points close enough, add the final point to list of points. Due
81 //to the order in which we look at the points in a ordered way we can
82 //replace the points in place
83 *(nextFreePoint++) = *finalPoint;
84 }
85
86 //Now delete all remaining elements
87 m_points.erase(nextFreePoint, end());
88}
std::vector< MCTrajectoryPoint >::iterator iterator
iterator definition to allow iteration
iterator end()
return iterator beyond the last point

◆ size()

size_t size ( ) const
inline

return number of points

Definition at line 39 of file MCParticleTrajectory.h.

39{ return m_points.size(); }

Member Data Documentation

◆ m_cacheArrayIndex

int m_cacheArrayIndex
mutableprivateinherited

Cache of the index in the TClonesArray to which this object belongs.

Definition at line 432 of file RelationsObject.h.

◆ m_cacheDataStoreEntry

DataStore::StoreEntry* m_cacheDataStoreEntry
mutableprivateinherited

Cache of the data store entry to which this object belongs.

Definition at line 429 of file RelationsObject.h.

◆ m_points

std::vector<MCTrajectoryPoint> m_points
private

Collection of points along the trajectory.

Definition at line 70 of file MCParticleTrajectory.h.


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