Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:04:01

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/CylinderVolumeBounds.hpp"
0013 #include "Acts/Geometry/Portal.hpp"
0014 #include "Acts/Geometry/PortalLinkBase.hpp"
0015 #include "Acts/Geometry/TrackingGeometryVisitor.hpp"
0016 #include "Acts/Geometry/TrackingVolume.hpp"
0017 #include "Acts/Surfaces/PlaneSurface.hpp"
0018 #include "Acts/Surfaces/RectangleBounds.hpp"
0019 #include "Acts/Surfaces/SurfaceArray.hpp"
0020 #include "Acts/Utilities/Helpers.hpp"
0021 
0022 #include "LayerStub.hpp"
0023 
0024 using namespace Acts::UnitLiterals;
0025 
0026 namespace Acts::Test {
0027 
0028 BOOST_AUTO_TEST_SUITE(Geometry)
0029 BOOST_AUTO_TEST_SUITE(TrackingVolumeTests)
0030 
0031 std::size_t countVolumes(const TrackingVolume& tv) {
0032   std::size_t count = 0;
0033   tv.visitVolumes([&count](const auto&) { ++count; });
0034   return count;
0035 }
0036 
0037 BOOST_AUTO_TEST_CASE(TrackigVolumeChildren) {
0038   auto cylBounds =
0039       std::make_shared<Acts::CylinderVolumeBounds>(10_mm, 20_mm, 100_mm);
0040 
0041   TrackingVolume tv{Transform3::Identity(), cylBounds};
0042 
0043   BOOST_CHECK(tv.volumes().empty());
0044   BOOST_CHECK_EQUAL(countVolumes(tv), 1);
0045 
0046   auto& child1 = tv.addVolume(
0047       std::make_unique<TrackingVolume>(Transform3::Identity(), cylBounds));
0048 
0049   BOOST_CHECK_EQUAL(tv.volumes().size(), 1);
0050 
0051   auto it = tv.volumes().begin();
0052   static_assert(std::is_same_v<decltype(*it), TrackingVolume&>);
0053 
0054   const auto& tvConst = tv;
0055   auto cit = tvConst.volumes().begin();
0056   static_assert(std::is_same_v<decltype(*cit), const TrackingVolume&>);
0057 
0058   BOOST_CHECK_EQUAL(&*it, &child1);
0059 
0060   BOOST_CHECK_EQUAL(countVolumes(tv), 2);
0061 
0062   tv.addVolume(
0063       std::make_unique<TrackingVolume>(Transform3::Identity(), cylBounds));
0064 
0065   BOOST_CHECK_EQUAL(countVolumes(tv), 3);
0066 }
0067 
0068 namespace {
0069 void testVisitor(auto visitor) {
0070   BOOST_CHECK(!visitor.m_surfaceCalled);
0071   BOOST_CHECK(!visitor.m_volumeCalled);
0072   BOOST_CHECK(!visitor.m_boundaryCalled);
0073   BOOST_CHECK(!visitor.m_layerCalled);
0074   BOOST_CHECK(!visitor.m_portalCalled);
0075 
0076   auto surface = Surface::makeShared<PlaneSurface>(
0077       Transform3::Identity(), std::make_shared<RectangleBounds>(10_mm, 10_mm));
0078 
0079   visitor.visitSurface(*surface);
0080   BOOST_CHECK(visitor.m_surfaceCalled);
0081 
0082   auto cylBounds =
0083       std::make_shared<Acts::CylinderVolumeBounds>(10_mm, 20_mm, 100_mm);
0084 
0085   TrackingVolume tv{Transform3::Identity(), cylBounds};
0086   visitor.visitVolume(tv);
0087 
0088   BOOST_CHECK(visitor.m_volumeCalled);
0089 
0090   BoundarySurfaceT<TrackingVolume> boundary{surface, &tv, nullptr};
0091   visitor.visitBoundarySurface(boundary);
0092   BOOST_CHECK(visitor.m_boundaryCalled);
0093 
0094   LayerStub layer{nullptr};
0095   visitor.visitLayer(layer);
0096   BOOST_CHECK(visitor.m_layerCalled);
0097 
0098   Portal portal{Direction::AlongNormal(), surface, tv};
0099   visitor.visitPortal(portal);
0100   BOOST_CHECK(visitor.m_portalCalled);
0101 
0102   visitor.m_volumeCalled = false;
0103   tv.apply(visitor);
0104   BOOST_CHECK(visitor.m_volumeCalled);
0105 }
0106 }  // namespace
0107 
0108 BOOST_AUTO_TEST_CASE(Visit) {
0109   struct Visitor : public TrackingGeometryVisitor {
0110     void visitSurface(const Surface& /*surface*/) override {
0111       m_surfaceCalled = true;
0112     }
0113 
0114     void visitVolume(const TrackingVolume& /*volume*/) override {
0115       m_volumeCalled = true;
0116     }
0117 
0118     void visitBoundarySurface(
0119         const BoundarySurfaceT<TrackingVolume>& /*boundary*/) override {
0120       m_boundaryCalled = true;
0121     }
0122 
0123     void visitLayer(const Layer& /*layer*/) override { m_layerCalled = true; }
0124 
0125     void visitPortal(const Portal& /*portal*/) override {
0126       m_portalCalled = true;
0127     }
0128 
0129     bool m_surfaceCalled = false;
0130     bool m_volumeCalled = false;
0131     bool m_boundaryCalled = false;
0132     bool m_layerCalled = false;
0133     bool m_portalCalled = false;
0134   };
0135 
0136   testVisitor(Visitor{});
0137 }
0138 
0139 BOOST_AUTO_TEST_CASE(VisitMutable) {
0140   struct MutableVisitor : public TrackingGeometryMutableVisitor {
0141     void visitSurface(Surface& /*surface*/) override { m_surfaceCalled = true; }
0142 
0143     void visitVolume(TrackingVolume& /*volume*/) override {
0144       m_volumeCalled = true;
0145     }
0146 
0147     void visitBoundarySurface(
0148         BoundarySurfaceT<TrackingVolume>& /*boundary*/) override {
0149       m_boundaryCalled = true;
0150     }
0151 
0152     void visitLayer(Layer& /*layer*/) override { m_layerCalled = true; }
0153 
0154     void visitPortal(Portal& /*portal*/) override { m_portalCalled = true; }
0155 
0156     bool m_surfaceCalled = false;
0157     bool m_volumeCalled = false;
0158     bool m_boundaryCalled = false;
0159     bool m_layerCalled = false;
0160     bool m_portalCalled = false;
0161   };
0162 
0163   testVisitor(MutableVisitor{});
0164 }
0165 
0166 BOOST_AUTO_TEST_CASE(VisitLambda) {
0167   bool surfaceCalled = false;
0168   bool volumeCalled = false;
0169   bool boundaryCalled = false;
0170   bool layerCalled = false;
0171   bool portalCalled = false;
0172 
0173   auto visitor = detail::TrackingGeometryLambdaVisitor{overloaded{
0174       [&](const Surface& /*surface*/) { surfaceCalled = true; },
0175       [&](const TrackingVolume& /*volume*/) { volumeCalled = true; },
0176       [&](const BoundarySurfaceT<TrackingVolume>& /*boundary*/) {
0177         boundaryCalled = true;
0178       },
0179       [&](const Layer& /*layer*/) { layerCalled = true; },
0180       [&](const Portal& /*portal*/) { portalCalled = true; },
0181   }};
0182 
0183   auto surface = Surface::makeShared<PlaneSurface>(
0184       Transform3::Identity(), std::make_shared<RectangleBounds>(10_mm, 10_mm));
0185 
0186   visitor.visitSurface(*surface);
0187   BOOST_CHECK(surfaceCalled);
0188 
0189   auto cylBounds =
0190       std::make_shared<Acts::CylinderVolumeBounds>(10_mm, 20_mm, 100_mm);
0191 
0192   TrackingVolume tv{Transform3::Identity(), cylBounds};
0193   visitor.visitVolume(tv);
0194 
0195   BOOST_CHECK(volumeCalled);
0196 
0197   BoundarySurfaceT<TrackingVolume> boundary{surface, &tv, nullptr};
0198   visitor.visitBoundarySurface(boundary);
0199   BOOST_CHECK(boundaryCalled);
0200 
0201   LayerStub layer{nullptr};
0202   visitor.visitLayer(layer);
0203   BOOST_CHECK(layerCalled);
0204 
0205   Portal portal{Direction::AlongNormal(), surface, tv};
0206   visitor.visitPortal(portal);
0207   BOOST_CHECK(portalCalled);
0208 
0209   volumeCalled = false;
0210   tv.apply(visitor);
0211   BOOST_CHECK(volumeCalled);
0212 }
0213 
0214 BOOST_AUTO_TEST_CASE(VisitLambdaMutable) {
0215   bool surfaceCalled = false;
0216   bool volumeCalled = false;
0217   bool boundaryCalled = false;
0218   bool layerCalled = false;
0219   bool portalCalled = false;
0220 
0221   auto overload = overloaded{
0222       [&](Surface& /*surface*/) { surfaceCalled = true; },
0223       [&](TrackingVolume& /*volume*/) { volumeCalled = true; },
0224       [&](BoundarySurfaceT<TrackingVolume>& /*boundary*/) {
0225         boundaryCalled = true;
0226       },
0227       [&](Layer& /*layer*/) { layerCalled = true; },
0228       [&](Portal& /*portal*/) { portalCalled = true; },
0229   };
0230 
0231   auto visitor = detail::TrackingGeometryLambdaMutableVisitor{overload};
0232 
0233   auto surface = Surface::makeShared<PlaneSurface>(
0234       Transform3::Identity(), std::make_shared<RectangleBounds>(10_mm, 10_mm));
0235 
0236   visitor.visitSurface(*surface);
0237   BOOST_CHECK(surfaceCalled);
0238 
0239   auto cylBounds =
0240       std::make_shared<Acts::CylinderVolumeBounds>(10_mm, 20_mm, 100_mm);
0241 
0242   TrackingVolume tv{Transform3::Identity(), cylBounds};
0243   visitor.visitVolume(tv);
0244 
0245   BOOST_CHECK(volumeCalled);
0246 
0247   BoundarySurfaceT<TrackingVolume> boundary{surface, &tv, nullptr};
0248   visitor.visitBoundarySurface(boundary);
0249   BOOST_CHECK(boundaryCalled);
0250 
0251   LayerStub layer{nullptr};
0252   visitor.visitLayer(layer);
0253   BOOST_CHECK(layerCalled);
0254 
0255   Portal portal{Direction::AlongNormal(), surface, tv};
0256   visitor.visitPortal(portal);
0257   BOOST_CHECK(portalCalled);
0258 
0259   volumeCalled = false;
0260   tv.apply(overload);
0261   BOOST_CHECK(volumeCalled);
0262 
0263   volumeCalled = false;
0264   tv.apply([&](Volume& /*volume*/) { volumeCalled = true; });
0265   BOOST_CHECK(volumeCalled);
0266 }
0267 
0268 BOOST_AUTO_TEST_CASE(CallableWithAny) {
0269   // Test callableWithAny
0270   static_assert(
0271       detail::callableWithAny<decltype([](Surface& /*surface*/) {})>());
0272   static_assert(
0273       detail::callableWithAny<decltype([](const Surface& /*surface*/) {})>());
0274   static_assert(detail::callableWithAny<decltype([](Portal& /*portal*/) {})>());
0275   static_assert(
0276       detail::callableWithAny<decltype([](const Portal& /*portal*/) {})>());
0277   static_assert(
0278       detail::callableWithAny<decltype([](TrackingVolume& /*volume*/) {})>());
0279   static_assert(!detail::callableWithAny<decltype([](int /*x*/) {})>());
0280   static_assert(!detail::callableWithAny<decltype([](void* /*ptr*/) {})>());
0281 
0282   // Test callableWithAnyConst specifically
0283   static_assert(detail::callableWithAnyConst<
0284                 decltype([](const Surface& /*surface*/) {})>());
0285   static_assert(detail::callableWithAnyConst<
0286                 decltype([](const TrackingVolume& /*volume*/) {})>());
0287   static_assert(
0288       detail::callableWithAnyConst<decltype([](const Layer& /*layer*/) {})>());
0289   static_assert(!detail::callableWithAnyConst<decltype([](int /*x*/) {})>());
0290   static_assert(
0291       !detail::callableWithAnyConst<decltype([](void* /*ptr*/) {})>());
0292 
0293   // Test callableWithAnyMutable specifically
0294   static_assert(
0295       detail::callableWithAnyMutable<decltype([](Surface& /*surface*/) {})>());
0296   static_assert(detail::callableWithAnyMutable<
0297                 decltype([](TrackingVolume& /*volume*/) {})>());
0298   static_assert(
0299       detail::callableWithAnyMutable<decltype([](Layer& /*layer*/) {})>());
0300   static_assert(!detail::callableWithAnyMutable<decltype([](int /*x*/) {})>());
0301   static_assert(
0302       !detail::callableWithAnyMutable<decltype([](void* /*ptr*/) {})>());
0303 
0304   // Test mixed const/non-const overloads
0305   static_assert(detail::callableWithAny<decltype(overloaded{
0306                     [](Surface& /*surface*/) {},
0307                     [](const TrackingVolume& /*volume*/) {},
0308                 })>());
0309 
0310   // Test with unrelated overloads
0311   static_assert(!detail::callableWithAny<decltype(overloaded{
0312                     [](int /*x*/) {},
0313                     [](double /*y*/) {},
0314                     [](const std::string& /*s*/) {},
0315                 })>());
0316 
0317   // Test with mix of geometry and unrelated overloads
0318   static_assert(detail::callableWithAny<decltype(overloaded{
0319                     [](int /*x*/) {},
0320                     [](Surface& /*surface*/) {},
0321                     [](const std::string& /*s*/) {},
0322                 })>());
0323 
0324   static_assert(detail::callableWithAny<decltype(overloaded{
0325                     [](void* /*ptr*/) {},
0326                     [](const Portal& /*portal*/) {},
0327                     [](double /*d*/) {},
0328                 })>());
0329 }
0330 
0331 BOOST_AUTO_TEST_SUITE_END()
0332 
0333 BOOST_AUTO_TEST_SUITE_END()
0334 
0335 }  // namespace Acts::Test