ATLAS Offline Software
Loading...
Searching...
No Matches
MuonCalib::Legendre Namespace Reference

Functions

constexpr double coeff (const unsigned l, const unsigned k)
 Calculates the n-th coefficient of the legendre polynomial series.
template<unsigned l, unsigned k>
constexpr double polySum (const double x)
 Assembles the sum of the legendre monomials.
template<unsigned l, unsigned k, unsigned d>
constexpr double derivativeSum (const double x)
 Assembles the n-th derivative of the legendre polynomial.
constexpr double derivativeSum (const unsigned l, const unsigned d, const double x)
 Assembles the n-th derivative of a legendre polynomial at run time.
constexpr double polySum (const unsigned l, const double x)
 Assembles the legendre polynomial at run-time.
template<unsigned l>
constexpr double poly (const double x)
 Evaluates the n-th Legendre polynomial at x.
template<unsigned l, unsigned d>
constexpr double derivative (const double x)
 Evaluates the d-th derivative of the n-th Legendre polynomial at x.

Function Documentation

◆ coeff()

double MuonCalib::Legendre::coeff ( const unsigned l,
const unsigned k )
constexpr

Calculates the n-th coefficient of the legendre polynomial series.

Parameters
lOrder of the legendre polynomial
kCoefficient insides the polynomial representation

Definition at line 92 of file LegendrePoly.h.

92 {
93 if (k %2 != l %2) {
94 return 0.;
95 } else if (k > 1) {
96 const double a_k = -(1.*(l- k +2)*(l+ k-1)) / (1.*(k * (k-1))) * coeff(l, k-2);
97 return a_k;
98 } else {
99 unsigned fl = (l - l %2) /2;
100 unsigned long binom = binomial(l,fl) * binomial(2*l - 2*fl,l);
101 return (fl % 2 ? -1. : 1.) * pow(0.5, l) * (1.*binom);
102 }
103 }
constexpr double coeff(const unsigned l, const unsigned k)
Calculates the n-th coefficient of the legendre polynomial series.
constexpr unsigned long binomial(const unsigned n, const unsigned k)
Calculates the binomial coefficient at compile time.
constexpr double pow(const double x)
Calculate the power of a variable x at compile time.

◆ derivative()

template<unsigned l, unsigned d>
double MuonCalib::Legendre::derivative ( const double x)
constexpr

Evaluates the d-th derivative of the n-th Legendre polynomial at x.

Parameters
lOrder of the Legendre polynomial
dOrder of the respective derivative
xPoint of evaluation [-1;1]

Definition at line 164 of file LegendrePoly.h.

164 {
165 return derivativeSum<l,l,d>(x);
166 }
#define x
constexpr double derivativeSum(const double x)
Assembles the n-th derivative of the legendre polynomial.

◆ derivativeSum() [1/2]

template<unsigned l, unsigned k, unsigned d>
double MuonCalib::Legendre::derivativeSum ( const double x)
constexpr

Assembles the n-th derivative of the legendre polynomial.

Parameters
lOrder of the legendre polynomial
kTerm in the polynomial to add
dOrder of the derivative
xPoint of evaluation [-1,1]

Definition at line 123 of file LegendrePoly.h.

123 {
124 if constexpr(k <= l && k>=d) {
125 constexpr unsigned long powFac = factorial(k) / factorial(k-d);
126 const double a_n = coeff(l,k) * powFac;
127 return a_n *pow<k-d>(x) + derivativeSum<l, k-2, d>(x);
128 } else {
129 return 0.;
130 }
131 }
constexpr unsigned long factorial(const int n)
Evaluated the n-th factorial at compile time.

◆ derivativeSum() [2/2]

double MuonCalib::Legendre::derivativeSum ( const unsigned l,
const unsigned d,
const double x )
constexpr

Assembles the n-th derivative of a legendre polynomial at run time.

Parameters
lOrder of the legendre polynomial
dOrder of the derivative
xPoint of evaluation [-1,1]

Definition at line 136 of file LegendrePoly.h.

136 {
137 double sum{0.};
138 for (int k=l; k>= static_cast<int>(d) && k >=0; k-=2) {
139 const double a_n = coeff(l,k) * factorial(k) / factorial(k-d);
140 sum += a_n * pow(x,k-d);
141 }
142 return sum;
143 }

◆ poly()

template<unsigned l>
double MuonCalib::Legendre::poly ( const double x)
constexpr

Evaluates the n-th Legendre polynomial at x.

Parameters
lOrder of the Legendre polynoimal
xPoint of evaluation [-1;1]

Definition at line 156 of file LegendrePoly.h.

156 {
157 return polySum<l,l>(x);
158 }
constexpr double polySum(const double x)
Assembles the sum of the legendre monomials.

◆ polySum() [1/2]

template<unsigned l, unsigned k>
double MuonCalib::Legendre::polySum ( const double x)
constexpr

Assembles the sum of the legendre monomials.

Parameters
lOrder of the legendre polynomial
kTerm in the polynomial to add to the sum
xPoint of evaluation [-1,1]

Definition at line 109 of file LegendrePoly.h.

109 {
110 const double a_n = coeff(l,k);
111 if constexpr (k > 1) {
112 return a_n* pow<k>(x) + polySum<l, k-2>(x);
113 } else{
114 return a_n*pow<k>(x);
115 }
116 }

◆ polySum() [2/2]

double MuonCalib::Legendre::polySum ( const unsigned l,
const double x )
constexpr

Assembles the legendre polynomial at run-time.

Definition at line 145 of file LegendrePoly.h.

145 {
146 double sum{0.};
147 for (unsigned k = l%2; k<=l; k+=2) {
148 sum += pow(x,k) * coeff(l,k);
149 }
150 return sum;
151 }