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);
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);
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);
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) {
228 void free_random_residual_tests() {
230 std::default_random_engine
e;
231 std::uniform_real_distribution<float> uniform_dist(-1000, 300);
238 const unsigned int toys = 1000;
239 for (
unsigned int i = 0; i < toys; ++i) {
240 const double x1 = uniform_dist(e);
241 const double y1 = uniform_dist(e);
242 const double z1 = uniform_dist(e);
243 const double t1 = uniform_dist(e);
244 const double tx1 = uniform_dist(e);
245 const double ty1 = uniform_dist(e);
246 const double tz1 = uniform_dist(e);
247 const double qop1 = uniform_dist(e);
248 parValues_1 << x1, y1,
z1,
t1, tx1, ty1, tz1, qop1;
249 parSet_1.setParameters(parValues_1);
251 const double x2 = uniform_dist(e);
252 const double y2 = uniform_dist(e);
253 const double z2 = uniform_dist(e);
254 const double t2 = uniform_dist(e);
255 const double tx2 = uniform_dist(e);
256 const double ty2 = uniform_dist(e);
257 const double tz2 = uniform_dist(e);
258 const double qop2 = uniform_dist(e);
259 parValues_2 <<
x2, y2,
z2,
t2, tx2, ty2, tz2, qop2;
260 parSet_2.setParameters(parValues_2);
262 const double delta_x = x1 -
x2;
263 const double delta_y = y1 - y2;
264 const double delta_z = z1 -
z2;
265 const double delta_t = t1 -
t2;
266 const double delta_tx = tx1 - tx2;
267 const double delta_ty = ty1 - ty2;
268 const double delta_tz = tz1 - tz2;
269 const double delta_qop = qop1 - qop2;
270 residual = parSet_1.residual(parSet_2);
273 if (
std::abs(residual(0) - delta_x) > tol) {
277 if (
std::abs(residual(1) - delta_y) > tol) {
281 if (
std::abs(residual(2) - delta_z) > tol) {
285 if (
std::abs(residual(3) - delta_t) > tol) {
289 if (
std::abs(residual(4) - delta_tx) > tol) {
293 if (
std::abs(residual(5) - delta_ty) > tol) {
297 if (
std::abs(residual(6) - delta_tz) > tol) {
301 if (
std::abs(residual(7) - delta_qop) > tol) {
338 cov2D << 0.5, 0., 0.8, 0.;
355 cov << 1, 0, 0, 0, 1.2, 0.2, 0, 0.2, 0.7;
362 Vector3D parValues(loc0, loc1, phi);
366 cov, loc0, loc1, phi);
370 vec << loc0, loc1,
phi;
372 parSet_with_cov_vec(cov, vec);
375 BOOST_CHECK(parSet_with_cov.
size() == 3);
398 parSet_without_cov(std::nullopt, parValues);
414 double newLoc0 = 0.1;
415 double newLoc1 = 0.6;
416 double newPhi = -0.15 *
M_PI;
417 parValues << newLoc0, newLoc1, newPhi;
438 cov << 1, 0, 0, 0, 1.2, 0.2, 0, 0.2, 0.7;
445 Vector3D firstParValues(loc0, loc1, phi);
449 cov, loc0, loc1, phi);
453 BOOST_CHECK(first == copy);
458 BOOST_CHECK(first == moved);
463 BOOST_CHECK(assigned == moved);
466 std::nullopt, 0, 1.7, -0.15);
467 BOOST_CHECK(assigned != other);
469 BOOST_CHECK(assigned == other);
472 BOOST_CHECK(first != assigned);
475 BOOST_CHECK(first == assigned);
481 std::nullopt, 2 * loc0, 2 * loc1, 2 * phi);
485 BOOST_CHECK(lhs != rhs && lhs == lhs_copy && rhs == rhs_copy);
496 cov << 1, 0, 0, 0, 1.2, 0.2, 0, 0.2, 0.7;
506 cov, loc0, loc1, phi);
508 std::nullopt, 2 * loc0, 2 * loc1, 2 * phi);
511 BOOST_CHECK(first == first);
512 BOOST_CHECK(not(first != first));
515 BOOST_CHECK(first != second);
516 BOOST_CHECK(not(first == second));
518 BOOST_CHECK(first == second);
522 BOOST_CHECK(first != second);
524 BOOST_CHECK(first == second);
527 BOOST_CHECK(first != second);
529 BOOST_CHECK(first == second);
532 BOOST_CHECK(first != second);
534 BOOST_CHECK(first == second);
538 BOOST_CHECK(first != second);
540 BOOST_CHECK(first == second);
542 cov(0, 0) = 2 *
cov(0, 0);
544 BOOST_CHECK(first != second);
546 BOOST_CHECK(first == second);
561 phi_proj << 0, 0, 1, 0, 0, 0;
564 loc0_qop_proj << 1, 0, 0, 0, 0, 0,
568 loc1_theta_proj << 0, 1, 0, 0, 0, 0,
572 loc0_loc1_phi_proj << 1, 0, 0, 0, 0, 0,
577 loc0_phi_theta_qop_proj << 1, 0, 0, 0, 0, 0,
583 loc0_loc1_phi_theta_qop_proj << 1, 0, 0, 0, 0, 0,
590 loc0_loc1_phi_theta_qop_t_proj;
591 loc0_loc1_phi_theta_qop_t_proj << 1, 0, 0, 0, 0, 0,
607 eBoundPhi>::projector() == loc0_loc1_phi_proj));
610 eBoundQOverP>::projector() == loc0_phi_theta_qop_proj));
613 loc0_loc1_phi_theta_qop_proj));
617 loc0_loc1_phi_theta_qop_t_proj));
633 const double large_number = 12443534120;
634 const double small_number = -924342675;
635 const double normal_number = 1.234;
637 std::nullopt, small_number, large_number, normal_number);
663 BOOST_CHECK(
std::abs(multiple - std::floor(multiple + 0.5)) < tol);
669 BOOST_CHECK(
std::abs(multiple - std::floor(multiple + 0.5)) < tol);
675 BOOST_CHECK(
std::abs(multiple - std::floor(multiple + 0.5)) < tol);
680 const double first_loc0 = 0.3;
681 const double first_phi = 0.9 *
M_PI;
682 const double first_theta = 0.7 *
M_PI;
684 const double second_loc0 = 2.7;
685 const double second_phi = -0.9 *
M_PI;
686 const double second_theta = 0.35 *
M_PI;
689 const double delta_loc0 = second_loc0 - first_loc0;
691 get_cyclic_difference(second_phi, first_phi, min, max);
692 const double delta_theta = second_theta - first_theta;
693 Vector3D residuals(delta_loc0, delta_phi, delta_theta);
696 std::nullopt, first_loc0, first_phi, first_theta);
698 std::nullopt, second_loc0, second_phi, second_theta);
702 check_residuals_for_bound_parameters();
705 check_residuals_for_cyclic_parameters();
708 random_residual_tests();
747 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<0>()>() == 0));
748 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<1>()>() == 1));
749 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<2>()>() == 2));
750 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<3>()>() == 3));
751 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<4>()>() == 4));
752 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<5>()>() == 5));
754 BOOST_CHECK((FullSet::getParameterIndex<FullSet::getIndex<eBoundLoc0>()>() ==
756 BOOST_CHECK((FullSet::getParameterIndex<FullSet::getIndex<eBoundLoc1>()>() ==
758 BOOST_CHECK((FullSet::getParameterIndex<FullSet::getIndex<eBoundPhi>()>() ==
760 BOOST_CHECK((FullSet::getParameterIndex<FullSet::getIndex<eBoundTheta>()>() ==
763 (FullSet::getParameterIndex<FullSet::getIndex<eBoundQOverP>()>() ==
765 BOOST_CHECK((FullSet::getParameterIndex<FullSet::getIndex<eBoundTime>()>() ==
770 (std::is_same<std::remove_cv<decltype(
773 BOOST_CHECK((std::is_same<decltype(FullSet::getParameterIndex<0>()),
796 cov << 1, 0, 0, 0, 1.2, 0.2, 0, 0.2, 0.7;
809 BOOST_CHECK(parSet_with_cov.
size() == 3);
834 std::nullopt, parValues);
853 parValues << newX, newY, newZ;
874 cov << 1, 0, 0, 0, 1.2, 0.2, 0, 0.2, 0.7;
888 BOOST_CHECK(first == copy);
893 BOOST_CHECK(first == moved);
897 BOOST_CHECK(assigned == moved);
900 std::nullopt, 0, 1.7, -0.15);
901 BOOST_CHECK(assigned != other);
903 BOOST_CHECK(assigned == other);
906 BOOST_CHECK(first != assigned);
908 BOOST_CHECK(first == assigned);
913 std::nullopt, 2 * x, 2 * y, 2 * z);
917 BOOST_CHECK(lhs != rhs && lhs == lhs_copy && rhs == rhs_copy);
928 cov << 1, 0, 0, 0, 1.2, 0.2, 0, 0.2, 0.7;
939 std::nullopt, 2 * x, 2 * y, 2 * z);
942 BOOST_CHECK(first == first);
943 BOOST_CHECK(not(first != first));
946 BOOST_CHECK(first != second);
947 BOOST_CHECK(not(first == second));
949 BOOST_CHECK(first == second);
953 BOOST_CHECK(first != second);
955 BOOST_CHECK(first == second);
958 BOOST_CHECK(first != second);
960 BOOST_CHECK(first == second);
963 BOOST_CHECK(first != second);
965 BOOST_CHECK(first == second);
969 BOOST_CHECK(first != second);
971 BOOST_CHECK(first == second);
973 cov(0, 0) = 2 *
cov(0, 0);
975 BOOST_CHECK(first != second);
977 BOOST_CHECK(first == second);
992 z_proj << 0, 0, 1, 0, 0, 0, 0, 0;
995 x_qop_proj << 1, 0, 0, 0, 0, 0, 0, 0,
996 0, 0, 0, 0, 0, 0, 0, 1;
999 y_tz_proj << 0, 1, 0, 0, 0, 0, 0, 0,
1000 0, 0, 0, 0, 0, 0, 1, 0;
1003 x_y_z_proj << 1, 0, 0, 0, 0, 0, 0, 0,
1004 0, 1, 0, 0, 0, 0, 0, 0,
1005 0, 0, 1, 0, 0, 0, 0, 0;
1008 x_z_tz_qop_proj << 1, 0, 0, 0, 0, 0, 0, 0,
1009 0, 0, 1, 0, 0, 0, 0, 0,
1010 0, 0, 0, 0, 0, 0, 1, 0,
1011 0, 0, 0, 0, 0, 0, 0, 1;
1014 x_y_z_tz_qop_proj << 1, 0, 0, 0, 0, 0, 0, 0,
1015 0, 1, 0, 0, 0, 0, 0, 0,
1016 0, 0, 1, 0, 0, 0, 0, 0,
1017 0, 0, 0, 0, 0, 0, 1, 0,
1018 0, 0, 0, 0, 0, 0, 0, 1;
1021 x_y_z_t_tz_qop_proj << 1, 0, 0, 0, 0, 0, 0, 0,
1022 0, 1, 0, 0, 0, 0, 0, 0,
1023 0, 0, 1, 0, 0, 0, 0, 0,
1024 0, 0, 0, 1, 0, 0, 0, 0,
1025 0, 0, 0, 0, 0, 0, 1, 0,
1026 0, 0, 0, 0, 0, 0, 0, 1;
1029 x_y_z_t_ty_tz_qop_proj << 1, 0, 0, 0, 0, 0, 0, 0,
1030 0, 1, 0, 0, 0, 0, 0, 0,
1031 0, 0, 1, 0, 0, 0, 0, 0,
1032 0, 0, 0, 1, 0, 0, 0, 0,
1033 0, 0, 0, 0, 0, 1, 0, 0,
1034 0, 0, 0, 0, 0, 0, 1, 0,
1035 0, 0, 0, 0, 0, 0, 0, 1;
1038 x_y_z_t_tx_ty_tz_qop_proj;
1039 x_y_z_t_tx_ty_tz_qop_proj << 1, 0, 0, 0, 0, 0, 0, 0,
1040 0, 1, 0, 0, 0, 0, 0, 0,
1041 0, 0, 1, 0, 0, 0, 0, 0,
1042 0, 0, 0, 1, 0, 0, 0, 0,
1043 0, 0, 0, 0, 1, 0, 0, 0,
1044 0, 0, 0, 0, 0, 1, 0, 0,
1045 0, 0, 0, 0, 0, 0, 1, 0,
1046 0, 0, 0, 0, 0, 0, 0, 1;
1064 x_y_z_t_tz_qop_proj));
1068 x_y_z_t_ty_tz_qop_proj));
1072 x_y_z_t_tx_ty_tz_qop_proj));
1087 const double large_number = 12443534120;
1088 const double small_number = -924342675;
1089 const double normal_number = 0.1234;
1091 std::nullopt, small_number, large_number, normal_number);
1098 const double first_x = 0.3;
1099 const double first_y = 0.9;
1100 const double first_z = 0.7;
1102 const double second_x = 2.7;
1103 const double second_y = -0.9;
1104 const double second_z = 0.35;
1107 const double delta_x = second_x - first_x;
1108 const double delta_y = second_y - first_y;
1109 const double delta_z = second_z - first_z;
1110 Vector3D residuals(delta_x, delta_y, delta_z);
1113 std::nullopt, first_x, first_y, first_z);
1115 std::nullopt, second_x, second_y, second_z);
1119 free_random_residual_tests();
1202 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<0>()>() == 0));
1203 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<1>()>() == 1));
1204 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<2>()>() == 2));
1205 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<3>()>() == 3));
1206 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<4>()>() == 4));
1207 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<5>()>() == 5));
1208 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<6>()>() == 6));
1209 BOOST_CHECK((FullSet::getIndex<FullSet::getParameterIndex<7>()>() == 7));
1211 BOOST_CHECK((FullSet::getParameterIndex<FullSet::getIndex<eFreePos0>()>() ==
1213 BOOST_CHECK((FullSet::getParameterIndex<FullSet::getIndex<eFreePos1>()>() ==
1215 BOOST_CHECK((FullSet::getParameterIndex<FullSet::getIndex<eFreePos2>()>() ==
1217 BOOST_CHECK((FullSet::getParameterIndex<FullSet::getIndex<eFreeTime>()>() ==
1219 BOOST_CHECK((FullSet::getParameterIndex<FullSet::getIndex<eFreeDir0>()>() ==
1221 BOOST_CHECK((FullSet::getParameterIndex<FullSet::getIndex<eFreeDir1>()>() ==
1223 BOOST_CHECK((FullSet::getParameterIndex<FullSet::getIndex<eFreeDir2>()>() ==
1225 BOOST_CHECK((FullSet::getParameterIndex<FullSet::getIndex<eFreeQOverP>()>() ==
1230 (std::is_same<std::remove_cv<decltype(
1233 BOOST_CHECK((std::is_same<decltype(FullSet::getParameterIndex<0>()),