Jpp  18.0.1-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JQuantile.cc File Reference

Example program to test JTOOLS::JQuantile calculation. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include "TRandom.h"
#include "JTools/JQuantile.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 JTOOLS::JQuantile calculation.

Author
mdejong

Definition in file JQuantile.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 21 of file JQuantile.cc.

22 {
23  using namespace std;
24  using namespace JPP;
25 
26  int numberOfEvents;
27  double x;
28  double sigma;
29  UInt_t seed;
30  double precision;
31  int debug;
32 
33  try {
34 
35  JParser<> zap("Example program to test quantile calculation.");
36 
37  zap['n'] = make_field(numberOfEvents);
38  zap['x'] = make_field(x) = 0.0;
39  zap['s'] = make_field(sigma) = 1.0;
40  zap['S'] = make_field(seed) = 0;
41  zap['e'] = make_field(precision) = 1.0e-2;
42  zap['d'] = make_field(debug) = 3;
43 
44  zap(argc, argv);
45  }
46  catch(const exception &error) {
47  FATAL(error.what() << endl);
48  }
49 
50  if (numberOfEvents < 2) {
51  FATAL("Fatal error: number of events " << numberOfEvents << endl);
52  }
53 
54  gRandom->SetSeed(seed);
55 
56  {
57  JQuantile Q;
58 
59  for (int i = 0; i != numberOfEvents; ++i) {
60  Q.put(gRandom->Gaus(x, sigma));
61  }
62 
63  NOTICE("quantity " << CENTER(10) << "calculated" << " | " << CENTER(10) << "true" << endl);
64  NOTICE("mean " << FIXED(10,3) << Q.getMean() << " | " << FIXED(10,3) << x << endl);
65  NOTICE("RMS " << FIXED(10,3) << Q.getSTDev() << " | " << FIXED(10,3) << sigma << endl);
66 
67  ASSERT(numberOfEvents > 0, "Test number of events.");
68  ASSERT(fabs(Q.getMean() - x) <= precision, "Test mean.");
69  ASSERT(fabs(Q.getSTDev() - sigma) <= precision, "Test sigma.");
70  }
71  {
72  JQuantile Q("", true);
73 
74  for (int i = 0; i != numberOfEvents; ++i) {
75  Q.put(gRandom->Uniform(0.0, 1.0));
76  }
77 
78  for (const double x : { 0.1, 0.5, 0.9}) {
79 
80  NOTICE("forward quantile " << FIXED(6,3) << x << ' ' << FIXED(6,3) << Q.getQuantile(x, JQuantile::forward_t) << endl);
81  NOTICE("symmetric quantile " << FIXED(6,3) << x << ' ' << FIXED(6,3) << Q.getQuantile(x, JQuantile::symmetric_t) << endl);
82  NOTICE("backward quantile " << FIXED(6,3) << x << ' ' << FIXED(6,3) << Q.getQuantile(x, JQuantile::backward_t) << endl);
83 
84  ASSERT(fabs(Q.getQuantile(x, JQuantile::forward_t) - ( x )) <= precision, "Test forward quantile ");
85  ASSERT(fabs(Q.getQuantile(x, JQuantile::symmetric_t) - ( x )) <= precision, "Test symmetric quantile ");
86  ASSERT(fabs(Q.getQuantile(x, JQuantile::backward_t) - (1.0 - x)) <= precision, "Test backward quantile ");
87  }
88  }
89 
90  return 0;
91 }
Utility class to parse command line options.
Definition: JParser.hh:1514
Q(UTCMax_s-UTCMin_s)-livetime_s
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
const double sigma[]
Definition: JQuadrature.cc:74
Auxiliary data structure for alignment of data.
Definition: JManip.hh:366
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level