LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TrackTrajectory.tcc
Go to the documentation of this file.
1 /**
2  * @file TrackTrajectory.tcc
3  * @brief Template implementation for TrackTrajectory.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_TRACKTRAJECTORY_TCC
12 #define LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_TCC
13 
14 #ifndef LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_H
15 #error "Do not include TrackTrajectory.tcc. Include in TrackTrajectory.h instead."
16 #endif // !LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_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 
24 //------------------------------------------------------------------------------
25 template <typename Stream>
26 void recob::TrackTrajectory::Dump(Stream&& out,
27  unsigned int verbosity,
28  std::string indent,
29  std::string indentFirst) const
30 {
31  /*
32  * This implementation follows this table:
33  *
34  * * level `0`: start position, direction, momentum modulus and number of
35  * points
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
43  */
44 
45  if (NPoints() < 2) {
46  out << indentFirst << "invalid track trajectory with " << NPoints() << " points";
47  return;
48  }
49 
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...
55 
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";
62 
63  if (verbosity <= 1) return;
64  //----------------------------------------------------------------------------
65  out << " running " << Length() << " cm long";
66 
67  if (verbosity <= 2) return;
68  //----------------------------------------------------------------------------
69 
70  unsigned int const nInvalidPoints = NPoints() - CountValidPoints();
71  if (nInvalidPoints > 0) out << " (with " << nInvalidPoints << " invalid points)";
72 
73  if (verbosity <= 3) return;
74  //----------------------------------------------------------------------------
75 
76  out << "\n"
77  << indent << "starting with theta " << Theta() << " rad, phi " << Phi()
78  << " rad; zenith: " << ZenithAngle() << " rad, azimuth: " << AzimuthAngle() << " rad";
79 
80  if (verbosity <= 4) return;
81  //----------------------------------------------------------------------------
82  auto const startIndex = FirstValidPoint();
83  auto const endIndex = LastValidPoint();
84 
85  auto const nPoints = NPoints();
86  unsigned int nPrintedPoints;
87  switch (verbosity) {
88  case 4: nPrintedPoints = 10; break;
89  case 5: nPrintedPoints = 20; break;
90  case 6:
91  default: nPrintedPoints = nPoints; break;
92  } // switch
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;
97  out << " through:";
98 
99  for (unsigned int step = 0; step < nPrintedPoints; ++step) {
100  size_t iPoint = (size_t)std::llround(delta * step);
101  if (iPoint > LastPoint()) break;
102 
103  // new line every pointsPerLine points
104  if (pointsInLine++ == 0) out << "\n" << indent;
105  if (pointsInLine >= pointsPerLine) pointsInLine = 0;
106 
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";
112  }
113  out << " " << FlagsAtPoint(iPoint);
114  if (iPoint == startIndex) out << " <START>";
115  if (iPoint == endIndex) out << " <END>";
116 
117  } // for
118 
119  if (verbosity <= 7) return;
120  //----------------------------------------------------------------------------
121  static_assert(
122  MaxDumpVerbosity == 7,
123  "recob::TrackTrajectory: either Dump() code or MaxDumpVerbosity value must be updated");
124 
125 } // recob::TrackTrajectory::Dump()
126 
127 //------------------------------------------------------------------------------
128 template <typename Stream>
129 void recob::TrackTrajectory::LowLevelDump(Stream&& out,
130  std::string indent,
131  std::string indentFirst) const
132 {
133  out << indentFirst << "recob::TrackTrajectory[" << ((void*)this) << "]("
134  << "\n"
135  << indent;
136  Trajectory().LowLevelDump(std::forward<Stream>(out), indent + " ", "");
137  out << ","
138  << "\n"
139  << indent << "fFlags={ // " << fFlags.size() << " elements";
140  for (size_t i = 0; i < fFlags.size(); ++i) {
141  out << "\n" << indent << " [" << i << "] " << fFlags[i];
142  }
143  out << "\n"
144  << indent << "}"
145  << "\n"
146  << indent << ")";
147 
148 } // recob::TrackTrajectory::LowLevelDump()
149 
150 //------------------------------------------------------------------------------
151 template <int Dir>
152 size_t recob::TrackTrajectory::ToValidPoint(size_t index) const
153 {
154 
155  static_assert((Dir == +1) || (Dir == -1),
156  "recob::Trajectory::ToValidPoint<Dir>() must have Dir either -1 or +1");
157 
158  ssize_t sindex = static_cast<ssize_t>(index);
159  ssize_t const last = (Dir > 0) ? (ssize_t)LastPoint() : 0;
160  while (!HasValidPoint(sindex)) {
161  sindex += Dir;
162  if (Dir * sindex > Dir * last) return InvalidIndex;
163  }
164  return static_cast<size_t>(sindex);
165 
166 } // recob::TrackTrajectory::ToValidPoint<+1>()
167 
168 //------------------------------------------------------------------------------
169 
170 #endif // LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_TCC