From 48eb8dad8707ae22ab47c1ba289e81ceede1ea26 Mon Sep 17 00:00:00 2001
From: Riccardo DAmico <rdamico@neutrino-01.novalocal>
Date: Thu, 15 Feb 2024 11:06:57 +0100
Subject: [PATCH 1/3] Added GetFirstPointInDetector and GetLastPointInDetector
 methods and first_points and last_points private variables to EDEPTrajectory

---
 include/EDEPTrajectory.h |   6 ++
 src/EDEPTrajectory.cpp   | 170 ++++++++++++++++++++++++++++++---------
 2 files changed, 139 insertions(+), 37 deletions(-)

diff --git a/include/EDEPTrajectory.h b/include/EDEPTrajectory.h
index 62f8291..7d8d10c 100644
--- a/include/EDEPTrajectory.h
+++ b/include/EDEPTrajectory.h
@@ -42,6 +42,10 @@ class EDEPTrajectory {
     int GetDepth()    const {return depth_;};
     int GetParentId() const {return parent_id_;};
     int GetPDGCode()  const {return pdg_code_;};
+
+     EDEPTrajectoryHits& GetFirstPointInDetector(component component_name);
+     EDEPTrajectoryHits& GetLastPointInDetector(component component_name);
+
     TLorentzVector GetInitialMomentum()  const {return p0_;};
 
           std::vector<EDEPTrajectory>& GetChildrenTrajectories()       {return children_trajectories_;};
@@ -102,6 +106,8 @@ class EDEPTrajectory {
     std::vector<EDEPTrajectory> children_trajectories_;
     std::map<component, bool> exiting_map_;
     std::map<component, bool> entering_map_;
+    std::map<component, EDEPTrajectoryHits> last_points_;
+    std::map<component, EDEPTrajectoryHits> first_points_;
     EDEPTrajectory* parent_trajectory_;
     int id_;
     int parent_id_;
diff --git a/src/EDEPTrajectory.cpp b/src/EDEPTrajectory.cpp
index fdc4782..5034439 100644
--- a/src/EDEPTrajectory.cpp
+++ b/src/EDEPTrajectory.cpp
@@ -28,42 +28,115 @@ EDEPTrajectory::EDEPTrajectory(const TG4Trajectory& trajectory, const TG4HitSegm
                                                pdg_code_(trajectory.GetPDGCode()) {
       
   for (auto it = trajectory.Points.begin(); it != trajectory.Points.end(); ++it) {
-    trajectory_points_.push_back(*it);
-
-    auto next_it = std::next(it);
-
-    if (next_it == trajectory.Points.end()) {
-      continue;
-    }
-
-    auto current_node   = GetNode(*it, geo);
-    auto current_volume = current_node->GetName();
-    auto next_node   = GetNode(*next_it, geo);
-    auto next_volume = next_node->GetName();
-
-    bool in_grain   = Match(current_volume, grain_names);
-    bool in_stt     = Match(current_volume, stt_names);
-    bool in_ecal    = Match(current_volume, ecal_names);
-    bool in_mag     = Match(current_volume, magnet_names);
-    bool in_world   = Match(current_volume, world_names);
-
-    bool next_grain = Match(next_volume,    grain_names);
-    bool next_stt   = Match(next_volume,    stt_names);
-    bool next_ecal  = Match(next_volume,    ecal_names);       
-    bool next_mag   = Match(next_volume,    magnet_names);
-    bool next_world = Match(next_volume,    world_names);
-
-    if (!exiting_map_[component::GRAIN])   exiting_map_[component::GRAIN]   = (in_grain   && ( next_stt   || next_ecal  || next_mag   || next_world ));
-    if (!exiting_map_[component::STRAW])   exiting_map_[component::STRAW]   = (in_stt     && ( next_grain || next_ecal  || next_mag   || next_world ));
-    if (!exiting_map_[component::ECAL])    exiting_map_[component::ECAL]    = (in_ecal    && ( next_stt   || next_grain || next_mag   || next_world ));
-    if (!exiting_map_[component::MAGNET])  exiting_map_[component::MAGNET]  = (in_mag     && ( next_stt   || next_ecal  || next_grain || next_world ));
-    if (!exiting_map_[component::WORLD])   exiting_map_[component::WORLD]   = (in_world   && ( next_stt   || next_ecal  || next_mag   || next_grain ));
-
-    if (!entering_map_[component::GRAIN])  entering_map_[component::GRAIN]  = (next_grain && ( in_stt     || in_ecal    || in_mag     || in_world   ));
-    if (!entering_map_[component::STRAW])  entering_map_[component::STRAW]  = (next_stt   && ( in_grain   || in_ecal    || in_mag     || in_world   ));
-    if (!entering_map_[component::ECAL])   entering_map_[component::ECAL]   = (next_ecal  && ( in_stt     || in_grain   || in_mag     || in_world   ));
-    if (!entering_map_[component::MAGNET]) entering_map_[component::MAGNET] = (next_mag   && ( in_stt     || in_ecal    || in_grain   || in_world   ));
-    if (!entering_map_[component::WORLD])  entering_map_[component::WORLD]  = (next_world && ( in_stt     || in_ecal    || in_mag     || in_grain   ));
+      trajectory_points_.push_back(*it);
+      
+      auto next_it = std::next(it);
+      
+      if (next_it == trajectory.Points.end()) {
+          continue;
+      }
+      
+      auto current_node   = GetNode(*it, geo);
+      auto current_volume = current_node->GetName();
+      auto next_node   = GetNode(*next_it, geo);
+      auto next_volume = next_node->GetName();
+      
+      bool in_grain   = Match(current_volume, grain_names);
+      bool in_stt     = Match(current_volume, stt_names);
+      bool in_ecal    = Match(current_volume, ecal_names);
+      bool in_mag     = Match(current_volume, magnet_names);
+      bool in_world   = Match(current_volume, world_names);
+      
+      bool next_grain = Match(next_volume,    grain_names);
+      bool next_stt   = Match(next_volume,    stt_names);
+      bool next_ecal  = Match(next_volume,    ecal_names);       
+      bool next_mag   = Match(next_volume,    magnet_names);
+      bool next_world = Match(next_volume,    world_names);
+      
+      if (!exiting_map_[component::GRAIN])   exiting_map_[component::GRAIN]   = (in_grain   && ( next_stt   || next_ecal  || next_mag   || next_world ));
+      if (!exiting_map_[component::STRAW])   exiting_map_[component::STRAW]   = (in_stt     && ( next_grain || next_ecal  || next_mag   || next_world ));
+      if (!exiting_map_[component::ECAL])    exiting_map_[component::ECAL]    = (in_ecal    && ( next_stt   || next_grain || next_mag   || next_world ));
+      if (!exiting_map_[component::MAGNET])  exiting_map_[component::MAGNET]  = (in_mag     && ( next_stt   || next_ecal  || next_grain || next_world ));
+      if (!exiting_map_[component::WORLD])   exiting_map_[component::WORLD]   = (in_world   && ( next_stt   || next_ecal  || next_mag   || next_grain ));
+      
+      if (!entering_map_[component::GRAIN])  entering_map_[component::GRAIN]  = (next_grain && ( in_stt     || in_ecal    || in_mag     || in_world   ));
+      if (!entering_map_[component::STRAW])  entering_map_[component::STRAW]  = (next_stt   && ( in_grain   || in_ecal    || in_mag     || in_world   ));
+      if (!entering_map_[component::ECAL])   entering_map_[component::ECAL]   = (next_ecal  && ( in_stt     || in_grain   || in_mag     || in_world   ));
+      if (!entering_map_[component::MAGNET]) entering_map_[component::MAGNET] = (next_mag   && ( in_stt     || in_ecal    || in_grain   || in_world   ));
+      if (!entering_map_[component::WORLD])  entering_map_[component::WORLD]  = (next_world && ( in_stt     || in_ecal    || in_mag     || in_grain   ));
+      
+      
+      if(in_grain && next_stt){
+          last_points_[component::GRAIN].push_back(*it);
+          first_points_[component::STRAW].push_back(*next_it);
+      } else if(in_grain && next_ecal){
+          last_points_[component::GRAIN].push_back(*it);
+          first_points_[component::ECAL].push_back(*next_it);
+      } else if(in_grain && next_mag){
+          last_points_[component::GRAIN].push_back(*it);
+          first_points_[component::MAGNET].push_back(*next_it);
+      } else if(in_grain && next_world){
+          last_points_[component::GRAIN].push_back(*it);
+          first_points_[component::WORLD].push_back(*next_it);
+      }
+      
+      if(in_stt && next_grain){
+          last_points_[component::STRAW].push_back(*it);
+          first_points_[component::GRAIN].push_back(*next_it);
+      } else if(in_stt && next_ecal){
+          last_points_[component::STRAW].push_back(*it);
+          first_points_[component::ECAL].push_back(*next_it);
+      } else if(in_stt && next_mag){
+          last_points_[component::STRAW].push_back(*it);
+          first_points_[component::MAGNET].push_back(*next_it);
+      } else if(in_stt && next_world){
+          last_points_[component::STRAW].push_back(*it);
+          first_points_[component::WORLD].push_back(*next_it);
+      }
+      
+      if(in_ecal && next_grain){
+          last_points_[component::ECAL].push_back(*it);
+          first_points_[component::GRAIN].push_back(*next_it);
+      } else if(in_ecal && next_stt){
+          last_points_[component::ECAL].push_back(*it);
+          first_points_[component::STRAW].push_back(*next_it);
+          
+      } else if(in_ecal && next_mag){
+          last_points_[component::ECAL].push_back(*it);
+          first_points_[component::MAGNET].push_back(*next_it);
+          
+      } else if(in_ecal && next_world){
+          last_points_[component::ECAL].push_back(*it);
+          first_points_[component::WORLD].push_back(*next_it);
+      }
+      
+      if(in_mag && next_grain){
+          last_points_[component::MAGNET].push_back(*it);
+          first_points_[component::GRAIN].push_back(*next_it);
+      } else if(in_mag && next_stt){
+          last_points_[component::MAGNET].push_back(*it);
+          first_points_[component::STRAW].push_back(*next_it);
+      } else if(in_mag && next_ecal){
+          last_points_[component::MAGNET].push_back(*it);
+          first_points_[component::ECAL].push_back(*next_it);
+      } else if(in_mag && next_world){
+          last_points_[component::MAGNET].push_back(*it);
+          first_points_[component::WORLD].push_back(*next_it);
+      }
+      
+      if(in_world && next_grain){
+          last_points_[component::WORLD].push_back(*it);
+          first_points_[component::GRAIN].push_back(*next_it);
+      } else if(in_world && next_stt){
+          last_points_[component::WORLD].push_back(*it);
+          first_points_[component::STRAW].push_back(*next_it);
+      } else if(in_world && next_ecal){
+          last_points_[component::WORLD].push_back(*it);
+          first_points_[component::ECAL].push_back(*next_it);
+      } else if(in_world && next_world){
+          last_points_[component::WORLD].push_back(*it);
+          first_points_[component::MAGNET].push_back(*next_it);
+      }    
   }
 
   for (const auto& hmap:hits) {
@@ -80,6 +153,8 @@ EDEPTrajectory::EDEPTrajectory(const TG4Trajectory& trajectory, const TG4HitSegm
       hit_map_[string_to_component[hmap.first]] = edep_hits;
     }
   }
+
+
 }
 
 EDEPTrajectory::EDEPTrajectory(const EDEPTrajectory& trj) {
@@ -100,7 +175,9 @@ EDEPTrajectory& EDEPTrajectory::operator=(const EDEPTrajectory& trj) {
   this->hit_map_ = trj.hit_map_;
   this->entering_map_ = trj.entering_map_;
   this->exiting_map_ = trj.exiting_map_;
-  this->trajectory_points_ = trj.trajectory_points_;
+  this -> last_points_ = trj.last_points_;
+  this-> first_points_ = trj.first_points_;
+  this->trajectory_points_ = trj.trajectory_points_;  
   return *this;
 }
 
@@ -115,6 +192,8 @@ bool EDEPTrajectory::operator==(const EDEPTrajectory& trj) {
     // this->hit_map_ == trj.hit_map_ &&
     this->entering_map_ == trj.entering_map_ &&
     this->exiting_map_ == trj.exiting_map_ 
+    // this->last_points_ == trj.last_points_ &&
+    // this -> first_points_ == trj.first_points_
     // this->trajectory_points_ == trj.trajectory_points_
   );
 }
@@ -134,6 +213,8 @@ EDEPTrajectory& EDEPTrajectory::operator=(EDEPTrajectory&& trj) {
   std::swap(this->hit_map_, trj.hit_map_);
   std::swap(this->entering_map_, trj.entering_map_);
   std::swap(this->exiting_map_, trj.exiting_map_);
+  std::swap(this->first_points_, trj.first_points_);
+  std::swap(this->last_points_, trj.last_points_);
   std::swap(this->trajectory_points_, trj.trajectory_points_);
   for (auto& t:this->children_trajectories_) {
     t.parent_trajectory_ = this;
@@ -259,3 +340,18 @@ bool EDEPTrajectory::IsEntering(component component_name) const {
 bool EDEPTrajectory::IsExiting(component component_name) const {
   return exiting_map_.at(component_name);
 }
+
+EDEPTrajectoryHits& EDEPTrajectory::GetFirstPointInDetector(component component_name) {
+  
+    if(HasHitInDetector(component_name) && (first_points_.find(component_name) == first_points_.end())){
+      first_points_[component_name].push_back(trajectory_points_.front());
+    }
+    return first_points_.at(component_name);
+}
+
+EDEPTrajectoryHits& EDEPTrajectory::GetLastPointInDetector(component component_name) {
+    if(HasHitInDetector(component_name) && (last_points_.find(component_name) == last_points_.end())){
+      last_points_[component_name].push_back(trajectory_points_.back());
+    }
+    return last_points_.at(component_name);
+}
\ No newline at end of file
-- 
GitLab


From 830dcae94fae0f889ef24be4e61d670f9e11e9ed Mon Sep 17 00:00:00 2001
From: Riccardo DAmico <rdamico@neutrino-01.novalocal>
Date: Mon, 19 Feb 2024 17:37:12 +0100
Subject: [PATCH 2/3] Corrected if statement in constructor

---
 src/EDEPTrajectory.cpp | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/EDEPTrajectory.cpp b/src/EDEPTrajectory.cpp
index 5034439..9791538 100644
--- a/src/EDEPTrajectory.cpp
+++ b/src/EDEPTrajectory.cpp
@@ -99,12 +99,10 @@ EDEPTrajectory::EDEPTrajectory(const TG4Trajectory& trajectory, const TG4HitSegm
           first_points_[component::GRAIN].push_back(*next_it);
       } else if(in_ecal && next_stt){
           last_points_[component::ECAL].push_back(*it);
-          first_points_[component::STRAW].push_back(*next_it);
-          
+          first_points_[component::STRAW].push_back(*next_it);          
       } else if(in_ecal && next_mag){
           last_points_[component::ECAL].push_back(*it);
-          first_points_[component::MAGNET].push_back(*next_it);
-          
+          first_points_[component::MAGNET].push_back(*next_it);    
       } else if(in_ecal && next_world){
           last_points_[component::ECAL].push_back(*it);
           first_points_[component::WORLD].push_back(*next_it);
@@ -133,7 +131,7 @@ EDEPTrajectory::EDEPTrajectory(const TG4Trajectory& trajectory, const TG4HitSegm
       } else if(in_world && next_ecal){
           last_points_[component::WORLD].push_back(*it);
           first_points_[component::ECAL].push_back(*next_it);
-      } else if(in_world && next_world){
+      } else if(in_world && next_mag){
           last_points_[component::WORLD].push_back(*it);
           first_points_[component::MAGNET].push_back(*next_it);
       }    
-- 
GitLab


From a31e88e9a076adf894c808d26aa1efeef959d4a8 Mon Sep 17 00:00:00 2001
From: Riccardo DAmico <rdamico@neutrino-01.novalocal>
Date: Tue, 24 Sep 2024 17:46:30 +0200
Subject: [PATCH 3/3] Changed sand_inner volume flag from ecal to world names
 in EDEPHit. Added generalizations to EDEPTrajectory first and last points.

---
 include/EDEPTrajectory.h |  1 -
 src/EDEPHit.cpp          |  4 +-
 src/EDEPTrajectory.cpp   | 82 +++++++++++++++++++++++++++++-----------
 3 files changed, 61 insertions(+), 26 deletions(-)

diff --git a/include/EDEPTrajectory.h b/include/EDEPTrajectory.h
index 7d8d10c..ae5e4e5 100644
--- a/include/EDEPTrajectory.h
+++ b/include/EDEPTrajectory.h
@@ -76,7 +76,6 @@ class EDEPTrajectory {
     bool HasHitBeforeTime(double start_time) const;
     bool HasHitAfterTime(double stop_time) const;
     bool IsTrajectorySaturated() const;
-
     bool Match(std::string volume, std::initializer_list<std::string> names) const;
     bool IsEntering(component component_name) const;
     bool IsExiting(component component_name) const;
diff --git a/src/EDEPHit.cpp b/src/EDEPHit.cpp
index a3ba6f8..e2073d5 100644
--- a/src/EDEPHit.cpp
+++ b/src/EDEPHit.cpp
@@ -18,6 +18,6 @@ std::map<std::string, component> string_to_component = {
 
 std::initializer_list<std::string> grain_names   = {"GRAIN", "GRIAN"};
 std::initializer_list<std::string> stt_names     = {"horizontalST", "STT", "TrkMod", "CMod", "C3H6Mod"};
-std::initializer_list<std::string> ecal_names    = {"ECAL", "kloe_calo_volume", "sand_inner"};
+std::initializer_list<std::string> ecal_names    = {"ECAL", "kloe_calo_volume"};
 std::initializer_list<std::string> magnet_names  = {"KLOE", "Yoke", "Mag"};
-std::initializer_list<std::string> world_names   = {"World", "rock", "volSAND"};
+std::initializer_list<std::string> world_names   = {"World", "rock", "volSAND" , "volDetEnclosure" , "sand_inner"};
diff --git a/src/EDEPTrajectory.cpp b/src/EDEPTrajectory.cpp
index 9791538..6a66a1a 100644
--- a/src/EDEPTrajectory.cpp
+++ b/src/EDEPTrajectory.cpp
@@ -31,28 +31,55 @@ EDEPTrajectory::EDEPTrajectory(const TG4Trajectory& trajectory, const TG4HitSegm
       trajectory_points_.push_back(*it);
       
       auto next_it = std::next(it);
-      
-      if (next_it == trajectory.Points.end()) {
-          continue;
-      }
-      
+
+
       auto current_node   = GetNode(*it, geo);
-      auto current_volume = current_node->GetName();
-      auto next_node   = GetNode(*next_it, geo);
-      auto next_volume = next_node->GetName();
-      
+      std::string current_volume;
+      if(current_node != nullptr ){
+           current_volume = current_node->GetName();
+      } else {
+        current_volume = "";
+      }
       bool in_grain   = Match(current_volume, grain_names);
       bool in_stt     = Match(current_volume, stt_names);
       bool in_ecal    = Match(current_volume, ecal_names);
       bool in_mag     = Match(current_volume, magnet_names);
       bool in_world   = Match(current_volume, world_names);
       
+
+      if(it == trajectory.Points.begin()){
+          if(in_ecal) first_points_[component::ECAL].push_back(*it);
+          if(in_grain) first_points_[component::GRAIN].push_back(*it);
+          if(in_stt) first_points_[component::STRAW].push_back(*it);
+          if(in_mag) first_points_[component::MAGNET].push_back(*it);
+          if(in_world) first_points_[component::WORLD].push_back(*it);
+      } 
+      if(next_it == trajectory.Points.end()){
+          if(in_ecal) last_points_[component::ECAL].push_back(*it);
+          if(in_grain) last_points_[component::GRAIN].push_back(*it);
+          if(in_stt) last_points_[component::STRAW].push_back(*it);
+          if(in_mag) last_points_[component::MAGNET].push_back(*it);
+          if(in_world) last_points_[component::WORLD].push_back(*it);
+          continue;
+      
+      }
+      auto next_node   = GetNode(*next_it, geo);
+      std::string next_volume;
+      if(next_node != nullptr){
+          next_volume = next_node->GetName();
+
+      } else {
+        next_volume = "";
+
+      }
+
+
       bool next_grain = Match(next_volume,    grain_names);
       bool next_stt   = Match(next_volume,    stt_names);
       bool next_ecal  = Match(next_volume,    ecal_names);       
       bool next_mag   = Match(next_volume,    magnet_names);
       bool next_world = Match(next_volume,    world_names);
-      
+
       if (!exiting_map_[component::GRAIN])   exiting_map_[component::GRAIN]   = (in_grain   && ( next_stt   || next_ecal  || next_mag   || next_world ));
       if (!exiting_map_[component::STRAW])   exiting_map_[component::STRAW]   = (in_stt     && ( next_grain || next_ecal  || next_mag   || next_world ));
       if (!exiting_map_[component::ECAL])    exiting_map_[component::ECAL]    = (in_ecal    && ( next_stt   || next_grain || next_mag   || next_world ));
@@ -64,8 +91,7 @@ EDEPTrajectory::EDEPTrajectory(const TG4Trajectory& trajectory, const TG4HitSegm
       if (!entering_map_[component::ECAL])   entering_map_[component::ECAL]   = (next_ecal  && ( in_stt     || in_grain   || in_mag     || in_world   ));
       if (!entering_map_[component::MAGNET]) entering_map_[component::MAGNET] = (next_mag   && ( in_stt     || in_ecal    || in_grain   || in_world   ));
       if (!entering_map_[component::WORLD])  entering_map_[component::WORLD]  = (next_world && ( in_stt     || in_ecal    || in_mag     || in_grain   ));
-      
-      
+
       if(in_grain && next_stt){
           last_points_[component::GRAIN].push_back(*it);
           first_points_[component::STRAW].push_back(*next_it);
@@ -79,7 +105,7 @@ EDEPTrajectory::EDEPTrajectory(const TG4Trajectory& trajectory, const TG4HitSegm
           last_points_[component::GRAIN].push_back(*it);
           first_points_[component::WORLD].push_back(*next_it);
       }
-      
+
       if(in_stt && next_grain){
           last_points_[component::STRAW].push_back(*it);
           first_points_[component::GRAIN].push_back(*next_it);
@@ -93,7 +119,7 @@ EDEPTrajectory::EDEPTrajectory(const TG4Trajectory& trajectory, const TG4HitSegm
           last_points_[component::STRAW].push_back(*it);
           first_points_[component::WORLD].push_back(*next_it);
       }
-      
+
       if(in_ecal && next_grain){
           last_points_[component::ECAL].push_back(*it);
           first_points_[component::GRAIN].push_back(*next_it);
@@ -107,7 +133,7 @@ EDEPTrajectory::EDEPTrajectory(const TG4Trajectory& trajectory, const TG4HitSegm
           last_points_[component::ECAL].push_back(*it);
           first_points_[component::WORLD].push_back(*next_it);
       }
-      
+
       if(in_mag && next_grain){
           last_points_[component::MAGNET].push_back(*it);
           first_points_[component::GRAIN].push_back(*next_it);
@@ -121,7 +147,7 @@ EDEPTrajectory::EDEPTrajectory(const TG4Trajectory& trajectory, const TG4HitSegm
           last_points_[component::MAGNET].push_back(*it);
           first_points_[component::WORLD].push_back(*next_it);
       }
-      
+
       if(in_world && next_grain){
           last_points_[component::WORLD].push_back(*it);
           first_points_[component::GRAIN].push_back(*next_it);
@@ -134,11 +160,11 @@ EDEPTrajectory::EDEPTrajectory(const TG4Trajectory& trajectory, const TG4HitSegm
       } else if(in_world && next_mag){
           last_points_[component::WORLD].push_back(*it);
           first_points_[component::MAGNET].push_back(*next_it);
-      }    
+      }
   }
 
   for (const auto& hmap:hits) {
-    std::vector<EDEPHit> edep_hits;
+      std::vector<EDEPHit> edep_hits;
     for (uint i = 0; i < hmap.second.size(); i++) {
       auto h = hmap.second[i];
       if (id_ == h.Contrib[0]) {
@@ -153,6 +179,7 @@ EDEPTrajectory::EDEPTrajectory(const TG4Trajectory& trajectory, const TG4HitSegm
   }
 
 
+
 }
 
 EDEPTrajectory::EDEPTrajectory(const EDEPTrajectory& trj) {
@@ -341,15 +368,24 @@ bool EDEPTrajectory::IsExiting(component component_name) const {
 
 EDEPTrajectoryHits& EDEPTrajectory::GetFirstPointInDetector(component component_name) {
   
-    if(HasHitInDetector(component_name) && (first_points_.find(component_name) == first_points_.end())){
-      first_points_[component_name].push_back(trajectory_points_.front());
-    }
+    if( (IsEntering(component_name)|| HasHitInDetector(component_name)) && (first_points_.find(component_name) == first_points_.end())){
+        first_points_[component_name].push_back(trajectory_points_.front());
+    }// else {
+    //     for(int i = 0 ; i< first_points_[component_name].size() ; i ++) {
+    //         for(int j = 0 ; j< last_points_[component_name].size() ; j ++){
+    //             if(first_points_[component_name].at(i).GetPosition().T() >last_points_[component_name].at(j).GetPosition().T() && i == j){
+    //                 std::cout << first_points_[component_name].at(i).GetPosition().T() << std::endl;
+    //                 std::cout << last_points_[component_name].at(j).GetPosition().T() << std::endl;
+    //             } 
+    //         }
+    //     }
+    // }
     return first_points_.at(component_name);
 }
 
 EDEPTrajectoryHits& EDEPTrajectory::GetLastPointInDetector(component component_name) {
-    if(HasHitInDetector(component_name) && (last_points_.find(component_name) == last_points_.end())){
-      last_points_[component_name].push_back(trajectory_points_.back());
+    if((IsEntering(component_name)|| HasHitInDetector(component_name))&& (last_points_.find(component_name) == last_points_.end())){
+        last_points_[component_name].push_back(trajectory_points_.back());
     }
     return last_points_.at(component_name);
 }
\ No newline at end of file
-- 
GitLab