gtestBLI2DUnifGrid.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3 
4 \program gtestBLI2DUnifGrid
5 
6 \brief Program used for testing / debugging GENIE's BLI2DUnifGrid
7 
8 \author Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
9  University of Liverpool & STFC Rutherford Appleton Lab
10 
11 \created May 29, 2009
12 
13 \cpright Copyright (c) 2003-2016, GENIE Neutrino MC Generator Collaboration
14  For the full text of the license visit http://copyright.genie-mc.org
15  or see $GENIE/LICENSE
16 */
17 //____________________________________________________________________________
18 
19 #include <TMath.h>
20 #include <TFile.h>
21 #include <TNtuple.h>
22 
23 #include "Messenger/Messenger.h"
24 #include "Numerical/BLI2D.h"
25 #include "Numerical/RandomGen.h"
26 
27 using namespace genie;
28 
29 double func(double x, double y);
30 
31 int main(int /*argc*/, char ** /*argv*/)
32 {
33  int npoints=10000;
34 
35  int nx = 100;
36  int ny = 100;
37 
38  double xmin = -5;
39  double xmax = 5;
40  double ymin = -5;
41  double ymax = 5;
42 
43  double dx = (xmax-xmin)/(nx-1);
44  double dy = (ymax-ymin)/(ny-1);
45 
46  BLI2DUnifGrid biln(nx,xmin,xmax,ny,ymin,ymax);
47 
48  for(int ix=0; ix<nx; ix++) {
49  double x = xmin + ix * dx;
50  for(int iy=0; iy<ny; iy++) {
51  double y = ymin + iy * dy;
52  double z = func(x,y);
53  biln.AddPoint(x,y,z);
54  }
55  }
56 
58 
59  TNtuple * nt = new TNtuple("nt","billinear interpolation validation","x:y:ztrue:zeval");
60 
61  for(int ip=0; ip<npoints; ip++) {
62  double rx = rnd->RndGen().Uniform();
63  double ry = rnd->RndGen().Uniform();
64  double x = xmin + (xmax-xmin)*rx;
65  double y = ymin + (ymax-ymin)*ry;
66  double zt = func(x,y);
67  double ze = biln.Evaluate(x,y);
68 
69  nt->Fill(x,y,zt,ze);
70  }
71 
72  TFile f("./bli2dug.root","recreate");
73  nt->Write();
74  f.Close();
75 
76  LOG("test", pINFO) << "Done!";
77  return 0;
78 }
79 
80 
81 double func(double x, double y)
82 {
83  //return x*y+10*x-7*y+1;
84  return TMath::Sin(x)/x * TMath::Sin(y)/y;
85 }
Bilinear interpolation of 2D functions on a regular grid.
Definition: BLI2D.h:76
std::map< std::string, double > xmax
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:79
TString ip
Definition: loadincs.C:5
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:30
Double_t ymax
Definition: plot.C:25
bool AddPoint(double x, double y, double z)
Definition: BLI2D.cxx:86
double dy[NP][NC]
double dx[NP][NC]
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
double func(double x, double y)
#define pINFO
Definition: Messenger.h:63
z
Definition: test.py:28
double Evaluate(double x, double y) const
Definition: BLI2D.cxx:105
TRandom3 & RndGen(void) const
rnd number generator for generic usage
Definition: RandomGen.h:81
Double_t ymin
Definition: plot.C:24
TNtuple * nt
Definition: drawXsec.C:2
int main(int, char **)