Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-06 09:23:52

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/Units.hpp"
0012 #include "Acts/Geometry/DiamondPortalShell.hpp"
0013 #include "Acts/Geometry/GridPortalLink.hpp"
0014 #include "Acts/Geometry/TrackingVolume.hpp"
0015 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
0016 #include "Acts/Geometry/TrivialPortalLink.hpp"
0017 #include "Acts/Utilities/AxisDefinitions.hpp"
0018 
0019 using namespace Acts;
0020 using namespace Acts::UnitLiterals;
0021 
0022 namespace ActsTests {
0023 
0024 GeometryContext gctx = GeometryContext();
0025 
0026 BOOST_AUTO_TEST_SUITE(GeometrySuite)
0027 
0028 BOOST_AUTO_TEST_CASE(ConstructionFromVolume) {
0029   // check exception throw if not the correct shape
0030 
0031   TrackingVolume fVol(
0032       Transform3::Identity(),
0033       std::make_shared<TrapezoidVolumeBounds>(20._cm, 10._cm, 10._cm, 5._cm));
0034 
0035   BOOST_CHECK_THROW(SingleDiamondPortalShell{fVol}, std::invalid_argument);
0036 
0037   // conastruct a convex polygon tracking volume for which we are gonna build
0038   // the portal shell
0039 
0040   TrackingVolume testVol(Transform3::Identity(),
0041                          std::make_shared<DiamondVolumeBounds>(
0042                              20._cm, 25._cm, 15._cm, 15._cm, 20._cm, 12._cm));
0043 
0044   SingleDiamondPortalShell polygShell{testVol};
0045 
0046   BOOST_CHECK(polygShell.isValid());
0047   BOOST_CHECK_EQUAL(polygShell.size(), 8);
0048 
0049   // check if the portals are correctly built from the faces
0050   using enum DiamondVolumeBounds::Face;
0051 
0052   const auto nXY = polygShell.portalPtr(NegativeZFaceXY);
0053   const auto pXY = polygShell.portalPtr(PositiveZFaceXY);
0054   const auto nXZ = polygShell.portalPtr(NegativeYFaceZX);
0055   const auto pXZ = polygShell.portalPtr(PositiveYFaceZX);
0056   const auto nYZ12 = polygShell.portalPtr(NegativeXFaceYZ12);
0057   const auto pYZ12 = polygShell.portalPtr(PositiveXFaceYZ12);
0058   const auto nYZ23 = polygShell.portalPtr(NegativeXFaceYZ23);
0059   const auto pYZ23 = polygShell.portalPtr(PositiveXFaceYZ23);
0060 
0061   double alphaAngle = std::numbers::pi - std::atan2(15._cm, 5._cm);
0062   double betaAngle = std::atan2(20._cm, 10._cm);
0063 
0064   BOOST_REQUIRE_NE(nXY, nullptr);
0065   BOOST_REQUIRE_NE(pXY, nullptr);
0066   BOOST_REQUIRE_NE(nXZ, nullptr);
0067   BOOST_REQUIRE_NE(pXZ, nullptr);
0068   BOOST_REQUIRE_NE(nYZ12, nullptr);
0069   BOOST_REQUIRE_NE(pYZ12, nullptr);
0070   BOOST_REQUIRE_NE(nYZ23, nullptr);
0071   BOOST_REQUIRE_NE(pYZ23, nullptr);
0072 
0073   BOOST_CHECK_EQUAL(
0074       nXY->resolveVolume(gctx, Vector3{0., 0., -12._cm}, Vector3::UnitZ())
0075           .value(),
0076       &testVol);
0077   BOOST_CHECK_EQUAL(
0078       pXY->resolveVolume(gctx, Vector3{0., 0., 12._cm}, -Vector3::UnitZ())
0079           .value(),
0080       &testVol);
0081   BOOST_CHECK_EQUAL(
0082       nXZ->resolveVolume(gctx, Vector3{0., -15._cm, 0.}, Vector3::UnitY())
0083           .value(),
0084       &testVol);
0085 
0086   BOOST_CHECK_EQUAL(
0087       pXZ->resolveVolume(gctx, Vector3{0., 20._cm, 0.}, -Vector3::UnitY())
0088           .value(),
0089       &testVol);
0090 
0091   Vector3 normalVec =
0092       Vector3{std::cos(-std::numbers::pi / 2. + alphaAngle),
0093               std::sin(-std::numbers::pi / 2. + alphaAngle), 0.};
0094 
0095   BOOST_CHECK_EQUAL(
0096       nYZ12->resolveVolume(gctx, Vector3{-22.5_cm, -7.5_cm, 0.}, normalVec)
0097           .value(),
0098       &testVol);
0099 
0100   BOOST_CHECK_EQUAL(
0101       pYZ12->resolveVolume(gctx, Vector3{22.5_cm, -7.5_cm, 0.}, -normalVec)
0102           .value(),
0103       &testVol);
0104 
0105   normalVec = {std::cos(std::numbers::pi / 2. - betaAngle),
0106                std::sin(std::numbers::pi / 2. - betaAngle), 0.};
0107   BOOST_CHECK_EQUAL(
0108       pYZ23->resolveVolume(gctx, Vector3{20._cm, 10._cm, 0}, -normalVec)
0109           .value(),
0110       &testVol);
0111 
0112   BOOST_CHECK_EQUAL(
0113       nYZ23->resolveVolume(gctx, Vector3{-20._cm, 10._cm, 0.}, normalVec)
0114           .value(),
0115       &testVol);
0116 }
0117 
0118 BOOST_AUTO_TEST_CASE(PortalAssignment) {
0119   using enum DiamondVolumeBounds::Face;
0120 
0121   TrackingVolume polygVol(Transform3::Identity(),
0122                           std::make_shared<DiamondVolumeBounds>(
0123                               20._cm, 25._cm, 15._cm, 15._cm, 20._cm, 12._cm));
0124 
0125   SingleDiamondPortalShell polygShell{polygVol};
0126 
0127   // get the portal faces
0128   const auto nXY = polygShell.portalPtr(NegativeZFaceXY);
0129   const auto pXY = polygShell.portalPtr(PositiveZFaceXY);
0130 
0131   BOOST_REQUIRE_NE(nXY, nullptr);
0132   BOOST_REQUIRE_NE(pXY, nullptr);
0133 
0134   const auto nYZ12 = polygShell.portalPtr(NegativeXFaceYZ12);
0135   const auto pYZ12 = polygShell.portalPtr(PositiveXFaceYZ12);
0136 
0137   const auto nYZ23 = polygShell.portalPtr(NegativeXFaceYZ23);
0138   const auto pYZ23 = polygShell.portalPtr(PositiveXFaceYZ23);
0139 
0140   const auto nZX = polygShell.portalPtr(NegativeYFaceZX);
0141   const auto pZX = polygShell.portalPtr(PositiveYFaceZX);
0142 
0143   BOOST_REQUIRE_NE(nYZ23, nullptr);
0144   BOOST_REQUIRE_NE(pYZ23, nullptr);
0145 
0146   BOOST_REQUIRE_NE(nZX, nullptr);
0147   BOOST_REQUIRE_NE(pZX, nullptr);
0148 
0149   BOOST_REQUIRE_NE(nYZ12, nullptr);
0150   BOOST_REQUIRE_NE(pYZ12, nullptr);
0151 
0152   auto* pZXLink = dynamic_cast<const TrivialPortalLink*>(
0153       pZX->getLink(Direction::OppositeNormal()));
0154   auto grid = pZXLink->makeGrid(AxisDirection::AxisY);
0155 
0156   BOOST_REQUIRE_NE(pZXLink, nullptr);
0157 
0158   auto newPortalpZX =
0159       std::make_shared<Portal>(Direction::OppositeNormal(), std::move(grid));
0160   polygShell.setPortal(newPortalpZX, PositiveYFaceZX);
0161 
0162   BOOST_CHECK_EQUAL(polygShell.portalPtr(PositiveYFaceZX), newPortalpZX);
0163 
0164   // //check also the other portals
0165   BOOST_CHECK_EQUAL(polygShell.portalPtr(NegativeZFaceXY), nXY);
0166   BOOST_CHECK_EQUAL(polygShell.portalPtr(PositiveZFaceXY), pXY);
0167   BOOST_CHECK_EQUAL(polygShell.portalPtr(NegativeXFaceYZ12), nYZ12);
0168   BOOST_CHECK_EQUAL(polygShell.portalPtr(PositiveXFaceYZ12), pYZ12);
0169   BOOST_CHECK_EQUAL(polygShell.portalPtr(NegativeXFaceYZ23), nYZ23);
0170   BOOST_CHECK_EQUAL(polygShell.portalPtr(PositiveXFaceYZ23), pYZ23);
0171   BOOST_CHECK_EQUAL(polygShell.portalPtr(NegativeYFaceZX), nZX);
0172 }
0173 
0174 BOOST_AUTO_TEST_CASE(Fill) {
0175   using enum DiamondVolumeBounds::Face;
0176 
0177   TrackingVolume testVol(Transform3::Identity(),
0178                          std::make_shared<DiamondVolumeBounds>(
0179                              20._cm, 25._cm, 15._cm, 15._cm, 20._cm, 12._cm));
0180   SingleDiamondPortalShell polygShell(testVol);
0181 
0182   // without filling the protal shell from a volume the portal link to this
0183   // direction shouldn't exist - but only the other direction
0184   BOOST_CHECK_EQUAL(polygShell.portalPtr(NegativeZFaceXY)
0185                         ->getLink(Direction::OppositeNormal()),
0186                     nullptr);
0187   BOOST_CHECK(polygShell.portalPtr(NegativeZFaceXY)
0188                   ->getLink(Direction::AlongNormal()) != nullptr);
0189 
0190   // create a volume to link to the portal to the other side
0191   TrackingVolume testVol2(
0192       Transform3::Identity() * Translation3(Vector3::UnitZ() * 24_cm),
0193       std::make_shared<DiamondVolumeBounds>(20._cm, 25._cm, 15._cm, 15._cm,
0194                                             20._cm, 12._cm));
0195   polygShell.fill(testVol2);
0196 
0197   BOOST_CHECK_NE(polygShell.portalPtr(NegativeZFaceXY)
0198                      ->getLink(Direction::OppositeNormal()),
0199                  nullptr);
0200 }
0201 
0202 BOOST_AUTO_TEST_CASE(ApplyToVolume) {
0203   // test the volume's portals
0204   TrackingVolume testVol(Transform3::Identity(),
0205                          std::make_shared<DiamondVolumeBounds>(
0206                              20._cm, 25._cm, 15._cm, 15._cm, 20._cm, 12._cm));
0207   SingleDiamondPortalShell polygShell(testVol);
0208   // before apply to volueme called - the volume should have zero portals
0209   BOOST_CHECK_EQUAL(testVol.portals().size(), 0);
0210 
0211   polygShell.applyToVolume();
0212 
0213   // let's see now
0214   BOOST_CHECK_EQUAL(testVol.portals().size(), 8);
0215 }
0216 
0217 BOOST_AUTO_TEST_SUITE_END();
0218 
0219 }  // namespace ActsTests