All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //------------------------------------------------------------------------------
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
TrackTrajectory()=default
Default constructor; do not use it! it&#39;s needed by ROOT I/O.
tracking::Positions_t Positions_t
Type of trajectory point list.
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 NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:167
A trajectory in space reconstructed from hits.
walls no left
Definition: selectors.fcl:105
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:67
std::string to_string(WindowPattern const &pattern)
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::size_t count(Cont const &cont)