ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
smatrix_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/definitions/detail/qualifiers.hpp"
13
14// ROOT/Smatrix include(s).
15#include <Math/Expression.h>
16#include <Math/Functions.h>
17#include <Math/SVector.h>
18#include <TMath.h>
19
20namespace detray::algebra::smatrix::math {
21
25template <concepts::scalar scalar_t, auto N>
26 requires(N >= 2)
27DETRAY_HOST constexpr scalar_t phi(
28 const ROOT::Math::SVector<scalar_t, N> &v) noexcept {
29 return static_cast<scalar_t>(TMath::ATan2(v[1], v[0]));
30}
31
32template <concepts::scalar scalar_t, class A, auto N>
33 requires(N >= 2)
34DETRAY_HOST constexpr scalar_t phi(
35 const ROOT::Math::VecExpr<A, scalar_t, N> &v) noexcept {
36 return static_cast<scalar_t>(TMath::ATan2(v.apply(1), v.apply(0)));
37}
38
42template <concepts::scalar scalar_t, auto N>
43 requires(N >= 3)
44DETRAY_HOST constexpr scalar_t theta(
45 const ROOT::Math::SVector<scalar_t, N> &v) noexcept {
46 return static_cast<scalar_t>(
47 TMath::ATan2(TMath::Sqrt(v[0] * v[0] + v[1] * v[1]), v[2]));
48}
49
50template <concepts::scalar scalar_t, class A, auto N>
51 requires(N >= 3)
52DETRAY_HOST constexpr scalar_t theta(
53 const ROOT::Math::VecExpr<A, scalar_t, N> &v) noexcept {
54 return static_cast<scalar_t>(TMath::ATan2(
55 TMath::Sqrt(v.apply(0) * v.apply(0) + v.apply(1) * v.apply(1)),
56 v.apply(2)));
57}
58
62template <concepts::scalar scalar_t, auto N>
63DETRAY_HOST constexpr scalar_t norm(const ROOT::Math::SVector<scalar_t, N> &v) {
64 return static_cast<scalar_t>(TMath::Sqrt(ROOT::Math::Dot(v, v)));
65}
66
67template <concepts::scalar scalar_t, class A, auto N>
68DETRAY_HOST constexpr scalar_t norm(
69 const ROOT::Math::VecExpr<A, scalar_t, N> &v) {
70 return static_cast<scalar_t>(TMath::Sqrt(ROOT::Math::Dot(v, v)));
71}
72
77template <concepts::scalar scalar_t, auto N>
78 requires(N >= 3)
79DETRAY_HOST constexpr scalar_t eta(
80 const ROOT::Math::SVector<scalar_t, N> &v) noexcept {
81 return static_cast<scalar_t>(TMath::ATanH(v[2] / norm(v)));
82}
83
84template <concepts::scalar scalar_t, class A, auto N>
85 requires(N >= 3)
86DETRAY_HOST constexpr scalar_t eta(
87 const ROOT::Math::VecExpr<A, scalar_t, N> &v) noexcept {
88 return static_cast<scalar_t>(TMath::ATanH(v.apply(2) / norm(v)));
89}
90
94template <concepts::scalar scalar_t, auto N>
95 requires(N >= 2)
96DETRAY_HOST constexpr scalar_t perp(
97 const ROOT::Math::SVector<scalar_t, N> &v) noexcept {
98 return static_cast<scalar_t>(TMath::Sqrt(v[0] * v[0] + v[1] * v[1]));
99}
100
101template <concepts::scalar scalar_t, class A, auto N>
102 requires(N >= 2)
103DETRAY_HOST constexpr scalar_t perp(
104 const ROOT::Math::VecExpr<A, scalar_t, N> &v) noexcept {
105 return static_cast<scalar_t>(
106 TMath::Sqrt(v.apply(0) * v.apply(0) + v.apply(1) * v.apply(1)));
107}
108
112template <concepts::scalar scalar_t, auto N>
113DETRAY_HOST constexpr ROOT::Math::SVector<scalar_t, N> normalize(
114 const ROOT::Math::SVector<scalar_t, N> &v) {
115 return ROOT::Math::Unit(v);
116}
117
121template <concepts::scalar scalar_t, class A, auto N>
122DETRAY_HOST constexpr ROOT::Math::SVector<scalar_t, N> normalize(
123 const ROOT::Math::VecExpr<A, scalar_t, N> &v) {
124 return ROOT::Math::Unit(v);
125}
126
133template <concepts::scalar scalar_t, auto N>
134DETRAY_HOST constexpr scalar_t dot(const ROOT::Math::SVector<scalar_t, N> &a,
135 const ROOT::Math::SVector<scalar_t, N> &b) {
136 return ROOT::Math::Dot(a, b);
137}
138
145template <concepts::scalar scalar_t, class A, auto N>
146DETRAY_HOST constexpr scalar_t dot(
147 const ROOT::Math::SVector<scalar_t, N> &a,
148 const ROOT::Math::VecExpr<A, scalar_t, N> &b) {
149 return ROOT::Math::Dot(a, b);
150}
151
158template <concepts::scalar scalar_t, class A, auto N>
159DETRAY_HOST constexpr scalar_t dot(const ROOT::Math::VecExpr<A, scalar_t, N> &a,
160 const ROOT::Math::SVector<scalar_t, N> &b) {
161 return ROOT::Math::Dot(a, b);
162}
163
170template <concepts::scalar scalar_t, class A, class B, auto N>
171DETRAY_HOST constexpr scalar_t dot(
172 const ROOT::Math::VecExpr<A, scalar_t, N> &a,
173 const ROOT::Math::VecExpr<B, scalar_t, N> &b) {
174 return ROOT::Math::Dot(a, b);
175}
176
183template <concepts::scalar scalar_t, class A, auto N>
184DETRAY_HOST constexpr scalar_t dot(
185 const ROOT::Math::SMatrix<scalar_t, N, 1> &a,
186 const ROOT::Math::VecExpr<A, scalar_t, N> &b) {
187 return ROOT::Math::Dot(a.Col(0), b);
188}
189
196template <concepts::scalar scalar_t, class A, auto N>
197DETRAY_HOST constexpr scalar_t dot(
198 const ROOT::Math::VecExpr<A, scalar_t, N> &a,
199 const ROOT::Math::SMatrix<scalar_t, N, 1> &b) {
200 return dot(b, a);
201}
202
209template <concepts::scalar scalar_t, auto N>
210DETRAY_HOST constexpr scalar_t dot(const ROOT::Math::SMatrix<scalar_t, N, 1> &a,
211 const ROOT::Math::SVector<scalar_t, N> &b) {
212 return ROOT::Math::Dot(a.Col(0), b);
213}
214
221template <concepts::scalar scalar_t, auto N>
222DETRAY_HOST constexpr scalar_t dot(
223 const ROOT::Math::SVector<scalar_t, N> &a,
224 const ROOT::Math::SMatrix<scalar_t, N, 1> &b) {
225 return dot(b, a);
226}
227
234template <concepts::scalar scalar_t>
235DETRAY_HOST constexpr ROOT::Math::SVector<scalar_t, 3> cross(
236 const ROOT::Math::SVector<scalar_t, 3> &a,
237 const ROOT::Math::SVector<scalar_t, 3> &b) {
238 return ROOT::Math::Cross(a, b);
239}
240
247template <concepts::scalar scalar_t, class A>
248DETRAY_HOST constexpr ROOT::Math::SVector<scalar_t, 3> cross(
249 const ROOT::Math::SVector<scalar_t, 3> &a,
250 const ROOT::Math::VecExpr<A, scalar_t, 3> &b) {
251 return ROOT::Math::Cross(a, b);
252}
253
260template <concepts::scalar scalar_t, class A>
261DETRAY_HOST constexpr ROOT::Math::SVector<scalar_t, 3> cross(
262 const ROOT::Math::VecExpr<A, scalar_t, 3> &a,
263 const ROOT::Math::SVector<scalar_t, 3> &b) {
264 return ROOT::Math::Cross(a, b);
265}
266
273template <concepts::scalar scalar_t, class A, class B>
274DETRAY_HOST constexpr ROOT::Math::SVector<scalar_t, 3> cross(
275 const ROOT::Math::VecExpr<A, scalar_t, 3> &a,
276 const ROOT::Math::VecExpr<B, scalar_t, 3> &b) {
277 return ROOT::Math::Cross(a, b);
278}
279
286template <concepts::scalar scalar_t>
287DETRAY_HOST constexpr ROOT::Math::SVector<scalar_t, 3> cross(
288 const ROOT::Math::SVector<scalar_t, 3> &a,
289 const ROOT::Math::SMatrix<scalar_t, 3, 1> &b) {
290 return ROOT::Math::Cross(a, b.Col(0));
291}
292
299template <concepts::scalar scalar_t>
300DETRAY_HOST constexpr ROOT::Math::SVector<scalar_t, 3> cross(
301 const ROOT::Math::SMatrix<scalar_t, 3, 1> &a,
302 const ROOT::Math::SVector<scalar_t, 3> &b) {
303 return ROOT::Math::Cross(a.Col(0), b);
304}
305
312template <concepts::scalar scalar_t>
313DETRAY_HOST constexpr ROOT::Math::SVector<scalar_t, 3> cross(
314 const ROOT::Math::SMatrix<scalar_t, 3, 1> &a,
315 const ROOT::Math::SMatrix<scalar_t, 3, 1> &b) {
316 return ROOT::Math::Cross(a.Col(0), b.Col(0));
317}
318
319} // namespace detray::algebra::smatrix::math