3 #include <edep_reader/EDEPHit.h>
4 #include <edep_reader/EDEPTrajectoryPoint.h>
10 #include <string_view>
11 #include <type_traits>
22 using base_type = std::vector<EDEPTrajectory*>::const_iterator;
25 using iterator_category = std::random_access_iterator_tag;
26 using value_type = std::remove_const_t<T>;
27 using difference_type = std::ptrdiff_t;
33 template <
typename U,
typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
36 base_type base()
const {
return it_; }
38 reference operator* ()
const {
return **it_; }
39 pointer operator->()
const {
return *it_; }
40 reference operator[] (difference_type n)
const {
return **(it_ + n); }
69 using value_type = std::remove_const_t<T>;
75 std::size_t size()
const {
return v_->size(); }
76 bool empty()
const {
return v_->empty(); }
77 T& operator[] (std::size_t i)
const {
return *(*v_).at(i); }
78 T& at(std::size_t i)
const {
return *v_->at(i); }
79 T& front()
const {
return *v_->front(); }
80 T& back()
const {
return *v_->back(); }
83 const std::vector<EDEPTrajectory*>* v_;
101 :
p0_(trajectory.GetInitialMomentum()),
102 id_(trajectory.GetTrackId()),
105 UFW_ASSERT(
id_ !=
parent_id_,
"Trajectory is its own parent");
193 std::vector<EDEPTrajectoryPoint>& GetFirstPointsInDetector(sand::subdetector_t c) {
return first_points_.at(c); }
194 const std::vector<EDEPTrajectoryPoint>& GetFirstPointsInDetector(sand::subdetector_t c)
const {
197 std::vector<EDEPTrajectoryPoint>& GetLastPointsInDetector(sand::subdetector_t c) {
return last_points_.at(c); }
198 const std::vector<EDEPTrajectoryPoint>& GetLastPointsInDetector(sand::subdetector_t c)
const {
228 bool HasHits()
const {
return !
hit_map_.empty(); }
229 bool HasHitWithId(
int id)
const {
return FindHit(
id) !=
nullptr; }
231 bool HasHitInDetector(sand::subdetector_t c)
const {
return hit_map_.find(c) !=
hit_map_.end(); }
243 bool HasHitInTimeAndEnergy(
double start_time,
double stop_time,
double min_energy,
double max_energy)
const;
247 bool HasHitInTime(
double start_time,
double stop_time)
const;
257 std::string Print(std::string& full_out,
int depth = 100,
int current_depth = 0)
const;
259 bool IsEntering(sand::subdetector_t c)
const {
return entering_.at(c); };
260 bool IsExiting(sand::subdetector_t c)
const {
return exiting_.at(c); };
262 template <
typename Funct>
263 bool HasHitWhere(Funct&& f)
const {
265 for (
const auto& hit : hits.second) {
274 template <
typename Funct>
275 const EDEPHit* GetHitWhere(Funct&& f)
const {
277 for (
const auto& hit : hits.second) {
287 static bool Match(std::string_view volume, std::initializer_list<std::string> names);
292 const EDEPHit* FindHit(
int id)
const;
294 static constexpr std::size_t kMaxPoints = 10000;
296 sand::vec_4d
p0_{0, 0, 0, 0};
302 mutable std::array<std::vector<EDEPTrajectoryPoint>, sand::kNumComponents>
last_points_;
303 mutable std::array<std::vector<EDEPTrajectoryPoint>, sand::kNumComponents>
first_points_;
Represents a hit in a detector.
Definition: EDEPHit.h:17
Represents a trajectory of a particle through a detector.
Definition: EDEPTrajectory.h:96
bool HasHitAfterTime(double t) const
Checks if the trajectory has hits after a specified time.
Definition: EDEPTrajectory.cpp:98
bool HasHitInEnergy(double min, double max) const
Checks if the trajectory has hits within a specified energy range.
Definition: EDEPTrajectory.cpp:120
const EDEPHit * GetHitNear4DPoint(sand::vec_4d point, double distance, double time) const
First hit near the 4D point, nullptr if none.
Definition: EDEPTrajectory.cpp:185
int pdg_code_
PDG code of the trajectory.
Definition: EDEPTrajectory.h:307
bool operator==(const EDEPTrajectory &trj) const
Equality operator for EDEPTrajectory.
Definition: EDEPTrajectory.cpp:18
double GetDepositedEnergy(sand::subdetector_t c) const
Sum of the secondary deposits in c, 0 if there are no hits there.
Definition: EDEPTrajectory.cpp:224
double GetTotalEnergyDeposit(sand::subdetector_t c) const
Sum of the total energy deposits (EDEPHit::GetEnergyDeposit) of the hits in c [MeV],...
Definition: EDEPTrajectory.cpp:242
int depth_
Depth of the trajectory.
Definition: EDEPTrajectory.h:308
int GetInteractionNumber() const
Get the number of the interaction that generated this trajectory.
Definition: EDEPTrajectory.h:173
std::array< std::vector< EDEPTrajectoryPoint >, sand::kNumComponents > first_points_
Map of all the last points in each sand::subdetector_t.
Definition: EDEPTrajectory.h:303
bool HasHitWithEnergyLargerThan(double e) const
Checks if the trajectory has hits with energy larger than the specified amount.
Definition: EDEPTrajectory.cpp:89
int id_
ID of the trajectory.
Definition: EDEPTrajectory.h:305
EDEPHitsMap hit_map_
Map of hits associated with the trajectory.
Definition: EDEPTrajectory.h:297
~EDEPTrajectory()=default
Destructor for EDEPTrajectory.
bool HasHitWithEnergySmallerThan(double e) const
Checks if the trajectory has hits with energy smaller than the specified amount.
Definition: EDEPTrajectory.cpp:80
EDEPTrajectory & operator=(const EDEPTrajectory &)=default
Assignment operator for EDEPTrajectory.
bool HasHitInTime(double start_time, double stop_time) const
Checks if the trajectory has hits within a specified time range.
Definition: EDEPTrajectory.cpp:108
bool HasHitNearPoint(sand::pos_3d point, double distance) const
Checks if any hit is within a given distance from a point.
Definition: EDEPTrajectory.cpp:151
const EDEPHit & GetHitWithId(int id) const
Returns the hit in the trajectory with the specified ID.
Definition: EDEPTrajectory.cpp:197
std::array< bool, sand::kNumComponents > exiting_
Map indicating whether the trajectory is exiting a sand::subdetector_t.
Definition: EDEPTrajectory.h:300
EDEPTrajectoryPoints trajectory_points_
Trajectory points.
Definition: EDEPTrajectory.h:298
bool HasHitNear4DPoint(sand::vec_4d point, double distance, double time) const
Checks if any hit is within a given 4D distance (space and time) from a point.
Definition: EDEPTrajectory.cpp:169
bool IsTrajectorySaturated() const
True if the trajectory reached the edep-sim limit on the number of stored points.
Definition: EDEPTrajectory.cpp:270
int parent_id_
Parent ID of the trajectory.
Definition: EDEPTrajectory.h:306
int GetPDGCode() const
Get the PDG code of this trajectory.
Definition: EDEPTrajectory.h:191
std::vector< EDEPTrajectory * > children_
Children trajectories.
Definition: EDEPTrajectory.h:299
bool HasHitWithIdInDetector(int id, sand::subdetector_t c) const
Checks if the trajectory has a hit with the specified ID in the specified detector sand::subdetector_...
Definition: EDEPTrajectory.cpp:211
int GetId() const
Get the ID of this trajectory.
Definition: EDEPTrajectory.h:161
EDEPTrajectory * GetParent() const
Get the parent trajectory of this trajectory.
Definition: EDEPTrajectory.h:155
std::vector< EDEPTrajectoryPoint > GetTrajectoryPointsVect() const
Get the trajectory points associated with this trajectory.
Definition: EDEPTrajectory.cpp:293
int GetParentId() const
Get the parent ID of this trajectory.
Definition: EDEPTrajectory.h:185
EDEPTrajectory * parent_trajectory_
Pointer to the parent trajectory.
Definition: EDEPTrajectory.h:304
bool HasHitBeforeTime(double t) const
Checks if the trajectory has hits before a specified time.
Definition: EDEPTrajectory.cpp:71
int interaction_number_
Number of the interaction that generated this trajectory.
Definition: EDEPTrajectory.h:309
int GetDepth() const
Get the depth of this trajectory.
Definition: EDEPTrajectory.h:167
std::array< std::vector< EDEPTrajectoryPoint >, sand::kNumComponents > last_points_
Map of all the first points in each sand::subdetector_t.
Definition: EDEPTrajectory.h:302
static bool Match(std::string_view volume, std::initializer_list< std::string > names)
True if volume contains any of names as a substring.
Definition: EDEPTrajectory.cpp:284
const EDEPTrajectoryPoints & GetTrajectoryPoints() const
Get the trajectory points associated with this trajectory.
Definition: EDEPTrajectory.h:219
std::string GetReaction() const
Get the reaction of the interaction that generated this trajectory.
Definition: EDEPTrajectory.h:179
std::array< bool, sand::kNumComponents > entering_
Map indicating whether the trajectory is entering a sand::subdetector_t.
Definition: EDEPTrajectory.h:301
std::string reaction_
String corresponding to the reaction that generated this trajectory.
Definition: EDEPTrajectory.h:310
const EDEPHitsMap & GetHitMap() const
Get the hit map associated with this trajectory.
Definition: EDEPTrajectory.h:214
sand::vec_4d p0_
Initial momentum of the trajectory.
Definition: EDEPTrajectory.h:296
EDEPTrajectory * Get()
Get a pointer to this trajectory.
Definition: EDEPTrajectory.h:143
double GetTrackLength(sand::subdetector_t c) const
Sum of the track lengths (EDEPHit::GetTrackLength) of the hits in c [mm], 0 if there are none.
Definition: EDEPTrajectory.cpp:257
const EDEPTrajectory * Get() const
Get a const pointer to this trajectory.
Definition: EDEPTrajectory.h:149
sand::vec_4d GetInitialMomentum() const
Get the initial momentum of this trajectory.
Definition: EDEPTrajectory.h:206
bool HasHitInTimeAndEnergy(double start_time, double stop_time, double min_energy, double max_energy) const
Checks if the trajectory has hits within a specified energy and time ranges.
Definition: EDEPTrajectory.cpp:134
Tree of the trajectories of an edep-sim event. The tree itself is the (id -1) root,...
Definition: EDEPTree.h:24
Definition: EDEPTrajectory.h:21
Non-owning view over a vector of trajectory pointers, usable as a range of trajectory references.
Definition: EDEPTrajectory.h:65