LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
GeoTrajectory.cxx
Go to the documentation of this file.
1 #ifndef BASICTOOL_GEOTRAJECTORY_CXX
2 #define BASICTOOL_GEOTRAJECTORY_CXX
3 
4 #include "GeoTrajectory.h"
5 #include <sstream>
6 namespace geoalgo {
7 
8  Trajectory::Trajectory(size_t npoints, size_t ndimension)
9  : std::vector<geoalgo::Point_t>(npoints, Point_t(ndimension))
10  {}
11 
12  Trajectory::Trajectory(const std::vector<std::vector<double> > &obj)
13  {
14  this->reserve(obj.size());
15  for(auto const& p : obj) this->push_back(Point_t(p));
16  }
17 
18  Trajectory::Trajectory(const std::vector<geoalgo::Point_t> &obj)
19  {
20  this->reserve(obj.size());
21  for(auto const& p : obj) this->push_back(p);
22  }
23 
24  double Trajectory::Length(size_t start_step,size_t end_step) const {
25 
26  if(end_step == 0) end_step = size() - 1; // By default end_step is 0. Then consider the whole trajectory()
27 
28  // Sanity checks
29  if(start_step >= end_step) throw GeoAlgoException("Cannot have start step >= end step!");
30 
31  if(end_step >= size()) throw GeoAlgoException("Requested step index bigger than size!");
32 
33  // if length < 2, no length
34  if(size()<2) return 0;
35 
36  double length = 0;
37  for(size_t i=start_step; i<end_step; ++i)
38 
39  length += (*this)[i]._Dist_((*this)[i+1]);
40 
41  return length;
42  }
43 
44  bool Trajectory::IsLonger(double ref) const {
45 
46  if(size()<2) return false;
47 
48  double length = 0;
49  for(size_t i=0; i<size()-1; ++i) {
50 
51  length += (*this)[i]._Dist_((*this)[i+1]);
52 
53  if(length > ref) return true;
54  }
55 
56  return false;
57  }
58 
59  void Trajectory::push_back(const Point_t& obj) {
60  compat(obj);
61  if (!(size() && obj == (*rbegin())))
62  std::vector<geoalgo::Point_t>::push_back(obj);
63  }
64 
65  void Trajectory::compat(const Point_t& obj) const {
66 
67  if(!size()) return;
68  if( (*(this->begin())).size() != obj.size() ) {
69 
70  std::ostringstream msg;
71  msg << "<<" << __FUNCTION__ << ">>"
72  << " size mismatch: "
73  << (*(this->begin())).size() << " != " << obj.size() << std::endl;
74  throw GeoAlgoException(msg.str());
75  }
76  }
77 
78  void Trajectory::compat(const Trajectory &obj) const {
79 
80  if(!size() || !(obj.size())) return;
81 
82  if( (*(this->begin())).size() != (*obj.begin()).size() ) {
83 
84  std::ostringstream msg;
85  msg << "<<" << __FUNCTION__ << ">>"
86  << " size mismatch: "
87  << (*(this->begin())).size() << " != " << (*obj.begin()).size() << std::endl;
88  throw GeoAlgoException(msg.str());
89 
90  }
91  }
92 
93  Vector Trajectory::Dir(size_t i) const {
94 
95  if(size() < (i+2)) {
96  std::ostringstream msg;
97  msg << "<<" << __FUNCTION__ << ">>"
98  << " length=" << size() << " is too short to find a direction @ index=" << i << std::endl;
99  throw GeoAlgoException(msg.str());
100  }
101  return _Dir_(i);
102  }
103 
104  Vector Trajectory::_Dir_(size_t i) const {
105 
106  return ((*this)[i+1] - (*this)[i]);
107 
108  }
109 }
110 
111 #endif
112 
113 
void compat(const Point_t &obj) const
Dimensionality check function w/ Trajectory.
STL namespace.
Trajectory(size_t npoints=0, size_t ndimension=0)
Default ctor to specify # points and dimension of each point.
void push_back(const Point_t &obj)
push_back overrie w/ dimensionality check
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
Vector Point_t
Definition: GeoVector.h:200
double Length(size_t start_step=0, size_t end_step=0) const
The summed-length along all trajectory points.
Vector Dir(size_t i=0) const
The direction at a specified trajectory point.
bool IsLonger(double) const
Check if the trajectory is longer than specified value.
Class def header for a class Trajectory.
Vector _Dir_(size_t i) const
Returns a direction vector at a specified trajectory point w/o size check.