87 n_points =
static_cast<int> (
a.size());
88 if (n_points < 2 || degree < 1) {
91 degree = std::min (degree,
static_cast<unsigned int> (n_points) - 1);
94 unsigned int ix = std::lower_bound (
a.begin(),
a.begin()+n_points,
x,
108 unsigned int npts = degree + 2 - (degree%2);
114 bool extralo =
false;
115 bool extrahi =
false;
118 int ilo = ix - npts/2;
126 while (ilo < n_points &&
136 bool himoved =
false;
137 int ihi = ilo + npts;
138 if (ihi > n_points) {
152 bool lomoved =
false;
158 while (ilo < n_points &&
171 std::vector<float> t;
173 std::vector<float> d;
179 if (extralo && is_different (
a[ilo][xcol],
regions[
ir-1])) {
185 d.push_back (
a[ilo][ycol]);
187 if (extrahi && is_different (
a[ihi-1][xcol],
regions[
ir])) {
193 d.push_back (
a[ihi-1][ycol]);
197 for (; ilo < ihi; ++ilo) {
198 t.push_back (
a[ilo][xcol]);
199 d.push_back (
a[ilo][ycol]);
203 assert (t.size() == npts);
204 assert (d.size() == npts);
205 degree = std::min (degree, npts-1);
211 for (
size_t i = 1; i < npts-1; i++) {
213 d[i] = (d[i-1] + d[i+1])/2;
220 bool extra = npts != degree+1;
233 for (
unsigned int l=0; l<degree; l++) {
235 d[degree+1] = (d[degree+1]-d[degree-1])/(t[degree+1]-t[degree-1-l]);
236 for (
unsigned int i = degree; i > l; --i)
237 d[i] = (d[i]-d[i-1])/(t[i]-t[i-1-l]);
242 float sum = d[degree];
244 sum = 0.5*(sum+d[degree+1]);
245 for (
int j = degree-1; j >= 0; --j)
246 sum = d[j] + (
x - t[j]) * sum;
float interpolate(const CaloRec::Array< 2 > &a, float x, unsigned int degree, unsigned int ycol=1, const CaloRec::Array< 1 > ®ions=CaloRec::Array< 1 >(), int n_points=-1, bool fixZero=false)
Polynomial interpolation in a table.