Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:17

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Utilities/Grid.hpp"
0012 #include "Acts/Utilities/TypeList.hpp"
0013 #include "Acts/Utilities/detail/Axis.hpp"
0014 
0015 #include <array>
0016 #include <tuple>
0017 #include <vector>
0018 
0019 /// Axis generators are used to allow defining different grid types
0020 /// for indexed geometry objects.
0021 ///
0022 /// The call operator() API allows to plug axis generators into
0023 /// dedicated code snippets and create fitting axis types on the fly
0024 /// which then turn into concrete Grid types.
0025 namespace Acts::GridAxisGenerators {
0026 
0027 /// @brief  Templated base generator for equidistant axis as a tuple - 1D
0028 ///
0029 /// @tparam aType the type of the axis (Bound, Closed, Open)
0030 template <Acts::detail::AxisBoundaryType aType>
0031 struct Eq {
0032   /// Broadcast the return_type
0033   using return_type = std::tuple<
0034       Acts::detail::Axis<Acts::detail::AxisType::Equidistant, aType>>;
0035 
0036   /// Broadcast the grid type
0037   template <typename T>
0038   using grid_type = Acts::Grid<
0039       T, Acts::detail::Axis<Acts::detail::AxisType::Equidistant, aType>>;
0040 
0041   std::array<ActsScalar, 2u> range = {};
0042   std::size_t nBins = 0u;
0043 
0044   /// Call operator that generates the Axis
0045   return_type operator()() const {
0046     Acts::detail::Axis<Acts::detail::AxisType::Equidistant, aType> eAxis(
0047         range[0u], range[1u], nBins);
0048     return {eAxis};
0049   }
0050 };
0051 
0052 // All 1D equidistant options
0053 using EqBound = Eq<Acts::detail::AxisBoundaryType::Bound>;
0054 using EqOpen = Eq<Acts::detail::AxisBoundaryType::Open>;
0055 using EqClosed = Eq<Acts::detail::AxisBoundaryType::Closed>;
0056 
0057 /// @brief  Templated base generator for variable axis as a tuple - 1D
0058 ///
0059 /// @tparam aType the type of the axis (Bound, Closed, Open)
0060 template <Acts::detail::AxisBoundaryType aType>
0061 struct Var {
0062   /// Broadcast the return_type
0063   using return_type =
0064       std::tuple<Acts::detail::Axis<Acts::detail::AxisType::Variable, aType>>;
0065 
0066   /// Broadcast the grid type
0067   template <typename T>
0068   using grid_type =
0069       Acts::Grid<T,
0070                  Acts::detail::Axis<Acts::detail::AxisType::Variable, aType>>;
0071 
0072   std::vector<ActsScalar> edges = {};
0073 
0074   /// Call operator that generates the Axis
0075   return_type operator()() const {
0076     Acts::detail::Axis<Acts::detail::AxisType::Variable, aType> vAxis(edges);
0077     return {vAxis};
0078   }
0079 };
0080 
0081 // All 1D variable options
0082 using VarBound = Var<Acts::detail::AxisBoundaryType::Bound>;
0083 using VarOpen = Var<Acts::detail::AxisBoundaryType::Open>;
0084 using VarClosed = Var<Acts::detail::AxisBoundaryType::Closed>;
0085 
0086 /// @brief  Templated base generator for two equidistant axes as a tuple - 2D
0087 ///
0088 /// @tparam aType the type of the first axis (Bound, Closed, Open)
0089 /// @tparam bType the type of the second axis (Bound, Closed, Open)
0090 ///
0091 template <Acts::detail::AxisBoundaryType aType,
0092           Acts::detail::AxisBoundaryType bType>
0093 struct EqEq {
0094   /// Broadcast the return_type
0095   using return_type = std::tuple<
0096       Acts::detail::Axis<Acts::detail::AxisType::Equidistant, aType>,
0097       Acts::detail::Axis<Acts::detail::AxisType::Equidistant, bType>>;
0098 
0099   /// Broadcast the grid type
0100   template <typename T>
0101   using grid_type = Acts::Grid<
0102       T, Acts::detail::Axis<Acts::detail::AxisType::Equidistant, aType>,
0103       Acts::detail::Axis<Acts::detail::AxisType::Equidistant, bType>>;
0104 
0105   std::array<ActsScalar, 2u> range0 = {};
0106   std::size_t nBins0 = 0u;
0107   std::array<ActsScalar, 2u> range1 = {};
0108   std::size_t nBins1 = 1u;
0109 
0110   /// Call operator that generates the Axis
0111   return_type operator()() const {
0112     // Create the two axis
0113     Acts::detail::Axis<Acts::detail::AxisType::Equidistant, aType> aEq(
0114         range0[0u], range0[1u], nBins0);
0115     Acts::detail::Axis<Acts::detail::AxisType::Equidistant, bType> bEq(
0116         range1[0u], range1[1u], nBins1);
0117     return std::tie(aEq, bEq);
0118   }
0119 };
0120 
0121 // All 2D EqEq options
0122 using EqBoundEqBound = EqEq<Acts::detail::AxisBoundaryType::Bound,
0123                             Acts::detail::AxisBoundaryType::Bound>;
0124 using EqBoundEqOpen = EqEq<Acts::detail::AxisBoundaryType::Bound,
0125                            Acts::detail::AxisBoundaryType::Open>;
0126 using EqBoundEqClosed = EqEq<Acts::detail::AxisBoundaryType::Bound,
0127                              Acts::detail::AxisBoundaryType::Closed>;
0128 using EqOpenEqBound = EqEq<Acts::detail::AxisBoundaryType::Open,
0129                            Acts::detail::AxisBoundaryType::Bound>;
0130 using EqOpenEqOpen = EqEq<Acts::detail::AxisBoundaryType::Open,
0131                           Acts::detail::AxisBoundaryType::Open>;
0132 using EqOpenEqClosed = EqEq<Acts::detail::AxisBoundaryType::Open,
0133                             Acts::detail::AxisBoundaryType::Closed>;
0134 using EqClosedEqBound = EqEq<Acts::detail::AxisBoundaryType::Closed,
0135                              Acts::detail::AxisBoundaryType::Bound>;
0136 using EqClosedEqOpen = EqEq<Acts::detail::AxisBoundaryType::Closed,
0137                             Acts::detail::AxisBoundaryType::Open>;
0138 using EqClosedEqClosed = EqEq<Acts::detail::AxisBoundaryType::Closed,
0139                               Acts::detail::AxisBoundaryType::Closed>;
0140 
0141 /// @brief  Templated base generator for equidistant / variable axes as a tuple - 2D
0142 ///
0143 /// @tparam aType the type of the first axis (Bound, Closed, Open)
0144 /// @tparam bType the type of the second axis (Bound, Closed, Open)
0145 ///
0146 template <Acts::detail::AxisBoundaryType aType,
0147           Acts::detail::AxisBoundaryType bType>
0148 struct EqVar {
0149   /// Broadcast the return_type
0150   using return_type =
0151       std::tuple<Acts::detail::Axis<Acts::detail::AxisType::Equidistant, aType>,
0152                  Acts::detail::Axis<Acts::detail::AxisType::Variable, bType>>;
0153 
0154   /// Broadcast the grid type
0155   template <typename T>
0156   using grid_type =
0157       Acts::Grid<T,
0158                  Acts::detail::Axis<Acts::detail::AxisType::Equidistant, aType>,
0159                  Acts::detail::Axis<Acts::detail::AxisType::Variable, bType>>;
0160 
0161   std::array<ActsScalar, 2u> range = {};
0162   std::size_t nBins = 0u;
0163   std::vector<ActsScalar> edges = {};
0164 
0165   /// Call operator that generates the Axis
0166   return_type operator()() const {
0167     Acts::detail::Axis<Acts::detail::AxisType::Equidistant, aType> eqA(
0168         range[0u], range[1u], nBins);
0169     Acts::detail::Axis<Acts::detail::AxisType::Variable, bType> varB(edges);
0170     return std::tie(eqA, varB);
0171   }
0172 };
0173 
0174 // All 2D EqVar options
0175 using EqBoundVarBound = EqVar<Acts::detail::AxisBoundaryType::Bound,
0176                               Acts::detail::AxisBoundaryType::Bound>;
0177 using EqBoundVarOpen = EqVar<Acts::detail::AxisBoundaryType::Bound,
0178                              Acts::detail::AxisBoundaryType::Open>;
0179 using EqBoundVarClosed = EqVar<Acts::detail::AxisBoundaryType::Bound,
0180                                Acts::detail::AxisBoundaryType::Closed>;
0181 using EqOpenVarBound = EqVar<Acts::detail::AxisBoundaryType::Open,
0182                              Acts::detail::AxisBoundaryType::Bound>;
0183 using EqOpenVarOpen = EqVar<Acts::detail::AxisBoundaryType::Open,
0184                             Acts::detail::AxisBoundaryType::Open>;
0185 using EqOpenVarClosed = EqVar<Acts::detail::AxisBoundaryType::Open,
0186                               Acts::detail::AxisBoundaryType::Closed>;
0187 using EqClosedVarBound = EqVar<Acts::detail::AxisBoundaryType::Closed,
0188                                Acts::detail::AxisBoundaryType::Bound>;
0189 using EqClosedVarOpen = EqVar<Acts::detail::AxisBoundaryType::Closed,
0190                               Acts::detail::AxisBoundaryType::Open>;
0191 using EqClosedVarClosed = EqVar<Acts::detail::AxisBoundaryType::Closed,
0192                                 Acts::detail::AxisBoundaryType::Closed>;
0193 
0194 /// @brief  Templated base generator for a variable, equidistant axes tuple - 2D
0195 ///
0196 /// @tparam aType the type of the first axis (Bound, Closed, Open)
0197 /// @tparam bType the type of the second axis (Bound, Closed, Open)
0198 ///
0199 template <Acts::detail::AxisBoundaryType aType,
0200           Acts::detail::AxisBoundaryType bType>
0201 struct VarEq {
0202   /// Broadcast the return_type
0203   using return_type = std::tuple<
0204       Acts::detail::Axis<Acts::detail::AxisType::Variable, aType>,
0205       Acts::detail::Axis<Acts::detail::AxisType::Equidistant, bType>>;
0206 
0207   /// Broadcast the grid type
0208   template <typename T>
0209   using grid_type = Acts::Grid<
0210       T, Acts::detail::Axis<Acts::detail::AxisType::Variable, aType>,
0211       Acts::detail::Axis<Acts::detail::AxisType::Equidistant, bType>>;
0212 
0213   std::vector<ActsScalar> edges = {};
0214   std::array<ActsScalar, 2u> range = {};
0215   std::size_t nBins = 0u;
0216 
0217   /// Call operator that generates the Axis
0218   return_type operator()() const {
0219     Acts::detail::Axis<Acts::detail::AxisType::Variable, aType> varA(edges);
0220     Acts::detail::Axis<Acts::detail::AxisType::Equidistant, bType> eqB(
0221         range[0u], range[1u], nBins);
0222     return std::tie(varA, eqB);
0223   }
0224 };
0225 
0226 // All 2D VarEq options
0227 using VarBoundEqBound = VarEq<Acts::detail::AxisBoundaryType::Bound,
0228                               Acts::detail::AxisBoundaryType::Bound>;
0229 using VarBoundEqOpen = VarEq<Acts::detail::AxisBoundaryType::Bound,
0230                              Acts::detail::AxisBoundaryType::Open>;
0231 using VarBoundEqClosed = VarEq<Acts::detail::AxisBoundaryType::Bound,
0232                                Acts::detail::AxisBoundaryType::Closed>;
0233 using VarOpenEqBound = VarEq<Acts::detail::AxisBoundaryType::Open,
0234                              Acts::detail::AxisBoundaryType::Bound>;
0235 using VarOpenEqOpen = VarEq<Acts::detail::AxisBoundaryType::Open,
0236                             Acts::detail::AxisBoundaryType::Open>;
0237 using VarOpenEqClosed = VarEq<Acts::detail::AxisBoundaryType::Open,
0238                               Acts::detail::AxisBoundaryType::Closed>;
0239 using VarClosedEqBound = VarEq<Acts::detail::AxisBoundaryType::Closed,
0240                                Acts::detail::AxisBoundaryType::Bound>;
0241 using VarClosedEqOpen = VarEq<Acts::detail::AxisBoundaryType::Closed,
0242                               Acts::detail::AxisBoundaryType::Open>;
0243 using VarClosedEqClosed = VarEq<Acts::detail::AxisBoundaryType::Closed,
0244                                 Acts::detail::AxisBoundaryType::Closed>;
0245 
0246 /// @brief  Templated base generator for a two variable axes tuple - 2D
0247 ///
0248 /// @tparam aType the type of the first axis (Bound, Closed, Open)
0249 /// @tparam bType the type of the second axis (Bound, Closed, Open)
0250 ///
0251 template <Acts::detail::AxisBoundaryType aType,
0252           Acts::detail::AxisBoundaryType bType>
0253 struct VarVar {
0254   /// Broadcast the return_type
0255   using return_type =
0256       std::tuple<Acts::detail::Axis<Acts::detail::AxisType::Variable, aType>,
0257                  Acts::detail::Axis<Acts::detail::AxisType::Variable, bType>>;
0258 
0259   /// Broadcast the grid type
0260   template <typename T>
0261   using grid_type =
0262       Acts::Grid<T, Acts::detail::Axis<Acts::detail::AxisType::Variable, aType>,
0263                  Acts::detail::Axis<Acts::detail::AxisType::Variable, bType>>;
0264 
0265   std::vector<ActsScalar> edges0 = {};
0266   std::vector<ActsScalar> edges1 = {};
0267 
0268   /// Call operator that generates the Axis
0269   return_type operator()() const {
0270     Acts::detail::Axis<Acts::detail::AxisType::Variable, aType> varA(edges0);
0271     Acts::detail::Axis<Acts::detail::AxisType::Variable, bType> varB(edges1);
0272     return std::tie(varA, varB);
0273   }
0274 };
0275 
0276 // All 2D VarVar options
0277 using VarBoundVarBound = VarVar<Acts::detail::AxisBoundaryType::Bound,
0278                                 Acts::detail::AxisBoundaryType::Bound>;
0279 using VarBoundVarOpen = VarVar<Acts::detail::AxisBoundaryType::Bound,
0280                                Acts::detail::AxisBoundaryType::Open>;
0281 using VarBoundVarClosed = VarVar<Acts::detail::AxisBoundaryType::Bound,
0282                                  Acts::detail::AxisBoundaryType::Closed>;
0283 using VarOpenVarBound = VarVar<Acts::detail::AxisBoundaryType::Open,
0284                                Acts::detail::AxisBoundaryType::Bound>;
0285 using VarOpenVarOpen = VarVar<Acts::detail::AxisBoundaryType::Open,
0286                               Acts::detail::AxisBoundaryType::Open>;
0287 using VarOpenVarClosed = VarVar<Acts::detail::AxisBoundaryType::Open,
0288                                 Acts::detail::AxisBoundaryType::Closed>;
0289 using VarClosedVarBound = VarVar<Acts::detail::AxisBoundaryType::Closed,
0290                                  Acts::detail::AxisBoundaryType::Bound>;
0291 using VarClosedVarOpen = VarVar<Acts::detail::AxisBoundaryType::Closed,
0292                                 Acts::detail::AxisBoundaryType::Open>;
0293 using VarClosedVarClosed = VarVar<Acts::detail::AxisBoundaryType::Closed,
0294                                   Acts::detail::AxisBoundaryType::Closed>;
0295 
0296 // Generate the possible axes in this case
0297 using PossibleAxes =
0298     TypeList<EqBound, EqOpen, EqClosed,
0299              // All 1D Var  options
0300              VarBound, VarOpen, VarClosed,
0301              // All 2D EqEq options
0302              EqBoundEqBound, EqBoundEqOpen, EqBoundEqClosed, EqOpenEqBound,
0303              EqOpenEqOpen, EqOpenEqClosed, EqClosedEqBound, EqClosedEqOpen,
0304              EqClosedEqClosed,
0305              // All 2D EqVar options
0306              EqBoundVarBound, EqBoundVarOpen, EqBoundVarClosed, EqOpenVarBound,
0307              EqOpenVarOpen, EqOpenVarClosed, EqClosedVarBound, EqClosedVarOpen,
0308              EqClosedVarClosed,
0309              // All 2D VarEq options
0310              VarBoundEqBound, VarBoundEqOpen, VarBoundEqClosed, VarOpenEqBound,
0311              VarOpenEqOpen, VarOpenEqClosed, VarClosedEqBound, VarClosedEqOpen,
0312              VarClosedEqClosed,
0313              // All 2D VarEq options
0314              VarBoundVarBound, VarBoundVarOpen, VarBoundVarClosed,
0315              VarOpenVarBound, VarOpenVarOpen, VarOpenVarClosed,
0316              VarClosedVarBound, VarClosedVarOpen, VarClosedVarClosed>;
0317 
0318 }  // namespace Acts::GridAxisGenerators