GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <c.andreopoulos \at cern.ch>
9  University of Liverpool
10 
11 \created May 29, 2009
12 
13 \cpright Copyright (c) 2003-2024, The GENIE Collaboration
14  For the full text of the license visit http://copyright.genie-mc.org
15 
16 */
17 //____________________________________________________________________________
18 
19 #include <TMath.h>
20 #include <TFile.h>
21 #include <TNtuple.h>
22 
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:75
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:71
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
int main(int argc, char **argv)
Definition: gAtmoEvGen.cxx:327
bool AddPoint(double x, double y, double z)
Definition: BLI2D.cxx:73
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
double func(double x, double y)
#define pINFO
Definition: Messenger.h:62
double Evaluate(double x, double y) const
Definition: BLI2D.cxx:92
TRandom3 & RndGen(void) const
rnd number generator for generic usage
Definition: RandomGen.h:80