EDEpReader
Loading...
Searching...
No Matches
EDEPTree.h
1#include <iostream>
2
3#include "EDEPTrajectory.h"
4
5// Binary search not implemented due to low counts of child elements
6
15class EDEPTree : public EDEPTrajectory {
16
17 public:
18 // Iterators
19 typedef std::vector<EDEPTrajectory>::iterator child_iterator;
20
25 class iterator {
26
27 public:
28 typedef EDEPTrajectory value_type;
29 typedef std::forward_iterator_tag iterator_category;
30 typedef ptrdiff_t difference_type;
31 typedef value_type* pointer;
32 typedef value_type& reference;
33
34 reference operator * () {return *current_it_;};
35 pointer operator -> () {return &(*current_it_);};
36 bool operator == (const iterator& it) {return (this->parent_trj_ == it.parent_trj_ && this->current_it_ == it.current_it_);};
37 bool operator != (const iterator& it) {return (this->parent_trj_ != it.parent_trj_ || this->current_it_ != it.current_it_);};
38 iterator& operator ++ (); //++it
39 iterator operator ++ (int) {iterator tmpIt = *this; ++*this; return tmpIt;}; //it++
40 // iterator& operator -- (); //--it
41 // iterator operator -- (int); //it--
42
43 private:
44 iterator(pointer parent_trj_, child_iterator child_it);
45
46 pointer parent_trj_ = nullptr;
47 child_iterator current_it_;
48
49 friend class EDEPTree;
50 };
51
52 typedef std::vector<EDEPTrajectory>::const_iterator const_child_iterator;
53
58 class const_iterator {
59
60 public:
61 typedef const EDEPTrajectory value_type;
62 typedef std::forward_iterator_tag iterator_category;
63 typedef ptrdiff_t difference_type;
64 typedef value_type* pointer;
65 typedef value_type& reference;
66
67 reference operator * () {return *current_it_;};
68 pointer operator -> () {return &(*current_it_);};
69 bool operator == (const const_iterator& it) {return (this->parent_trj_ == it.parent_trj_ && this->current_it_ == it.current_it_);};
70 bool operator != (const const_iterator& it) {return (this->parent_trj_ != it.parent_trj_ || this->current_it_ != it.current_it_);};
71 const_iterator& operator ++ (); //++it
72 const_iterator operator ++ (int) {const_iterator tmpIt = *this; ++*this; return tmpIt;}; //it++
73 // const_iterator& operator -- (); //--it
74 // const_iterator operator -- (int); //it--
75
76 private:
77 const_iterator(pointer parent_trj_, const_child_iterator child_it);
78
79 pointer parent_trj_ = nullptr;
80 const_child_iterator current_it_;
81
82 friend class EDEPTree;
83 };
84
85 // Constructor
86 EDEPTree();
87
88 // Functions
89 iterator begin() {return iterator(nullptr, this->GetChildrenTrajectories().begin());}
90 const_iterator begin() const {return const_iterator(nullptr, this->GetChildrenTrajectories().begin());}
91 iterator end() {return iterator(nullptr, this->GetChildrenTrajectories().end());}
92 const_iterator end() const {return const_iterator(nullptr, this->GetChildrenTrajectories().end());}
93
94
95 void InizializeFromEdep(const TG4Event& edep_event, TGeoManager* geo);
96 void InizializeFromTrj(const std::vector<EDEPTrajectory>& trajectories_vect);
97
98 void AddTrajectory (const EDEPTrajectory& trajectory);
99 void AddTrajectoryTo(const EDEPTrajectory& trajectory, iterator it);
100
101 void RemoveTrajectory (int trj_id);
102 void RemoveTrajectoryFrom(int trj_id, iterator it);
103 void MoveTrajectoryTo (int id_to_move, int next_parent_id);
104
105 bool HasTrajectory (int trj_id) const;
106 bool IsTrajectoryIn(int trj_id, iterator it);
107 bool IsTrajectoryIn(int trj_id, const_iterator it) const;
108
109 iterator GetTrajectory(int trj_id) {return std::find_if(this->begin(), this->end(), [trj_id](const EDEPTrajectory& trj){ return trj_id == trj.GetId();});}
110 const_iterator GetTrajectory(int trj_id) const {return std::find_if(this->begin(), this->end(), [trj_id](const EDEPTrajectory& trj){ return trj_id == trj.GetId();});}
111
112 iterator GetParentOf(int trj_id);
113 const_iterator GetParentOf(int trj_id) const;
114 iterator GetParentOf(int trj_id, iterator it);
115 const_iterator GetParentOf(int trj_id, const_iterator it) const;
116
117 iterator GetTrajectoryFrom(int trj_id, iterator it);
118 const_iterator GetTrajectoryFrom(int trj_id, const_iterator it) const;
119
122
125
127 const_iterator GetTrajectoryWithHitIdInDetector(int id, component component_name) const;
128
154 template <typename OutputIterator, typename F>
155 OutputIterator Filter(OutputIterator out_it, F&& funct) {
156 for (auto first = this->begin(); first != this->end(); ++first)
157 {
158 if (std::forward<F>(funct)(*first))
159 {
160 *out_it = *first;
161 ++out_it;
162 }
163 }
164
165 return out_it;
166
167 }
168
169 private:
170 void CreateTree(const std::vector<EDEPTrajectory>& trajectories_vect);
171};
172
component
Enum representing different components in the detector.
Definition EDEPUtils.h:12
std::vector< EDEPTrajectory > & GetChildrenTrajectories()
Get the children trajectories of this trajectory.
Definition EDEPTrajectory.h:133
int GetId() const
Get the ID of this trajectory.
Definition EDEPTrajectory.h:87
Const iterator for traversing the tree.
Definition EDEPTree.h:58
const_iterator & operator++()
Prefix increment operator for the const_iterator class.
Definition EDEPTree.cpp:63
Iterator for traversing the tree.
Definition EDEPTree.h:25
iterator & operator++()
Prefix increment operator for the iterator class.
Definition EDEPTree.cpp:20
iterator GetTrajectoryWithHitId(int id)
Returns an iterator to the trajectory containing a hit with the specified ID.
Definition EDEPTree.cpp:324
void RemoveTrajectoryFrom(int trj_id, iterator it)
Removes a trajectory from the tree at a specified position.
Definition EDEPTree.cpp:195
iterator GetTrajectoryWithHitIdInDetector(int id, component component_name)
Retrieves the iterator to the trajectory containing a hit with the given ID in the specified detector...
Definition EDEPTree.cpp:351
void AddTrajectoryTo(const EDEPTrajectory &trajectory, iterator it)
Adds a trajectory to the tree at a specified position.
Definition EDEPTree.cpp:171
void InizializeFromEdep(const TG4Event &edep_event, TGeoManager *geo)
Initializes the tree from a TG4Event and TGeoManager.
Definition EDEPTree.cpp:127
void AddTrajectory(const EDEPTrajectory &trajectory)
Adds a trajectory to the tree.
Definition EDEPTree.cpp:156
bool HasTrajectory(int trj_id) const
Checks if the tree contains a trajectory with the given ID.
Definition EDEPTree.cpp:216
void MoveTrajectoryTo(int id_to_move, int next_parent_id)
Moves a trajectory to a new parent trajectory.
Definition EDEPTree.cpp:204
OutputIterator Filter(OutputIterator out_it, F &&funct)
Filter trajectories based on a custom predicate and copy the results to an output iterator.
Definition EDEPTree.h:155
void InizializeFromTrj(const std::vector< EDEPTrajectory > &trajectories_vect)
Initializes the tree from a vector of trajectories.
Definition EDEPTree.cpp:147
iterator GetParentOf(int trj_id)
Retrieves the parent trajectory of a trajectory with the given ID.
Definition EDEPTree.cpp:250
void RemoveTrajectory(int trj_id)
Removes a trajectory from the tree.
Definition EDEPTree.cpp:186
bool IsTrajectoryIn(int trj_id, iterator it)
Checks if a trajectory is in a specified subtree.
Definition EDEPTree.cpp:227
EDEPTree()
Constructor for the EDEPTree class.
Definition EDEPTree.cpp:95
iterator GetTrajectoryEnd(iterator start)
Retrieves the iterator to the end of the subtree starting from the specified iterator position.
Definition EDEPTree.cpp:374
iterator GetTrajectoryFrom(int trj_id, iterator it)
Retrieves the iterator to the trajectory with the given ID within a specified subtree.
Definition EDEPTree.cpp:297