File indexing completed on 2025-01-18 09:12:38
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/Definitions/Units.hpp"
0013 #include "Acts/Geometry/Extent.hpp"
0014 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0015 #include "Acts/Utilities/BinningType.hpp"
0016
0017 #include <array>
0018 #include <cmath>
0019 #include <string>
0020 #include <vector>
0021
0022 using namespace Acts::UnitLiterals;
0023
0024 namespace Acts::Test {
0025
0026 BOOST_AUTO_TEST_SUITE(Geometry)
0027
0028
0029 BOOST_AUTO_TEST_CASE(ExtentTest) {
0030 std::vector<Vector3> vertices = {
0031 Vector3(15_mm, -3_mm, -10_mm), Vector3(18_mm, 0_mm, -10_mm),
0032 Vector3(15_mm, 3_mm, -10_mm), Vector3(15_mm, -3_mm, 10_mm),
0033 Vector3(18_mm, 0_mm, 10_mm), Vector3(15_mm, 3_mm, 10_mm)};
0034
0035
0036 Extent gExt;
0037 for (const auto& v : vertices) {
0038 gExt.extend(v);
0039 }
0040
0041 double phiMin = std::atan2(-3_mm, 15_mm);
0042 double phiMax = std::atan2(3_mm, 15_mm);
0043 double rMin = std::hypot(15_mm, 3_mm);
0044
0045 CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisX), 15_mm, 1e-6);
0046 CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisX), 18_mm, 1e-6);
0047 CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisY), -3_mm, 1e-6);
0048 CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisY), 3_mm, 1e-6);
0049 CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisZ), -10_mm, 1e-6);
0050 CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisZ), 10_mm, 1e-6);
0051 CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisR), rMin, 1e-6);
0052 CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisR), 18_mm, 1e-6);
0053 CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisPhi), phiMin, 1e-6);
0054 CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisPhi), phiMax, 1e-6);
0055
0056
0057 Extent gExtHist;
0058 for (const auto& v : vertices) {
0059 gExtHist.extend(v, {AxisDirection::AxisX}, false, true);
0060 }
0061 const auto& vHist = gExtHist.valueHistograms();
0062 auto xVals = vHist[toUnderlying(AxisDirection::AxisX)];
0063
0064 BOOST_CHECK_EQUAL(xVals.size(), 6u);
0065 std::vector<double> reference = {15_mm, 18_mm, 15_mm, 15_mm, 18_mm, 15_mm};
0066 BOOST_CHECK(xVals == reference);
0067
0068
0069 Extent gExtItr;
0070 gExtItr.extend(vertices.begin(), vertices.end());
0071 CHECK_CLOSE_ABS(gExtItr.min(AxisDirection::AxisX), 15_mm, 1e-6);
0072 CHECK_CLOSE_ABS(gExtItr.max(AxisDirection::AxisX), 18_mm, 1e-6);
0073 CHECK_CLOSE_ABS(gExtItr.min(AxisDirection::AxisY), -3_mm, 1e-6);
0074 CHECK_CLOSE_ABS(gExtItr.max(AxisDirection::AxisY), 3_mm, 1e-6);
0075 CHECK_CLOSE_ABS(gExtItr.min(AxisDirection::AxisZ), -10_mm, 1e-6);
0076 CHECK_CLOSE_ABS(gExtItr.max(AxisDirection::AxisZ), 10_mm, 1e-6);
0077 CHECK_CLOSE_ABS(gExtItr.min(AxisDirection::AxisR), rMin, 1e-6);
0078 CHECK_CLOSE_ABS(gExtItr.max(AxisDirection::AxisR), 18_mm, 1e-6);
0079 CHECK_CLOSE_ABS(gExtItr.min(AxisDirection::AxisPhi), phiMin, 1e-6);
0080 CHECK_CLOSE_ABS(gExtItr.max(AxisDirection::AxisPhi), phiMax, 1e-6);
0081
0082
0083 Extent gExtCopy;
0084 gExtCopy.extend(gExt);
0085
0086 CHECK_CLOSE_ABS(gExtCopy.min(AxisDirection::AxisX), 15_mm, 1e-6);
0087 CHECK_CLOSE_ABS(gExtCopy.max(AxisDirection::AxisX), 18_mm, 1e-6);
0088 CHECK_CLOSE_ABS(gExtCopy.min(AxisDirection::AxisY), -3_mm, 1e-6);
0089 CHECK_CLOSE_ABS(gExtCopy.max(AxisDirection::AxisY), 3_mm, 1e-6);
0090 CHECK_CLOSE_ABS(gExtCopy.min(AxisDirection::AxisZ), -10_mm, 1e-6);
0091 CHECK_CLOSE_ABS(gExtCopy.max(AxisDirection::AxisZ), 10_mm, 1e-6);
0092 CHECK_CLOSE_ABS(gExtCopy.min(AxisDirection::AxisR), rMin, 1e-6);
0093 CHECK_CLOSE_ABS(gExtCopy.max(AxisDirection::AxisR), 18_mm, 1e-6);
0094 CHECK_CLOSE_ABS(gExtCopy.min(AxisDirection::AxisPhi), phiMin, 1e-6);
0095 CHECK_CLOSE_ABS(gExtCopy.max(AxisDirection::AxisPhi), phiMax, 1e-6);
0096
0097
0098 Extent unbound;
0099 BOOST_CHECK(unbound.contains(gExt));
0100 BOOST_CHECK(unbound.contains(gExtCopy));
0101
0102
0103 ExtentEnvelope xEnvelopes = ExtentEnvelope::Zero();
0104 xEnvelopes[AxisDirection::AxisX] = {1., 2.};
0105
0106
0107 Extent envelope(xEnvelopes);
0108 gExt.extend(envelope);
0109
0110 CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisX), 14_mm, 1e-6);
0111 CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisX), 20_mm, 1e-6);
0112
0113 CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisY), -3_mm, 1e-6);
0114 CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisY), 3_mm, 1e-6);
0115 CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisZ), -10_mm, 1e-6);
0116 CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisZ), 10_mm, 1e-6);
0117 CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisR), rMin, 1e-6);
0118 CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisR), 18_mm, 1e-6);
0119 CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisPhi), phiMin, 1e-6);
0120 CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisPhi), phiMax, 1e-6);
0121
0122
0123 Extent gExtEnv(envelope);
0124 gExtEnv.extend(vertices.begin(), vertices.end());
0125
0126 CHECK_CLOSE_ABS(gExtEnv.min(AxisDirection::AxisX), 14_mm, 1e-6);
0127 CHECK_CLOSE_ABS(gExtEnv.max(AxisDirection::AxisX), 20_mm, 1e-6);
0128
0129
0130 gExt.set(AxisDirection::AxisX, 2_mm, 8_mm);
0131 CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisX), 2_mm, 1e-6);
0132 CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisX), 8_mm, 1e-6);
0133
0134
0135 gExt.set(AxisDirection::AxisR, -2_mm, 18_mm);
0136 CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisR), 0_mm, 1e-6);
0137 CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisR), 18_mm, 1e-6);
0138
0139
0140 Extent gExtConst;
0141 gExtConst.set(AxisDirection::AxisR, 0., 5.);
0142 Extent gExtNonConst;
0143 BOOST_CHECK(!gExtNonConst.constrains(AxisDirection::AxisR));
0144 gExtNonConst.addConstrain(gExtConst);
0145 BOOST_CHECK(gExtNonConst.constrains(AxisDirection::AxisR));
0146
0147 std::string tString = gExtConst.toString();
0148 BOOST_CHECK(!tString.empty());
0149
0150
0151 Extent gExtVertexCheck;
0152 gExtVertexCheck.set(AxisDirection::AxisR, 0., 5.);
0153 BOOST_CHECK(gExtVertexCheck.contains(Vector3(1., 0., 0.)));
0154 BOOST_CHECK(!gExtVertexCheck.contains(Vector3(6., 0., 0.)));
0155 }
0156
0157
0158
0159 BOOST_AUTO_TEST_CASE(ProtoSupportCaseTests) {
0160 std::vector<Vector3> vertices = {
0161 Vector3(15_mm, -3_mm, -10_mm), Vector3(18_mm, 0_mm, -10_mm),
0162 Vector3(15_mm, 3_mm, -10_mm), Vector3(15_mm, -3_mm, 10_mm),
0163 Vector3(18_mm, 0_mm, 10_mm), Vector3(15_mm, 3_mm, 10_mm)};
0164
0165 Extent volumeExtent;
0166 volumeExtent.set(AxisDirection::AxisZ, -300_mm, 300_mm);
0167
0168 BOOST_CHECK(volumeExtent.constrains(AxisDirection::AxisZ));
0169 BOOST_CHECK(!volumeExtent.constrains(AxisDirection::AxisR));
0170
0171 for (const auto& v : vertices) {
0172 volumeExtent.extend(v, {AxisDirection::AxisR});
0173 }
0174
0175 BOOST_CHECK(volumeExtent.constrains(AxisDirection::AxisR));
0176 }
0177
0178 BOOST_AUTO_TEST_CASE(DesignatedInitializers) {
0179 using enum AxisDirection;
0180 ExtentEnvelope exp;
0181 exp[AxisX] = {1., 2.};
0182 exp[AxisEta] = {-1., 1.};
0183
0184 ExtentEnvelope act{{.x = {1., 2.}, .eta = {-1., 1.}}};
0185
0186 BOOST_CHECK(exp == act);
0187 }
0188
0189 BOOST_AUTO_TEST_SUITE_END()
0190
0191 }