Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-24 08:18:53

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/Definitions/Algebra.hpp"
0012 
0013 #include <ostream>
0014 
0015 namespace Acts {
0016 
0017 /// @enum AxisDirection to specify a local axis direction
0018 enum class AxisDirection : int {
0019   /// AxisX, AxisY, AxisZ are the cartesian directions in the local frame
0020   AxisX = 0,
0021   AxisY = 1,
0022   AxisZ = 2,
0023   /// AxisR is a radial direction
0024   AxisR = 3,
0025   /// AxisPhi is the azimuthal direction
0026   AxisPhi = 4,
0027   /// AxisRPhi is the radial-azimuthal direction
0028   AxisRPhi = 5,
0029   /// AxisTheta is the polar angle direction
0030   AxisTheta = 6,
0031   /// AxisEta is the pseudorapidity direction
0032   AxisEta = 7,
0033   /// AxisMag is the magnitude of the vector
0034   AxisMag = 8
0035 };
0036 
0037 /// Get all possible axis directions
0038 /// @return a vector of all possible axis directions
0039 const std::vector<AxisDirection>& allAxisDirections();
0040 
0041 /// Returns the total number of axis directions
0042 /// @return the number of axis directions
0043 constexpr std::size_t numAxisDirections() {
0044   return 9;
0045 }
0046 
0047 /// Get an axis direction from its string name
0048 ///
0049 /// @param name is the name of the axis direction
0050 /// @return the axis direction
0051 AxisDirection axisDirectionFromName(const std::string& name);
0052 
0053 /// Get the name of a binning value as a string
0054 /// @param aDir is the binning value
0055 /// @return the name of the binning value
0056 const std::string& axisDirectionName(AxisDirection aDir);
0057 
0058 /// Output stream operator for @c AxisDirection
0059 /// @param os is the output stream
0060 /// @param aDir is the axis direction
0061 /// @return the output stream
0062 std::ostream& operator<<(std::ostream& os, AxisDirection aDir);
0063 
0064 /// Enum which determines how the axis handle its outer boundaries
0065 /// possible values values
0066 enum class AxisBoundaryType {
0067   /// Default behaviour: out of bounds
0068   /// positions are filled into the over or underflow bins
0069   Open,
0070   /// Out-of-bounds positions resolve to first/last bin
0071   /// respectively
0072   Bound,
0073   /// Out-of-bounds positions resolve to the outermost
0074   /// bin on the opposite side
0075   Closed,
0076 };
0077 
0078 /// Tag helper type for Axis constructors with class template deduction
0079 /// @tparam bdt the boundary type
0080 template <AxisBoundaryType bdt>
0081 struct AxisBoundaryTypeTag {};
0082 
0083 /// Convenience typedefs for AxisBoundaryTypeTag
0084 /// Constant for open boundary type axis
0085 constexpr auto AxisOpen = AxisBoundaryTypeTag<AxisBoundaryType::Open>{};
0086 /// Constant for bound boundary type axis
0087 constexpr auto AxisBound = AxisBoundaryTypeTag<AxisBoundaryType::Bound>{};
0088 /// Constant for closed boundary type axis
0089 constexpr auto AxisClosed = AxisBoundaryTypeTag<AxisBoundaryType::Closed>{};
0090 
0091 /// Stream operator for AxisBoundaryType
0092 /// @param os Output stream
0093 /// @param bdt AxisBoundaryType to output
0094 /// @return Reference to output stream
0095 inline std::ostream& operator<<(std::ostream& os, AxisBoundaryType bdt) {
0096   using enum AxisBoundaryType;
0097   switch (bdt) {
0098     case Open:
0099       os << "Open";
0100       break;
0101     case Bound:
0102       os << "Bound";
0103       break;
0104     case Closed:
0105       os << "Closed";
0106       break;
0107   }
0108   return os;
0109 }
0110 
0111 /// Enum which determines the binning type of the axis
0112 enum class AxisType {
0113   /// An axis where all bins have the same size
0114   Equidistant,
0115   /// An axis where bins can have different sizes
0116   Variable,
0117 };
0118 
0119 /// Stream operator for AxisType
0120 /// @param os Output stream
0121 /// @param type AxisType to output
0122 /// @return Reference to output stream
0123 inline std::ostream& operator<<(std::ostream& os, AxisType type) {
0124   switch (type) {
0125     case AxisType::Equidistant:
0126       os << "Equidistant";
0127       break;
0128     case AxisType::Variable:
0129       os << "Variable";
0130       break;
0131   }
0132   return os;
0133 }
0134 
0135 /// @brief calculate bin indices from a given binning structure
0136 ///
0137 /// This class provides some basic functionality for calculating bin indices
0138 /// for a given binning configuration. Both equidistant as well as variable
0139 /// binning structures are supported.
0140 ///
0141 /// Bin intervals are defined such that the lower bound is closed and the
0142 /// upper bound is open.
0143 ///
0144 /// @tparam equidistant flag whether binning is equidistant (@c true)
0145 ///                     or not (@c false)
0146 template <AxisType type, AxisBoundaryType bdt = AxisBoundaryType::Open>
0147 class Axis;
0148 
0149 /// Deduction guide for equidistant axis with open boundaries
0150 /// @param min Minimum value
0151 /// @param max Maximum value
0152 /// @param bins Number of bins
0153 Axis(double min, double max,
0154      std::size_t bins) -> Axis<AxisType::Equidistant, AxisBoundaryType::Open>;
0155 
0156 /// Deduction guide for equidistant axis with specified boundary type
0157 /// @param min Minimum value
0158 /// @param max Maximum value
0159 /// @param bins Number of bins
0160 template <AxisBoundaryType bdt>
0161 Axis(AxisBoundaryTypeTag<bdt> /*bdt*/, double min, double max,
0162      std::size_t bins) -> Axis<AxisType::Equidistant, bdt>;
0163 
0164 /// Deduction guide for variable axis with open boundaries
0165 /// @param bins Vector of bin edges
0166 Axis(std::vector<double> bins)
0167     -> Axis<AxisType::Variable, AxisBoundaryType::Open>;
0168 
0169 /// Deduction guide for variable axis with specified boundary type
0170 /// @param bins Vector of bin edges
0171 template <AxisBoundaryType bdt>
0172 Axis(AxisBoundaryTypeTag<bdt> /*bdt*/,
0173      std::vector<double> bins) -> Axis<AxisType::Variable, bdt>;
0174 
0175 }  // namespace Acts