1#ifndef EDEPTRAJECTORY_H
2#define EDEPTRAJECTORY_H
7#include "EDEPTrajectoryPoint.h"
9#include <TGeoManager.h>
23 EDEPTrajectory() : p0_(0,0,0,0), parent_trajectory_(
nullptr),
24 id_(-1), parent_id_(-99), pdg_code_(0) {};
26 EDEPTrajectory(
const TG4Trajectory& trajectory) : p0_(trajectory.GetInitialMomentum()),
27 parent_trajectory_(
nullptr) ,
28 id_(trajectory.GetTrackId()),
29 parent_id_(trajectory.GetParentId()),
30 pdg_code_(trajectory.GetPDGCode()) {};
32 EDEPTrajectory(
const TG4Trajectory& trajectory,
const std::map<
int, std::map<
component, std::vector<EDEPHit>>>& hit_map,
const TG4PrimaryVertexContainer& primaries, TGeoManager* geo);
34 EDEPTrajectory(
const EDEPTrajectory& trj);
35 EDEPTrajectory(EDEPTrajectory&& trj);
69 EDEPTrajectory*
Get() {
return this;};
75 const EDEPTrajectory*
Get()
const {
return this;};
81 EDEPTrajectory*
GetParent()
const {
return parent_trajectory_;};
87 int GetId()
const {
return id_;};
120 std::vector<EDEPTrajectoryPoint>& GetFirstPointsInDetector(
component component_name);
121 std::vector<EDEPTrajectoryPoint>& GetLastPointsInDetector(
component component_name);
145 const EDEPHitsMap&
GetHitMap()
const {
return hit_map_;};
189 void SetParent(EDEPTrajectory* parent_trajectory) {parent_trajectory_ = parent_trajectory;};
198 children_trajectories_.push_back(trajectory);
199 children_trajectories_.back().SetParent(
this);
206 bool HasHits()
const {
return !hit_map_.empty();}
209 std::vector<EDEPHit> GetHitsInDetector(
component component_name)
const;
210 double GetPrimaryDepositedEnergy(
component component_name);
220 bool HasHitInTime(
double start_time,
double stop_time)
const;
224 bool HasHitNear4DPoint(TLorentzVector point,
double distance,
double time)
const;
225 std::vector<EDEPHit>::iterator
GetHitNear4DPoint(TLorentzVector point,
double distance,
double time);
227 std::string
Print(std::string& full_out,
int depth = 100,
int current_depth = 0)
const;
234 template<
typename Funct>
bool HasHitWhere(Funct&& f)
const {
235 for(
const auto& hits:hit_map_) {
236 for(
const auto& hit:hits.second) {
245 template<
typename Funct> std::vector<EDEPHit>::iterator GetHitWhere(Funct&& f) {
246 for(
auto& hits:hit_map_) {
247 for(
auto it = hits.second.begin();
248 it != hits.second.end(); ++it) {
254 return hit_map_.rbegin()->second.end();
257 bool Match(std::string volume, std::initializer_list<std::string> names)
const;
259 void CheckInNext(
bool* in,
bool* next, TG4TrajectoryPoint it, TG4TrajectoryPoint next_it);
261 friend class EDEPTree;
265 EDEPHitsMap hit_map_;
266 EDEPTrajectoryPoints trajectory_points_;
267 std::vector<EDEPTrajectory> children_trajectories_;
268 std::map<component, bool> exiting_map_;
269 std::map<component, bool> entering_map_;
270 EDEPTrajectoryPoints last_points_;
271 EDEPTrajectoryPoints first_points_;
272 EDEPTrajectory* parent_trajectory_;
277 int interaction_number_ = -1;
278 std::string reaction_ =
"";
component
Enum representing different components in the detector.
Definition EDEPUtils.h:12
Represents a trajectory of a particle through a detector.
Definition EDEPTrajectory.h:19
bool operator==(const EDEPTrajectory &trj)
Equality operator for EDEPTrajectory.
Definition EDEPTrajectory.cpp:249
bool HasHitNearPoint(TVector3 point, double distance) const
Checks if any hit is within a given distance from a point.
Definition EDEPTrajectory.cpp:438
const EDEPHitsMap & GetHitMap() const
Get the hit map associated with this trajectory.
Definition EDEPTrajectory.h:145
TLorentzVector GetInitialMomentum() const
Get the initial momentum of this trajectory.
Definition EDEPTrajectory.h:127
~EDEPTrajectory()
Destructor for EDEPTrajectory.
Definition EDEPTrajectory.h:39
bool Match(std::string volume, std::initializer_list< std::string > names) const
Matches a given volume name against a list of names.
Definition EDEPTrajectory.cpp:614
bool HasHitAfterTime(double stop_time) const
Checks if the trajectory has hits after a specified time.
Definition EDEPTrajectory.cpp:414
int GetInteractionNumber() const
Get the number of the interaction that generated this trajectory.
Definition EDEPTrajectory.h:99
bool HasHitWithId(int id) const
Checks if any hit in the trajectory has the specified ID.
Definition EDEPTrajectory.cpp:503
EDEPTrajectory * Get()
Get a pointer to this trajectory.
Definition EDEPTrajectory.h:69
EDEPTrajectory & operator=(const EDEPTrajectory &trj)
Assignment operator for EDEPTrajectory.
Definition EDEPTrajectory.cpp:227
double GetRecursiveDepositedEnergy(component component_name)
Calculates the deposited energy from scintillation in the specified detector component by a trajector...
Definition EDEPTrajectory.cpp:573
void SetDepth(int depth)
Set the depth of this trajectory.
Definition EDEPTrajectory.h:177
bool HasHitInTime(double start_time, double stop_time) const
Checks if the trajectory has hits within a specified time range.
Definition EDEPTrajectory.cpp:424
double GetTotalDepositedEnergy()
Calculates the total deposited energy ove all components.
Definition EDEPTrajectory.cpp:546
bool StartsInDetector(component component_name) const
Checks if the trajectory has its first TrajectoryPoint in the specified component.
Definition EDEPTrajectory.cpp:718
bool IsTrajectorySaturated() const
Checks if the trajectory is saturated (i.e., has reached the maximum number of points).
Definition EDEPTrajectory.cpp:604
int GetPDGCode() const
Get the PDG code of this trajectory.
Definition EDEPTrajectory.h:117
std::vector< EDEPTrajectory > & GetChildrenTrajectories()
Get the children trajectories of this trajectory.
Definition EDEPTrajectory.h:133
bool HasHitNear4DPoint(TLorentzVector 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:458
void SetParentId(int parent_id)
Set the parent ID of this trajectory.
Definition EDEPTrajectory.h:183
double GetDepositedEnergy(component component_name)
Calculates the total deposited energy in the specified detector component.
Definition EDEPTrajectory.cpp:533
std::vector< EDEPTrajectoryPoint > GetTrajectoryPointsInComponentVect(component component_name) const
Get a time-ordered vector of the trajectory points associated with this trajectory,...
Definition EDEPTrajectory.cpp:665
bool HasHitInDetector(component component_name) const
Checks if the trajectory has hits in the specified detector component.
Definition EDEPTrajectory.cpp:388
int GetId() const
Get the ID of this trajectory.
Definition EDEPTrajectory.h:87
bool IsExiting(component component_name) const
Checks if the trajectory is exiting the specified detector component.
Definition EDEPTrajectory.cpp:637
std::vector< EDEPTrajectoryPoint > GetTrajectoryPointsVect() const
Get the trajectory points associated with this trajectory.
Definition EDEPTrajectory.cpp:649
const EDEPTrajectoryPoints & GetTrajectoryPoints() const
Get the trajectory points associated with this trajectory.
Definition EDEPTrajectory.h:151
int GetParentId() const
Get the parent ID of this trajectory.
Definition EDEPTrajectory.h:111
void SetId(int id)
Set the ID of this trajectory.
Definition EDEPTrajectory.h:171
double GetTotalRecursiveDepositedEnergy()
Calculates the deposited energy from scintillation over all components.
Definition EDEPTrajectory.cpp:586
void SetParent(EDEPTrajectory *parent_trajectory)
Set the parent trajectory of this trajectory.
Definition EDEPTrajectory.h:189
bool RemoveChildWithId(int child_id)
Removes a child trajectory with the given ID.
Definition EDEPTrajectory.cpp:311
int GetDepth() const
Get the depth of this trajectory.
Definition EDEPTrajectory.h:93
bool HasHitWithIdInDetector(int id, component component_name) const
Checks if the trajectory has a hit with the specified ID in the specified detector component.
Definition EDEPTrajectory.cpp:519
double GetRecursivePrimaryDepositedEnergy(component component_name)
Calculates the total (scintillation + other) deposited energy in the specified detector component by ...
Definition EDEPTrajectory.cpp:560
std::string GetReaction() const
Get the reaction of the interaction that generated this trajectory.
Definition EDEPTrajectory.h:105
component GetStartDetector() const
Retrieves the component containing the first point of the trajectory.
Definition EDEPTrajectory.cpp:684
bool IsEntering(component component_name) const
Checks if the trajectory is entering the specified detector component.
Definition EDEPTrajectory.cpp:628
void AddChild(const EDEPTrajectory &trajectory)
Add a child trajectory to this trajectory.
Definition EDEPTrajectory.h:197
std::string Print(std::string &full_out, int depth=100, int current_depth=0) const
Prints the trajectory information to stdout and stores it in a string.
Definition EDEPTrajectory.cpp:326
std::vector< EDEPHit >::iterator GetHitNear4DPoint(TLorentzVector point, double distance, double time)
Returns an iterator to the hit near a given 4D point (space and time).
Definition EDEPTrajectory.cpp:482
const EDEPTrajectory * Get() const
Get a const pointer to this trajectory.
Definition EDEPTrajectory.h:75
EDEPTrajectory * GetParent() const
Get the parent trajectory of this trajectory.
Definition EDEPTrajectory.h:81
void CheckInNext(bool *in, bool *next, TG4TrajectoryPoint it, TG4TrajectoryPoint next_it)
Checks for transitions between detector components in a particle trajectory.
Definition EDEPTrajectory.cpp:60
bool HasHitBeforeTime(double start_time) const
Checks if the trajectory has hits before a specified time.
Definition EDEPTrajectory.cpp:405
const std::vector< EDEPTrajectory > & GetChildrenTrajectories() const
Get the const children trajectories of this trajectory.
Definition EDEPTrajectory.h:139
void ComputeDepth()
Computes the depth of the trajectory in the tree.
Definition EDEPTrajectory.cpp:373