LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Trajectory.h
Go to the documentation of this file.
1 
15 #ifndef LARDATAOBJ_RECOBASE_TRAJECTORY_H
16 #define LARDATAOBJ_RECOBASE_TRAJECTORY_H
17 
19 
20 // C/C++ standard libraries
21 #include <iosfwd> // std::ostream
22 #include <utility> // std::pair<>
23 #include <vector>
24 
25 namespace recob {
26 
66  class Trajectory {
67  public:
70 
73 
76 
79 
82 
84  enum Ends_t {
87  kEnd,
89  }; // enum Ends_t
90 
93 
96 
98  Trajectory() = default;
99 
119  Trajectory(Positions_t&& positions, Momenta_t&& momenta, bool hasMomenta);
120 
128  Trajectory(Positions_t const& positions, Momenta_t const& momenta, bool hasMomenta)
129  : Trajectory(Positions_t(positions), Momenta_t(momenta), hasMomenta)
130  {}
131 
134 
143  size_t NumberTrajectoryPoints() const { return NPoints(); }
144 
153  size_t NPoints() const { return fPositions.size(); }
154 
156  size_t FirstPoint() const { return 0U; }
157 
159  size_t LastPoint() const { return NPoints() - 1; }
160 
166  bool HasPoint(size_t i) const { return i < NPoints(); }
167 
172  const Positions_t& Positions() const { return fPositions; }
173 
178  const Momenta_t& Momenta() const { return fMomenta; }
179 
196  {
197  return {LocationAtPoint(i), MomentumVectorAtPoint(i)};
198  }
199 
201  Point_t const& Vertex() const { return Start(); }
202 
204  Point_t const& Start() const { return LocationAtPoint(FirstPoint()); }
205 
207  Point_t const& End() const { return LocationAtPoint(LastPoint()); }
208 
216  Point_t const& LocationAtPoint(size_t i) const { return fPositions[i]; }
217 
226  template <typename T>
227  std::pair<T, T> Extent() const
228  {
229  return {Vertex<T>(), End<T>()};
230  }
231 
248  std::pair<Point_t, Point_t> Extent() const { return {Start(), End()}; }
249 
266  double Length(size_t startAt = 0) const;
267 
269 
272 
275 
278 
281 
295  double Theta(size_t p = 0) const { return MomentumVectorAtPoint(p).Theta(); }
296 
311  double Phi(size_t p = 0) const { return MomentumVectorAtPoint(p).Phi(); }
312 
330  double ZenithAngle(size_t p = 0) const;
331 
348  double AzimuthAngle(size_t p = 0) const;
349 
351  Vector_t const& VertexMomentumVector() const { return StartMomentumVector(); }
352 
355 
358 
360  double VertexMomentum() const { return StartMomentum(); }
361 
363  double StartMomentum() const { return StartMomentumVector().R(); }
364 
366  double EndMomentum() const { return EndMomentumVector().R(); }
367 
377  Vector_t DirectionAtPoint(size_t i) const;
378 
387  bool HasMomentum() const { return fHasMomentum; }
388 
402  double MomentumAtPoint(size_t i) const { return MomentumVectorAtPoint(i).R(); }
403 
416  Vector_t const& MomentumVectorAtPoint(size_t i) const { return fMomenta[i]; }
417 
430  template <typename T>
431  std::pair<T, T> Direction() const
432  {
433  return {VertexDirection<T>(), EndDirection<T>()};
434  }
435 
453  std::pair<Vector_t, Vector_t> Direction() const { return {StartDirection(), EndDirection()}; }
454 
479 
496 
499 
501  template <typename T>
502  inline T Start() const
503  {
504  auto& loc = Start();
505  return T(loc.X(), loc.Y(), loc.Z());
506  }
507 
509  template <typename T>
510  inline T Vertex() const
511  {
512  auto& loc = Vertex();
513  return T(loc.X(), loc.Y(), loc.Z());
514  }
515 
517  template <typename T>
518  inline T End() const
519  {
520  auto& loc = End();
521  return T(loc.X(), loc.Y(), loc.Z());
522  }
523 
525  template <typename T>
526  inline T LocationAtPoint(unsigned int p) const
527  {
528  auto& loc = LocationAtPoint(p);
529  return T(loc.X(), loc.Y(), loc.Z());
530  }
531 
533  template <typename T>
534  inline T StartDirection() const
535  {
536  auto dir = StartDirection();
537  return T(dir.X(), dir.Y(), dir.Z());
538  }
539 
541  template <typename T>
542  inline T VertexDirection() const
543  {
544  auto dir = VertexDirection();
545  return T(dir.X(), dir.Y(), dir.Z());
546  }
547 
549  template <typename T>
550  inline T EndDirection() const
551  {
552  auto dir = EndDirection();
553  return T(dir.X(), dir.Y(), dir.Z());
554  }
555 
557  template <typename T>
558  inline T DirectionAtPoint(unsigned int p) const
559  {
560  auto dir = DirectionAtPoint(p);
561  return T(dir.X(), dir.Y(), dir.Z());
562  }
563 
565  template <typename T>
566  inline T StartMomentumVector() const
567  {
568  auto mom = StartMomentumVector();
569  return T(mom.X(), mom.Y(), mom.Z());
570  }
571 
573  template <typename T>
574  inline T VertexMomentumVector() const
575  {
576  auto mom = VertexMomentumVector();
577  return T(mom.X(), mom.Y(), mom.Z());
578  }
579 
581  template <typename T>
582  inline T EndMomentumVector() const
583  {
584  auto mom = EndMomentumVector();
585  return T(mom.X(), mom.Y(), mom.Z());
586  }
587 
589  template <typename T>
590  inline T MomentumVectorAtPoint(unsigned int p) const
591  {
592  auto mom = MomentumVectorAtPoint(p);
593  return T(mom.X(), mom.Y(), mom.Z());
594  }
595 
597  template <typename T>
598  inline T GlobalToLocalRotationAtPoint(unsigned int p) const
599  {
600  T rot(3, 3);
601  GlobalToLocalRotationAtPoint(p).GetRotationMatrix(rot);
602  return rot;
603  }
604 
606  template <typename T>
607  inline T LocalToGlobalRotationAtPoint(unsigned int p) const
608  {
609  T rot(3, 3);
610  LocalToGlobalRotationAtPoint(p).GetRotationMatrix(rot);
611  return rot;
612  }
614 
648  template <typename Stream>
649  void Dump(Stream&& out,
650  unsigned int verbosity,
651  std::string indent,
652  std::string indentFirst) const;
653 
664  template <typename Stream>
665  void Dump(Stream&& out, unsigned int verbosity = 1, std::string indent = {}) const
666  {
667  Dump(std::forward<Stream>(out), verbosity, indent, indent);
668  }
669 
677  template <typename Stream>
678  void LowLevelDump(Stream&& out, std::string indent, std::string indentFirst) const;
679 
681  static constexpr unsigned int MaxDumpVerbosity = 6;
682 
683  protected:
684  private:
687 
688  bool fHasMomentum = true;
689 
690  }; // class Trajectory
691 
701  std::ostream& operator<<(std::ostream& out, Trajectory const& traj);
702 
703  //----------------------------------------------------------------------------
704  namespace details {
705  namespace legacy {
706  // These implementation details are shared with other classes
707  // until the legacy support is gone.
708 
710  template <typename Vect>
711  void FillVector(Vect const& source, std::vector<double>& dest);
712 
714  template <typename Vect>
715  void FillVector(Vect const& source, double* dest);
716 
718  template <typename SrcVect, typename DestVect>
719  void FillTwoVectors(SrcVect const& firstSource,
720  SrcVect const& secondSource,
721  DestVect&& firstDest,
722  DestVect&& secondDest);
723 
724  } // namespace legacy
725  } // namespace details
726 
727 } // namespace recob
728 
729 //------------------------------------------------------------------------------
730 //--- Inline implementation
731 //---
732 
733 //------------------------------------------------------------------------------
734 //--- Template implementation
735 //---
736 #include "Trajectory.tcc"
737 
738 //------------------------------------------------------------------------------
739 
740 #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:128
Point_t const & Vertex() const
Returns the position of the first point of the trajectory [cm].
Definition: Trajectory.h:201
double Phi(size_t p=0) const
Azimuthal angle at a point on the trajectory, with respect to z.
Definition: Trajectory.h:311
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:366
bool HasPoint(size_t i) const
Returns whether the specified trajectory point is available.
Definition: Trajectory.h:166
A point in the trajectory, with position and momentum.
Definition: TrackingTypes.h:85
std::pair< Vector_t, Vector_t > Direction() const
Returns the trajectory directions at first and last point.
Definition: Trajectory.h:453
Reconstruction base classes.
Vector_t EndDirection() const
Returns the direction of the trajectory at the last point.
Definition: Trajectory.h:280
T End() const
End position. Use e.g. as:
Definition: Trajectory.h:518
Ends_t
Mnemonics for the access to begin and end of trajectory.
Definition: Trajectory.h:84
Vector_t const & StartMomentumVector() const
Returns the momentum of the trajectory at the first point [GeV/c].
Definition: Trajectory.h:354
tracking::Coord_t Coord_t
Type used for coordinates and values in general.
Definition: Trajectory.h:69
Point_t const & End() const
Returns the position of the last point of the trajectory [cm].
Definition: Trajectory.h:207
double AzimuthAngle(size_t p=0) const
"Azimuth" angle of trajectory, with respect to the sky.
Definition: Trajectory.cxx:88
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
"Zenith" angle of trajectory, with respect to the vertical axis.
Definition: Trajectory.cxx:74
double Length(size_t startAt=0) const
Returns the approximate length of the trajectory.
Definition: Trajectory.cxx:55
Rotation_t LocalToGlobalRotationAtPoint(size_t p) const
Returns a rotation matrix bringing relative directions to global.
Definition: Trajectory.cxx:124
std::pair< Point_t, Point_t > Extent() const
Returns a copy of the first and last point in the trajectory.
Definition: Trajectory.h:248
double VertexMomentum() const
Computes and returns the modulus of momentum at the first point [GeV/c].
Definition: Trajectory.h:360
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:363
Momenta_t fMomenta
Momentum of each of the points in trajectory.
Definition: Trajectory.h:686
Vector_t DirectionAtPoint(size_t i) const
Computes and returns the direction of the trajectory at a point.
Definition: Trajectory.cxx:109
Rotation_t GlobalToLocalRotationAtPoint(size_t p) const
Returns a rotation matrix that brings trajectory direction along z.
Definition: Trajectory.cxx:118
tracking::Vector_t Vector_t
Type for representation of momenta in 3D space.
Definition: Trajectory.h:75
T Start() const
Start position. Use e.g. as:
Definition: Trajectory.h:502
Positions_t fPositions
List of points the trajectory goes through.
Definition: Trajectory.h:685
Index representing the end of the trajectory.
Definition: Trajectory.h:87
size_t LastPoint() const
Returns the index of the last point in the trajectory.
Definition: Trajectory.h:159
const Positions_t & Positions() const
Returns reference to stored vector of positions.
Definition: Trajectory.h:172
TrajectoryPoint_t TrajectoryPoint(size_t i) const
Returns position and momentum at the specified trajectory point.
Definition: Trajectory.h:195
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:153
Index representing the start of the trajectory.
Definition: Trajectory.h:85
T DirectionAtPoint(unsigned int p) const
Direction at point p. Use e.g. as:
Definition: Trajectory.h:558
void Dump(Stream &&out, unsigned int verbosity=1, std::string indent={}) const
Prints trajectory content into a stream.
Definition: Trajectory.h:665
T EndMomentumVector() const
Momentum vector at end point. Use e.g. as:
Definition: Trajectory.h:582
std::pair< T, T > Extent() const
Fills the first and last point in the trajectory.
Definition: Trajectory.h:227
Index representing the start of the trajectory.
Definition: Trajectory.h:86
std::string indent(std::size_t const i)
T MomentumVectorAtPoint(unsigned int p) const
Momentum vector at point p. Use e.g. as:
Definition: Trajectory.h:590
double MomentumAtPoint(size_t i) const
Computes and returns the modulus of the momentum at a point.
Definition: Trajectory.h:402
bool fHasMomentum
Whether we have momentum modulus information.
Definition: Trajectory.h:688
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:31
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
Definition: Trajectory.h:216
std::vector< Vector_t > Momenta_t
Type of momentum list.
Definition: TrackingTypes.h:37
std::pair< T, T > Direction() const
Fills the starting and ending direction of the trajectory.
Definition: Trajectory.h:431
Vector_t VertexDirection() const
Returns the direction of the trajectory at the first point.
Definition: Trajectory.h:274
T Vertex() const
Start position. Use e.g. as:
Definition: Trajectory.h:510
tracking::Positions_t Positions_t
Type of trajectory point list.
Definition: Trajectory.h:78
static constexpr unsigned int MaxDumpVerbosity
Largest verbosity level supported by Dump().
Definition: Trajectory.h:681
size_t FirstPoint() const
Returns the index of the first point in the trajectory (yep, it&#39;s 0).
Definition: Trajectory.h:156
T StartDirection() const
Start direction. Use e.g. as:
Definition: Trajectory.h:534
size_t NumberTrajectoryPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:143
tracking::Momenta_t Momenta_t
Type of momentum list.
Definition: Trajectory.h:81
ROOT::Math::Rotation3D Rotation_t
Type for representation of space rotations.
Definition: TrackingTypes.h:40
Vector_t const & MomentumVectorAtPoint(size_t i) const
Returns the momentum vector at a point.
Definition: Trajectory.h:416
T GlobalToLocalRotationAtPoint(unsigned int p) const
Returns a rotation matrix that brings trajectory direction along z. Use e.g. as:
Definition: Trajectory.h:598
Vector_t StartDirection() const
Returns the direction of the trajectory at the first point.
Definition: Trajectory.h:277
A trajectory in space reconstructed from hits.
Definition: Trajectory.h:66
T LocationAtPoint(unsigned int p) const
Position at point p. Use e.g. as:
Definition: Trajectory.h:526
T StartMomentumVector() const
Momentum vector at start point. Use e.g. as:
Definition: Trajectory.h:566
std::vector< Point_t > Positions_t
Type of trajectory point list.
Definition: TrackingTypes.h:34
bool HasMomentum() const
Returns whether information about the momentum is available.
Definition: Trajectory.h:387
TDirectory * dir
Definition: macro.C:5
T VertexDirection() const
Start direction. Use e.g. as:
Definition: Trajectory.h:542
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
Definition: Trajectory.h:72
const Momenta_t & Momenta() const
Returns reference to stored vector of momenta.
Definition: Trajectory.h:178
Vector_t const & VertexMomentumVector() const
Returns the momentum of the trajectory at the first point [GeV/c].
Definition: Trajectory.h:351
double Theta(size_t p=0) const
Trajectory angle at point, with respect to positive z direction.
Definition: Trajectory.h:295
void Dump(Stream &&out, unsigned int verbosity, std::string indent, std::string indentFirst) const
Prints trajectory content into a stream.
void FillVector(Vect const &source, double *dest)
Converts a vector into a C array.
Point_t const & Start() const
Returns the position of the first point of the trajectory [cm].
Definition: Trajectory.h:204
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:27
T LocalToGlobalRotationAtPoint(unsigned int p) const
Returns a rotation matrix bringing relative directions to global. Use e.g. as:
Definition: Trajectory.h:607
T VertexMomentumVector() const
Momentum vector at start point. Use e.g. as:
Definition: Trajectory.h:574
tracking::Rotation_t Rotation_t
Type for representation of space rotations.
Definition: Trajectory.h:95
T EndDirection() const
End direction. Use e.g. as:
Definition: Trajectory.h:550
std::ostream & operator<<(std::ostream &o, Cluster const &c)
Definition: Cluster.cxx:168
Number of ends.
Definition: Trajectory.h:88
Vector_t const & EndMomentumVector() const
Returns the momentum of the trajectory at the last point [GeV/c].
Definition: Trajectory.h:357
void FillTwoVectors(SrcVect const &firstSource, SrcVect const &secondSource, DestVect &&firstDest, DestVect &&secondDest)
Converts two vectors into another type of vector using FillVector.