Classes | Macros | Functions
TrackTrajectory_test.cc File Reference

Simple test on a recob::TrackTrajectory object. More...

#include "boost/test/unit_test.hpp"
#include "lardataobj/RecoBase/TrackTrajectory.h"
#include "lardataobj/RecoBase/TrajectoryPointFlags.h"
#include "larcoreobj/SimpleTypesAndConstants/PhysicalConstants.h"
#include "TVector3.h"
#include "TMatrixD.h"
#include <set>
#include <iterator>
#include <algorithm>
#include <tuple>
#include <iostream>

Go to the source code of this file.

Classes

struct  Expected_t
 

Macros

#define BOOST_TEST_MODULE   ( tracktrajectory_test )
 

Functions

template<typename T >
void CheckValue (T v, T exp, T tol, std::string tag="")
 
template<typename VectA , typename VectB >
void CheckVectorsEqual (VectA const &v, VectB const &exp)
 
template<typename VectA , typename VectB >
void CheckVectorsClose (VectA const &v, VectB const &exp, double tol=0.01)
 
recob::TrackTrajectory::Rotation_t makeRotationMatrix (TMatrixD const &Tm)
 
void TestTrackTrajectory (recob::TrackTrajectory const &traj, Expected_t const &expected)
 
void TrackTrajectoryTestDefaultConstructor ()
 
void TrackTrajectoryTestMainConstructor ()
 
 BOOST_AUTO_TEST_CASE (TrackTrajectoryTestDefaultConstructorTestCase)
 
 BOOST_AUTO_TEST_CASE (TrackTrajectoryTestMainConstructorTestCase)
 

Detailed Description

Simple test on a recob::TrackTrajectory object.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
January 3, 2016
Version
1.0

This test simply creates recob::TrackTrajectory objects and verifies that the values it can access are the right ones.

See http://www.boost.org/libs/test for the Boost test library home page.

Definition in file TrackTrajectory_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( tracktrajectory_test )

Definition at line 26 of file TrackTrajectory_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( TrackTrajectoryTestDefaultConstructorTestCase  )

Definition at line 618 of file TrackTrajectory_test.cc.

618  {
620 }
void TrackTrajectoryTestDefaultConstructor()
BOOST_AUTO_TEST_CASE ( TrackTrajectoryTestMainConstructorTestCase  )

Definition at line 622 of file TrackTrajectory_test.cc.

622  {
624 }
void TrackTrajectoryTestMainConstructor()
template<typename T >
void CheckValue ( v,
exp,
tol,
std::string  tag = "" 
)

Definition at line 65 of file TrackTrajectory_test.cc.

65  {
66  if (!tag.empty()) BOOST_TEST_MESSAGE(tag);
67  if (std::abs(exp) < (tol / 100.)) BOOST_CHECK_SMALL(v, tol);
68  else BOOST_CHECK_CLOSE(v, exp, tol);
69 } // CheckValue()
auto const tol
Definition: SurfXYZTest.cc:16
T abs(T value)
template<typename VectA , typename VectB >
void CheckVectorsClose ( VectA const &  v,
VectB const &  exp,
double  tol = 0.01 
)

Definition at line 79 of file TrackTrajectory_test.cc.

79  {
80  CheckValue(v.X(), exp.X(), tol, " X()");
81  CheckValue(v.Y(), exp.Y(), tol, " Y()");
82  CheckValue(v.Z(), exp.Z(), tol, " Z()");
83 } // CheckVectorsClose()
auto const tol
Definition: SurfXYZTest.cc:16
void CheckValue(T v, T exp, T tol, std::string tag="")
template<typename VectA , typename VectB >
void CheckVectorsEqual ( VectA const &  v,
VectB const &  exp 
)

Definition at line 72 of file TrackTrajectory_test.cc.

72  {
73  BOOST_TEST(v.X() == exp.X());
74  BOOST_TEST(v.Y() == exp.Y());
75  BOOST_TEST(v.Z() == exp.Z());
76 } // CheckVectorsEqual()
recob::TrackTrajectory::Rotation_t makeRotationMatrix ( TMatrixD const &  Tm)

Definition at line 86 of file TrackTrajectory_test.cc.

86  {
88  m.SetRotationMatrix(Tm);
89  return m;
90 } // makeRotationMatrix()
tracking::Rotation_t Rotation_t
Type for representation of space rotations.
void TestTrackTrajectory ( recob::TrackTrajectory const &  traj,
Expected_t const &  expected 
)

Definition at line 93 of file TrackTrajectory_test.cc.

97 {
98 
99  //----------------------------------------------------------------------------
100  const size_t NPoints = expected.positions.size();
101  BOOST_TEST(traj.NPoints() == NPoints);
102  BOOST_TEST(traj.NumberTrajectoryPoints() == NPoints);
103 
104  for (size_t i = 0; i <= NPoints + 1; ++i) {
105  BOOST_TEST_MESSAGE("HasPoint() position #" << i);
106  BOOST_TEST(traj.HasPoint(i) == (i < NPoints));
107  } // for
108 
109  if (NPoints == 0) return; // nothing else is defined
110 
111  BOOST_TEST(traj.HasMomentum() == expected.hasMomenta);
112 
113  //----------------------------------------------------------------------------
114  // some preparation:
115  std::set<size_t> validPoints;
116  for (size_t i = 0; i < NPoints; ++i) {
118  continue;
119  validPoints.insert(i);
120  } // for
121  std::size_t const firstValidPoint = validPoints.empty()
122  ? recob::TrackTrajectory::InvalidIndex: *(validPoints.begin());
123  std::size_t const lastValidPoint = validPoints.empty()
124  ? recob::TrackTrajectory::InvalidIndex: *(validPoints.rbegin());
125 
126  //----------------------------------------------------------------------------
127  BOOST_TEST(traj.LastPoint() == NPoints - 1);
128 
129  //----------------------------------------------------------------------------
130  for (size_t i = 0; i < NPoints; ++i) {
131 
132  bool const isValid = (validPoints.count(i) > 0);
133  BOOST_TEST_MESSAGE("HasValidPoint() position #" << i);
134  BOOST_TEST(traj.HasValidPoint(i) == isValid);
135 
136  if (isValid) {
137  BOOST_TEST(traj.NextValidPoint(i) == i);
138  BOOST_TEST(traj.PreviousValidPoint(i) == i);
139  }
140  else { // if not a valid point
142  auto iNext = validPoints.upper_bound(i);
143  if (iNext == validPoints.end()) { // after last valid point
144  BOOST_TEST(traj.PreviousValidPoint(i) == lastValidPoint);
145  BOOST_TEST(traj.NextValidPoint(i) == InvalidIndex);
146  }
147  else if (iNext == validPoints.begin()) { // before first valid point
148  BOOST_TEST(traj.PreviousValidPoint(i) == InvalidIndex);
149  BOOST_TEST(traj.NextValidPoint(i) == firstValidPoint);
150  }
151  else { // in the middle of the trajectory
152  BOOST_TEST(traj.PreviousValidPoint(i) == *(std::prev(iNext)));
153  BOOST_TEST(traj.NextValidPoint(i) == *iNext);
154  }
155  }
156 
157  } // for
158 
159  if (!validPoints.empty()) {
160  BOOST_TEST(traj.FirstValidPoint() == firstValidPoint);
161  BOOST_TEST(traj.LastValidPoint() == lastValidPoint);
162  }
163 
164  BOOST_TEST(traj.CountValidPoints() == validPoints.size());
165 
166  //----------------------------------------------------------------------------
167  BOOST_TEST_MESSAGE("Vertex()");
168  CheckVectorsEqual(traj.Vertex(), expected.positions[firstValidPoint]);
169 
170  BOOST_TEST_MESSAGE("Start()");
171  CheckVectorsEqual(traj.Start(), expected.positions[firstValidPoint]);
172 
173  BOOST_TEST_MESSAGE("End()");
174  CheckVectorsEqual(traj.End(), expected.positions[lastValidPoint]);
175 
176  //----------------------------------------------------------------------------
177  for (size_t i = 0; i < NPoints; ++i) {
178 
179  BOOST_TEST_MESSAGE("LocationAtPoint() position #" << i);
180  CheckVectorsEqual(traj.LocationAtPoint(i), expected.positions[i]);
181 
182  } // for
183 
184 
185  //----------------------------------------------------------------------------
186  TVector3 Vstart, Vend;
187  std::tie(Vstart, Vend) = traj.Extent<TVector3>();
188  BOOST_TEST(Vstart[0] == expected.positions[firstValidPoint].X());
189  BOOST_TEST(Vstart[1] == expected.positions[firstValidPoint].Y());
190  BOOST_TEST(Vstart[2] == expected.positions[firstValidPoint].Z());
191  BOOST_TEST(Vend[0] == expected.positions[lastValidPoint].X());
192  BOOST_TEST(Vend[1] == expected.positions[lastValidPoint].Y());
193  BOOST_TEST(Vend[2] == expected.positions[lastValidPoint].Z());
194 
195 
197  std::tie(start, end) = traj.Extent(); // assign both start and end
198  BOOST_TEST_MESSAGE("Extent() start");
199  CheckVectorsEqual(start, expected.positions[firstValidPoint]);
200  BOOST_TEST_MESSAGE("Extent() end");
201  CheckVectorsEqual(end, expected.positions[lastValidPoint]);
202 
203 
204  //----------------------------------------------------------------------------
205  BOOST_CHECK_CLOSE(traj.Length(), expected.length, 0.01); // 0.01%
206  if (validPoints.size() >= 2) {
207  std::size_t const secondValidPoint = *(std::next(validPoints.begin()));
208  BOOST_CHECK_CLOSE(traj.Length(firstValidPoint + 1),
209  expected.length - (
210  expected.positions[secondValidPoint]
211  - expected.positions[firstValidPoint]
212  ).R(),
213  0.01
214  );
215  } // if
216 
217 
218  //----------------------------------------------------------------------------
219  BOOST_TEST_MESSAGE("VertexDirection()");
221  (traj.VertexDirection(), expected.momenta[firstValidPoint].Unit());
222  BOOST_CHECK_CLOSE(traj.VertexDirection().Mag2(), 1.0, 0.01);
223 
224  BOOST_TEST_MESSAGE("StartDirection()");
226  (traj.StartDirection(), expected.momenta[firstValidPoint].Unit());
227  BOOST_CHECK_CLOSE(traj.StartDirection().Mag2(), 1.0, 0.01);
228 
229  BOOST_TEST_MESSAGE("EndDirection()");
231  (traj.EndDirection(), expected.momenta[lastValidPoint].Unit());
232  BOOST_CHECK_CLOSE(traj.EndDirection().Mag2(), 1.0, 0.01);
233 
234 
235  //----------------------------------------------------------------------------
236  BOOST_CHECK_CLOSE(traj.Theta(), expected.theta, 0.01);
237  BOOST_CHECK_CLOSE(traj.Phi(), expected.phi, 0.01);
238  BOOST_CHECK_CLOSE(traj.ZenithAngle(), expected.zenith, 0.01);
239  BOOST_CHECK_CLOSE(traj.AzimuthAngle(), expected.azimuth, 0.01);
240 
241 
242  //----------------------------------------------------------------------------
243 
244  BOOST_TEST_MESSAGE("VertexMomentumVector()");
246  (traj.VertexMomentumVector(), expected.momenta[firstValidPoint]);
247 
248  BOOST_TEST_MESSAGE("StartMomentumVector()");
250  (traj.StartMomentumVector(), expected.momenta[firstValidPoint]);
251 
252  BOOST_TEST_MESSAGE("EndMomentumVector()");
253  CheckVectorsClose(traj.EndMomentumVector(), expected.momenta[lastValidPoint]);
254 
255 
256  //----------------------------------------------------------------------------
257  BOOST_TEST_MESSAGE("VertexMomentum()");
258  BOOST_CHECK_CLOSE
259  (traj.VertexMomentum(), expected.momenta[firstValidPoint].R(), 0.01);
260 
261  BOOST_TEST_MESSAGE("StartMomentum()");
262  BOOST_CHECK_CLOSE
263  (traj.StartMomentum(), expected.momenta[firstValidPoint].R(), 0.01);
264 
265  BOOST_TEST_MESSAGE("EndMomentum()");
266  BOOST_CHECK_CLOSE
267  (traj.EndMomentum(), expected.momenta[lastValidPoint].R(), 0.01);
268 
269 
270  //----------------------------------------------------------------------------
271  for (size_t i = 0; i < NPoints; ++i) {
272 
273  BOOST_TEST_MESSAGE("DirectionAtPoint() position #" << i);
274  CheckVectorsClose(traj.DirectionAtPoint(i), expected.momenta[i].Unit());
275 
276  } // for
277 
278 
279  //----------------------------------------------------------------------------
280  for (size_t i = 0; i < NPoints; ++i) {
281 
282  if (validPoints.count(i) == 0) continue; // invalid points can be whatever
283 
284  BOOST_TEST_MESSAGE("MomentumVectorAtPoint() position #" << i);
285  if (traj.HasMomentum())
286  CheckVectorsClose(traj.MomentumVectorAtPoint(i), expected.momenta[i]);
287  else {
289  (traj.MomentumVectorAtPoint(i), expected.momenta[i].Unit());
290  }
291 
292  BOOST_TEST_MESSAGE("MomentumAtPoint() position #" << i);
293  if (traj.HasMomentum()) {
294  BOOST_CHECK_CLOSE
295  (traj.MomentumAtPoint(i), expected.momenta[i].R(), 0.01);
296  }
297  else
298  BOOST_CHECK_CLOSE(traj.MomentumAtPoint(i), 1.0, 0.01);
299 
300  } // for
301 
302 
303  //----------------------------------------------------------------------------
304  TVector3 AstartDir, AendDir;
305  std::tie(AstartDir, AendDir) = traj.Direction<TVector3>();
306  BOOST_CHECK_CLOSE
307  (AstartDir[0], expected.momenta[firstValidPoint].Unit().X(), 0.01);
308  BOOST_CHECK_CLOSE
309  (AstartDir[1], expected.momenta[firstValidPoint].Unit().Y(), 0.01);
310  BOOST_CHECK_CLOSE
311  (AstartDir[2], expected.momenta[firstValidPoint].Unit().Z(), 0.01);
312  BOOST_CHECK_CLOSE
313  (AendDir[0], expected.momenta[lastValidPoint].Unit().X(), 0.01);
314  BOOST_CHECK_CLOSE
315  (AendDir[1], expected.momenta[lastValidPoint].Unit().Y(), 0.01);
316  BOOST_CHECK_CLOSE
317  (AendDir[2], expected.momenta[lastValidPoint].Unit().Z(), 0.01);
318 
319  recob::Trajectory::Vector_t startDir, endDir;
320  std::tie(startDir, endDir) = traj.Direction();
321  BOOST_TEST_MESSAGE("Direction() start");
322  CheckVectorsClose(startDir, expected.momenta[firstValidPoint].Unit());
323  BOOST_TEST_MESSAGE("Direction() end");
324  CheckVectorsClose(endDir, expected.momenta[lastValidPoint].Unit());
325 
326 
327  //----------------------------------------------------------------------------
328 
329  for (size_t i = 0; i < NPoints; ++i) {
330 
331  if (validPoints.count(i) == 0) continue; // invalid points can be whatever
332 
333  auto const& dir = expected.momenta[i];
334  recob::Trajectory::Vector_t localDir(0., 0., dir.R());
335 
336  BOOST_TEST_MESSAGE("Test transformation to local at point #" << i);
337  auto toLocal = traj.GlobalToLocalRotationAtPoint(i);
338  CheckVectorsClose(toLocal * dir, localDir);
339 
340  BOOST_TEST_MESSAGE("Test transformation to global at point #" << i);
341  auto toGlobal = traj.LocalToGlobalRotationAtPoint(i);
342  CheckVectorsClose(toGlobal * localDir, dir);
343 
344  } // for
345 
346  //----------------------------------------------------------------------------
347  for (size_t i = 0; i < NPoints; ++i) {
348 
349  if (validPoints.count(i) == 0) continue; // invalid points can be whatever
350 
351  auto const& dir = expected.momenta[i];
352  recob::Trajectory::Vector_t localDir(0., 0., dir.R());
353 
354  BOOST_TEST_MESSAGE("Test legacy transformation to local at point #" << i);
355  TMatrixD TtoLocal = traj.GlobalToLocalRotationAtPoint<TMatrixD>(i);
356  auto toLocal = makeRotationMatrix(TtoLocal);
357  CheckVectorsClose(toLocal * dir, localDir);
358 
359  BOOST_TEST_MESSAGE("Test legacy transformation to global at point #" << i);
360  TMatrixD TtoGlobal = traj.LocalToGlobalRotationAtPoint<TMatrixD>(i);
361  auto toGlobal = makeRotationMatrix(TtoGlobal);
362  CheckVectorsClose(toGlobal * localDir, dir);
363 
364  } // for
365 
366  //----------------------------------------------------------------------------
367 
368 } // TestTrackTrajectory()
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
static constexpr Flag_t NoPoint
The trajectory point is not defined.
const char expected[]
Definition: Exception_t.cc:22
string dir
recob::TrackTrajectory::Rotation_t makeRotationMatrix(TMatrixD const &Tm)
void CheckVectorsEqual(VectA const &v, VectB const &exp)
const Index InvalidIndex
tracking::Vector_t Vector_t
Type for representation of momenta in 3D space.
Definition: Trajectory.h:76
static constexpr size_t InvalidIndex
Value returned on failed index queries.
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
Definition: Trajectory.h:73
void CheckVectorsClose(VectA const &v, VectB const &exp, double tol=0.01)
void TrackTrajectoryTestDefaultConstructor ( )

Definition at line 372 of file TrackTrajectory_test.cc.

372  {
373 
374  BOOST_TEST_MESSAGE("Testing the default recob::TrackTrajectory constructor");
375 
376  //
377  // Part I: initialization of trajectory inputs
378  //
379  // these are the values expected for a default-constructed trajectory
381  expected.positions.clear();
382  expected.momenta.clear();
383  expected.flags.clear();
384  expected.hasMomenta = false;
385  expected.length = 0.0;
386 
387  //
388  // Part II: default constructor
389  //
390  // step II.1: create a trajectory with the default constructor
392 
393  for (unsigned int v = 0; v <= recob::TrackTrajectory::MaxDumpVerbosity; ++v) {
394  std::cout
395  << "Default-constructed track trajectory dump with verbosity level "
396  << v << ":" << std::endl;
397  traj.Dump(std::cout, v, " ", " ");
398  std::cout << std::endl;
399  } // for
400 
401  // step II.2: verify that the values are as expected
402  TestTrackTrajectory(traj, expected);
403 
404 } // TrackTrajectoryTestDefaultConstructor()
void Dump(Stream &&out, unsigned int verbosity, std::string indent, std::string indentFirst) const
Prints trajectory content into a stream.
recob::TrackTrajectory::Positions_t positions
const char expected[]
Definition: Exception_t.cc:22
A trajectory in space reconstructed from hits.
recob::TrackTrajectory::Flags_t flags
void TestTrackTrajectory(recob::TrackTrajectory const &traj, Expected_t const &expected)
recob::TrackTrajectory::Momenta_t momenta
static constexpr unsigned int MaxDumpVerbosity
Largest verbosity level supported by Dump().
QTextStream & endl(QTextStream &s)
void TrackTrajectoryTestMainConstructor ( )

Definition at line 408 of file TrackTrajectory_test.cc.

408  {
409 
410  BOOST_TEST_MESSAGE("Testing the main recob::TrackTrajectory constructor");
411 
412  //
413  // Part I: initialization of trajectory inputs
414  //
415  const recob::TrackTrajectory::Coord_t V2_2 = std::sqrt(0.5);
417  // we describe a trajectory with uniform electric and magnetic fields aligned
418  // on z; curvature is 1 on the x/y plane.
419  expected.positions = {
420  recob::TrackTrajectory::Point_t( -1.0, 0.0, 0.0 ),
421  recob::TrackTrajectory::Point_t( -V2_2, +V2_2, 1.0 ),
422  recob::TrackTrajectory::Point_t( 0.0, +1.0, 2.0 ),
423  recob::TrackTrajectory::Point_t( +V2_2, +V2_2, 3.0 ),
424  recob::TrackTrajectory::Point_t( +1.0, 0.0, 4.0 ),
425  recob::TrackTrajectory::Point_t( +V2_2, -V2_2, 5.0 ),
426  recob::TrackTrajectory::Point_t( 0.0, -1.0, 6.0 ),
427  recob::TrackTrajectory::Point_t( -V2_2, -V2_2, 7.0 ),
428  recob::TrackTrajectory::Point_t( -1.0, 0.0, 8.0 ),
429  recob::TrackTrajectory::Point_t( -V2_2, +V2_2, 9.0 ),
430  recob::TrackTrajectory::Point_t( 0.0, +1.0, 10.0 ),
431  recob::TrackTrajectory::Point_t( +V2_2, +V2_2, 11.0 ),
432  recob::TrackTrajectory::Point_t( +1.0, 0.0, 12.0 ),
433  recob::TrackTrajectory::Point_t( +V2_2, -V2_2, 13.0 ),
434  recob::TrackTrajectory::Point_t( 0.0, -1.0, 14.0 ),
435  recob::TrackTrajectory::Point_t( -V2_2, -V2_2, 15.0 ),
436  recob::TrackTrajectory::Point_t( -1.0, 0.0, 16.0 ),
437  recob::TrackTrajectory::Point_t( -V2_2, +V2_2, 17.0 ),
438  recob::TrackTrajectory::Point_t( 0.0, +1.0, 18.0 ),
439  recob::TrackTrajectory::Point_t( +V2_2, +V2_2, 19.0 ),
440  recob::TrackTrajectory::Point_t( +1.0, 0.0, 20.0 ),
441  recob::TrackTrajectory::Point_t( +V2_2, -V2_2, 21.0 ),
442  recob::TrackTrajectory::Point_t( 0.0, -1.0, 22.0 ),
443  recob::TrackTrajectory::Point_t( -V2_2, -V2_2, 23.0 ),
444  recob::TrackTrajectory::Point_t( -1.0, 0.0, 24.0 )
445  };
446  expected.momenta = {
447  recob::TrackTrajectory::Vector_t( 0.0, +1.0, 1.0 ),
448  recob::TrackTrajectory::Vector_t( +V2_2, +V2_2, 1.0 ),
449  recob::TrackTrajectory::Vector_t( +1.0, 0.0, 1.0 ),
450  recob::TrackTrajectory::Vector_t( +V2_2, -V2_2, 1.0 ),
451  recob::TrackTrajectory::Vector_t( 0.0, -1.0, 1.0 ),
452  recob::TrackTrajectory::Vector_t( -V2_2, -V2_2, 1.0 ),
453  recob::TrackTrajectory::Vector_t( -1.0, 0.0, 1.0 ),
454  recob::TrackTrajectory::Vector_t( -V2_2, +V2_2, 1.0 ),
455  recob::TrackTrajectory::Vector_t( 0.0, +1.0, 1.0 ),
456  recob::TrackTrajectory::Vector_t( +V2_2, +V2_2, 1.0 ),
457  recob::TrackTrajectory::Vector_t( +1.0, 0.0, 1.0 ),
458  recob::TrackTrajectory::Vector_t( +V2_2, -V2_2, 1.0 ),
459  recob::TrackTrajectory::Vector_t( 0.0, -1.0, 1.0 ),
460  recob::TrackTrajectory::Vector_t( -V2_2, -V2_2, 1.0 ),
461  recob::TrackTrajectory::Vector_t( -1.0, 0.0, 1.0 ),
462  recob::TrackTrajectory::Vector_t( -V2_2, +V2_2, 1.0 ),
463  recob::TrackTrajectory::Vector_t( 0.0, +1.0, 1.0 ),
464  recob::TrackTrajectory::Vector_t( +V2_2, +V2_2, 1.0 ),
465  recob::TrackTrajectory::Vector_t( +1.0, 0.0, 1.0 ),
466  recob::TrackTrajectory::Vector_t( +V2_2, -V2_2, 1.0 ),
467  recob::TrackTrajectory::Vector_t( 0.0, -1.0, 1.0 ),
468  recob::TrackTrajectory::Vector_t( -V2_2, -V2_2, 1.0 ),
469  recob::TrackTrajectory::Vector_t( -1.0, 0.0, 1.0 ),
470  recob::TrackTrajectory::Vector_t( -V2_2, +V2_2, 1.0 ),
471  recob::TrackTrajectory::Vector_t( 0.0, +1.0, 1.0 )
472  };
473  using trkflag = recob::TrackTrajectory::flag;
474  expected.flags = {
500  };
501  expected.hasMomenta = true;
502  expected.length = 12. * std::sqrt(6);
503  expected.theta = util::pi() / 4.0;
504  expected.phi = util::pi() / 2.0;
505  expected.zenith = 0.75 * util::pi();
506  expected.azimuth = 0.0;
507 
508  //
509  // Part II: complete constructor
510  //
511  // step II.1: create a track with momentum information
512  auto positions = expected.positions;
513  auto momenta = expected.momenta;
514  auto flags = expected.flags;
516  (std::move(positions), std::move(momenta), std::move(flags), true);
517 
518  for (unsigned int v = 0; v <= recob::TrackTrajectory::MaxDumpVerbosity; ++v) {
519  std::cout << "Track trajectory dump with verbosity level "
520  << v << ":" << std::endl;
521  traj.Dump(std::cout, v, " ", " ");
522  std::cout << std::endl;
523  } // for
524 
525  // step II.2: verify that the values are as expected
526  TestTrackTrajectory(traj, expected);
527 
528  //
529  // Part III: complete constructor, no momentum
530  //
531 
532  // step III.1: amend the expectation for a momentumless track
533  std::transform(expected.momenta.begin(), expected.momenta.end(),
534  expected.momenta.begin(), [](auto const& v){ return v.unit(); });
535  expected.hasMomenta = false;
536 
537  // step III.2: create a track with no momentum information
538  positions = expected.positions; // copy again
539  recob::TrackTrajectory::Momenta_t directions = expected.momenta;
540  flags = expected.flags;
542  (std::move(positions), std::move(directions), std::move(flags), false);
543 
544  for (unsigned int v = 0; v <= recob::TrackTrajectory::MaxDumpVerbosity; ++v) {
545  std::cout << "Momentumless trajectory dump with verbosity level "
546  << v << ":" << std::endl;
547  mltraj.Dump(std::cout, v, " ", " ");
548  std::cout << std::endl;
549  } // for
550 
551  // step III.3: verify that the values are as expected
552  TestTrackTrajectory(mltraj, expected);
553 
554  //
555  // Part IV: complete constructor, less valid points
556  //
557 
558  // step IV.2: suppress the points
559  expected.flags = {
585  };
586  expected.hasMomenta = true;
587  expected.length = 2. * std::sqrt(20.0);
588 
589  // step IV.2: create the track
590  positions = expected.positions; // copy again
591  momenta = expected.momenta;
592  flags = expected.flags;
593  recob::TrackTrajectory shorttraj
594  (std::move(positions), std::move(momenta), std::move(flags), true);
595 
596  for (unsigned int v = 0; v <= recob::TrackTrajectory::MaxDumpVerbosity; ++v) {
597  std::cout << "Short trajectory dump with verbosity level "
598  << v << ":" << std::endl;
599  shorttraj.Dump(std::cout, v, " ", " ");
600  std::cout << std::endl;
601  } // for
602 
603  // step IV.3: verify that the values are as expected
604  TestTrackTrajectory(shorttraj, expected);
605 
606 } // TrackTrajectoryTestMainConstructor()
recob::TrackTrajectory::Positions_t positions
const char expected[]
Definition: Exception_t.cc:22
PointFlags_t::flag flag
Flag traits (including the definition of flag mnemonics).
tracking::Momenta_t Momenta_t
Type of momentum list.
A trajectory in space reconstructed from hits.
def move(depos, offset)
Definition: depos.py:107
recob::TrackTrajectory::Flags_t flags
tracking::Vector_t Vector_t
Type for representation of momenta in 3D space.
void TestTrackTrajectory(recob::TrackTrajectory const &traj, Expected_t const &expected)
static constexpr HitIndex_t InvalidHitIndex
Value marking an invalid hit index.
recob::TrackTrajectory::Momenta_t momenta
tracking::Coord_t Coord_t
Type used for coordinates and values in general.
static constexpr unsigned int MaxDumpVerbosity
Largest verbosity level supported by Dump().
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
QTextStream & endl(QTextStream &s)