ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
vc_soa_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_soa_math.hpp"
13#include "detray/algebra/common/vector.hpp"
14#include "detray/algebra/concepts.hpp"
15#include "detray/definitions/detail/qualifiers.hpp"
16
17// Vc include(s).
18#ifdef _MSC_VER
19#pragma warning(push, 0)
20#endif // MSVC
21#include <Vc/Vc>
22#ifdef _MSC_VER
23#pragma warning(pop)
24#endif // MSVC
25
26namespace detray::algebra::vc_soa::math {
27
35template <std::size_t N, concepts::value value_t,
36 template <typename, std::size_t> class array_t>
37 requires(N >= 2)
38DETRAY_HOST_DEVICE constexpr auto phi(
39 const algebra::storage::vector<N, Vc::Vector<value_t>, array_t> &v) {
40 return Vc::atan2(v[1], v[0]);
41}
42
50template <std::size_t N, concepts::value value_t,
51 template <typename, std::size_t> class array_t>
52 requires(N >= 2)
53DETRAY_HOST_DEVICE constexpr auto perp(
54 const algebra::storage::vector<N, Vc::Vector<value_t>, array_t> &v) {
55 return Vc::sqrt(Vc::fma(v[0], v[0], v[1] * v[1]));
56}
57
65template <std::size_t N, concepts::value value_t,
66 template <typename, std::size_t> class array_t>
67 requires(N >= 3)
68DETRAY_HOST_DEVICE constexpr auto theta(
69 const algebra::storage::vector<N, Vc::Vector<value_t>, array_t> &v) {
70 return Vc::atan2(perp(v), v[2]);
71}
72
83template <std::size_t N, concepts::value value_t,
84 template <typename, std::size_t> class array_t>
85 requires(N == 3)
86DETRAY_HOST_DEVICE constexpr algebra::storage::vector<N, Vc::Vector<value_t>,
87 array_t>
88cross(const algebra::storage::vector<N, Vc::Vector<value_t>, array_t> &a,
89 const algebra::storage::vector<N, Vc::Vector<value_t>, array_t> &b) {
90 return {Vc::fma(a[1], b[2], -b[1] * a[2]), Vc::fma(a[2], b[0], -b[2] * a[0]),
91 Vc::fma(a[0], b[1], -b[0] * a[1])};
92}
93
104template <std::size_t N, concepts::value value_t,
105 template <typename, std::size_t> class array_t>
106DETRAY_HOST_DEVICE constexpr Vc::Vector<value_t> dot(
107 const algebra::storage::vector<N, Vc::Vector<value_t>, array_t> &a,
108 const algebra::storage::vector<N, Vc::Vector<value_t>, array_t> &b) {
109 auto ret = a[0] * b[0];
110
111 for (unsigned int i{1u}; i < N; i++) {
112 ret = Vc::fma(a[i], b[i], ret);
113 }
114
115 return ret;
116}
117
125template <std::size_t N, concepts::value value_t,
126 template <typename, std::size_t> class array_t>
127DETRAY_HOST_DEVICE constexpr auto norm(
128 const algebra::storage::vector<N, Vc::Vector<value_t>, array_t> &v) {
129 return Vc::sqrt(dot(v, v));
130}
131
139template <std::size_t N, concepts::value value_t,
140 template <typename, std::size_t> class array_t>
141DETRAY_HOST_DEVICE constexpr algebra::storage::vector<N, Vc::Vector<value_t>,
142 array_t>
143normalize(const algebra::storage::vector<N, Vc::Vector<value_t>, array_t> &v) {
144 return (Vc::Vector<value_t>::One() / norm(v)) * v;
145
146 // Less accurate, but faster
147 // return Vc::reciprocal(norm(v)) * v;
148
149 // Even less accurate, but even faster
150 // return Vc::rsqrt(dot(v, v)) * v;
151}
152
161template <std::size_t N, concepts::value value_t,
162 template <typename, std::size_t> class array_t>
163 requires(N >= 3)
164DETRAY_HOST_DEVICE constexpr auto eta(
165 const algebra::storage::vector<N, Vc::Vector<value_t>, array_t> &v) {
166 // atanh does not exist in Vc
167 auto atanh_func = [](value_t e) { return std::atanh(e); };
168
169 return (v[2] / norm(v)).apply(atanh_func);
170
171 // Faster, but less accurate
172 // return (Vc::reciprocal(norm(v)) * v[2]).apply(atanh_func);
173
174 // Even faster, but even less accurate
175 // return (Vc::rsqrt(dot(v, v)) * v[2]).apply(atanh_func);
176}
177
187template <std::size_t N, concepts::value value_t,
188 template <typename, std::size_t> class array_t>
189DETRAY_HOST_DEVICE constexpr Vc::Vector<value_t> sum(
190 const algebra::storage::vector<N, Vc::Vector<value_t>, array_t> &v) {
191 Vc::Vector<value_t> res{v[0]};
192
193 for (std::size_t i = 1u; i < Vc::Vector<value_t>::size(); ++i) {
194 res = res + v[i];
195 }
196
197 return res;
198}
199
200} // namespace detray::algebra::vc_soa::math
constexpr double e
Charge, native unit e (elementary charge).
Definition Units.hpp:165