All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackTrajectory.h
Go to the documentation of this file.
1 /**
2  * @file TrackTrajectory.h
3  * @brief Data product for reconstructed trajectory in space
4  * @date December 9, 2016
5  * @version 2.4 (20170119)
6  *
7  * Changes
8  * --------
9  *
10  * - 20170119 [v2.4]
11  * taken from recob::Trajectory, with added flags
12  *
13  */
14 
15 #ifndef LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_H
16 #define LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_H
17 
18 // ROOT libraries
21 
22 // C/C++ standard libraries
23 #include <vector>
24 #include <iosfwd> // std::ostream
25 #include <limits> // std::numeric_limits<>
26 
27 
28 namespace recob {
29 
30 
31  /** **************************************************************************
32  * @brief A trajectory in space reconstructed from hits.
33  * @see recob::Trajectory, recob::Track,
34  * recob::trackutil::makeTrajectory()
35  *
36  * The track trajectory class contains a trajectory in 6D space representing
37  * the path walked by a particle. A trajectory point is made of a 3D position
38  * component (measured in centimeters) and a momentum component (measured in
39  * GeV/c); for a discussion on the object type for coordinates see recob::tracking::Coord_t.
40  * The associated hits are integral part of the track trajectory.
41  * To store additional point-by-point information, the track trajectory
42  * augments `recob::Trajectory`, of which it presents most of the interface,
43  * with point metadata called for convenience "flags".
44  *
45  * Each point is formally associated to a reconstructed hit, as for
46  * `recob::Trajectory` requirements. One flag set is provided for each point,
47  * whose flags describe the point and/or the hit.
48  *
49  * The meaning of the flags is documented also in the flags class
50  * `recob::TrajectoryPointFlagTraits`, which can be accessed as typedef
51  * `flags` in this class (e.g. `recob::TrackTrajectory::flag::NoPoint`).
52  *
53  *
54  * Invariants
55  * -----------
56  *
57  * The same as `recob::Trajectory`, plus:
58  * * there must be one flag set per trajectory point
59  * * there must be at least two points with the flag `NoPoint` not set
60  *
61  */
64 
65  public:
66  /// Type used for coordinates and values in general.
68 
69  /// Type for representation of position in physical 3D space.
71 
72  /// Type for representation of momenta in 3D space.
74 
75  /// Type for flags of a point/hit
77 
78  /// Flag traits (including the definition of flag mnemonics).
80 
81  /// Type of trajectory point list.
83 
84  /// Type of momentum list.
86 
87  /// Type of point flag list.
88  using Flags_t = std::vector<PointFlags_t>;
89 
90  /// Mnemonics for the access to begin and end of trajectory.
92 
93  /// A point in the trajectory, with position and momentum.
95 
96  /// Type for representation of space rotations.
98 
99 
100  /// Default constructor; do not use it! it's needed by ROOT I/O.
101  TrackTrajectory() = default;
102 
103 
104  /**
105  * @brief Constructor: specifies all the data for the trajectory.
106  * @param positions (_moved_) trajectory as a sorted list of points
107  * @param momenta (_moved_) momentum along the trajectory, one per point
108  * @param flags (_moved_) flag sets, one flag set per point
109  * @param hasMomenta whether the information on momentum modulus is provided
110  * @throws std::runtime_error if the invariants are violated
111  * @see recob::trackutil::makeTrackTrajectory()
112  *
113  * The most convenient way to create a recob::Trajectory is to use
114  * `recob::trackutil::makeTrackTrajectory()`.
115  *
116  *
117  * Requirements
118  * -------------
119  *
120  * - one momentum is required for each trajectory point
121  * - one flag is required for each trajectory point
122  * - at least two points must be provided
123  *
124  */
126  Positions_t&& positions,
127  Momenta_t&& momenta,
128  Flags_t&& flags,
129  bool hasMomenta
130  );
131 
132 
133  /**
134  * @brief Constructor: copies positions and momenta from an existing Trajectory, adds the flags.
135  * @param traj existing Trajectory
136  * @param flags (_moved_) flag sets, one flag set per point
137  * @throw std::runtime_error if the invariants are violated
138  */
139  TrackTrajectory(const Trajectory& traj, Flags_t&& flags)
140  : TrackTrajectory(Positions_t(traj.Positions()),Momenta_t(traj.Momenta()),std::move(flags),traj.HasMomentum()) {}
141 
142 
143  /// Returns the plain trajectory of this object
144  Trajectory_t const& Trajectory() const
145  { return static_cast<Trajectory_t const&>(*this); }
146 
147 
149 
150  using Trajectory_t::NPoints;
151 
153 
155 
157 
158  /**
159  * @brief Returns the flags for the specified trajectory point.
160  * @param i index of the point in the trajectory
161  * @return flags for the specified trajectory point [cm]
162  *
163  * If the point index is invalid, the result is undefined.
164  */
165  PointFlags_t const& FlagsAtPoint(size_t i) const
166  { return fFlags[i]; }
167 
168  /**
169  * @brief Returns all flags.
170  */
171  Flags_t const& Flags() const
172  { return fFlags; }
173 
174  /**
175  * @brief Returns whether the specified point has `NoPoint` flag unset.
176  * @return whether the specified point has `NoPoint` flag unset
177  *
178  * A point with flag `NoPoint` set is actually an invalid point, that the
179  * algorithm could not at all set, but it has still a hit associated with
180  * it.
181  *
182  * If the point index is invalid, false is returned.
183  */
184  bool HasValidPoint(size_t i) const
185  {
186  return Trajectory().HasPoint(i)
188  }
189 
190  /**
191  * @brief Returns the index of the first valid point in the trajectory.
192  * @return index of the first point in the trajectory, or `InvalidIndex`
193  *
194  * Returns the index of the first point with the flag `NoPoint` unset.
195  * It never returns `InvalidIndex` unless the track trajectory is invalid.
196  */
197  size_t FirstValidPoint() const
198  { return NextValidPoint(0U); }
199 
200  /**
201  * @brief Returns the index of the next valid point in the trajectory.
202  * @param index starting index
203  * @return index of next valid point in the trajectory, or `InvalidIndex`
204  *
205  * Returns the index of the first point with the flag `NoPoint` unset,
206  * starting with the point with the specified index (included), and moving
207  * forward toward the end of the trajectory.
208  * It returns `InvalidIndex` if point at index is invalid and there are no
209  * valid points left after it.
210  */
211  size_t NextValidPoint(size_t index) const
212  { return ToValidPoint<+1>(index); }
213 
214  /**
215  * @brief Returns the index of the previous valid point in the trajectory.
216  * @param index starting index
217  * @return index of previous valid point in trajectory, or `InvalidIndex`
218  *
219  * Returns the index of the first point with the flag `NoPoint` unset,
220  * starting with the point with the specified index (included), and moving
221  * backward toward the start of the trajectory.
222  * It returns `InvalidIndex` if point at index is invalid and there are no
223  * valid points before it.
224  */
225  size_t PreviousValidPoint(size_t index) const
226  { return ToValidPoint<-1>(index); }
227 
228  /**
229  * @brief Returns the index of the last valid point in the trajectory.
230  * @return index of the last point in the trajectory, or `InvalidIndex`
231  *
232  * Returns the index of the last point with the flag `NoPoint` unset.
233  * It never returns `InvalidIndex` unless the track trajectory is invalid.
234  */
235  size_t LastValidPoint() const
236  { return PreviousValidPoint(LastPoint()); }
237 
238  /**
239  * @brief Computes and returns the number of points with valid location.
240  * @return number of points in the trajectory with valid location
241  *
242  * This method is slow, taking O(NPoints()) time.
243  */
244  unsigned int CountValidPoints() const;
245 
247 
248  /// Returns the position of the first valid point of the trajectory [cm].
249  Point_t const& Vertex() const
250  { return Start(); }
251 
252  /// Returns the position of the first valid point of the trajectory [cm].
253  Point_t const& Start() const
254  { return LocationAtPoint(FirstValidPoint()); }
255 
256  /// Returns the position of the last valid point of the trajectory [cm].
257  Point_t const& End() const
258  { return LocationAtPoint(LastValidPoint()); }
259 
261 
262  /**
263  * @brief Fills the first and last valid point in the trajectory.
264  * @param start (_output_) position of the beginning of the trajectory
265  * @param end (_output_) position of the end of the trajectory
266  *
267  * The labelling of start and end is consistent within the trajectory but is
268  * not guaranteed to be physically correct.
269  */
270  template<typename T> std::pair<T,T> Extent( ) const { return { Vertex<T>(), End<T>() }; }
271 
272  /**
273  * @brief Returns a copy of the first and last valid point in the
274  * trajectory.
275  * @return a pair: the first and last point in the trajectory
276  *
277  * The labelling of start and end is consistent within the trajectory but is
278  * not guaranteed to be physically correct.
279  *
280  * Example:
281  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
282  *
283  * recob::TrackTrajectory::Point_t start, end;
284  *
285  * std::tie(start, end) = traj.Extent(); // assign both start and end
286  *
287  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
288  */
289  std::pair<Point_t, Point_t> Extent() const
290  { return { Start(), End() }; }
291 
292 
293  /**
294  * @brief Returns the approximate length of the trajectory.
295  * @param startAt (_default: 0, from beginning_) point to start from
296  * @return the approximate length of the trajectory [cm]
297  *
298  * The residual length from the trajectory point startAt to the end of the
299  * trajectory is computed and returned. By default, the whole trajectory
300  * length is returned.
301  * All invalid points are skipped. If after skipping, less than two valid
302  * points are left, 0 is returned.
303  *
304  * The length approximation is just the sum of Euclidean distances between
305  * each valid trajectory point and the next (starting from the first valid
306  * one with index `startAt` or larger).
307  *
308  * This operation is slow, and the result should be stored in a variable.
309  */
310  double Length (size_t startAt = 0) const;
311 
312  /// Returns the direction of the trajectory at the first point.
314  { return StartDirection(); }
315 
316  /// Returns the direction of the trajectory at the first point.
318  { return DirectionAtPoint(FirstValidPoint()); }
319 
320  /// Returns the direction of the trajectory at the last point.
322  { return DirectionAtPoint(LastValidPoint()); }
323 
324 
325  /**
326  * @brief Trajectory angle at point, with respect to positive _z_ direction.
327  * @param p the index point to extract the angle from (_no default!_)
328  * @return angle with respect to positive _z_, in @f$ [0,\pi] @f$ [radians]
329  *
330  * The angle @f$ \vartheta @f$ is returned, as defined in
331  * `recob::Trajectory::Theta()`, for point with the specified index `p`.
332  *
333  * If the point is invalid, the behaviour is undefined.
334  *
335  * @note This function has no default value for `p`; if `p` is not specified
336  * at all, the method `Theta()` is called instead.
337  *
338  */
339  double Theta(size_t p) const
340  { return Trajectory().Theta(p); }
341 
342  /**
343  * @brief Trajectory angle at start, with respect to positive _z_ direction.
344  * @return angle with respect to positive _z_, in @f$ [0,\pi] @f$ [radians]
345  *
346  * The angle @f$ \vartheta @f$ is returned, as defined in
347  * `recob::Trajectory::Theta()`, for the first valid point in the
348  * trajectory.
349  *
350  * @note This is _not_ equivalent to `Theta(0)`, but instead to
351  * `Theta(FirstValidPoint())`.
352  */
353  double Theta() const
354  { return Theta(FirstValidPoint()); }
355 
356  /**
357  * @brief Azimuthal angle at a point on the trajectory, with respect to _z_.
358  * @param p the index point to extract the angle from (_no default!_)
359  * @return the azimuthal angle, in @f$ [-\pi,\pi[ @f$ [radians]
360  * @see Phi(), Theta(size_t), ZenithAngle(size_t)
361  *
362  * The angle @f$ \phi @f$ is returned, as defined in
363  * `recob::Trajectory::Phi()`, for point with the specified index `p`.
364  *
365  * If the point is invalid, the behaviour is undefined.
366  *
367  * @note This function has no default value for `p`; if `p` is not specified
368  * at all, the method `Phi()` is called instead.
369  *
370  */
371  double Phi(size_t p) const
372  { return Trajectory().Phi(p); }
373 
374  /**
375  * @brief Azimuthal angle at a first valid point, with respect to _z_.
376  * @return angle with respect to positive _z_, in @f$ [0,\pi] @f$ [radians]
377  * @see Phi(size_t), Theta(), ZenithAngle()
378  *
379  * The angle @f$ \phi @f$ is returned, as defined in
380  * `recob::Trajectory::Phi()`, for the first valid point in the trajectory.
381  *
382  * @note This is _not_ equivalent to `Phi(0)`, but instead to
383  * `Phi(FirstValidPoint())`.
384  */
385  double Phi() const
386  { return Phi(FirstValidPoint()); }
387 
388 
389  /**
390  * @brief "Zenith" angle of trajectory, with respect to the vertical axis.
391  * @param p the index point to extract the angle from (_no default!_)
392  * @return opposite of the actual zenith angle, in @f$ [0,\pi] @f$ [radians]
393  * @see AzimuthAngle(size_t)
394  *
395  * The zenith is returned, as defined in `recob::Trajectory::Zenith()`,
396  * for point with the specified index `p`.
397  *
398  * If the point is invalid, the behaviour is undefined.
399  *
400  * @note This function has no default value for `p`; if `p` is not specified
401  * at all, the method `Zenith()` is called instead.
402  *
403  */
404  double ZenithAngle(size_t p) const
405  { return Trajectory().ZenithAngle(p); }
406 
407  /**
408  * @brief "Zenith" angle of trajectory, with respect to the vertical axis.
409  * @return opposite of the actual zenith angle, in @f$ [0,\pi] @f$ [radians]
410  * @see Zenith(size_t), Theta()
411  *
412  * The zenith angle is returned, as defined in
413  * `recob::Trajectory::Zenith()`, for the first valid point in the
414  * trajectory.
415  *
416  * @note This is _not_ equivalent to `Zenith(0)`, but instead to
417  * `Zenith(FirstValidPoint())`.
418  */
419  double ZenithAngle() const
420  { return ZenithAngle(FirstValidPoint()); }
421 
422  /**
423  * @brief "Azimuth" angle of trajectory, with respect to the sky.
424  * @param p the index point to extract the angle from (_no default!_)
425  * @return the azimuth angle, in @f$ [-\pi,\pi[ @f$ [radians]
426  * @see AzimuthAngle(), ZenithAngle(size_t), Phi(size_t)
427  *
428  * The azimuth is returned, as defined in `recob::Trajectory::Azimuth()`,
429  * for point with the specified index `p`.
430  *
431  * If the point is invalid, the behaviour is undefined.
432  *
433  * @note This function has no default value for `p`; if `p` is not specified
434  * at all, the method `Azimuth()` is called instead.
435  *
436  */
437  double AzimuthAngle(size_t p) const
438  { return Trajectory().AzimuthAngle(p); }
439 
440  /**
441  * @brief "Azimuth" angle of trajectory, with respect to the sky.
442  * @return the azimuth angle, in @f$ [-\pi,\pi[ @f$ [radians]
443  * @see AzimuthAngle(size_t), ZenithAngle(), Phi()
444  * @see Zenith(size_t), Theta()
445  *
446  * The azimuth angle is returned, as defined in
447  * `recob::Trajectory::Azimuth()`, for the first valid point in the
448  * trajectory.
449  *
450  * @note This is _not_ equivalent to `Azimuth(0)`, but instead to
451  * `Azimuth(FirstValidPoint())`.
452  */
453  double AzimuthAngle() const
454  { return AzimuthAngle(FirstValidPoint()); }
455 
456 
457  /// Returns the momentum of the trajectory at the first valid point [GeV/c].
459  { return StartMomentumVector(); }
460 
461  /// Returns the momentum of the trajectory at the first valid point [GeV/c].
464 
465  /// Returns the momentum of the trajectory at the last valid point [GeV/c].
468 
469 
470  /// Computes and returns the modulus of momentum at the first point [GeV/c].
471  /// @see StartMomentum()
472  double VertexMomentum() const
473  { return StartMomentum(); }
474 
475  /// Computes and returns the modulus of momentum at the first point [GeV/c].
476  /// @see StartMomentumVector()
477  double StartMomentum() const
478  { return StartMomentumVector().R(); }
479 
480  /// Computes and returns the modulus of momentum at the last point [GeV/c].
481  /// @see EndMomentumVector()
482  double EndMomentum() const
483  { return EndMomentumVector().R(); }
484 
485 
487 
489 
491 
493 
494  /**
495  * @brief Fills the starting and ending direction of the trajectory.
496  * @param start (_output_) direction at the beginning of the trajectory
497  * @param end (_output_) direction at the end of the trajectory
498  *
499  * The two arguments are expected to point each one to an area with room for
500  * at least three `double` numbers.
501  * The two filled vectors have norm 1.
502  *
503  * The labelling of start and end is consistent within the trajectory but is
504  * not guaranteed to be physically correct.
505  */
506  template<typename T> std::pair<T,T> Direction() const { return { VertexDirection<T>(), EndDirection<T>() }; }
507 
508 
509  /**
510  * @brief Returns the trajectory directions at first and last valid points.
511  * @return a pair with the first and last direction
512  *
513  * The two returned vectors have norm 1.
514  * The labelling of start and end is consistent within the trajectory but is
515  * not guaranteed to be physically correct.
516  *
517  * Example:
518  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
519  *
520  * recob::Trajectory::Vector_t startDir, endDir;
521  *
522  * std::tie(startDir, endDir) = traj.Direction(); // assign start and end
523  *
524  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
525  */
526  std::pair<Vector_t, Vector_t> Direction() const
527  { return { StartDirection(), EndDirection() }; }
528 
529 
531 
533 
534  /// @{
535  /// @name Templated version of homonymous functions to access to position, direction, and momentum information.
536 
537  /// Start position. Use e.g. as: @code{.cpp} TVector3 start = tracktraj.Start<TVector3>(); @endcode.
538  template<typename T> inline T Start() const { auto& loc = Start(); return T(loc.X(),loc.Y(),loc.Z()); }
539 
540  /// Start position. Use e.g. as: @code{.cpp} TVector3 vertex = tracktraj.Vertex<TVector3>(); @endcode.
541  template<typename T> inline T Vertex() const { auto& loc = Vertex(); return T(loc.X(),loc.Y(),loc.Z()); }
542 
543  /// End position. Use e.g. as: @code{.cpp} TVector3 end = tracktraj.End<TVector3>(); @endcode.
544  template<typename T> inline T End() const { auto& loc = End(); return T(loc.X(),loc.Y(),loc.Z()); }
545 
546  /// Position at point p. Use e.g. as: @code{.cpp} TVector3 pos = tracktraj.LocationAtPoint<TVector3>(p); @endcode.
547  template<typename T> inline T LocationAtPoint(unsigned int p) const { auto& loc = LocationAtPoint(p); return T(loc.X(),loc.Y(),loc.Z()); }
548 
549  /// Start direction. Use e.g. as: @code{.cpp} TVector3 startdir = tracktraj.StartDirection<TVector3>(); @endcode.
550  template<typename T> inline T StartDirection() const { auto dir = StartDirection(); return T(dir.X(),dir.Y(),dir.Z()); }
551 
552  /// Start direction. Use e.g. as: @code{.cpp} TVector3 vertexdir = tracktraj.VertexDirection<TVector3>(); @endcode.
553  template<typename T> inline T VertexDirection() const { auto dir = VertexDirection(); return T(dir.X(),dir.Y(),dir.Z()); }
554 
555  /// End direction. Use e.g. as: @code{.cpp} TVector3 enddir = tracktraj.EndDirection<TVector3>(); @endcode.
556  template<typename T> inline T EndDirection() const { auto dir = EndDirection(); return T(dir.X(),dir.Y(),dir.Z()); }
557 
558  /// Direction at point p. Use e.g. as: @code{.cpp} TVector3 dir = tracktraj.DirectionAtPoint<TVector3>(p); @endcode.
559  template<typename T> inline T DirectionAtPoint(unsigned int p) const { auto dir = DirectionAtPoint(p); return T(dir.X(),dir.Y(),dir.Z()); }
560 
561  /// Momentum vector at start point. Use e.g. as: @code{.cpp} TVector3 startmom = tracktraj.StartMomentumVector<TVector3>(); @endcode.
562  template<typename T> inline T StartMomentumVector() const { auto mom = StartMomentumVector(); return T(mom.X(),mom.Y(),mom.Z()); }
563 
564  /// Momentum vector at start point. Use e.g. as: @code{.cpp} TVector3 vertexmom = tracktraj.VertexMomentumVector<TVector3>(); @endcode.
565  template<typename T> inline T VertexMomentumVector() const { auto mom = VertexMomentumVector(); return T(mom.X(),mom.Y(),mom.Z()); }
566 
567  /// Momentum vector at end point. Use e.g. as: @code{.cpp} TVector3 endmom = tracktraj.EndMomentumVector<TVector3>(); @endcode.
568  template<typename T> inline T EndMomentumVector() const { auto mom = EndMomentumVector(); return T(mom.X(),mom.Y(),mom.Z()); }
569 
570  /// Momentum vector at point p. Use e.g. as: @code{.cpp} TVector3 mom = tracktraj.MomentumVectorAtPoint<TVector3>(p); @endcode.
571  template<typename T> inline T MomentumVectorAtPoint(unsigned int p) const { auto mom = MomentumVectorAtPoint(p); return T(mom.X(),mom.Y(),mom.Z()); }
572 
573  /// Returns a rotation matrix that brings trajectory direction along _z_. Use e.g. as: @code{.cpp} TMatrixD rot = tracktraj.GlobalToLocalRotationAtPoint<TMatrixD>(p); @endcode.
574  template<typename T> inline T GlobalToLocalRotationAtPoint(unsigned int p) const {
575  T rot(3,3);
576  GlobalToLocalRotationAtPoint(p).GetRotationMatrix(rot);
577  return rot;
578  }
579 
580  /// Returns a rotation matrix bringing relative directions to global. Use e.g. as: @code{.cpp} TMatrixD rot = tracktraj.LocalToGlobalRotationAtPoint<TMatrixD>(p); @endcode.
581  template<typename T> inline T LocalToGlobalRotationAtPoint(unsigned int p) const {
582  T rot(3,3);
583  LocalToGlobalRotationAtPoint(p).GetRotationMatrix(rot);
584  return rot;
585  }
586  /// @}
587 
588  /**
589  * @brief Prints trajectory content into a stream.
590  * @tparam Stream type of the output stream
591  * @param out stream to output the information into
592  * @param verbosity verbosity level (default: `1`)
593  * @param indent indentation string (default: none)
594  * @param indentFirst indentation for first output line (default: as indent)
595  *
596  * The amount of information dumped to screen is regulated by the
597  * Indentation string is prepended to each line, and the first line has its
598  * own special indentation string (`indentFirst`).
599  *
600  * The output can be multi-line, it ends with no end-of-line and it does not
601  * inserts an end-of-line at its beginning (unless that is explicitly inside
602  * `indentFirst`).
603  * The lowest verbosity is guaranteed to be on a single line.
604  *
605  *
606  * Information printed out (`verbosity` argument)
607  * -----------------------------------------------
608  *
609  * * level `0`: start position, direction, momentum modulus and number of
610  * points
611  * * level `1`: also end position, direction and momentum modulus
612  * * level `2`: also trajectory length
613  * * level `3`: also angles at start
614  * * level `4`: also 9 intermediate valid trajectory points
615  * * level `5`: also 10 more intermediate valid trajectory points (19 total)
616  * * level `6`: all valid trajectory points
617  * * level `7`: all trajectory points
618  *
619  * @internal Default values are implemented in a different method.
620  *
621  */
622  template <typename Stream>
623  void Dump(
624  Stream&& out,
625  unsigned int verbosity,
626  std::string indent, std::string indentFirst
627  ) const;
628 
629  /**
630  * @brief Prints trajectory content into a stream.
631  * @tparam Stream type of the output stream
632  * @param out stream to output the information into
633  * @param verbosity verbosity level (default: `1`)
634  * @param indent indentation string (default: none)
635  * @see Dump(Stream&&, unsigned int, std::string, std::string)
636  *
637  * Implementation detail for Dump(Stream&&, unsigned int, std::string).
638  */
639  template <typename Stream>
640  void Dump
641  (Stream&& out, unsigned int verbosity = 1, std::string indent = {})
642  const
643  { Dump(std::forward<Stream>(out), verbosity, indent, indent); }
644 
645  /**
646  * @brief Prints low-level trajectory content into a stream.
647  * @tparam Stream type of the output stream
648  * @param out stream to output the information into
649  * @param indent indentation string (default: none)
650  * @param indentFirst indentation for first output line (default: as indent)
651  */
652  template <typename Stream>
653  void LowLevelDump
654  (Stream&& out, std::string indent, std::string indentFirst) const;
655 
656 
657  /// Largest verbosity level supported by Dump().
658  static constexpr unsigned int MaxDumpVerbosity = 7;
659 
660  /// Value returned on failed index queries
661  static constexpr size_t InvalidIndex = std::numeric_limits<size_t>::max();
662 
663  private:
664 
665  Flags_t fFlags; ///< Flags of each of the points in trajectory
666 
667 
668  /**
669  * @brief Returns the index of the first valid point from index on.
670  * @tparam Dir the direction to move when an index has an invalid point
671  * @param index the starting index
672  * @return index of the first valid point from index on (or InvalidIndex)
673  *
674  * The valid direction `Dir` values are only +1 and -1.
675  * The first point considered is always the one at `index`.
676  * If no valid point is found, `InvalidIndex` is returned.
677  * The invariant guarantees that all these calls return a valid index:
678  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
679  * if (!(
680  * (ToValidPoint<+1>(0) != InvalidIndex) // FirstValidPoint()
681  * && (ToValidPoint<-1>(LastPoint()) != InvalidIndex) // LastValidPoint()
682  * && (ToValidPoint<+1>(FirstValidPoint()) != InvalidIndex) // LastValidPoint()
683  * && (ToValidPoint<-1>(LastValidPoint()) != InvalidIndex) // FirstValidPoint()
684  * )) throw std::logic_error("Invalid TrackTrajectory!");
685  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
686  */
687  template <int Dir>
688  size_t ToValidPoint(size_t index) const;
689 
690  /// Returns whether there are at least `min` valid points in the trajectory.
691  bool AtLeastValidTrajectoryPoints(unsigned int left) const;
692 
693  }; // class TrackTrajectory
694 
695 
696  /**
697  * @brief Prints trajectory content into a stream.
698  * @tparam Stream type of the output stream
699  * @param out stream to output the information into
700  * @param traj trajectory to be printed
701  * @return a reference to stream
702  *
703  * See `recob::Trajectory::Dump()` for details.
704  */
705  std::ostream& operator << (std::ostream&& out, TrackTrajectory const& traj);
706 
707 
708 } // namespace recob
709 
710 
711 //------------------------------------------------------------------------------
712 //--- Inline implementation
713 //---
714 
715 //------------------------------------------------------------------------------
716 //--- Template implementation
717 //---
718 #include "TrackTrajectory.tcc"
719 
720 //------------------------------------------------------------------------------
721 
722 
723 #endif // LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_H
Double32_t Coord_t
Definition: TrackingTypes.h:23
void Dump(Stream &&out, unsigned int verbosity, std::string indent, std::string indentFirst) const
Prints trajectory content into a stream.
double Phi(size_t p=0) const
Azimuthal angle at a point on the trajectory, with respect to z.
Definition: Trajectory.h:337
Data product for reconstructed trajectory in space.
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
T VertexDirection() const
Start direction. Use e.g. as:
bool HasPoint(size_t i) const
Returns whether the specified trajectory point is available.
Definition: Trajectory.h:183
A point in the trajectory, with position and momentum.
Definition: TrackingTypes.h:63
Trajectory_t const & Trajectory() const
Returns the plain trajectory of this object.
T Vertex() const
Start position. Use e.g. as:
TrajectoryPointFlagTraits flag
Type of flag traits (indices and meaning of flags).
TrackTrajectory()=default
Default constructor; do not use it! it&#39;s needed by ROOT I/O.
Flags_t const & Flags() const
Returns all flags.
static constexpr Flag_t NoPoint
The trajectory point is not defined.
T DirectionAtPoint(unsigned int p) const
Direction at point p. Use e.g. as:
T EndDirection() const
End direction. Use e.g. as:
bool isSet(Flag_t flag) const
Returns true if the flag exists and is set.
size_t LastValidPoint() const
Returns the index of the last valid point in the trajectory.
Ends_t
Mnemonics for the access to begin and end of trajectory.
Definition: Trajectory.h:85
T GlobalToLocalRotationAtPoint(unsigned int p) const
Returns a rotation matrix that brings trajectory direction along z. Use e.g. as:
T Start() const
Start position. Use e.g. as:
pdgs p
Definition: selectors.fcl:22
tracking::Positions_t Positions_t
Type of trajectory point list.
double ZenithAngle(size_t p) const
&quot;Zenith&quot; angle of trajectory, with respect to the vertical axis.
Vector_t const & StartMomentumVector() const
Returns the momentum of the trajectory at the first valid point [GeV/c].
T VertexMomentumVector() const
Momentum vector at start point. Use e.g. as:
Vector_t const & VertexMomentumVector() const
Returns the momentum of the trajectory at the first valid point [GeV/c].
T StartDirection() const
Start direction. Use e.g. as:
Namespace for the trajectory point flags.
double AzimuthAngle(size_t p=0) const
&quot;Azimuth&quot; angle of trajectory, with respect to the sky.
Definition: Trajectory.cxx:96
T LocalToGlobalRotationAtPoint(unsigned int p) const
Returns a rotation matrix bringing relative directions to global. Use e.g. as:
double ZenithAngle(size_t p=0) const
&quot;Zenith&quot; angle of trajectory, with respect to the vertical axis.
Definition: Trajectory.cxx:82
double EndMomentum() const
T StartMomentumVector() const
Momentum vector at start point. Use e.g. as:
Rotation_t LocalToGlobalRotationAtPoint(size_t p) const
Returns a rotation matrix bringing relative directions to global.
Definition: Trajectory.cxx:136
unsigned int CountValidPoints() const
Computes and returns the number of points with valid location.
tracking::Momenta_t Momenta_t
Type of momentum list.
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
std::pair< T, T > Extent() const
Fills the first and last valid point in the trajectory.
Flags_t fFlags
Flags of each of the points in trajectory.
Vector_t DirectionAtPoint(size_t i) const
Computes and returns the direction of the trajectory at a point.
Definition: Trajectory.cxx:117
Rotation_t GlobalToLocalRotationAtPoint(size_t p) const
Returns a rotation matrix that brings trajectory direction along z.
Definition: Trajectory.cxx:128
double AzimuthAngle() const
&quot;Azimuth&quot; angle of trajectory, with respect to the sky.
T EndMomentumVector() const
Momentum vector at end point. Use e.g. as:
Vector_t VertexDirection() const
Returns the direction of the trajectory at the first point.
std::pair< T, T > Direction() const
Fills the starting and ending direction of the trajectory.
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space. See recob::tracking::Coord_t for more details on the ...
Definition: TrackingTypes.h:29
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 PreviousValidPoint(size_t index) const
Returns the index of the previous valid point in the trajectory.
const Positions_t & Positions() const
Returns reference to stored vector of positions.
Definition: Trajectory.h:190
TrajectoryPoint_t TrajectoryPoint(size_t i) const
Returns position and momentum at the specified trajectory point.
Definition: Trajectory.h:213
PointFlags_t const & FlagsAtPoint(size_t i) const
Returns the flags for the specified trajectory point.
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:
double MomentumAtPoint(size_t i) const
Computes and returns the modulus of the momentum at a point.
Definition: Trajectory.h:442
bool HasValidPoint(size_t i) const
Returns whether the specified point has NoPoint flag unset.
std::pair< Vector_t, Vector_t > Direction() const
Returns the trajectory directions at first and last valid points.
double StartMomentum() const
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
Definition: Trajectory.h:236
tracking::Rotation_t Rotation_t
Type for representation of space rotations.
std::vector< Vector_t > Momenta_t
Type of momentum list.
Definition: TrackingTypes.h:35
double ZenithAngle() const
&quot;Zenith&quot; angle of trajectory, with respect to the vertical axis.
walls no left
Definition: selectors.fcl:105
tracking::Vector_t Vector_t
Type for representation of momenta in 3D space.
std::vector< PointFlags_t > Flags_t
Type of point flag list.
size_t FirstPoint() const
Returns the index of the first point in the trajectory (yep, it&#39;s 0).
Definition: Trajectory.h:171
size_t NumberTrajectoryPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:156
Set of flags pertaining a point of the track.
double Phi(size_t p) const
Azimuthal angle at a point on the trajectory, with respect to z.
Point_t const & Vertex() const
Returns the position of the first valid point of the trajectory [cm].
tuple dir
Definition: dropbox.py:28
ROOT::Math::Rotation3D Rotation_t
Type for representation of space rotations.
Definition: TrackingTypes.h:38
Vector_t const & MomentumVectorAtPoint(size_t i) const
Returns the momentum vector at a point.
Definition: Trajectory.h:457
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:67
double Theta(size_t p) const
Trajectory angle at point, with respect to positive z direction.
size_t ToValidPoint(size_t index) const
Returns the index of the first valid point from index on.
std::vector< Point_t > Positions_t
Type of trajectory point list.
Definition: TrackingTypes.h:32
size_t FirstValidPoint() const
Returns the index of the first valid point in the trajectory.
static constexpr size_t InvalidIndex
Value returned on failed index queries.
bool HasMomentum() const
Returns whether information about the momentum is available.
Definition: Trajectory.h:425
Vector_t const & EndMomentumVector() const
Returns the momentum of the trajectory at the last valid point [GeV/c].
static constexpr unsigned int MaxDumpVerbosity
Largest verbosity level supported by Dump().
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
TrackTrajectory(const Trajectory &traj, Flags_t &&flags)
Constructor: copies positions and momenta from an existing Trajectory, adds the flags.
const Momenta_t & Momenta() const
Returns reference to stored vector of momenta.
Definition: Trajectory.h:196
size_t NextValidPoint(size_t index) const
Returns the index of the next valid point in the trajectory.
double Phi() const
Azimuthal angle at a first valid point, with respect to z.
double AzimuthAngle(size_t p) const
&quot;Azimuth&quot; angle of trajectory, with respect to the sky.
bool AtLeastValidTrajectoryPoints(unsigned int left) const
Returns whether there are at least min valid points in the trajectory.
double Theta(size_t p=0) const
Trajectory angle at point, with respect to positive z direction.
Definition: Trajectory.h:320
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
double VertexMomentum() const
T MomentumVectorAtPoint(unsigned int p) const
Momentum vector at point p. Use e.g. as:
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].
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space. See recob::tracking::Coord_t for more detai...
Definition: TrackingTypes.h:26
std::pair< Point_t, Point_t > Extent() const
Returns a copy of the first and last valid point in the trajectory.
double Theta() const
Trajectory angle at start, with respect to positive z direction.
Set of flags pertaining a point of the track.
bnb BNB Stream
T End() const
End position. Use e.g. as:
void LowLevelDump(Stream &&out, std::string indent, std::string indentFirst) const
Prints low-level trajectory content into a stream.
std::ostream & operator<<(std::ostream &o, Cluster const &c)
Definition: Cluster.cxx:173