Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:22:02

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2026 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 #pragma once
0009 
0010 // Project include(s).
0011 #include "traccc/definitions/primitives.hpp"
0012 #include "traccc/definitions/qualifiers.hpp"
0013 
0014 // System include(s)
0015 #include <cassert>
0016 
0017 namespace traccc {
0018 
0019 /// @brief Compute a masked inverse of a 2x2 matrix.
0020 ///
0021 /// For 1D measurements only the [0, 0] element of the input matrix is
0022 /// meaningful, so we compute 1 / M[0,0] and zero out the rest. For 2D
0023 /// measurements a regular 2x2 inverse is computed.
0024 ///
0025 /// @param M   the 2x2 matrix to invert
0026 /// @param dim the meaningful dimension of @c M (1 or 2)
0027 /// @returns the masked inverse of @c M
0028 template <detray::concepts::algebra algebra_t>
0029 TRACCC_HOST_DEVICE inline detray::dmatrix<algebra_t, 2, 2> masked_inverse(
0030     const detray::dmatrix<algebra_t, 2, 2>& M, const unsigned int dim) {
0031   assert(dim == 1u || dim == 2u);
0032 
0033   detray::dmatrix<algebra_t, 2, 2> M_inv;
0034   if (dim == 1u) {
0035     assert(getter::element(M, 0u, 0u) != 0.f);
0036     getter::element(M_inv, 0u, 0u) = 1.f / getter::element(M, 0u, 0u);
0037     getter::element(M_inv, 0u, 1u) = 0.f;
0038     getter::element(M_inv, 1u, 0u) = 0.f;
0039     getter::element(M_inv, 1u, 1u) = 0.f;
0040   } else {
0041     M_inv = matrix::inverse(M);
0042   }
0043   return M_inv;
0044 }
0045 
0046 }  // namespace traccc