ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
eigen_vector.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s).
12#include "detray/algebra/common/math.hpp"
13#include "detray/definitions/detail/qualifiers.hpp"
14
15// Eigen include(s).
16#ifdef _MSC_VER
17#pragma warning(push, 0)
18#endif // MSVC
19#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
20#pragma nv_diagnostic push
21#pragma nv_diag_suppress 20012
22#endif // __NVCC_DIAG_PRAGMA_SUPPORT__
23#include <Eigen/Core>
24#ifdef _MSC_VER
25#pragma warning(pop)
26#endif // MSVC
27#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
28#pragma nv_diagnostic pop
29#endif // __NVCC_DIAG_PRAGMA_SUPPORT__
30
31namespace detray::algebra::eigen::math {
32
34template <typename derived_type>
35DETRAY_HOST_DEVICE constexpr auto phi(
36 const Eigen::MatrixBase<derived_type> &v) {
37 return algebra::math::atan2(v[1], v[0]);
38}
39
41template <typename derived_type>
42DETRAY_HOST_DEVICE constexpr auto perp(
43 const Eigen::MatrixBase<derived_type> &v) {
44 return algebra::math::sqrt(algebra::math::fma(v[0], v[0], v[1] * v[1]));
45}
46
48template <typename derived_type>
49DETRAY_HOST_DEVICE constexpr auto theta(
50 const Eigen::MatrixBase<derived_type> &v) {
51 return algebra::math::atan2(perp(v), v[2]);
52}
53
57template <typename derived_type>
58DETRAY_HOST_DEVICE constexpr auto norm(
59 const Eigen::MatrixBase<derived_type> &v) {
60 return v.norm();
61}
62
67template <typename derived_type>
68 requires(Eigen::MatrixBase<derived_type>::RowsAtCompileTime >= 3)
69DETRAY_HOST_DEVICE constexpr auto eta(
70 const Eigen::MatrixBase<derived_type> &v) noexcept {
71 return algebra::math::atanh(v[2] / v.norm());
72}
73
79template <typename derived_type>
80DETRAY_HOST_DEVICE constexpr auto normalize(
81 const Eigen::MatrixBase<derived_type> &v) {
82 return v.normalized();
83}
84
94template <typename derived_type_lhs, typename derived_type_rhs>
95DETRAY_HOST_DEVICE constexpr auto dot(
96 const Eigen::MatrixBase<derived_type_lhs> &a,
97 const Eigen::MatrixBase<derived_type_rhs> &b) {
98 return a.dot(b);
99}
100
110template <typename derived_type_lhs, typename derived_type_rhs>
111DETRAY_HOST_DEVICE constexpr auto cross(
112 const Eigen::MatrixBase<derived_type_lhs> &a,
113 const Eigen::MatrixBase<derived_type_rhs> &b) {
114 return a.cross(b);
115}
116
117} // namespace detray::algebra::eigen::math
constexpr decltype(auto) sqrt(T &&vec)
Definition vc_soa_math.hpp:78
constexpr decltype(auto) fma(T &&x, T &&y, T &&z)
Evaluate the fused multiply-add x * y + z lane by lane.
Definition vc_soa_math.hpp:168