Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-22 07:51:59

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   /// Range [min, max] for the equidistant axis
0039   std::array<double, 2u> range = {};
0040   /// Number of bins for the equidistant axis
0041   std::size_t nBins = 0u;
0042 
0043   /// Call operator that generates the Axis
0044   /// @return Tuple containing the generated equidistant axis
0045   return_type operator()() const {
0046     Axis<AxisType::Equidistant, aType> eAxis(range[0u], range[1u], nBins);
0047     return {eAxis};
0048   }
0049 };
0050 
0051 // All 1D equidistant options
0052 /// Type alias for 1D equidistant axis generator with bound boundary type
0053 using EqBound = Eq<AxisBoundaryType::Bound>;
0054 /// Type alias for 1D equidistant axis generator with open boundary type
0055 using EqOpen = Eq<AxisBoundaryType::Open>;
0056 /// Type alias for 1D equidistant axis generator with closed boundary type
0057 using EqClosed = Eq<AxisBoundaryType::Closed>;
0058 
0059 /// @brief  Templated base generator for variable axis as a tuple - 1D
0060 ///
0061 /// @tparam aType the type of the axis (Bound, Closed, Open)
0062 template <AxisBoundaryType aType>
0063 struct Var {
0064   /// Broadcast the return_type
0065   using return_type = std::tuple<Axis<AxisType::Variable, aType>>;
0066 
0067   /// Broadcast the grid type
0068   template <typename T>
0069   using grid_type = Grid<T, Axis<AxisType::Variable, aType>>;
0070 
0071   /// Bin edges for the variable axis
0072   std::vector<double> edges = {};
0073 
0074   /// Call operator that generates the Axis
0075   /// @return Tuple containing the generated variable axis
0076   return_type operator()() const {
0077     Axis<AxisType::Variable, aType> vAxis(edges);
0078     return {vAxis};
0079   }
0080 };
0081 
0082 // All 1D variable options
0083 /// Type alias for 1D variable axis generator with bound boundary type
0084 using VarBound = Var<AxisBoundaryType::Bound>;
0085 /// Type alias for 1D variable axis generator with open boundary type
0086 using VarOpen = Var<AxisBoundaryType::Open>;
0087 /// Type alias for 1D variable axis generator with closed boundary type
0088 using VarClosed = Var<AxisBoundaryType::Closed>;
0089 
0090 /// @brief  Templated base generator for two equidistant axes as a tuple - 2D
0091 ///
0092 /// @tparam aType the type of the first axis (Bound, Closed, Open)
0093 /// @tparam bType the type of the second axis (Bound, Closed, Open)
0094 ///
0095 template <AxisBoundaryType aType, AxisBoundaryType bType>
0096 struct EqEq {
0097   /// Broadcast the return_type
0098   using return_type = std::tuple<Axis<AxisType::Equidistant, aType>,
0099                                  Axis<AxisType::Equidistant, bType>>;
0100 
0101   /// Broadcast the grid type
0102   template <typename T>
0103   using grid_type = Grid<T, Axis<AxisType::Equidistant, aType>,
0104                          Axis<AxisType::Equidistant, bType>>;
0105 
0106   /// Range [min, max] for the first equidistant axis
0107   std::array<double, 2u> range0 = {};
0108   /// Number of bins for the first equidistant axis
0109   std::size_t nBins0 = 0u;
0110   /// Range [min, max] for the second equidistant axis
0111   std::array<double, 2u> range1 = {};
0112   /// Number of bins for the second equidistant axis
0113   std::size_t nBins1 = 1u;
0114 
0115   /// Call operator that generates the Axis
0116   /// @return Tuple containing the two generated equidistant axes
0117   return_type operator()() const {
0118     // Create the two axis
0119     Axis<AxisType::Equidistant, aType> aEq(range0[0u], range0[1u], nBins0);
0120     Axis<AxisType::Equidistant, bType> bEq(range1[0u], range1[1u], nBins1);
0121     return {aEq, bEq};
0122   }
0123 };
0124 
0125 // All 2D EqEq options
0126 /// Type alias for 2D equidistant axis generator with bound/bound boundary types
0127 using EqBoundEqBound = EqEq<AxisBoundaryType::Bound, AxisBoundaryType::Bound>;
0128 /// Type alias for 2D equidistant axis generator with bound/open boundary types
0129 using EqBoundEqOpen = EqEq<AxisBoundaryType::Bound, AxisBoundaryType::Open>;
0130 /// Type alias for 2D equidistant axis generator with bound/closed boundary
0131 /// types
0132 using EqBoundEqClosed = EqEq<AxisBoundaryType::Bound, AxisBoundaryType::Closed>;
0133 /// Type alias for 2D equidistant axis generator with open/bound boundary types
0134 using EqOpenEqBound = EqEq<AxisBoundaryType::Open, AxisBoundaryType::Bound>;
0135 /// Type alias for 2D equidistant axis generator with open/open boundary types
0136 using EqOpenEqOpen = EqEq<AxisBoundaryType::Open, AxisBoundaryType::Open>;
0137 /// Type alias for 2D equidistant axis generator with open/closed boundary types
0138 using EqOpenEqClosed = EqEq<AxisBoundaryType::Open, AxisBoundaryType::Closed>;
0139 /// Type alias for 2D equidistant axis generator with closed/bound boundary
0140 /// types
0141 using EqClosedEqBound = EqEq<AxisBoundaryType::Closed, AxisBoundaryType::Bound>;
0142 /// Type alias for 2D equidistant axis generator with closed/open boundary types
0143 using EqClosedEqOpen = EqEq<AxisBoundaryType::Closed, AxisBoundaryType::Open>;
0144 /// Type alias for 2D equidistant axis generator with closed/closed boundary
0145 /// types
0146 using EqClosedEqClosed =
0147     EqEq<AxisBoundaryType::Closed, AxisBoundaryType::Closed>;
0148 
0149 /// @brief  Templated base generator for equidistant / variable axes as a tuple - 2D
0150 ///
0151 /// @tparam aType the type of the first axis (Bound, Closed, Open)
0152 /// @tparam bType the type of the second axis (Bound, Closed, Open)
0153 ///
0154 template <AxisBoundaryType aType, AxisBoundaryType bType>
0155 struct EqVar {
0156   /// Broadcast the return_type
0157   using return_type = std::tuple<Axis<AxisType::Equidistant, aType>,
0158                                  Axis<AxisType::Variable, bType>>;
0159 
0160   /// Broadcast the grid type
0161   template <typename T>
0162   using grid_type = Grid<T, Axis<AxisType::Equidistant, aType>,
0163                          Axis<AxisType::Variable, bType>>;
0164 
0165   /// Range [min, max] for the equidistant axis
0166   std::array<double, 2u> range = {};
0167   /// Number of bins for the equidistant axis
0168   std::size_t nBins = 0u;
0169   /// Bin edges for the variable axis
0170   std::vector<double> edges = {};
0171 
0172   /// Call operator that generates the Axis
0173   /// @return Tuple containing an equidistant axis and a variable axis
0174   return_type operator()() const {
0175     Axis<AxisType::Equidistant, aType> eqA(range[0u], range[1u], nBins);
0176     Axis<AxisType::Variable, bType> varB(edges);
0177     return {eqA, varB};
0178   }
0179 };
0180 
0181 // All 2D EqVar options
0182 /// Type alias for 2D equidistant/variable axis generator with bound/bound
0183 /// boundary types
0184 using EqBoundVarBound = EqVar<AxisBoundaryType::Bound, AxisBoundaryType::Bound>;
0185 /// Type alias for 2D equidistant/variable axis generator with bound/open
0186 /// boundary types
0187 using EqBoundVarOpen = EqVar<AxisBoundaryType::Bound, AxisBoundaryType::Open>;
0188 /// Type alias for 2D equidistant/variable axis generator with bound/closed
0189 /// boundary types
0190 using EqBoundVarClosed =
0191     EqVar<AxisBoundaryType::Bound, AxisBoundaryType::Closed>;
0192 /// Type alias for 2D equidistant/variable axis generator with open/bound
0193 /// boundary types
0194 using EqOpenVarBound = EqVar<AxisBoundaryType::Open, AxisBoundaryType::Bound>;
0195 /// Type alias for 2D equidistant/variable axis generator with open/open
0196 /// boundary types
0197 using EqOpenVarOpen = EqVar<AxisBoundaryType::Open, AxisBoundaryType::Open>;
0198 /// Type alias for 2D equidistant/variable axis generator with open/closed
0199 /// boundary types
0200 using EqOpenVarClosed = EqVar<AxisBoundaryType::Open, AxisBoundaryType::Closed>;
0201 /// Type alias for 2D equidistant/variable axis generator with closed/bound
0202 /// boundary types
0203 using EqClosedVarBound =
0204     EqVar<AxisBoundaryType::Closed, AxisBoundaryType::Bound>;
0205 /// Type alias for 2D equidistant/variable axis generator with closed/open
0206 /// boundary types
0207 using EqClosedVarOpen = EqVar<AxisBoundaryType::Closed, AxisBoundaryType::Open>;
0208 /// Type alias for 2D equidistant/variable axis generator with closed/closed
0209 /// boundary types
0210 using EqClosedVarClosed =
0211     EqVar<AxisBoundaryType::Closed, AxisBoundaryType::Closed>;
0212 
0213 /// @brief  Templated base generator for a variable, equidistant axes tuple - 2D
0214 ///
0215 /// @tparam aType the type of the first axis (Bound, Closed, Open)
0216 /// @tparam bType the type of the second axis (Bound, Closed, Open)
0217 ///
0218 template <AxisBoundaryType aType, AxisBoundaryType bType>
0219 struct VarEq {
0220   /// Broadcast the return_type
0221   using return_type = std::tuple<Axis<AxisType::Variable, aType>,
0222                                  Axis<AxisType::Equidistant, bType>>;
0223 
0224   /// Broadcast the grid type
0225   template <typename T>
0226   using grid_type = Grid<T, Axis<AxisType::Variable, aType>,
0227                          Axis<AxisType::Equidistant, bType>>;
0228 
0229   /// Bin edges for the variable axis
0230   std::vector<double> edges = {};
0231   /// Range [min, max] for the equidistant axis
0232   std::array<double, 2u> range = {};
0233   /// Number of bins for the equidistant axis
0234   std::size_t nBins = 0u;
0235 
0236   /// Call operator that generates the Axis
0237   /// @return Tuple containing a variable axis and an equidistant axis
0238   return_type operator()() const {
0239     Axis<AxisType::Variable, aType> varA(edges);
0240     Axis<AxisType::Equidistant, bType> eqB(range[0u], range[1u], nBins);
0241     return {varA, eqB};
0242   }
0243 };
0244 
0245 // All 2D VarEq options
0246 /// Type alias for 2D variable/equidistant axis generator with bound/bound
0247 /// boundary types
0248 using VarBoundEqBound = VarEq<AxisBoundaryType::Bound, AxisBoundaryType::Bound>;
0249 /// Type alias for 2D variable/equidistant axis generator with bound/open
0250 /// boundary types
0251 using VarBoundEqOpen = VarEq<AxisBoundaryType::Bound, AxisBoundaryType::Open>;
0252 /// Type alias for 2D variable/equidistant axis generator with bound/closed
0253 /// boundary types
0254 using VarBoundEqClosed =
0255     VarEq<AxisBoundaryType::Bound, AxisBoundaryType::Closed>;
0256 /// Type alias for 2D variable/equidistant axis generator with open/bound
0257 /// boundary types
0258 using VarOpenEqBound = VarEq<AxisBoundaryType::Open, AxisBoundaryType::Bound>;
0259 /// Type alias for 2D variable/equidistant axis generator with open/open
0260 /// boundary types
0261 using VarOpenEqOpen = VarEq<AxisBoundaryType::Open, AxisBoundaryType::Open>;
0262 /// Type alias for 2D variable/equidistant axis generator with open/closed
0263 /// boundary types
0264 using VarOpenEqClosed = VarEq<AxisBoundaryType::Open, AxisBoundaryType::Closed>;
0265 /// Type alias for 2D variable/equidistant axis generator with closed/bound
0266 /// boundary types
0267 using VarClosedEqBound =
0268     VarEq<AxisBoundaryType::Closed, AxisBoundaryType::Bound>;
0269 /// Type alias for 2D variable/equidistant axis generator with closed/open
0270 /// boundary types
0271 using VarClosedEqOpen = VarEq<AxisBoundaryType::Closed, AxisBoundaryType::Open>;
0272 /// Type alias for 2D variable/equidistant axis generator with closed/closed
0273 /// boundary types
0274 using VarClosedEqClosed =
0275     VarEq<AxisBoundaryType::Closed, AxisBoundaryType::Closed>;
0276 
0277 /// @brief  Templated base generator for a two variable axes tuple - 2D
0278 ///
0279 /// @tparam aType the type of the first axis (Bound, Closed, Open)
0280 /// @tparam bType the type of the second axis (Bound, Closed, Open)
0281 ///
0282 template <AxisBoundaryType aType, AxisBoundaryType bType>
0283 struct VarVar {
0284   /// Broadcast the return_type
0285   using return_type = std::tuple<Axis<AxisType::Variable, aType>,
0286                                  Axis<AxisType::Variable, bType>>;
0287 
0288   /// Broadcast the grid type
0289   template <typename T>
0290   using grid_type =
0291       Grid<T, Axis<AxisType::Variable, aType>, Axis<AxisType::Variable, bType>>;
0292 
0293   /// Bin edges for the first variable axis
0294   std::vector<double> edges0 = {};
0295   /// Bin edges for the second variable axis
0296   std::vector<double> edges1 = {};
0297 
0298   /// Call operator that generates the Axis
0299   /// @return Tuple containing two variable axes
0300   return_type operator()() const {
0301     Axis<AxisType::Variable, aType> varA(edges0);
0302     Axis<AxisType::Variable, bType> varB(edges1);
0303     return {varA, varB};
0304   }
0305 };
0306 
0307 // All 2D VarVar options
0308 /// Type alias for 2D variable/variable axis generator with bound/bound boundary
0309 /// types
0310 using VarBoundVarBound =
0311     VarVar<AxisBoundaryType::Bound, AxisBoundaryType::Bound>;
0312 /// Type alias for 2D variable/variable axis generator with bound/open boundary
0313 /// types
0314 using VarBoundVarOpen = VarVar<AxisBoundaryType::Bound, AxisBoundaryType::Open>;
0315 /// Type alias for 2D variable/variable axis generator with bound/closed
0316 /// boundary types
0317 using VarBoundVarClosed =
0318     VarVar<AxisBoundaryType::Bound, AxisBoundaryType::Closed>;
0319 /// Type alias for 2D variable/variable axis generator with open/bound boundary
0320 /// types
0321 using VarOpenVarBound = VarVar<AxisBoundaryType::Open, AxisBoundaryType::Bound>;
0322 /// Type alias for 2D variable/variable axis generator with open/open boundary
0323 /// types
0324 using VarOpenVarOpen = VarVar<AxisBoundaryType::Open, AxisBoundaryType::Open>;
0325 /// Type alias for 2D variable/variable axis generator with open/closed boundary
0326 /// types
0327 using VarOpenVarClosed =
0328     VarVar<AxisBoundaryType::Open, AxisBoundaryType::Closed>;
0329 /// Type alias for 2D variable/variable axis generator with closed/bound
0330 /// boundary types
0331 using VarClosedVarBound =
0332     VarVar<AxisBoundaryType::Closed, AxisBoundaryType::Bound>;
0333 /// Type alias for 2D variable/variable axis generator with closed/open boundary
0334 /// types
0335 using VarClosedVarOpen =
0336     VarVar<AxisBoundaryType::Closed, AxisBoundaryType::Open>;
0337 /// Type alias for 2D variable/variable axis generator with closed/closed
0338 /// boundary types
0339 using VarClosedVarClosed =
0340     VarVar<AxisBoundaryType::Closed, AxisBoundaryType::Closed>;
0341 
0342 // Generate the possible axes in this case
0343 /// Type alias for type list of all possible axis generator combinations
0344 using PossibleAxes =
0345     TypeList<EqBound, EqOpen, EqClosed,
0346              // All 1D Var  options
0347              VarBound, VarOpen, VarClosed,
0348              // All 2D EqEq options
0349              EqBoundEqBound, EqBoundEqOpen, EqBoundEqClosed, EqOpenEqBound,
0350              EqOpenEqOpen, EqOpenEqClosed, EqClosedEqBound, EqClosedEqOpen,
0351              EqClosedEqClosed,
0352              // All 2D EqVar options
0353              EqBoundVarBound, EqBoundVarOpen, EqBoundVarClosed, EqOpenVarBound,
0354              EqOpenVarOpen, EqOpenVarClosed, EqClosedVarBound, EqClosedVarOpen,
0355              EqClosedVarClosed,
0356              // All 2D VarEq options
0357              VarBoundEqBound, VarBoundEqOpen, VarBoundEqClosed, VarOpenEqBound,
0358              VarOpenEqOpen, VarOpenEqClosed, VarClosedEqBound, VarClosedEqOpen,
0359              VarClosedEqClosed,
0360              // All 2D VarEq options
0361              VarBoundVarBound, VarBoundVarOpen, VarBoundVarClosed,
0362              VarOpenVarBound, VarOpenVarOpen, VarOpenVarClosed,
0363              VarClosedVarBound, VarClosedVarOpen, VarClosedVarClosed>;
0364 
0365 }  // namespace Acts::GridAxisGenerators