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

Test application of consistency between ROOT and C++ or Jpp functions. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include "TMath.h"
#include "Math/PdfFuncMathCore.h"
#include "Math/ProbFuncMathCore.h"
#include "JMath/JMathSupportkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "Jeep/JPrint.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Test application of consistency between ROOT and C++ or Jpp functions.

Author
mdejong

Definition in file JMathSupportkit.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file JMathSupportkit.cc.

24 {
25  using namespace std;
26  using namespace JPP;
27 
28  double precision;
29  int debug;
30 
31  try {
32 
33  JParser<> zap;
34 
35  zap['p'] = make_field(precision) = 1.0e-10;
36  zap['d'] = make_field(debug) = 3;
37 
38  zap(argc, argv);
39  }
40  catch(const exception &error) {
41  FATAL(error.what() << endl);
42  }
43 
44 
45  for (int n = 1; n != 12; ++n) {
46  for (int m = 1; m <= n; ++m) {
47 
48  DEBUG(setw(2) << n << ' ' << setw(2) << m << ' ' << TMath::Binomial(n,m) << ' ' << binomial(n,m) << endl);
49 
50  ASSERT(TMath::Binomial(n,m) == binomial(n,m), "Test of binomial function");
51  }
52  }
53 
54  for (const double x : { -1.0e10, -10.0, -1.0, 0.0, +1.0, +10.0, +1.0e10 } ) {
55 
56  DEBUG("TMath::Erf (" << SCIENTIFIC(12,5) << x << ") " << SCIENTIFIC(12,5) << TMath::Erf(x) << ' ' <<
57  "erf(" << SCIENTIFIC(12,5) << x << ") " << SCIENTIFIC(12,5) << erf(x) << endl);
58 
59  ASSERT(fabs(TMath::Erf(x) - erf(x)) <= precision, "Test of erf function");
60  }
61 
62  for (const double x : { -1.0e10, -10.0, -1.0, 0.0, +1.0, +10.0, +1.0e10 } ) {
63 
64  DEBUG("TMath::Erfc (" << SCIENTIFIC(12,5) << x << ") " << SCIENTIFIC(12,5) << TMath::Erfc (x) << ' ' <<
65  "erfc(" << SCIENTIFIC(12,5) << x << ") " << SCIENTIFIC(12,5) << erfc(x) << endl);
66 
67  ASSERT(fabs(TMath::Erfc(x) - erfc(x)) <= precision, "Test of erfc function");
68  }
69 
70  for (const double x : { 1.0e-10, +1.0, +10.0, 100.0 } ) {
71 
72  DEBUG("TMath::Gamma(" << SCIENTIFIC(12,5) << x << ") " << SCIENTIFIC(12,5) << TMath::Gamma(x) << ' ' <<
73  "tgamma(" << SCIENTIFIC(12,5) << x << ") " << SCIENTIFIC(12,5) << tgamma(x) << endl);
74 
75  ASSERT(fabs(TMath::Gamma(x) - tgamma(x)) <= precision * tgamma(x), "Test of Gamma function");
76  }
77 
78  for (const double a : { 1.0e-10, +1.0, +10.0, +1.0e10 } ) {
79  for (const double x : { 1.0e-10, +1.0, +10.0, +1.0e10 } ) {
80 
81  DEBUG("TMath::Gamma(" << SCIENTIFIC(12,5) << a << "," << SCIENTIFIC(12,5) << x << ") " << SCIENTIFIC(12,5) << TMath::Gamma(a, x) << ' ' <<
82  "Gamma(" << SCIENTIFIC(12,5) << a << "," << SCIENTIFIC(12,5) << x << ") " << SCIENTIFIC(12,5) << Gamma(a, x) << endl);
83 
84  ASSERT(fabs(TMath::Gamma(a,x) - Gamma(a,x)) <= precision, "Test of Gamma function");
85  }
86  }
87 
88  for (int n : { 0, 1, 10, 100 }) {
89  for (const double mu : { 1.0e-10, +1.0, +10.0, +1.0e10 } ) {
90 
91  DEBUG("ROOT::Math::poisson_pdf(" << n << "," << SCIENTIFIC(12,5) << mu << ") " << SCIENTIFIC(12,5) << ROOT::Math::poisson_pdf(n, mu) << ' ' <<
92  "poisson(" << n << "," << SCIENTIFIC(12,5) << mu << ") " << SCIENTIFIC(12,5) << poisson(n, mu) << endl);
93 
94  ASSERT(fabs(ROOT::Math::poisson_cdf(n, mu) - Poisson(n,mu)) <= precision, "Test of Poisson cumulative density function");
95  }
96  }
97 
98  for (int n : { 0, 1, 10, 100 }) {
99  for (const double mu : { 1.0e-10, +1.0, +10.0, +1.0e10 } ) {
100 
101  DEBUG("ROOT::Math::poisson_cdf(" << n << "," << SCIENTIFIC(12,5) << mu << ") " << SCIENTIFIC(12,5) << ROOT::Math::poisson_cdf(n, mu) << ' ' <<
102  "Poisson(" << n << "," << SCIENTIFIC(12,5) << mu << ") " << SCIENTIFIC(12,5) << Poisson(n, mu) << endl);
103 
104  ASSERT(fabs(ROOT::Math::poisson_cdf(n, mu) - Poisson(n,mu)) <= precision, "Test of Poisson cumulative density function");
105  }
106  }
107 
108  return 0;
109 }
Utility class to parse command line options.
Definition: JParser.hh:1500
double Gamma(const double a, const double x)
Incomplete gamma function.
const int n
Definition: JPolint.hh:676
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#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
double Poisson(const size_t n, const double mu)
Poisson cumulative density distribition.
then JCalibrateToT a
Definition: JTuneHV.sh:116
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
double poisson(const size_t n, const double mu)
Poisson probability density distribition.
double binomial(const size_t n, const size_t k)
Binomial function.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484