npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
ChebyshevIntegral.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_CHEBYSHEVINTEGRAL_HH_
2 #define NPSTAT_CHEBYSHEVINTEGRAL_HH_
3 
4 /*!
5 // \file ChebyshevIntegral.hh
6 //
7 // \brief Integrate functions by representing them with Chebyshev series
8 //
9 // Author: I. Volobouev
10 //
11 // March 2023
12 */
13 
14 #include <vector>
15 #include <cassert>
16 
18 #include "npstat/nm/MathUtils.hh"
19 
20 namespace npstat {
21  class ChebyshevIntegral : public Functor1<long double,long double>
22  {
23  public:
24  template<class Functor>
25  inline ChebyshevIntegral(const Functor& fcn, const unsigned maxdeg,
26  const long double xmin, const long double xmax)
27  : xmin_(xmin), xmax_(xmax), coeffs_(maxdeg+2U)
28  {
29  assert(xmin < xmax);
30  std::vector<long double> series(maxdeg+1U);
31  chebyshevSeriesCoeffs(fcn, xmin, xmax, maxdeg, &series[0]);
32  chebyshevIntegralCoeffs(&series[0], maxdeg, xmin, xmax, &coeffs_[0]);
33  }
34 
35  inline virtual ~ChebyshevIntegral() {}
36 
37  // x must lie inside the interval [xmin, xmax],
38  // where xmin and xmax were specified in the constructor.
39  // This operator returns the value of the integral
40  // from xmin to x.
41  inline long double operator()(const long double& x) const
42  {
43  assert(x >= xmin_ && x <= xmax_);
44  return chebyshevSeriesSum(&coeffs_[0], coeffs_.size()-1U,
45  xmin_, xmax_, x);
46  }
47 
48  private:
49  long double xmin_;
50  long double xmax_;
51  std::vector<long double> coeffs_;
52  };
53 }
54 
55 #endif // NPSTAT_CHEBYSHEVINTEGRAL_HH_
Various simple mathematical utilities which did not end up inside dedicated headers.
Interface definitions and concrete simple functors for a variety of functor-based calculations.
Definition: ChebyshevIntegral.hh:22
Definition: AbsArrayProjector.hh:14
void chebyshevSeriesCoeffs(const Functor &f, long double xmin, long double xmax, unsigned degree, Numeric *coeffs)
long double chebyshevSeriesSum(const Numeric *coeffs, unsigned degree, long double x)
void chebyshevIntegralCoeffs(const Numeric *coeffs, unsigned degree, long double xmin, long double xmax, Numeric *integralCoeffs)
Definition: SimpleFunctors.hh:58