Back to home page

EIC code displayed by LXR

 
 

    


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

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