CMS 3D CMS Logo

invertPosDefMatrix.h
Go to the documentation of this file.
1 #ifndef DataFormat_Math_invertPosDefMatrix_H
2 #define DataFormat_Math_invertPosDefMatrix_H
3 
4 #define SMATRIX_USE_CONSTEXPR
5 #include "Math/SMatrix.h"
6 #include "Math/CholeskyDecomp.h"
7 #include <type_traits>
8 
9 template <typename T, unsigned int N>
10 inline bool invertPosDefMatrix(ROOT::Math::SMatrix<T, N, N, ROOT::Math::MatRepSym<T, N> >& m) {
11  ROOT::Math::CholeskyDecomp<T, N> decomp(m);
12  if (!decomp) {
13  return m.Invert();
14  } else
15  decomp.Invert(m);
16  return true;
17 }
18 
19 template <typename PDM2>
20 void fastInvertPDM2(PDM2& mm) {
21  auto m = mm.Array();
22 
23  constexpr typename std::remove_reference<decltype(m[0])>::type one = 1.;
24  auto c0 = one / m[0];
25  auto c1 = m[1] * m[1] * c0;
26  auto c2 = one / (m[2] - c1);
27 
28  auto li21 = c1 * c0 * c2;
29  m[0] = li21 + c0;
30  m[1] = -m[1] * c0 * c2;
31  m[2] = c2;
32 }
33 
34 template <>
35 inline bool invertPosDefMatrix<double, 1>(ROOT::Math::SMatrix<double, 1, 1, ROOT::Math::MatRepSym<double, 1> >& m) {
36  m(0, 0) = 1. / m(0, 0);
37  return true;
38 }
39 template <>
40 inline bool invertPosDefMatrix<float, 1>(ROOT::Math::SMatrix<float, 1, 1, ROOT::Math::MatRepSym<float, 1> >& m) {
41  m(0, 0) = 1.f / m(0, 0);
42  return true;
43 }
44 
45 template <>
46 inline bool invertPosDefMatrix<double, 2>(ROOT::Math::SMatrix<double, 2, 2, ROOT::Math::MatRepSym<double, 2> >& m) {
48  return true;
49 }
50 template <>
51 inline bool invertPosDefMatrix<float, 2>(ROOT::Math::SMatrix<float, 2, 2, ROOT::Math::MatRepSym<float, 2> >& m) {
53  return true;
54 }
55 
56 template <typename T, unsigned int N>
57 inline bool invertPosDefMatrix(ROOT::Math::SMatrix<T, N, N, ROOT::Math::MatRepSym<T, N> > const& mIn,
58  ROOT::Math::SMatrix<T, N, N, ROOT::Math::MatRepSym<T, N> >& mOut) {
59  ROOT::Math::CholeskyDecomp<T, N> decomp(mIn);
60  if (!decomp) {
61  mOut = mIn;
62  return mOut.Invert();
63  } else
64  decomp.Invert(mOut);
65  return true;
66 }
67 
68 #endif
invertPosDefMatrix< double, 2 >
bool invertPosDefMatrix< double, 2 >(ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > &m)
Definition: invertPosDefMatrix.h:46
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
N
#define N
Definition: blowfish.cc:9
invertPosDefMatrix< float, 2 >
bool invertPosDefMatrix< float, 2 >(ROOT::Math::SMatrix< float, 2, 2, ROOT::Math::MatRepSym< float, 2 > > &m)
Definition: invertPosDefMatrix.h:51
alignmentValidation.c1
c1
do drawing
Definition: alignmentValidation.py:1025
fastInvertPDM2
void fastInvertPDM2(PDM2 &mm)
Definition: invertPosDefMatrix.h:20
invertPosDefMatrix
bool invertPosDefMatrix(ROOT::Math::SMatrix< T, N, N, ROOT::Math::MatRepSym< T, N > > &m)
Definition: invertPosDefMatrix.h:10
type
type
Definition: HCALResponse.h:21
invertPosDefMatrix< double, 1 >
bool invertPosDefMatrix< double, 1 >(ROOT::Math::SMatrix< double, 1, 1, ROOT::Math::MatRepSym< double, 1 > > &m)
Definition: invertPosDefMatrix.h:35
T
long double T
Definition: Basic3DVectorLD.h:48
math::cholesky::li21
auto li21
Definition: choleskyInversion.h:190
fftjetpileupestimator_calo_uncalib_cfi.c0
c0
Definition: fftjetpileupestimator_calo_uncalib_cfi.py:8
invertPosDefMatrix< float, 1 >
bool invertPosDefMatrix< float, 1 >(ROOT::Math::SMatrix< float, 1, 1, ROOT::Math::MatRepSym< float, 1 > > &m)
Definition: invertPosDefMatrix.h:40