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
19 #include "lardataobj/Utilities/DataIOmanip.h" // util::manip::vector3D
21 // C/C++ standard libraries
22 #include <algorithm> // std::max()
23 #include <utility> // std::forward()
25 //------------------------------------------------------------------------------
26 template <typename Stream>
27 void recob::Trajectory::Dump(Stream&& out,
28 unsigned int verbosity,
30 std::string indentFirst) const
33 * This implementation follows this table:
36 * * level `0`: start position, direction, momentum modulus and number of
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
48 out << indentFirst << "invalid trajectory with " << NPoints() << " points";
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...
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";
65 if (verbosity <= 1) return;
66 //----------------------------------------------------------------------------
67 out << " running " << Length() << " cm long";
69 if (verbosity <= 2) return;
70 //----------------------------------------------------------------------------
73 << indent << "starting with theta " << Theta() << " rad, phi " << Phi()
74 << " rad; zenith: " << ZenithAngle() << " rad, azimuth: " << AzimuthAngle() << " rad";
76 if (verbosity <= 3) return;
77 //----------------------------------------------------------------------------
78 auto const nPoints = NPoints();
79 unsigned int nPrintedPoints;
81 case 4: nPrintedPoints = 9; break;
82 case 5: nPrintedPoints = 19; break;
84 default: nPrintedPoints = nPoints - 2; break;
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;
92 for (unsigned int step = 1; step <= nPrintedPoints; ++step) {
93 size_t iPoint = delta * step;
94 if (iPoint >= LastPoint()) break;
96 // new line every pointsPerLine points
97 if (pointsInLine++ == 0) out << "\n" << indent;
98 if (pointsInLine >= pointsPerLine) pointsInLine = 0;
100 out << " [#" << iPoint << "] at " << util::manip::vector3D(LocationAtPoint(iPoint)) << " cm, "
101 << util::manip::vector3D(MomentumVectorAtPoint(iPoint));
102 if (HasMomentum()) out << " GeV/c";
106 if (verbosity <= 6) return;
107 //----------------------------------------------------------------------------
108 static_assert(MaxDumpVerbosity == 6,
109 "recob::Trajectory: either Dump() code or MaxDumpVerbosity value must be updated");
111 } // recob::Trajectory::Dump()
113 //------------------------------------------------------------------------------
114 template <typename Stream>
115 void recob::Trajectory::LowLevelDump(Stream&& out,
117 std::string indentFirst) const
119 out << indentFirst << "recob::Trajectory[" << ((void*)this) << "]("
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]);
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]);
135 << indent << "fHasMomenta=" << fHasMomentum << "\n"
138 } // recob::Trajectory::LowLevelDump()
140 //------------------------------------------------------------------------------
141 template <typename Vect>
142 void recob::details::legacy::FillVector(Vect const& source, std::vector<double>& dest)
145 dest[0] = source.X();
146 dest[1] = source.Y();
147 dest[2] = source.Z();
148 } // recob::details::legacy::FillVector(std::vector<double>)
150 template <typename Vect>
151 void recob::details::legacy::FillVector(Vect const& source, double* dest)
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*)
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)
165 FillVector(firstSource, std::forward<DestVect>(firstDest));
166 FillVector(secondSource, std::forward<DestVect>(secondDest));
167 } // recob::details::legacy::FillTwoVectors()
169 //------------------------------------------------------------------------------
171 #endif // LARDATAOBJ_RECOBASE_TRAJECTORY_TCC