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
19 #include "lardataobj/Utilities/DataIOmanip.h" // util::manip::vector3D
21 // C/C++ standard libraries
22 #include <algorithm> // std::max()
24 //------------------------------------------------------------------------------
25 template <typename Stream>
26 void recob::TrackTrajectory::Dump(Stream&& out,
27 unsigned int verbosity,
29 std::string indentFirst) const
32 * This implementation follows this table:
34 * * level `0`: start position, direction, momentum modulus and number of
36 * * level `1`: also end position, direction and momentum modulus
37 * * level `2`: also trajectory length
38 * * level `3`: also angles at start
39 * * level `4`: also 9 intermediate valid trajectory points
40 * * level `5`: also 10 more intermediate valid trajectory points (19 total)
41 * * level `6`: all valid trajectory points
42 * * level `7`: all trajectory points
46 out << indentFirst << "invalid track trajectory with " << NPoints() << " points";
50 //----------------------------------------------------------------------------
51 out << indentFirst << "track trajectory with " << NPoints() << " points at "
52 << util::manip::vector3D(Start()) << " cm toward " << util::manip::vector3D(StartDirection());
53 if (HasMomentum()) out << " with momentum " << StartMomentum() << " GeV/c";
54 // else out << " (no momentum information)"; // this is already evident...
56 if (verbosity <= 0) return;
57 //----------------------------------------------------------------------------
58 out << indentFirst << "\n"
59 << indent << "ends at " << util::manip::vector3D(End()) << " cm toward "
60 << util::manip::vector3D(EndDirection());
61 if (HasMomentum()) out << " with momentum " << EndMomentum() << " GeV/c";
63 if (verbosity <= 1) return;
64 //----------------------------------------------------------------------------
65 out << " running " << Length() << " cm long";
67 if (verbosity <= 2) return;
68 //----------------------------------------------------------------------------
70 unsigned int const nInvalidPoints = NPoints() - CountValidPoints();
71 if (nInvalidPoints > 0) out << " (with " << nInvalidPoints << " invalid points)";
73 if (verbosity <= 3) return;
74 //----------------------------------------------------------------------------
77 << indent << "starting with theta " << Theta() << " rad, phi " << Phi()
78 << " rad; zenith: " << ZenithAngle() << " rad, azimuth: " << AzimuthAngle() << " rad";
80 if (verbosity <= 4) return;
81 //----------------------------------------------------------------------------
82 auto const startIndex = FirstValidPoint();
83 auto const endIndex = LastValidPoint();
85 auto const nPoints = NPoints();
86 unsigned int nPrintedPoints;
88 case 4: nPrintedPoints = 10; break;
89 case 5: nPrintedPoints = 20; break;
91 default: nPrintedPoints = nPoints; break;
93 float delta = std::max(float(nPoints) / nPrintedPoints, 1.0f);
94 // number of trajectory points printed per line:
95 constexpr unsigned int pointsPerLine = 1;
96 unsigned int pointsInLine = 0;
99 for (unsigned int step = 0; step < nPrintedPoints; ++step) {
100 size_t iPoint = (size_t)std::llround(delta * step);
101 if (iPoint > LastPoint()) break;
103 // new line every pointsPerLine points
104 if (pointsInLine++ == 0) out << "\n" << indent;
105 if (pointsInLine >= pointsPerLine) pointsInLine = 0;
107 out << " [#" << iPoint << "]";
108 if (HasValidPoint(iPoint)) {
109 out << " at " << util::manip::vector3D(LocationAtPoint(iPoint)) << " cm, "
110 << util::manip::vector3D(MomentumVectorAtPoint(iPoint));
111 if (HasMomentum()) out << " GeV/c";
113 out << " " << FlagsAtPoint(iPoint);
114 if (iPoint == startIndex) out << " <START>";
115 if (iPoint == endIndex) out << " <END>";
119 if (verbosity <= 7) return;
120 //----------------------------------------------------------------------------
122 MaxDumpVerbosity == 7,
123 "recob::TrackTrajectory: either Dump() code or MaxDumpVerbosity value must be updated");
125 } // recob::TrackTrajectory::Dump()
127 //------------------------------------------------------------------------------
128 template <typename Stream>
129 void recob::TrackTrajectory::LowLevelDump(Stream&& out,
131 std::string indentFirst) const
133 out << indentFirst << "recob::TrackTrajectory[" << ((void*)this) << "]("
136 Trajectory().LowLevelDump(std::forward<Stream>(out), indent + " ", "");
139 << indent << "fFlags={ // " << fFlags.size() << " elements";
140 for (size_t i = 0; i < fFlags.size(); ++i) {
141 out << "\n" << indent << " [" << i << "] " << fFlags[i];
148 } // recob::TrackTrajectory::LowLevelDump()
150 //------------------------------------------------------------------------------
152 size_t recob::TrackTrajectory::ToValidPoint(size_t index) const
155 static_assert((Dir == +1) || (Dir == -1),
156 "recob::Trajectory::ToValidPoint<Dir>() must have Dir either -1 or +1");
158 ssize_t sindex = static_cast<ssize_t>(index);
159 ssize_t const last = (Dir > 0) ? (ssize_t)LastPoint() : 0;
160 while (!HasValidPoint(sindex)) {
162 if (Dir * sindex > Dir * last) return InvalidIndex;
164 return static_cast<size_t>(sindex);
166 } // recob::TrackTrajectory::ToValidPoint<+1>()
168 //------------------------------------------------------------------------------
170 #endif // LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_TCC