Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:18

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