9 #include <boost/test/unit_test.hpp>
19 using namespace Acts::detail;
32 const double tol = 1
e-6;
34 double get_cyclic_value(
double value,
double min,
double max) {
35 return value - (max -
min) * std::floor((value - min) / (max -
min));
38 double get_cyclic_difference(
double a,
double b,
double min,
double max) {
39 const double period = max -
min;
40 const double half_period = period / 2;
41 a = get_cyclic_value(a, min, max);
42 b = get_cyclic_value(b, min, max);
43 double raw_diff = a -
b;
45 (raw_diff > half_period)
47 : ((raw_diff < -half_period) ? period + raw_diff : raw_diff);
51 void check_residuals_for_bound_parameters() {
54 double theta_1 = 0.7 *
M_PI;
55 double theta_2 = 0.4 *
M_PI;
56 ActsVectorD<1> dTheta;
57 dTheta << (theta_1 - theta_2);
60 ParameterSet<eBoundTheta> bound1(std::nullopt, theta_1);
61 ParameterSet<eBoundTheta> bound2(std::nullopt, theta_2);
65 dTheta << (theta_2 - theta_1);
71 dTheta << max - theta_2;
75 dTheta << theta_2 -
max;
81 dTheta << theta_2 -
min;
85 dTheta << min - theta_2;
113 void check_residuals_for_cyclic_parameters() {
120 dPhi << (phi_1 -
phi_2);
122 ParameterSet<eBoundPhi> cyclic1(std::nullopt, phi_1);
123 ParameterSet<eBoundPhi> cyclic2(std::nullopt, phi_2);
134 dPhi << get_cyclic_difference(phi_1, phi_2, min, max);
143 dPhi << get_cyclic_difference(phi_1, phi_2, min, max);
148 void random_residual_tests() {
150 std::default_random_engine
e;
151 std::uniform_real_distribution<float> uniform_dist(-1000, 300);
160 FullParameterSet parSet_1(std::nullopt, parValues_1);
161 FullParameterSet parSet_2(std::nullopt, parValues_2);
163 const unsigned int toys = 1000;
164 for (
unsigned int i = 0; i < toys; ++i) {
165 const double loc0_1 = uniform_dist(e);
166 const double loc1_1 = uniform_dist(e);
167 const double phi_1 = uniform_dist(e);
168 const double theta_1 = uniform_dist(e);
169 const double qop_1 = uniform_dist(e);
170 parValues_1 << loc0_1, loc1_1,
phi_1, theta_1, qop_1, 0.;
171 parSet_1.setParameters(parValues_1);
173 const double loc0_2 = uniform_dist(e);
174 const double loc1_2 = uniform_dist(e);
175 const double phi_2 = uniform_dist(e);
176 const double theta_2 = uniform_dist(e);
177 const double qop_2 = uniform_dist(e);
178 parValues_2 << loc0_2, loc1_2,
phi_2, theta_2, qop_2, 0.;
179 parSet_2.setParameters(parValues_2);
181 const double delta_loc0 = loc0_1 - loc0_2;
182 const double delta_loc1 = loc1_1 - loc1_2;
185 const double delta_theta =
186 (theta_1 > theta_max ? theta_max
187 : (theta_1 < theta_min ? theta_min : theta_1)) -
188 (theta_2 > theta_max ? theta_max
189 : (theta_2 < theta_min ? theta_min : theta_2));
190 const double delta_qop = qop_1 - qop_2;
191 residual = parSet_1.residual(parSet_2);
194 if (
std::abs(residual(0) - delta_loc0) > tol) {
198 if (
std::abs(residual(1) - delta_loc1) > tol) {
206 get_cyclic_value(phi_2, phi_min, phi_max) + residual(2),
208 get_cyclic_value(phi_1, phi_min, phi_max)) > tol or
209 std::abs(residual(2)) > (phi_max - phi_min) / 2) {
215 if (
std::abs(residual(3) - delta_theta) > tol or
216 std::abs(residual(3)) > (theta_max - theta_min)) {
221 if (
std::abs(residual(4) - delta_qop) > tol) {
249 cov << 1, 0, 0, 0, 1.2, 0.2, 0, 0.2, 0.7;
263 BOOST_CHECK(parSet_with_cov.
size() == 3);
286 std::nullopt, parValues);
302 double newLoc0 = 0.1;
303 double newLoc1 = 0.6;
304 double newPhi = -0.15 *
M_PI;
305 parValues << newLoc0, newLoc1, newPhi;
327 cov << 1, 0, 0, 0, 1.2, 0.2, 0, 0.2, 0.7;
341 BOOST_CHECK(first == copy);
345 BOOST_CHECK(first == moved);
349 BOOST_CHECK(assigned == moved);
353 BOOST_CHECK(assigned != other);
355 BOOST_CHECK(assigned == other);
358 BOOST_CHECK(first != assigned);
360 BOOST_CHECK(first == assigned);
369 BOOST_CHECK(lhs != rhs && lhs == lhs_copy && rhs == rhs_copy);
372 BOOST_CHECK(lhs != rhs && rhs == lhs_copy && lhs == rhs_copy);
383 cov << 1, 0, 0, 0, 1.2, 0.2, 0, 0.2, 0.7;
397 BOOST_CHECK(first == first);
398 BOOST_CHECK(not(first != first));
401 BOOST_CHECK(first != second);
402 BOOST_CHECK(not(first == second));
404 BOOST_CHECK(first == second);
408 BOOST_CHECK(first != second);
410 BOOST_CHECK(first == second);
413 BOOST_CHECK(first != second);
415 BOOST_CHECK(first == second);
418 BOOST_CHECK(first != second);
420 BOOST_CHECK(first == second);
424 BOOST_CHECK(first != second);
426 BOOST_CHECK(first == second);
428 cov(0, 0) = 2 * cov(0, 0);
430 BOOST_CHECK(first != second);
432 BOOST_CHECK(first == second);
446 phi_proj << 0, 0, 1, 0, 0, 0;
449 loc0_qop_proj << 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0;
452 loc1_theta_proj << 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0;
455 loc0_loc1_phi_proj << 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0;
458 loc0_phi_theta_qop_proj << 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0,
462 loc0_loc1_phi_theta_qop_proj << 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1,
463 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0;
466 loc0_loc1_phi_theta_qop_t_proj;
467 loc0_loc1_phi_theta_qop_t_proj << 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1,
468 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1;
476 loc0_loc1_phi_proj));
479 eBoundQOverP>::projector() == loc0_phi_theta_qop_proj));
482 loc0_loc1_phi_theta_qop_proj));
485 loc0_loc1_phi_theta_qop_t_proj));
501 const double large_number = 12443534120;
502 const double small_number = -924342675;
503 const double normal_number = 1.234;
505 std::nullopt, small_number, large_number, normal_number);
531 BOOST_CHECK(
std::abs(multiple - std::floor(multiple + 0.5)) < tol);
537 BOOST_CHECK(
std::abs(multiple - std::floor(multiple + 0.5)) < tol);
543 BOOST_CHECK(
std::abs(multiple - std::floor(multiple + 0.5)) < tol);
548 const double first_loc0 = 0.3;
549 const double first_phi = 0.9 *
M_PI;
550 const double first_theta = 0.7 *
M_PI;
552 const double second_loc0 = 2.7;
553 const double second_phi = -0.9 *
M_PI;
554 const double second_theta = 0.35 *
M_PI;
557 const double delta_loc0 = second_loc0 - first_loc0;
559 get_cyclic_difference(second_phi, first_phi, min, max);
560 const double delta_theta = second_theta - first_theta;
564 std::nullopt, first_loc0, first_phi, first_theta);
566 std::nullopt, second_loc0, second_phi, second_theta);
570 check_residuals_for_bound_parameters();
573 check_residuals_for_cyclic_parameters();
576 random_residual_tests();
591 eT>::getIndex<eBoundLoc0>() == 0));
593 eT>::getIndex<eBoundLoc1>() == 1));
595 eT>::getIndex<eBoundPhi>() == 2));
597 eT>::getIndex<eBoundQOverP>() == 3));
599 eT>::getIndex<eT>() == 4));
611 eT>::getParID<4>() ==
eT));
614 using FullSet = FullParameterSet;
615 BOOST_CHECK((FullSet::getIndex<FullSet::getParID<0>()>() == 0));
616 BOOST_CHECK((FullSet::getIndex<FullSet::getParID<1>()>() == 1));
617 BOOST_CHECK((FullSet::getIndex<FullSet::getParID<2>()>() == 2));
618 BOOST_CHECK((FullSet::getIndex<FullSet::getParID<3>()>() == 3));
619 BOOST_CHECK((FullSet::getIndex<FullSet::getParID<4>()>() == 4));
620 BOOST_CHECK((FullSet::getIndex<FullSet::getParID<5>()>() == 5));
623 (FullSet::getParID<FullSet::getIndex<eBoundLoc0>()>() ==
eBoundLoc0));
625 (FullSet::getParID<FullSet::getIndex<eBoundLoc1>()>() ==
eBoundLoc1));
627 (FullSet::getParID<FullSet::getIndex<eBoundPhi>()>() ==
eBoundPhi));
629 (FullSet::getParID<FullSet::getIndex<eBoundTheta>()>() ==
eBoundTheta));
631 (FullSet::getParID<FullSet::getIndex<eBoundQOverP>()>() ==
eBoundQOverP));
632 BOOST_CHECK((FullSet::getParID<FullSet::getIndex<eT>()>() ==
eT));
635 BOOST_CHECK((std::is_same<std::remove_cv<decltype(
638 BOOST_CHECK((std::is_same<decltype(FullSet::getParID<0>()),