File indexing completed on 2025-01-18 09:11:08
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <cmath>
0012 #include <numbers>
0013
0014 namespace Acts::AngleHelpers {
0015
0016 template <typename Scalar>
0017 struct EtaThetaConversionTraits {};
0018
0019 template <>
0020 struct EtaThetaConversionTraits<float> {
0021 static constexpr float minTheta = 1e-6f;
0022 static constexpr float maxTheta = std::numbers::pi_v<float> - minTheta;
0023
0024 static constexpr float maxEta = 80.0f;
0025 static constexpr float minEta = -maxEta;
0026 };
0027
0028 template <>
0029 struct EtaThetaConversionTraits<double> {
0030 static constexpr double minTheta = 1e-12;
0031 static constexpr double maxTheta = std::numbers::pi - minTheta;
0032
0033 static constexpr double maxEta = 700.0;
0034 static constexpr double minEta = -maxEta;
0035 };
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 template <typename Scalar>
0046 Scalar etaFromTheta(Scalar theta) {
0047 if (theta <= EtaThetaConversionTraits<Scalar>::minTheta) {
0048 return std::numeric_limits<Scalar>::infinity();
0049 }
0050 if (theta >= EtaThetaConversionTraits<Scalar>::maxTheta) {
0051 return -std::numeric_limits<Scalar>::infinity();
0052 }
0053
0054 return -std::log(std::tan(theta / 2));
0055 }
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 template <typename Scalar>
0066 Scalar thetaFromEta(Scalar eta) {
0067 if (eta <= EtaThetaConversionTraits<Scalar>::minEta) {
0068 return std::numbers::pi_v<Scalar>;
0069 }
0070 if (eta >= EtaThetaConversionTraits<Scalar>::maxEta) {
0071 return 0;
0072 }
0073
0074 return 2 * std::atan(std::exp(-eta));
0075 }
0076
0077 }