LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Trajectory.cxx
Go to the documentation of this file.
1 
11 
12 // LArSoft libraries
14 
15 // C/C++ standard libraries
16 #include <ostream>
17 #include <stdexcept> // std::runtime_error
18 #include <utility> // std::move()
19 
20 //------------------------------------------------------------------------------
21 recob::Trajectory::Trajectory(Positions_t&& positions, Momenta_t&& momenta, bool hasMomenta)
22  : fPositions(std::move(positions)), fMomenta(std::move(momenta)), fHasMomentum(hasMomenta)
23 {
24  // invariant check
25  if (fPositions.size() != fMomenta.size()) {
26  throw std::runtime_error("recob::Trajectory constructed with " +
27  std::to_string(fPositions.size()) + " positions and " +
28  std::to_string(fMomenta.size()) +
29  " momenta! it requires the same number for both.");
30  }
31  if (fPositions.size() < 2) {
32  throw std::runtime_error("recob::Trajectory constructed with " +
33  std::to_string(fPositions.size()) +
34  " trajectory points! it requires at least 2.");
35  }
36 } // recob::Trajectory::Trajectory()
37 
38 //------------------------------------------------------------------------------
55 double recob::Trajectory::Length(size_t startAt /* = 0 */) const
56 {
57 
58  // sanity check
59  if (startAt >= LastPoint()) return 0.;
60 
61  // just sum the distance between all locations in the trajectory
62  Point_t const* curr = &(LocationAtPoint(startAt));
63  Point_t const* next = curr;
64  Point_t const* last = &(End());
65  Coord_t length = 0.0;
66  while (next++ != last) {
67  length += (*next - *curr).R();
68  curr = next;
69  } // while
70  return length;
71 } // recob::Trajectory::Length()
72 
73 //------------------------------------------------------------------------------
74 double recob::Trajectory::ZenithAngle(size_t p /* = 0 */) const
75 {
76 
77  // The zenith angle is defined by the angle between the track starting
78  // direction and the y axis.
79  // The y component of the starting direction is in fact the cosine of that
80  // angle (and std::acos() conveniently returns a value in [0;pi]).
81  // Our convention has the zenith angle the supplemental of the standard one.
82 
83  return util::pi<Coord_t>() - std::acos(DirectionAtPoint(p).Y());
84 
85 } // recob::Trajectory::ZenithAngle()
86 
87 //------------------------------------------------------------------------------
88 double recob::Trajectory::AzimuthAngle(size_t p /* = 0 */) const
89 {
90  //
91  // std::atan2(y, x) returns the angle of a point (x,y) respect to x axis.
92  // In our case, the definition of the angle (0 for z axis, pi/2 for x axis)
93  // translates atan2's y into our x, and x into z.
94  //
95  decltype(auto) startDir = DirectionAtPoint(p);
96  return std::atan2(startDir.X(), startDir.Z());
97 } // recob::Trajectory::AzimuthAngle()
98 
99 //------------------------------------------------------------------------------
110 {
111 
112  auto const& mom = MomentumVectorAtPoint(i);
113  return HasMomentum() ? (mom / mom.R()) : mom;
114 
115 } // recob::Trajectory::DirectionAtPoint()
116 
117 //------------------------------------------------------------------------------
119 {
121 } // recob::Trajectory::GlobalToLocalRotationAtPoint()
122 
123 //------------------------------------------------------------------------------
125 {
127 } // recob::Trajectory::GlobalToLocalRotationAtPoint()
128 
129 //------------------------------------------------------------------------------
130 std::ostream& recob::operator<<(std::ostream& out, recob::Trajectory const& traj)
131 {
132  traj.Dump(out);
133  return out;
134 }
135 
136 //------------------------------------------------------------------------------
Trajectory()=default
Default constructor; do not use it! it&#39;s needed by ROOT I/O.
Data product for reconstructed trajectory in space.
Rotation_t Global3DToLocal3DRotation() const
Calculate rotation matrices from global (x,y,z) to local (u,v,w) coordinates.
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
STL namespace.
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
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
Positions_t fPositions
List of points the trajectory goes through.
Definition: Trajectory.h:685
size_t LastPoint() const
Returns the index of the last point in the trajectory.
Definition: Trajectory.h:159
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
Definition: Trajectory.h:216
tracking::Positions_t Positions_t
Type of trajectory point list.
Definition: Trajectory.h:78
tracking::Momenta_t Momenta_t
Type of momentum list.
Definition: Trajectory.h:81
Vector_t const & MomentumVectorAtPoint(size_t i) const
Returns the momentum vector at a point.
Definition: Trajectory.h:416
A trajectory in space reconstructed from hits.
Definition: Trajectory.h:66
bool HasMomentum() const
Returns whether information about the momentum is available.
Definition: Trajectory.h:387
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
Definition: Trajectory.h:72
void Dump(Stream &&out, unsigned int verbosity, std::string indent, std::string indentFirst) const
Prints trajectory content into a stream.
Collection of Physical constants used in LArSoft.
Rotation_t Local3DToGlobal3DRotation() const
Calculate rotation matrices from local (u,v,w) to global (x,y,z) coordinates.
tracking::Rotation_t Rotation_t
Type for representation of space rotations.
Definition: Trajectory.h:95
std::ostream & operator<<(std::ostream &o, Cluster const &c)
Definition: Cluster.cxx:168