4#ifndef MUONCALIBMATH_LEGENDREPOLYS_H
5#define MUONCALIBMATH_LEGENDREPOLYS_H
9#define POLYSWITCH(order , x) \
11 return Legendre::poly<order>(x); \
14#define DERIVPOLYSWITICH(l, d, x) \
16 return Legendre::derivative<l,d>(x); \
21#define DERIVORDERSWITCH(l, d, x) \
24 DERIVPOLYSWITICH(0, d, x) \
25 DERIVPOLYSWITICH(1, d, x) \
26 DERIVPOLYSWITICH(2, d, x) \
27 DERIVPOLYSWITICH(3, d, x) \
28 DERIVPOLYSWITICH(4, d, x) \
29 DERIVPOLYSWITICH(5, d, x) \
30 DERIVPOLYSWITICH(6, d, x) \
31 DERIVPOLYSWITICH(7, d, x) \
32 DERIVPOLYSWITICH(8, d, x) \
33 DERIVPOLYSWITICH(9, d, x) \
34 DERIVPOLYSWITICH(10, d, x) \
35 DERIVPOLYSWITICH(11, d, x) \
36 DERIVPOLYSWITICH(12, d, x) \
37 DERIVPOLYSWITICH(13, d, x) \
38 DERIVPOLYSWITICH(14, d, x) \
39 DERIVPOLYSWITICH(15, d, x) \
40 DERIVPOLYSWITICH(16, d, x) \
60 constexpr unsigned long binomial(
const unsigned n,
const unsigned k) {
65 template <
int k>
constexpr double pow(
const double x) {
66 if constexpr (k < 0) {
68 }
else if constexpr(k > 0) {
75 constexpr double pow(
double x,
int power) {
81 for (
int iter = 1; iter<=power; ++iter) {
92 constexpr double coeff(
const unsigned l,
const unsigned k) {
96 const double a_k = -(1.*(l- k +2)*(l+ k-1)) / (1.*(k * (k-1))) *
coeff(l, k-2);
99 unsigned fl = (l - l %2) /2;
101 return (fl % 2 ? -1. : 1.) *
pow(0.5, l) * (1.*binom);
108 template <
unsigned l,
unsigned k>
110 const double a_n =
coeff(l,k);
111 if constexpr (k > 1) {
122 template <
unsigned l,
unsigned k,
unsigned d>
124 if constexpr(k <= l && k>=d) {
126 const double a_n =
coeff(l,k) * powFac;
136 constexpr double derivativeSum(
const unsigned l,
const unsigned d,
const double x) {
138 for (
int k=l; k>=
static_cast<int>(d) && k >=0; k-=2) {
140 sum += a_n *
pow(
x,k-d);
145 constexpr double polySum(
const unsigned l,
const double x) {
147 for (
unsigned k = l%2; k<=l; k+=2) {
155 template <
unsigned l>
156 constexpr double poly(
const double x) {
163 template <
unsigned l,
unsigned d>
198 constexpr double legendreDeriv(
const unsigned l,
const unsigned d,
const double x){
215#undef DERIVORDERSWITCH
216#undef DERIVPOLYSWITICH
std::pair< std::vector< unsigned int >, bool > res
#define DERIVORDERSWITCH(l, d, x)
#define POLYSWITCH(order, x)
constexpr double coeff(const unsigned l, const unsigned k)
Calculates the n-th coefficient of the legendre polynomial series.
constexpr double poly(const double x)
Evaluates the n-th Legendre polynomial at x.
constexpr double polySum(const double x)
Assembles the sum of the legendre monomials.
constexpr double derivative(const double x)
Evaluates the d-th derivative of the n-th Legendre polynomial at x.
constexpr double derivativeSum(const double x)
Assembles the n-th derivative of the legendre polynomial.
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
constexpr unsigned long factorial(const int n)
Evaluated the n-th factorial at compile time.
constexpr double legendrePoly(const unsigned l, const double x)
Calculates the legendre polynomial of rank l at x.
constexpr double legendreDeriv(const unsigned l, const unsigned d, const double x)
Evaluates the n-th derivative of the l-th Legendre polynomial.
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.