diff --git a/Core/include/Acts/Detector/Blueprint.hpp b/Core/include/Acts/Detector/Blueprint.hpp index b3724f3fec5..e593c45b034 100644 --- a/Core/include/Acts/Detector/Blueprint.hpp +++ b/Core/include/Acts/Detector/Blueprint.hpp @@ -10,10 +10,10 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Definitions/Common.hpp" -#include "Acts/Detector/ProtoBinning.hpp" #include "Acts/Geometry/Extent.hpp" #include "Acts/Geometry/VolumeBounds.hpp" #include "Acts/Utilities/AxisDefinitions.hpp" +#include "Acts/Utilities/ProtoAxis.hpp" #include "Acts/Utilities/StringHelpers.hpp" #include @@ -99,7 +99,7 @@ struct Node final { std::vector binning = {}; /// Portal proto material binning - std::map portalMaterialBinning = {}; + std::map> portalMaterialBinning = {}; /// Auxiliary information std::vector auxiliary = {}; diff --git a/Core/include/Acts/Detector/CylindricalContainerBuilder.hpp b/Core/include/Acts/Detector/CylindricalContainerBuilder.hpp index 2abc41327fb..475608b54ae 100644 --- a/Core/include/Acts/Detector/CylindricalContainerBuilder.hpp +++ b/Core/include/Acts/Detector/CylindricalContainerBuilder.hpp @@ -10,11 +10,11 @@ #include "Acts/Detector/Blueprint.hpp" #include "Acts/Detector/DetectorComponents.hpp" -#include "Acts/Detector/ProtoBinning.hpp" #include "Acts/Detector/interface/IDetectorComponentBuilder.hpp" #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Utilities/AxisDefinitions.hpp" #include "Acts/Utilities/Logger.hpp" +#include "Acts/Utilities/ProtoAxis.hpp" #include #include @@ -56,7 +56,7 @@ class CylindricalContainerBuilder : public IDetectorComponentBuilder { /// The geometry id generator std::shared_ptr geoIdGenerator = nullptr; /// Material binning to be assigned to portals - std::map portalMaterialBinning = {}; + std::map> portalMaterialBinning = {}; /// An eventual reverse geometry id generation bool geoIdReverseGen = false; /// Auxiliary information, mainly for screen output diff --git a/Core/include/Acts/Detector/DetectorVolumeBuilder.hpp b/Core/include/Acts/Detector/DetectorVolumeBuilder.hpp index 6cb5e6647db..4360f19c2ac 100644 --- a/Core/include/Acts/Detector/DetectorVolumeBuilder.hpp +++ b/Core/include/Acts/Detector/DetectorVolumeBuilder.hpp @@ -9,10 +9,10 @@ #pragma once #include "Acts/Detector/DetectorComponents.hpp" -#include "Acts/Detector/ProtoBinning.hpp" #include "Acts/Detector/interface/IDetectorComponentBuilder.hpp" #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Utilities/Logger.hpp" +#include "Acts/Utilities/ProtoAxis.hpp" #include #include @@ -43,7 +43,7 @@ class DetectorVolumeBuilder : public IDetectorComponentBuilder { /// The geometry id generator std::shared_ptr geoIdGenerator = nullptr; /// Material binning to be assigned to portals - std::map portalMaterialBinning = {}; + std::map> portalMaterialBinning = {}; /// Add eventual internal volume to root bool addInternalsToRoot = false; /// Auxiliary information diff --git a/Core/include/Acts/Detector/LayerStructureBuilder.hpp b/Core/include/Acts/Detector/LayerStructureBuilder.hpp index 02fd726824e..51750a42d60 100644 --- a/Core/include/Acts/Detector/LayerStructureBuilder.hpp +++ b/Core/include/Acts/Detector/LayerStructureBuilder.hpp @@ -10,15 +10,13 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Detector/DetectorComponents.hpp" -#include "Acts/Detector/ProtoBinning.hpp" #include "Acts/Detector/ProtoSupport.hpp" #include "Acts/Detector/interface/IInternalStructureBuilder.hpp" #include "Acts/Detector/interface/ISurfacesProvider.hpp" #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Surfaces/Surface.hpp" -#include "Acts/Utilities/BinningData.hpp" -#include "Acts/Utilities/BinningType.hpp" #include "Acts/Utilities/Logger.hpp" +#include "Acts/Utilities/ProtoAxis.hpp" #include #include @@ -84,7 +82,7 @@ class LayerStructureBuilder : public IInternalStructureBuilder { /// Definition of Supports std::vector supports = {}; /// Definition of Binnings - std::vector binnings = {}; + std::vector binnings = {}; /// Optional extent (if already parsed), will trigger binning autorange /// check std::optional extent = std::nullopt; diff --git a/Core/include/Acts/Detector/MultiWireStructureBuilder.hpp b/Core/include/Acts/Detector/MultiWireStructureBuilder.hpp index 48159bf806c..3967ea0fac6 100644 --- a/Core/include/Acts/Detector/MultiWireStructureBuilder.hpp +++ b/Core/include/Acts/Detector/MultiWireStructureBuilder.hpp @@ -9,13 +9,13 @@ #pragma once #include "Acts/Detector/LayerStructureBuilder.hpp" -#include "Acts/Detector/ProtoBinning.hpp" #include "Acts/Detector/interface/IDetectorComponentBuilder.hpp" #include "Acts/Detector/interface/IExternalStructureBuilder.hpp" #include "Acts/Detector/interface/IInternalStructureBuilder.hpp" #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Surfaces/Surface.hpp" #include "Acts/Utilities/Logger.hpp" +#include "Acts/Utilities/ProtoAxis.hpp" #include #include @@ -41,7 +41,7 @@ class MultiWireStructureBuilder { std::vector mlBounds = {}; // The binning of the multi wire structure - std::vector mlBinning = {}; + std::vector mlBinning = {}; /// A tolerance config float toleranceOverlap = 10.; diff --git a/Core/include/Acts/Detector/ProtoBinning.hpp b/Core/include/Acts/Detector/ProtoBinning.hpp deleted file mode 100644 index 231405d5991..00000000000 --- a/Core/include/Acts/Detector/ProtoBinning.hpp +++ /dev/null @@ -1,192 +0,0 @@ -// 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/Definitions/Common.hpp" -#include "Acts/Utilities/AxisDefinitions.hpp" -#include "Acts/Utilities/BinUtility.hpp" - -#include -#include -#include -#include - -namespace Acts::Experimental { - -/// @brief Simple helper class to define a binning structure -/// -/// @note no checks are performed on the consistency, this is -/// only for convenience that the binning can be defined and then -/// translated into concrete axis types -struct ProtoBinning { - /// The axis direction - AxisDirection axisDir; - /// The axis type: equidistant or variable - Acts::AxisType axisType = Acts::AxisType::Equidistant; - /// The axis boundary type: Open, Bound or Closed - Acts::AxisBoundaryType boundaryType = Acts::AxisBoundaryType::Bound; - /// The binning edges - std::vector edges = {}; - /// An expansion for the filling (in bins) - std::size_t expansion = 0u; - /// Indication if this is an auto-range binning - bool autorange = false; - - /// Convenience constructors - for variable binning - /// - /// @param aDir the value/cast in which this is binned - /// @param bType the axis boundary type - /// @param e the bin edges (variable binning) - /// @param exp the expansion (in bins) - ProtoBinning(AxisDirection aDir, Acts::AxisBoundaryType bType, - const std::vector& e, std::size_t exp = 0u) - : axisDir(aDir), - axisType(Acts::AxisType::Variable), - boundaryType(bType), - edges(e), - expansion(exp) { - if (edges.size() < 2u) { - throw std::invalid_argument( - "ProtoBinning: Invalid binning, at least two edges are needed."); - } - } - - /// Convenience constructors - for equidistant binning - /// - /// @param aDir the value/cast in which this is binned - /// @param bType the axis boundary type - /// @param minE the lowest edge of the binning - /// @param maxE the highest edge of the binning - /// @param nbins the number of bins - /// @param exp the expansion (in bins) - ProtoBinning(AxisDirection aDir, Acts::AxisBoundaryType bType, double minE, - double maxE, std::size_t nbins, std::size_t exp = 0u) - : axisDir(aDir), boundaryType(bType), expansion(exp) { - if (minE >= maxE) { - std::string msg = "ProtoBinning: Invalid axis range for direction '"; - msg += axisDirectionName(axisDir); - msg += "', min edge (" + std::to_string(minE) + ") "; - msg += " needs to be smaller than max edge ("; - msg += std::to_string(maxE) + ")."; - throw std::invalid_argument(msg); - } - if (nbins < 1u) { - throw std::invalid_argument( - "ProtoBinning: Invalid binning, at least one bin is needed."); - } - - double stepE = (maxE - minE) / nbins; - edges.reserve(nbins + 1); - for (std::size_t i = 0; i <= nbins; i++) { - edges.push_back(minE + i * stepE); - } - } - - /// Placeholder constructors - for equidistant binning - /// - /// @note this is designed to give a binning prescription - /// when the actual extent is not yet evaluated, only works - /// for equidistant binning obviously - /// - /// @param aDir the value/cast in which this is binned - /// @param bType the axis boundary type - /// @param nbins the number of bins - /// @param exp the expansion (in bins) - ProtoBinning(AxisDirection aDir, Acts::AxisBoundaryType bType, - std::size_t nbins, std::size_t exp = 0u) - : axisDir(aDir), - boundaryType(bType), - edges(nbins + 1, 0.), - expansion(exp), - autorange(true) {} - - // Return the number of bins - std::size_t bins() const { return edges.size() - 1u; } - - // Screen output - std::string toString() const { - std::stringstream ss; - ss << "ProtoBinning: " << bins() << " bins in " - << axisDirectionName(axisDir); - ss << (axisType == Acts::AxisType::Variable ? ", variable " - : ", equidistant "); - if (!autorange) { - ss << "within [" << edges.front() << ", " << edges.back() << "] "; - } else { - ss << "within automatic range"; - } - return ss.str(); - } -}; - -/// @brief A binning description, it helps for screen output -struct BinningDescription { - /// Convert the binning description into a bin utility - /// - /// @param binUtility the bin utility to be converted into a BinningDescription - static BinningDescription fromBinUtility(const BinUtility& binUtility) { - BinningDescription bDesc; - for (const auto& bData : binUtility.binningData()) { - // One proto binning per binning data - Acts::AxisBoundaryType boundaryType = - bData.option == open ? Acts::AxisBoundaryType::Bound - : Acts::AxisBoundaryType::Closed; - std::vector edges; - if (bData.type == equidistant) { - bDesc.binning.push_back(ProtoBinning(bData.binvalue, boundaryType, - bData.min, bData.max, bData.bins(), - 0u)); - - } else { - std::for_each(bData.boundaries().begin(), bData.boundaries().end(), - [&](double edge) { edges.push_back(edge); }); - bDesc.binning.push_back( - ProtoBinning(bData.binvalue, boundaryType, edges, 0u)); - } - } - return bDesc; - } - - /// Convert to a BinUtility - only basic types are supported - /// - BinUtility toBinUtility() const { - BinUtility binUtility; - for (const auto& b : binning) { - Acts::BinningOption bOption = - b.boundaryType == Acts::AxisBoundaryType::Bound ? Acts::open - : Acts::closed; - if (b.axisType == Acts::AxisType::Equidistant) { - binUtility += BinUtility(b.bins(), b.edges.front(), b.edges.back(), - bOption, b.axisDir); - } else { - std::vector edges; - std::for_each(b.edges.begin(), b.edges.end(), - [&](double edge) { edges.push_back(edge); }); - binUtility += BinUtility(edges, bOption, b.axisDir); - } - } - return binUtility; - } - - /// The contained binnings - std::vector binning; - - // Screen output - std::string toString() const { - std::stringstream ss; - ss << "BinningDescription: " << binning.size() << "D" << std::endl; - for (const auto& b : binning) { - ss << " " << b.toString() << std::endl; - } - return ss.str(); - } -}; - -} // namespace Acts::Experimental diff --git a/Core/include/Acts/Detector/ProtoSupport.hpp b/Core/include/Acts/Detector/ProtoSupport.hpp index 2c02bd2ba22..e9f5417290c 100644 --- a/Core/include/Acts/Detector/ProtoSupport.hpp +++ b/Core/include/Acts/Detector/ProtoSupport.hpp @@ -10,10 +10,10 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Definitions/Common.hpp" -#include "Acts/Detector/ProtoBinning.hpp" #include "Acts/Surfaces/Surface.hpp" #include "Acts/Utilities/AxisDefinitions.hpp" #include "Acts/Utilities/BinningData.hpp" +#include "Acts/Utilities/ProtoAxis.hpp" #include #include @@ -63,7 +63,7 @@ struct ProtoSupport { std::shared_ptr surface = nullptr; /// The (optional) binning description for proto material - std::optional protoMaterialBinning = std::nullopt; + std::optional> protoMaterialBinning = std::nullopt; /// Potential splits into planar approximations (valid for cylinder/disc) unsigned int splits = 1u; diff --git a/Core/include/Acts/Detector/detail/IndexedSurfacesGenerator.hpp b/Core/include/Acts/Detector/detail/IndexedSurfacesGenerator.hpp index 08fc8043d99..039a6add303 100644 --- a/Core/include/Acts/Detector/detail/IndexedSurfacesGenerator.hpp +++ b/Core/include/Acts/Detector/detail/IndexedSurfacesGenerator.hpp @@ -17,89 +17,113 @@ #include #include -namespace Acts::Experimental::detail { +namespace Acts::detail::IndexedSurfacesGenerator { -/// @brief A templated indexed grid generator. +/// Factory method to create a 1D indexed surface grid /// -/// This Generator creates a InternalNavigationDelegate delegate -/// which can then be used in the DetectorVolume class for updating -/// given surface candidates based on an index grid. -/// -/// It allows for: -/// - certain indices being forcly assigned to all bins -/// - a chosen expansion to fill indices in neighborhood bins -/// -/// @tparam objects_container the objects container -template class indexed_updator> -struct IndexedSurfacesGenerator { - /// The surfaces to be indexed - /// (including surfaces that are assigned to all bins) - surface_container surfaces = {}; - // Indices of surfaces that are to be assigned to all bins - std::vector assignToAll = {}; - /// The binning for the indexing - std::vector bValues = {}; - // Bin expansion - std::vector binExpansion = {}; - /// The transform into the local binning schema - Transform3 transform = Transform3::Identity(); - /// Screen output logger - std::unique_ptr oLogger = - getDefaultLogger("IndexedSurfacesGenerator", Logging::INFO); - - /// Create the Surface candidate updator - /// - /// @tparam axis_generator does generate the axis of the grid - /// @tparam reference_generator does generate the reference query points - /// - /// @param gctx the geometry context - /// @param aGenerator the axis generator - /// @param rGenerator the reference generataor - /// - /// @return an InternalNavigationDelegate - template - InternalNavigationDelegate operator()( - const GeometryContext& gctx, const axis_generator& aGenerator, - const reference_generator& rGenerator) const { - ACTS_DEBUG("Indexing " << surfaces.size() << " surface, " - << assignToAll.size() << " of which into all bins."); - // Create the grid with the provided axis generator - using GridType = - typename axis_generator::template grid_type>; - GridType grid(std::move(aGenerator())); - - std::array bvArray = {}; - for (auto [ibv, bv] : enumerate(bValues)) { - bvArray[ibv] = bv; - } - - indexed_updator indexedSurfaces(std::move(grid), bvArray, - transform); - // Fill the bin indices - IndexedGridFiller filler{binExpansion}; - filler.oLogger = oLogger->cloneWithSuffix("_filler"); +/// @param gctx the geometry context +/// @param surfaces the surfaces to be indexed +/// @param rGenerator the reference generator +/// @param pAxis the proto axis +/// @param assignToAll the indices assigned to all bins +/// @param transform the transform into the local binning schema +/// @return an internal navigation delegate +template