LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TrackTrajectory.h
Go to the documentation of this file.
1 
15 #ifndef LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_H
16 #define LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_H
17 
18 // ROOT libraries
21 
22 // C/C++ standard libraries
23 #include <iosfwd> // std::ostream
24 #include <limits> // std::numeric_limits<>
25 #include <vector>
26 
27 namespace recob {
28 
62 
63  public:
66 
69 
72 
75 
78 
81 
84 
86  using Flags_t = std::vector<PointFlags_t>;
87 
90 
93 
96 
98  TrackTrajectory() = default;
99 
121  TrackTrajectory(Positions_t&& positions, Momenta_t&& momenta, Flags_t&& flags, bool hasMomenta);
122 
129  TrackTrajectory(const Trajectory& traj, Flags_t&& flags)
131  Momenta_t(traj.Momenta()),
132  std::move(flags),
133  traj.HasMomentum())
134  {}
135 
137  Trajectory_t const& Trajectory() const { return static_cast<Trajectory_t const&>(*this); }
138 
140 
141  using Trajectory_t::NPoints;
142 
144 
146 
148 
156  PointFlags_t const& FlagsAtPoint(size_t i) const { return fFlags[i]; }
157 
161  Flags_t const& Flags() const { return fFlags; }
162 
173  bool HasValidPoint(size_t i) const
174  {
175  return Trajectory().HasPoint(i) && !FlagsAtPoint(i).isSet(flag::NoPoint);
176  }
177 
185  size_t FirstValidPoint() const { return NextValidPoint(0U); }
186 
198  size_t NextValidPoint(size_t index) const { return ToValidPoint<+1>(index); }
199 
211  size_t PreviousValidPoint(size_t index) const { return ToValidPoint<-1>(index); }
212 
220  size_t LastValidPoint() const { return PreviousValidPoint(LastPoint()); }
221 
228  unsigned int CountValidPoints() const;
229 
231 
233  Point_t const& Vertex() const { return Start(); }
234 
236  Point_t const& Start() const { return LocationAtPoint(FirstValidPoint()); }
237 
239  Point_t const& End() const { return LocationAtPoint(LastValidPoint()); }
240 
242 
251  template <typename T>
252  std::pair<T, T> Extent() const
253  {
254  return {Vertex<T>(), End<T>()};
255  }
256 
274  std::pair<Point_t, Point_t> Extent() const { return {Start(), End()}; }
275 
293  double Length(size_t startAt = 0) const;
294 
297 
300 
303 
318  double Theta(size_t p) const { return Trajectory().Theta(p); }
319 
331  double Theta() const { return Theta(FirstValidPoint()); }
332 
348  double Phi(size_t p) const { return Trajectory().Phi(p); }
349 
361  double Phi() const { return Phi(FirstValidPoint()); }
362 
378  double ZenithAngle(size_t p) const { return Trajectory().ZenithAngle(p); }
379 
392  double ZenithAngle() const { return ZenithAngle(FirstValidPoint()); }
393 
409  double AzimuthAngle(size_t p) const { return Trajectory().AzimuthAngle(p); }
410 
424  double AzimuthAngle() const { return AzimuthAngle(FirstValidPoint()); }
425 
427  Vector_t const& VertexMomentumVector() const { return StartMomentumVector(); }
428 
431 
434 
437  double VertexMomentum() const { return StartMomentum(); }
438 
441  double StartMomentum() const { return StartMomentumVector().R(); }
442 
445  double EndMomentum() const { return EndMomentumVector().R(); }
446 
448 
450 
452 
454 
467  template <typename T>
468  std::pair<T, T> Direction() const
469  {
470  return {VertexDirection<T>(), EndDirection<T>()};
471  }
472 
490  std::pair<Vector_t, Vector_t> Direction() const { return {StartDirection(), EndDirection()}; }
491 
493 
495 
498 
500  template <typename T>
501  inline T Start() const
502  {
503  auto& loc = Start();
504  return T(loc.X(), loc.Y(), loc.Z());
505  }
506 
508  template <typename T>
509  inline T Vertex() const
510  {
511  auto& loc = Vertex();
512  return T(loc.X(), loc.Y(), loc.Z());
513  }
514 
516  template <typename T>
517  inline T End() const
518  {
519  auto& loc = End();
520  return T(loc.X(), loc.Y(), loc.Z());
521  }
522 
524  template <typename T>
525  inline T LocationAtPoint(unsigned int p) const
526  {
527  auto& loc = LocationAtPoint(p);
528  return T(loc.X(), loc.Y(), loc.Z());
529  }
530 
532  template <typename T>
533  inline T StartDirection() const
534  {
535  auto dir = StartDirection();
536  return T(dir.X(), dir.Y(), dir.Z());
537  }
538 
540  template <typename T>
541  inline T VertexDirection() const
542  {
543  auto dir = VertexDirection();
544  return T(dir.X(), dir.Y(), dir.Z());
545  }
546 
548  template <typename T>
549  inline T EndDirection() const
550  {
551  auto dir = EndDirection();
552  return T(dir.X(), dir.Y(), dir.Z());
553  }
554 
556  template <typename T>
557  inline T DirectionAtPoint(unsigned int p) const
558  {
559  auto dir = DirectionAtPoint(p);
560  return T(dir.X(), dir.Y(), dir.Z());
561  }
562 
564  template <typename T>
565  inline T StartMomentumVector() const
566  {
567  auto mom = StartMomentumVector();
568  return T(mom.X(), mom.Y(), mom.Z());
569  }
570 
572  template <typename T>
573  inline T VertexMomentumVector() const
574  {
575  auto mom = VertexMomentumVector();
576  return T(mom.X(), mom.Y(), mom.Z());
577  }
578 
580  template <typename T>
581  inline T EndMomentumVector() const
582  {
583  auto mom = EndMomentumVector();
584  return T(mom.X(), mom.Y(), mom.Z());
585  }
586 
588  template <typename T>
589  inline T MomentumVectorAtPoint(unsigned int p) const
590  {
591  auto mom = MomentumVectorAtPoint(p);
592  return T(mom.X(), mom.Y(), mom.Z());
593  }
594 
596  template <typename T>
597  inline T GlobalToLocalRotationAtPoint(unsigned int p) const
598  {
599  T rot(3, 3);
600  GlobalToLocalRotationAtPoint(p).GetRotationMatrix(rot);
601  return rot;
602  }
603 
605  template <typename T>
606  inline T LocalToGlobalRotationAtPoint(unsigned int p) const
607  {
608  T rot(3, 3);
609  LocalToGlobalRotationAtPoint(p).GetRotationMatrix(rot);
610  return rot;
611  }
613 
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 = 7;
682 
684  static constexpr size_t InvalidIndex = std::numeric_limits<size_t>::max();
685 
686  private:
688 
708  template <int Dir>
709  size_t ToValidPoint(size_t index) const;
710 
712  bool AtLeastValidTrajectoryPoints(unsigned int left) const;
713 
714  }; // class TrackTrajectory
715 
725  std::ostream& operator<<(std::ostream&& out, TrackTrajectory const& traj);
726 
727 } // namespace recob
728 
729 //------------------------------------------------------------------------------
730 //--- Inline implementation
731 //---
732 
733 //------------------------------------------------------------------------------
734 //--- Template implementation
735 //---
736 #include "TrackTrajectory.tcc"
737 
738 //------------------------------------------------------------------------------
739 
740 #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:311
Data product for reconstructed trajectory in space.
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:166
A point in the trajectory, with position and momentum.
Definition: TrackingTypes.h:85
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).
Reconstruction base classes.
TrackTrajectory()=default
Default constructor; do not use it! it&#39;s needed by ROOT I/O.
std::pair< T, T > Direction() const
Fills the starting and ending direction of the trajectory.
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:
std::pair< T, T > Extent() const
Fills the first and last valid point in the trajectory.
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:84
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:
tracking::Positions_t Positions_t
Type of trajectory point list.
double ZenithAngle(size_t p) const
"Zenith" 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
"Azimuth" angle of trajectory, with respect to the sky.
Definition: Trajectory.cxx:88
T LocalToGlobalRotationAtPoint(unsigned int p) const
Returns a rotation matrix bringing relative directions to global. Use e.g. as:
STL namespace.
double ZenithAngle(size_t p=0) const
"Zenith" angle of trajectory, with respect to the vertical axis.
Definition: Trajectory.cxx:74
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:124
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
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:109
Rotation_t GlobalToLocalRotationAtPoint(size_t p) const
Returns a rotation matrix that brings trajectory direction along z.
Definition: Trajectory.cxx:118
double AzimuthAngle() const
"Azimuth" 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.
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:159
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:172
TrajectoryPoint_t TrajectoryPoint(size_t i) const
Returns position and momentum at the specified trajectory point.
Definition: Trajectory.h:195
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:153
A trajectory in space reconstructed from hits.
T LocationAtPoint(unsigned int p) const
Position at point p. Use e.g. as:
std::string indent(std::size_t const i)
double MomentumAtPoint(size_t i) const
Computes and returns the modulus of the momentum at a point.
Definition: Trajectory.h:402
bool HasValidPoint(size_t i) const
Returns whether the specified point has NoPoint flag unset.
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
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:216
tracking::Rotation_t Rotation_t
Type for representation of space rotations.
std::vector< Vector_t > Momenta_t
Type of momentum list.
Definition: TrackingTypes.h:37
double ZenithAngle() const
"Zenith" angle of trajectory, with respect to the vertical axis.
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:156
size_t NumberTrajectoryPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:143
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].
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
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:66
double Theta(size_t p) const
Trajectory angle at point, with respect to positive z direction.
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:94
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:34
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:387
TDirectory * dir
Definition: macro.C:5
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:178
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
"Azimuth" 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:295
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:
void Dump(Stream &&out, unsigned int verbosity=1, std::string indent={}) const
Prints trajectory content into a stream.
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:27
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.
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:168