LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
Trajectory.tcc
Go to the documentation of this file.
1 /**
2  * @file Trajectory.tcc
3  * @brief Template implementation for Trajectory.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_TRAJECTORY_TCC
12 #define LARDATAOBJ_RECOBASE_TRAJECTORY_TCC
13 
14 #ifndef LARDATAOBJ_RECOBASE_TRAJECTORY_H
15 # error "Do not include Trajectory.tcc. Include in Trajectory.h instead."
16 #endif // !LARDATAOBJ_RECOBASE_TRAJECTORY_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 #include <utility> // std::forward()
25 
26 
27 //------------------------------------------------------------------------------
28 template <typename Stream>
29 void recob::Trajectory::Dump(
30  Stream&& out,
31  unsigned int verbosity,
32  std::string indent, std::string indentFirst
33  ) const
34 {
35  /*
36  * This implementation follows this table:
37  *
38  *
39  * * level `0`: start position, direction, momentum modulus and number of
40  * points
41  * * level `1`: also end position, direction and momentum modulus
42  * * level `2`: also trajectory length
43  * * level `3`: also angles at start
44  * * level `4`: also 9 intermediate trajectory points
45  * * level `5`: also 10 more intermediate trajectory points (19 total)
46  * * level `6`: all trajectory points
47  *
48  */
49 
50  if (NPoints() < 2) {
51  out << indentFirst
52  << "invalid trajectory with " << NPoints() << " points";
53  return;
54  }
55 
56  //----------------------------------------------------------------------------
57  out << indentFirst
58  << "trajectory with " << NPoints() << " points at "
59  << util::manip::vector3D(Start()) << " cm toward "
60  << util::manip::vector3D(StartDirection());
61  if (HasMomentum()) out << " with momentum " << StartMomentum() << " GeV/c";
62 // else out << " (no momentum information)"; // this is already evident...
63 
64  if (verbosity <= 0) return;
65  //----------------------------------------------------------------------------
66  out << indentFirst
67  << "\n" << indent << "ends at " << util::manip::vector3D(End())
68  << " cm toward " << util::manip::vector3D(EndDirection());
69  if (HasMomentum()) out << " with momentum " << EndMomentum() << " GeV/c";
70 
71  if (verbosity <= 1) return;
72  //----------------------------------------------------------------------------
73  out
74  << " running " << Length() << " cm long";
75 
76  if (verbosity <= 2) return;
77  //----------------------------------------------------------------------------
78 
79  out << "\n" << indent
80  << "starting with theta " << Theta() << " rad, phi " << Phi()
81  << " rad; zenith: " << ZenithAngle() << " rad, azimuth: " << AzimuthAngle()
82  << " rad";
83 
84  if (verbosity <= 3) return;
85  //----------------------------------------------------------------------------
86  auto const nPoints = NPoints();
87  unsigned int nPrintedPoints;
88  switch (verbosity) {
89  case 4:
90  nPrintedPoints = 9; break;
91  case 5:
92  nPrintedPoints = 19; break;
93  case 6:
94  default:
95  nPrintedPoints = nPoints - 2; break;
96  } // switch
97  float delta = std::max(float(nPoints - 1) / (nPrintedPoints + 1), 1.0f);
98  // number of trajectory points printed per line:
99  constexpr unsigned int pointsPerLine = 2;
100  unsigned int pointsInLine = 0;
101  out << " through:";
102 
103  for (unsigned int step = 1; step <= nPrintedPoints; ++step) {
104  size_t iPoint = delta * step;
105  if (iPoint >= LastPoint()) break;
106 
107  // new line every pointsPerLine points
108  if (pointsInLine++ == 0) out << "\n" << indent;
109  if (pointsInLine >= pointsPerLine) pointsInLine = 0;
110 
111  out << " [#" << iPoint << "] at "
112  << util::manip::vector3D(LocationAtPoint(iPoint)) << " cm, "
113  << util::manip::vector3D(MomentumVectorAtPoint(iPoint));
114  if (HasMomentum()) out << " GeV/c";
115 
116  } // for
117 
118 
119  if (verbosity <= 6) return;
120  //----------------------------------------------------------------------------
121  static_assert(MaxDumpVerbosity == 6,
122  "recob::Trajectory: either Dump() code or MaxDumpVerbosity value must be updated"
123  );
124 
125 } // recob::Trajectory::Dump()
126 
127 
128 //------------------------------------------------------------------------------
129 template <typename Stream>
130 void recob::Trajectory::LowLevelDump
131  (Stream&& out, std::string indent, std::string indentFirst) const
132 {
133  out << indentFirst << "recob::Trajectory[" << ((void*) this) << "]("
134  << "\n" << indent << "fPositions={ // " << fPositions.size() << " elements";
135  for (size_t i = 0; i < fPositions.size(); ++i) {
136  out << "\n" << indent << " [" << i << "] "
137  << util::manip::vector3D(fPositions[i]);
138  }
139  out
140  << "\n" << indent << "},"
141  << "\n" << indent << "fMomenta={ // " << fMomenta.size() << " elements";
142  for (size_t i = 0; i < fMomenta.size(); ++i) {
143  out << "\n" << indent << " [" << i << "] "
144  << util::manip::vector3D(fMomenta[i]);
145  }
146  out
147  << "\n" << indent << "},"
148  << "\n" << indent << "fHasMomenta=" << fHasMomentum
149  << "\n" << indent << ")";
150 
151 } // recob::Trajectory::LowLevelDump()
152 
153 
154 //------------------------------------------------------------------------------
155 template <typename Vect>
156 void recob::details::legacy::FillVector
157  (Vect const& source, std::vector<double>& dest)
158 {
159  dest.resize(3);
160  dest[0] = source.X();
161  dest[1] = source.Y();
162  dest[2] = source.Z();
163 } // recob::details::legacy::FillVector(std::vector<double>)
164 
165 template <typename Vect>
166 void recob::details::legacy::FillVector
167  (Vect const& source, double* dest)
168 {
169  // just hope there is enough space
170  dest[0] = source.X();
171  dest[1] = source.Y();
172  dest[2] = source.Z();
173 } // recob::details::legacy::FillVector(double*)
174 
175 
176 template <typename SrcVect, typename DestVect>
177 void recob::details::legacy::FillTwoVectors(
178  SrcVect const& firstSource, SrcVect const& secondSource,
179  DestVect&& firstDest, DestVect&& secondDest
180  )
181 {
182  FillVector(firstSource, std::forward<DestVect>(firstDest));
183  FillVector(secondSource, std::forward<DestVect>(secondDest));
184 } // recob::details::legacy::FillTwoVectors()
185 
186 
187 //------------------------------------------------------------------------------
188 
189 
190 #endif // LARDATAOBJ_RECOBASE_TRAJECTORY_TCC