Trajectory.cxx
Go to the documentation of this file.
1 /**
2  * @file Trajectory.cxx
3  * @brief Data product for reconstructed trajectory in space
4  * @date December 9, 2016
5  * @see Trajectory.h
6  *
7  */
8 
9 
12 
13 // LArSoft libraries
15 
16 // C/C++ standard libraries
17 #include <ostream>
18 #include <utility> // std::move()
19 #include <stdexcept> // std::runtime_error
20 
21 
22 //------------------------------------------------------------------------------
24  (Positions_t&& positions, Momenta_t&& momenta, bool hasMomenta)
25  : fPositions(std::move(positions))
26  , fMomenta(std::move(momenta))
27  , fHasMomentum(hasMomenta)
28 {
29  // invariant check
30  if (fPositions.size() != fMomenta.size()) {
31  throw std::runtime_error("recob::Trajectory constructed with "
32  + std::to_string(fPositions.size()) + " positions and "
33  + std::to_string(fMomenta.size())
34  + " momenta! it requires the same number for both."
35  );
36  }
37  if (fPositions.size() < 2) {
38  throw std::runtime_error("recob::Trajectory constructed with "
39  + std::to_string(fPositions.size())
40  + " trajectory points! it requires at least 2."
41  );
42  }
43 } // recob::Trajectory::Trajectory()
44 
45 
46 //------------------------------------------------------------------------------
47 /**
48  * @brief Returns the approximate length of the trajectory.
49  * @param startAt (_default: 0, from beginning_) point to start from
50  * @return the approximate length of the trajectory [cm]
51  *
52  * The residual length from the trajectory point startAt to the end of the
53  * trajectory is computed and returned. By default, the whole trajectory
54  * length is returned.
55  * If a non-existing point is specified, 0 is returned.
56  *
57  * The length approximation is just the sum of Euclidean distances between
58  * all consecutive trajectory points (starting from the one with index
59  * `startAt`).
60  *
61  * This operation is slow, and the result should be stored in a variable.
62  */
63 double recob::Trajectory::Length(size_t startAt /* = 0 */) const {
64 
65  // sanity check
66  if (startAt >= LastPoint()) return 0.;
67 
68  // just sum the distance between all locations in the trajectory
69  Point_t const* curr = &(LocationAtPoint(startAt));
70  Point_t const* next = curr;
71  Point_t const* last = &(End());
72  Coord_t length = 0.0;
73  while (next++ != last) {
74  length += (*next - *curr).R();
75  curr = next;
76  } // while
77  return length;
78 } // recob::Trajectory::Length()
79 
80 
81 //------------------------------------------------------------------------------
82 double recob::Trajectory::ZenithAngle(size_t p /* = 0 */) const {
83 
84  // The zenith angle is defined by the angle between the track starting
85  // direction and the y axis.
86  // The y component of the starting direction is in fact the cosine of that
87  // angle (and std::acos() conveniently returns a value in [0;pi]).
88  // Our convention has the zenith angle the supplemental of the standard one.
89 
90  return util::pi<Coord_t>() - std::acos(DirectionAtPoint(p).Y());
91 
92 } // recob::Trajectory::ZenithAngle()
93 
94 
95 //------------------------------------------------------------------------------
96 double recob::Trajectory::AzimuthAngle(size_t p /* = 0 */) const {
97  //
98  // std::atan2(y, x) returns the angle of a point (x,y) respect to x axis.
99  // In our case, the definition of the angle (0 for z axis, pi/2 for x axis)
100  // translates atan2's y into our x, and x into z.
101  //
102  decltype(auto) startDir = DirectionAtPoint(p);
103  return std::atan2(startDir.X(), startDir.Z());
104 } // recob::Trajectory::AzimuthAngle()
105 
106 
107 //------------------------------------------------------------------------------
108 /**
109  * @brief Computes and returns the direction of the trajectory at a point
110  * @param i index of the point in the trajectory
111  * @return the direction at that point
112  *
113  * The direction is computed as unit vector parallel to the momentum at that
114  * trajectory point.
115  * If the index is not contained in the trajectory, the result is undefined.
116  */
118 {
119 
120  auto const& mom = MomentumVectorAtPoint(i);
121  return HasMomentum()? (mom / mom.R()): mom;
122 
123 } // recob::Trajectory::DirectionAtPoint()
124 
125 
126 //------------------------------------------------------------------------------
128  (size_t p) const
129 {
131 } // recob::Trajectory::GlobalToLocalRotationAtPoint()
132 
133 
134 //------------------------------------------------------------------------------
136  (size_t p) const
137 {
139 } // recob::Trajectory::GlobalToLocalRotationAtPoint()
140 
141 
142 //------------------------------------------------------------------------------
143 std::ostream& recob::operator <<
144  (std::ostream& out, recob::Trajectory const& traj)
145  { traj.Dump(out); return out; }
146 
147 
148 //------------------------------------------------------------------------------
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:70
Point_t const & End() const
Returns the position of the last point of the trajectory [cm].
Definition: Trajectory.h:226
double AzimuthAngle(size_t p=0) const
"Azimuth" angle of trajectory, with respect to the sky.
Definition: Trajectory.cxx:96
double ZenithAngle(size_t p=0) const
"Zenith" angle of trajectory, with respect to the vertical axis.
Definition: Trajectory.cxx:82
double Length(size_t startAt=0) const
Returns the approximate length of the trajectory.
Definition: Trajectory.cxx:63
Rotation_t LocalToGlobalRotationAtPoint(size_t p) const
Returns a rotation matrix bringing relative directions to global.
Definition: Trajectory.cxx:136
Vector_t DirectionAtPoint(size_t i) const
Computes and returns the direction of the trajectory at a point.
Definition: Trajectory.cxx:117
Rotation_t GlobalToLocalRotationAtPoint(size_t p) const
Returns a rotation matrix that brings trajectory direction along z.
Definition: Trajectory.cxx:128
tracking::Vector_t Vector_t
Type for representation of momenta in 3D space.
Definition: Trajectory.h:76
size_t LastPoint() const
Returns the index of the last point in the trajectory.
Definition: Trajectory.h:175
def move(depos, offset)
Definition: depos.py:107
p
Definition: test.py:223
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
Definition: Trajectory.h:236
tracking::Positions_t Positions_t
Type of trajectory point list.
Definition: Trajectory.h:79
tracking::Momenta_t Momenta_t
Type of momentum list.
Definition: Trajectory.h:82
Vector_t const & MomentumVectorAtPoint(size_t i) const
Returns the momentum vector at a point.
Definition: Trajectory.h:457
A trajectory in space reconstructed from hits.
Definition: Trajectory.h:67
bool HasMomentum() const
Returns whether information about the momentum is available.
Definition: Trajectory.h:425
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
Definition: Trajectory.h:73
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.
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
tracking::Rotation_t Rotation_t
Type for representation of space rotations.
Definition: Trajectory.h:97