File indexing completed on 2025-01-18 09:11:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012
0013 #include <cmath>
0014 #include <limits>
0015 #include <utility>
0016
0017 namespace Acts {
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 template <typename T>
0029 inline Eigen::Matrix<T, 3, 1> makeDirectionFromPhiEta(T phi, T eta) {
0030 const auto coshEtaInv = 1 / std::cosh(eta);
0031 return {
0032 std::cos(phi) * coshEtaInv,
0033 std::sin(phi) * coshEtaInv,
0034 std::tanh(eta),
0035 };
0036 }
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 template <typename T>
0048 inline Eigen::Matrix<T, 3, 1> makeDirectionFromPhiTheta(T phi, T theta) {
0049 const auto cosTheta = std::cos(theta);
0050 const auto sinTheta = std::sin(theta);
0051 return {
0052 std::cos(phi) * sinTheta,
0053 std::sin(phi) * sinTheta,
0054 cosTheta,
0055 };
0056 }
0057
0058
0059
0060
0061
0062 template <typename T>
0063 inline Eigen::Matrix<T, 2, 1> makePhiThetaFromDirection(
0064 Eigen::Matrix<T, 3, 1> unitDir) {
0065 unitDir.normalize();
0066 T phi = std::atan2(unitDir[1], unitDir[0]);
0067 T theta = std::acos(unitDir[2]);
0068 return {
0069 phi,
0070 theta,
0071 };
0072 }
0073
0074
0075
0076
0077
0078
0079
0080
0081 template <typename InputVector>
0082 inline auto makeCurvilinearUnitU(
0083 const Eigen::MatrixBase<InputVector>& direction) {
0084 EIGEN_STATIC_ASSERT_FIXED_SIZE(InputVector);
0085 EIGEN_STATIC_ASSERT_VECTOR_ONLY(InputVector);
0086 static_assert(3 <= InputVector::RowsAtCompileTime,
0087 "Direction vector must be at least three-dimensional.");
0088
0089 using OutputVector = typename InputVector::PlainObject;
0090 using OutputScalar = typename InputVector::Scalar;
0091
0092 OutputVector unitU = OutputVector::Zero();
0093
0094 unitU[0] = -direction[1];
0095 unitU[1] = direction[0];
0096 const auto scale = unitU.template head<2>().norm();
0097
0098
0099
0100
0101 if (scale < (16 * std::numeric_limits<OutputScalar>::epsilon())) {
0102 unitU[0] = 1;
0103 unitU[1] = 0;
0104 } else {
0105 unitU.template head<2>() /= scale;
0106 }
0107 return unitU;
0108 }
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 template <typename InputVector>
0124 inline auto makeCurvilinearUnitVectors(
0125 const Eigen::MatrixBase<InputVector>& direction) {
0126 EIGEN_STATIC_ASSERT_FIXED_SIZE(InputVector);
0127 EIGEN_STATIC_ASSERT_VECTOR_ONLY(InputVector);
0128 static_assert(3 <= InputVector::RowsAtCompileTime,
0129 "Direction vector must be at least three-dimensional.");
0130
0131 using OutputVector = typename InputVector::PlainObject;
0132
0133 std::pair<OutputVector, OutputVector> unitVectors;
0134 unitVectors.first = makeCurvilinearUnitU(direction);
0135 unitVectors.second = direction.cross(unitVectors.first);
0136 unitVectors.second.normalize();
0137 return unitVectors;
0138 }
0139
0140 }