Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 07:52:40

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