53{
56
57 int numberOfEvents;
59
60 try {
61
62 JParser<> zap(
"Example program to test interpolation between 2D tables.");
63
66
67 zap(argc, argv);
68 }
69 catch(const exception &error) {
70 FATAL(error.what() << endl);
71 }
72
73
74 const int NX = 21;
75 const int NY = 11;
76 const int NZ = 11;
77
81
82
86
87
88 JFunction1D_t buffer;
89
90 for (int i = 0; i != X.getSize(); ++i) {
91
92 DEBUG(
"table[" << i <<
"]" << endl);
93
94 const double x = X.getX(i);
95
96 JTable2D_t& table = buffer[
x];
97
98 for (int __i = 0; __i != NY; ++__i) {
99 for (int __j = 0; __j != NZ; ++__j) {
100
101 const double y = Y.getX(__i);
102 const double z = Z.getX(__j);
103
104 table[__i][__j] =
f3(x,y,z);
105
107 }
109 }
110 }
111
112
113
114
117
118 JMultiFunction_t g2;
119
120 g2.configure(Y);
121
122 for (JMultiFunction_t::iterator i = g2.begin(); i != g2.end(); ++i) {
123 i->getY().configure(Z);
124 }
125
126
129
132
133
134 for (int i = 0; i != numberOfEvents; ++i) {
135
136 const double x = gRandom->Uniform(X.getXmin(), X.getXmax());
137 const double y = gRandom->Uniform(Y.getXmin(), Y.getXmax());
138 const double z = gRandom->Uniform(Z.getXmin(), Z.getXmax());
139
140 const double v =
f3(x,y,z);
141
142
143
144
145 t1.start();
146
147 const int __i = (int) (Y.getSize() * (y - Y.getXmin()) / (Y.getXmax() - Y.getXmin()));
148 const int __j = (int) (Z.getSize() * (z - Z.getXmin()) / (Z.getXmax() - Z.getXmin()));
149
150 const double w1 = buffer(x)[__i][__j];
151
152 t1.stop();
153
154
155
156
157 t2.start();
158
159 const JTable2D_t& table = buffer(x);
160
161 for (int __i = 0; __i != Y.getSize(); ++__i) {
162 for (int __j = 0; __j != Z.getSize(); ++__j) {
163 g2.getY(__i).getY(__j) = table[__i][__j];
164 }
165 }
166
167 g2.compile();
168
169 const double w2 = g2(y,z);
170
171 t2.stop();
172
173 f1.put(v - w1);
174 f2.put(v - w2);
175 }
176
177
179
180 cout << i->getTitle() << endl;
181 cout <<
"mean " <<
SCIENTIFIC(10,2) << i->getMean() << endl;
182 cout <<
"RMS " <<
SCIENTIFIC(10,2) << i->getSTDev() << endl;
183 }
184
186 i->print(cout, true, micro_t);
187 }
188}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
double f3(const double x, const double y, const double z)
3D function.
Auxiliary class for CPU timing and usage.
const std::string & getTitle() const
Get title.
Utility class to parse command line options.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Auxiliary data structure for floating point format specification.