Jpp  17.1.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPolynome3D.cc
Go to the documentation of this file.
1 
2 
3 #include <string>
4 #include <iostream>
5 #include <iomanip>
6 
7 #include "TRandom3.h"
8 
9 #include "JTools/JMapList.hh"
10 #include "JTools/JFunction1D_t.hh"
12 #include "JTools/JMultiFunction.hh"
13 #include "JTools/JQuantile.hh"
14 
15 #include "Jeep/JTimer.hh"
16 #include "Jeep/JParser.hh"
17 #include "Jeep/JMessage.hh"
18 
19 
20 /**
21  * 3D function.
22  */
23 inline double f3(const double x, const double y, const double z)
24 {
25  static const double a = 1.0;
26  static const double b = 1.0;
27  static const double c = 1.0;
28 
29  return
30  x * (a + x * (b + c*x)) *
31  y * (a + y * (b + c*y)) *
32  z * (a + z * (b + c*z));
33 }
34 
35 
36 /**
37  * \file
38  *
39  * Example program to test multi-dimensional interpolation.
40  * \author mdejong
41  */
42 int main(int argc, char **argv)
43 {
44  using namespace std;
45  using namespace JPP;
46 
47  int numberOfEvents;
48  int numberOfBins;
49  double precision;
50  int debug;
51 
52  try {
53 
54  JParser<> zap("Example program to test multi-dimensional interpolation.");
55 
56  zap['n'] = make_field(numberOfEvents) = 1000;
57  zap['N'] = make_field(numberOfBins) = 11;
58  zap['e'] = make_field(precision) = 1.0e-14;
59  zap['d'] = make_field(debug) = 3;
60 
61  zap(argc, argv);
62  }
63  catch(const exception &error) {
64  FATAL(error.what() << endl);
65  }
66 
67 
68  const double xmin = -1.0;
69  const double xmax = +1.0;
70  const double dx = (xmax - xmin) / (numberOfBins - 1);
71 
72 
73  typedef JGridPolint3Function1D_t JFunction1D_t;
74 
75  typedef JMAPLIST<JPolint3FunctionalGridMap,
76  JPolint3FunctionalGridMap>::maplist JMaplist_t;
77 
78  typedef JMultiFunction<JFunction1D_t, JMaplist_t> JMultiFunction_t;
79 
80 
81  JMultiFunction_t g3;
82 
83 
84  for (double x = xmin; x < xmax + 0.5*dx; x += dx) {
85  for (double y = xmin; y < xmax + 0.5*dx; y += dx) {
86  for (double z = xmin; z < xmax + 0.5*dx; z += dx) {
87  g3[x][y][z] = f3(x,y,z);
88  }
89  }
90  }
91 
92 
93  g3.compile();
94  g3.setExceptionHandler(new JFunction1D_t::JDefaultResult(JMATH::zero));
95 
96 
97  if (numberOfEvents > 0) {
98 
99  JTimer timer;
100 
101  JQuantile Q;
102 
103  for (int i = 0; i != numberOfEvents; ++i) {
104 
105  const double x = gRandom->Uniform(xmin, xmax);
106  const double y = gRandom->Uniform(xmin, xmax);
107  const double z = gRandom->Uniform(xmin, xmax);
108 
109  const double v = f3(x,y,z);
110 
111  timer.start();
112 
113  const double w = g3(x,y,z);
114 
115  timer.stop();
116 
117  Q.put(v - w);
118  }
119 
120  if (debug >= debug_t) {
121 
122  Q.print(cout);
123 
124  timer.print(cout, 1.0 / numberOfEvents, micro_t);
125  }
126 
127  ASSERT(Q.getMean() <= precision);
128  ASSERT(Q.getSTDev() <= precision);
129 
130  } else {
131 
132  for ( ; ; ) {
133 
134  cout << "> " << flush;
135 
136  string buffer;
137 
138  if (getline(cin, buffer) && !buffer.empty()) {
139 
140  double x, y, z;
141 
142  istringstream(buffer) >> x >> y >> z;
143 
144  try {
145  cout << f3(x,y,z) << ' ' << g3(x,y,z) << endl;
146  }
147  catch(const JException& exception) {
148  cout << exception << endl;
149  }
150 
151  } else {
152  break;
153  }
154  }
155  }
156 
157  return 0;
158 }
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1517
data_type w[N+1][M+1]
Definition: JPolint.hh:778
Q(UTCMax_s-UTCMin_s)-livetime_s
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
micro
Definition: JScale.hh:29
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
Various implementations of functional maps.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
const double xmin
Definition: JQuadrature.cc:23
then JCalibrateToT a
Definition: JTuneHV.sh:116
Utility class to parse command line options.
double f3(const double x, const double y, const double z)
3D function.
Definition: JPolynome3D.cc:23
$WORKDIR ev_configure_domsimulator txt echo process $DOM_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DOM_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
data_type v[N+1][M+1]
Definition: JPolint.hh:777
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:68
int debug
debug level