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 <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 /// Calculate the pseudorapidity from the polar angle theta.
0038 ///
0039 /// This function aims to be FPE safe and returns infinity for theta values
0040 /// outside the floating point precision range.
0041 ///
0042 /// @param theta is the polar angle in radian towards the z-axis.
0043 ///
0044 /// @return the pseudorapidity towards the z-axis.
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 /// Calculate the polar angle theta from the pseudorapidity.
0058 ///
0059 /// This function aims to be FPE safe and returns 0/pi for eta values outside
0060 /// the floating point precision range.
0061 ///
0062 /// @param eta is the pseudorapidity towards the z-axis.
0063 ///
0064 /// @return the polar angle in radian towards the z-axis.
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 }  // namespace Acts::AngleHelpers