LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TrackTrajectory.cxx
Go to the documentation of this file.
1 
10 
11 // C/C++ standard libraries
12 #include <ostream>
13 #include <stdexcept> // std::runtime_error
14 #include <utility> // std::move()
15 
16 //------------------------------------------------------------------------------
18  Momenta_t&& momenta,
19  Flags_t&& flags,
20  bool hasMomenta)
21  : Trajectory_t(std::move(positions), std::move(momenta), hasMomenta), fFlags(std::move(flags))
22 {
23  // additional invariant check
24  if (fFlags.size() != NPoints()) {
25  throw std::runtime_error(
26  "recob::TrackTrajectory constructed with " + std::to_string(NPoints()) + " points " +
27  std::to_string(fFlags.size()) + " point flags! it requires the same number for both.");
28  }
30  throw std::runtime_error("recob::TrackTrajectory constructed with only " +
32  " valid positions! at least 2 are required.");
33  }
34 } // recob::TrackTrajectory::TrackTrajectory()
35 
36 //------------------------------------------------------------------------------
38 {
39 
40  unsigned int count = 0;
41  for (size_t index = 0; index < NPoints(); ++index) {
42  if (HasValidPoint(index)) ++count;
43  } // for
44  return count;
45 
46 } // recob::TrackTrajectory::CountValidPoints()
47 
48 //------------------------------------------------------------------------------
65 double recob::TrackTrajectory::Length(size_t startAt /* = 0 */) const
66 {
67 
68  // sanity check
69  if (startAt >= LastPoint()) return 0.;
70 
71  // just sum the distance between all locations in the trajectory
72  size_t iCurr = ToValidPoint<+1>(startAt);
73  size_t iNext = iCurr;
74  size_t iLast = LastValidPoint();
75  Point_t const* curr = &(LocationAtPoint(iCurr));
76  Coord_t length = 0.0;
77  while ((iNext = ToValidPoint<+1>(++iNext)) <= iLast) {
78  Point_t const* next = &LocationAtPoint(iNext);
79  length += (*next - *curr).R();
80  curr = next;
81  } // while
82  return length;
83 } // recob::TrackTrajectory::Length()
84 
85 //------------------------------------------------------------------------------
87 {
88  if (min == 0) return true;
89  unsigned int left = min;
90  for (size_t i = 0; i < NPoints(); ++i) {
91  if (!HasValidPoint(i)) continue;
92  if (--left == 0) return true;
93  } // for
94  return false;
95 
96 } // moreThanTwoValidTrajectoryPoints()
97 
98 //------------------------------------------------------------------------------
99 std::ostream& recob::operator<<(std::ostream&& out, recob::TrackTrajectory const& traj)
100 {
101  traj.Dump(out);
102  return out;
103 }
104 
105 //------------------------------------------------------------------------------
void Dump(Stream &&out, unsigned int verbosity, std::string indent, std::string indentFirst) const
Prints trajectory content into a stream.
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:159
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:153
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
A trajectory in space reconstructed from hits.
T LocationAtPoint(unsigned int p) const
Position at point p. Use e.g. as:
bool HasValidPoint(size_t i) const
Returns whether the specified point has NoPoint flag unset.
Data product for reconstructed trajectory in space.
std::vector< PointFlags_t > Flags_t
Type of point flag list.
tracking::Coord_t Coord_t
Type used for coordinates and values in general.
A trajectory in space reconstructed from hits.
Definition: Trajectory.h:66
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:94
bool AtLeastValidTrajectoryPoints(unsigned int left) const
Returns whether there are at least min valid points in the trajectory.
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
std::ostream & operator<<(std::ostream &o, Cluster const &c)
Definition: Cluster.cxx:168