GENIEGenerator
Loading...
Searching...
No Matches
genie::BLI2DNonUnifGrid Class Reference

#include <BLI2D.h>

Inheritance diagram for genie::BLI2DNonUnifGrid:
[legend]
Collaboration diagram for genie::BLI2DNonUnifGrid:
[legend]

Public Member Functions

 BLI2DNonUnifGrid ()
 BLI2DNonUnifGrid (int nx, double xmin, double xmax, int ny, double ymin, double ymax)
 BLI2DNonUnifGrid (int nx, int ny, double *x, double *y, double *z)
bool AddPoint (double x, double y, double z)
double Evaluate (double x, double y) const
Public Member Functions inherited from genie::BLI2DGrid
 BLI2DGrid ()
virtual ~BLI2DGrid ()
double XMin (void) const
double XMax (void) const
double YMin (void) const
double YMax (void) const
double ZMin (void) const
double ZMax (void) const

Private Member Functions

void Init (int nx=0, double xmin=0, double xmax=0, int ny=0, double ymin=0, double ymax=0)

Private Attributes

int fNFillX
int fNFillY

Additional Inherited Members

Protected Member Functions inherited from genie::BLI2DGrid
int IdxZ (int ix, int iy) const
Protected Attributes inherited from genie::BLI2DGrid
int fNX
int fNY
int fNZ
double * fX
double * fY
double * fZ
double fDX
double fDY
double fXmin
double fXmax
double fYmin
double fYmax
double fZmin
double fZmax

Detailed Description

Definition at line 99 of file BLI2D.h.

Constructor & Destructor Documentation

◆ BLI2DNonUnifGrid() [1/3]

genie::BLI2DNonUnifGrid::BLI2DNonUnifGrid ( )

◆ BLI2DNonUnifGrid() [2/3]

BLI2DNonUnifGrid::BLI2DNonUnifGrid ( int nx,
double xmin,
double xmax,
int ny,
double ymin,
double ymax )

Definition at line 182 of file BLI2D.cxx.

184{
185 this->Init(nx, xmin, xmax, ny, ymin, ymax);
186}
void Init(void)

References Init().

◆ BLI2DNonUnifGrid() [3/3]

BLI2DNonUnifGrid::BLI2DNonUnifGrid ( int nx,
int ny,
double * x,
double * y,
double * z )

Definition at line 188 of file BLI2D.cxx.

190{
191 double xmin = x[0];
192 double xmax = x[nx-1];
193 double ymin = y[0];
194 double ymax = y[ny-1];
195
196 this->Init(nx, xmin, xmax, ny, ymin, ymax);
197
198 for(int ix=0; ix<nx; ix++) {
199 for(int iy=0; iy<ny; iy++) {
200 this->AddPoint(x[ix], y[iy], z[this->IdxZ(ix,iy)]);
201 }
202 }
203}
int IdxZ(int ix, int iy) const
Definition BLI2D.cxx:36
bool AddPoint(double x, double y, double z)
Definition BLI2D.cxx:205

References AddPoint(), genie::BLI2DGrid::IdxZ(), and Init().

Member Function Documentation

◆ AddPoint()

bool BLI2DNonUnifGrid::AddPoint ( double x,
double y,
double z )
virtual

Implements genie::BLI2DGrid.

Definition at line 205 of file BLI2D.cxx.

206{
207
208 // check the x,y values' existence before moving anything
209 // if they do, use them
210 // if they don't, add them in the appropriate place
211 //
212 int xidx = -1;
213 int yidx = -1;
214 bool changex = true;
215 bool changey = true;
216 // first, check and see if the x,y values exist
217 // NOTE: == should not be used with double values:
218 // instead, a tolerance of ~5 significant digits is checked
219 for(int i=0;i<fNFillX;i++)
220 {
221 if (!(TMath::Abs(x-fX[i])<=.5*.0000001*(TMath::Abs(x)+TMath::Abs(fX[i]))) && x<fX[i])
222 {
223 // missed one, make sure there aren't too many x and move everything up
224 if (fNFillX==fNX)
225 {
226 LOG("BLI2DNonUnifGrid", pWARN) << "Warning: too many x values, cannot add x = "<<x;
227 return false;
228 }
229 else
230 {
231 xidx=i;
232 changex=true;
233 break;
234 }
235 }
236 else
237 {
238 if (TMath::Abs(x-fX[i])<=.5*.0000001*(TMath::Abs(x)+TMath::Abs(fX[i]))) {
239 xidx=i;
240 LOG("BLI2DNonUnifGrid", pDEBUG) << "x value found at index "<<i;
241 changex=false; break;}
242 changex=true;
243 }
244 }
245 if (changex && xidx<0) xidx=fNFillX;
246 if (changex) LOG("BLI2DNonUnifGrid", pDEBUG) << "Adding x value at index "<<xidx;
247
248 for(int i=0;i<fNFillY;i++)
249 {
250 if (!(TMath::Abs(y-fY[i])<=.5*.0000001*(TMath::Abs(y)+TMath::Abs(fY[i]))) && y<fY[i])
251 {
252 if (fNFillY==fNY)
253 {
254 LOG("BLI2DNonUnifGrid", pWARN) << "Warning: too many y values, cannot add y = "<<y;
255 return false;
256 }
257 else
258 {
259 yidx=i;
260 changey=true;
261 break;
262 }
263 }
264 else
265 {
266 if (TMath::Abs(y-fY[i])<=.5*.0000001*(TMath::Abs(y)+TMath::Abs(fY[i]))) {
267 yidx=i;
268 LOG("BLI2DNonUnifGrid", pDEBUG) << "y value found at index "<<i;
269 changey=false; break;}
270 changey=true;
271 }
272 }
273 if (changey && yidx<0) yidx=fNFillY;
274 if (changey) LOG("BLI2DNonUnifGrid", pDEBUG) << "Adding y value at index "<<yidx;
275
276 // make new entries if needed
277 if (changex && xidx>=0)
278 {
279 for (int j=0;j<fNFillX-xidx;j++)
280 {
281 fX[fNFillX-j]=fX[fNFillX-j-1];
282 for (int k=0;k<fNFillY;k++)
283 {
284 fZ[ this->IdxZ(fNFillX-j,k) ]
285 = fZ[ this->IdxZ(fNFillX-j-1,k) ];
286 }
287 }
288 fX[xidx]=x;
289 fNFillX++;
290 fXmin = TMath::Min(x,fXmin);
291 fXmax = TMath::Max(x,fXmax);
292 }
293 if (changey && yidx>=0)
294 {
295 for (int j=0;j<fNFillY-yidx;j++)
296 {
297 fY[fNFillY-j]=fY[fNFillY-j-1];
298 for (int k=0;k<fNFillX;k++)
299 {
300 fZ[ this->IdxZ(k,fNFillY-j) ]
301 = fZ[ this->IdxZ(k,fNFillY-j-1) ];
302 }
303 }
304 fY[yidx]=y;
305 fNFillY++;
306 fYmin = TMath::Min(y,fYmin);
307 fYmax = TMath::Max(y,fYmax);
308 }
309
310 int iz = this->IdxZ(xidx,yidx);
311
312 fZ[iz] = z;
313
314 fZmin = TMath::Min(z, fZmin);
315 fZmax = TMath::Max(z, fZmax);
316
317 LOG("BLI2DNonUnifGrid", pDEBUG)
318 << "Added x = " << x << " (ix = " << xidx << ")"
319 << " y = " << y << " (iy = " << yidx << ") -> "
320 << " z = " << z << " (iz = " << iz << ")";
321
322 return true;
323}
#define pDEBUG
Definition Messenger.h:63
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
#define pWARN
Definition Messenger.h:60
double fYmin
Definition BLI2D.h:64
double fXmax
Definition BLI2D.h:63
double fZmax
Definition BLI2D.h:67
double * fX
Definition BLI2D.h:57
double fXmin
Definition BLI2D.h:62
double fZmin
Definition BLI2D.h:66
double * fY
Definition BLI2D.h:58
double * fZ
Definition BLI2D.h:59
double fYmax
Definition BLI2D.h:65

References fNFillX, fNFillY, genie::BLI2DGrid::fNX, genie::BLI2DGrid::fNY, genie::BLI2DGrid::fX, genie::BLI2DGrid::fXmax, genie::BLI2DGrid::fXmin, genie::BLI2DGrid::fY, genie::BLI2DGrid::fYmax, genie::BLI2DGrid::fYmin, genie::BLI2DGrid::fZ, genie::BLI2DGrid::fZmax, genie::BLI2DGrid::fZmin, genie::BLI2DGrid::IdxZ(), LOG, pDEBUG, and pWARN.

Referenced by BLI2DNonUnifGrid().

◆ Evaluate()

double BLI2DNonUnifGrid::Evaluate ( double x,
double y ) const
virtual

Implements genie::BLI2DGrid.

Definition at line 325 of file BLI2D.cxx.

326{
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);
331
332 int ix_lo = -2;
333 int iy_lo = -2;
334 for (int i=0;i<fNFillX;i++)
335 {
336 if (evalx<=fX[fNFillX-1-i]) ix_lo=fNFillX-2-i;
337 else break;
338 }
339 for (int i=0;i<fNFillY;i++)
340 {
341 if (evaly<=fY[fNFillY-1-i]) iy_lo=fNFillY-2-i;
342 else break;
343 }
344 int ix_hi = ix_lo + 1;
345 int iy_hi = iy_lo + 1;
346
347 // in case x = xmin
348 if (ix_lo==-1) {ix_lo++; ix_hi++;}
349 if (iy_lo==-1) {iy_lo++; iy_hi++;}
350 // in case x = xmax
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;}
353 // if an error occurs
354 if (ix_lo<0 || iy_lo<0 ) return 0.;
355 if (ix_hi>fNFillX || iy_hi>fNFillY) return 0.;
356
357 double x1 = fX[ix_lo];
358 double x2 = fX[ix_hi];
359 double y1 = fY[iy_lo];
360 double y2 = fY[iy_hi];
361
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) ];
366
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);
370
371 /*
372 LOG("BLI2DNonUnifGrid", pINFO) << "x = " << evalx << " -> nearby nodes: " << x1 << ", " << x2;
373 LOG("BLI2DNonUnifGrid", pINFO) << "y = " << evaly << " -> nearby nodes: " << y1 << ", " << y2;
374 LOG("BLI2DNonUnifGrid", pINFO) << "xmin = " << fXmin << ", xmax = " << fXmax;
375 LOG("BLI2DNonUnifGrid", pINFO) << "ymin = " << fYmin << ", ymax = " << fYmax;
376 LOG("BLI2DNonUnifGrid", pINFO) << "z11 := z(" << this->IdxZ(ix_lo,iy_lo) << ") = " << z11;
377 LOG("BLI2DNonUnifGrid", pINFO) << "z21 := z(" << this->IdxZ(ix_hi,iy_lo) << ") = " << z21;
378 LOG("BLI2DNonUnifGrid", pINFO) << "z12 := z(" << this->IdxZ(ix_lo,iy_hi) << ") = " << z12;
379 LOG("BLI2DNonUnifGrid", pINFO) << "z22 := z(" << this->IdxZ(ix_hi,iy_hi) << ") = " << z22;
380 LOG("BLI2DNonUnifGrid", pINFO) << "z1 = " << z1 << ", z2 = " << z2;
381 LOG("BLI2DNonUnifGrid", pINFO) << "interpolated z(x,y) = " << z;
382 */
383
384 return z;
385}

References fNFillX, fNFillY, genie::BLI2DGrid::fX, genie::BLI2DGrid::fXmax, genie::BLI2DGrid::fXmin, genie::BLI2DGrid::fY, genie::BLI2DGrid::fYmax, genie::BLI2DGrid::fYmin, genie::BLI2DGrid::fZ, and genie::BLI2DGrid::IdxZ().

◆ Init()

void BLI2DNonUnifGrid::Init ( int nx = 0,
double xmin = 0,
double xmax = 0,
int ny = 0,
double ymin = 0,
double ymax = 0 )
privatevirtual

Implements genie::BLI2DGrid.

Definition at line 387 of file BLI2D.cxx.

389{
390 fNX = 0;
391 fNY = 0;
392 fNZ = 0;
393 fNFillX= 0;
394 fNFillY= 0;
395 fXmin = 0.;
396 fXmax = 0.;
397 fYmin = 0.;
398 fYmax = 0.;
399 fZmin = std::numeric_limits<double>::max();
400 fZmax = std::numeric_limits<double>::min();
401 fX = 0;
402 fY = 0;
403 fZ = 0;
404
405 if(nx>1 && ny>1) {
406 fNX = nx;
407 fNY = ny;
408 fNZ = nx * ny;
409
410 fXmin = xmin;
411 fXmax = xmax;
412 fYmin = ymin;
413 fYmax = ymax;
414 fZmin = std::numeric_limits<double>::max();
415 fZmax = std::numeric_limits<double>::min();
416
417 fX = new double[fNX];
418 fY = new double[fNY];
419 fZ = new double[fNZ];
420
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.; }
424 }
425}

References fNFillX, fNFillY, genie::BLI2DGrid::fNX, genie::BLI2DGrid::fNY, genie::BLI2DGrid::fNZ, genie::BLI2DGrid::fX, genie::BLI2DGrid::fXmax, genie::BLI2DGrid::fXmin, genie::BLI2DGrid::fY, genie::BLI2DGrid::fYmax, genie::BLI2DGrid::fYmin, genie::BLI2DGrid::fZ, genie::BLI2DGrid::fZmax, and genie::BLI2DGrid::fZmin.

Member Data Documentation

◆ fNFillX

int genie::BLI2DNonUnifGrid::fNFillX
private

Definition at line 116 of file BLI2D.h.

Referenced by AddPoint(), Evaluate(), and Init().

◆ fNFillY

int genie::BLI2DNonUnifGrid::fNFillY
private

Definition at line 117 of file BLI2D.h.

Referenced by AddPoint(), Evaluate(), and Init().


The documentation for this class was generated from the following files: