LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
geoalgo::Trajectory Class Reference

#include "GeoTrajectory.h"

Inheritance diagram for geoalgo::Trajectory:

Public Member Functions

 Trajectory (size_t npoints=0, size_t ndimension=0)
 Default ctor to specify # points and dimension of each point. More...
 
virtual ~Trajectory ()
 Default dtor. More...
 
 Trajectory (const std::vector< std::vector< double >> &obj)
 Alternative ctor (0) using a vector of mere vector point expression. More...
 
 Trajectory (const std::vector< geoalgo::Point_t > &obj)
 Alternative ctor (1) using a vector of point. More...
 
double Length (size_t start_step=0, size_t end_step=0) const
 The summed-length along all trajectory points. More...
 
bool IsLonger (double) const
 Check if the trajectory is longer than specified value. More...
 
Vector Dir (size_t i=0) const
 The direction at a specified trajectory point. More...
 
void push_back (const Point_t &obj)
 push_back overrie w/ dimensionality check More...
 
Trajectoryoperator+= (const Point_t &rhs)
 
void compat (const Point_t &obj) const
 Dimensionality check function w/ Trajectory. More...
 
void compat (const Trajectory &obj) const
 Dimensionality check function w/ Point_t. More...
 
template<class T >
void push_back (const T &obj)
 push_back template More...
 

Public Attributes

elements
 STL member. More...
 

Protected Member Functions

Vector _Dir_ (size_t i) const
 Returns a direction vector at a specified trajectory point w/o size check. More...
 

Friends

std::ostream & operator<< (std::ostream &o, Trajectory const &a)
 Streamer. More...
 

Detailed Description

This class represents a trajectory which is an ordered list of Point. It is a friend class w/ geoalgo::Point_t hence it has an access to protected functions that avoids dimensionality sanity checks for speed.

Definition at line 31 of file GeoTrajectory.h.

Constructor & Destructor Documentation

geoalgo::Trajectory::Trajectory ( size_t  npoints = 0,
size_t  ndimension = 0 
)

Default ctor to specify # points and dimension of each point.

Definition at line 8 of file GeoTrajectory.cxx.

Referenced by ~Trajectory().

9  : std::vector<geoalgo::Point_t>(npoints, Point_t(ndimension))
10  {}
Vector Point_t
Definition: GeoVector.h:204
virtual geoalgo::Trajectory::~Trajectory ( )
inlinevirtual

Default dtor.

Definition at line 38 of file GeoTrajectory.h.

References Dir(), IsLonger(), Length(), push_back(), Trajectory(), and lar::dump::vector().

38 {}
geoalgo::Trajectory::Trajectory ( const std::vector< std::vector< double >> &  obj)

Alternative ctor (0) using a vector of mere vector point expression.

Definition at line 12 of file GeoTrajectory.cxx.

References push_back().

13  {
14  this->reserve(obj.size());
15  for (auto const& p : obj)
16  this->push_back(Point_t(p));
17  }
void push_back(const Point_t &obj)
push_back overrie w/ dimensionality check
Vector Point_t
Definition: GeoVector.h:204
geoalgo::Trajectory::Trajectory ( const std::vector< geoalgo::Point_t > &  obj)

Alternative ctor (1) using a vector of point.

Definition at line 19 of file GeoTrajectory.cxx.

References push_back().

20  {
21  this->reserve(obj.size());
22  for (auto const& p : obj)
23  this->push_back(p);
24  }
void push_back(const Point_t &obj)
push_back overrie w/ dimensionality check

Member Function Documentation

Vector geoalgo::Trajectory::_Dir_ ( size_t  i) const
protected

Returns a direction vector at a specified trajectory point w/o size check.

Definition at line 110 of file GeoTrajectory.cxx.

Referenced by Dir(), and operator+=().

111  {
112  return ((*this)[i + 1] - (*this)[i]);
113  }
void geoalgo::Trajectory::compat ( const Point_t obj) const

Dimensionality check function w/ Trajectory.

Definition at line 70 of file GeoTrajectory.cxx.

References util::begin(), and util::size().

Referenced by geoalgo::GeoAlgo::ClosestPt(), geoalgo::GeoAlgo::commonOrigin(), geoalgo::GeoAlgo::Intersection(), operator+=(), push_back(), and geoalgo::GeoAlgo::SqDist().

71  {
72 
73  if (!size()) return;
74  if ((*(this->begin())).size() != obj.size()) {
75 
76  std::ostringstream msg;
77  msg << "<<" << __FUNCTION__ << ">>"
78  << " size mismatch: " << (*(this->begin())).size() << " != " << obj.size() << std::endl;
79  throw GeoAlgoException(msg.str());
80  }
81  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
void geoalgo::Trajectory::compat ( const Trajectory obj) const

Dimensionality check function w/ Point_t.

Definition at line 83 of file GeoTrajectory.cxx.

References util::begin(), and util::size().

84  {
85 
86  if (!size() || !(obj.size())) return;
87 
88  if ((*(this->begin())).size() != (*obj.begin()).size()) {
89 
90  std::ostringstream msg;
91  msg << "<<" << __FUNCTION__ << ">>"
92  << " size mismatch: " << (*(this->begin())).size() << " != " << (*obj.begin()).size()
93  << std::endl;
94  throw GeoAlgoException(msg.str());
95  }
96  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
Vector geoalgo::Trajectory::Dir ( size_t  i = 0) const

The direction at a specified trajectory point.

Definition at line 98 of file GeoTrajectory.cxx.

References _Dir_(), and util::size().

Referenced by ~Trajectory().

99  {
100 
101  if (size() < (i + 2)) {
102  std::ostringstream msg;
103  msg << "<<" << __FUNCTION__ << ">>"
104  << " length=" << size() << " is too short to find a direction @ index=" << i << std::endl;
105  throw GeoAlgoException(msg.str());
106  }
107  return _Dir_(i);
108  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
Vector _Dir_(size_t i) const
Returns a direction vector at a specified trajectory point w/o size check.
bool geoalgo::Trajectory::IsLonger ( double  ref) const

Check if the trajectory is longer than specified value.

Definition at line 48 of file GeoTrajectory.cxx.

References util::size().

Referenced by ~Trajectory().

49  {
50 
51  if (size() < 2) return false;
52 
53  double length = 0;
54  for (size_t i = 0; i < size() - 1; ++i) {
55 
56  length += (*this)[i]._Dist_((*this)[i + 1]);
57 
58  if (length > ref) return true;
59  }
60 
61  return false;
62  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
double geoalgo::Trajectory::Length ( size_t  start_step = 0,
size_t  end_step = 0 
) const

The summed-length along all trajectory points.

Definition at line 26 of file GeoTrajectory.cxx.

References util::size().

Referenced by ~Trajectory().

27  {
28 
29  if (end_step == 0)
30  end_step = size() - 1; // By default end_step is 0. Then consider the whole trajectory()
31 
32  // Sanity checks
33  if (start_step >= end_step) throw GeoAlgoException("Cannot have start step >= end step!");
34 
35  if (end_step >= size()) throw GeoAlgoException("Requested step index bigger than size!");
36 
37  // if length < 2, no length
38  if (size() < 2) return 0;
39 
40  double length = 0;
41  for (size_t i = start_step; i < end_step; ++i)
42 
43  length += (*this)[i]._Dist_((*this)[i + 1]);
44 
45  return length;
46  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
Trajectory& geoalgo::Trajectory::operator+= ( const Point_t rhs)
inline

Definition at line 59 of file GeoTrajectory.h.

References _Dir_(), compat(), and push_back().

60  {
61  push_back(rhs);
62  return *this;
63  }
void push_back(const Point_t &obj)
push_back overrie w/ dimensionality check
void geoalgo::Trajectory::push_back ( const Point_t obj)

push_back overrie w/ dimensionality check

Definition at line 64 of file GeoTrajectory.cxx.

References compat(), and util::size().

Referenced by operator+=(), push_back(), Trajectory(), and ~Trajectory().

65  {
66  compat(obj);
67  if (!(size() && obj == (*rbegin()))) std::vector<geoalgo::Point_t>::push_back(obj);
68  }
void compat(const Point_t &obj) const
Dimensionality check function w/ Trajectory.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
template<class T >
void geoalgo::Trajectory::push_back ( const T &  obj)
inline

push_back template

Definition at line 81 of file GeoTrajectory.h.

References pt, and push_back().

82  {
83  Point_t pt(obj);
84  push_back(pt);
85  }
recob::tracking::Point_t Point_t
void push_back(const Point_t &obj)
push_back overrie w/ dimensionality check
TMarker * pt
Definition: egs.C:25

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
Trajectory const &  a 
)
friend

Streamer.

Definition at line 90 of file GeoTrajectory.h.

91  {
92  o << "Trajectory with " << a.size() << " points " << std::endl;
93  for (auto const& p : a)
94  o << " " << p << std::endl;
95  return o;
96  }

Member Data Documentation

T std::vector< T >::elements
inherited

STL member.


The documentation for this class was generated from the following files: