Classes | Macros | Functions
geo_vectors_utils_test.cc File Reference

Test of geo_vectors_utils.h utilities. More...

#include <boost/test/unit_test.hpp>
#include "larcorealg/Geometry/geo_vectors_utils_TVector.h"
#include "larcorealg/Geometry/geo_vectors_utils.h"
#include "larcorealg/CoreUtils/MetaUtils.h"
#include "TVector2.h"
#include "TVector3.h"
#include "TLorentzVector.h"
#include <iostream>
#include <sstream>
#include <string>
#include <array>
#include <vector>
#include <numeric>
#include <type_traits>
#include <stdexcept>
#include <cmath>

Go to the source code of this file.

Classes

struct  test_vectorAccess< Vector >
 
struct  test_vectorAccess< Vector const >
 
struct  IsfiniteTester< Vector, Dim >
 
struct  IsfiniteTester< Vector, 4U >
 
struct  IsfiniteTester< Vector, 3U >
 
struct  IsfiniteTester< Vector, 2U >
 
struct  VectorTraitsTester
 
struct  VectorTraitsTester::Vector0D< C >
 
struct  VectorTraitsTester::Vector1D< C >
 
struct  VectorTraitsTester::Vector2D< C >
 
struct  VectorTraitsTester::Vector3D< C >
 
struct  VectorTraitsTester::Vector4D< C >
 
struct  VectorTraitsTester::Vector5D< C >
 

Macros

#define BOOST_TEST_MODULE   ( geo_vectors_test )
 

Functions

template<typename PointA , typename PointB >
void CheckPoint (PointA const &test, PointB const &ref, std::string tag="")
 
void test_MiddlePointAccumulator_defaultConstructor ()
 
void test_MiddlePointAccumulator_sequenceConstructor ()
 
template<typename Point >
void test_MiddlePointAccumulator_generic ()
 
void test_MiddlePointAccumulator_documentation_class ()
 
void test_MiddlePointAccumulator_documentation_middlePointAs ()
 
void test_MiddlePointAccumulator_documentation ()
 
void test_middlePoint ()
 
void test_middlePointAs_documentation ()
 
void test_middlePoint_iterators_documentation ()
 
void test_middlePoint_initlist_documentation ()
 
template<typename Vector >
void test_vectorProcessing ()
 
template<typename Source , typename Dest >
void test_vector2Dconvert ()
 
template<typename Source , typename Dest >
void test_vector3Dconvert ()
 
template<typename Source , typename Dest >
void test_vector4Dconvert ()
 
void test_makeFromCoords_documentation ()
 
template<typename Vector >
void test_transform ()
 
void test_XcoordManager_documentation ()
 
template<typename Vector >
void test_CoordConstIterator ()
 
template<typename Vector >
void test_fillCoords ()
 
 BOOST_AUTO_TEST_CASE (MiddlePointAccumulator_test)
 
 BOOST_AUTO_TEST_CASE (middlePoint_test)
 
 BOOST_AUTO_TEST_CASE (middlePoint_documentation_test)
 
 BOOST_AUTO_TEST_CASE (vectorAccess_test)
 
 BOOST_AUTO_TEST_CASE (vectorUtilDocumentation_test)
 
 BOOST_AUTO_TEST_CASE (vectorProperties_test)
 
 BOOST_AUTO_TEST_CASE (vectorProcessing_test)
 
 BOOST_AUTO_TEST_CASE (vectorConversion_test)
 
 BOOST_AUTO_TEST_CASE (vectorCoordinateIteration_test)
 

Detailed Description

Test of geo_vectors_utils.h utilities.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
March 23, 2017

Definition in file geo_vectors_utils_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( geo_vectors_test )

Definition at line 10 of file geo_vectors_utils_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( MiddlePointAccumulator_test  )

Definition at line 1094 of file geo_vectors_utils_test.cc.

1094  {
1098  test_MiddlePointAccumulator_generic<TVector3>();
1099  test_MiddlePointAccumulator_generic<geo::Vector_t>();
1100  test_MiddlePointAccumulator_generic<geo::Point_t>();
1101 } // BOOST_AUTO_TEST_CASE(MiddlePointAccumulator_test)
void test_MiddlePointAccumulator_defaultConstructor()
void test_MiddlePointAccumulator_sequenceConstructor()
void test_MiddlePointAccumulator_documentation()
BOOST_AUTO_TEST_CASE ( middlePoint_test  )

Definition at line 1103 of file geo_vectors_utils_test.cc.

1103  {
1104  test_middlePoint();
1105 }
void test_middlePoint()
BOOST_AUTO_TEST_CASE ( middlePoint_documentation_test  )

Definition at line 1107 of file geo_vectors_utils_test.cc.

1107  {
1111 }
void test_middlePoint_iterators_documentation()
void test_middlePoint_initlist_documentation()
void test_middlePointAs_documentation()
BOOST_AUTO_TEST_CASE ( vectorAccess_test  )
BOOST_AUTO_TEST_CASE ( vectorUtilDocumentation_test  )

Definition at line 1124 of file geo_vectors_utils_test.cc.

1124  {
1127 } // BOOST_AUTO_TEST_CASE(vectorUtilDocumentation_test)
void test_XcoordManager_documentation()
void test_makeFromCoords_documentation()
BOOST_AUTO_TEST_CASE ( vectorProperties_test  )

Definition at line 1131 of file geo_vectors_utils_test.cc.

1131  {
1132  (void) VectorTraitsTester();
1133 } // BOOST_AUTO_TEST_CASE(vectorConversion_test)
BOOST_AUTO_TEST_CASE ( vectorProcessing_test  )

Definition at line 1137 of file geo_vectors_utils_test.cc.

1137  {
1138  test_vectorProcessing<TVector2>();
1139  test_vectorProcessing<geo::Point_t>();
1140  test_vectorProcessing<geo::Vector_t>();
1141  test_vectorProcessing<TVector3>();
1142  test_vectorProcessing<TLorentzVector>();
1143 } // BOOST_AUTO_TEST_CASE(vectorProcessing_test)
BOOST_AUTO_TEST_CASE ( vectorConversion_test  )

Definition at line 1147 of file geo_vectors_utils_test.cc.

1147  {
1148  // BUG until clang bug 21629 is fixed, the amount of work to make the *test*
1149  // work on double[N] vectors is not worth; HERE are some things to restore
1150  // when the bug is fixed:
1151  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
1152 
1153  // 2D
1154  test_vector2Dconvert<TVector2 , TVector2 >();
1155  test_vector2Dconvert<std::array<double, 2U>, TVector2 >();
1156  // HERE
1157  // test_vector2Dconvert<double[2U] , TVector2 >();
1158 
1159  // 3D
1160  test_vector3Dconvert<std::array<double, 3U>, TVector3 >();
1161 
1162  // HERE
1163  // test_vector3Dconvert<double[3U] , TVector3 >();
1164  test_vector3Dconvert<TVector3 , TVector3 >();
1165  test_vector3Dconvert<geo::Point_t , TVector3 >();
1166  test_vector3Dconvert<geo::Vector_t , TVector3 >();
1167  test_vector3Dconvert<std::array<double, 3U>, geo::Point_t >();
1168  // HERE
1169  // test_vector3Dconvert<double[3U] , geo::Point_t >();
1170  test_vector3Dconvert<TVector3 , geo::Point_t >();
1171  test_vector3Dconvert<geo::Point_t , geo::Point_t >();
1172  test_vector3Dconvert<geo::Vector_t , geo::Point_t >();
1173  test_vector3Dconvert<std::array<double, 3U>, geo::Vector_t>();
1174  // HERE
1175  // test_vector3Dconvert<double[3U] , geo::Vector_t>();
1176  test_vector3Dconvert<TVector3 , geo::Vector_t>();
1177  test_vector3Dconvert<geo::Point_t , geo::Vector_t>();
1178  test_vector3Dconvert<geo::Vector_t , geo::Vector_t>();
1179 
1180  test_transform<TVector3>();
1181 
1182  // 4D
1183  test_vector4Dconvert<TLorentzVector , TLorentzVector>();
1184  test_vector4Dconvert<std::array<double, 4U>, TLorentzVector>();
1185  // HERE
1186  // test_vector4Dconvert<double[4U] , TLorentzVector>();
1187 
1188 } // BOOST_AUTO_TEST_CASE(vectorAccess_test)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
BOOST_AUTO_TEST_CASE ( vectorCoordinateIteration_test  )

Definition at line 1191 of file geo_vectors_utils_test.cc.

1191  {
1192 
1193  test_CoordConstIterator<TVector2 >();
1194  test_CoordConstIterator<TVector3 >();
1195  test_CoordConstIterator<geo::Point_t >();
1196  test_CoordConstIterator<geo::Vector_t >();
1197  test_CoordConstIterator<TLorentzVector>();
1198 
1199  test_fillCoords<TVector2 >();
1200  test_fillCoords<TVector3 >();
1201  test_fillCoords<geo::Point_t >();
1202  test_fillCoords<geo::Vector_t >();
1203  test_fillCoords<TLorentzVector>();
1204 
1205 } // BOOST_AUTO_TEST_CASE(vectorCoordinateIteration_test)
template<typename PointA , typename PointB >
void CheckPoint ( PointA const &  test,
PointB const &  ref,
std::string  tag = "" 
)

Definition at line 38 of file geo_vectors_utils_test.cc.

39 {
40  auto const tol = 0.001% tolerance();
41 
42  if (!tag.empty()) BOOST_TEST_CHECKPOINT(tag);
43 
44  for (auto ic: geo::vect::indices(test)) {
45  BOOST_TEST_CHECKPOINT(" coordinate #" << ic);
46  BOOST_TEST
47  (geo::vect::coord(test, ic)() == geo::vect::coord(ref, ic)(), tol);
48  }
49 
50 } // CheckPoint()
auto coord(Vector &v, unsigned int n) noexcept
Returns an object to manage the coordinate n of a vector.
auto const tol
Definition: SurfXYZTest.cc:16
auto const tolerance
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
template<typename Vector >
void test_CoordConstIterator ( )

Definition at line 1043 of file geo_vectors_utils_test.cc.

1043  {
1044 
1045  using Vector_t = Vector;
1047 
1048  std::array<Coord_t, geo::vect::dimension<Vector_t>()> expected;
1049  std::iota(expected.begin(), expected.end(), Coord_t(1));
1050  auto const v = geo::vect::makeFromCoords<Vector_t>(expected);
1051 
1052  unsigned int index = 0;
1053  for (Coord_t c: geo::vect::iterateCoords(v)) {
1054  BOOST_TEST(c == expected[index]);
1055  ++index;
1056  } // for
1057 
1058  // same test as above,
1059  // but implicitly using ROOT::Math::cbegin()/cend() we provide
1060  index = 0;
1061  for (Coord_t c: v) {
1062  BOOST_TEST(c == expected[index]);
1063  ++index;
1064  } // for
1065 
1066 } // test_CoordConstIterator()
vector< T > Vector
const char expected[]
Definition: Exception_t.cc:22
auto iterateCoords(Vector const &v)
Returns an object for ranged-for iteration on coordinates.
enum geo::coordinates Coord_t
details::VectorScalar_t< Vector > coordinate_t
Type of coordinate of the specified vector type.
recob::tracking::Vector_t Vector_t
template<typename Vector >
void test_fillCoords ( )

Definition at line 1071 of file geo_vectors_utils_test.cc.

1071  {
1072 
1073  using Vector_t = Vector;
1075 
1076  std::array<Coord_t, geo::vect::dimension<Vector_t>()> expected;
1077  std::iota(expected.begin(), expected.end(), Coord_t(1));
1078  auto const v = geo::vect::makeFromCoords<Vector_t>(expected);
1079 
1080  Coord_t coords[geo::vect::dimension<Vector_t>()];
1081  auto const dim = geo::vect::fillCoords(coords, v);
1082 
1083  BOOST_TEST(dim == expected.size());
1084 
1085  for (unsigned int index = 0; index < dim; ++index)
1086  BOOST_TEST(coords[index] == expected[index]);
1087 
1088 } // test_fillCoords()
vector< T > Vector
const char expected[]
Definition: Exception_t.cc:22
enum geo::coordinates Coord_t
unsigned int fillCoords(Coords &dest, Vector const &src)
Fills a coordinate array with the coordinates of a vector.
details::VectorScalar_t< Vector > coordinate_t
Type of coordinate of the specified vector type.
recob::tracking::Vector_t Vector_t
void test_makeFromCoords_documentation ( )

Definition at line 846 of file geo_vectors_utils_test.cc.

846  {
847 
848  /*
849  * constexpr std::array<float, 5U> data { 2.0, 5.0, 7.0, 11.0, 15.5 };
850  * constexpr auto p = geo::vect::makeFromCoords<geo::Point_t>(data);
851  * auto v = geo::vect::makeFromCoords<geo::Vector_t>(data.data() + 1);
852  */
853  // BUG the double brace syntax is required to work around clang bug 21629
854  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
855  constexpr std::array<float, 5U> data {{ 2.0, 5.0, 7.0, 11.0, 15.5 }};
856  auto const p = geo::vect::makeFromCoords<geo::Point_t>(data);
857  auto const v = geo::vect::makeFromCoords<geo::Vector_t>(data.data() + 1);
858 
859  BOOST_TEST(p == (geo::Point_t { 2.0, 5.0, 7.0 }));
860  BOOST_TEST(v == (geo::Vector_t{ 5.0, 7.0, 11.0 }));
861 
862 } // test_makeFromCoords_documentation()
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
p
Definition: test.py:223
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
void test_middlePoint ( )

Definition at line 288 of file geo_vectors_utils_test.cc.

288  {
289 
290  geo::Point_t expected(2., 4., 6.);
291 
292  std::vector<geo::Point_t> points {
293  geo::Point_t(1., 2., 3.),
294  geo::Point_t(2., 4., 6.),
295  geo::Point_t(3., 6., 9.)
296  };
297 
298  //
299  // sequence
300  //
301  CheckPoint
302  (geo::vect::middlePoint(points.begin(), points.end()), expected, "iterators");
303 
304 
305  //
306  // points (initializer list)
307  //
308  CheckPoint(
309  geo::vect::middlePoint({ points[0], points[1], points[2] }), expected,
310  "initializer list"
311  );
312 
313 
314  //
315  // middlePointAs() (sequence)
316  //
317  auto const mp3 = geo::vect::middlePointAs<TVector3>(points.begin(), points.end());
318  static_assert(
319  std::is_same<std::decay_t<decltype(mp3)>, TVector3>::value,
320  "geo::vect::middlePointAs<TVector3> does not return a TVector3!"
321  );
322  CheckPoint(mp3, expected, "geo::vect::middlePointAs(sequence)");
323 
324 
325 } // test_middlePoint()
const char expected[]
Definition: Exception_t.cc:22
void CheckPoint(PointA const &test, PointB const &ref, std::string tag="")
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
geo::Point_t middlePoint(BeginIter begin, EndIter end)
Returns the middle of the specified points.
void test_middlePoint_initlist_documentation ( )

Definition at line 379 of file geo_vectors_utils_test.cc.

379  {
380 
381  /*
382  * auto mp = geo::vect::middlePoint
383  * ({ geo::Point_t(1., 2., 3.), geo::Point_t(3., 6., 9.) });
384  *
385  */
386 
387  auto mp = geo::vect::middlePoint
388  ({ geo::Point_t(1., 2., 3.), geo::Point_t(3., 6., 9.) });
389 
390  static_assert(std::is_same<std::decay_t<decltype(mp)>, geo::Point_t>::value,
391  "geo::vect::middlePoint() result is not geo::Point_t");
392  CheckPoint(mp, geo::Point_t(2., 4., 6.));
393 
394 } // test_middlePoint_initlist_documentation()
void CheckPoint(PointA const &test, PointB const &ref, std::string tag="")
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
geo::Point_t middlePoint(BeginIter begin, EndIter end)
Returns the middle of the specified points.
void test_middlePoint_iterators_documentation ( )

Definition at line 352 of file geo_vectors_utils_test.cc.

352  {
353 
354  /*
355  * std::vector<geo::Point_t> points {
356  * geo::Point_t(1., 2., 3.),
357  * geo::Point_t(2., 4., 6.),
358  * geo::Point_t(3., 6., 9.)
359  * };
360  *
361  * auto mp = geo::vect::middlePoint(points.begin(), points.end());
362  */
363 
364  std::vector<geo::Point_t> points {
365  geo::Point_t(1., 2., 3.),
366  geo::Point_t(2., 4., 6.),
367  geo::Point_t(3., 6., 9.)
368  };
369 
370  auto mp = geo::vect::middlePoint(points.begin(), points.end());
371 
372  static_assert(std::is_same<std::decay_t<decltype(mp)>, geo::Point_t>::value,
373  "geo::vect::middlePoint() result is not geo::Point_t");
374  CheckPoint(mp, geo::Point_t(2., 4., 6.));
375 
376 } // test_middlePoint_iterators_documentation()
void CheckPoint(PointA const &test, PointB const &ref, std::string tag="")
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
geo::Point_t middlePoint(BeginIter begin, EndIter end)
Returns the middle of the specified points.
void test_MiddlePointAccumulator_defaultConstructor ( )

Definition at line 54 of file geo_vectors_utils_test.cc.

54  {
55 
56  geo::Point_t expected(2., 4., 6.);
57 
58  std::vector<geo::Point_t> points {
59  geo::Point_t(1., 2., 3.),
60  geo::Point_t(2., 4., 6.),
61  geo::Point_t(3., 6., 9.)
62  };
63  TVector3 another(expected.X(), expected.Y(), expected.Z());
64 
65  //
66  // default construction, then bulk addition
67  //
69  BOOST_TEST(acc.empty());
70  BOOST_TEST(acc.weight() == 0.0, 0.001% tolerance());
71  // add a single point
72  acc.add(another);
73  BOOST_TEST(!acc.empty());
74  BOOST_TEST(acc.weight() == 1.0, 0.001% tolerance());
75  CheckPoint(acc.middlePoint(), expected, "Single add");
76  // add many points
77  acc.add(points.begin(), points.end());
78  BOOST_TEST(!acc.empty());
79  BOOST_TEST(acc.weight() == 1.0 + points.size(), 0.001% tolerance());
80  CheckPoint(acc.middlePoint(), expected, "Single add plus sequence");
81 
82  //
83  // clear test
84  //
85  acc.clear();
86  BOOST_TEST(acc.empty());
87  acc.add(geo::Point_t{ expected.X() + 1.0, expected.Z(), expected.Y() });
88  CheckPoint(
89  acc.middlePoint(),
90  geo::Point_t{ expected.X() + 1.0, expected.Z(), expected.Y() },
91  "clear test"
92  );
93 
94  //
95  // start over (same accumulator)
96  //
97  acc.clear();
98  // add many points
99  acc.add(points.begin(), points.end());
100  BOOST_TEST(!acc.empty());
101  CheckPoint(acc.middlePoint(), expected, "Sequence add");
102  // add another one
103  acc.add(another);
104  BOOST_TEST(!acc.empty());
105  CheckPoint(acc.middlePoint(), expected, "Sequence add plus single point");
106 
107 } // test_MiddlePointAccumulator_defaultConstructor()
const char expected[]
Definition: Exception_t.cc:22
Helper class to compute the middle point in a point set.
void CheckPoint(PointA const &test, PointB const &ref, std::string tag="")
auto const tolerance
void add(Point const &p)
Accumulates a point.
void another()
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
void test_MiddlePointAccumulator_documentation ( )

Definition at line 279 of file geo_vectors_utils_test.cc.

279  {
280 
283 
284 } // test_MiddlePointAccumulator_documentation()
void test_MiddlePointAccumulator_documentation_middlePointAs()
void test_MiddlePointAccumulator_documentation_class()
void test_MiddlePointAccumulator_documentation_class ( )

Definition at line 210 of file geo_vectors_utils_test.cc.

210  {
211 
212  geo::Point_t expected { 0.0, 1.0, 0.0 };
213  /*
214  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
215  * std::array<geo::Point_t, 4> const points = {
216  * geo::Point_t{ 0.0, 1.0, 2.0 },
217  * geo::Point_t{ 0.0, -1.0, 2.0 },
218  * geo::Point_t{ 0.0, 1.0, -2.0 },
219  * geo::Point_t{ 0.0, -1.0, -2.0 }
220  * };
221  *
222  * geo::vect::MiddlePointAccumulator pointsAboveGround;
223  * for (auto const& point: points)
224  * if (point.Y() > 0.0) pointsAboveGround.add(point);
225  *
226  * if (pointsAboveGround.empty())
227  * throw std::runtime_error("No point above ground!");
228  *
229  * auto middleAboveGround = pointsAboveGround.middlePoint();
230  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
231  */
232  // BUG the double brace syntax is required to work around clang bug 21629
233  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
234  std::array<geo::Point_t, 4> const points = {{
235  geo::Point_t{ 0.0, 1.0, 2.0 },
236  geo::Point_t{ 0.0, -1.0, 2.0 },
237  geo::Point_t{ 0.0, 1.0, -2.0 },
238  geo::Point_t{ 0.0, -1.0, -2.0 }
239  }};
240 
241  geo::vect::MiddlePointAccumulator pointsAboveGround;
242  for (auto const& point: points)
243  if (point.Y() > 0.0) pointsAboveGround.add(point);
244 
245  if (pointsAboveGround.empty())
246  throw std::runtime_error("No point above ground!");
247 
248  auto middleAboveGround = pointsAboveGround.middlePoint();
249 
250 
251  static_assert(std::is_same<decltype(middleAboveGround), geo::Point_t>::value,
252  "unexpected return type for geo::vect::MiddlePointAccumulator::middlePoint()");
253  CheckPoint
254  (middleAboveGround, expected, "MiddlePointAccumulator::middlePoint()");
255 
256 } // test_MiddlePointAccumulator_documentation_middlePointAs()
const char expected[]
Definition: Exception_t.cc:22
Helper class to compute the middle point in a point set.
void CheckPoint(PointA const &test, PointB const &ref, std::string tag="")
void add(Point const &p)
Accumulates a point.
bool empty() const
Returns whether the total weight is zero (usually means no points).
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
void test_MiddlePointAccumulator_documentation_middlePointAs ( )

Definition at line 259 of file geo_vectors_utils_test.cc.

259  {
260 
261  //
262  // middlePointAs()
263  //
265  accumulator.add(geo::Point_t());
266 
267  /*
268  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
269  * auto mp = accumulator.middlePointAs<TVector3>();
270  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
271  */
272  auto mp = accumulator.middlePointAs<TVector3>();
273 
274  CheckPoint(mp, geo::Point_t(), "MiddlePointAccumulator::middlePointAs()");
275 
276 } // test_MiddlePointAccumulator_documentation_middlePointAs()
Point middlePointAs() const
Returns the middle point, NaN components if no point.
Helper class to compute the middle point in a point set.
void CheckPoint(PointA const &test, PointB const &ref, std::string tag="")
void add(Point const &p)
Accumulates a point.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
template<typename Point >
void test_MiddlePointAccumulator_generic ( )

Definition at line 137 of file geo_vectors_utils_test.cc.

137  {
138 
139  constexpr unsigned int Dim = geo::vect::dimension<Point>();
140  using Scalar_t = geo::vect::coordinate_t<Point>;
141 
142  // prepare the input from larger dimension input data
143  constexpr unsigned int MaxDim = 4U;
144 
145  static_assert(Dim < MaxDim, "This test supports only up to dimension 4");
146  using GenType = std::array<Scalar_t, MaxDim>;
147  // BUG the double brace syntax is required to work around clang bug 21629
148  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
149  GenType const genExpected{{ 2., 4., 6., 8. }};
150 
151  // BUG the double brace syntax is required to work around clang bug 21629
152  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
153  std::vector<GenType> genPoints {
154  GenType{{ 1., 2., 3., 4. }},
155  GenType{{ 2., 4., 6., 8. }},
156  GenType{{ 3., 6., 9., 12. }}
157  };
158 
159  std::vector<Point> points;
160  for (auto const& genPoint: genPoints)
161  points.push_back(geo::vect::makeFromCoords<Point>(genPoint.data()));
162  auto const expected = geo::vect::makeFromCoords<Point>(genExpected.data());
163  auto const another = expected;
164 
165  //
166  // default construction, then bulk addition
167  //
169  BOOST_TEST(acc.empty());
170  BOOST_TEST(acc.weight() == 0.0, 0.001% tolerance());
171  // add a single point
172  acc.add(another);
173  BOOST_TEST(!acc.empty());
174  BOOST_TEST(acc.weight() == 1.0, 0.001% tolerance());
175  CheckPoint(acc.middlePoint(), expected, "Single add");
176  // add many points
177  acc.add(points.begin(), points.end());
178  BOOST_TEST(!acc.empty());
179  BOOST_TEST(acc.weight() == 1.0 + points.size(), 0.001% tolerance());
180  CheckPoint(acc.middlePoint(), expected, "Single add plus sequence");
181 
182  //
183  // clear test
184  //
185  acc.clear();
186  BOOST_TEST(acc.empty());
187  acc.add(geo::Point_t{ expected.X() + 1.0, expected.Z(), expected.Y() });
188  CheckPoint(
189  acc.middlePoint(),
190  geo::Point_t{ expected.X() + 1.0, expected.Z(), expected.Y() },
191  "clear test"
192  );
193 
194  //
195  // start over (same accumulator)
196  //
197  acc.clear();
198  // add many points
199  acc.add(points.begin(), points.end());
200  BOOST_TEST(!acc.empty());
201  CheckPoint(acc.middlePoint(), expected, "Sequence add");
202  // add another one
203  acc.add(another);
204  BOOST_TEST(!acc.empty());
205  CheckPoint(acc.middlePoint(), expected, "Sequence add plus single point");
206 
207 } // test_MiddlePointAccumulator_generic()
void clear()
Resets the status of the object to no accumulated points.
const char expected[]
Definition: Exception_t.cc:22
Helper class to compute the middle point in a point set.
void CheckPoint(PointA const &test, PointB const &ref, std::string tag="")
auto const tolerance
double weight() const
Returns the total weight (number of points if all have weight 1).
void add(Point const &p)
Accumulates a point.
bool empty() const
Returns whether the total weight is zero (usually means no points).
void another()
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
details::VectorScalar_t< Vector > coordinate_t
Type of coordinate of the specified vector type.
void test_MiddlePointAccumulator_sequenceConstructor ( )

Definition at line 110 of file geo_vectors_utils_test.cc.

110  {
111 
112  geo::Point_t expected(2., 4., 6.);
113 
114  std::vector<geo::Point_t> points {
115  geo::Point_t(1., 2., 3.),
116  geo::Point_t(2., 4., 6.),
117  geo::Point_t(3., 6., 9.)
118  };
119  TVector3 another(expected.X(), expected.Y(), expected.Z());
120 
121  //
122  // sequence constructor
123  //
124  geo::vect::MiddlePointAccumulator acc(points.begin(), points.end());
125  BOOST_TEST(!acc.empty());
126  CheckPoint(acc.middlePoint(), expected, "Sequence construction");
127  // add another one
128  acc.add(another);
129  BOOST_TEST(!acc.empty());
130  CheckPoint(acc.middlePoint(), expected, "Sequence construction plus single");
131 
132 } // test_MiddlePointAccumulator_sequenceConstructor()
const char expected[]
Definition: Exception_t.cc:22
Helper class to compute the middle point in a point set.
void CheckPoint(PointA const &test, PointB const &ref, std::string tag="")
void another()
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
void test_middlePointAs_documentation ( )

Definition at line 328 of file geo_vectors_utils_test.cc.

328  {
329 
330  /*
331  * std::vector<geo::Point_t> points {
332  * geo::Point_t(1., 2., 3.),
333  * geo::Point_t(2., 4., 6.),
334  * geo::Point_t(3., 6., 9.)
335  * };
336  * auto mp = geo::vect::middlePointAs<geo::Vector_t>(points.begin(), points.end());
337  */
338  std::vector<geo::Point_t> points {
339  geo::Point_t(1., 2., 3.),
340  geo::Point_t(2., 4., 6.),
341  geo::Point_t(3., 6., 9.)
342  };
343  auto mp = geo::vect::middlePointAs<geo::Vector_t>(points.begin(), points.end());
344 
345  static_assert(std::is_same<std::decay_t<decltype(mp)>, geo::Vector_t>::value,
346  "geo::vect::middlePointAs<geo::Vector_t> result is not geo::Vector_t");
347  CheckPoint(mp, geo::Vector_t(2., 4., 6.));
348 
349 } // test_middlePointAs_documentation()
void CheckPoint(PointA const &test, PointB const &ref, std::string tag="")
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
template<typename Vector >
void test_transform ( )

Definition at line 867 of file geo_vectors_utils_test.cc.

867  {
868 
869  // BUG the double brace syntax is required to work around clang bug 21629
870  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
871  std::array<float, 5U> data {{ 4.0, 5.0, 7.0, 11.0, 15.5 }};
872  auto const v = geo::vect::makeFromCoords<Vector>(data);
873 
874  auto const neg_v = geo::vect::transformCoords(v, [](auto c){ return -c; });
875  static_assert
876  (std::is_same<decltype(neg_v), decltype(v)>(), "Unexpected return type");
877  BOOST_TEST(neg_v == -v);
878 
879 } // test_transform()
Vector transformCoords(Vector const &v, Pred &&pred)
Returns a new vector applying a predicate to each component.
template<typename Source , typename Dest >
void test_vector2Dconvert ( )

Definition at line 757 of file geo_vectors_utils_test.cc.

757  {
758 
759  // BUG the double brace syntax is required to work around clang bug 21629
760  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
761  std::array<double, 4U> srcData {{ 1.0, 5.0, 9.0, 16.0 }};
762 
763  // BUG the double brace syntax is required to work around clang bug 21629
764  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
765  // Source const src{ srcData[0], srcData[1] };
766  Source srcForClangBug;
767  if constexpr (util::is_STLarray_v<Source>)
768  srcForClangBug = Source{{ srcData[0], srcData[1] }};
769  else
770  srcForClangBug = Source{ srcData[0], srcData[1] };
771  Source const src { srcForClangBug };
772 
773  auto dest = geo::vect::convertTo<Dest>(src);
774 
775  static_assert
776  (std::is_same<decltype(dest), Dest>(), "Unexpected return type!");
777 
778  BOOST_TEST(geo::vect::Xcoord(dest) == srcData[0]);
779  BOOST_TEST(geo::vect::Ycoord(dest) == srcData[1]);
780 
781 } // test_vector2Dconvert()
auto Ycoord(Vector &v)
Returns an object to manage the coordinate Y of the vector v.
auto Xcoord(Vector &v)
Returns an object to manage the coordinate X of the vector v.
template<typename Source , typename Dest >
void test_vector3Dconvert ( )

Definition at line 786 of file geo_vectors_utils_test.cc.

786  {
787 
788  // BUG the double brace syntax is required to work around clang bug 21629
789  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
790  std::array<double, 4U> srcData {{ 1.0, 5.0, 9.0, 16.0 }};
791 
792  // BUG the double brace syntax is required to work around clang bug 21629
793  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
794  // Source const src{ srcData[0], srcData[1], srcData[2] };
795  Source srcForClangBug;
796  if constexpr (util::is_STLarray_v<Source>)
797  srcForClangBug = Source{{ srcData[0], srcData[1], srcData[2] }};
798  else
799  srcForClangBug = Source{ srcData[0], srcData[1], srcData[2] };
800  Source const src { srcForClangBug };
801 
802  auto dest = geo::vect::convertTo<Dest>(src);
803 
804  static_assert
805  (std::is_same<decltype(dest), Dest>(), "Unexpected return type!");
806 
807  BOOST_TEST(geo::vect::Xcoord(dest) == srcData[0]);
808  BOOST_TEST(geo::vect::Ycoord(dest) == srcData[1]);
809  BOOST_TEST(geo::vect::Zcoord(dest) == srcData[2]);
810 
811 } // test_vector3Dconvert()
auto Zcoord(Vector &v)
Returns an object to manage the coordinate Z of the vector v.
auto Ycoord(Vector &v)
Returns an object to manage the coordinate Y of the vector v.
auto Xcoord(Vector &v)
Returns an object to manage the coordinate X of the vector v.
template<typename Source , typename Dest >
void test_vector4Dconvert ( )

Definition at line 816 of file geo_vectors_utils_test.cc.

816  {
817 
818  // BUG the double brace syntax is required to work around clang bug 21629
819  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
820  std::array<double, 4U> srcData {{ 1.0, 5.0, 9.0, 16.0 }};
821 
822  // BUG the double brace syntax is required to work around clang bug 21629
823  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
824  // Source const src{ srcData[0], srcData[1], srcData[2], srcData[3] };
825  Source srcForClangBug;
826  if constexpr (util::is_STLarray_v<Source>)
827  srcForClangBug = Source{{ srcData[0], srcData[1], srcData[2], srcData[3] }};
828  else
829  srcForClangBug = Source{ srcData[0], srcData[1], srcData[2], srcData[3] };
830  Source const src { srcForClangBug };
831 
832 
833  auto dest = geo::vect::convertTo<Dest>(src);
834 
835  static_assert
836  (std::is_same<decltype(dest), Dest>(), "Unexpected return type!");
837 
838  BOOST_TEST(geo::vect::Xcoord(dest) == srcData[0]);
839  BOOST_TEST(geo::vect::Ycoord(dest) == srcData[1]);
840  BOOST_TEST(geo::vect::Zcoord(dest) == srcData[2]);
841  BOOST_TEST(geo::vect::Tcoord(dest) == srcData[3]);
842 
843 } // test_vector4Dconvert()
auto Zcoord(Vector &v)
Returns an object to manage the coordinate Z of the vector v.
auto Ycoord(Vector &v)
Returns an object to manage the coordinate Y of the vector v.
auto Xcoord(Vector &v)
Returns an object to manage the coordinate X of the vector v.
auto Tcoord(Vector &v)
Returns an object to manage the coordinate T of the vector v.
template<typename Vector >
void test_vectorProcessing ( )

Definition at line 748 of file geo_vectors_utils_test.cc.

748  {
749 
750  (void) IsfiniteTester<Vector>();
751 
752 } // test_vectorProcessing()
void test_XcoordManager_documentation ( )

Definition at line 883 of file geo_vectors_utils_test.cc.

883  {
884  std::ostringstream expected, out;
885  /*
886  * // constant vectors get a "reader" (read-only manager):
887  * geo::Vector_t v { 1.0, 2.0, 3.0 };
888  *
889  * auto vx = geo::vect::bindCoord(v, geo::vect::XcoordManager<geo::Vector_t const>);
890  * std::cout << v << " has x=" << vx() << std::endl;
891  */
892 
893  // constant vectors get a "reader" (read-only manager):
894  geo::Vector_t v { 1.0, 2.0, 3.0 };
895 
896  auto vx = geo::vect::bindCoord(v, geo::vect::XcoordManager<geo::Vector_t const>);
897  std::cout << v << " has x=" << vx() << std::endl;
898  out << v << " has x=" << vx();
899  expected << v << " has x=" << v.X();
900 
901  BOOST_TEST(out.str() == expected.str());
902 
903  out.str("");
904  expected.str("");
905  /*
906  * // mutable vectors get a full-featured "manager":
907  * geo::Point_t p { 1.0, 2.0, 3.0 };
908  * auto px = geo::vect::bindCoord(p, geo::vect::XcoordManager<geo::Point_t>);
909  * px *= 5.0;
910  * std::cout << p << " has now x=" << px() << std::endl;
911  */
912 
913  // mutable vectors get a full-featured "manager":
914  geo::Point_t p { 1.0, 2.0, 3.0 };
915  auto px = geo::vect::bindCoord(p, geo::vect::XcoordManager<geo::Point_t>);
916  px *= 5.0;
917  std::cout << p << " has now x=" << px() << std::endl;
918  out << p << " has now x=" << px();
919  expected << p << " has now x=" << p.X();
920 
921  BOOST_TEST(out.str() == expected.str());
922 
923 } // test_XcoordManager_documentation()
const char expected[]
Definition: Exception_t.cc:22
constexpr auto bindCoord(Vector const &v, CoordReader_t< Vector > helper)
Binds the specified constant vector to the coordinate reader.
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
p
Definition: test.py:223
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
QTextStream & endl(QTextStream &s)