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

Example program to test transformable function. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TMath.h"
#include "TRandom.h"
#include "JTools/JFunction1D_t.hh"
#include "JTools/JTransformableMultiFunction.hh"
#include "JTools/JFunctionalMap_t.hh"
#include "JTools/JQuantile.hh"
#include "Jeep/JPrint.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 test transformable function.

Author
mdejong

Definition in file JTransformableFunction.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 163 of file JTransformableFunction.cc.

164{
165 using namespace std;
166 using namespace JPP;
167
168 int numberOfEvents;
169 int numberOfBins;
170 bool transform;
171 int debug;
172
173 try {
174
175 JParser<> zap("Example program to test transformable function.");
176
177 zap['n'] = make_field(numberOfEvents);
178 zap['N'] = make_field(numberOfBins) = 35;
179 zap['U'] = make_field(transform);
180 zap['d'] = make_field(debug) = 3;
181
182 zap(argc, argv);
183 }
184 catch(const exception &error) {
185 FATAL(error.what() << endl);
186 }
187
188 if (numberOfEvents <= 0) {
189 FATAL("No events." << endl);
190 }
191
192
193 const double xmin = 0.1;
194 const double xmax = 1.0;
195 const double dx = (xmax - xmin) / 3;
196
197 function_type h2;
198
199 for (double x = xmin; x < xmax + 0.5*dx; x += dx) {
200
201 const double ymin = -5.0 * xmax;
202 const double ymax = +5.0 * xmax;
203 const double dy = (ymax - ymin) / (numberOfBins - 1);
204
205 for (double y = ymin; y < ymax + 0.5*dy; y += dy) {
206 h2[x][y] = f2(x,y);
207 }
208 }
209
210 h2.setExceptionHandler(new typename function_type::JDefaultResult(JMATH::zero));
211
212 if (transform) {
213 h2.transform(JTransformer_t());
214 }
215
216 h2.compile();
217
218
219 JQuantile Q[] = {
220 JQuantile("function"),
221 JQuantile("derivative"),
222 JQuantile("integral")
223 };
224
225 const double ymin = -5.0 * xmax;
226 const double ymax = +5.0 * xmax;
227
228 for (int i = 0; i != numberOfEvents; ++i) {
229
230 const double x = gRandom->Uniform(xmin, xmax);
231 const double y = gRandom->Uniform(ymin, ymax);
232
233 try {
234
235 const result_type value = h2(x,y);
236
237 const double f = f2(x,y);
238 const double fp = g2(x,y);
239 const double v = G2(x,y);
240
241 Q[0].put(value.f - f);
242 Q[1].put(value.fp - fp);
243 Q[2].put(value.v - v);
244 }
245 catch(const std::exception& error) {}
246 }
247
248
249 if (debug >= notice_t) {
250
251 cout << " ";
252 for (int i = 0; i != sizeof(Q)/sizeof(Q[0]); ++i) {
253 cout << " " << setw(10) << Q[i].getTitle();
254 }
255 cout << endl;
256
257 cout << "mean ";
258 for (int i = 0; i != sizeof(Q)/sizeof(Q[0]); ++i) {
259 cout << " " << SCIENTIFIC(10,2) << Q[i].getMean();
260 }
261 cout << endl;
262
263 cout << "RMS ";
264 for (int i = 0; i != sizeof(Q)/sizeof(Q[0]); ++i) {
265 cout << " " << SCIENTIFIC(10,2) << Q[i].getSTDev();
266 }
267 cout << endl;
268 }
269}
#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
int numberOfBins
number of bins for average CDF integral of optical module
Definition JSirene.cc:73
const std::string & getTitle() const
Get title.
Definition JTitle.hh:55
Utility class to parse command line options.
Definition JParser.hh:1698
const double xmax
const double xmin
@ notice_t
notice
Definition JMessage.hh:32
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).
Auxiliary data structure for running average, standard deviation and quantiles.
Definition JQuantile.hh:46
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
Auxiliary data structure for floating point format specification.
Definition JManip.hh:488