All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Trajectory.h
Go to the documentation of this file.
1 /**
2  * @file Trajectory.h
3  * @brief Data product for reconstructed trajectory in space
4  * @date December 9, 2016
5  * @version 2.3 (20170118)
6  *
7  * Changes
8  * --------
9  *
10  * 20170118 [v2.3]
11  * renamed recob::Track into recob::Trajectory
12  *
13  */
14 
15 #ifndef LARDATAOBJ_RECOBASE_TRAJECTORY_H
16 #define LARDATAOBJ_RECOBASE_TRAJECTORY_H
17 
19 
20 // C/C++ standard libraries
21 #include <vector>
22 #include <utility> // std::pair<>
23 #include <iosfwd> // std::ostream
24 
25 namespace recob {
26 
27 
28  /** **************************************************************************
29  * @brief A trajectory in space reconstructed from hits.
30  * @see recob::Track,
31  * recob::trackutil::makeTrajectory()
32  *
33  * The trajectory class contains a trajectory in 6D space representing the
34  * path
35  * walked by a particle. A trajectory point is made of a 3D position component
36  * (measured in centimeters) and a momentum component (measured in GeV/c);
37  * for a discussion on the object type for coordinates see: recob::tracking::Coord_t.
38  *
39  * The object contains information about the trajectory, and no
40  * uncertainty, as that is considered a fit result (see `recob::Track`).
41  * By convention the first point is considered "start" (or "vertex") and the
42  * last point "end", although this assignment can be arbitrary and should not
43  * be relied upon for physics decisions.
44  *
45  * The momentum content is in part optional: the trajectory creating algorithm
46  * may decide not to provide information about the modulus of the momentum.
47  * In that case, `Trajectory::HasMomentum()` will return false and every
48  * attempt to access the momentum vector will yield only the trajectory
49  * direction.
50  *
51  *
52  * Invariants
53  * -----------
54  *
55  * * there must be at least two trajectory points;
56  * * there must be one momentum per position;
57  * recob::trackutil::makeTrajectory() can make up a simple momentum vector
58  * from the trajectory, for algorithms reconstructing the trajectory which
59  * do not estimate momenta; `Trajectory::HasMomentum()` reports whether
60  * momentum modulus information is available;
61  * * a list of hits associated with the trajectory is considered a mandatory
62  * part of the trajectory information; see
63  * `recob::TrajectoryCollectionMaker`.
64  *
65  *
66  */
67  class Trajectory {
68  public:
69  /// Type used for coordinates and values in general.
71 
72  /// Type for representation of position in physical 3D space.
74 
75  /// Type for representation of momenta in 3D space.
77 
78  /// Type of trajectory point list.
80 
81  /// Type of momentum list.
83 
84  /// Mnemonics for the access to begin and end of trajectory.
85  enum Ends_t {
86  kStart, ///< Index representing the start of the trajectory.
87  kVertex = kStart, ///< Index representing the start of the trajectory.
88  kEnd, ///< Index representing the end of the trajectory.
89  NEnds ///< Number of ends.
90  }; // enum Ends_t
91 
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  Trajectory() = 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 hasMomenta whether the information on momentum modulus is provided
109  * @throws std::runtime_error if the invariants are violated
110  * @see recob::trackutil::makeTrajectory()
111  *
112  * The most convenient way to create a recob::Trajectory is to use
113  * `recob::trackutil::makeTrajectory()`.
114  *
115  *
116  * Requirements
117  * -------------
118  *
119  * - one momentum is required for each trajectory point
120  * - at least two points must be provided
121  *
122  */
123  Trajectory(
124  Positions_t&& positions,
125  Momenta_t&& momenta,
126  bool hasMomenta
127  );
128 
129  /**
130  * @brief Constructor: copies positions and momenta.
131  * @param positions trajectory as a sorted list of points
132  * @param momenta momentum along the trajectory, one per point
133  * @param hasMomenta whether the information on momentum modulus is provided
134  * @throw std::runtime_error if the invariants are violated
135  */
137  Positions_t const& positions,
138  Momenta_t const& momenta,
139  bool hasMomenta
140  )
141  : Trajectory(Positions_t(positions), Momenta_t(momenta), hasMomenta)
142  {}
143 
144  /// @{
145  /// @name Access to trajectory information
146 
147 
148  /**
149  * @brief Returns the number of stored trajectory points.
150  * @return the number of stored trajectory points
151  * @see PositionAtPoint(), MomentumVectorAtPoint(),
152  * DirectionAtPoint()
153  *
154  * For each point, both position and momentum are available.
155  */
156  size_t NumberTrajectoryPoints() const
157  { return NPoints(); }
158 
159  /**
160  * @brief Returns the number of stored trajectory points.
161  * @return the number of stored trajectory points
162  * @see PositionAtPoint(), MomentumVectorAtPoint(),
163  * DirectionAtPoint()
164  *
165  * For each point, both position and momentum are available.
166  */
167  size_t NPoints() const
168  { return fPositions.size(); }
169 
170  /// Returns the index of the first point in the trajectory (yep, it's `0`).
171  size_t FirstPoint() const
172  { return 0U; }
173 
174  /// Returns the index of the last point in the trajectory.
175  size_t LastPoint() const
176  { return NPoints() - 1; }
177 
178  /**
179  * @brief Returns whether the specified trajectory point is available.
180  * @param i index of the trajectory point
181  * @return whether the specified trajectory point is available.
182  */
183  bool HasPoint(size_t i) const
184  { return i < NPoints(); }
185 
186  /**
187  * @brief Returns reference to stored vector of positions
188  * @return reference to stored vector of positions
189  */
190  const Positions_t& Positions() const { return fPositions; }
191 
192  /**
193  * @brief Returns reference to stored vector of momenta
194  * @return reference to stored vector of momenta
195  */
196  const Momenta_t& Momenta() const { return fMomenta; }
197 
198  /**
199  * @brief Returns position and momentum at the specified trajectory point.
200  * @param i index of the trajectory point
201  * @return the information at the specified trajectory point
202  *
203  * Note that this method returns the momentum, not the direction.
204  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
205  * auto trajPoint = traj.TrajectoryPoint(0);
206  * std::cout << "Start of trajectory at " << trajPoint.position
207  * << " cm, with momentum " << trajPoint.momentum << " GeV/c"
208  * << std::endl;
209  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
210  *
211  * If the specified index is not valid, result is undefined.
212  */
214  { return { LocationAtPoint(i), MomentumVectorAtPoint(i) }; }
215 
216 
217  /// Returns the position of the first point of the trajectory [cm].
218  Point_t const& Vertex() const
219  { return Start(); }
220 
221  /// Returns the position of the first point of the trajectory [cm].
222  Point_t const& Start() const
223  { return LocationAtPoint(FirstPoint()); }
224 
225  /// Returns the position of the last point of the trajectory [cm].
226  Point_t const& End() const
227  { return LocationAtPoint(LastPoint()); }
228 
229  /**
230  * @brief Returns the position at the specified trajectory point.
231  * @param i index of the point in the trajectory
232  * @return position at the specified trajectory point [cm]
233  *
234  * If the point index is invalid, the result is undefined.
235  */
236  Point_t const& LocationAtPoint (size_t i) const
237  { return fPositions[i]; }
238 
239 
240  /**
241  * @brief Fills the first and last point in the trajectory.
242  * @param start (_output_) position of the beginning of the trajectory
243  * @param end (_output_) position of the end of the trajectory
244  *
245  * The labelling of start and end is consistent within the trajectory but is
246  * not guaranteed to be physically correct.
247  */
248  template<typename T> std::pair<T,T> Extent() const { return { Vertex<T>(),End<T>() }; }
249 
250  /**
251  * @brief Returns a copy of the first and last point in the trajectory.
252  * @return a pair: the first and last point in the trajectory
253  *
254  * The labelling of start and end is consistent within the trajectory but is
255  * not guaranteed to be physically correct.
256  *
257  * Example:
258  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
259  *
260  * recob::Trajectory::Point_t start, end;
261  *
262  * std::tie(start, end) = traj.Extent(); // assign both start and end
263  *
264  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
265  */
266  std::pair<Point_t, Point_t> Extent() const
267  { return { Start(), End() }; }
268 
269 
270  /**
271  * @brief Returns the approximate length of the trajectory.
272  * @param startAt (_default: 0, from beginning_) point to start from
273  * @return the approximate length of the trajectory [cm]
274  *
275  * The residual length from the trajectory point startAt to the end of the
276  * trajectory is computed and returned. By default, the whole trajectory
277  * length is returned.
278  * If a non-existing point is specified, 0 is returned.
279  *
280  * The length approximation is just the sum of Euclidean distances between
281  * all consecutive trajectory points (starting from the one with index
282  * `startAt`).
283  *
284  * This operation is slow, and the result should be stored in a variable.
285  */
286  double Length (size_t startAt = 0) const;
287 
288  /// @}
289 
290 
291  /// @{
292  /// @name Access to direction and momentum information
293 
294  /// Returns the direction of the trajectory at the first point.
296  { return StartDirection(); }
297 
298  /// Returns the direction of the trajectory at the first point.
300  { return DirectionAtPoint(FirstPoint()); }
301 
302  /// Returns the direction of the trajectory at the last point.
304  { return DirectionAtPoint(LastPoint()); }
305 
306 
307  /**
308  * @brief Trajectory angle at point, with respect to positive _z_ direction.
309  * @param p the index point to extract the angle from (default: start)
310  * @return angle with respect to positive _z_, in @f$ [0,\pi] @f$ [radians]
311  *
312  * The reference direction is the positive _z_ axis. Although this usually
313  * matches the beam direction, this is not guaranteed and if the explicit
314  * angle from beam direction is needed, the scalar product of the beam
315  * direction and the direction from `StartDirection()` should be used
316  * instead.
317  *
318  * If the point number is invalid, the behaviour is undefined.
319  */
320  double Theta(size_t p = 0) const
321  { return MomentumVectorAtPoint(p).Theta(); }
322 
323  /**
324  * @brief Azimuthal angle at a point on the trajectory, with respect to _z_.
325  * @param p the point index to extract the angle from (default: start)
326  * @return the azimuthal angle, in @f$ [-\pi,\pi[ @f$ [radians]
327  * @see Theta(), ZenithAngle()
328  *
329  * The angle is measured on the plane orthogonal to the _z_ axis, in the
330  * same reference where `Theta()` is measured. The angle is measured
331  * counterclockwise from the _x_ axis. Skyward direction is expected to be
332  * @f$ +\pi/2 @f$ radians in this system, provided that the standard
333  * reference frame with the _y_ axis pointing skyward is chosen.
334  *
335  * If the point number is invalid, the behaviour is undefined.
336  */
337  double Phi(size_t p = 0) const
338  { return MomentumVectorAtPoint(p).Phi(); }
339 
340 
341  /**
342  * @brief "Zenith" angle of trajectory, with respect to the vertical axis.
343  * @param p the point index to extract the angle from (default: start)
344  * @return opposite of the actual zenith angle, in @f$ [0,\pi] @f$ [radians]
345  * @see AzimuthAngle()
346  *
347  * The angle is defined with respect to the negative _y_ direction.
348  * It describes the angle at the specified point on the trajectory.
349  * Therefore, a trajectory starting along the positive _y_ direction returns
350  * @f$ \pi @f$ radians, while a trajectory going downward along the negative
351  * _y_ direction returns 0.
352  *
353  * This is designed so that vertical cosmic rays produce trajectories with
354  * angle 0 radians.
355  *
356  * If the point number is invalid, the behaviour is undefined.
357  */
358  double ZenithAngle(size_t p = 0) const;
359 
360  /**
361  * @brief "Azimuth" angle of trajectory, with respect to the sky.
362  * @param p the point index to extract the angle from (default: start)
363  * @return the azimuth angle, in @f$ [-\pi,\pi[ @f$ [radians]
364  * @see ZenithAngle()
365  *
366  * The angle is defined on the plane orthogonal to the _y_ direction.
367  * It describes the angle of the trajectory at the specified point.
368  * The angle is measured starting from the positive _z_ direction,
369  * counterclockwise. Therefore, a trajectory start lying on the demiplane of
370  * _y_ axis and positive _z_ axis returns 0 radians, while one lying on
371  * the demiplane of _y_ axis and positive _x_ axis returns @f$ +\pi/2 @f$
372  * radians.
373  *
374  * If the point number is invalid, the behaviour is undefined.
375  */
376  double AzimuthAngle(size_t p = 0) const;
377 
378 
379  /// Returns the momentum of the trajectory at the first point [GeV/c].
381  { return StartMomentumVector(); }
382 
383  /// Returns the momentum of the trajectory at the first point [GeV/c].
385  { return MomentumVectorAtPoint(FirstPoint()); }
386 
387  /// Returns the momentum of the trajectory at the last point [GeV/c].
389  { return MomentumVectorAtPoint(LastPoint()); }
390 
391 
392  /// Computes and returns the modulus of momentum at the first point [GeV/c].
393  double VertexMomentum() const
394  { return StartMomentum(); }
395 
396  /// Computes and returns the modulus of momentum at the first point [GeV/c].
397  double StartMomentum() const
398  { return StartMomentumVector().R(); }
399 
400  /// Computes and returns the modulus of momentum at the last point [GeV/c].
401  double EndMomentum() const
402  { return EndMomentumVector().R(); }
403 
404 
405  /**
406  * @brief Computes and returns the direction of the trajectory at a point.
407  * @param i index of the point in the trajectory
408  * @return the direction at that point
409  *
410  * The direction is computed as unit vector parallel to the momentum at that
411  * trajectory point.
412  * If the index is not contained in the trajectory, the result is undefined.
413  */
414  Vector_t DirectionAtPoint(size_t i) const;
415 
416 
417  /**
418  * @brief Returns whether information about the momentum is available.
419  * @return whether information about the momentum is available
420  *
421  * The trajectory may or may not store valid momentum information. If not,
422  * the methods returning momentum information will stick to a modulus
423  * 1 GeV/c and the momentum numerically matches the direction.
424  */
425  bool HasMomentum() const
426  { return fHasMomentum; }
427 
428 
429  /**
430  * @brief Computes and returns the modulus of the momentum at a point.
431  * @param i index of the point in the trajectory
432  * @return modulus of the momentum at that point [GeV/c]
433  * @see HasMomentum()
434  *
435  * The modulus of the momentum at the specified trajectory point is computed
436  * and returned.
437  * If the trajectory does not have momentum information, the value 1 GeV/c
438  * is always returned. This can be tested trajectory by trajectory by
439  * HasMomentum().
440  * If the index is not valid in the trajectory, the result is undefined.
441  */
442  double MomentumAtPoint(size_t i) const
443  { return MomentumVectorAtPoint(i).R(); }
444 
445  /**
446  * @brief Returns the momentum vector at a point.
447  * @param i index of the point in the trajectory
448  * @return the momentum at that point [GeV/c]
449  * @see HasMomentum(), MomentumAtPoint(), DirectionAtPoint()
450  *
451  * The momentum at the specified trajectory point is returned.
452  * If the trajectory does not have momentum information, the returned value
453  * will represent the direction, that is a momentum with modulus 1 GeV/c.
454  * This can be tested trajectory by trajectory by HasMomentum().
455  * If the index is not valid in the trajectory, the result is undefined.
456  */
457  Vector_t const& MomentumVectorAtPoint(size_t i) const
458  { return fMomenta[i]; }
459 
460  /**
461  * @brief Fills the starting and ending direction of the trajectory.
462  * @param start (_output_) direction at the beginning of the trajectory
463  * @param end (_output_) direction at the end of the trajectory
464  *
465  * The two arguments are expected to point each one to an area with room for
466  * at least three `double` numbers.
467  * The two filled vectors have norm 1.
468  *
469  * The labelling of start and end is consistent within the trajectory but is
470  * not guaranteed to be physically correct.
471  */
472  template<typename T> std::pair<T,T> Direction() const { return { VertexDirection<T>(),EndDirection<T>() }; }
473 
474 
475  /**
476  * @brief Returns the trajectory directions at first and last point.
477  * @return a pair with the first and last direction
478  *
479  * The two returned vectors have norm 1.
480  * The labelling of start and end is consistent within the trajectory but is
481  * not guaranteed to be physically correct.
482  *
483  * Example:
484  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
485  *
486  * recob::Trajectory::Vector_t startDir, endDir;
487  *
488  * std::tie(startDir, endDir) = traj.Direction(); // assign start and end
489  *
490  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
491  */
492  std::pair<Vector_t, Vector_t> Direction() const
493  { return { StartDirection(), EndDirection() }; }
494 
495 
496 
497  /**
498  * @brief Returns a rotation matrix that brings trajectory direction along
499  * _z_.
500  * @param p index of the trajectory point where to apply the rotation
501  * @return a rotation matrix suitable to point the trajectory along _z_
502  *
503  * The returned rotation matrix, applied to the direction vector of the
504  * trajectory at point `p`, will make that direction point toward the
505  * positive _z_ axis direction, in a sort of "first person view" of the
506  * trajectory at that point.
507  * If `p` does not denote a valid trajectory point, the result is undefined.
508  *
509  * The return value can be used on a `Vector_t` to rotate it. For example:
510  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
511  * auto rot = traj.GlobalToLocalRotationAtPoint(0);
512  * auto local = rot * traj.DirectionAtPoint(0);
513  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
514  * local will be a `Vector_t` object (like the direction at the right side
515  * of the product) that points to (0, 0, 1).
516  *
517  * While the transformation that yields the rotation matrix is continuous,
518  * the direction of the new "local" _x_ and _y_ axes is not defined.
519  */
521 
522  /**
523  * @brief Returns a rotation matrix bringing relative directions to global.
524  * @param p index of the trajectory point where to apply the rotation
525  * @return a rotation matrix suitable to convert directions to global
526  *
527  * The returned rotation matrix, applied to the unit vector (0, 0, 1) (local
528  * _z_ axis direction), will turn it into the trajectory direction at point
529  * `p`.
530  * If `p` does not denote a valid trajectory point, the result is undefined.
531  *
532  * While the transformation that yields the rotation matrix is continuous,
533  * the conversion of the directions orthogonal to the local _z_ is not
534  * defined.
535  */
537  /// @}
538 
539  /// @{
540  /// @name Templated version of homonymous functions to access to position, direction, and momentum information.
541 
542  /// Start position. Use e.g. as: @code{.cpp} TVector3 start = traj.Start<TVector3>(); @endcode.
543  template<typename T> inline T Start() const { auto& loc = Start(); return T(loc.X(),loc.Y(),loc.Z()); }
544 
545  /// Start position. Use e.g. as: @code{.cpp} TVector3 vertex = traj.Vertex<TVector3>(); @endcode.
546  template<typename T> inline T Vertex() const { auto& loc = Vertex(); return T(loc.X(),loc.Y(),loc.Z()); }
547 
548  /// End position. Use e.g. as: @code{.cpp} TVector3 end = traj.End<TVector3>(); @endcode.
549  template<typename T> inline T End() const { auto& loc = End(); return T(loc.X(),loc.Y(),loc.Z()); }
550 
551  /// Position at point p. Use e.g. as: @code{.cpp} TVector3 pos = traj.LocationAtPoint<TVector3>(p); @endcode.
552  template<typename T> inline T LocationAtPoint(unsigned int p) const { auto& loc = LocationAtPoint(p); return T(loc.X(),loc.Y(),loc.Z()); }
553 
554  /// Start direction. Use e.g. as: @code{.cpp} TVector3 startdir = traj.StartDirection<TVector3>(); @endcode.
555  template<typename T> inline T StartDirection() const { auto dir = StartDirection(); return T(dir.X(),dir.Y(),dir.Z()); }
556 
557  /// Start direction. Use e.g. as: @code{.cpp} TVector3 vertexdir = traj.VertexDirection<TVector3>(); @endcode.
558  template<typename T> inline T VertexDirection() const { auto dir = VertexDirection(); return T(dir.X(),dir.Y(),dir.Z()); }
559 
560  /// End direction. Use e.g. as: @code{.cpp} TVector3 enddir = traj.EndDirection<TVector3>(); @endcode.
561  template<typename T> inline T EndDirection() const { auto dir = EndDirection(); return T(dir.X(),dir.Y(),dir.Z()); }
562 
563  /// Direction at point p. Use e.g. as: @code{.cpp} TVector3 dir = traj.DirectionAtPoint<TVector3>(p); @endcode.
564  template<typename T> inline T DirectionAtPoint(unsigned int p) const { auto dir = DirectionAtPoint(p); return T(dir.X(),dir.Y(),dir.Z()); }
565 
566  /// Momentum vector at start point. Use e.g. as: @code{.cpp} TVector3 startmom = traj.StartMomentumVector<TVector3>(); @endcode.
567  template<typename T> inline T StartMomentumVector() const { auto mom = StartMomentumVector(); return T(mom.X(),mom.Y(),mom.Z()); }
568 
569  /// Momentum vector at start point. Use e.g. as: @code{.cpp} TVector3 vertexmom = traj.VertexMomentumVector<TVector3>(); @endcode.
570  template<typename T> inline T VertexMomentumVector() const { auto mom = VertexMomentumVector(); return T(mom.X(),mom.Y(),mom.Z()); }
571 
572  /// Momentum vector at end point. Use e.g. as: @code{.cpp} TVector3 endmom = traj.EndMomentumVector<TVector3>(); @endcode.
573  template<typename T> inline T EndMomentumVector() const { auto mom = EndMomentumVector(); return T(mom.X(),mom.Y(),mom.Z()); }
574 
575  /// Momentum vector at point p. Use e.g. as: @code{.cpp} TVector3 mom = traj.MomentumVectorAtPoint<TVector3>(p); @endcode.
576  template<typename T> inline T MomentumVectorAtPoint(unsigned int p) const { auto mom = MomentumVectorAtPoint(p); return T(mom.X(),mom.Y(),mom.Z()); }
577 
578  /// Returns a rotation matrix that brings trajectory direction along _z_. Use e.g. as: @code{.cpp} TMatrixD rot = traj.GlobalToLocalRotationAtPoint<TMatrixD>(p); @endcode.
579  template<typename T> inline T GlobalToLocalRotationAtPoint(unsigned int p) const {
580  T rot(3,3);
581  GlobalToLocalRotationAtPoint(p).GetRotationMatrix(rot);
582  return rot;
583  }
584 
585  /// Returns a rotation matrix bringing relative directions to global. Use e.g. as: @code{.cpp} TMatrixD rot = traj.LocalToGlobalRotationAtPoint<TMatrixD>(p); @endcode.
586  template<typename T> inline T LocalToGlobalRotationAtPoint(unsigned int p) const {
587  T rot(3,3);
588  LocalToGlobalRotationAtPoint(p).GetRotationMatrix(rot);
589  return rot;
590  }
591  /// @}
592 
593  /**
594  * @brief Prints trajectory content into a stream.
595  * @tparam Stream type of the output stream
596  * @param out stream to output the information into
597  * @param verbosity verbosity level (default: `1`)
598  * @param indent indentation string (default: none)
599  * @param indentFirst indentation for first output line (default: as indent)
600  *
601  * The amount of information dumped to screen is regulated by the
602  * Indentation string is prepended to each line, and the first line has its
603  * own special indentation string (`indentFirst`).
604  *
605  * The output can be multi-line, it ends with no end-of-line and it does not
606  * inserts an end-of-line at its beginning (unless that is explicitly inside
607  * `indentFirst`).
608  * The lowest verbosity is guaranteed to be on a single line.
609  *
610  *
611  * Information printed out (`verbosity` argument)
612  * -----------------------------------------------
613  *
614  * * level `0`: start position, direction, momentum modulus and number of
615  * points
616  * * level `1`: also end position, direction and momentum modulus
617  * * level `2`: also trajectory length
618  * * level `3`: also angles at start
619  * * level `4`: also 9 intermediate trajectory points
620  * * level `5`: also 10 more intermediate trajectory points (19 total)
621  * * level `6`: all trajectory points
622  *
623  * @internal Default values are implemented in a different method.
624  *
625  */
626  template <typename Stream>
627  void Dump(
628  Stream&& out,
629  unsigned int verbosity,
630  std::string indent, std::string indentFirst
631  ) const;
632 
633  /**
634  * @brief Prints trajectory content into a stream.
635  * @tparam Stream type of the output stream
636  * @param out stream to output the information into
637  * @param verbosity verbosity level (default: `1`)
638  * @param indent indentation string (default: none)
639  * @see Dump(Stream&&, unsigned int, std::string, std::string)
640  *
641  * Implementation detail for Dump(Stream&&, unsigned int, std::string).
642  */
643  template <typename Stream>
644  void Dump
645  (Stream&& out, unsigned int verbosity = 1, std::string indent = {})
646  const
647  { Dump(std::forward<Stream>(out), verbosity, indent, indent); }
648 
649  /**
650  * @brief Prints low-level trajectory content into a stream.
651  * @tparam Stream type of the output stream
652  * @param out stream to output the information into
653  * @param indent indentation string (default: none)
654  * @param indentFirst indentation for first output line (default: as indent)
655  */
656  template <typename Stream>
657  void LowLevelDump
658  (Stream&& out, std::string indent, std::string indentFirst) const;
659 
660 
661  /// Largest verbosity level supported by Dump().
662  static constexpr unsigned int MaxDumpVerbosity = 6;
663 
664 
665  protected:
666 
667  private:
668 
669  Positions_t fPositions; ///< List of points the trajectory goes through.
670  Momenta_t fMomenta; ///< Momentum of each of the points in trajectory.
671 
672  bool fHasMomentum = true; ///< Whether we have momentum modulus information.
673 
674 
675  }; // class Trajectory
676 
677 
678  /**
679  * @brief Prints trajectory content into a stream.
680  * @tparam Stream type of the output stream
681  * @param out stream to output the information into
682  * @param traj trajectory to be printed
683  * @return a reference to stream
684  *
685  * See `recob::Trajectory::Dump()` for details.
686  */
687  std::ostream& operator << (std::ostream& out, Trajectory const& traj);
688 
689 
690  //----------------------------------------------------------------------------
691  namespace details {
692  namespace legacy {
693  // These implementation details are shared with other classes
694  // until the legacy support is gone.
695 
696  /// Converts a vector into STL vector
697  template <typename Vect>
698  void FillVector(Vect const& source, std::vector<double>& dest);
699 
700  /// Converts a vector into a C array
701  template <typename Vect>
702  void FillVector(Vect const& source, double* dest);
703 
704  /// Converts two vectors into another type of vector using FillVector
705  template <typename SrcVect, typename DestVect>
706  void FillTwoVectors(
707  SrcVect const& firstSource, SrcVect const& secondSource,
708  DestVect&& firstDest, DestVect&& secondDest
709  );
710 
711 
712  } // namespace legacy
713  } // namespace details
714 
715 
716 } // namespace recob
717 
718 
719 //------------------------------------------------------------------------------
720 //--- Inline implementation
721 //---
722 
723 //------------------------------------------------------------------------------
724 //--- Template implementation
725 //---
726 #include "Trajectory.tcc"
727 
728 //------------------------------------------------------------------------------
729 
730 
731 #endif // LARDATAOBJ_RECOBASE_TRAJECTORY_H
Double32_t Coord_t
Definition: TrackingTypes.h:23
Trajectory(Positions_t const &positions, Momenta_t const &momenta, bool hasMomenta)
Constructor: copies positions and momenta.
Definition: Trajectory.h:136
Point_t const & Vertex() const
Returns the position of the first point of the trajectory [cm].
Definition: Trajectory.h:218
double Phi(size_t p=0) const
Azimuthal angle at a point on the trajectory, with respect to z.
Definition: Trajectory.h:337
Trajectory()=default
Default constructor; do not use it! it&#39;s needed by ROOT I/O.
double EndMomentum() const
Computes and returns the modulus of momentum at the last point [GeV/c].
Definition: Trajectory.h:401
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
std::pair< Vector_t, Vector_t > Direction() const
Returns the trajectory directions at first and last point.
Definition: Trajectory.h:492
Vector_t EndDirection() const
Returns the direction of the trajectory at the last point.
Definition: Trajectory.h:303
T End() const
End position. Use e.g. as:
Definition: Trajectory.h:549
do source
Ends_t
Mnemonics for the access to begin and end of trajectory.
Definition: Trajectory.h:85
Vector_t const & StartMomentumVector() const
Returns the momentum of the trajectory at the first point [GeV/c].
Definition: Trajectory.h:384
tracking::Coord_t Coord_t
Type used for coordinates and values in general.
Definition: Trajectory.h:70
pdgs p
Definition: selectors.fcl:22
Point_t const & End() const
Returns the position of the last point of the trajectory [cm].
Definition: Trajectory.h:226
double AzimuthAngle(size_t p=0) const
&quot;Azimuth&quot; angle of trajectory, with respect to the sky.
Definition: Trajectory.cxx:96
void LowLevelDump(Stream &&out, std::string indent, std::string indentFirst) const
Prints low-level trajectory content into a stream.
double ZenithAngle(size_t p=0) const
&quot;Zenith&quot; angle of trajectory, with respect to the vertical axis.
Definition: Trajectory.cxx:82
double Length(size_t startAt=0) const
Returns the approximate length of the trajectory.
Definition: Trajectory.cxx:63
Rotation_t LocalToGlobalRotationAtPoint(size_t p) const
Returns a rotation matrix bringing relative directions to global.
Definition: Trajectory.cxx:136
std::pair< Point_t, Point_t > Extent() const
Returns a copy of the first and last point in the trajectory.
Definition: Trajectory.h:266
double VertexMomentum() const
Computes and returns the modulus of momentum at the first point [GeV/c].
Definition: Trajectory.h:393
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
double StartMomentum() const
Computes and returns the modulus of momentum at the first point [GeV/c].
Definition: Trajectory.h:397
Momenta_t fMomenta
Momentum of each of the points in trajectory.
Definition: Trajectory.h:670
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
tracking::Vector_t Vector_t
Type for representation of momenta in 3D space.
Definition: Trajectory.h:76
T Start() const
Start position. Use e.g. as:
Definition: Trajectory.h:543
Positions_t fPositions
List of points the trajectory goes through.
Definition: Trajectory.h:669
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
Index representing the end of the trajectory.
Definition: Trajectory.h:88
size_t LastPoint() const
Returns the index of the last point in the trajectory.
Definition: Trajectory.h:175
std::pair< T, T > Extent() const
Fills the first and last point in the trajectory.
Definition: Trajectory.h:248
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
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:167
Index representing the start of the trajectory.
Definition: Trajectory.h:86
T DirectionAtPoint(unsigned int p) const
Direction at point p. Use e.g. as:
Definition: Trajectory.h:564
T EndMomentumVector() const
Momentum vector at end point. Use e.g. as:
Definition: Trajectory.h:573
Index representing the start of the trajectory.
Definition: Trajectory.h:87
T MomentumVectorAtPoint(unsigned int p) const
Momentum vector at point p. Use e.g. as:
Definition: Trajectory.h:576
double MomentumAtPoint(size_t i) const
Computes and returns the modulus of the momentum at a point.
Definition: Trajectory.h:442
void FillVector(Vect const &source, std::vector< double > &dest)
Converts a vector into STL vector.
bool fHasMomentum
Whether we have momentum modulus information.
Definition: Trajectory.h:672
std::pair< T, T > Direction() const
Fills the starting and ending direction of the trajectory.
Definition: Trajectory.h:472
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
Definition: Trajectory.h:236
std::vector< Vector_t > Momenta_t
Type of momentum list.
Definition: TrackingTypes.h:35
Vector_t VertexDirection() const
Returns the direction of the trajectory at the first point.
Definition: Trajectory.h:295
T Vertex() const
Start position. Use e.g. as:
Definition: Trajectory.h:546
tracking::Positions_t Positions_t
Type of trajectory point list.
Definition: Trajectory.h:79
static constexpr unsigned int MaxDumpVerbosity
Largest verbosity level supported by Dump().
Definition: Trajectory.h:662
size_t FirstPoint() const
Returns the index of the first point in the trajectory (yep, it&#39;s 0).
Definition: Trajectory.h:171
T StartDirection() const
Start direction. Use e.g. as:
Definition: Trajectory.h:555
size_t NumberTrajectoryPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:156
tracking::Momenta_t Momenta_t
Type of momentum list.
Definition: Trajectory.h:82
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
T GlobalToLocalRotationAtPoint(unsigned int p) const
Returns a rotation matrix that brings trajectory direction along z. Use e.g. as:
Definition: Trajectory.h:579
Vector_t StartDirection() const
Returns the direction of the trajectory at the first point.
Definition: Trajectory.h:299
A trajectory in space reconstructed from hits.
Definition: Trajectory.h:67
T LocationAtPoint(unsigned int p) const
Position at point p. Use e.g. as:
Definition: Trajectory.h:552
T StartMomentumVector() const
Momentum vector at start point. Use e.g. as:
Definition: Trajectory.h:567
std::vector< Point_t > Positions_t
Type of trajectory point list.
Definition: TrackingTypes.h:32
bool HasMomentum() const
Returns whether information about the momentum is available.
Definition: Trajectory.h:425
T VertexDirection() const
Start direction. Use e.g. as:
Definition: Trajectory.h:558
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
Definition: Trajectory.h:73
const Momenta_t & Momenta() const
Returns reference to stored vector of momenta.
Definition: Trajectory.h:196
Vector_t const & VertexMomentumVector() const
Returns the momentum of the trajectory at the first point [GeV/c].
Definition: Trajectory.h:380
double Theta(size_t p=0) const
Trajectory angle at point, with respect to positive z direction.
Definition: Trajectory.h:320
void Dump(Stream &&out, unsigned int verbosity, std::string indent, std::string indentFirst) const
Prints trajectory content into a stream.
Point_t const & Start() const
Returns the position of the first point of the trajectory [cm].
Definition: Trajectory.h:222
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
T LocalToGlobalRotationAtPoint(unsigned int p) const
Returns a rotation matrix bringing relative directions to global. Use e.g. as:
Definition: Trajectory.h:586
recob::tracking::Vector_t Vector_t
T VertexMomentumVector() const
Momentum vector at start point. Use e.g. as:
Definition: Trajectory.h:570
tracking::Rotation_t Rotation_t
Type for representation of space rotations.
Definition: Trajectory.h:97
bnb BNB Stream
T EndDirection() const
End direction. Use e.g. as:
Definition: Trajectory.h:561
std::ostream & operator<<(std::ostream &o, Cluster const &c)
Definition: Cluster.cxx:173
Number of ends.
Definition: Trajectory.h:89
Vector_t const & EndMomentumVector() const
Returns the momentum of the trajectory at the last point [GeV/c].
Definition: Trajectory.h:388
void FillTwoVectors(SrcVect const &firstSource, SrcVect const &secondSource, DestVect &&firstDest, DestVect &&secondDest)
Converts two vectors into another type of vector using FillVector.