ATLAS Offline Software
MatrixUtils.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef MUONPATTERNHELPERS_UTILS_H
5 #define MUONPATTERNHELPERS_UTILS_H
6 #include <CxxUtils/ArrayHelper.h>
7 #include <array>
8 
9 namespace MuonR4{
11  constexpr double sign(const double x) {
12  return x > 0. ? 1. : x < 0. ? -1. : 0.;
13  }
15  constexpr unsigned int sumUp(unsigned k){
16  return k*(k+1)/ 2;
17  }
27  template <unsigned int n>
28  constexpr unsigned int vecIdxFromSymMat(unsigned int i, unsigned k) {
29  assert(i<n);
30  assert(k<n);
31  if (k < i) {
32  return vecIdxFromSymMat<n>(k,i);
33  }
34  constexpr unsigned int nPars = sumUp(n);
35  return nPars - sumUp(n-i) + (k-i);
36  }
40  template <int n>
41  constexpr std::array<unsigned, 2> symMatIdxFromVec(unsigned int k) {
42  static_assert(n>=0);
43  assert (k < sumUp(n));
44  if (k <n) {
45  return std::array{0u, k};
46  }
47  if constexpr(n > 0){
48  const auto [i, j] = symMatIdxFromVec<n-1>(k-n);
49  return std::array{i+1u, j+1u};
50  }
51  return make_array<unsigned, 2>(0);
52  }
53 }
54 #endif
x
#define x
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
MuonR4::sumUp
constexpr unsigned int sumUp(unsigned k)
Calculates the sum of 1 + 2 +3 +4 +...
Definition: MatrixUtils.h:15
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
ArrayHelper.h
MuonR4::symMatIdxFromVec
constexpr std::array< unsigned, 2 > symMatIdxFromVec(unsigned int k)
Translates back the global index into the two matrix access indices under the assumption that the mat...
Definition: MatrixUtils.h:41
lumiFormat.array
array
Definition: lumiFormat.py:91
MuonR4::sign
constexpr double sign(const double x)
Returns the sign of a number.
Definition: MatrixUtils.h:11
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MuonR4::vecIdxFromSymMat
constexpr unsigned int vecIdxFromSymMat(unsigned int i, unsigned k)
If a n-dimensional Matrix is symmetric, it has n* (n+1) /2 parameters The following function returns ...
Definition: MatrixUtils.h:28
MuonR4::SegmentFit::ParamDefs::nPars
@ nPars
fitman.k
k
Definition: fitman.py:528