Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:08

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 constexpr auto AxisOpen = AxisBoundaryTypeTag<AxisBoundaryType::Open>{};
0085 constexpr auto AxisBound = AxisBoundaryTypeTag<AxisBoundaryType::Bound>{};
0086 constexpr auto AxisClosed = AxisBoundaryTypeTag<AxisBoundaryType::Closed>{};
0087 
0088 inline std::ostream& operator<<(std::ostream& os, AxisBoundaryType bdt) {
0089   using enum AxisBoundaryType;
0090   switch (bdt) {
0091     case Open:
0092       os << "Open";
0093       break;
0094     case Bound:
0095       os << "Bound";
0096       break;
0097     case Closed:
0098       os << "Closed";
0099       break;
0100   }
0101   return os;
0102 }
0103 
0104 /// Enum which determines the binning type of the axis
0105 enum class AxisType {
0106   /// An axis where all bins have the same size
0107   Equidistant,
0108   /// An axis where bins can have different sizes
0109   Variable,
0110 };
0111 
0112 inline std::ostream& operator<<(std::ostream& os, AxisType type) {
0113   switch (type) {
0114     case AxisType::Equidistant:
0115       os << "Equidistant";
0116       break;
0117     case AxisType::Variable:
0118       os << "Variable";
0119       break;
0120   }
0121   return os;
0122 }
0123 
0124 /// @brief calculate bin indices from a given binning structure
0125 ///
0126 /// This class provides some basic functionality for calculating bin indices
0127 /// for a given binning configuration. Both equidistant as well as variable
0128 /// binning structures are supported.
0129 ///
0130 /// Bin intervals are defined such that the lower bound is closed and the
0131 /// upper bound is open.
0132 ///
0133 /// @tparam equidistant flag whether binning is equidistant (@c true)
0134 ///                     or not (@c false)
0135 template <AxisType type, AxisBoundaryType bdt = AxisBoundaryType::Open>
0136 class Axis;
0137 
0138 Axis(double min, double max,
0139      std::size_t bins) -> Axis<AxisType::Equidistant, AxisBoundaryType::Open>;
0140 
0141 template <AxisBoundaryType bdt>
0142 Axis(AxisBoundaryTypeTag<bdt> /*bdt*/, double min, double max,
0143      std::size_t bins) -> Axis<AxisType::Equidistant, bdt>;
0144 
0145 Axis(std::vector<double> bins)
0146     -> Axis<AxisType::Variable, AxisBoundaryType::Open>;
0147 
0148 template <AxisBoundaryType bdt>
0149 Axis(AxisBoundaryTypeTag<bdt> /*bdt*/,
0150      std::vector<double> bins) -> Axis<AxisType::Variable, bdt>;
0151 
0152 }  // namespace Acts