Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPolynome3D+2D.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 
6 #include "TRandom3.h"
7 
8 #include "JTools/JMapList.hh"
11 #include "JTools/JMultiFunction.hh"
12 #include "JTools/JQuantile.hh"
13 
14 #include "Jeep/JTimer.hh"
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 
19 /**
20  * 5D function.
21  */
22 inline double f5(const double x0,
23  const double x1,
24  const double x2,
25  const double x3,
26  const double x4)
27 {
28  static const double a = 1.0;
29  static const double b = 1.0;
30  static const double c = 1.0;
31 
32  return
33  x0 * (a + x0 * (b + c*x0)) *
34  x1 * (a + x1 * (b + c*x1)) *
35  x2 * (a + x2 * (b + c*x2)) *
36  x3 * (a + x3 * (b + c*x3)) *
37  x4 * (a + x4 * (b + c*x4));
38 }
39 
40 
41 /**
42  * \file
43  * Example program to test multi-dimensional interpolation with multi-dimensional function objects.
44  * \author mdejong
45  */
46 int main(int argc, char **argv)
47 {
48  using namespace std;
49 
50  int numberOfEvents;
51  int numberOfBins;
52  int debug;
53 
54  try {
55 
56  JParser<> zap("Example program to test multi-dimensional interpolation with multi-dimensional function objects.");
57 
58  zap['n'] = make_field(numberOfEvents) = 1000;
59  zap['N'] = make_field(numberOfBins) = 11;
60  zap['d'] = make_field(debug) = 3;
61 
62  zap(argc, argv);
63  }
64  catch(const exception &error) {
65  FATAL(error.what() << endl);
66  }
67 
68 
69  using namespace JPP;
70 
71 
72  const double xmin = -1.0;
73  const double xmax = +1.0;
74  const double dx = (xmax - xmin) / (numberOfBins - 1);
75 
76 
77  typedef JGridPolint3Function1D_t JFunction1D_t;
78 
79  typedef JMAPLIST<JPolint3FunctionalGridMap>::maplist JMaplist1D_t;
80 
81  typedef JMAPLIST<JPolint3FunctionalGridMap,
82  JPolint3FunctionalGridMap,
83  JPolint3FunctionalGridMap>::maplist JMaplist3D_t;
84 
85  typedef JMultiFunction<JFunction1D_t, JMaplist1D_t> JFunction2D_t;
86  typedef JMultiFunction<JFunction2D_t, JMaplist3D_t> JFunction5D_t;
87 
88  JFunction5D_t g5;
89 
90 
91  for (double x0 = xmin; x0 <= xmax + 0.5*dx; x0 += dx) {
92  for (double x1 = xmin; x1 <= xmax + 0.5*dx; x1 += dx) {
93  for (double x2 = xmin; x2 <= xmax + 0.5*dx; x2 += dx) {
94  for (double x3 = xmin; x3 <= xmax + 0.5*dx; x3 += dx) {
95  for (double x4 = xmin; x4 <= xmax + 0.5*dx; x4 += dx) {
96  g5[x0][x1][x2][x3][x4] = f5(x0, x1, x2, x3, x4);
97  }
98  }
99  }
100  }
101  }
102 
103  g5.compile();
104  g5.setExceptionHandler(new JFunction1D_t::JDefaultResult(JMATH::zero));
105 
106 
107  if (numberOfEvents > 0) {
108 
109  JTimer timer;
110 
111  JQuantile Q;
112 
113  for (int i = 0; i != numberOfEvents; ++i) {
114 
115  const double x0 = gRandom->Uniform(xmin, xmax);
116  const double x1 = gRandom->Uniform(xmin, xmax);
117  const double x2 = gRandom->Uniform(xmin, xmax);
118  const double x3 = gRandom->Uniform(xmin, xmax);
119  const double x4 = gRandom->Uniform(xmin, xmax);
120 
121  const double v = f5(x0,x1,x2,x3,x4);
122 
123  timer.start();
124 
125  const double w = g5(x0,x1,x2,x3,x4);
126 
127  timer.stop();
128 
129  Q.put(v - w);
130  }
131 
132  Q.print(cout);
133 
134  timer.print(cout, 1.0 / numberOfEvents);
135  }
136 }
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1514
data_type w[N+1][M+1]
Definition: JPolint.hh:867
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
Definition: Main.cc:15
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
Various implementations of functional maps.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
then JCalibrateToT a
Definition: JTuneHV.sh:113
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
$WORKDIR ev_configure_dqsimulator txt echo process $DQ_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DQ_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
const double xmin
Definition: JQuadrature.cc:23
Utility class to parse command line options.
double f5(const double x0, const double x1, const double x2, const double x3, const double x4)
5D function.
data_type v[N+1][M+1]
Definition: JPolint.hh:866
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:69
int debug
debug level