Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
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

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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
Quantile calculator.
Definition: JQuantile.hh:88
notice
Definition: JMessage.hh:32
do set_array DAQHEADER JPrintDAQHeader f
Definition: JTuneHV.sh:79
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
data_type v[N+1][M+1]
Definition: JPolint.hh:740
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:483
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:64