ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
vc_aos_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 "algebra/impl/vc_aos_types.hpp"
13#include "detray/algebra/common/math.hpp"
14#include "detray/algebra/common/vector.hpp"
15#include "detray/algebra/concepts.hpp"
16#include "detray/definitions/detail/qualifiers.hpp"
17
18// Vc include(s).
19#ifdef _MSC_VER
20#pragma warning(push, 0)
21#endif // MSVC
22#include <Vc/Vc>
23#ifdef _MSC_VER
24#pragma warning(pop)
25#endif // MSVC
26
27// System include(s).
28#include <concepts>
29#include <utility>
30
31namespace detray::algebra::vc_aos::math {
32
34template <detray::concepts::vc_aos_vector vector_t>
35DETRAY_HOST_DEVICE constexpr auto phi(const vector_t &v) {
36 return algebra::math::atan2(v[1], v[0]);
37}
38
40template <detray::concepts::vc_aos_vector vector_t>
41DETRAY_HOST_DEVICE constexpr auto perp(const vector_t &v) {
42 return algebra::math::sqrt(algebra::math::fma(v[0], v[0], v[1] * v[1]));
43}
44
46template <detray::concepts::vc_aos_vector vector_t>
47DETRAY_HOST_DEVICE constexpr auto theta(const vector_t &v) {
48 return algebra::math::atan2(perp(v), v[2]);
49}
50
59template <detray::concepts::vc_aos_vector vector_t1,
60 detray::concepts::vc_aos_vector vector_t2>
61DETRAY_HOST_DEVICE constexpr auto dot(const vector_t1 &a, const vector_t2 &b) {
62 return (a * b).sum();
63}
64
68template <detray::concepts::vc_aos_vector vector_t>
69DETRAY_HOST_DEVICE constexpr auto norm(const vector_t &v) {
70 return algebra::math::sqrt(dot(v, v));
71}
72
78template <detray::concepts::vc_aos_vector vector_t>
79DETRAY_HOST_DEVICE constexpr auto normalize(const vector_t &v) {
80 return v / norm(v);
81}
82
87template <detray::concepts::vc_aos_vector vector_t>
88DETRAY_HOST_DEVICE constexpr auto eta(const vector_t &v) noexcept {
89 return algebra::math::atanh(v[2] / norm(v));
90}
91
100template <detray::concepts::vc_aos_vector vector_t1,
101 detray::concepts::vc_aos_vector vector_t2>
102 requires(std::same_as<detray::traits::value_t<vector_t1>, float> &&
103 std::same_as<detray::traits::value_t<vector_t2>, float>)
104DETRAY_HOST_DEVICE constexpr auto cross(const vector_t1 &a, const vector_t2 &b)
105 -> decltype(a * b - b * a) {
106 using T = detray::traits::value_t<vector_t1>;
107 using simd_array_t = Vc::SimdArray<T, 4>;
108
109 // Mask to write on the last two elements: [0011]
110 const typename simd_array_t::mask_type m{simd_array_t::IndexesFromZero() > 1};
111
112 // a = [a1, a2, a3, 0]
113 // a_rot = [a2, a3, 0, a1]
114 simd_array_t a_rot = static_cast<simd_array_t>(a).rotated(1);
115 // a_rot = [a2, a3, a1, a2]
116 a_rot(m) = a_rot.rotated(1);
117
118 // Same for b
119 simd_array_t b_rot = static_cast<simd_array_t>(b).rotated(1);
120 b_rot(m) = b_rot.rotated(1);
121
122 simd_array_t res = a_rot * b_rot.rotated(1) - a_rot.rotated(1) * b_rot;
123 // Restore trailing zero
124 res[3] = 0.f;
125
126 return res;
127}
128
137template <detray::concepts::vc_aos_vector vector_t1,
138 detray::concepts::vc_aos_vector vector_t2>
139 requires(std::same_as<detray::traits::value_t<vector_t1>, double> ||
140 std::same_as<detray::traits::value_t<vector_t2>, double>)
141DETRAY_HOST_DEVICE constexpr auto cross(const vector_t1 &a, const vector_t2 &b)
142 -> decltype(a * b - b * a) {
143 return {algebra::math::fma(a[1], b[2], -b[1] * a[2]),
144 algebra::math::fma(a[2], b[0], -b[2] * a[0]),
145 algebra::math::fma(a[0], b[1], -b[0] * a[1]), 0.f};
146}
147
155template <detray::concepts::vc_aos_vector vector_t>
156DETRAY_HOST_DEVICE constexpr auto sum(const vector_t &v) {
157 return v.get().sum();
158}
159
160} // namespace detray::algebra::vc_aos::math
constexpr double m
Meter.
Definition Units.hpp:97
constexpr double T
Magnetic field, native unit (eV*s)/(e*m²).
Definition Units.hpp:168
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