Jpp  18.2.1-ARCA-DF-PATCH
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JQuantiles.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <cmath>
6 
7 #include "TMath.h"
8 
9 #include "JTools/JCollection.hh"
10 #include "JTools/JGrid.hh"
11 #include "JTools/JQuantiles.hh"
12 #include "JTools/JFunction1D_t.hh"
13 
14 #include "Jeep/JPrint.hh"
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 
19 /**
20  * Function.
21  *
22  * \param x
23  * \return function value
24  */
25 inline Double_t g1(const Double_t x)
26 {
27  return TMath::Gaus(x, 0.0, 1.0, kTRUE);
28 }
29 
30 
31 /**
32  * Integral of method g1.
33  *
34  * \param x
35  * \return integral value
36  */
37 inline Double_t G1(const Double_t x)
38 {
39  return 0.5 * (1.0 + TMath::Erf(sqrt(0.5)*x));
40 }
41 
42 
43 /**
44  * \file
45  * Example program to test JTOOLS::JQuantiles calculation of a function.
46  * \author mdejong
47  */
48 int main(int argc, char **argv)
49 {
50  using namespace std;
51 
52  int numberOfBins;
53  double Q;
54  double precision;
55  int debug;
56 
57  try {
58 
59  JParser<> zap("Example program to test quantiles calculation of a function.");
60 
61  zap['N'] = make_field(numberOfBins) = 13;
62  zap['Q'] = make_field(Q) = 0.5;
63  zap['e'] = make_field(precision) = 1.0e-3;
64  zap['d'] = make_field(debug) = 3;
65 
66  zap(argc, argv);
67  }
68  catch(const exception &error) {
69  FATAL(error.what() << endl);
70  }
71 
72  if (numberOfBins < 2) {
73  FATAL("Fatal error: number of bins " << numberOfBins << endl);
74  }
75 
76  if (Q < 0.0 || Q > 1.0) {
77  FATAL("Fatal error: quantile " << Q << endl);
78  }
79 
80  using namespace JPP;
81 
82  const Double_t xmin = -5.0;
83  const Double_t xmax = +5.0;
84 
85  JQuantiles quantiles(make_grid(numberOfBins, xmin, xmax), g1, Q);
86 
87  NOTICE("quantity " << setw(10) << "calculated" << " / " << setw(10) << "true" << endl);
88  NOTICE("X " << FIXED(10,6) << quantiles.getX() << " / " << FIXED(10,6) << 0.0 << endl);
89  NOTICE("FWHM " << FIXED(10,6) << quantiles.getFWHM() << " / " << FIXED(10,6) << 2.0*sqrt(2.0*log(2.0)) << endl);
90  NOTICE("integral " << FIXED(10,6) << quantiles.getIntegral() << " / " << FIXED(10,6) << G1(xmax) - G1(xmin) << endl);
91  NOTICE("quantile " << FIXED(10,6) << (G1(quantiles.getUpperLimit()) -
92  G1(quantiles.getLowerLimit())) << " / " << FIXED(10,6) << Q << endl);
93 
94  ASSERT(fabs(quantiles.getX() - 0.0) < precision);
95  ASSERT(fabs(quantiles.getFWHM() - 2.0*sqrt(2.0*log(2.0))) < precision);
96  ASSERT(fabs(quantiles.getIntegral() - (G1(xmax) - G1(xmin))) < precision);
97  ASSERT(fabs((G1(quantiles.getUpperLimit()) -
98  G1(quantiles.getLowerLimit())) - Q) < precision);
99 }
100 
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1514
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
Definition: Main.cc:15
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
Double_t G1(const Double_t x)
Integral of method g1.
Definition: JQuantiles.cc:37
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define NOTICE(A)
Definition: JMessage.hh:64
General purpose class for a collection of sorted elements.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
then set_variable DIR else fatal Wrong number of arguments fi for INPUT_FILE in ls rt $DIR stage * log
const double xmin
Definition: JQuadrature.cc:23
Utility class to parse command line options.
JGrid< JAbscissa_t > make_grid(const int nx, const JAbscissa_t Xmin, const JAbscissa_t Xmax)
Helper method for JGrid.
Definition: JGrid.hh:209
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:69
int debug
debug level
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25