Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow custom precision for volume grid building #2609

Merged
merged 12 commits into from
Nov 9, 2023
21 changes: 15 additions & 6 deletions Core/include/Acts/Detector/detail/CylindricalDetectorHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename volume_container_t>
std::array<std::vector<ActsScalar>, 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));
Expand All @@ -187,6 +189,13 @@ std::array<std::vector<ActsScalar>, 3u> rzphiBoundaries(

// The return boundaries
std::array<std::set<ActsScalar>, 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) {
Expand All @@ -207,12 +216,12 @@ std::array<std::vector<ActsScalar>, 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);
}
}

Expand Down
25 changes: 24 additions & 1 deletion Tests/UnitTests/Core/Detector/CylindricalDetectorHelperTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@ BOOST_AUTO_TEST_CASE(RZPhiBoundaries) {
std::vector<std::shared_ptr<DetectorVolume>> 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<ActsScalar> rBoundaries = {0., 20., 40., 60., 120.};
Expand All @@ -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<CylinderVolumeBounds>(0., 20., 100);
auto innerV = DetectorVolumeFactory::construct(
portalGenerator, tContext, "Inner", Transform3::Identity(),
std::move(innerB), tryAllPortals());

auto outerB = std::make_unique<CylinderVolumeBounds>(20.001, 100., 100);
auto outerV = DetectorVolumeFactory::construct(
portalGenerator, tContext, "Inner", Transform3::Identity(),
std::move(outerB), tryAllPortals());

std::vector<std::shared_ptr<DetectorVolume>> 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()
Loading