Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-30 07:55:20

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;
0025 using namespace Acts::UnitLiterals;
0026 
0027 namespace ActsTests {
0028 
0029 BOOST_AUTO_TEST_SUITE(GeometrySuite)
0030 
0031 BOOST_AUTO_TEST_SUITE(TrackingVolumeTests)
0032 
0033 std::size_t countVolumes(const TrackingVolume& tv) {
0034   std::size_t count = 0;
0035   tv.visitVolumes([&count](const auto&) { ++count; });
0036   return count;
0037 }
0038 
0039 BOOST_AUTO_TEST_CASE(TrackigVolumeChildren) {
0040   auto cylBounds = std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 100_mm);
0041 
0042   TrackingVolume tv{Transform3::Identity(), cylBounds};
0043 
0044   BOOST_CHECK(tv.volumes().empty());
0045   BOOST_CHECK_EQUAL(countVolumes(tv), 1);
0046 
0047   auto& child1 = tv.addVolume(
0048       std::make_unique<TrackingVolume>(Transform3::Identity(), cylBounds));
0049 
0050   BOOST_CHECK_EQUAL(tv.volumes().size(), 1);
0051 
0052   auto it = tv.volumes().begin();
0053   static_assert(std::is_same_v<decltype(*it), TrackingVolume&>);
0054 
0055   const auto& tvConst = tv;
0056   auto cit = tvConst.volumes().begin();
0057   static_assert(std::is_same_v<decltype(*cit), const TrackingVolume&>);
0058 
0059   BOOST_CHECK_EQUAL(&*it, &child1);
0060 
0061   BOOST_CHECK_EQUAL(countVolumes(tv), 2);
0062 
0063   tv.addVolume(
0064       std::make_unique<TrackingVolume>(Transform3::Identity(), cylBounds));
0065 
0066   BOOST_CHECK_EQUAL(countVolumes(tv), 3);
0067 }
0068 
0069 namespace {
0070 void testVisitor(auto visitor) {
0071   BOOST_CHECK(!visitor.m_surfaceCalled);
0072   BOOST_CHECK(!visitor.m_volumeCalled);
0073   BOOST_CHECK(!visitor.m_boundaryCalled);
0074   BOOST_CHECK(!visitor.m_layerCalled);
0075   BOOST_CHECK(!visitor.m_portalCalled);
0076 
0077   auto surface = Surface::makeShared<PlaneSurface>(
0078       Transform3::Identity(), std::make_shared<RectangleBounds>(10_mm, 10_mm));
0079 
0080   visitor.visitSurface(*surface);
0081   BOOST_CHECK(visitor.m_surfaceCalled);
0082 
0083   auto cylBounds = std::make_shared<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 = std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 100_mm);
0190 
0191   TrackingVolume tv{Transform3::Identity(), cylBounds};
0192   visitor.visitVolume(tv);
0193 
0194   BOOST_CHECK(volumeCalled);
0195 
0196   BoundarySurfaceT<TrackingVolume> boundary{surface, &tv, nullptr};
0197   visitor.visitBoundarySurface(boundary);
0198   BOOST_CHECK(boundaryCalled);
0199 
0200   LayerStub layer{nullptr};
0201   visitor.visitLayer(layer);
0202   BOOST_CHECK(layerCalled);
0203 
0204   Portal portal{Direction::AlongNormal(), surface, tv};
0205   visitor.visitPortal(portal);
0206   BOOST_CHECK(portalCalled);
0207 
0208   volumeCalled = false;
0209   tv.apply(visitor);
0210   BOOST_CHECK(volumeCalled);
0211 }
0212 
0213 BOOST_AUTO_TEST_CASE(VisitLambdaMutable) {
0214   bool surfaceCalled = false;
0215   bool volumeCalled = false;
0216   bool boundaryCalled = false;
0217   bool layerCalled = false;
0218   bool portalCalled = false;
0219 
0220   auto overload = overloaded{
0221       [&](Surface& /*surface*/) { surfaceCalled = true; },
0222       [&](TrackingVolume& /*volume*/) { volumeCalled = true; },
0223       [&](BoundarySurfaceT<TrackingVolume>& /*boundary*/) {
0224         boundaryCalled = true;
0225       },
0226       [&](Layer& /*layer*/) { layerCalled = true; },
0227       [&](Portal& /*portal*/) { portalCalled = true; },
0228   };
0229 
0230   auto visitor = detail::TrackingGeometryLambdaMutableVisitor{overload};
0231 
0232   auto surface = Surface::makeShared<PlaneSurface>(
0233       Transform3::Identity(), std::make_shared<RectangleBounds>(10_mm, 10_mm));
0234 
0235   visitor.visitSurface(*surface);
0236   BOOST_CHECK(surfaceCalled);
0237 
0238   auto cylBounds = std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 100_mm);
0239 
0240   TrackingVolume tv{Transform3::Identity(), cylBounds};
0241   visitor.visitVolume(tv);
0242 
0243   BOOST_CHECK(volumeCalled);
0244 
0245   BoundarySurfaceT<TrackingVolume> boundary{surface, &tv, nullptr};
0246   visitor.visitBoundarySurface(boundary);
0247   BOOST_CHECK(boundaryCalled);
0248 
0249   LayerStub layer{nullptr};
0250   visitor.visitLayer(layer);
0251   BOOST_CHECK(layerCalled);
0252 
0253   Portal portal{Direction::AlongNormal(), surface, tv};
0254   visitor.visitPortal(portal);
0255   BOOST_CHECK(portalCalled);
0256 
0257   volumeCalled = false;
0258   tv.apply(overload);
0259   BOOST_CHECK(volumeCalled);
0260 
0261   volumeCalled = false;
0262   tv.apply([&](Volume& /*volume*/) { volumeCalled = true; });
0263   BOOST_CHECK(volumeCalled);
0264 }
0265 
0266 BOOST_AUTO_TEST_CASE(CallableWithAny) {
0267   // Test callableWithAny
0268   static_assert(
0269       detail::callableWithAny<decltype([](Surface& /*surface*/) {})>());
0270   static_assert(
0271       detail::callableWithAny<decltype([](const Surface& /*surface*/) {})>());
0272   static_assert(detail::callableWithAny<decltype([](Portal& /*portal*/) {})>());
0273   static_assert(
0274       detail::callableWithAny<decltype([](const Portal& /*portal*/) {})>());
0275   static_assert(
0276       detail::callableWithAny<decltype([](TrackingVolume& /*volume*/) {})>());
0277   static_assert(!detail::callableWithAny<decltype([](int /*x*/) {})>());
0278   static_assert(!detail::callableWithAny<decltype([](void* /*ptr*/) {})>());
0279 
0280   // Test callableWithAnyConst specifically
0281   static_assert(detail::callableWithAnyConst<
0282                 decltype([](const Surface& /*surface*/) {})>());
0283   static_assert(detail::callableWithAnyConst<
0284                 decltype([](const TrackingVolume& /*volume*/) {})>());
0285   static_assert(
0286       detail::callableWithAnyConst<decltype([](const Layer& /*layer*/) {})>());
0287   static_assert(!detail::callableWithAnyConst<decltype([](int /*x*/) {})>());
0288   static_assert(
0289       !detail::callableWithAnyConst<decltype([](void* /*ptr*/) {})>());
0290 
0291   // Test callableWithAnyMutable specifically
0292   static_assert(
0293       detail::callableWithAnyMutable<decltype([](Surface& /*surface*/) {})>());
0294   static_assert(detail::callableWithAnyMutable<
0295                 decltype([](TrackingVolume& /*volume*/) {})>());
0296   static_assert(
0297       detail::callableWithAnyMutable<decltype([](Layer& /*layer*/) {})>());
0298   static_assert(!detail::callableWithAnyMutable<decltype([](int /*x*/) {})>());
0299   static_assert(
0300       !detail::callableWithAnyMutable<decltype([](void* /*ptr*/) {})>());
0301 
0302   // Test mixed const/non-const overloads
0303   static_assert(detail::callableWithAny<decltype(overloaded{
0304                     [](Surface& /*surface*/) {},
0305                     [](const TrackingVolume& /*volume*/) {},
0306                 })>());
0307 
0308   // Test with unrelated overloads
0309   static_assert(!detail::callableWithAny<decltype(overloaded{
0310                     [](int /*x*/) {},
0311                     [](double /*y*/) {},
0312                     [](const std::string& /*s*/) {},
0313                 })>());
0314 
0315   // Test with mix of geometry and unrelated overloads
0316   static_assert(detail::callableWithAny<decltype(overloaded{
0317                     [](int /*x*/) {},
0318                     [](Surface& /*surface*/) {},
0319                     [](const std::string& /*s*/) {},
0320                 })>());
0321 
0322   static_assert(detail::callableWithAny<decltype(overloaded{
0323                     [](void* /*ptr*/) {},
0324                     [](const Portal& /*portal*/) {},
0325                     [](double /*d*/) {},
0326                 })>());
0327 }
0328 
0329 BOOST_AUTO_TEST_SUITE_END()
0330 
0331 BOOST_AUTO_TEST_SUITE_END()
0332 
0333 }  // namespace ActsTests