TrackTrajectory.cxx
Go to the documentation of this file.
1 /**
2  * @file TrackTrajectory.cxx
3  * @brief Data product for reconstructed trajectory in space
4  * @date December 9, 2016
5  * @see TrackTrajectory.h
6  *
7  */
8 
9 
11 
12 // C/C++ standard libraries
13 #include <ostream>
14 #include <utility> // std::move()
15 #include <stdexcept> // std::runtime_error
16 
17 //------------------------------------------------------------------------------
19  Positions_t&& positions, Momenta_t&& momenta, Flags_t&& flags, bool hasMomenta
20  )
21  : Trajectory_t(std::move(positions), std::move(momenta), hasMomenta)
22  , fFlags(std::move(flags))
23 {
24  // additional invariant check
25  if (fFlags.size() != NPoints()) {
26  throw std::runtime_error("recob::TrackTrajectory constructed with "
27  + std::to_string(NPoints()) + " points "
28  + std::to_string(fFlags.size())
29  + " point flags! it requires the same number for both."
30  );
31  }
33  throw std::runtime_error("recob::TrackTrajectory constructed with only "
35  + " valid positions! at least 2 are required."
36  );
37  }
38 } // recob::TrackTrajectory::TrackTrajectory()
39 
40 
41 //------------------------------------------------------------------------------
43 
44  unsigned int count = 0;
45  for (size_t index = 0; index < NPoints(); ++index) {
46  if (HasValidPoint(index)) ++count;
47  } // for
48  return count;
49 
50 } // recob::TrackTrajectory::CountValidPoints()
51 
52 
53 //------------------------------------------------------------------------------
54 /**
55  * @brief Returns the approximate length of the trajectory.
56  * @param startAt (_default: 0, from beginning_) point to start from
57  * @return the approximate length of the trajectory [cm]
58  *
59  * The residual length from the trajectory point startAt to the end of the
60  * trajectory is computed and returned. By default, the whole trajectory
61  * length is returned.
62  * If a non-existing point is specified, 0 is returned.
63  *
64  * The length approximation is just the sum of Euclidean distances between
65  * all consecutive trajectory points (starting from the one with index
66  * `startAt`).
67  *
68  * This operation is slow, and the result should be stored in a variable.
69  */
70 double recob::TrackTrajectory::Length(size_t startAt /* = 0 */) const {
71 
72  // sanity check
73  if (startAt >= LastPoint()) return 0.;
74 
75  // just sum the distance between all locations in the trajectory
76  size_t iCurr = ToValidPoint<+1>(startAt);
77  size_t iNext = iCurr;
78  size_t iLast = LastValidPoint();
79  Point_t const* curr = &(LocationAtPoint(iCurr));
80  Coord_t length = 0.0;
81  while ((iNext = ToValidPoint<+1>(++iNext)) <= iLast) {
82  Point_t const* next = &LocationAtPoint(iNext);
83  length += (*next - *curr).R();
84  curr = next;
85  } // while
86  return length;
87 } // recob::TrackTrajectory::Length()
88 
89 
90 //------------------------------------------------------------------------------
92  (unsigned int min) const
93 {
94  if (min == 0) return true;
95  unsigned int left = min;
96  for (size_t i = 0; i < NPoints(); ++i) {
97  if (!HasValidPoint(i)) continue;
98  if (--left == 0) return true;
99  } // for
100  return false;
101 
102 } // moreThanTwoValidTrajectoryPoints()
103 
104 //------------------------------------------------------------------------------
105 std::ostream& recob::operator<<
106  (std::ostream&& out, recob::TrackTrajectory const& traj)
107  { traj.Dump(out); return out; }
108 
109 
110 //------------------------------------------------------------------------------
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:175
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:167
A trajectory in space reconstructed from hits.
T LocationAtPoint(unsigned int p) const
Position at point p. Use e.g. as:
def move(depos, offset)
Definition: depos.py:107
bool HasValidPoint(size_t i) const
Returns whether the specified point has NoPoint flag unset.
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:67
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
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::string to_string(ModuleType const mt)
Definition: ModuleType.h:34