LArSoft  v06_85_00
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 
72  class Trajectory {
73  public:
76 
79 
82 
85 
88 
90  enum Ends_t {
93  kEnd,
95  }; // enum Ends_t
96 
97 
100 
103 
104 
106  Trajectory() = default;
107 
108 
128  Trajectory(
129  Positions_t&& positions,
130  Momenta_t&& momenta,
131  bool hasMomenta
132  );
133 
142  Positions_t const& positions,
143  Momenta_t const& momenta,
144  bool hasMomenta
145  )
146  : Trajectory(Positions_t(positions), Momenta_t(momenta), hasMomenta)
147  {}
148 
151 
152 
161  size_t NumberTrajectoryPoints() const
162  { return NPoints(); }
163 
172  size_t NPoints() const
173  { return fPositions.size(); }
174 
176  size_t FirstPoint() const
177  { return 0U; }
178 
180  size_t LastPoint() const
181  { return NPoints() - 1; }
182 
188  bool HasPoint(size_t i) const
189  { return i < NPoints(); }
190 
195  const Positions_t& Positions() const { return fPositions; }
196 
201  const Momenta_t& Momenta() const { return fMomenta; }
202 
213  bool TrajectoryAtPoint(size_t i, TVector3& pos, TVector3& dir) const;
214 
215 
232  { return { LocationAtPoint(i), MomentumVectorAtPoint(i) }; }
233 
234 
236  Point_t const& Vertex() const
237  { return Start(); }
238 
240  Point_t const& Start() const
241  { return LocationAtPoint(FirstPoint()); }
242 
244  Point_t const& End() const
245  { return LocationAtPoint(LastPoint()); }
246 
247 
255  Point_t const& LocationAtPoint (size_t i) const
256  { return fPositions[i]; }
257 
258 
269  [[deprecated("Use point interface instead")]]
270  void Extent(std::vector<double>& start, std::vector<double>& end) const;
271 
288  std::pair<Point_t, Point_t> Extent() const
289  { return { Start(), End() }; }
290 
291 
308  double Length (size_t startAt = 0) const;
309 
311 
312 
315 
324  [[deprecated("Use NumberTrajectoryPoints() instead")]]
325  size_t NumberFitMomentum() const
326  { return HasMomentum()? NPoints(): 0U; }
327 
328 
331  { return StartDirection(); }
332 
335  { return DirectionAtPoint(FirstPoint()); }
336 
339  { return DirectionAtPoint(LastPoint()); }
340 
341 
355  double Theta(size_t p = 0) const
356  { return MomentumVectorAtPoint(p).Theta(); }
357 
372  double Phi(size_t p = 0) const
373  { return MomentumVectorAtPoint(p).Phi(); }
374 
375 
393  double ZenithAngle(size_t p = 0) const;
394 
411  double AzimuthAngle(size_t p = 0) const;
412 
413 
416  { return StartMomentumVector(); }
417 
420  { return MomentumVectorAtPoint(FirstPoint()); }
421 
424  { return MomentumVectorAtPoint(LastPoint()); }
425 
426 
428  double VertexMomentum() const
429  { return StartMomentum(); }
430 
432  double StartMomentum() const
433  { return StartMomentumVector().R(); }
434 
436  double EndMomentum() const
437  { return EndMomentumVector().R(); }
438 
439 
449  Vector_t DirectionAtPoint(size_t i) const;
450 
451 
460  bool HasMomentum() const
461  { return fHasMomentum; }
462 
463 
477  double MomentumAtPoint(size_t i) const
478  { return MomentumVectorAtPoint(i).R(); }
479 
492  Vector_t const& MomentumVectorAtPoint(size_t i) const
493  { return fMomenta[i]; }
494 
509  void Direction(double* start, double* end) const;
510 
511 
529  std::pair<Vector_t, Vector_t> Direction() const
530  { return { StartDirection(), EndDirection() }; }
531 
532 
533 
558 
567  void GlobalToLocalRotationAtPoint(unsigned int p, TMatrixD &rot) const;
568 
584 
592  void LocalToGlobalRotationAtPoint(unsigned int p, TMatrixD &rot) const;
593 
595 
596 
630  template <typename Stream>
631  void Dump(
632  Stream&& out,
633  unsigned int verbosity,
634  std::string indent, std::string indentFirst
635  ) const;
636 
647  template <typename Stream>
648  void Dump
649  (Stream&& out, unsigned int verbosity = 1, std::string indent = {})
650  const
651  { Dump(std::forward<Stream>(out), verbosity, indent, indent); }
652 
660  template <typename Stream>
661  void LowLevelDump
662  (Stream&& out, std::string indent, std::string indentFirst) const;
663 
664 
666  static constexpr unsigned int MaxDumpVerbosity = 6;
667 
668 
669  protected:
670 
671  private:
672 
675 
676  bool fHasMomentum = true;
677 
678 
679  }; // class Trajectory
680 
681 
691  std::ostream& operator << (std::ostream& out, Trajectory const& traj);
692 
693 
694  //----------------------------------------------------------------------------
695  namespace details {
696  namespace legacy {
697  // These implementation details are shared with other classes
698  // until the legacy support is gone.
699 
701  template <typename Vect>
702  void FillVector(Vect const& source, std::vector<double>& dest);
703 
705  template <typename Vect>
706  void FillVector(Vect const& source, double* dest);
707 
709  template <typename SrcVect, typename DestVect>
710  void FillTwoVectors(
711  SrcVect const& firstSource, SrcVect const& secondSource,
712  DestVect&& firstDest, DestVect&& secondDest
713  );
714 
715 
716  } // namespace legacy
717  } // namespace details
718 
719 
720 } // namespace recob
721 
722 
723 //------------------------------------------------------------------------------
724 //--- Inline implementation
725 //---
726 
727 //------------------------------------------------------------------------------
728 //--- Template implementation
729 //---
730 #include "Trajectory.tcc"
731 
732 //------------------------------------------------------------------------------
733 
734 
735 #endif // LARDATAOBJ_RECOBASE_TRAJECTORY_H
Trajectory(Positions_t const &positions, Momenta_t const &momenta, bool hasMomenta)
Constructor: copies positions and momenta.
Definition: Trajectory.h:141
Point_t const & Vertex() const
Returns the position of the first point of the trajectory [cm].
Definition: Trajectory.h:236
double Phi(size_t p=0) const
Azimuthal angle at a point on the trajectory, with respect to z.
Definition: Trajectory.h:372
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:436
bool HasPoint(size_t i) const
Returns whether the specified trajectory point is available.
Definition: Trajectory.h:188
A point in the trajectory, with position and momentum.
Definition: TrackingTypes.h:35
std::pair< Vector_t, Vector_t > Direction() const
Returns the trajectory directions at first and last point.
Definition: Trajectory.h:529
Reconstruction base classes.
Vector_t EndDirection() const
Returns the direction of the trajectory at the last point.
Definition: Trajectory.h:338
geo::Point_t Point_t
Type for representation of position in physical 3D space.
Definition: TrackingTypes.h:20
Ends_t
Mnemonics for the access to begin and end of trajectory.
Definition: Trajectory.h:90
Vector_t const & StartMomentumVector() const
Returns the momentum of the trajectory at the first point [GeV/c].
Definition: Trajectory.h:419
tracking::Coord_t Coord_t
Type used for coordinates and values in general.
Definition: Trajectory.h:75
Point_t const & End() const
Returns the position of the last point of the trajectory [cm].
Definition: Trajectory.h:244
bool TrajectoryAtPoint(size_t i, TVector3 &pos, TVector3 &dir) const
Fills position and direction at the specified trajectory point.
Definition: Trajectory.cxx:66
double AzimuthAngle(size_t p=0) const
"Azimuth" angle of trajectory, with respect to the sky.
Definition: Trajectory.cxx:136
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:122
double Length(size_t startAt=0) const
Returns the approximate length of the trajectory.
Definition: Trajectory.cxx:103
Rotation_t LocalToGlobalRotationAtPoint(size_t p) const
Returns a rotation matrix bringing relative directions to global.
Definition: Trajectory.cxx:190
std::pair< Point_t, Point_t > Extent() const
Returns a copy of the first and last point in the trajectory.
Definition: Trajectory.h:288
double VertexMomentum() const
Computes and returns the modulus of momentum at the first point [GeV/c].
Definition: Trajectory.h:428
double StartMomentum() const
Computes and returns the modulus of momentum at the first point [GeV/c].
Definition: Trajectory.h:432
Momenta_t fMomenta
Momentum of each of the points in trajectory.
Definition: Trajectory.h:674
Vector_t DirectionAtPoint(size_t i) const
Computes and returns the direction of the trajectory at a point.
Definition: Trajectory.cxx:157
size_t NumberFitMomentum() const
Returns the number of stored momenta.
Definition: Trajectory.h:325
Rotation_t GlobalToLocalRotationAtPoint(size_t p) const
Returns a rotation matrix that brings trajectory direction along z.
Definition: Trajectory.cxx:173
tracking::Vector_t Vector_t
Type for representation of momenta in 3D space.
Definition: Trajectory.h:81
Positions_t fPositions
List of points the trajectory goes through.
Definition: Trajectory.h:673
Index representing the end of the trajectory.
Definition: Trajectory.h:93
size_t LastPoint() const
Returns the index of the last point in the trajectory.
Definition: Trajectory.h:180
const Positions_t & Positions() const
Returns reference to stored vector of positions.
Definition: Trajectory.h:195
TrajectoryPoint_t TrajectoryPoint(size_t i) const
Returns position and momentum at the specified trajectory point.
Definition: Trajectory.h:231
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:172
Index representing the start of the trajectory.
Definition: Trajectory.h:91
Index representing the start of the trajectory.
Definition: Trajectory.h:92
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:477
bool fHasMomentum
Whether we have momentum modulus information.
Definition: Trajectory.h:676
geo::Vector_t Vector_t
Type for representation of momenta in 3D space.
Definition: TrackingTypes.h:23
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
Definition: Trajectory.h:255
std::vector< Vector_t > Momenta_t
Type of momentum list.
Definition: TrackingTypes.h:29
Vector_t VertexDirection() const
Returns the direction of the trajectory at the first point.
Definition: Trajectory.h:330
tracking::Positions_t Positions_t
Type of trajectory point list.
Definition: Trajectory.h:84
static constexpr unsigned int MaxDumpVerbosity
Largest verbosity level supported by Dump().
Definition: Trajectory.h:666
size_t FirstPoint() const
Returns the index of the first point in the trajectory (yep, it&#39;s 0).
Definition: Trajectory.h:176
double Coord_t
Type used for coordinates and values in general.
Definition: TrackingTypes.h:17
size_t NumberTrajectoryPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:161
tracking::Momenta_t Momenta_t
Type of momentum list.
Definition: Trajectory.h:87
ROOT::Math::Rotation3D Rotation_t
Type for representation of space rotations.
Definition: TrackingTypes.h:32
Vector_t const & MomentumVectorAtPoint(size_t i) const
Returns the momentum vector at a point.
Definition: Trajectory.h:492
Vector_t StartDirection() const
Returns the direction of the trajectory at the first point.
Definition: Trajectory.h:334
A trajectory in space reconstructed from hits.
Definition: Trajectory.h:72
std::vector< Point_t > Positions_t
Type of trajectory point list.
Definition: TrackingTypes.h:26
bool HasMomentum() const
Returns whether information about the momentum is available.
Definition: Trajectory.h:460
TDirectory * dir
Definition: macro.C:5
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
Definition: Trajectory.h:78
const Momenta_t & Momenta() const
Returns reference to stored vector of momenta.
Definition: Trajectory.h:201
Vector_t const & VertexMomentumVector() const
Returns the momentum of the trajectory at the first point [GeV/c].
Definition: Trajectory.h:415
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
double Theta(size_t p=0) const
Trajectory angle at point, with respect to positive z direction.
Definition: Trajectory.h:355
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:240
tracking::Rotation_t Rotation_t
Type for representation of space rotations.
Definition: Trajectory.h:102
std::ostream & operator<<(std::ostream &o, Cluster const &c)
Definition: Cluster.cxx:173
Number of ends.
Definition: Trajectory.h:94
Vector_t const & EndMomentumVector() const
Returns the momentum of the trajectory at the last point [GeV/c].
Definition: Trajectory.h:423
void FillTwoVectors(SrcVect const &firstSource, SrcVect const &secondSource, DestVect &&firstDest, DestVect &&secondDest)
Converts two vectors into another type of vector using FillVector.