LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Trajectory.tcc
Go to the documentation of this file.
1 /**
2  * @file Trajectory.tcc
3  * @brief Template implementation for Trajectory.h
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date January 3, 2016
6  *
7  * This file is directly included in `Trajectory.h`.
8  *
9  */
10 
11 #ifndef LARDATAOBJ_RECOBASE_TRAJECTORY_TCC
12 #define LARDATAOBJ_RECOBASE_TRAJECTORY_TCC
13 
14 #ifndef LARDATAOBJ_RECOBASE_TRAJECTORY_H
15 #error "Do not include Trajectory.tcc. Include in Trajectory.h instead."
16 #endif // !LARDATAOBJ_RECOBASE_TRAJECTORY_H
17 
18 // LArSoft libraries
19 #include "lardataobj/Utilities/DataIOmanip.h" // util::manip::vector3D
20 
21 // C/C++ standard libraries
22 #include <algorithm> // std::max()
23 #include <utility> // std::forward()
24 
25 //------------------------------------------------------------------------------
26 template <typename Stream>
27 void recob::Trajectory::Dump(Stream&& out,
28  unsigned int verbosity,
29  std::string indent,
30  std::string indentFirst) const
31 {
32  /*
33  * This implementation follows this table:
34  *
35  *
36  * * level `0`: start position, direction, momentum modulus and number of
37  * points
38  * * level `1`: also end position, direction and momentum modulus
39  * * level `2`: also trajectory length
40  * * level `3`: also angles at start
41  * * level `4`: also 9 intermediate trajectory points
42  * * level `5`: also 10 more intermediate trajectory points (19 total)
43  * * level `6`: all trajectory points
44  *
45  */
46 
47  if (NPoints() < 2) {
48  out << indentFirst << "invalid trajectory with " << NPoints() << " points";
49  return;
50  }
51 
52  //----------------------------------------------------------------------------
53  out << indentFirst << "trajectory with " << NPoints() << " points at "
54  << util::manip::vector3D(Start()) << " cm toward " << util::manip::vector3D(StartDirection());
55  if (HasMomentum()) out << " with momentum " << StartMomentum() << " GeV/c";
56  // else out << " (no momentum information)"; // this is already evident...
57 
58  if (verbosity <= 0) return;
59  //----------------------------------------------------------------------------
60  out << indentFirst << "\n"
61  << indent << "ends at " << util::manip::vector3D(End()) << " cm toward "
62  << util::manip::vector3D(EndDirection());
63  if (HasMomentum()) out << " with momentum " << EndMomentum() << " GeV/c";
64 
65  if (verbosity <= 1) return;
66  //----------------------------------------------------------------------------
67  out << " running " << Length() << " cm long";
68 
69  if (verbosity <= 2) return;
70  //----------------------------------------------------------------------------
71 
72  out << "\n"
73  << indent << "starting with theta " << Theta() << " rad, phi " << Phi()
74  << " rad; zenith: " << ZenithAngle() << " rad, azimuth: " << AzimuthAngle() << " rad";
75 
76  if (verbosity <= 3) return;
77  //----------------------------------------------------------------------------
78  auto const nPoints = NPoints();
79  unsigned int nPrintedPoints;
80  switch (verbosity) {
81  case 4: nPrintedPoints = 9; break;
82  case 5: nPrintedPoints = 19; break;
83  case 6:
84  default: nPrintedPoints = nPoints - 2; break;
85  } // switch
86  float delta = std::max(float(nPoints - 1) / (nPrintedPoints + 1), 1.0f);
87  // number of trajectory points printed per line:
88  constexpr unsigned int pointsPerLine = 2;
89  unsigned int pointsInLine = 0;
90  out << " through:";
91 
92  for (unsigned int step = 1; step <= nPrintedPoints; ++step) {
93  size_t iPoint = delta * step;
94  if (iPoint >= LastPoint()) break;
95 
96  // new line every pointsPerLine points
97  if (pointsInLine++ == 0) out << "\n" << indent;
98  if (pointsInLine >= pointsPerLine) pointsInLine = 0;
99 
100  out << " [#" << iPoint << "] at " << util::manip::vector3D(LocationAtPoint(iPoint)) << " cm, "
101  << util::manip::vector3D(MomentumVectorAtPoint(iPoint));
102  if (HasMomentum()) out << " GeV/c";
103 
104  } // for
105 
106  if (verbosity <= 6) return;
107  //----------------------------------------------------------------------------
108  static_assert(MaxDumpVerbosity == 6,
109  "recob::Trajectory: either Dump() code or MaxDumpVerbosity value must be updated");
110 
111 } // recob::Trajectory::Dump()
112 
113 //------------------------------------------------------------------------------
114 template <typename Stream>
115 void recob::Trajectory::LowLevelDump(Stream&& out,
116  std::string indent,
117  std::string indentFirst) const
118 {
119  out << indentFirst << "recob::Trajectory[" << ((void*)this) << "]("
120  << "\n"
121  << indent << "fPositions={ // " << fPositions.size() << " elements";
122  for (size_t i = 0; i < fPositions.size(); ++i) {
123  out << "\n" << indent << " [" << i << "] " << util::manip::vector3D(fPositions[i]);
124  }
125  out << "\n"
126  << indent << "},"
127  << "\n"
128  << indent << "fMomenta={ // " << fMomenta.size() << " elements";
129  for (size_t i = 0; i < fMomenta.size(); ++i) {
130  out << "\n" << indent << " [" << i << "] " << util::manip::vector3D(fMomenta[i]);
131  }
132  out << "\n"
133  << indent << "},"
134  << "\n"
135  << indent << "fHasMomenta=" << fHasMomentum << "\n"
136  << indent << ")";
137 
138 } // recob::Trajectory::LowLevelDump()
139 
140 //------------------------------------------------------------------------------
141 template <typename Vect>
142 void recob::details::legacy::FillVector(Vect const& source, std::vector<double>& dest)
143 {
144  dest.resize(3);
145  dest[0] = source.X();
146  dest[1] = source.Y();
147  dest[2] = source.Z();
148 } // recob::details::legacy::FillVector(std::vector<double>)
149 
150 template <typename Vect>
151 void recob::details::legacy::FillVector(Vect const& source, double* dest)
152 {
153  // just hope there is enough space
154  dest[0] = source.X();
155  dest[1] = source.Y();
156  dest[2] = source.Z();
157 } // recob::details::legacy::FillVector(double*)
158 
159 template <typename SrcVect, typename DestVect>
160 void recob::details::legacy::FillTwoVectors(SrcVect const& firstSource,
161  SrcVect const& secondSource,
162  DestVect&& firstDest,
163  DestVect&& secondDest)
164 {
165  FillVector(firstSource, std::forward<DestVect>(firstDest));
166  FillVector(secondSource, std::forward<DestVect>(secondDest));
167 } // recob::details::legacy::FillTwoVectors()
168 
169 //------------------------------------------------------------------------------
170 
171 #endif // LARDATAOBJ_RECOBASE_TRAJECTORY_TCC