LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 
18 #include "TMatrixDfwd.h" // forward declarations for legacy interface
19 
21 
22 // C/C++ standard libraries
23 #include <vector>
24 #include <utility> // std::pair<>
25 #include <iosfwd> // std::ostream
26 
27 
28 // ROOT forward declarations (for legacy interface)
29 class TVector3;
30 
31 namespace recob {
32 
33 
73  class Trajectory {
74  public:
77 
80 
83 
86 
89 
91  enum Ends_t {
94  kEnd,
96  }; // enum Ends_t
97 
98 
101 
104 
105 
107  Trajectory() = default;
108 
109 
129  Trajectory(
130  Positions_t&& positions,
131  Momenta_t&& momenta,
132  bool hasMomenta
133  );
134 
143  Positions_t const& positions,
144  Momenta_t const& momenta,
145  bool hasMomenta
146  )
147  : Trajectory(Positions_t(positions), Momenta_t(momenta), hasMomenta)
148  {}
149 
152 
153 
162  size_t NumberTrajectoryPoints() const
163  { return NPoints(); }
164 
173  size_t NPoints() const
174  { return fPositions.size(); }
175 
177  size_t FirstPoint() const
178  { return 0U; }
179 
181  size_t LastPoint() const
182  { return NPoints() - 1; }
183 
189  bool HasPoint(size_t i) const
190  { return i < NPoints(); }
191 
196  const Positions_t& Positions() const { return fPositions; }
197 
202  const Momenta_t& Momenta() const { return fMomenta; }
203 
220  { return { LocationAtPoint(i), MomentumVectorAtPoint(i) }; }
221 
222 
224  Point_t const& Vertex() const
225  { return Start(); }
226 
228  Point_t const& Start() const
229  { return LocationAtPoint(FirstPoint()); }
230 
232  Point_t const& End() const
233  { return LocationAtPoint(LastPoint()); }
234 
242  Point_t const& LocationAtPoint (size_t i) const
243  { return fPositions[i]; }
244 
245 
254  template<typename T> std::pair<T,T> Extent() const { return { Vertex<T>(),End<T>() }; }
255 
272  std::pair<Point_t, Point_t> Extent() const
273  { return { Start(), End() }; }
274 
275 
292  double Length (size_t startAt = 0) const;
293 
295 
296 
299 
302  { return StartDirection(); }
303 
306  { return DirectionAtPoint(FirstPoint()); }
307 
310  { return DirectionAtPoint(LastPoint()); }
311 
312 
326  double Theta(size_t p = 0) const
327  { return MomentumVectorAtPoint(p).Theta(); }
328 
343  double Phi(size_t p = 0) const
344  { return MomentumVectorAtPoint(p).Phi(); }
345 
346 
364  double ZenithAngle(size_t p = 0) const;
365 
382  double AzimuthAngle(size_t p = 0) const;
383 
384 
387  { return StartMomentumVector(); }
388 
391  { return MomentumVectorAtPoint(FirstPoint()); }
392 
395  { return MomentumVectorAtPoint(LastPoint()); }
396 
397 
399  double VertexMomentum() const
400  { return StartMomentum(); }
401 
403  double StartMomentum() const
404  { return StartMomentumVector().R(); }
405 
407  double EndMomentum() const
408  { return EndMomentumVector().R(); }
409 
410 
420  Vector_t DirectionAtPoint(size_t i) const;
421 
422 
431  bool HasMomentum() const
432  { return fHasMomentum; }
433 
434 
448  double MomentumAtPoint(size_t i) const
449  { return MomentumVectorAtPoint(i).R(); }
450 
463  Vector_t const& MomentumVectorAtPoint(size_t i) const
464  { return fMomenta[i]; }
465 
478  template<typename T> std::pair<T,T> Direction() const { return { VertexDirection<T>(),EndDirection<T>() }; }
479 
480 
498  std::pair<Vector_t, Vector_t> Direction() const
499  { return { StartDirection(), EndDirection() }; }
500 
501 
502 
527 
544 
547 
549  template<typename T> inline T Start() const { auto& loc = Start(); return T(loc.X(),loc.Y(),loc.Z()); }
550 
552  template<typename T> inline T Vertex() const { auto& loc = Vertex(); return T(loc.X(),loc.Y(),loc.Z()); }
553 
555  template<typename T> inline T End() const { auto& loc = End(); return T(loc.X(),loc.Y(),loc.Z()); }
556 
558  template<typename T> inline T LocationAtPoint(unsigned int p) const { auto& loc = LocationAtPoint(p); return T(loc.X(),loc.Y(),loc.Z()); }
559 
561  template<typename T> inline T StartDirection() const { auto dir = StartDirection(); return T(dir.X(),dir.Y(),dir.Z()); }
562 
564  template<typename T> inline T VertexDirection() const { auto dir = VertexDirection(); return T(dir.X(),dir.Y(),dir.Z()); }
565 
567  template<typename T> inline T EndDirection() const { auto dir = EndDirection(); return T(dir.X(),dir.Y(),dir.Z()); }
568 
570  template<typename T> inline T DirectionAtPoint(unsigned int p) const { auto dir = DirectionAtPoint(p); return T(dir.X(),dir.Y(),dir.Z()); }
571 
573  template<typename T> inline T StartMomentumVector() const { auto mom = StartMomentumVector(); return T(mom.X(),mom.Y(),mom.Z()); }
574 
576  template<typename T> inline T VertexMomentumVector() const { auto mom = VertexMomentumVector(); return T(mom.X(),mom.Y(),mom.Z()); }
577 
579  template<typename T> inline T EndMomentumVector() const { auto mom = EndMomentumVector(); return T(mom.X(),mom.Y(),mom.Z()); }
580 
582  template<typename T> inline T MomentumVectorAtPoint(unsigned int p) const { auto mom = MomentumVectorAtPoint(p); return T(mom.X(),mom.Y(),mom.Z()); }
583 
585  template<typename T> inline T GlobalToLocalRotationAtPoint(unsigned int p) const {
586  T rot(3,3);
587  GlobalToLocalRotationAtPoint(p).GetRotationMatrix(rot);
588  return rot;
589  }
590 
592  template<typename T> inline T LocalToGlobalRotationAtPoint(unsigned int p) const {
593  T rot(3,3);
594  LocalToGlobalRotationAtPoint(p).GetRotationMatrix(rot);
595  return rot;
596  }
598 
632  template <typename Stream>
633  void Dump(
634  Stream&& out,
635  unsigned int verbosity,
636  std::string indent, std::string indentFirst
637  ) const;
638 
649  template <typename Stream>
650  void Dump
651  (Stream&& out, unsigned int verbosity = 1, std::string indent = {})
652  const
653  { Dump(std::forward<Stream>(out), verbosity, indent, indent); }
654 
662  template <typename Stream>
663  void LowLevelDump
664  (Stream&& out, std::string indent, std::string indentFirst) const;
665 
666 
668  static constexpr unsigned int MaxDumpVerbosity = 6;
669 
670 
671  protected:
672 
673  private:
674 
677 
678  bool fHasMomentum = true;
679 
680 
681  }; // class Trajectory
682 
683 
693  std::ostream& operator << (std::ostream& out, Trajectory const& traj);
694 
695 
696  //----------------------------------------------------------------------------
697  namespace details {
698  namespace legacy {
699  // These implementation details are shared with other classes
700  // until the legacy support is gone.
701 
703  template <typename Vect>
704  void FillVector(Vect const& source, std::vector<double>& dest);
705 
707  template <typename Vect>
708  void FillVector(Vect const& source, double* dest);
709 
711  template <typename SrcVect, typename DestVect>
712  void FillTwoVectors(
713  SrcVect const& firstSource, SrcVect const& secondSource,
714  DestVect&& firstDest, DestVect&& secondDest
715  );
716 
717 
718  } // namespace legacy
719  } // namespace details
720 
721 
722 } // namespace recob
723 
724 
725 //------------------------------------------------------------------------------
726 //--- Inline implementation
727 //---
728 
729 //------------------------------------------------------------------------------
730 //--- Template implementation
731 //---
732 #include "Trajectory.tcc"
733 
734 //------------------------------------------------------------------------------
735 
736 
737 #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:142
Point_t const & Vertex() const
Returns the position of the first point of the trajectory [cm].
Definition: Trajectory.h:224
double Phi(size_t p=0) const
Azimuthal angle at a point on the trajectory, with respect to z.
Definition: Trajectory.h:343
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:407
bool HasPoint(size_t i) const
Returns whether the specified trajectory point is available.
Definition: Trajectory.h:189
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:498
Reconstruction base classes.
Vector_t EndDirection() const
Returns the direction of the trajectory at the last point.
Definition: Trajectory.h:309
T End() const
End position. Use e.g. as:
Definition: Trajectory.h:555
Ends_t
Mnemonics for the access to begin and end of trajectory.
Definition: Trajectory.h:91
Vector_t const & StartMomentumVector() const
Returns the momentum of the trajectory at the first point [GeV/c].
Definition: Trajectory.h:390
tracking::Coord_t Coord_t
Type used for coordinates and values in general.
Definition: Trajectory.h:76
Point_t const & End() const
Returns the position of the last point of the trajectory [cm].
Definition: Trajectory.h:232
double AzimuthAngle(size_t p=0) const
"Azimuth" angle of trajectory, with respect to the sky.
Definition: Trajectory.cxx:97
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:83
double Length(size_t startAt=0) const
Returns the approximate length of the trajectory.
Definition: Trajectory.cxx:64
Rotation_t LocalToGlobalRotationAtPoint(size_t p) const
Returns a rotation matrix bringing relative directions to global.
Definition: Trajectory.cxx:137
std::pair< Point_t, Point_t > Extent() const
Returns a copy of the first and last point in the trajectory.
Definition: Trajectory.h:272
double VertexMomentum() const
Computes and returns the modulus of momentum at the first point [GeV/c].
Definition: Trajectory.h:399
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:403
Momenta_t fMomenta
Momentum of each of the points in trajectory.
Definition: Trajectory.h:676
Vector_t DirectionAtPoint(size_t i) const
Computes and returns the direction of the trajectory at a point.
Definition: Trajectory.cxx:118
Rotation_t GlobalToLocalRotationAtPoint(size_t p) const
Returns a rotation matrix that brings trajectory direction along z.
Definition: Trajectory.cxx:129
tracking::Vector_t Vector_t
Type for representation of momenta in 3D space.
Definition: Trajectory.h:82
T Start() const
Start position. Use e.g. as:
Definition: Trajectory.h:549
Positions_t fPositions
List of points the trajectory goes through.
Definition: Trajectory.h:675
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:94
size_t LastPoint() const
Returns the index of the last point in the trajectory.
Definition: Trajectory.h:181
std::pair< T, T > Extent() const
Fills the first and last point in the trajectory.
Definition: Trajectory.h:254
const Positions_t & Positions() const
Returns reference to stored vector of positions.
Definition: Trajectory.h:196
TrajectoryPoint_t TrajectoryPoint(size_t i) const
Returns position and momentum at the specified trajectory point.
Definition: Trajectory.h:219
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:173
Index representing the start of the trajectory.
Definition: Trajectory.h:92
T DirectionAtPoint(unsigned int p) const
Direction at point p. Use e.g. as:
Definition: Trajectory.h:570
T EndMomentumVector() const
Momentum vector at end point. Use e.g. as:
Definition: Trajectory.h:579
Index representing the start of the trajectory.
Definition: Trajectory.h:93
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:582
double MomentumAtPoint(size_t i) const
Computes and returns the modulus of the momentum at a point.
Definition: Trajectory.h:448
bool fHasMomentum
Whether we have momentum modulus information.
Definition: Trajectory.h:678
std::pair< T, T > Direction() const
Fills the starting and ending direction of the trajectory.
Definition: Trajectory.h:478
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
Definition: Trajectory.h:242
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:301
T Vertex() const
Start position. Use e.g. as:
Definition: Trajectory.h:552
tracking::Positions_t Positions_t
Type of trajectory point list.
Definition: Trajectory.h:85
static constexpr unsigned int MaxDumpVerbosity
Largest verbosity level supported by Dump().
Definition: Trajectory.h:668
size_t FirstPoint() const
Returns the index of the first point in the trajectory (yep, it&#39;s 0).
Definition: Trajectory.h:177
T StartDirection() const
Start direction. Use e.g. as:
Definition: Trajectory.h:561
size_t NumberTrajectoryPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:162
tracking::Momenta_t Momenta_t
Type of momentum list.
Definition: Trajectory.h:88
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:463
T GlobalToLocalRotationAtPoint(unsigned int p) const
Returns a rotation matrix that brings trajectory direction along z. Use e.g. as:
Definition: Trajectory.h:585
Vector_t StartDirection() const
Returns the direction of the trajectory at the first point.
Definition: Trajectory.h:305
A trajectory in space reconstructed from hits.
Definition: Trajectory.h:73
T LocationAtPoint(unsigned int p) const
Position at point p. Use e.g. as:
Definition: Trajectory.h:558
T StartMomentumVector() const
Momentum vector at start point. Use e.g. as:
Definition: Trajectory.h:573
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:431
TDirectory * dir
Definition: macro.C:5
T VertexDirection() const
Start direction. Use e.g. as:
Definition: Trajectory.h:564
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
Definition: Trajectory.h:79
const Momenta_t & Momenta() const
Returns reference to stored vector of momenta.
Definition: Trajectory.h:202
Vector_t const & VertexMomentumVector() const
Returns the momentum of the trajectory at the first point [GeV/c].
Definition: Trajectory.h:386
double Theta(size_t p=0) const
Trajectory angle at point, with respect to positive z direction.
Definition: Trajectory.h:326
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:228
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:592
T VertexMomentumVector() const
Momentum vector at start point. Use e.g. as:
Definition: Trajectory.h:576
tracking::Rotation_t Rotation_t
Type for representation of space rotations.
Definition: Trajectory.h:103
T EndDirection() const
End direction. Use e.g. as:
Definition: Trajectory.h:567
std::ostream & operator<<(std::ostream &o, Cluster const &c)
Definition: Cluster.cxx:173
Number of ends.
Definition: Trajectory.h:95
Vector_t const & EndMomentumVector() const
Returns the momentum of the trajectory at the last point [GeV/c].
Definition: Trajectory.h:394
void FillTwoVectors(SrcVect const &firstSource, SrcVect const &secondSource, DestVect &&firstDest, DestVect &&secondDest)
Converts two vectors into another type of vector using FillVector.