File indexing completed on 2025-10-28 07:55:13
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/Detector/DetectorVolume.hpp"
0013 #include "Acts/Detector/PortalGenerators.hpp"
0014 #include "Acts/Detector/detail/CuboidalDetectorHelper.hpp"
0015 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0016 #include "Acts/Geometry/GeometryContext.hpp"
0017 #include "Acts/Navigation/InternalNavigation.hpp"
0018 #include "Acts/Utilities/BinningData.hpp"
0019 #include "Acts/Utilities/StringHelpers.hpp"
0020 #include "Acts/Visualization/GeometryView3D.hpp"
0021 #include "Acts/Visualization/ObjVisualization3D.hpp"
0022
0023 #include <array>
0024 #include <memory>
0025 #include <stdexcept>
0026
0027 using namespace Acts;
0028
0029 auto portalGenerator = Experimental::defaultPortalGenerator();
0030 auto tContext = GeometryContext();
0031
0032 namespace ActsTests {
0033
0034 BOOST_AUTO_TEST_SUITE(DetectorSuite)
0035
0036 BOOST_AUTO_TEST_CASE(CubicVolumeExceptions) {
0037
0038 auto box = std::make_shared<CuboidVolumeBounds>(10, 10, 10);
0039
0040
0041 auto volumeA = Experimental::DetectorVolumeFactory::construct(
0042 portalGenerator, tContext, "VolumeA", Transform3::Identity(), box,
0043 Experimental::tryAllPortals());
0044
0045
0046 auto transformB = Transform3::Identity();
0047 transformB.prerotate(AngleAxis3(0.234, Vector3::UnitZ()));
0048
0049 auto volumeB = Experimental::DetectorVolumeFactory::construct(
0050 portalGenerator, tContext, "volumeB", transformB, box,
0051 Experimental::tryAllPortals());
0052
0053 std::vector<std::shared_ptr<Experimental::DetectorVolume>> volumes = {
0054 volumeA, volumeB};
0055
0056 BOOST_CHECK_THROW(
0057 Experimental::detail::CuboidalDetectorHelper::connect(
0058 tContext, volumes, AxisDirection::AxisX, {}, Logging::VERBOSE),
0059 std::invalid_argument);
0060 }
0061
0062 BOOST_AUTO_TEST_CASE(SimpleBoxConnection) {
0063 std::array<AxisDirection, 3> binningValues = {
0064 AxisDirection::AxisX, AxisDirection::AxisY, AxisDirection::AxisZ};
0065 for (auto bVal : binningValues) {
0066
0067 auto box = std::make_shared<CuboidVolumeBounds>(10, 10, 10);
0068
0069
0070 auto volumeA = Experimental::DetectorVolumeFactory::construct(
0071 portalGenerator, tContext, "VolumeA", Transform3::Identity(), box,
0072 Experimental::tryAllPortals());
0073
0074
0075 auto transformB = Transform3::Identity();
0076
0077 Vector3 translation = Vector3::Zero();
0078 translation[toUnderlying(bVal)] = 20;
0079 transformB.pretranslate(translation);
0080
0081 auto volumeB = Experimental::DetectorVolumeFactory::construct(
0082 portalGenerator, tContext, "VolumeB", transformB, box,
0083 Experimental::tryAllPortals());
0084
0085 std::vector<std::shared_ptr<Experimental::DetectorVolume>> volumes = {
0086 volumeA, volumeB};
0087 auto container = Experimental::detail::CuboidalDetectorHelper::connect(
0088 tContext, volumes, bVal, {}, Logging::VERBOSE);
0089
0090
0091 BOOST_CHECK(!container.empty());
0092
0093 ObjVisualization3D obj;
0094 GeometryView3D::drawDetectorVolume(obj, *volumeA, tContext);
0095 GeometryView3D::drawDetectorVolume(obj, *volumeB, tContext);
0096 obj.write("ConnectectBoxesRegular_" + axisDirectionName(bVal) + ".obj");
0097 }
0098 }
0099
0100 BOOST_AUTO_TEST_CASE(IrregularBoxConnectionInZ) {
0101 std::vector<AxisDirection> binningValues = {
0102 AxisDirection::AxisX, AxisDirection::AxisY, AxisDirection::AxisZ};
0103
0104 using HlPos = std::array<double, 2u>;
0105 using VolHlPos = std::array<HlPos, 3u>;
0106 using VolSetup = std::array<VolHlPos, 3u>;
0107
0108 VolHlPos cPA = {{{10., 0.}, {10., 0.}, {10., 0.}}};
0109 VolHlPos cPB = {{{20., 0.}, {20., 0.}, {20., 0.}}};
0110 VolHlPos sP = {{{10., -30.}, {30., 10.}, {90., 130.}}};
0111
0112 std::array<VolSetup, 3u> volSetups = {
0113 {{sP, cPA, cPB}, {cPB, sP, cPA}, {cPA, cPB, sP}}};
0114
0115 std::array<Transform3, 2u> transforms = {
0116 Transform3::Identity(),
0117 Transform3{Transform3::Identity()}.prerotate(
0118 AngleAxis3(0.34, Vector3(1., 1., 1.).normalized()))};
0119
0120
0121 for (auto [it, t] : enumerate(transforms)) {
0122 std::string trstr = it == 0 ? "" : "_rotated";
0123 auto rotation = t.rotation();
0124
0125 for (auto bVal : binningValues) {
0126 auto [vsA, vsB, vsC] = volSetups[toUnderlying(bVal)];
0127
0128
0129 auto boxA =
0130 std::make_shared<CuboidVolumeBounds>(vsA[0][0], vsB[0][0], vsC[0][0]);
0131 auto boxB =
0132 std::make_shared<CuboidVolumeBounds>(vsA[1][0], vsB[1][0], vsC[1][0]);
0133 auto boxC =
0134 std::make_shared<CuboidVolumeBounds>(vsA[2][0], vsB[2][0], vsC[2][0]);
0135
0136 auto transformA = Transform3::Identity();
0137 auto transformB = Transform3::Identity();
0138 auto transformC = Transform3::Identity();
0139
0140 transformA.pretranslate(Vector3(vsA[0][1], vsB[0][1], vsC[0][1]));
0141 transformB.pretranslate(Vector3(vsA[1][1], vsB[1][1], vsC[1][1]));
0142 transformC.pretranslate(Vector3(vsA[2][1], vsB[2][1], vsC[2][1]));
0143
0144 transformA.prerotate(rotation);
0145 transformB.prerotate(rotation);
0146 transformC.prerotate(rotation);
0147
0148
0149 auto volumeA = Experimental::DetectorVolumeFactory::construct(
0150 portalGenerator, tContext, "VolumeA", transformA, boxA,
0151 Experimental::tryAllPortals());
0152 auto volumeB = Experimental::DetectorVolumeFactory::construct(
0153 portalGenerator, tContext, "VolumeB", transformB, boxB,
0154 Experimental::tryAllPortals());
0155 auto volumeC = Experimental::DetectorVolumeFactory::construct(
0156 portalGenerator, tContext, "VolumeC", transformC, boxC,
0157 Experimental::tryAllPortals());
0158
0159
0160 std::vector<std::shared_ptr<Experimental::DetectorVolume>> volumes = {
0161 volumeA, volumeB, volumeC};
0162 auto container = Experimental::detail::CuboidalDetectorHelper::connect(
0163 tContext, volumes, bVal, {}, Logging::VERBOSE);
0164
0165
0166 BOOST_CHECK(!container.empty());
0167
0168 ObjVisualization3D obj;
0169 GeometryView3D::drawDetectorVolume(obj, *volumeA, tContext);
0170 GeometryView3D::drawDetectorVolume(obj, *volumeB, tContext);
0171 GeometryView3D::drawDetectorVolume(obj, *volumeC, tContext);
0172 obj.write("ConnectectBoxesIrregular_" + axisDirectionName(bVal) + trstr +
0173 ".obj");
0174 }
0175 }
0176 }
0177
0178 BOOST_AUTO_TEST_CASE(ContainerConnection) {
0179
0180 auto box = std::make_shared<CuboidVolumeBounds>(10, 10, 10);
0181
0182
0183
0184
0185 auto volumeA = Experimental::DetectorVolumeFactory::construct(
0186 portalGenerator, tContext, "VolumeA", Transform3::Identity(), box,
0187 Experimental::tryAllPortals());
0188
0189
0190 auto transformB = Transform3::Identity();
0191 Vector3 translationB = Vector3::Zero();
0192 translationB[toUnderlying(AxisDirection::AxisX)] = 20;
0193 transformB.pretranslate(translationB);
0194
0195 auto volumeB = Experimental::DetectorVolumeFactory::construct(
0196 portalGenerator, tContext, "VolumeB", transformB, box,
0197 Experimental::tryAllPortals());
0198
0199 std::vector<std::shared_ptr<Experimental::DetectorVolume>> volumes = {
0200 volumeA, volumeB};
0201 auto containerAB = Experimental::detail::CuboidalDetectorHelper::connect(
0202 tContext, volumes, AxisDirection::AxisX, {}, Logging::VERBOSE);
0203
0204
0205
0206 auto transformC = Transform3::Identity();
0207 Vector3 translationC = Vector3::Zero();
0208 translationC[toUnderlying(AxisDirection::AxisY)] = 20;
0209 transformC.pretranslate(translationC);
0210
0211 auto volumeC = Experimental::DetectorVolumeFactory::construct(
0212 portalGenerator, tContext, "VolumeC", transformC, box,
0213 Experimental::tryAllPortals());
0214
0215 auto transformD = Transform3::Identity();
0216 Vector3 translationD = Vector3::Zero();
0217 translationD[toUnderlying(AxisDirection::AxisX)] = 20;
0218 translationD[toUnderlying(AxisDirection::AxisY)] = 20;
0219 transformD.pretranslate(translationD);
0220
0221 auto volumeD = Experimental::DetectorVolumeFactory::construct(
0222 portalGenerator, tContext, "VolumeD", transformD, box,
0223 Experimental::tryAllPortals());
0224
0225 volumes = {volumeC, volumeD};
0226 auto containerCD = Experimental::detail::CuboidalDetectorHelper::connect(
0227 tContext, volumes, AxisDirection::AxisX, {}, Logging::VERBOSE);
0228
0229 auto containerABCD = Experimental::detail::CuboidalDetectorHelper::connect(
0230 tContext, {containerAB, containerCD}, AxisDirection::AxisY, {},
0231 Logging::VERBOSE);
0232
0233
0234 BOOST_CHECK(!containerABCD.empty());
0235
0236 ObjVisualization3D obj;
0237 GeometryView3D::drawDetectorVolume(obj, *volumeA, tContext);
0238 GeometryView3D::drawDetectorVolume(obj, *volumeB, tContext);
0239 GeometryView3D::drawDetectorVolume(obj, *volumeC, tContext);
0240 GeometryView3D::drawDetectorVolume(obj, *volumeD, tContext);
0241
0242 obj.write("ConnectContainers_binX.obj");
0243 }
0244
0245 BOOST_AUTO_TEST_SUITE_END()
0246
0247 }