diff --git a/Core/include/Acts/Detector/Detector.hpp b/Core/include/Acts/Detector/Detector.hpp index bbdec5931d8..6ce3d4bc488 100644 --- a/Core/include/Acts/Detector/Detector.hpp +++ b/Core/include/Acts/Detector/Detector.hpp @@ -102,6 +102,13 @@ class Detector : public std::enable_shared_from_this { /// @return the map which can be queried with GeometryID for ranges const GeometryHierarchyMap& sensitiveHierarchyMap() const; + /// Search for a surface with the given identifier. + /// + /// @param id is the geometry identifier of the surface + /// @retval nullptr if no such surface exists + /// @retval pointer to the found surface otherwise. + const Surface* findSurface(GeometryIdentifier id) const; + /// @brief Visit all reachable surfaces of the detector /// /// @tparam visitor_t Type of the callable visitor diff --git a/Core/include/Acts/EventData/detail/TestSourceLink.hpp b/Core/include/Acts/EventData/detail/TestSourceLink.hpp index 421180eb279..d215867036c 100644 --- a/Core/include/Acts/EventData/detail/TestSourceLink.hpp +++ b/Core/include/Acts/EventData/detail/TestSourceLink.hpp @@ -10,6 +10,7 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Definitions/TrackParametrization.hpp" +#include "Acts/Detector/Detector.hpp" #include "Acts/EventData/MultiTrajectory.hpp" #include "Acts/EventData/SourceLink.hpp" #include "Acts/Geometry/GeometryContext.hpp" @@ -27,6 +28,8 @@ namespace Acts::detail::Test { +struct TestSourceLinkSurfaceAccessor; + /// A minimal source link implementation for testing. /// /// Instead of storing a reference to a measurement or raw data, the measurement @@ -35,6 +38,8 @@ namespace Acts::detail::Test { /// identifier is stored that can be used to store additional information. How /// this is interpreted depends on the specific tests. struct TestSourceLink final { + using SurfaceAccessor = TestSourceLinkSurfaceAccessor; + GeometryIdentifier m_geometryId{}; std::size_t sourceId = 0u; // use eBoundSize to indicate unused indices @@ -87,17 +92,30 @@ struct TestSourceLink final { return os; } constexpr std::size_t index() const { return sourceId; } +}; - struct SurfaceAccessor { - const Acts::TrackingGeometry& trackingGeometry; +struct TestSourceLinkSurfaceAccessor { + const TrackingGeometry& geometry; - const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const { - const auto& testSourceLink = sourceLink.get(); - return trackingGeometry.findSurface(testSourceLink.m_geometryId); - } - }; + const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const { + const auto& testSourceLink = sourceLink.get(); + return geometry.findSurface(testSourceLink.m_geometryId); + } }; +namespace Experimental { + +struct TestSourceLinkSurfaceAccessor { + const Acts::Experimental::Detector& geometry; + + const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const { + const auto& testSourceLink = sourceLink.get(); + return geometry.findSurface(testSourceLink.m_geometryId); + } +}; + +} // namespace Experimental + inline std::ostream& operator<<(std::ostream& os, const TestSourceLink& sourceLink) { return sourceLink.print(os); diff --git a/Core/src/Detector/Detector.cpp b/Core/src/Detector/Detector.cpp index 61a5e6b155c..c63fe1e8802 100644 --- a/Core/src/Detector/Detector.cpp +++ b/Core/src/Detector/Detector.cpp @@ -207,3 +207,8 @@ const Acts::GeometryHierarchyMap& Acts::Experimental::Detector::sensitiveHierarchyMap() const { return m_sensitiveHierarchyMap; } + +const Acts::Surface* Acts::Experimental::Detector::findSurface( + GeometryIdentifier geoID) const { + return *m_sensitiveHierarchyMap.find(geoID); +} diff --git a/Examples/Framework/include/ActsExamples/EventData/IndexSourceLink.hpp b/Examples/Framework/include/ActsExamples/EventData/IndexSourceLink.hpp index 0e532e8ff26..aaaac49d78a 100644 --- a/Examples/Framework/include/ActsExamples/EventData/IndexSourceLink.hpp +++ b/Examples/Framework/include/ActsExamples/EventData/IndexSourceLink.hpp @@ -8,6 +8,7 @@ #pragma once +#include "Acts/Detector/Detector.hpp" #include "Acts/EventData/SourceLink.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" #include "Acts/Surfaces/Surface.hpp" @@ -18,6 +19,8 @@ namespace ActsExamples { +struct IndexSourceLinkSurfaceAccessor; + /// A source link that stores just an index. /// /// This is intentionally kept as barebones as possible. The source link @@ -29,6 +32,8 @@ namespace ActsExamples { /// easily changed without having to also change the source link. class IndexSourceLink final { public: + using SurfaceAccessor = IndexSourceLinkSurfaceAccessor; + /// Construct from geometry identifier and index. constexpr IndexSourceLink(Acts::GeometryIdentifier gid, Index idx) : m_geometryId(gid), m_index(idx) {} @@ -46,15 +51,6 @@ class IndexSourceLink final { Acts::GeometryIdentifier geometryId() const { return m_geometryId; } - struct SurfaceAccessor { - const Acts::TrackingGeometry& trackingGeometry; - - const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const { - const auto& indexSourceLink = sourceLink.get(); - return trackingGeometry.findSurface(indexSourceLink.geometryId()); - } - }; - private: Acts::GeometryIdentifier m_geometryId; Index m_index = 0; @@ -70,6 +66,28 @@ class IndexSourceLink final { } }; +struct IndexSourceLinkSurfaceAccessor { + const Acts::TrackingGeometry& geometry; + + const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const { + const auto& indexSourceLink = sourceLink.get(); + return geometry.findSurface(indexSourceLink.geometryId()); + } +}; + +namespace Experimental { + +struct IndexSourceLinkSurfaceAccessor { + const Acts::Experimental::Detector& geometry; + + const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const { + const auto& indexSourceLink = sourceLink.get(); + return geometry.findSurface(indexSourceLink.geometryId()); + } +}; + +} // namespace Experimental + /// Container of index source links. /// /// Since the source links provide a `.geometryId()` accessor, they can be diff --git a/Tests/UnitTests/Core/Detector/DetectorTests.cpp b/Tests/UnitTests/Core/Detector/DetectorTests.cpp index 6f009e42523..d5fe8f18c11 100644 --- a/Tests/UnitTests/Core/Detector/DetectorTests.cpp +++ b/Tests/UnitTests/Core/Detector/DetectorTests.cpp @@ -264,7 +264,12 @@ BOOST_AUTO_TEST_CASE(DetectorConstructionWithHierarchyMap) { "DetWithSurfaces", {cylVolume}, Acts::Experimental::tryRootVolumes()); const auto& sensitiveHierarchyMap = det->sensitiveHierarchyMap(); + + const Acts::Surface* surface0 = + det->findSurface(Acts::GeometryIdentifier{}.setSensitive(1)); + BOOST_CHECK_EQUAL(sensitiveHierarchyMap.size(), 6u); + BOOST_CHECK_NE(surface0, nullptr); } BOOST_AUTO_TEST_SUITE_END() diff --git a/Tests/UnitTests/Core/EventData/SourceLinkTests.cpp b/Tests/UnitTests/Core/EventData/SourceLinkTests.cpp index 67b4bf1d890..ecd59253455 100644 --- a/Tests/UnitTests/Core/EventData/SourceLinkTests.cpp +++ b/Tests/UnitTests/Core/EventData/SourceLinkTests.cpp @@ -22,6 +22,7 @@ BOOST_AUTO_TEST_SUITE(EventDataSourceLink) BOOST_AUTO_TEST_CASE(TestSourceLinkCoverage) { using Acts::detail::Test::TestSourceLink; + TestSourceLink ts; Acts::Vector2 stddev(0.01, 0.1); Acts::SquareMatrix2 cov = stddev.cwiseProduct(stddev).asDiagonal();