Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-06 09:18:47

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/Portal.hpp"
0014 #include "Acts/Detector/PortalGenerators.hpp"
0015 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0016 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0017 #include "Acts/Geometry/GeometryContext.hpp"
0018 #include "Acts/Navigation/InternalNavigation.hpp"
0019 #include "Acts/Navigation/NavigationState.hpp"
0020 
0021 #include <cmath>
0022 #include <memory>
0023 #include <numbers>
0024 #include <vector>
0025 
0026 using namespace Acts;
0027 using namespace Acts::Experimental;
0028 
0029 // A test context
0030 GeometryContext tContext;
0031 
0032 namespace ActsTests {
0033 
0034 BOOST_AUTO_TEST_SUITE(DetectorSuite)
0035 
0036 BOOST_AUTO_TEST_CASE(CylindricalPortalGenerator) {
0037   // Access Vectors, they should yield the detector volume
0038   // as a return on nextVolume(...) call
0039   Vector3 negPos(-200., 0., 0.);
0040   Vector3 negDir(0., 0., 1.);
0041 
0042   Vector3 posPos(200., 0., 0.);
0043   Vector3 posDir(0., 0., -1.);
0044 
0045   Vector3 outerPos(100., 0., 0.);
0046   Vector3 outerDir(-1., 0., 0.);
0047 
0048   Vector3 innerPos(10., 0., 0.);
0049   Vector3 innerDir(1., 0., 0.);
0050 
0051   // Filled Cylinder
0052   CylinderVolumeBounds cBar(0., 100, 200.);
0053 
0054   auto dTransform = Transform3::Identity();
0055   auto pGenerator = defaultPortalGenerator();
0056   auto dVolume = DetectorVolumeFactory::construct(
0057       pGenerator, tContext, "dummy", dTransform,
0058       std::make_unique<CuboidVolumeBounds>(1, 1, 1),
0059       tryAllPortalsAndSurfaces());
0060 
0061   auto cBarPortals = generatePortals(dTransform, cBar, dVolume);
0062 
0063   BOOST_CHECK_EQUAL(cBarPortals.size(), 3u);
0064   // Check they are not nullptrs
0065   for (const auto& p : cBarPortals) {
0066     BOOST_REQUIRE_NE(p, nullptr);
0067   }
0068 
0069   // Pointing inside the volume
0070   NavigationState nState;
0071 
0072   auto testDetectorVolumeUpdate =
0073       [&](const Experimental::Portal& portal, const Vector3& position,
0074           const Vector3& direction,
0075           const Experimental::DetectorVolume* expected) -> void {
0076     nState.position = position;
0077     nState.direction = direction;
0078     portal.updateDetectorVolume(tContext, nState);
0079     BOOST_CHECK_EQUAL(nState.currentVolume, expected);
0080   };
0081 
0082   testDetectorVolumeUpdate(*cBarPortals[0], negPos, negDir, dVolume.get());
0083   testDetectorVolumeUpdate(*cBarPortals[1], posPos, posDir, dVolume.get());
0084   testDetectorVolumeUpdate(*cBarPortals[2], outerPos, outerDir, dVolume.get());
0085 
0086   testDetectorVolumeUpdate(*cBarPortals[0], negPos, -negDir, nullptr);
0087   testDetectorVolumeUpdate(*cBarPortals[1], posPos, -posDir, nullptr);
0088   testDetectorVolumeUpdate(*cBarPortals[2], outerPos, -outerDir, nullptr);
0089 
0090   // Tube Cylinder
0091   CylinderVolumeBounds cTube(10., 100, 200.);
0092   auto cTubePortals = generatePortals(dTransform, cTube, dVolume);
0093   BOOST_CHECK_EQUAL(cTubePortals.size(), 4u);
0094   // Check they are not nullptrs
0095   for (const auto& p : cTubePortals) {
0096     BOOST_REQUIRE_NE(p, nullptr);
0097   }
0098 
0099   testDetectorVolumeUpdate(*cTubePortals[0], negPos, negDir, dVolume.get());
0100   testDetectorVolumeUpdate(*cTubePortals[1], posPos, posDir, dVolume.get());
0101   testDetectorVolumeUpdate(*cTubePortals[2], outerPos, outerDir, dVolume.get());
0102   testDetectorVolumeUpdate(*cTubePortals[3], innerPos, innerDir, dVolume.get());
0103 
0104   testDetectorVolumeUpdate(*cTubePortals[0], negPos, -negDir, nullptr);
0105   testDetectorVolumeUpdate(*cTubePortals[1], posPos, -posDir, nullptr);
0106   testDetectorVolumeUpdate(*cTubePortals[2], outerPos, -outerDir, nullptr);
0107   testDetectorVolumeUpdate(*cTubePortals[3], innerPos, -innerDir, nullptr);
0108 
0109   // Sectoral tube cylinder
0110   double alpha = std::numbers::pi / 4.;
0111   double r = 50;
0112 
0113   Vector3 negPhiSecPos(r * std::cos(-alpha), r * std::sin(-alpha), 0.);
0114   Vector3 negPhiSecDir(-r * std::cos(-alpha), r * std::sin(-alpha), 0.);
0115   Vector3 posPhiSecPos(r * std::cos(alpha), r * std::sin(alpha), 0.);
0116   Vector3 posPhiSecDir(r * std::cos(alpha), -r * std::sin(alpha), 0.);
0117 
0118   CylinderVolumeBounds cTubeSector(10., 100., 200., alpha, 0.);
0119   auto cTubeSectorPortals = generatePortals(dTransform, cTubeSector, dVolume);
0120   BOOST_CHECK_EQUAL(cTubeSectorPortals.size(), 6u);
0121   // Check they are not nullptrs
0122   for (const auto& p : cTubeSectorPortals) {
0123     BOOST_REQUIRE_NE(p, nullptr);
0124   }
0125 
0126   // Pointing inside the volume
0127   testDetectorVolumeUpdate(*cTubeSectorPortals[0], negPos, negDir,
0128                            dVolume.get());
0129   testDetectorVolumeUpdate(*cTubeSectorPortals[1], posPos, posDir,
0130                            dVolume.get());
0131   testDetectorVolumeUpdate(*cTubeSectorPortals[2], outerPos, outerDir,
0132                            dVolume.get());
0133   testDetectorVolumeUpdate(*cTubeSectorPortals[3], innerPos, innerDir,
0134                            dVolume.get());
0135   testDetectorVolumeUpdate(*cTubeSectorPortals[4], negPhiSecPos, negPhiSecDir,
0136                            dVolume.get());
0137   testDetectorVolumeUpdate(*cTubeSectorPortals[5], posPhiSecPos, posPhiSecDir,
0138                            dVolume.get());
0139 
0140   // Pointing to nowhere land
0141   testDetectorVolumeUpdate(*cTubeSectorPortals[0], negPos, -negDir, nullptr);
0142   testDetectorVolumeUpdate(*cTubeSectorPortals[1], posPos, -posDir, nullptr);
0143   testDetectorVolumeUpdate(*cTubeSectorPortals[2], outerPos, -outerDir,
0144                            nullptr);
0145   testDetectorVolumeUpdate(*cTubeSectorPortals[3], innerPos, -innerDir,
0146                            nullptr);
0147   testDetectorVolumeUpdate(*cTubeSectorPortals[4], negPhiSecPos, -negPhiSecDir,
0148                            nullptr);
0149   testDetectorVolumeUpdate(*cTubeSectorPortals[5], posPhiSecPos, -posPhiSecDir,
0150                            nullptr);
0151 }
0152 
0153 BOOST_AUTO_TEST_SUITE_END()
0154 
0155 }  // namespace ActsTests