Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMultiFunction2D.cc File Reference

Example program to create 1D function interpolator from multi-dimensional interpolator. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include "TRandom3.h"
#include "TMath.h"
#include "JTools/JMapList.hh"
#include "JTools/JFunction1D_t.hh"
#include "JTools/JFunctionalMap_t.hh"
#include "JTools/JConstantFunction1D.hh"
#include "JTools/JMultiFunction.hh"
#include "JTools/JQuantile.hh"
#include "JTools/JToolsToolkit.hh"
#include "Jeep/JTimer.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to create 1D function interpolator from multi-dimensional interpolator.

Author
mdejong

Definition in file JMultiFunction2D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 45 of file JMultiFunction2D.cc.

46 {
47  using namespace std;
48  using namespace JPP;
49 
50  int numberOfEvents;
51  int numberOfBins;
52  double precision;
53  int debug;
54 
55  try {
56 
57  JParser<> zap("Example program to create 1D function interpolator from multi-dimensional interpolator.");
58 
59  zap['n'] = make_field(numberOfEvents) = 1000;
60  zap['N'] = make_field(numberOfBins) = 11;
61  zap['e'] = make_field(precision) = 1.0e-14;
62  zap['d'] = make_field(debug) = 3;
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;
74  const double dx = (xmax - xmin) / (numberOfBins - 1);
75 
76  typedef JSplineFunction1D_t JFunction1D_t;
77  typedef JFunction1D_t::abscissa_type abscissa_type;
78  typedef JFunction1D_t::value_type value_type;
79 
80  typedef JMAPLIST<JPolint1FunctionalMap>::maplist JMaplist1D_t;
81  typedef JMultiFunction<JFunction1D_t, JMaplist1D_t> JFunction2D_t;
82 
84 
88  JPolint1FunctionalMap>::maplist JMaplist4D_t;
89 
92  JPolint1FunctionalMap>::maplist JMaplist3D_t;
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 
110  g5.compile();
111 
112 
113  const double x0 = +0.15;
114  const double x1 = -0.25;
115  const double x2 = 0.25;
116 
117  JFunction2D_t g2;
118 
119  JTimer timer("3D interpolator");
120 
121  timer.start();
122 
123  for (int i = 0; i != 100; ++i) {
124  copy(h5(x0,x1,x2), g2); // put interpolated data into 1D functional object
125  }
126 
127  timer.stop();
128  timer.print(cout, 1.0/100, micro_t);
129 
130  g2.compile();
131 
132  JTimer t2("2D interpolator");
133  JTimer t5("5D interpolator");
134 
135  JQuantile Q2("2D interpolator");
136  JQuantile Q5("5D interpolator");
137 
138  // mini buffer to reduce overhead in timer
139 
140  const int N = 100;
141 
142  double x[N];
143  double y[N];
144  double z[N];
145  double v[N];
146  double w[N];
147 
148  for (int i = 0; i != numberOfEvents; ++i) {
149 
150  for (int __i = 0; __i != N; ++__i) {
151 
152  const double x3 = gRandom->Uniform(xmin, xmax);
153  const double x4 = gRandom->Uniform(xmin, xmax);
154 
155  x[__i] = x3;
156  y[__i] = x4;
157  z[__i] = f5(x0,x1,x2,x3,x4);
158  }
159 
160  t2.start();
161 
162  for (int __i = 0; __i != N; ++__i) {
163  v[__i] = g2(x[__i], y[__i]);
164  }
165 
166  t2.stop();
167 
168  t5.start();
169 
170  for (int __i = 0; __i != N; ++__i) {
171  w[__i] = g5(x0,x1,x2,x[__i],y[__i]);
172  }
173 
174  t5.stop();
175 
176  for (int __i = 0; __i != N; ++__i) {
177  Q2.put(v[__i] - z[__i]);
178  Q5.put(w[__i] - z[__i]);
179  }
180  }
181 
182  if (debug >= notice_t) {
183 
184  Q2.print(cout);
185  Q5.print(cout, false);
186 
187  t2.print(cout, 1.0 / (N * numberOfEvents), nano_t);
188  t5.print(cout, 1.0 / (N * numberOfEvents), nano_t);
189  }
190 
191  ASSERT(fabs(Q2.getMean() - Q5.getMean()) <= precision);
192  ASSERT(fabs(Q2.getSTDev() - Q5.getSTDev()) <= precision);
193 
194  return 0;
195 }
Utility class to parse command line options.
Definition: JParser.hh:1410
micro
Definition: JScale.hh:29
notice
Definition: JMessage.hh:30
Quantile calculator.
Definition: JQuantile.hh:34
Type definition of a spline interpolation method based on a JCollection with double result type...
Template implementation of function object in one dimension returning a constant value.
#define ASSERT(A)
Assert macro.
Definition: JMessage.hh:72
Multidimensional interpolation method.
Map list.
Definition: JMapList.hh:24
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
Auxiliary class for CPU timing and usage.
Definition: JTimer.hh:32
int debug
debug level
Definition: JSirene.cc:59
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:108
#define FATAL(A)
Definition: JMessage.hh:65
nano
Definition: JScale.hh:28
double f5(const double x0, const double x1, const double x2, const double x3, const double x4)
5D function.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:40