/home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/util/include/RAT/BoundedInterpolator.hh Source File

Ratpac-two: /home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/util/include/RAT/BoundedInterpolator.hh Source File
Ratpac-two
BoundedInterpolator.hh
1 #ifndef __RAT_BoundedInterpolator__
2 #define __RAT_BoundedInterpolator__
3 
4 #include <Math/Interpolator.h>
5 
6 #include <vector>
7 
8 // Wrapper around ROOT::Math::Interpolator class, with extra control of out-of-bound evaluations.
9 namespace RAT {
10 
12  public:
13  BoundedInterpolator(const std::vector<double> &x, const std::vector<double> &y,
14  ROOT::Math::Interpolation::Type type = ROOT::Math::Interpolation::kCSPLINE)
15  : fInterpolator(x, y, type) {
16  bound_left = x.at(0);
17  bound_right = x.at(x.size() - 1);
18  }
19 
20  BoundedInterpolator(unsigned int ndata = 0,
21  ROOT::Math::Interpolation::Type type = ROOT::Math::Interpolation::kCSPLINE)
22  : fInterpolator(ndata, type) {}
23 
24  bool SetData(const std::vector<double> &x, const std::vector<double> &y) {
25  bound_left = x.at(0);
26  bound_right = x.at(x.size() - 1);
27  return fInterpolator.SetData(x, y);
28  }
29 
30  bool SetData(unsigned int ndata, const double *x, const double *y) {
31  bound_left = x[0];
32  bound_right = x[ndata - 1];
33  return fInterpolator.SetData(ndata, x, y);
34  }
35 
36  double Eval(double x) const {
37  if (x < bound_left) return fInterpolator.Eval(bound_left + 1e-8);
38  if (x > bound_right) return fInterpolator.Eval(bound_right - 1e-8);
39  return fInterpolator.Eval(x);
40  }
41 
42  double Deriv(double x) const {
43  if (x < bound_left || x > bound_right) return 0;
44  return fInterpolator.Deriv(x);
45  }
46 
47  double Deriv2(double x) const {
48  if (x < bound_left || x > bound_right) return 0;
49  return fInterpolator.Deriv2(x);
50  }
51 
52  double Integ(double xlow, double xhigh) const {
53  if (xlow <= bound_left) xlow = bound_left + 1e-8;
54  if (xhigh >= bound_right) xhigh = bound_right - 1e-8;
55  if (xlow >= xhigh) return 0;
56  return fInterpolator.Integ(xlow, xhigh);
57  }
58 
59  protected:
60  ROOT::Math::Interpolator fInterpolator;
61  double bound_left, bound_right;
62 };
63 
64 } // namespace RAT
65 
66 #endif
Definition: BoundedInterpolator.hh:11
Definition: CCCrossSecMessenger.hh:29