File indexing completed on 2025-01-18 09:12:56
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Utilities/BinUtility.hpp"
0013 #include "Acts/Utilities/BinningType.hpp"
0014
0015 #include <array>
0016 #include <cmath>
0017 #include <cstddef>
0018 #include <numbers>
0019 #include <utility>
0020 #include <vector>
0021
0022 namespace Acts::Test {
0023
0024
0025 BOOST_AUTO_TEST_CASE(BinUtility_equidistant_binning) {
0026 Vector3 xyzPosition(1.5, 2.5, 3.5);
0027 Vector3 edgePosition(0.5, 0.5, 0.5);
0028
0029
0030 BinUtility xUtil_eq(10, 0., 10., open, AxisDirection::AxisX);
0031 BinUtility yUtil_eq(10, 0., 10., open, AxisDirection::AxisY);
0032 BinUtility zUtil_eq(10, 0., 10., open, AxisDirection::AxisZ);
0033 BOOST_CHECK_EQUAL(xUtil_eq.bins(), std::size_t{10});
0034
0035 BinUtility xyUtil_eq(10, 0., 10., open, AxisDirection::AxisX);
0036 xyUtil_eq += yUtil_eq;
0037 BOOST_CHECK_EQUAL(xyUtil_eq.bins(), 100u);
0038
0039 BinUtility xyzUtil_eq(xyUtil_eq);
0040 xyzUtil_eq += zUtil_eq;
0041 BOOST_CHECK_EQUAL(xyzUtil_eq.bins(), 1000u);
0042
0043 BOOST_CHECK_EQUAL(xUtil_eq.dimensions(), 1u);
0044 BOOST_CHECK_EQUAL(xyUtil_eq.dimensions(), 2u);
0045 BOOST_CHECK_EQUAL(xyzUtil_eq.dimensions(), 3u);
0046
0047
0048 BinUtility xUtil_eq_copy(10, 0., 10., open, AxisDirection::AxisX);
0049 BOOST_CHECK_EQUAL(xUtil_eq_copy, xUtil_eq);
0050 BOOST_CHECK_NE(yUtil_eq, xUtil_eq);
0051
0052
0053 auto xTriple = xUtil_eq.binTriple(xyzPosition);
0054 auto xyTriple = xyUtil_eq.binTriple(xyzPosition);
0055 auto xyzTriple = xyzUtil_eq.binTriple(xyzPosition);
0056
0057 BOOST_CHECK_EQUAL(xTriple[0], 1u);
0058 BOOST_CHECK_EQUAL(xTriple[1], 0u);
0059 BOOST_CHECK_EQUAL(xTriple[2], 0u);
0060
0061 BOOST_CHECK_EQUAL(xyTriple[0], 1u);
0062 BOOST_CHECK_EQUAL(xyTriple[1], 2u);
0063 BOOST_CHECK_EQUAL(xyTriple[2], 0u);
0064
0065 BOOST_CHECK_EQUAL(xyzTriple[0], 1u);
0066 BOOST_CHECK_EQUAL(xyzTriple[1], 2u);
0067 BOOST_CHECK_EQUAL(xyzTriple[2], 3u);
0068 }
0069
0070
0071 BOOST_AUTO_TEST_CASE(BinUtility_arbitrary_binning) {
0072 std::vector<float> bvalues = {-5., 0., 1., 1.1, 8.};
0073 BinUtility xUtil(bvalues, Acts::open, Acts::AxisDirection::AxisX);
0074
0075
0076 BOOST_CHECK_EQUAL(xUtil.bin(Vector3(-6., 0., 0.)), 0u);
0077
0078 BOOST_CHECK_EQUAL(xUtil.bin(Vector3(-4., 0., 0.)), 0u);
0079
0080 BOOST_CHECK_EQUAL(xUtil.bin(Vector3(0.5, 0., 0.)), 1u);
0081
0082 BOOST_CHECK_EQUAL(xUtil.bin(Vector3(1.05, 0., 0.)), 2u);
0083
0084 BOOST_CHECK_EQUAL(xUtil.bin(Vector3(4., 0., 0.)), 3u);
0085
0086 BOOST_CHECK_EQUAL(xUtil.bin(Vector3(9., 0., 0.)), 3u);
0087 }
0088
0089
0090 BOOST_AUTO_TEST_CASE(BinUtility_transform) {
0091 Transform3 transform_LtoG = Transform3::Identity();
0092 transform_LtoG = transform_LtoG * Translation3(0., 0., -50);
0093 transform_LtoG =
0094 transform_LtoG * AngleAxis3(std::numbers::pi / 4., Vector3(0, 0, 1));
0095
0096 Transform3 transform_GtoL = transform_LtoG.inverse();
0097
0098 BinUtility rUtil(10, 0., 100., open, AxisDirection::AxisR);
0099 BinUtility phiUtil(10, -std::numbers::pi, std::numbers::pi, closed,
0100 AxisDirection::AxisPhi);
0101 BinUtility zUtil(10, -100., 100., open, AxisDirection::AxisZ);
0102
0103 BinUtility noTranform;
0104 noTranform += rUtil;
0105 noTranform += phiUtil;
0106 noTranform += zUtil;
0107
0108 BinUtility withTranform(transform_LtoG);
0109 withTranform += rUtil;
0110 withTranform += phiUtil;
0111 withTranform += zUtil;
0112
0113 Vector3 pos1(0, 0, 0);
0114 Vector3 pos2(60, 0, 0);
0115 Vector3 pos3(34, std::numbers::pi / 2., 0);
0116 Vector3 pos4(0, 0, -80);
0117 Vector3 pos5(80, -std::numbers::pi / 4., 50);
0118
0119 for (int i = 0; i < 3; i++) {
0120 BOOST_CHECK_EQUAL(withTranform.bin(pos1, i),
0121 noTranform.bin(transform_GtoL * pos1, i));
0122 BOOST_CHECK_EQUAL(withTranform.bin(pos2, i),
0123 noTranform.bin(transform_GtoL * pos2, i));
0124 BOOST_CHECK_EQUAL(withTranform.bin(pos3, i),
0125 noTranform.bin(transform_GtoL * pos3, i));
0126 BOOST_CHECK_EQUAL(withTranform.bin(pos4, i),
0127 noTranform.bin(transform_GtoL * pos4, i));
0128 BOOST_CHECK_EQUAL(withTranform.bin(pos5, i),
0129 noTranform.bin(transform_GtoL * pos5, i));
0130 }
0131 }
0132
0133 }