File indexing completed on 2025-10-15 08:05:45
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/tools/output_test_stream.hpp>
0010 #include <boost/test/unit_test.hpp>
0011
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Surfaces/ConeBounds.hpp"
0014 #include "Acts/Surfaces/SurfaceBounds.hpp"
0015 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0016
0017 #include <algorithm>
0018 #include <array>
0019 #include <cmath>
0020 #include <numbers>
0021 #include <stdexcept>
0022 #include <vector>
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 using namespace Acts;
0035
0036 namespace ActsTests {
0037
0038 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0039
0040 const double alpha = std::numbers::pi / 8.;
0041 const double zMin = 3.;
0042 const double zMax = 6.;
0043 const double halfPhi = std::numbers::pi / 4.;
0044 const double averagePhi = 0.;
0045 const bool symmetric = false;
0046
0047
0048 BOOST_AUTO_TEST_CASE(ConeBoundsConstruction) {
0049
0050
0051
0052 BOOST_TEST_CHECKPOINT("Four parameter constructor (last two at default)");
0053 ConeBounds defaultConeBounds(alpha, symmetric);
0054 BOOST_CHECK_EQUAL(defaultConeBounds.type(), SurfaceBounds::eCone);
0055
0056 BOOST_TEST_CHECKPOINT("Four parameter constructor");
0057 ConeBounds fourParameterConstructed(alpha, symmetric, halfPhi, averagePhi);
0058 BOOST_CHECK_EQUAL(fourParameterConstructed.type(), SurfaceBounds::eCone);
0059
0060 BOOST_TEST_CHECKPOINT("Five parameter constructor (last two at default)");
0061 ConeBounds defaulted5ParamConeBounds(alpha, zMin, zMax);
0062 BOOST_CHECK_EQUAL(defaulted5ParamConeBounds.type(), SurfaceBounds::eCone);
0063
0064 BOOST_TEST_CHECKPOINT("Five parameter constructor)");
0065 ConeBounds fiveParamConstructedConeBounds(alpha, zMin, zMax, halfPhi,
0066 averagePhi);
0067 BOOST_CHECK_EQUAL(fiveParamConstructedConeBounds.type(),
0068 SurfaceBounds::eCone);
0069
0070 BOOST_TEST_CHECKPOINT("Copy constructor");
0071 ConeBounds copyConstructedConeBounds(fiveParamConstructedConeBounds);
0072 BOOST_CHECK_EQUAL(copyConstructedConeBounds, fiveParamConstructedConeBounds);
0073 }
0074
0075
0076 BOOST_AUTO_TEST_CASE(ConeBoundsRecreation) {
0077 ConeBounds original(alpha, zMin, zMax, halfPhi, averagePhi);
0078 auto valvector = original.values();
0079 std::array<double, ConeBounds::eSize> values{};
0080 std::copy_n(valvector.begin(), ConeBounds::eSize, values.begin());
0081 ConeBounds recreated(values);
0082
0083 BOOST_CHECK_EQUAL(recreated, original);
0084 }
0085
0086
0087 BOOST_AUTO_TEST_CASE(ConeBoundsExceptions) {
0088
0089 BOOST_CHECK_THROW(ConeBounds(-alpha, zMin, zMax, halfPhi, averagePhi),
0090 std::logic_error);
0091
0092
0093 BOOST_CHECK_THROW(
0094 ConeBounds(std::numbers::pi, zMin, zMax, halfPhi, averagePhi),
0095 std::logic_error);
0096
0097
0098 BOOST_CHECK_THROW(ConeBounds(alpha, zMax, zMin, halfPhi, averagePhi),
0099 std::logic_error);
0100
0101
0102 BOOST_CHECK_THROW(ConeBounds(alpha, zMin, zMax, -halfPhi, averagePhi),
0103 std::logic_error);
0104
0105
0106 BOOST_CHECK_THROW(
0107 ConeBounds(alpha, zMin, zMax, halfPhi, 2 * std::numbers::pi),
0108 std::logic_error);
0109 }
0110
0111
0112 BOOST_AUTO_TEST_CASE(ConeBoundsProperties) {
0113 const Vector2 origin(0, 0);
0114 const Vector2 somewhere(4., 4.);
0115 ConeBounds coneBoundsObject(alpha, zMin, zMax, halfPhi, averagePhi);
0116
0117
0118 BOOST_CHECK_EQUAL(coneBoundsObject.type(), SurfaceBounds::eCone);
0119
0120
0121 BOOST_CHECK(!coneBoundsObject.inside(origin));
0122
0123
0124 CHECK_CLOSE_REL(coneBoundsObject.r(zMin), zMin * std::tan(alpha), 1e-6);
0125
0126
0127 CHECK_CLOSE_REL(coneBoundsObject.tanAlpha(), std::tan(alpha), 1e-6);
0128
0129
0130 CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eAlpha), alpha, 1e-6);
0131
0132
0133 CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eMinZ), zMin, 1e-6);
0134
0135
0136 CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eMaxZ), zMax, 1e-6);
0137
0138
0139 CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eHalfPhiSector), halfPhi,
0140 1e-6);
0141
0142
0143 boost::test_tools::output_test_stream dumpOutput;
0144 coneBoundsObject.toStream(dumpOutput);
0145 BOOST_CHECK(dumpOutput.is_equal(
0146 "Acts::ConeBounds: (tanAlpha, minZ, maxZ, halfPhiSector, averagePhi) = "
0147 "(0.4142136, 3.0000000, 6.0000000, 0.7853982, 0.0000000)"));
0148 }
0149
0150
0151 BOOST_AUTO_TEST_CASE(ConeBoundsAssignment) {
0152 ConeBounds originalConeBounds(alpha, zMin, zMax, halfPhi, averagePhi);
0153 ConeBounds assignedConeBounds(0.1, 2.3, 4.5, 1.2, 2.1);
0154 assignedConeBounds = originalConeBounds;
0155
0156 BOOST_CHECK_EQUAL(assignedConeBounds, originalConeBounds);
0157 }
0158
0159 BOOST_AUTO_TEST_CASE(ConeBoundsCenter) {
0160
0161 ConeBounds cone(alpha, zMin, zMax, halfPhi, averagePhi);
0162 Vector2 center = cone.center();
0163
0164 double expectedZ = 0.5 * (zMin + zMax);
0165 BOOST_CHECK_EQUAL(center.x(), averagePhi);
0166 BOOST_CHECK_EQUAL(center.y(), expectedZ);
0167
0168
0169 const double avgPhiOffset = std::numbers::pi / 6.;
0170 ConeBounds coneOffset(alpha, zMin, zMax, halfPhi, avgPhiOffset);
0171 Vector2 centerOffset = coneOffset.center();
0172 BOOST_CHECK_EQUAL(centerOffset.x(), avgPhiOffset);
0173 BOOST_CHECK_EQUAL(centerOffset.y(), expectedZ);
0174 }
0175
0176 BOOST_AUTO_TEST_SUITE_END()
0177
0178 }