86 n_points =
static_cast<int> (
a.size());
87 if (n_points < 2 || degree < 1) {
90 degree = std::min (degree,
static_cast<unsigned int> (n_points) - 1);
93 unsigned int ix = std::lower_bound (
a.begin(),
a.begin()+n_points,
x,
107 unsigned int npts = degree + 2 - (degree%2);
113 bool extralo =
false;
114 bool extrahi =
false;
117 int ilo = ix - npts/2;
125 while (ilo < n_points &&
135 bool himoved =
false;
136 int ihi = ilo + npts;
137 if (ihi > n_points) {
151 bool lomoved =
false;
157 while (ilo < n_points &&
171 std::vector<float> t;
174 std::vector<float> d;
180 if (extralo && is_different (
a[ilo][xcol],
regions[
ir-1])) {
186 d.push_back (
a[ilo][ycol]);
188 if (extrahi && is_different (
a[ihi-1][xcol],
regions[
ir])) {
194 d.push_back (
a[ihi-1][ycol]);
198 for (; ilo < ihi; ++ilo) {
199 t.push_back (
a[ilo][xcol]);
200 d.push_back (
a[ilo][ycol]);
204 assert (t.size() == npts);
205 assert (d.size() == npts);
207 degree = std::min (degree, npts-1);
213 for (
size_t i = 1; i < npts-1; i++) {
216 d[i] = (d[i-1] + d[i+1])/2;
223 bool extra = npts != degree+1;
237 for (
unsigned int l=0; l<degree; l++) {
239 d[degree+1] = (d[degree+1]-d[degree-1])/(t[degree+1]-t[degree-1-l]);
240 for (
unsigned int i = degree; i > l; --i)
241 d[i] = (d[i]-d[i-1])/(t[i]-t[i-1-l]);
246 float sum = d[degree];
248 sum = 0.5*(sum+d[degree+1]);
249 for (
int j = degree-1; j >= 0; --j)
250 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.