46{
   49 
   50  int         numberOfEvents;
   52  double      precision;
   54 
   55  try {
   56 
   57    JParser<> zap(
"Example program to create 2D function interpolator from multi-dimensional interpolator.");
 
   58 
   63 
   64    zap(argc, argv);
   65  }
   66  catch(const exception &error) {
   67    FATAL(error.what() << endl);
 
   68  }
   69 
   70  ASSERT(numberOfEvents > 0);
 
   71 
   72  const double xmin = -1.0;
 
   73  const double xmax = +1.0;
 
   75 
   77  typedef JFunction1D_t::abscissa_type                                     abscissa_type;
   78  typedef JFunction1D_t::value_type                                        value_type;
   79 
   82 
   84 
   89 
   93 
   96 
   97  for (
double x0 = xmin; x0 < 
xmax + 0.5*dx; x0 += dx) {
 
   98    for (
double x1 = xmin; x1 < 
xmax + 0.5*dx; x1 += dx) {
 
   99      for (
double x2 = xmin; x2 < 
xmax + 0.5*dx; x2 += dx) {
 
  100        for (
double x3 = xmin; x3 < 
xmax + 0.5*dx; x3 += dx) {
 
  101          for (
double x4 = xmin; x4 < 
xmax + 0.5*dx; x4 += dx) {
 
  102            g5[x0][x1][x2][x3][x4] = 
f5(x0,x1,x2,x3,x4);
 
  103            h5[x0][x1][x2][x3][x4] = 
f5(x0,x1,x2,x3,x4);
 
  104          }
  105        }
  106      }
  107    }
  108  }
  109 
  112 
  113 
  114  const double x0 = +0.15;
  115  const double x1 = -0.25;
  116  const double x2 =  0.25;
  117    
  118  JFunction2D_t g2;
  119 
  120  JTimer timer(
"3D interpolator");
 
  121 
  122  timer.start();
  123 
  124  for (int i = 0; i != 100; ++i) {
  125    copy(h5(x0,x1,x2), g2);      
 
  126  }
  127 
  128  timer.stop();
  129  timer.print(cout, 1.0/100, 
micro_t);
 
  130 
  131  g2.compile();
  132 
  133  JTimer t2(
"2D interpolator");
 
  134  JTimer t5(
"5D interpolator");
 
  135 
  138    
  139  
  140 
  141  const int N = 100;
  142 
  145  double z[N];
  146  double v[N];
  147  double w[N];
  148 
  149  for (int i = 0; i != numberOfEvents; ++i) {
  150 
  151    for (int __i = 0; __i != N; ++__i) {
  152 
  153      const double x3 = gRandom->Uniform(xmin, xmax);
  154      const double x4 = gRandom->Uniform(xmin, xmax);
  155 
  158      z[__i] = 
f5(x0,x1,x2,x3,x4);
 
  159    }
  160 
  161    t2.start();
  162 
  163    for (int __i = 0; __i != N; ++__i) {
  164      v[__i] = g2(x[__i], y[__i]);
  165    }
  166 
  167    t2.stop();
  168 
  169    t5.start();
  170 
  171    for (int __i = 0; __i != N; ++__i) {
  172      w[__i] = g5(x0,x1,x2,x[__i],y[__i]);
  173    }
  174 
  175    t5.stop();
  176 
  177    for (int __i = 0; __i != N; ++__i) {
  178      Q2.put(v[__i] - z[__i]);
  179      Q5.put(w[__i] - z[__i]);
  180    }
  181  }
  182 
  184 
  185    Q2.print(cout);
  186    Q5.print(cout, false);
  187      
  188    t2.print(cout, 1.0 / (N * numberOfEvents), 
nano_t);
 
  189    t5.print(cout, 1.0 / (N * numberOfEvents), 
nano_t);
 
  190  }
  191 
  192  ASSERT(fabs(Q2.getMean()  - Q5.getMean())  <= precision);
 
  193  ASSERT(fabs(Q2.getSTDev() - Q5.getSTDev()) <= precision);
 
  194 
  195  return 0;
  196}
#define ASSERT(A,...)
Assert macro.
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
double f5(const double x0, const double x1, const double x2, const double x3, const double x4)
5D function.
 
int numberOfBins
number of bins for average CDF integral of optical module
 
Auxiliary class for CPU timing and usage.
 
Utility class to parse command line options.
 
void copy(const Head &from, JHead &to)
Copy header from from to to.
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).