LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
TrackTrajectory.cxx
Go to the documentation of this file.
1 
11 
12 // LArSoft libraries
13 
14 // C/C++ standard libraries
15 #include <ostream>
16 #include <utility> // std::move()
17 #include <string> // std::to_string()
18 #include <stdexcept> // std::runtime_error
19 
20 //------------------------------------------------------------------------------
22  Positions_t&& positions, Momenta_t&& momenta, Flags_t&& flags, bool hasMomenta
23  )
24  : Trajectory_t(std::move(positions), std::move(momenta), hasMomenta)
25  , fFlags(std::move(flags))
26 {
27  // additional invariant check
28  if (fFlags.size() != NPoints()) {
29  throw std::runtime_error("recob::TrackTrajectory constructed with "
30  + std::to_string(NPoints()) + " points "
31  + std::to_string(fFlags.size())
32  + " point flags! it requires the same number for both."
33  );
34  }
36  throw std::runtime_error("recob::TrackTrajectory constructed with only "
38  + " valid positions! at least 2 are required."
39  );
40  }
41 } // recob::TrackTrajectory::TrackTrajectory()
42 
43 
44 //------------------------------------------------------------------------------
46 
47  unsigned int count = 0;
48  for (size_t index = 0; index < NPoints(); ++index) {
49  if (HasValidPoint(index)) ++count;
50  } // for
51  return count;
52 
53 } // recob::TrackTrajectory::CountValidPoints()
54 
55 
56 //------------------------------------------------------------------------------
58  (std::vector<double>& start, std::vector<double>& end) const
59  { details::legacy::FillTwoVectors(Start(), End(), start, end); }
60 
61 
62 //------------------------------------------------------------------------------
79 double recob::TrackTrajectory::Length(size_t startAt /* = 0 */) const {
80 
81  // sanity check
82  if (startAt >= LastPoint()) return 0.;
83 
84  // just sum the distance between all locations in the trajectory
85  size_t iCurr = ToValidPoint<+1>(startAt);
86  size_t iNext = iCurr;
87  size_t iLast = LastValidPoint();
88  Point_t const* curr = &(LocationAtPoint(iCurr));
89  Coord_t length = 0.0;
90  while ((iNext = ToValidPoint<+1>(++iNext)) <= iLast) {
91  Point_t const* next = &LocationAtPoint(iNext);
92  length += (*next - *curr).R();
93  curr = next;
94  } // while
95  return length;
96 } // recob::TrackTrajectory::Length()
97 
98 
99 //------------------------------------------------------------------------------
100 void recob::TrackTrajectory::Direction(double* start, double* end) const {
102 } // recob::TrackTrajectory::Direction()
103 
104 
105 //------------------------------------------------------------------------------
107  (unsigned int min) const
108 {
109  if (min == 0) return true;
110  unsigned int left = min;
111  for (size_t i = 0; i < NPoints(); ++i) {
112  if (!HasValidPoint(i)) continue;
113  if (--left == 0) return true;
114  } // for
115  return false;
116 
117 } // moreThanTwoValidTrajectoryPoints()
118 
119 //------------------------------------------------------------------------------
120 std::ostream& recob::operator<<
121  (std::ostream&& out, recob::TrackTrajectory const& traj)
122  { traj.Dump(out); return out; }
123 
124 
125 //------------------------------------------------------------------------------
TrackTrajectory()=default
Default constructor; do not use it! it&#39;s needed by ROOT I/O.
size_t LastValidPoint() const
Returns the index of the last valid point in the trajectory.
tracking::Positions_t Positions_t
Type of trajectory point list.
STL namespace.
unsigned int CountValidPoints() const
Computes and returns the number of points with valid location.
tracking::Momenta_t Momenta_t
Type of momentum list.
Flags_t fFlags
Flags of each of the points in trajectory.
double Length(size_t startAt=0) const
Returns the approximate length of the trajectory.
size_t LastPoint() const
Returns the index of the last point in the trajectory.
Definition: Trajectory.h:180
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:172
A trajectory in space reconstructed from hits.
bool HasValidPoint(size_t i) const
Returns whether the specified point has NoPoint flag unset.
Double_t R
std::pair< Vector_t, Vector_t > Direction() const
Returns the trajectory directions at first and last valid points.
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
Definition: Trajectory.h:255
Data product for reconstructed trajectory in space.
std::vector< PointFlags_t > Flags_t
Type of point flag list.
Vector_t EndDirection() const
Returns the direction of the trajectory at the last point.
tracking::Coord_t Coord_t
Type used for coordinates and values in general.
A trajectory in space reconstructed from hits.
Definition: Trajectory.h:72
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
Definition: BitMask.h:187
Int_t min
Definition: plot.C:26
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
bool AtLeastValidTrajectoryPoints(unsigned int left) const
Returns whether there are at least min valid points in the trajectory.
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
Vector_t StartDirection() const
Returns the direction of the trajectory at the first point.
Point_t const & Start() const
Returns the position of the first valid point of the trajectory [cm].
std::pair< Point_t, Point_t > Extent() const
Returns a copy of the first and last valid point in the trajectory.
void FillTwoVectors(SrcVect const &firstSource, SrcVect const &secondSource, DestVect &&firstDest, DestVect &&secondDest)
Converts two vectors into another type of vector using FillVector.