diff --git a/Core/include/Acts/Detector/detail/CylindricalDetectorHelper.hpp b/Core/include/Acts/Detector/detail/CylindricalDetectorHelper.hpp index c423f4fa689..e603c4fb0ef 100644 --- a/Core/include/Acts/Detector/detail/CylindricalDetectorHelper.hpp +++ b/Core/include/Acts/Detector/detail/CylindricalDetectorHelper.hpp @@ -172,12 +172,14 @@ DetectorComponent::PortalContainer wrapInZR( /// /// @param gctx the geometry context of the call /// @param volumes the volumes at input +/// @param precision the precision to be used for (optionally) /// @param logLevel is the screen logging level /// /// @return extracted boundary values template std::array, 3u> rzphiBoundaries( const GeometryContext& gctx, const volume_container_t& volumes, + double precision = 0., Acts::Logging::Level logLevel = Acts::Logging::INFO) { // The local logger ACTS_LOCAL_LOGGER(getDefaultLogger("CylindricalDetectorHelper", logLevel)); @@ -187,6 +189,13 @@ std::array, 3u> rzphiBoundaries( // The return boundaries std::array, 3u> uniqueBoundaries; + auto insertWithPrecision = [&](std::size_t is, ActsScalar value) -> void { + if (precision == 0.) { + uniqueBoundaries[is].insert(value); + return; + } + uniqueBoundaries[is].insert(std::round(value / precision) * precision); + }; // Loop over the volumes and collect boundaries for (const auto& v : volumes) { @@ -207,12 +216,12 @@ std::array, 3u> rzphiBoundaries( ActsScalar phiMin = phiCenter - phiSector; ActsScalar phiMax = phiCenter + phiSector; // Fill the sets - uniqueBoundaries[0].insert(rMin); - uniqueBoundaries[0].insert(rMax); - uniqueBoundaries[1].insert(zMin); - uniqueBoundaries[1].insert(zMax); - uniqueBoundaries[2].insert(phiMin); - uniqueBoundaries[2].insert(phiMax); + insertWithPrecision(0u, rMin); + insertWithPrecision(0u, rMax); + insertWithPrecision(1u, zMin); + insertWithPrecision(1u, zMax); + insertWithPrecision(2u, phiMin); + insertWithPrecision(2u, phiMax); } } diff --git a/Tests/UnitTests/Core/Detector/CylindricalDetectorHelperTests.cpp b/Tests/UnitTests/Core/Detector/CylindricalDetectorHelperTests.cpp index 52f9c273570..1695af9457d 100644 --- a/Tests/UnitTests/Core/Detector/CylindricalDetectorHelperTests.cpp +++ b/Tests/UnitTests/Core/Detector/CylindricalDetectorHelperTests.cpp @@ -646,7 +646,8 @@ BOOST_AUTO_TEST_CASE(RZPhiBoundaries) { std::vector> volumes = { innerV, middleLV, middleDV, middleUV, middleRV, outerV}; - auto boundaries = rzphiBoundaries(tContext, volumes, Acts::Logging::VERBOSE); + auto boundaries = + rzphiBoundaries(tContext, volumes, 0., Acts::Logging::VERBOSE); BOOST_CHECK(boundaries.size() == 3u); // Check the r boundaries std::vector rBoundaries = {0., 20., 40., 60., 120.}; @@ -657,4 +658,26 @@ BOOST_AUTO_TEST_CASE(RZPhiBoundaries) { BOOST_CHECK(boundaries[2u].size() == 2u); } +BOOST_AUTO_TEST_CASE(RZPhiBoundariesWithTolerance) { + auto innerB = std::make_unique(0., 20., 100); + auto innerV = DetectorVolumeFactory::construct( + portalGenerator, tContext, "Inner", Transform3::Identity(), + std::move(innerB), tryAllPortals()); + + auto outerB = std::make_unique(20.001, 100., 100); + auto outerV = DetectorVolumeFactory::construct( + portalGenerator, tContext, "Inner", Transform3::Identity(), + std::move(outerB), tryAllPortals()); + + std::vector> volumes = {innerV, outerV}; + + auto boundariesWoTol = + rzphiBoundaries(tContext, volumes, 0., Acts::Logging::VERBOSE); + BOOST_CHECK_EQUAL(boundariesWoTol[0u].size(), 4u); + + auto boundariesWTol = + rzphiBoundaries(tContext, volumes, 0.01, Acts::Logging::VERBOSE); + BOOST_CHECK_EQUAL(boundariesWTol[0u].size(), 3u); +} + BOOST_AUTO_TEST_SUITE_END()