3 * @brief Template implementation for Trajectory.h
4 * @author Gianluca Petrillo (petrillo@fnal.gov)
5 * @date January 3, 2016
7 * This file is directly included in `Trajectory.h`.
11 #ifndef LARDATAOBJ_RECOBASE_TRAJECTORY_TCC
12 #define LARDATAOBJ_RECOBASE_TRAJECTORY_TCC
14 #ifndef LARDATAOBJ_RECOBASE_TRAJECTORY_H
15 # error "Do not include Trajectory.tcc. Include in Trajectory.h instead."
16 #endif // !LARDATAOBJ_RECOBASE_TRAJECTORY_H
20 #include "lardataobj/Utilities/DataIOmanip.h" // util::manip::vector3D
22 // C/C++ standard libraries
23 #include <algorithm> // std::max()
24 #include <utility> // std::forward()
27 //------------------------------------------------------------------------------
28 template <typename Stream>
29 void recob::Trajectory::Dump(
31 unsigned int verbosity,
32 std::string indent, std::string indentFirst
36 * This implementation follows this table:
39 * * level `0`: start position, direction, momentum modulus and number of
41 * * level `1`: also end position, direction and momentum modulus
42 * * level `2`: also trajectory length
43 * * level `3`: also angles at start
44 * * level `4`: also 9 intermediate trajectory points
45 * * level `5`: also 10 more intermediate trajectory points (19 total)
46 * * level `6`: all trajectory points
52 << "invalid trajectory with " << NPoints() << " points";
56 //----------------------------------------------------------------------------
58 << "trajectory with " << NPoints() << " points at "
59 << util::manip::vector3D(Start()) << " cm toward "
60 << util::manip::vector3D(StartDirection());
61 if (HasMomentum()) out << " with momentum " << StartMomentum() << " GeV/c";
62 // else out << " (no momentum information)"; // this is already evident...
64 if (verbosity <= 0) return;
65 //----------------------------------------------------------------------------
67 << "\n" << indent << "ends at " << util::manip::vector3D(End())
68 << " cm toward " << util::manip::vector3D(EndDirection());
69 if (HasMomentum()) out << " with momentum " << EndMomentum() << " GeV/c";
71 if (verbosity <= 1) return;
72 //----------------------------------------------------------------------------
74 << " running " << Length() << " cm long";
76 if (verbosity <= 2) return;
77 //----------------------------------------------------------------------------
80 << "starting with theta " << Theta() << " rad, phi " << Phi()
81 << " rad; zenith: " << ZenithAngle() << " rad, azimuth: " << AzimuthAngle()
84 if (verbosity <= 3) return;
85 //----------------------------------------------------------------------------
86 auto const nPoints = NPoints();
87 unsigned int nPrintedPoints;
90 nPrintedPoints = 9; break;
92 nPrintedPoints = 19; break;
95 nPrintedPoints = nPoints - 2; break;
97 float delta = std::max(float(nPoints - 1) / (nPrintedPoints + 1), 1.0f);
98 // number of trajectory points printed per line:
99 constexpr unsigned int pointsPerLine = 2;
100 unsigned int pointsInLine = 0;
103 for (unsigned int step = 1; step <= nPrintedPoints; ++step) {
104 size_t iPoint = delta * step;
105 if (iPoint >= LastPoint()) break;
107 // new line every pointsPerLine points
108 if (pointsInLine++ == 0) out << "\n" << indent;
109 if (pointsInLine >= pointsPerLine) pointsInLine = 0;
111 out << " [#" << iPoint << "] at "
112 << util::manip::vector3D(LocationAtPoint(iPoint)) << " cm, "
113 << util::manip::vector3D(MomentumVectorAtPoint(iPoint));
114 if (HasMomentum()) out << " GeV/c";
119 if (verbosity <= 6) return;
120 //----------------------------------------------------------------------------
121 static_assert(MaxDumpVerbosity == 6,
122 "recob::Trajectory: either Dump() code or MaxDumpVerbosity value must be updated"
125 } // recob::Trajectory::Dump()
128 //------------------------------------------------------------------------------
129 template <typename Stream>
130 void recob::Trajectory::LowLevelDump
131 (Stream&& out, std::string indent, std::string indentFirst) const
133 out << indentFirst << "recob::Trajectory[" << ((void*) this) << "]("
134 << "\n" << indent << "fPositions={ // " << fPositions.size() << " elements";
135 for (size_t i = 0; i < fPositions.size(); ++i) {
136 out << "\n" << indent << " [" << i << "] "
137 << util::manip::vector3D(fPositions[i]);
140 << "\n" << indent << "},"
141 << "\n" << indent << "fMomenta={ // " << fMomenta.size() << " elements";
142 for (size_t i = 0; i < fMomenta.size(); ++i) {
143 out << "\n" << indent << " [" << i << "] "
144 << util::manip::vector3D(fMomenta[i]);
147 << "\n" << indent << "},"
148 << "\n" << indent << "fHasMomenta=" << fHasMomentum
149 << "\n" << indent << ")";
151 } // recob::Trajectory::LowLevelDump()
154 //------------------------------------------------------------------------------
155 template <typename Vect>
156 void recob::details::legacy::FillVector
157 (Vect const& source, std::vector<double>& dest)
160 dest[0] = source.X();
161 dest[1] = source.Y();
162 dest[2] = source.Z();
163 } // recob::details::legacy::FillVector(std::vector<double>)
165 template <typename Vect>
166 void recob::details::legacy::FillVector
167 (Vect const& source, double* dest)
169 // just hope there is enough space
170 dest[0] = source.X();
171 dest[1] = source.Y();
172 dest[2] = source.Z();
173 } // recob::details::legacy::FillVector(double*)
176 template <typename SrcVect, typename DestVect>
177 void recob::details::legacy::FillTwoVectors(
178 SrcVect const& firstSource, SrcVect const& secondSource,
179 DestVect&& firstDest, DestVect&& secondDest
182 FillVector(firstSource, std::forward<DestVect>(firstDest));
183 FillVector(secondSource, std::forward<DestVect>(secondDest));
184 } // recob::details::legacy::FillTwoVectors()
187 //------------------------------------------------------------------------------
190 #endif // LARDATAOBJ_RECOBASE_TRAJECTORY_TCC