Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JPolynome3D.cc File Reference

Example program to test multi-dimensional interpolation. More...

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

Go to the source code of this file.

Functions

double f3 (const double x, const double y, const double z)
 3D function.
 
int main (int argc, char **argv)
 

Detailed Description

Example program to test multi-dimensional interpolation.

Author
mdejong

Definition in file JPolynome3D.cc.

Function Documentation

◆ f3()

double f3 ( const double x,
const double y,
const double z )
inline

3D function.

Definition at line 23 of file JPolynome3D.cc.

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}
const double a

◆ main()

int main ( int argc,
char ** argv )

Definition at line 42 of file JPolynome3D.cc.

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
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}
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
double f3(const double x, const double y, const double z)
3D function.
int numberOfBins
number of bins for average CDF integral of optical module
Definition JSirene.cc:73
Auxiliary class for CPU timing and usage.
Definition JTimer.hh:33
void print(std::ostream &out, const JScale_t scale=milli_t) const
Print timer data.
Definition JTimer.hh:172
void stop()
Stop timer.
Definition JTimer.hh:127
void start()
Start timer.
Definition JTimer.hh:106
General exception.
Definition JException.hh:24
Utility class to parse command line options.
Definition JParser.hh:1698
Multidimensional interpolation method.
void compile()
Compilation.
const double xmax
const double xmin
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478
static const JZero zero
Function object to assign zero value.
Definition JZero.hh:105
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Type definition of a 3rd degree polynomial interpolation based on a JGridCollection with result type ...
Auxiliary class for recursive map list generation.
Definition JMapList.hh:109
Type definition of a 3rd degree polynomial interpolation based on a JGridMap implementation.
Auxiliary data structure for running average, standard deviation and quantiles.
Definition JQuantile.hh:46
std::ostream & print(std::ostream &out, bool lpr=true) const
Print quantile.
Definition JQuantile.hh:382
double getSTDev() const
Get standard deviation.
Definition JQuantile.hh:281
void put(const double x, const double w=1.0)
Put value.
Definition JQuantile.hh:133
double getMean() const
Get mean value.
Definition JQuantile.hh:252