12#include "detray/definitions/detail/qualifiers.hpp"
15#include <Math/Expression.h>
16#include <Math/Functions.h>
17#include <Math/SVector.h>
20namespace detray::algebra::smatrix::math {
25template <concepts::scalar scalar_t, auto N>
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]));
32template <concepts::scalar scalar_t,
class A, auto N>
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)));
42template <concepts::scalar scalar_t, auto N>
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]));
50template <concepts::scalar scalar_t,
class A, auto N>
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)),
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)));
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)));
77template <concepts::scalar scalar_t, auto N>
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)));
84template <concepts::scalar scalar_t,
class A, auto N>
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)));
94template <concepts::scalar scalar_t, auto N>
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]));
101template <concepts::scalar scalar_t,
class A, auto N>
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)));
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);
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);
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);
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);
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);
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);
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);
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) {
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);
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) {
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);
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);
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);
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);
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));
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);
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));