LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 <vector>
24 #include <iosfwd> // std::ostream
25 #include <limits> // std::numeric_limits<>
26 
27 
28 namespace recob {
29 
30 
64 
65  public:
68 
71 
74 
77 
80 
83 
86 
88  using Flags_t = std::vector<PointFlags_t>;
89 
92 
95 
98 
99 
101  TrackTrajectory() = default;
102 
103 
126  Positions_t&& positions,
127  Momenta_t&& momenta,
128  Flags_t&& flags,
129  bool hasMomenta
130  );
131 
132 
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 
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 
165  PointFlags_t const& FlagsAtPoint(size_t i) const
166  { return fFlags[i]; }
167 
171  Flags_t const& Flags() const
172  { return fFlags; }
173 
184  bool HasValidPoint(size_t i) const
185  {
186  return Trajectory().HasPoint(i)
188  }
189 
197  size_t FirstValidPoint() const
198  { return NextValidPoint(0U); }
199 
211  size_t NextValidPoint(size_t index) const
212  { return ToValidPoint<+1>(index); }
213 
225  size_t PreviousValidPoint(size_t index) const
226  { return ToValidPoint<-1>(index); }
227 
235  size_t LastValidPoint() const
236  { return PreviousValidPoint(LastPoint()); }
237 
244  unsigned int CountValidPoints() const;
245 
247 
249  Point_t const& Vertex() const
250  { return Start(); }
251 
253  Point_t const& Start() const
254  { return LocationAtPoint(FirstValidPoint()); }
255 
257  Point_t const& End() const
258  { return LocationAtPoint(LastValidPoint()); }
259 
261 
270  template<typename T> std::pair<T,T> Extent( ) const { return { Vertex<T>(), End<T>() }; }
271 
289  std::pair<Point_t, Point_t> Extent() const
290  { return { Start(), End() }; }
291 
292 
310  double Length (size_t startAt = 0) const;
311 
314  { return StartDirection(); }
315 
318  { return DirectionAtPoint(FirstValidPoint()); }
319 
322  { return DirectionAtPoint(LastValidPoint()); }
323 
324 
339  double Theta(size_t p) const
340  { return Trajectory().Theta(p); }
341 
353  double Theta() const
354  { return Theta(FirstValidPoint()); }
355 
371  double Phi(size_t p) const
372  { return Trajectory().Phi(p); }
373 
385  double Phi() const
386  { return Phi(FirstValidPoint()); }
387 
388 
404  double ZenithAngle(size_t p) const
405  { return Trajectory().ZenithAngle(p); }
406 
419  double ZenithAngle() const
420  { return ZenithAngle(FirstValidPoint()); }
421 
437  double AzimuthAngle(size_t p) const
438  { return Trajectory().AzimuthAngle(p); }
439 
453  double AzimuthAngle() const
454  { return AzimuthAngle(FirstValidPoint()); }
455 
456 
459  { return StartMomentumVector(); }
460 
464 
468 
469 
472  double VertexMomentum() const
473  { return StartMomentum(); }
474 
477  double StartMomentum() const
478  { return StartMomentumVector().R(); }
479 
482  double EndMomentum() const
483  { return EndMomentumVector().R(); }
484 
485 
487 
489 
491 
493 
506  template<typename T> std::pair<T,T> Direction() const { return { VertexDirection<T>(), EndDirection<T>() }; }
507 
508 
526  std::pair<Vector_t, Vector_t> Direction() const
527  { return { StartDirection(), EndDirection() }; }
528 
529 
531 
533 
536 
538  template<typename T> inline T Start() const { auto& loc = Start(); return T(loc.X(),loc.Y(),loc.Z()); }
539 
541  template<typename T> inline T Vertex() const { auto& loc = Vertex(); return T(loc.X(),loc.Y(),loc.Z()); }
542 
544  template<typename T> inline T End() const { auto& loc = End(); return T(loc.X(),loc.Y(),loc.Z()); }
545 
547  template<typename T> inline T LocationAtPoint(unsigned int p) const { auto& loc = LocationAtPoint(p); return T(loc.X(),loc.Y(),loc.Z()); }
548 
550  template<typename T> inline T StartDirection() const { auto dir = StartDirection(); return T(dir.X(),dir.Y(),dir.Z()); }
551 
553  template<typename T> inline T VertexDirection() const { auto dir = VertexDirection(); return T(dir.X(),dir.Y(),dir.Z()); }
554 
556  template<typename T> inline T EndDirection() const { auto dir = EndDirection(); return T(dir.X(),dir.Y(),dir.Z()); }
557 
559  template<typename T> inline T DirectionAtPoint(unsigned int p) const { auto dir = DirectionAtPoint(p); return T(dir.X(),dir.Y(),dir.Z()); }
560 
562  template<typename T> inline T StartMomentumVector() const { auto mom = StartMomentumVector(); return T(mom.X(),mom.Y(),mom.Z()); }
563 
565  template<typename T> inline T VertexMomentumVector() const { auto mom = VertexMomentumVector(); return T(mom.X(),mom.Y(),mom.Z()); }
566 
568  template<typename T> inline T EndMomentumVector() const { auto mom = EndMomentumVector(); return T(mom.X(),mom.Y(),mom.Z()); }
569 
571  template<typename T> inline T MomentumVectorAtPoint(unsigned int p) const { auto mom = MomentumVectorAtPoint(p); return T(mom.X(),mom.Y(),mom.Z()); }
572 
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 
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  }
587 
622  template <typename Stream>
623  void Dump(
624  Stream&& out,
625  unsigned int verbosity,
626  std::string indent, std::string indentFirst
627  ) const;
628 
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 
652  template <typename Stream>
653  void LowLevelDump
654  (Stream&& out, std::string indent, std::string indentFirst) const;
655 
656 
658  static constexpr unsigned int MaxDumpVerbosity = 7;
659 
661  static constexpr size_t InvalidIndex = std::numeric_limits<size_t>::max();
662 
663  private:
664 
666 
667 
687  template <int Dir>
688  size_t ToValidPoint(size_t index) const;
689 
691  bool AtLeastValidTrajectoryPoints(unsigned int left) const;
692 
693  }; // class TrackTrajectory
694 
695 
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:343
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:189
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).
Reconstruction base classes.
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:91
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:97
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:83
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:137
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:118
Rotation_t GlobalToLocalRotationAtPoint(size_t p) const
Returns a rotation matrix that brings trajectory direction along z.
Definition: Trajectory.cxx:129
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.
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
Int_t max
Definition: plot.C:27
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:181
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:196
TrajectoryPoint_t TrajectoryPoint(size_t i) const
Returns position and momentum at the specified trajectory point.
Definition: Trajectory.h:219
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:173
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:448
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:242
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
"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:177
size_t NumberTrajectoryPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:162
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:38
Vector_t const & MomentumVectorAtPoint(size_t i) const
Returns the momentum vector at a point.
Definition: Trajectory.h:463
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:73
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:104
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:431
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:202
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:326
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.
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