LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
Trajectory.cxx
Go to the documentation of this file.
1 
12 
13 // LArSoft libraries
15 
16 // C/C++ standard libraries
17 #include <ostream>
18 #include <utility> // std::move()
19 #include <string> // std::to_string()
20 #include <stdexcept> // std::runtime_error
21 
22 
23 //------------------------------------------------------------------------------
25  (Positions_t&& positions, Momenta_t&& momenta, bool hasMomenta)
26  : fPositions(std::move(positions))
27  , fMomenta(std::move(momenta))
28  , fHasMomentum(hasMomenta)
29 {
30  // invariant check
31  if (fPositions.size() != fMomenta.size()) {
32  throw std::runtime_error("recob::Trajectory constructed with "
33  + std::to_string(fPositions.size()) + " positions and "
34  + std::to_string(fMomenta.size())
35  + " momenta! it requires the same number for both."
36  );
37  }
38  if (fPositions.size() < 2) {
39  throw std::runtime_error("recob::Trajectory constructed with "
40  + std::to_string(fPositions.size())
41  + " trajectory points! it requires at least 2."
42  );
43  }
44 } // recob::Trajectory::Trajectory()
45 
46 
47 //------------------------------------------------------------------------------
64 double recob::Trajectory::Length(size_t startAt /* = 0 */) const {
65 
66  // sanity check
67  if (startAt >= LastPoint()) return 0.;
68 
69  // just sum the distance between all locations in the trajectory
70  Point_t const* curr = &(LocationAtPoint(startAt));
71  Point_t const* next = curr;
72  Point_t const* last = &(End());
73  Coord_t length = 0.0;
74  while (next++ != last) {
75  length += (*next - *curr).R();
76  curr = next;
77  } // while
78  return length;
79 } // recob::Trajectory::Length()
80 
81 
82 //------------------------------------------------------------------------------
83 double recob::Trajectory::ZenithAngle(size_t p /* = 0 */) const {
84 
85  // The zenith angle is defined by the angle between the track starting
86  // direction and the y axis.
87  // The y component of the starting direction is in fact the cosine of that
88  // angle (and std::acos() conveniently returns a value in [0;pi]).
89  // Our convention has the zenith angle the supplemental of the standard one.
90 
91  return util::pi<Coord_t>() - std::acos(DirectionAtPoint(p).Y());
92 
93 } // recob::Trajectory::ZenithAngle()
94 
95 
96 //------------------------------------------------------------------------------
97 double recob::Trajectory::AzimuthAngle(size_t p /* = 0 */) const {
98  //
99  // std::atan2(y, x) returns the angle of a point (x,y) respect to x axis.
100  // In our case, the definition of the angle (0 for z axis, pi/2 for x axis)
101  // translates atan2's y into our x, and x into z.
102  //
103  decltype(auto) startDir = DirectionAtPoint(p);
104  return std::atan2(startDir.X(), startDir.Z());
105 } // recob::Trajectory::AzimuthAngle()
106 
107 
108 //------------------------------------------------------------------------------
119 {
120 
121  auto const& mom = MomentumVectorAtPoint(i);
122  return HasMomentum()? (mom / mom.R()): mom;
123 
124 } // recob::Trajectory::DirectionAtPoint()
125 
126 
127 //------------------------------------------------------------------------------
129  (size_t p) const
130 {
132 } // recob::Trajectory::GlobalToLocalRotationAtPoint()
133 
134 
135 //------------------------------------------------------------------------------
137  (size_t p) const
138 {
140 } // recob::Trajectory::GlobalToLocalRotationAtPoint()
141 
142 
143 //------------------------------------------------------------------------------
144 std::ostream& recob::operator <<
145  (std::ostream& out, recob::Trajectory const& traj)
146  { traj.Dump(out); return out; }
147 
148 
149 //------------------------------------------------------------------------------
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: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
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
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
size_t LastPoint() const
Returns the index of the last point in the trajectory.
Definition: Trajectory.h:181
Double_t R
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
Definition: Trajectory.h:242
tracking::Positions_t Positions_t
Type of trajectory point list.
Definition: Trajectory.h:85
tracking::Momenta_t Momenta_t
Type of momentum list.
Definition: Trajectory.h:88
Vector_t const & MomentumVectorAtPoint(size_t i) const
Returns the momentum vector at a point.
Definition: Trajectory.h:463
A trajectory in space reconstructed from hits.
Definition: Trajectory.h:73
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
Definition: BitMask.h:187
bool HasMomentum() const
Returns whether information about the momentum is available.
Definition: Trajectory.h:431
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
Definition: Trajectory.h:79
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:103