Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:31

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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 auto portalGenerator = Acts::Experimental::defaultPortalGenerator();
0028 auto tContext = Acts::GeometryContext();
0029 
0030 BOOST_AUTO_TEST_SUITE(Experimental)
0031 
0032 BOOST_AUTO_TEST_CASE(CubicVolumeExceptions) {
0033   // A perfect box shape
0034   auto box = std::make_shared<Acts::CuboidVolumeBounds>(10, 10, 10);
0035 
0036   // Create volume A
0037   auto volumeA = Acts::Experimental::DetectorVolumeFactory::construct(
0038       portalGenerator, tContext, "VolumeA", Acts::Transform3::Identity(), box,
0039       Acts::Experimental::tryAllPortals());
0040 
0041   // Create volume B
0042   auto transformB = Acts::Transform3::Identity();
0043   transformB.prerotate(Acts::AngleAxis3(0.234, Acts::Vector3::UnitZ()));
0044 
0045   auto volumeB = Acts::Experimental::DetectorVolumeFactory::construct(
0046       portalGenerator, tContext, "volumeB", transformB, box,
0047       Acts::Experimental::tryAllPortals());
0048   // Build the container
0049   std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>> volumes = {
0050       volumeA, volumeB};
0051 
0052   BOOST_CHECK_THROW(Acts::Experimental::detail::CuboidalDetectorHelper::connect(
0053                         tContext, volumes, Acts::AxisDirection::AxisX, {},
0054                         Acts::Logging::VERBOSE),
0055                     std::invalid_argument);
0056 }
0057 
0058 BOOST_AUTO_TEST_CASE(SimpleBoxConnection) {
0059   std::array<Acts::AxisDirection, 3> binningValues = {
0060       Acts::AxisDirection::AxisX, Acts::AxisDirection::AxisY,
0061       Acts::AxisDirection::AxisZ};
0062   for (auto bVal : binningValues) {
0063     // A perfect box shape
0064     auto box = std::make_shared<Acts::CuboidVolumeBounds>(10, 10, 10);
0065 
0066     // Create volume A
0067     auto volumeA = Acts::Experimental::DetectorVolumeFactory::construct(
0068         portalGenerator, tContext, "VolumeA", Acts::Transform3::Identity(), box,
0069         Acts::Experimental::tryAllPortals());
0070 
0071     // Move it into the bval direction
0072     auto transformB = Acts::Transform3::Identity();
0073 
0074     Acts::Vector3 translation = Acts::Vector3::Zero();
0075     translation[toUnderlying(bVal)] = 20;
0076     transformB.pretranslate(translation);
0077     // Create volume B
0078     auto volumeB = Acts::Experimental::DetectorVolumeFactory::construct(
0079         portalGenerator, tContext, "VolumeB", transformB, box,
0080         Acts::Experimental::tryAllPortals());
0081     // Build the container
0082     std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>> volumes = {
0083         volumeA, volumeB};
0084     auto container =
0085         Acts::Experimental::detail::CuboidalDetectorHelper::connect(
0086             tContext, volumes, bVal, {}, Acts::Logging::VERBOSE);
0087 
0088     // Check the container is constructed
0089     BOOST_CHECK(!container.empty());
0090 
0091     Acts::ObjVisualization3D obj;
0092     Acts::GeometryView3D::drawDetectorVolume(obj, *volumeA, tContext);
0093     Acts::GeometryView3D::drawDetectorVolume(obj, *volumeB, tContext);
0094     obj.write("ConnectectBoxesRegular_" + Acts::axisDirectionName(bVal) +
0095               ".obj");
0096   }
0097 }
0098 
0099 BOOST_AUTO_TEST_CASE(IrregularBoxConnectionInZ) {
0100   std::vector<Acts::AxisDirection> binningValues = {Acts::AxisDirection::AxisX,
0101                                                     Acts::AxisDirection::AxisY,
0102                                                     Acts::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<Acts::Transform3, 2u> transforms = {
0116       Acts::Transform3::Identity(),
0117       Acts::Transform3{Acts::Transform3::Identity()}.prerotate(
0118           Acts::AngleAxis3(0.34, Acts::Vector3(1., 1., 1.).normalized()))};
0119 
0120   // Try with arbitrary rotations
0121   for (auto [it, t] : Acts::enumerate(transforms)) {
0122     std::string trstr = it == 0 ? "" : "_rotated";
0123     auto rotation = t.rotation();
0124     // Try for all binning values
0125     for (auto bVal : binningValues) {
0126       auto [vsA, vsB, vsC] = volSetups[toUnderlying(bVal)];
0127 
0128       // Three box shares with different length in Z
0129       auto boxA = std::make_shared<Acts::CuboidVolumeBounds>(
0130           vsA[0][0], vsB[0][0], vsC[0][0]);
0131       auto boxB = std::make_shared<Acts::CuboidVolumeBounds>(
0132           vsA[1][0], vsB[1][0], vsC[1][0]);
0133       auto boxC = std::make_shared<Acts::CuboidVolumeBounds>(
0134           vsA[2][0], vsB[2][0], vsC[2][0]);
0135 
0136       auto transformA = Acts::Transform3::Identity();
0137       auto transformB = Acts::Transform3::Identity();
0138       auto transformC = Acts::Transform3::Identity();
0139 
0140       transformA.pretranslate(Acts::Vector3(vsA[0][1], vsB[0][1], vsC[0][1]));
0141       transformB.pretranslate(Acts::Vector3(vsA[1][1], vsB[1][1], vsC[1][1]));
0142       transformC.pretranslate(Acts::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       // Create volume A, B, C
0149       auto volumeA = Acts::Experimental::DetectorVolumeFactory::construct(
0150           portalGenerator, tContext, "VolumeA", transformA, boxA,
0151           Acts::Experimental::tryAllPortals());
0152       auto volumeB = Acts::Experimental::DetectorVolumeFactory::construct(
0153           portalGenerator, tContext, "VolumeB", transformB, boxB,
0154           Acts::Experimental::tryAllPortals());
0155       auto volumeC = Acts::Experimental::DetectorVolumeFactory::construct(
0156           portalGenerator, tContext, "VolumeC", transformC, boxC,
0157           Acts::Experimental::tryAllPortals());
0158 
0159       // Build the container
0160       std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>> volumes =
0161           {volumeA, volumeB, volumeC};
0162       auto container =
0163           Acts::Experimental::detail::CuboidalDetectorHelper::connect(
0164               tContext, volumes, bVal, {}, Acts::Logging::VERBOSE);
0165 
0166       // Check the container is constructed
0167       BOOST_CHECK(!container.empty());
0168 
0169       Acts::ObjVisualization3D obj;
0170       Acts::GeometryView3D::drawDetectorVolume(obj, *volumeA, tContext);
0171       Acts::GeometryView3D::drawDetectorVolume(obj, *volumeB, tContext);
0172       Acts::GeometryView3D::drawDetectorVolume(obj, *volumeC, tContext);
0173       obj.write("ConnectectBoxesIrregular_" + Acts::axisDirectionName(bVal) +
0174                 trstr + ".obj");
0175     }
0176   }
0177 }
0178 
0179 BOOST_AUTO_TEST_CASE(ContainerConnection) {
0180   // A perfect box shape
0181   auto box = std::make_shared<Acts::CuboidVolumeBounds>(10, 10, 10);
0182 
0183   // Create an AB container
0184 
0185   // Create volume A
0186   auto volumeA = Acts::Experimental::DetectorVolumeFactory::construct(
0187       portalGenerator, tContext, "VolumeA", Acts::Transform3::Identity(), box,
0188       Acts::Experimental::tryAllPortals());
0189 
0190   // Move it into the bval direction
0191   auto transformB = Acts::Transform3::Identity();
0192   Acts::Vector3 translationB = Acts::Vector3::Zero();
0193   translationB[toUnderlying(Acts::AxisDirection::AxisX)] = 20;
0194   transformB.pretranslate(translationB);
0195   // Create volume B
0196   auto volumeB = Acts::Experimental::DetectorVolumeFactory::construct(
0197       portalGenerator, tContext, "VolumeB", transformB, box,
0198       Acts::Experimental::tryAllPortals());
0199   // Build the container
0200   std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>> volumes = {
0201       volumeA, volumeB};
0202   auto containerAB =
0203       Acts::Experimental::detail::CuboidalDetectorHelper::connect(
0204           tContext, volumes, Acts::AxisDirection::AxisX, {},
0205           Acts::Logging::VERBOSE);
0206 
0207   // Create a CD container
0208 
0209   auto transformC = Acts::Transform3::Identity();
0210   Acts::Vector3 translationC = Acts::Vector3::Zero();
0211   translationC[toUnderlying(Acts::AxisDirection::AxisY)] = 20;
0212   transformC.pretranslate(translationC);
0213 
0214   auto volumeC = Acts::Experimental::DetectorVolumeFactory::construct(
0215       portalGenerator, tContext, "VolumeC", transformC, box,
0216       Acts::Experimental::tryAllPortals());
0217 
0218   auto transformD = Acts::Transform3::Identity();
0219   Acts::Vector3 translationD = Acts::Vector3::Zero();
0220   translationD[toUnderlying(Acts::AxisDirection::AxisX)] = 20;
0221   translationD[toUnderlying(Acts::AxisDirection::AxisY)] = 20;
0222   transformD.pretranslate(translationD);
0223 
0224   auto volumeD = Acts::Experimental::DetectorVolumeFactory::construct(
0225       portalGenerator, tContext, "VolumeD", transformD, box,
0226       Acts::Experimental::tryAllPortals());
0227 
0228   volumes = {volumeC, volumeD};
0229   auto containerCD =
0230       Acts::Experimental::detail::CuboidalDetectorHelper::connect(
0231           tContext, volumes, Acts::AxisDirection::AxisX, {},
0232           Acts::Logging::VERBOSE);
0233 
0234   auto containerABCD =
0235       Acts::Experimental::detail::CuboidalDetectorHelper::connect(
0236           tContext, {containerAB, containerCD}, Acts::AxisDirection::AxisY, {},
0237           Acts::Logging::VERBOSE);
0238 
0239   // Check the container is constructed
0240   BOOST_CHECK(!containerABCD.empty());
0241 
0242   Acts::ObjVisualization3D obj;
0243   Acts::GeometryView3D::drawDetectorVolume(obj, *volumeA, tContext);
0244   Acts::GeometryView3D::drawDetectorVolume(obj, *volumeB, tContext);
0245   Acts::GeometryView3D::drawDetectorVolume(obj, *volumeC, tContext);
0246   Acts::GeometryView3D::drawDetectorVolume(obj, *volumeD, tContext);
0247 
0248   obj.write("ConnectContainers_binX.obj");
0249 }
0250 
0251 BOOST_AUTO_TEST_SUITE_END()