From 3b12c86adef35ed3ec35f0d9bc4f010b2315a32f Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Thu, 4 Dec 2025 13:32:21 +0100 Subject: [PATCH 01/18] Add ProtoAxisHelper --- .../Acts/Utilities/ProtoAxisHelpers.hpp | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 Core/include/Acts/Utilities/ProtoAxisHelpers.hpp diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp new file mode 100644 index 00000000000..8ddbbc9e629 --- /dev/null +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -0,0 +1,117 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma once + +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/Utilities/AxisDefinitions.hpp" +#include "Acts/Utilities/BinningData.hpp" +#include "Acts/Utilities/BinningType.hpp" +#include "Acts/Utilities/Enumerate.hpp" +#include "Acts/Utilities/ProtoAxis.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Acts { + +/// @brief Get the number of bins from a ProtoAxis +/// @param axis DirectedProtoAxis object +/// @return Number of bins in the axis +inline std::size_t binsOfProtoAxis(DirectedProtoAxis& axis) { + return axis.getAxis().getNBins(); +} + +/// @brief Get the total number of bins from multiple ProtoAxes +/// @param axes Vector of DirectedProtoAxis objects +/// @return Total number of bins across all axes +inline std::size_t totalBinsFromProtoAxes( + const std::vector& axes) { + return axes[0].getAxis().getNBins() * + (axes.size() > 1 ? axes[1].getAxis().getNBins() : 1) * + (axes.size() > 2 ? axes[2].getAxis().getNBins() : 1); +} + +/// @brief Get the number of bins from a specific ProtoAxis in a collection +/// @param axes DirectedProtoAxis vector +/// @param ba Bin axis index +/// @return Number of bins in the specified axis +inline std::size_t binsFromProtoAxes(std::vector axes, + std::size_t ba) { + BinningData bd(axes[ba]); + return bd.bins(); +} + +/// @brief Get the bin index from a ProtoAxis using local coordinates +/// @param axis DirectedProtoAxis object +/// @param lp Local position vector +/// @return Bin index corresponding to the local position +inline std::size_t binFromProtoAxis(const DirectedProtoAxis& axis, + const Vector2& lp) { + BinningData bd(axis); + return bd.searchLocal(lp); +} + +/// @brief Get the bin index from a ProtoAxis using global coordinates +/// @param axis DirectedProtoAxis object +/// @param gp Global position vector +/// @return Bin index corresponding to the global position +inline std::size_t binFromProtoAxis(const DirectedProtoAxis& axis, + const Vector3& gp) { + BinningData bd(axis); + const Transform3& invTransform3 = Transform3::Identity().inverse(); + return bd.searchGlobal(invTransform3 * gp); +} + +/// @brief Get the bin triple from multiple ProtoAxes using global coordinates +/// @param axes Vector of DirectedProtoAxis objects +/// @param gp Global position vector +/// @return Array of bin indices corresponding to the global position for each axis +inline std::array binTripleFromProtoAxes( + const std::vector& axes, const Vector3& gp) { + const Transform3& invTransform3 = Transform3::Identity().inverse(); + const Vector3& bPosition = invTransform3 * gp; + std::array bTriple = {0, 0, 0}; + if (axes.size() > 0) { + BinningData bd0(axes[0]); + bTriple[0] = bd0.searchGlobal(bPosition); + } + if (axes.size() > 1) { + BinningData bd1(axes[1]); + bTriple[1] = bd1.searchGlobal(bPosition); + } + if (axes.size() > 2) { + BinningData bd2(axes[2]); + bTriple[2] = bd2.searchGlobal(bPosition); + } + return bTriple; +} + +/// @brief Get the maximum bin index from a specific ProtoAxis in a collection +/// @param axes DirectedProtoAxis vector +/// @param ba Bin axis index +/// @return Maximum bin index in the specified axis +inline std::size_t maxBin(std::vector& axes, + std::size_t ba = 0) const { + std::vector binningDataVec; + binningDataVec.reserve(axes.size()); + for (const auto& axis : axes) { + binningDataVec.emplace_back(BinningData(axis)); + } + if (ba >= binningDataVec.size()) { + return 0; + } + return (binningDataVec[ba].bins() - 1); +} + +} // namespace Acts \ No newline at end of file From 31f4a1e34212531dfc1996f41e6896390fa0937c Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Thu, 4 Dec 2025 13:38:49 +0100 Subject: [PATCH 02/18] Remove unnecessary header files --- .../include/Acts/Utilities/ProtoAxisHelpers.hpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index 8ddbbc9e629..0c0f39d507c 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -8,18 +8,15 @@ #pragma once #include "Acts/Definitions/Algebra.hpp" -#include "Acts/Utilities/AxisDefinitions.hpp" #include "Acts/Utilities/BinningData.hpp" -#include "Acts/Utilities/BinningType.hpp" -#include "Acts/Utilities/Enumerate.hpp" #include "Acts/Utilities/ProtoAxis.hpp" -#include -#include -#include -#include -#include -#include +// #include +// #include +// #include +// #include +// #include +// #include #include #include @@ -102,7 +99,7 @@ inline std::array binTripleFromProtoAxes( /// @param ba Bin axis index /// @return Maximum bin index in the specified axis inline std::size_t maxBin(std::vector& axes, - std::size_t ba = 0) const { + std::size_t ba = 0) { std::vector binningDataVec; binningDataVec.reserve(axes.size()); for (const auto& axis : axes) { From 313e3ff9e9bc17b90583f74f9927bc40e9a258d1 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Thu, 4 Dec 2025 13:40:01 +0100 Subject: [PATCH 03/18] Remove unnecessary header files - again --- Core/include/Acts/Utilities/ProtoAxisHelpers.hpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index 0c0f39d507c..abc63cb69eb 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -10,13 +10,8 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Utilities/BinningData.hpp" #include "Acts/Utilities/ProtoAxis.hpp" +#include "Acts/Utilities/Transform3.hpp" -// #include -// #include -// #include -// #include -// #include -// #include #include #include From 5455b3c6f4fe3171b6f317ff8546c657c981a98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=20Elitez?= <108287101+delitez@users.noreply.github.com> Date: Thu, 4 Dec 2025 14:06:18 +0100 Subject: [PATCH 04/18] Apply suggestions from code review Co-authored-by: junggjo9 --- Core/include/Acts/Utilities/ProtoAxisHelpers.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index abc63cb69eb..b2384b2bfe2 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -20,7 +20,7 @@ namespace Acts { /// @brief Get the number of bins from a ProtoAxis /// @param axis DirectedProtoAxis object /// @return Number of bins in the axis -inline std::size_t binsOfProtoAxis(DirectedProtoAxis& axis) { +inline std::size_t binsOfProtoAxis(const DirectedProtoAxis& axis) { return axis.getAxis().getNBins(); } @@ -38,7 +38,7 @@ inline std::size_t totalBinsFromProtoAxes( /// @param axes DirectedProtoAxis vector /// @param ba Bin axis index /// @return Number of bins in the specified axis -inline std::size_t binsFromProtoAxes(std::vector axes, +inline std::size_t binsFromProtoAxes(const std::vector& axes, std::size_t ba) { BinningData bd(axes[ba]); return bd.bins(); @@ -61,8 +61,7 @@ inline std::size_t binFromProtoAxis(const DirectedProtoAxis& axis, inline std::size_t binFromProtoAxis(const DirectedProtoAxis& axis, const Vector3& gp) { BinningData bd(axis); - const Transform3& invTransform3 = Transform3::Identity().inverse(); - return bd.searchGlobal(invTransform3 * gp); + return bd.searchGlobal( gp); } /// @brief Get the bin triple from multiple ProtoAxes using global coordinates @@ -93,7 +92,7 @@ inline std::array binTripleFromProtoAxes( /// @param axes DirectedProtoAxis vector /// @param ba Bin axis index /// @return Maximum bin index in the specified axis -inline std::size_t maxBin(std::vector& axes, +inline std::size_t maxBin(const std::vector& axes, std::size_t ba = 0) { std::vector binningDataVec; binningDataVec.reserve(axes.size()); From 16e4177285558f8ba5078e2171e6c96b806be0b7 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Thu, 4 Dec 2025 16:43:05 +0100 Subject: [PATCH 05/18] pre-commit --- Core/include/Acts/Utilities/ProtoAxisHelpers.hpp | 7 +++---- Core/src/Material/AccumulatedSurfaceMaterial.cpp | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index b2384b2bfe2..34733ae18b5 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -61,7 +61,7 @@ inline std::size_t binFromProtoAxis(const DirectedProtoAxis& axis, inline std::size_t binFromProtoAxis(const DirectedProtoAxis& axis, const Vector3& gp) { BinningData bd(axis); - return bd.searchGlobal( gp); + return bd.searchGlobal(gp); } /// @brief Get the bin triple from multiple ProtoAxes using global coordinates @@ -70,8 +70,7 @@ inline std::size_t binFromProtoAxis(const DirectedProtoAxis& axis, /// @return Array of bin indices corresponding to the global position for each axis inline std::array binTripleFromProtoAxes( const std::vector& axes, const Vector3& gp) { - const Transform3& invTransform3 = Transform3::Identity().inverse(); - const Vector3& bPosition = invTransform3 * gp; + const Vector3& bPosition = gp; std::array bTriple = {0, 0, 0}; if (axes.size() > 0) { BinningData bd0(axes[0]); @@ -105,4 +104,4 @@ inline std::size_t maxBin(const std::vector& axes, return (binningDataVec[ba].bins() - 1); } -} // namespace Acts \ No newline at end of file +} // namespace Acts diff --git a/Core/src/Material/AccumulatedSurfaceMaterial.cpp b/Core/src/Material/AccumulatedSurfaceMaterial.cpp index 04952107e50..9fb08edc903 100644 --- a/Core/src/Material/AccumulatedSurfaceMaterial.cpp +++ b/Core/src/Material/AccumulatedSurfaceMaterial.cpp @@ -10,6 +10,7 @@ #include "Acts/Material/BinnedSurfaceMaterial.hpp" #include "Acts/Material/HomogeneousSurfaceMaterial.hpp" +#include "Acts/Utilities/ProtoAxisHelpers.hpp" #include From 974b3ab94e7980bd206f3e44f22052acbf6a4d80 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Fri, 5 Dec 2025 10:57:18 +0100 Subject: [PATCH 06/18] fix --- Core/include/Acts/Utilities/ProtoAxisHelpers.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index 34733ae18b5..d375799a566 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -10,7 +10,6 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Utilities/BinningData.hpp" #include "Acts/Utilities/ProtoAxis.hpp" -#include "Acts/Utilities/Transform3.hpp" #include #include From 2bfab616a678ad8a97ed7653efcadf1ca5e89a01 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Fri, 5 Dec 2025 15:12:58 +0100 Subject: [PATCH 07/18] clang-tidy suggestions --- Core/include/Acts/Utilities/ProtoAxisHelpers.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index d375799a566..fe4ae8c955a 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -71,17 +71,22 @@ inline std::array binTripleFromProtoAxes( const std::vector& axes, const Vector3& gp) { const Vector3& bPosition = gp; std::array bTriple = {0, 0, 0}; - if (axes.size() > 0) { + if (!axes.empty()) + throw std::runtime_error("No axes provided for binTripleFromProtoAxes"); + if (axes.size() == 1) { BinningData bd0(axes[0]); bTriple[0] = bd0.searchGlobal(bPosition); } - if (axes.size() > 1) { + if (axes.size() == 2) { BinningData bd1(axes[1]); bTriple[1] = bd1.searchGlobal(bPosition); } - if (axes.size() > 2) { + if (axes.size() == 3) { BinningData bd2(axes[2]); bTriple[2] = bd2.searchGlobal(bPosition); + } else { + throw std::runtime_error( + "Unsupported number of axes for binTripleFromProtoAxes"); } return bTriple; } From 333edf0c0500975a57735cbff0257b8fe109b263 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Mon, 8 Dec 2025 15:40:01 +0100 Subject: [PATCH 08/18] Change namespace --- .../Acts/Utilities/ProtoAxisHelpers.hpp | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index fe4ae8c955a..4cf3fe8f59d 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -14,12 +14,12 @@ #include #include -namespace Acts { +namespace ProtoAxisHelpers { /// @brief Get the number of bins from a ProtoAxis /// @param axis DirectedProtoAxis object /// @return Number of bins in the axis -inline std::size_t binsOfProtoAxis(const DirectedProtoAxis& axis) { +inline std::size_t binsOfProtoAxis(const Acts::DirectedProtoAxis& axis) { return axis.getAxis().getNBins(); } @@ -27,7 +27,7 @@ inline std::size_t binsOfProtoAxis(const DirectedProtoAxis& axis) { /// @param axes Vector of DirectedProtoAxis objects /// @return Total number of bins across all axes inline std::size_t totalBinsFromProtoAxes( - const std::vector& axes) { + const std::vector& axes) { return axes[0].getAxis().getNBins() * (axes.size() > 1 ? axes[1].getAxis().getNBins() : 1) * (axes.size() > 2 ? axes[2].getAxis().getNBins() : 1); @@ -37,9 +37,9 @@ inline std::size_t totalBinsFromProtoAxes( /// @param axes DirectedProtoAxis vector /// @param ba Bin axis index /// @return Number of bins in the specified axis -inline std::size_t binsFromProtoAxes(const std::vector& axes, - std::size_t ba) { - BinningData bd(axes[ba]); +inline std::size_t binsFromProtoAxes( + const std::vector& axes, std::size_t ba) { + Acts::BinningData bd(axes[ba]); return bd.bins(); } @@ -47,9 +47,9 @@ inline std::size_t binsFromProtoAxes(const std::vector& axes, /// @param axis DirectedProtoAxis object /// @param lp Local position vector /// @return Bin index corresponding to the local position -inline std::size_t binFromProtoAxis(const DirectedProtoAxis& axis, - const Vector2& lp) { - BinningData bd(axis); +inline std::size_t binFromProtoAxis(const Acts::DirectedProtoAxis& axis, + const Acts::Vector2& lp) { + Acts::BinningData bd(axis); return bd.searchLocal(lp); } @@ -57,9 +57,9 @@ inline std::size_t binFromProtoAxis(const DirectedProtoAxis& axis, /// @param axis DirectedProtoAxis object /// @param gp Global position vector /// @return Bin index corresponding to the global position -inline std::size_t binFromProtoAxis(const DirectedProtoAxis& axis, - const Vector3& gp) { - BinningData bd(axis); +inline std::size_t binFromProtoAxis(const Acts::DirectedProtoAxis& axis, + const Acts::Vector3& gp) { + Acts::BinningData bd(axis); return bd.searchGlobal(gp); } @@ -68,21 +68,21 @@ inline std::size_t binFromProtoAxis(const DirectedProtoAxis& axis, /// @param gp Global position vector /// @return Array of bin indices corresponding to the global position for each axis inline std::array binTripleFromProtoAxes( - const std::vector& axes, const Vector3& gp) { - const Vector3& bPosition = gp; + const std::vector& axes, const Acts::Vector3& gp) { + const Acts::Vector3& bPosition = gp; std::array bTriple = {0, 0, 0}; if (!axes.empty()) throw std::runtime_error("No axes provided for binTripleFromProtoAxes"); if (axes.size() == 1) { - BinningData bd0(axes[0]); + Acts::BinningData bd0(axes[0]); bTriple[0] = bd0.searchGlobal(bPosition); } if (axes.size() == 2) { - BinningData bd1(axes[1]); + Acts::BinningData bd1(axes[1]); bTriple[1] = bd1.searchGlobal(bPosition); } if (axes.size() == 3) { - BinningData bd2(axes[2]); + Acts::BinningData bd2(axes[2]); bTriple[2] = bd2.searchGlobal(bPosition); } else { throw std::runtime_error( @@ -95,12 +95,12 @@ inline std::array binTripleFromProtoAxes( /// @param axes DirectedProtoAxis vector /// @param ba Bin axis index /// @return Maximum bin index in the specified axis -inline std::size_t maxBin(const std::vector& axes, +inline std::size_t maxBin(const std::vector& axes, std::size_t ba = 0) { - std::vector binningDataVec; + std::vector binningDataVec; binningDataVec.reserve(axes.size()); for (const auto& axis : axes) { - binningDataVec.emplace_back(BinningData(axis)); + binningDataVec.emplace_back(axis); } if (ba >= binningDataVec.size()) { return 0; @@ -108,4 +108,4 @@ inline std::size_t maxBin(const std::vector& axes, return (binningDataVec[ba].bins() - 1); } -} // namespace Acts +} // namespace ProtoAxisHelpers From 2c5fbe21e0d485d44fc8d631abf7c923afe2a9fa Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Mon, 8 Dec 2025 15:43:34 +0100 Subject: [PATCH 09/18] Replace brackets with .at --- .../Acts/Utilities/ProtoAxisHelpers.hpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index 4cf3fe8f59d..4719475d2ea 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -28,9 +28,9 @@ inline std::size_t binsOfProtoAxis(const Acts::DirectedProtoAxis& axis) { /// @return Total number of bins across all axes inline std::size_t totalBinsFromProtoAxes( const std::vector& axes) { - return axes[0].getAxis().getNBins() * - (axes.size() > 1 ? axes[1].getAxis().getNBins() : 1) * - (axes.size() > 2 ? axes[2].getAxis().getNBins() : 1); + return axes.at(0).getAxis().getNBins() * + (axes.size() > 1 ? axes.at(1).getAxis().getNBins() : 1) * + (axes.size() > 2 ? axes.at(2).getAxis().getNBins() : 1); } /// @brief Get the number of bins from a specific ProtoAxis in a collection @@ -39,7 +39,7 @@ inline std::size_t totalBinsFromProtoAxes( /// @return Number of bins in the specified axis inline std::size_t binsFromProtoAxes( const std::vector& axes, std::size_t ba) { - Acts::BinningData bd(axes[ba]); + Acts::BinningData bd(axes.at(ba)); return bd.bins(); } @@ -74,16 +74,16 @@ inline std::array binTripleFromProtoAxes( if (!axes.empty()) throw std::runtime_error("No axes provided for binTripleFromProtoAxes"); if (axes.size() == 1) { - Acts::BinningData bd0(axes[0]); - bTriple[0] = bd0.searchGlobal(bPosition); + Acts::BinningData bd0(axes.at(0)); + bTriple.at(0) = bd0.searchGlobal(bPosition); } if (axes.size() == 2) { - Acts::BinningData bd1(axes[1]); - bTriple[1] = bd1.searchGlobal(bPosition); + Acts::BinningData bd1(axes.at(1)); + bTriple.at(1) = bd1.searchGlobal(bPosition); } if (axes.size() == 3) { - Acts::BinningData bd2(axes[2]); - bTriple[2] = bd2.searchGlobal(bPosition); + Acts::BinningData bd2(axes.at(2)); + bTriple.at(2) = bd2.searchGlobal(bPosition); } else { throw std::runtime_error( "Unsupported number of axes for binTripleFromProtoAxes"); @@ -105,7 +105,7 @@ inline std::size_t maxBin(const std::vector& axes, if (ba >= binningDataVec.size()) { return 0; } - return (binningDataVec[ba].bins() - 1); + return (binningDataVec.at(ba).bins() - 1); } } // namespace ProtoAxisHelpers From d72a02173fa24c7b16efca82729bbb58f60e95ee Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Mon, 8 Dec 2025 16:30:30 +0100 Subject: [PATCH 10/18] vector to span --- .../Acts/Utilities/ProtoAxisHelpers.hpp | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index 4719475d2ea..dcfed9c2592 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -11,6 +11,7 @@ #include "Acts/Utilities/BinningData.hpp" #include "Acts/Utilities/ProtoAxis.hpp" +#include #include #include @@ -27,10 +28,13 @@ inline std::size_t binsOfProtoAxis(const Acts::DirectedProtoAxis& axis) { /// @param axes Vector of DirectedProtoAxis objects /// @return Total number of bins across all axes inline std::size_t totalBinsFromProtoAxes( - const std::vector& axes) { - return axes.at(0).getAxis().getNBins() * - (axes.size() > 1 ? axes.at(1).getAxis().getNBins() : 1) * - (axes.size() > 2 ? axes.at(2).getAxis().getNBins() : 1); + std::span axes) { + if (axes.size() <= 0 || axes.size() > 3) { + throw std::runtime_error("Unsupported number of axes, must be 1-3"); + } + return axes[0].getAxis().getNBins() * + (axes.size() > 1 ? axes[1].getAxis().getNBins() : 1) * + (axes.size() > 2 ? axes[2].getAxis().getNBins() : 1); } /// @brief Get the number of bins from a specific ProtoAxis in a collection @@ -68,22 +72,23 @@ inline std::size_t binFromProtoAxis(const Acts::DirectedProtoAxis& axis, /// @param gp Global position vector /// @return Array of bin indices corresponding to the global position for each axis inline std::array binTripleFromProtoAxes( - const std::vector& axes, const Acts::Vector3& gp) { + std::span axes, const Acts::Vector3& gp) { const Acts::Vector3& bPosition = gp; std::array bTriple = {0, 0, 0}; - if (!axes.empty()) - throw std::runtime_error("No axes provided for binTripleFromProtoAxes"); + if (axes.size() <= 0 || axes.size() > 3) { + throw std::runtime_error("Unsupported number of axes, must be 1-3"); + } if (axes.size() == 1) { - Acts::BinningData bd0(axes.at(0)); - bTriple.at(0) = bd0.searchGlobal(bPosition); + Acts::BinningData bd0(axes[0]); + bTriple[0] = bd0.searchGlobal(bPosition); } if (axes.size() == 2) { - Acts::BinningData bd1(axes.at(1)); - bTriple.at(1) = bd1.searchGlobal(bPosition); + Acts::BinningData bd1(axes[1]); + bTriple[1] = bd1.searchGlobal(bPosition); } if (axes.size() == 3) { - Acts::BinningData bd2(axes.at(2)); - bTriple.at(2) = bd2.searchGlobal(bPosition); + Acts::BinningData bd2(axes[2]); + bTriple[2] = bd2.searchGlobal(bPosition); } else { throw std::runtime_error( "Unsupported number of axes for binTripleFromProtoAxes"); @@ -95,8 +100,11 @@ inline std::array binTripleFromProtoAxes( /// @param axes DirectedProtoAxis vector /// @param ba Bin axis index /// @return Maximum bin index in the specified axis -inline std::size_t maxBin(const std::vector& axes, +inline std::size_t maxBin(std::span axes, std::size_t ba = 0) { + if (axes.size() <= 0 || axes.size() > 3) { + throw std::runtime_error("Unsupported number of axes, must be 1-3"); + } std::vector binningDataVec; binningDataVec.reserve(axes.size()); for (const auto& axis : axes) { From 24437c3c89b2a015b06ac74ee049a7852d14d28f Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Mon, 8 Dec 2025 16:40:36 +0100 Subject: [PATCH 11/18] forgotten span --- Core/include/Acts/Utilities/ProtoAxisHelpers.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index dcfed9c2592..557b0a38dc3 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -42,8 +42,11 @@ inline std::size_t totalBinsFromProtoAxes( /// @param ba Bin axis index /// @return Number of bins in the specified axis inline std::size_t binsFromProtoAxes( - const std::vector& axes, std::size_t ba) { - Acts::BinningData bd(axes.at(ba)); + std::span axes, std::size_t ba) { + if (axes.size() <= 0 || axes.size() > 3) { + throw std::runtime_error("Unsupported number of axes, must be 1-3"); + } + Acts::BinningData bd(axes[ba]); return bd.bins(); } From 32f07405a82e43f22c0f0b1766261c4dd9ca36d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=20Elitez?= <108287101+delitez@users.noreply.github.com> Date: Tue, 9 Dec 2025 13:38:03 +0100 Subject: [PATCH 12/18] Update comments --- Core/include/Acts/Utilities/ProtoAxisHelpers.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index 557b0a38dc3..40df7fda94a 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -25,7 +25,7 @@ inline std::size_t binsOfProtoAxis(const Acts::DirectedProtoAxis& axis) { } /// @brief Get the total number of bins from multiple ProtoAxes -/// @param axes Vector of DirectedProtoAxis objects +/// @param axes Span of DirectedProtoAxis objects /// @return Total number of bins across all axes inline std::size_t totalBinsFromProtoAxes( std::span axes) { @@ -38,7 +38,7 @@ inline std::size_t totalBinsFromProtoAxes( } /// @brief Get the number of bins from a specific ProtoAxis in a collection -/// @param axes DirectedProtoAxis vector +/// @param axes DirectedProtoAxis span /// @param ba Bin axis index /// @return Number of bins in the specified axis inline std::size_t binsFromProtoAxes( @@ -71,7 +71,7 @@ inline std::size_t binFromProtoAxis(const Acts::DirectedProtoAxis& axis, } /// @brief Get the bin triple from multiple ProtoAxes using global coordinates -/// @param axes Vector of DirectedProtoAxis objects +/// @param axes Span of DirectedProtoAxis objects /// @param gp Global position vector /// @return Array of bin indices corresponding to the global position for each axis inline std::array binTripleFromProtoAxes( @@ -100,7 +100,7 @@ inline std::array binTripleFromProtoAxes( } /// @brief Get the maximum bin index from a specific ProtoAxis in a collection -/// @param axes DirectedProtoAxis vector +/// @param axes DirectedProtoAxis span /// @param ba Bin axis index /// @return Maximum bin index in the specified axis inline std::size_t maxBin(std::span axes, From 023e0b8aaae271c7f0cfe32c686ad85a68b8f60e Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:20:31 +0100 Subject: [PATCH 13/18] Change namespace --- Core/include/Acts/Utilities/ProtoAxisHelpers.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index 40df7fda94a..bcff992ba9e 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -15,7 +15,7 @@ #include #include -namespace ProtoAxisHelpers { +namespace Acts::ProtoAxisHelpers { /// @brief Get the number of bins from a ProtoAxis /// @param axis DirectedProtoAxis object @@ -30,7 +30,8 @@ inline std::size_t binsOfProtoAxis(const Acts::DirectedProtoAxis& axis) { inline std::size_t totalBinsFromProtoAxes( std::span axes) { if (axes.size() <= 0 || axes.size() > 3) { - throw std::runtime_error("Unsupported number of axes, must be 1-3"); + throw std::runtime_error("Unsupported number of axes, must be 1-3, instead got " + + std::to_string(axes.size()) + ")"); } return axes[0].getAxis().getNBins() * (axes.size() > 1 ? axes[1].getAxis().getNBins() : 1) * @@ -44,7 +45,8 @@ inline std::size_t totalBinsFromProtoAxes( inline std::size_t binsFromProtoAxes( std::span axes, std::size_t ba) { if (axes.size() <= 0 || axes.size() > 3) { - throw std::runtime_error("Unsupported number of axes, must be 1-3"); + throw std::runtime_error("Unsupported number of axes, must be 1-3, instead got " + + std::to_string(axes.size()) + ")"); } Acts::BinningData bd(axes[ba]); return bd.bins(); @@ -79,7 +81,8 @@ inline std::array binTripleFromProtoAxes( const Acts::Vector3& bPosition = gp; std::array bTriple = {0, 0, 0}; if (axes.size() <= 0 || axes.size() > 3) { - throw std::runtime_error("Unsupported number of axes, must be 1-3"); + throw std::runtime_error("Unsupported number of axes, must be 1-3, instead got " + + std::to_string(axes.size()) + ")"); } if (axes.size() == 1) { Acts::BinningData bd0(axes[0]); @@ -106,7 +109,8 @@ inline std::array binTripleFromProtoAxes( inline std::size_t maxBin(std::span axes, std::size_t ba = 0) { if (axes.size() <= 0 || axes.size() > 3) { - throw std::runtime_error("Unsupported number of axes, must be 1-3"); + throw std::runtime_error("Unsupported number of axes, must be 1-3, instead got " + + std::to_string(axes.size()) + ")"); } std::vector binningDataVec; binningDataVec.reserve(axes.size()); From d79281eaa4bb262d48587f46c65727f98d52fd8d Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Tue, 9 Dec 2025 15:30:45 +0100 Subject: [PATCH 14/18] pre commit argh --- .../Acts/Utilities/ProtoAxisHelpers.hpp | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index bcff992ba9e..8ed459e3d14 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -30,8 +30,9 @@ inline std::size_t binsOfProtoAxis(const Acts::DirectedProtoAxis& axis) { inline std::size_t totalBinsFromProtoAxes( std::span axes) { if (axes.size() <= 0 || axes.size() > 3) { - throw std::runtime_error("Unsupported number of axes, must be 1-3, instead got " + - std::to_string(axes.size()) + ")"); + throw std::runtime_error( + "Unsupported number of axes, must be 1-3, instead got " + + std::to_string(axes.size()) + ")"); } return axes[0].getAxis().getNBins() * (axes.size() > 1 ? axes[1].getAxis().getNBins() : 1) * @@ -45,8 +46,9 @@ inline std::size_t totalBinsFromProtoAxes( inline std::size_t binsFromProtoAxes( std::span axes, std::size_t ba) { if (axes.size() <= 0 || axes.size() > 3) { - throw std::runtime_error("Unsupported number of axes, must be 1-3, instead got " + - std::to_string(axes.size()) + ")"); + throw std::runtime_error( + "Unsupported number of axes, must be 1-3, instead got " + + std::to_string(axes.size()) + ")"); } Acts::BinningData bd(axes[ba]); return bd.bins(); @@ -81,8 +83,9 @@ inline std::array binTripleFromProtoAxes( const Acts::Vector3& bPosition = gp; std::array bTriple = {0, 0, 0}; if (axes.size() <= 0 || axes.size() > 3) { - throw std::runtime_error("Unsupported number of axes, must be 1-3, instead got " + - std::to_string(axes.size()) + ")"); + throw std::runtime_error( + "Unsupported number of axes, must be 1-3, instead got " + + std::to_string(axes.size()) + ")"); } if (axes.size() == 1) { Acts::BinningData bd0(axes[0]); @@ -109,8 +112,9 @@ inline std::array binTripleFromProtoAxes( inline std::size_t maxBin(std::span axes, std::size_t ba = 0) { if (axes.size() <= 0 || axes.size() > 3) { - throw std::runtime_error("Unsupported number of axes, must be 1-3, instead got " + - std::to_string(axes.size()) + ")"); + throw std::runtime_error( + "Unsupported number of axes, must be 1-3, instead got " + + std::to_string(axes.size()) + ")"); } std::vector binningDataVec; binningDataVec.reserve(axes.size()); @@ -123,4 +127,4 @@ inline std::size_t maxBin(std::span axes, return (binningDataVec.at(ba).bins() - 1); } -} // namespace ProtoAxisHelpers +} // namespace Acts::ProtoAxisHelpers From 1b8db398ec02d21e0b13fcd0bad5d0b6990a04ad Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Wed, 10 Dec 2025 10:30:31 +0100 Subject: [PATCH 15/18] fix clang-tidy --- Core/include/Acts/Utilities/ProtoAxisHelpers.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index 8ed459e3d14..895a2a1bee8 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -29,7 +29,7 @@ inline std::size_t binsOfProtoAxis(const Acts::DirectedProtoAxis& axis) { /// @return Total number of bins across all axes inline std::size_t totalBinsFromProtoAxes( std::span axes) { - if (axes.size() <= 0 || axes.size() > 3) { + if (axes.empty() || axes.size() > 3) { throw std::runtime_error( "Unsupported number of axes, must be 1-3, instead got " + std::to_string(axes.size()) + ")"); @@ -45,7 +45,7 @@ inline std::size_t totalBinsFromProtoAxes( /// @return Number of bins in the specified axis inline std::size_t binsFromProtoAxes( std::span axes, std::size_t ba) { - if (axes.size() <= 0 || axes.size() > 3) { + if (axes.empty() || axes.size() > 3) { throw std::runtime_error( "Unsupported number of axes, must be 1-3, instead got " + std::to_string(axes.size()) + ")"); @@ -82,7 +82,7 @@ inline std::array binTripleFromProtoAxes( std::span axes, const Acts::Vector3& gp) { const Acts::Vector3& bPosition = gp; std::array bTriple = {0, 0, 0}; - if (axes.size() <= 0 || axes.size() > 3) { + if (axes.empty() || axes.size() > 3) { throw std::runtime_error( "Unsupported number of axes, must be 1-3, instead got " + std::to_string(axes.size()) + ")"); @@ -111,7 +111,7 @@ inline std::array binTripleFromProtoAxes( /// @return Maximum bin index in the specified axis inline std::size_t maxBin(std::span axes, std::size_t ba = 0) { - if (axes.size() <= 0 || axes.size() > 3) { + if (axes.empty() || axes.size() > 3) { throw std::runtime_error( "Unsupported number of axes, must be 1-3, instead got " + std::to_string(axes.size()) + ")"); From cd004704178b1f5ed18356a6e83b5e1f0247aa2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=20Elitez?= <108287101+delitez@users.noreply.github.com> Date: Wed, 10 Dec 2025 13:47:59 +0100 Subject: [PATCH 16/18] Update Core/include/Acts/Utilities/ProtoAxisHelpers.hpp Co-authored-by: Andreas Stefl --- Core/include/Acts/Utilities/ProtoAxisHelpers.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp index 895a2a1bee8..675621d61a7 100644 --- a/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp +++ b/Core/include/Acts/Utilities/ProtoAxisHelpers.hpp @@ -98,9 +98,6 @@ inline std::array binTripleFromProtoAxes( if (axes.size() == 3) { Acts::BinningData bd2(axes[2]); bTriple[2] = bd2.searchGlobal(bPosition); - } else { - throw std::runtime_error( - "Unsupported number of axes for binTripleFromProtoAxes"); } return bTriple; } From 7c3646f3911b882827e68865b524eb25d9b69e0a Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Thu, 11 Dec 2025 13:54:42 +0100 Subject: [PATCH 17/18] DirectedProtoAxes in accumulated surface material --- .../Material/AccumulatedSurfaceMaterial.hpp | 14 ++++ .../Acts/Material/BinnedSurfaceMaterial.hpp | 38 ++++++++++ .../Material/AccumulatedSurfaceMaterial.cpp | 73 ++++++++++++++----- Core/src/Material/BinnedSurfaceMaterial.cpp | 17 +++++ 4 files changed, 122 insertions(+), 20 deletions(-) diff --git a/Core/include/Acts/Material/AccumulatedSurfaceMaterial.hpp b/Core/include/Acts/Material/AccumulatedSurfaceMaterial.hpp index 85c522e8414..6073c345861 100644 --- a/Core/include/Acts/Material/AccumulatedSurfaceMaterial.hpp +++ b/Core/include/Acts/Material/AccumulatedSurfaceMaterial.hpp @@ -12,6 +12,8 @@ #include "Acts/Material/AccumulatedMaterialSlab.hpp" #include "Acts/Material/MaterialSlab.hpp" #include "Acts/Utilities/BinUtility.hpp" +#include "Acts/Utilities/ProtoAxis.hpp" +#include "Acts/Utilities/ProtoAxisHelpers.hpp" #include #include @@ -54,6 +56,12 @@ class AccumulatedSurfaceMaterial { explicit AccumulatedSurfaceMaterial(const BinUtility& binUtility, double splitFactor = 0.); + /// constructor using DirectedProtoAxes for binning + /// @param axes span of DirectedProtoAxis objects defining the binning + /// @param splitFactor is the pre/post splitting directive + AccumulatedSurfaceMaterial(const std::vector& axes, + double splitFactor = 0.); + /// Copy Constructor /// /// @param asma is the source object to be copied @@ -85,6 +93,9 @@ class AccumulatedSurfaceMaterial { /// @return Reference to the bin utility used for material binning const BinUtility& binUtility() const; + /// Return the proto axes + const std::vector& axes() const { return m_axes; } + /// Assign a material properties object /// /// @param lp local position for the bin assignment @@ -155,6 +166,9 @@ class AccumulatedSurfaceMaterial { /// The helper for the bin finding BinUtility m_binUtility{}; + /// The proto axes used for binning + std::vector m_axes{}; + /// the split factor double m_splitFactor{0.}; diff --git a/Core/include/Acts/Material/BinnedSurfaceMaterial.hpp b/Core/include/Acts/Material/BinnedSurfaceMaterial.hpp index 3b288eacf73..211a9df6744 100644 --- a/Core/include/Acts/Material/BinnedSurfaceMaterial.hpp +++ b/Core/include/Acts/Material/BinnedSurfaceMaterial.hpp @@ -12,6 +12,7 @@ #include "Acts/Material/ISurfaceMaterial.hpp" #include "Acts/Material/MaterialSlab.hpp" #include "Acts/Utilities/BinUtility.hpp" +#include "Acts/Utilities/ProtoAxis.hpp" #include @@ -62,6 +63,40 @@ class BinnedSurfaceMaterial : public ISurfaceMaterial { double splitFactor = 0., MappingType mappingType = MappingType::Default); + /// Explicit constructor with only full MaterialSlab, + /// for one-dimensional binning. + /// + /// The split factors: + /// - 1. : oppositePre + /// - 0. : alongPre + /// ===> 1 Dimensional array + /// + /// @param axes defines the binning structure on the surface (copied) + /// @param fullProperties is the vector of properties as recorded (moved) + /// @param splitFactor is the pre/post splitting directive + /// @param mappingType is the type of surface mapping associated to the surface + BinnedSurfaceMaterial(const std::vector& axes, + MaterialSlabVector fullProperties, + double splitFactor = 0., + MappingType mappingType = MappingType::Default); + + /// Explicit constructor with only full MaterialSlab, + /// for two-dimensional binning. + /// + /// The split factors: + /// - 1. : oppositePre + /// - 0. : alongPre + /// ===> 1 Dimensional array + /// + /// @param axes defines the binning structure on the surface (DirectedProtoAxis) (copied) + /// @param fullProperties is the vector of properties as recorded (moved) + /// @param splitFactor is the pre/post splitting directive + /// @param mappingType is the type of surface mapping associated to the surface + BinnedSurfaceMaterial(const std::vector& axes, + MaterialSlabMatrix fullProperties, + double splitFactor = 0., + MappingType mappingType = MappingType::Default); + /// Copy Move Constructor /// /// @param bsm is the source object to be copied @@ -114,6 +149,9 @@ class BinnedSurfaceMaterial : public ISurfaceMaterial { /// The helper for the bin finding BinUtility m_binUtility; + /// The proto axes used for binning + std::vector m_axes{}; + /// The five different MaterialSlab MaterialSlabMatrix m_fullMaterial; }; diff --git a/Core/src/Material/AccumulatedSurfaceMaterial.cpp b/Core/src/Material/AccumulatedSurfaceMaterial.cpp index 9fb08edc903..0f87db36ed3 100644 --- a/Core/src/Material/AccumulatedSurfaceMaterial.cpp +++ b/Core/src/Material/AccumulatedSurfaceMaterial.cpp @@ -22,6 +22,7 @@ Acts::AccumulatedSurfaceMaterial::AccumulatedSurfaceMaterial(double splitFactor) } // Binned Material constructor with split factor +// TODO: Remove this constructor after DirectedProtoAxis migration Acts::AccumulatedSurfaceMaterial::AccumulatedSurfaceMaterial( const BinUtility& binUtility, double splitFactor) : m_binUtility(binUtility), m_splitFactor(splitFactor) { @@ -31,15 +32,39 @@ Acts::AccumulatedSurfaceMaterial::AccumulatedSurfaceMaterial( m_accumulatedMaterial = AccumulatedMatrix(bins1, accVec); } +// Constructor using DirectedProtoAxes for binning +Acts::AccumulatedSurfaceMaterial::AccumulatedSurfaceMaterial( + const std::vector& axes, double splitFactor) + : m_axes(axes), m_splitFactor(splitFactor) { + if (m_axes.size() < 1 || m_axes.size() > 2) { + throw std::invalid_argument( + "AccumulatedSurfaceMaterial: At least one, maximum 2 proto axis is " + "required for binning."); + } + if (m_axes.size() == 1) { + std::size_t bins0 = m_axes[0].getAxis().getNBins(); + AccumulatedVector accVec(bins0, AccumulatedMaterialSlab()); + m_accumulatedMaterial = AccumulatedMatrix(1, accVec); + return; + } + if (m_axes.size() == 2) { + std::size_t bins0 = m_axes[0].getAxis().getNBins(); + std::size_t bins1 = m_axes[1].getAxis().getNBins(); + AccumulatedVector accVec(bins0, AccumulatedMaterialSlab()); + m_accumulatedMaterial = AccumulatedMatrix(bins1, accVec); + return; + } +} + // Assign a material properties object std::array Acts::AccumulatedSurfaceMaterial::accumulate( const Vector2& lp, const MaterialSlab& mp, double pathCorrection) { - if (m_binUtility.dimensions() == 0) { + if (m_axes.empty()) { m_accumulatedMaterial[0][0].accumulate(mp, pathCorrection); return {0, 0, 0}; } - std::size_t bin0 = m_binUtility.bin(lp, 0); - std::size_t bin1 = m_binUtility.bin(lp, 1); + std::size_t bin0 = Acts::ProtoAxisHelpers::binFromProtoAxis(m_axes[0], lp); + std::size_t bin1 = Acts::ProtoAxisHelpers::binFromProtoAxis(m_axes[1], lp); m_accumulatedMaterial[bin1][bin0].accumulate(mp, pathCorrection); return {bin0, bin1, 0}; } @@ -47,11 +72,12 @@ std::array Acts::AccumulatedSurfaceMaterial::accumulate( // Assign a material properties object std::array Acts::AccumulatedSurfaceMaterial::accumulate( const Vector3& gp, const MaterialSlab& mp, double pathCorrection) { - if (m_binUtility.dimensions() == 0) { + if (m_axes.empty()) { m_accumulatedMaterial[0][0].accumulate(mp, pathCorrection); return {0, 0, 0}; } - std::array bTriple = m_binUtility.binTriple(gp); + std::array bTriple = + Acts::ProtoAxisHelpers::binTripleFromProtoAxes(m_axes, gp); m_accumulatedMaterial[bTriple[1]][bTriple[0]].accumulate(mp, pathCorrection); return bTriple; } @@ -60,11 +86,12 @@ std::array Acts::AccumulatedSurfaceMaterial::accumulate( void Acts::AccumulatedSurfaceMaterial::trackVariance(const Vector3& gp, MaterialSlab slabReference, bool emptyHit) { - if (m_binUtility.dimensions() == 0) { + if (m_axes.empty()) { m_accumulatedMaterial[0][0].trackVariance(slabReference, emptyHit); return; } - std::array bTriple = m_binUtility.binTriple(gp); + std::array bTriple = + Acts::ProtoAxisHelpers::binTripleFromProtoAxes(m_axes, gp); std::vector> trackBins = {bTriple}; trackVariance(trackBins, slabReference); } @@ -74,7 +101,7 @@ void Acts::AccumulatedSurfaceMaterial::trackVariance( const std::vector>& trackBins, MaterialSlab slabReference, bool emptyHit) { // the homogeneous material case - if (m_binUtility.dimensions() == 0) { + if (m_axes.empty()) { m_accumulatedMaterial[0][0].trackVariance(slabReference, emptyHit); return; } @@ -96,12 +123,13 @@ void Acts::AccumulatedSurfaceMaterial::trackVariance( // Void average for vacuum assignment void Acts::AccumulatedSurfaceMaterial::trackAverage(const Vector3& gp, bool emptyHit) { - if (m_binUtility.dimensions() == 0) { + if (m_axes.empty()) { m_accumulatedMaterial[0][0].trackAverage(emptyHit); return; } - std::array bTriple = m_binUtility.binTriple(gp); + std::array bTriple = + Acts::ProtoAxisHelpers::binTripleFromProtoAxes(m_axes, gp); std::vector> trackBins = {bTriple}; trackAverage(trackBins, emptyHit); } @@ -110,7 +138,8 @@ void Acts::AccumulatedSurfaceMaterial::trackAverage(const Vector3& gp, void Acts::AccumulatedSurfaceMaterial::trackAverage( const std::vector>& trackBins, bool emptyHit) { // the homogeneous material case - if (m_binUtility.dimensions() == 0) { + // the homogeneous material case + if (m_axes.size() == 0) { m_accumulatedMaterial[0][0].trackAverage(emptyHit); return; } @@ -133,22 +162,26 @@ void Acts::AccumulatedSurfaceMaterial::trackAverage( /// Total average creates SurfaceMaterial std::unique_ptr Acts::AccumulatedSurfaceMaterial::totalAverage() { - if (m_binUtility.bins() == 1) { + std::cout << "AccumulatedSurfaceMaterial::totalAverage called with " + << m_axes.size() << " axes." << std::endl; + if (ProtoAxisHelpers::totalBinsFromProtoAxes(m_axes) <= 1) { // Return HomogeneousSurfaceMaterial return std::make_unique( m_accumulatedMaterial[0][0].totalAverage().first, m_splitFactor); } - // Create the properties matrix + + // number of bins per axis from DirectedProtoAxis + std::size_t bins0 = m_axes[0].getAxis().getNBins(); + std::size_t bins1 = m_axes[1].getAxis().getNBins(); + + // build the material-property matrix and fill from accumulated data MaterialSlabMatrix mpMatrix( - m_binUtility.bins(1), - MaterialSlabVector(m_binUtility.bins(0), MaterialSlab::Nothing())); - // Loop over and fill - for (std::size_t ib1 = 0; ib1 < m_binUtility.bins(1); ++ib1) { - for (std::size_t ib0 = 0; ib0 < m_binUtility.bins(0); ++ib0) { + bins1, MaterialSlabVector(bins0, MaterialSlab::Nothing())); + for (std::size_t ib1 = 0; ib1 < bins1; ++ib1) { + for (std::size_t ib0 = 0; ib0 < bins0; ++ib0) { mpMatrix[ib1][ib0] = m_accumulatedMaterial[ib1][ib0].totalAverage().first; } } - // Now return the BinnedSurfaceMaterial return std::make_unique( - m_binUtility, std::move(mpMatrix), m_splitFactor); + m_axes, std::move(mpMatrix), m_splitFactor); } diff --git a/Core/src/Material/BinnedSurfaceMaterial.cpp b/Core/src/Material/BinnedSurfaceMaterial.cpp index aae46bd02d7..448ef334782 100644 --- a/Core/src/Material/BinnedSurfaceMaterial.cpp +++ b/Core/src/Material/BinnedSurfaceMaterial.cpp @@ -29,6 +29,23 @@ Acts::BinnedSurfaceMaterial::BinnedSurfaceMaterial( m_binUtility(binUtility), m_fullMaterial(std::move(fullProperties)) {} +Acts::BinnedSurfaceMaterial::BinnedSurfaceMaterial( + const std::vector& axes, + MaterialSlabVector fullProperties, double splitFactor, + Acts::MappingType mappingType) + : ISurfaceMaterial(splitFactor, mappingType), m_axes(axes) { + // fill the material with deep copy + m_fullMaterial.push_back(std::move(fullProperties)); +} + +Acts::BinnedSurfaceMaterial::BinnedSurfaceMaterial( + const std::vector& axes, + MaterialSlabMatrix fullProperties, double splitFactor, + Acts::MappingType mappingType) + : ISurfaceMaterial(splitFactor, mappingType), + m_axes(axes), + m_fullMaterial(std::move(fullProperties)) {} + Acts::BinnedSurfaceMaterial& Acts::BinnedSurfaceMaterial::scale(double factor) { for (auto& materialVector : m_fullMaterial) { for (auto& materialBin : materialVector) { From cb81fab51d277e3b158d193f6723a021fda45252 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Thu, 11 Dec 2025 13:59:06 +0100 Subject: [PATCH 18/18] Fix accumulated surface material test --- .../AccumulatedSurfaceMaterialTests.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Tests/UnitTests/Core/Material/AccumulatedSurfaceMaterialTests.cpp b/Tests/UnitTests/Core/Material/AccumulatedSurfaceMaterialTests.cpp index 4e94f0f92e3..d6435266142 100644 --- a/Tests/UnitTests/Core/Material/AccumulatedSurfaceMaterialTests.cpp +++ b/Tests/UnitTests/Core/Material/AccumulatedSurfaceMaterialTests.cpp @@ -39,17 +39,19 @@ BOOST_AUTO_TEST_CASE(AccumulatedSurfaceMaterial_construction_test) { // Test: // BinsSurfaceMaterial accumulation - 1D - BinUtility binUtility1D(10, -5., 5., open, AxisDirection::AxisX); - AccumulatedSurfaceMaterial material1D{binUtility1D}; - auto accMat1D = material1D.accumulatedMaterial(); - BOOST_CHECK_EQUAL(accMat1D.size(), 1u); - BOOST_CHECK_EQUAL(accMat1D[0].size(), 10u); + DirectedProtoAxis axis00(AxisDirection::AxisX, AxisBoundaryType::Open, -5., + 5., 10); + std::vector axes0 = {axis00}; + AccumulatedSurfaceMaterial material1D{axes0}; // Test: // BinsSurfaceMaterial accumulation - 2D - BinUtility binUtility2D(10, -5., 5., open, AxisDirection::AxisX); - binUtility2D += BinUtility(20, -10., 10., open, AxisDirection::AxisY); - AccumulatedSurfaceMaterial material2D{binUtility2D}; + DirectedProtoAxis axis10(AxisDirection::AxisX, AxisBoundaryType::Open, -5., + 5., 10); + DirectedProtoAxis axis11(AxisDirection::AxisY, AxisBoundaryType::Open, -10., + 10., 20); + std::vector axes1 = {axis10, axis11}; + AccumulatedSurfaceMaterial material2D{axes1}; auto accMat2D = material2D.accumulatedMaterial(); BOOST_CHECK_EQUAL(accMat2D.size(), 20u); for (std::size_t ib = 0; ib < accMat2D.size(); ++ib) { @@ -95,9 +97,12 @@ BOOST_AUTO_TEST_CASE(AccumulatedSurfaceMaterial_fill_convert_1D) { MaterialSlab four(mat, 4.); // BinsSurfaceMaterial accumulation - 2D - BinUtility binUtility2D(2, -1., 1., open, AxisDirection::AxisX); - binUtility2D += BinUtility(2, -1., 1., open, AxisDirection::AxisY); - AccumulatedSurfaceMaterial material2D{binUtility2D}; + DirectedProtoAxis axis0{AxisDirection::AxisX, AxisBoundaryType::Open, -1., 1., + 2}; + DirectedProtoAxis axis1{AxisDirection::AxisY, AxisBoundaryType::Open, -1., 1., + 2}; + std::vector axes = {axis0, axis1}; + AccumulatedSurfaceMaterial material2D{axes}; const std::vector> bin; // assign in the different bins