LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 
19 // LArSoft libraries
20 #include "lardataobj/Utilities/DataIOmanip.h" // util::manip::vector3D
21 
22 // C/C++ standard libraries
23 #include <algorithm> // std::max()
24 
25 
26 //------------------------------------------------------------------------------
27 template <typename Stream>
28 void recob::TrackTrajectory::Dump(
29  Stream&& out,
30  unsigned int verbosity,
31  std::string indent, std::string indentFirst
32  ) const
33 {
34  /*
35  * This implementation follows this table:
36  *
37  * * level `0`: start position, direction, momentum modulus and number of
38  * points
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
46  */
47 
48  if (NPoints() < 2) {
49  out << indentFirst
50  << "invalid track trajectory with " << NPoints() << " points";
51  return;
52  }
53 
54  //----------------------------------------------------------------------------
55  out << indentFirst
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...
61 
62  if (verbosity <= 0) return;
63  //----------------------------------------------------------------------------
64  out << indentFirst
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";
68 
69  if (verbosity <= 1) return;
70  //----------------------------------------------------------------------------
71  out
72  << " running " << Length() << " cm long";
73 
74  if (verbosity <= 2) return;
75  //----------------------------------------------------------------------------
76 
77  unsigned int const nInvalidPoints = NPoints() - CountValidPoints();
78  if (nInvalidPoints > 0)
79  out << " (with " << nInvalidPoints << " invalid points)";
80 
81  if (verbosity <= 3) return;
82  //----------------------------------------------------------------------------
83 
84  out << "\n" << indent
85  << "starting with theta " << Theta() << " rad, phi " << Phi()
86  << " rad; zenith: " << ZenithAngle() << " rad, azimuth: " << AzimuthAngle()
87  << " rad";
88 
89  if (verbosity <= 4) return;
90  //----------------------------------------------------------------------------
91  auto const startIndex = FirstValidPoint();
92  auto const endIndex = LastValidPoint();
93 
94  auto const nPoints = NPoints();
95  unsigned int nPrintedPoints;
96  switch (verbosity) {
97  case 4:
98  nPrintedPoints = 10; break;
99  case 5:
100  nPrintedPoints = 20; break;
101  case 6:
102  default:
103  nPrintedPoints = nPoints; break;
104  } // switch
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;
109  out << " through:";
110 
111  for (unsigned int step = 0; step < nPrintedPoints; ++step) {
112  size_t iPoint = (size_t) std::llround(delta * step);
113  if (iPoint > LastPoint()) break;
114 
115  // new line every pointsPerLine points
116  if (pointsInLine++ == 0) out << "\n" << indent;
117  if (pointsInLine >= pointsPerLine) pointsInLine = 0;
118 
119  out << " [#" << iPoint << "]";
120  if (HasValidPoint(iPoint)) {
121  out << " at "
122  << util::manip::vector3D(LocationAtPoint(iPoint)) << " cm, "
123  << util::manip::vector3D(MomentumVectorAtPoint(iPoint));
124  if (HasMomentum()) out << " GeV/c";
125  }
126  out
127  << " " << FlagsAtPoint(iPoint);
128  if (iPoint == startIndex) out << " <START>";
129  if (iPoint == endIndex) out << " <END>";
130 
131  } // for
132 
133 
134  if (verbosity <= 7) return;
135  //----------------------------------------------------------------------------
136  static_assert(MaxDumpVerbosity == 7,
137  "recob::TrackTrajectory: either Dump() code or MaxDumpVerbosity value must be updated"
138  );
139 
140 } // recob::TrackTrajectory::Dump()
141 
142 
143 //------------------------------------------------------------------------------
144 template <typename Stream>
145 void recob::TrackTrajectory::LowLevelDump
146  (Stream&& out, std::string indent, std::string indentFirst) const
147 {
148  out << indentFirst << "recob::TrackTrajectory[" << ((void*) this) << "]("
149  << "\n" << indent;
150  Trajectory().LowLevelDump(std::forward<Stream>(out), indent + " ", "");
151  out << ","
152  << "\n" << indent << "fFlags={ // " << fFlags.size() << " elements";
153  for (size_t i = 0; i < fFlags.size(); ++i) {
154  out << "\n" << indent << " [" << i << "] "
155  << fFlags[i];
156  }
157  out
158  << "\n" << indent << "}"
159  << "\n" << indent << ")";
160 
161 } // recob::TrackTrajectory::LowLevelDump()
162 
163 //------------------------------------------------------------------------------
164 template <int Dir>
165 size_t recob::TrackTrajectory::ToValidPoint(size_t index) const {
166 
167  static_assert((Dir == +1) || (Dir == -1),
168  "recob::Trajectory::ToValidPoint<Dir>() must have Dir either -1 or +1"
169  );
170 
171  ssize_t sindex = static_cast<ssize_t>(index);
172  ssize_t const last = (Dir > 0)? (ssize_t) LastPoint(): 0;
173  while (!HasValidPoint(sindex)) {
174  sindex += Dir;
175  if (Dir * sindex > Dir * last) return InvalidIndex;
176  }
177  return static_cast<size_t>(sindex);
178 
179 } // recob::TrackTrajectory::ToValidPoint<+1>()
180 
181 
182 
183 //------------------------------------------------------------------------------
184 
185 
186 #endif // LARDATAOBJ_RECOBASE_TRACKTRAJECTORY_TCC