19 using namespace genie;
31 if (
fX) {
delete []
fX; }
32 if (
fY) {
delete []
fY; }
33 if (
fZ) {
delete []
fZ; }
51 int nx,
double xmin,
double xmax,
int ny,
double ymin,
double ymax)
53 this->
Init(nx, xmin, xmax, ny, ymin, ymax);
57 int nx,
int ny,
double *x,
double *y,
double *z)
60 double xmax = x[nx-1];
62 double ymax = y[nx-1];
64 this->
Init(nx, xmin, xmax, ny, ymin, ymax);
66 for(
int ix=0; ix<nx; ix++) {
67 for(
int iy=0; iy<ny; iy++) {
75 int ix = TMath::FloorNint( (x -
fXmin +
fDX/2) /
fDX );
76 int iy = TMath::FloorNint( (y -
fYmin +
fDY/2) /
fDY );
77 int iz = this->
IdxZ(ix,iy);
85 <<
"Added x = " << x <<
" (ix = " << ix <<
")"
86 <<
" y = " << y <<
" (iy = " << iy <<
") -> "
87 <<
" z = " << z <<
" (iz = " << iz <<
")";
94 if(x < fXmin || x >
fXmax)
return 0.;
95 if(y < fYmin || y >
fYmax)
return 0.;
97 int ix_lo = TMath::FloorNint( (x -
fXmin) /
fDX );
98 int iy_lo = TMath::FloorNint( (y -
fYmin) /
fDY );
99 int ix_hi = ix_lo + 1;
100 int iy_hi = iy_lo + 1;
102 double x1 =
fX[ix_lo];
103 double x2 =
fX[ix_hi];
104 double y1 =
fY[iy_lo];
105 double y2 =
fY[iy_hi];
107 double z11 =
fZ[ this->
IdxZ(ix_lo,iy_lo) ];
108 double z21 =
fZ[ this->
IdxZ(ix_hi,iy_lo) ];
109 double z12 =
fZ[ this->
IdxZ(ix_lo,iy_hi) ];
110 double z22 =
fZ[ this->
IdxZ(ix_hi,iy_hi) ];
112 double z1 = z11 * (x2-x)/(x2-x1) + z21 * (x-x1)/(x2-x1);
113 double z2 = z12 * (x2-x)/(x2-x1) + z22 * (x-x1)/(x2-x1);
114 double z = z1 * (y2-y)/(y2-y1) + z2 * (y-y1)/(y2-y1);
131 int nx,
double xmin,
double xmax,
int ny,
double ymin,
double ymax)
140 fZmin = std::numeric_limits<double>::max();
141 fZmax = std::numeric_limits<double>::min();
157 fZmin = std::numeric_limits<double>::max();
158 fZmax = std::numeric_limits<double>::min();
160 fDX = (xmax-xmin)/(nx-1);
161 fDY = (ymax-ymin)/(ny-1);
163 fX =
new double[
fNX];
164 fY =
new double[
fNY];
165 fZ =
new double[
fNZ];
167 for(
int i=0; i<
fNX; i++) {
fX[i] = xmin + i*
fDX; }
168 for(
int i=0; i<
fNY; i++) {
fY[i] = ymin + i*
fDY; }
169 for(
int i=0; i<
fNZ; i++) {
fZ[i] = 0.; }
183 int nx,
double xmin,
double xmax,
int ny,
double ymin,
double ymax)
185 this->
Init(nx, xmin, xmax, ny, ymin, ymax);
189 int nx,
int ny,
double *x,
double *y,
double *z)
192 double xmax = x[nx-1];
194 double ymax = y[ny-1];
196 this->
Init(nx, xmin, xmax, ny, ymin, ymax);
198 for(
int ix=0; ix<nx; ix++) {
199 for(
int iy=0; iy<ny; iy++) {
221 if (!(TMath::Abs(x-
fX[i])<=.5*.0000001*(TMath::Abs(x)+TMath::Abs(
fX[i]))) && x<
fX[i])
226 LOG(
"BLI2DNonUnifGrid",
pWARN) <<
"Warning: too many x values, cannot add x = "<<x;
238 if (TMath::Abs(x-
fX[i])<=.5*.0000001*(TMath::Abs(x)+TMath::Abs(
fX[i]))) {
240 LOG(
"BLI2DNonUnifGrid",
pDEBUG) <<
"x value found at index "<<i;
241 changex=
false;
break;}
245 if (changex && xidx<0) xidx=
fNFillX;
246 if (changex)
LOG(
"BLI2DNonUnifGrid",
pDEBUG) <<
"Adding x value at index "<<xidx;
250 if (!(TMath::Abs(y-
fY[i])<=.5*.0000001*(TMath::Abs(y)+TMath::Abs(
fY[i]))) && y<
fY[i])
254 LOG(
"BLI2DNonUnifGrid",
pWARN) <<
"Warning: too many y values, cannot add y = "<<y;
266 if (TMath::Abs(y-
fY[i])<=.5*.0000001*(TMath::Abs(y)+TMath::Abs(
fY[i]))) {
268 LOG(
"BLI2DNonUnifGrid",
pDEBUG) <<
"y value found at index "<<i;
269 changey=
false;
break;}
273 if (changey && yidx<0) yidx=
fNFillY;
274 if (changey)
LOG(
"BLI2DNonUnifGrid",
pDEBUG) <<
"Adding y value at index "<<yidx;
277 if (changex && xidx>=0)
279 for (
int j=0;j<fNFillX-xidx;j++)
281 fX[fNFillX-j]=
fX[fNFillX-j-1];
284 fZ[ this->
IdxZ(fNFillX-j,k) ]
285 =
fZ[ this->
IdxZ(fNFillX-j-1,k) ];
293 if (changey && yidx>=0)
295 for (
int j=0;j<fNFillY-yidx;j++)
297 fY[fNFillY-j]=
fY[fNFillY-j-1];
300 fZ[ this->
IdxZ(k,fNFillY-j) ]
301 =
fZ[ this->
IdxZ(k,fNFillY-j-1) ];
310 int iz = this->
IdxZ(xidx,yidx);
318 <<
"Added x = " << x <<
" (ix = " << xidx <<
")"
319 <<
" y = " << y <<
" (iy = " << yidx <<
") -> "
320 <<
" z = " << z <<
" (iz = " << iz <<
")";
327 double evalx=TMath::Min(x,
fXmax);
328 evalx=TMath::Max(evalx,
fXmin);
329 double evaly=TMath::Min(y,
fYmax);
330 evaly=TMath::Max(evaly,
fYmin);
336 if (evalx<=
fX[fNFillX-1-i]) ix_lo=fNFillX-2-i;
341 if (evaly<=
fY[fNFillY-1-i]) iy_lo=fNFillY-2-i;
344 int ix_hi = ix_lo + 1;
345 int iy_hi = iy_lo + 1;
348 if (ix_lo==-1) {ix_lo++; ix_hi++;}
349 if (iy_lo==-1) {iy_lo++; iy_hi++;}
351 if (ix_lo==-2) {ix_lo=fNFillX-2; ix_hi=fNFillX-1;}
352 if (iy_lo==-2) {iy_lo=fNFillY-2; iy_hi=fNFillY-1;}
354 if (ix_lo<0 || iy_lo<0 )
return 0.;
355 if (ix_hi>fNFillX || iy_hi>fNFillY)
return 0.;
357 double x1 =
fX[ix_lo];
358 double x2 =
fX[ix_hi];
359 double y1 =
fY[iy_lo];
360 double y2 =
fY[iy_hi];
362 double z11 =
fZ[ this->
IdxZ(ix_lo,iy_lo) ];
363 double z21 =
fZ[ this->
IdxZ(ix_hi,iy_lo) ];
364 double z12 =
fZ[ this->
IdxZ(ix_lo,iy_hi) ];
365 double z22 =
fZ[ this->
IdxZ(ix_hi,iy_hi) ];
367 double z1 = z11 * (x2-evalx)/(x2-x1) + z21 * (evalx-x1)/(x2-x1);
368 double z2 = z12 * (x2-evalx)/(x2-x1) + z22 * (evalx-x1)/(x2-x1);
369 double z = z1 * (y2-evaly)/(y2-y1) + z2 * (evaly-y1)/(y2-y1);
388 int nx,
double xmin,
double xmax,
int ny,
double ymin,
double ymax)
399 fZmin = std::numeric_limits<double>::max();
400 fZmax = std::numeric_limits<double>::min();
414 fZmin = std::numeric_limits<double>::max();
415 fZmax = std::numeric_limits<double>::min();
417 fX =
new double[
fNX];
418 fY =
new double[
fNY];
419 fZ =
new double[
fNZ];
421 for(
int i=0; i<
fNX; i++) {
fX[i] = 0.; }
422 for(
int i=0; i<
fNY; i++) {
fY[i] = 0.; }
423 for(
int i=0; i<
fNZ; i++) {
fZ[i] = 0.; }
Bilinear interpolation of 2D functions on a regular grid.
bool AddPoint(double x, double y, double z)
double Evaluate(double x, double y) const
void Init(int nx=0, double xmin=0, double xmax=0, int ny=0, double ymin=0, double ymax=0)
bool AddPoint(double x, double y, double z)
void Init(int nx=0, double xmin=0, double xmax=0, int ny=0, double ymin=0, double ymax=0)
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
double Evaluate(double x, double y) const
int IdxZ(int ix, int iy) const