2 * @file TrackTrajectory.tcc
3 * @brief Template implementation for TrackTrajectory.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_TRACKTRAJECTORY_TCC
12 #define LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_TCC
14 #ifndef LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_H
15 # error "Do not include TrackTrajectory.tcc. Include in TrackTrajectory.h instead."
16 #endif // !LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_H
20 #include "lardataobj/Utilities/DataIOmanip.h" // util::manip::vector3D
22 // C/C++ standard libraries
23 #include <algorithm> // std::max()
26 //------------------------------------------------------------------------------
27 template <typename Stream>
28 void recob::TrackTrajectory::Dump(
30 unsigned int verbosity,
31 std::string indent, std::string indentFirst
35 * This implementation follows this table:
37 * * level `0`: start position, direction, momentum modulus and number of
39 * * level `1`: also end position, direction and momentum modulus
40 * * level `2`: also trajectory length
41 * * level `3`: also angles at start
42 * * level `4`: also 9 intermediate valid trajectory points
43 * * level `5`: also 10 more intermediate valid trajectory points (19 total)
44 * * level `6`: all valid trajectory points
45 * * level `7`: all trajectory points
50 << "invalid track trajectory with " << NPoints() << " points";
54 //----------------------------------------------------------------------------
56 << "track trajectory with " << NPoints() << " points at "
57 << util::manip::vector3D(Start()) << " cm toward "
58 << util::manip::vector3D(StartDirection());
59 if (HasMomentum()) out << " with momentum " << StartMomentum() << " GeV/c";
60 // else out << " (no momentum information)"; // this is already evident...
62 if (verbosity <= 0) return;
63 //----------------------------------------------------------------------------
65 << "\n" << indent << "ends at " << util::manip::vector3D(End())
66 << " cm toward " << util::manip::vector3D(EndDirection());
67 if (HasMomentum()) out << " with momentum " << EndMomentum() << " GeV/c";
69 if (verbosity <= 1) return;
70 //----------------------------------------------------------------------------
72 << " running " << Length() << " cm long";
74 if (verbosity <= 2) return;
75 //----------------------------------------------------------------------------
77 unsigned int const nInvalidPoints = NPoints() - CountValidPoints();
78 if (nInvalidPoints > 0)
79 out << " (with " << nInvalidPoints << " invalid points)";
81 if (verbosity <= 3) return;
82 //----------------------------------------------------------------------------
85 << "starting with theta " << Theta() << " rad, phi " << Phi()
86 << " rad; zenith: " << ZenithAngle() << " rad, azimuth: " << AzimuthAngle()
89 if (verbosity <= 4) return;
90 //----------------------------------------------------------------------------
91 auto const startIndex = FirstValidPoint();
92 auto const endIndex = LastValidPoint();
94 auto const nPoints = NPoints();
95 unsigned int nPrintedPoints;
98 nPrintedPoints = 10; break;
100 nPrintedPoints = 20; break;
103 nPrintedPoints = nPoints; break;
105 float delta = std::max(float(nPoints) / nPrintedPoints, 1.0f);
106 // number of trajectory points printed per line:
107 constexpr unsigned int pointsPerLine = 1;
108 unsigned int pointsInLine = 0;
111 for (unsigned int step = 0; step < nPrintedPoints; ++step) {
112 size_t iPoint = (size_t) std::llround(delta * step);
113 if (iPoint > LastPoint()) break;
115 // new line every pointsPerLine points
116 if (pointsInLine++ == 0) out << "\n" << indent;
117 if (pointsInLine >= pointsPerLine) pointsInLine = 0;
119 out << " [#" << iPoint << "]";
120 if (HasValidPoint(iPoint)) {
122 << util::manip::vector3D(LocationAtPoint(iPoint)) << " cm, "
123 << util::manip::vector3D(MomentumVectorAtPoint(iPoint));
124 if (HasMomentum()) out << " GeV/c";
127 << " " << FlagsAtPoint(iPoint);
128 if (iPoint == startIndex) out << " <START>";
129 if (iPoint == endIndex) out << " <END>";
134 if (verbosity <= 7) return;
135 //----------------------------------------------------------------------------
136 static_assert(MaxDumpVerbosity == 7,
137 "recob::TrackTrajectory: either Dump() code or MaxDumpVerbosity value must be updated"
140 } // recob::TrackTrajectory::Dump()
143 //------------------------------------------------------------------------------
144 template <typename Stream>
145 void recob::TrackTrajectory::LowLevelDump
146 (Stream&& out, std::string indent, std::string indentFirst) const
148 out << indentFirst << "recob::TrackTrajectory[" << ((void*) this) << "]("
150 Trajectory().LowLevelDump(std::forward<Stream>(out), indent + " ", "");
152 << "\n" << indent << "fFlags={ // " << fFlags.size() << " elements";
153 for (size_t i = 0; i < fFlags.size(); ++i) {
154 out << "\n" << indent << " [" << i << "] "
158 << "\n" << indent << "}"
159 << "\n" << indent << ")";
161 } // recob::TrackTrajectory::LowLevelDump()
163 //------------------------------------------------------------------------------
165 size_t recob::TrackTrajectory::ToValidPoint(size_t index) const {
167 static_assert((Dir == +1) || (Dir == -1),
168 "recob::Trajectory::ToValidPoint<Dir>() must have Dir either -1 or +1"
171 ssize_t sindex = static_cast<ssize_t>(index);
172 ssize_t const last = (Dir > 0)? (ssize_t) LastPoint(): 0;
173 while (!HasValidPoint(sindex)) {
175 if (Dir * sindex > Dir * last) return InvalidIndex;
177 return static_cast<size_t>(sindex);
179 } // recob::TrackTrajectory::ToValidPoint<+1>()
183 //------------------------------------------------------------------------------
186 #endif // LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_TCC