ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
smatrix_matrix.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/smatrix_types.hpp"
13#include "detray/algebra/concepts.hpp"
14#include "detray/definitions/detail/qualifiers.hpp"
15
16// ROOT/Smatrix include(s).
17#include <Math/SMatrix.h>
18
19namespace detray::algebra::smatrix::math {
20
22template <concepts::matrix matrix_t>
23DETRAY_HOST_DEVICE constexpr matrix_t zero() {
24 return matrix_t();
25}
26
28template <concepts::matrix matrix_t>
29DETRAY_HOST_DEVICE constexpr matrix_t identity() {
30 return matrix_t(ROOT::Math::SMatrixIdentity());
31}
32
34template <unsigned int ROWS, unsigned int COLS, concepts::scalar scalar_t>
35DETRAY_HOST_DEVICE constexpr void set_zero(
36 ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &m) {
37 m = zero<ROOT::Math::SMatrix<scalar_t, ROWS, COLS>>();
38}
39
41template <unsigned int ROWS, unsigned int COLS, concepts::scalar scalar_t>
42DETRAY_HOST_DEVICE constexpr void set_identity(
43 ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &m) {
44 m = identity<ROOT::Math::SMatrix<scalar_t, ROWS, COLS>>();
45}
46
48template <unsigned int ROWS, unsigned int COLS, concepts::scalar scalar_t>
49DETRAY_HOST_DEVICE constexpr matrix_type<scalar_t, COLS, ROWS> transpose(
50 const ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &m) {
51 return ROOT::Math::Transpose(m);
52}
53
56template <unsigned int ROWS, unsigned int COLS, concepts::scalar scalar_t>
57 requires(ROWS == 3)
58DETRAY_HOST_DEVICE constexpr matrix_type<scalar_t, ROWS, COLS>
59column_wise_cross(const ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &m,
60 const ROOT::Math::SVector<scalar_t, ROWS> &v) {
61 matrix_type<scalar_t, ROWS, COLS> ret;
62 for (unsigned int j = 0u; j < COLS; j++) {
63 ROOT::Math::SVector<scalar_t, ROWS> col = ROOT::Math::Cross(
64 m.template SubCol<ROOT::Math::SVector<scalar_t, ROWS>>(j, 0u), v);
65 ret.Place_in_col(col, 0, j);
66 }
67
68 return ret;
69}
70
71template <typename OP, unsigned int ROWS, unsigned int COLS,
72 concepts::scalar scalar_t,
73 typename R = ROOT::Math::MatRepStd<scalar_t, ROWS, COLS>>
74 requires(ROWS == 3)
75DETRAY_HOST_DEVICE constexpr matrix_type<scalar_t, ROWS, COLS>
76column_wise_cross(const ROOT::Math::Expr<OP, scalar_t, ROWS, COLS, R> &m,
77 const ROOT::Math::SVector<scalar_t, ROWS> &v) {
78 return column_wise_cross(static_cast<matrix_type<scalar_t, ROWS, COLS>>(m),
79 v);
80}
82
85template <unsigned int ROWS, unsigned int COLS, concepts::scalar scalar_t>
86DETRAY_HOST_DEVICE constexpr matrix_type<scalar_t, ROWS, COLS>
87column_wise_multiply(const ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &m,
88 const ROOT::Math::SVector<scalar_t, ROWS> &v) {
89 matrix_type<scalar_t, ROWS, COLS> ret;
90 for (unsigned int j = 0u; j < COLS; j++) {
91 ROOT::Math::SVector<scalar_t, ROWS> col =
92 m.template SubCol<ROOT::Math::SVector<scalar_t, ROWS>>(j, 0u) * v;
93 ret.Place_in_col(col, 0, j);
94 }
95
96 return ret;
97}
98
99template <typename OP, unsigned int ROWS, unsigned int COLS,
100 concepts::scalar scalar_t,
101 typename R = ROOT::Math::MatRepStd<scalar_t, ROWS, COLS>>
102DETRAY_HOST_DEVICE constexpr matrix_type<scalar_t, ROWS, COLS>
103column_wise_multiply(const ROOT::Math::Expr<OP, scalar_t, ROWS, COLS, R> &m,
104 const ROOT::Math::SVector<scalar_t, ROWS> &v) {
105 return column_wise_multiply(static_cast<matrix_type<scalar_t, ROWS, COLS>>(m),
106 v);
107}
109
111template <unsigned int ROWS, concepts::scalar scalar_t>
112DETRAY_HOST_DEVICE constexpr matrix_type<scalar_t, ROWS, ROWS> outer_product(
113 const ROOT::Math::SVector<scalar_t, ROWS> &a,
114 const ROOT::Math::SVector<scalar_t, ROWS> &b) {
115 return ROOT::Math::TensorProd(a, b);
116}
117
119template <unsigned int ROWS, unsigned int COLS, concepts::scalar scalar_t>
120DETRAY_HOST_DEVICE constexpr scalar_t determinant(
121 const matrix_type<scalar_t, ROWS, COLS> &m) {
122 scalar_t det;
123 [[maybe_unused]] bool success = m.Det2(det);
124
125 return det;
126}
127
129template <unsigned int ROWS, unsigned int COLS, concepts::scalar scalar_t>
130DETRAY_HOST_DEVICE constexpr matrix_type<scalar_t, COLS, ROWS> inverse(
131 const matrix_type<scalar_t, ROWS, COLS> &m) {
132 int ifail = 0;
133 return m.Inverse(ifail);
134}
135
137template <unsigned int ROWS, unsigned int COLS, concepts::scalar scalar_t>
138DETRAY_HOST_DEVICE constexpr matrix_type<scalar_t, ROWS, COLS>
139cholesky_decomposition(const matrix_type<scalar_t, ROWS, COLS> &m) {
140 matrix_type<scalar_t, ROWS, COLS> L;
141
142 ROOT::Math::CholeskyDecomp<scalar_t, ROWS> decomp(m);
143 [[maybe_unused]] const bool res = decomp.getL(L);
144 assert(res);
145
146 return L;
147}
148
149} // namespace detray::algebra::smatrix::math
constexpr double m
Meter.
Definition Units.hpp:97
constexpr double u
atomic mass unit u
Definition Units.hpp:155
@ R
Radial coordinate.
Definition SpacePointColumns.hpp:26