Jpp in_tag_pdf_generation
the software that should make you happy
Loading...
Searching...
No Matches
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

◆ main()

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 for (double P : { 1.0e-3, 1.0e-4, 1.0e-5 }) {
109 for (double x : { 1.0e-1, 1.0e0, 1.0e1 }) {
110
111 DEBUG("getNs(" << FIXED(7,3) << x << "," << FIXED(9,5) << P << ") = " << setw(3) << getNs(x,P) << ' ' <<
112 "getFs(" << FIXED(7,3) << x << "," << FIXED(9,5) << P << ") = " << FIXED(7,3) << getFs(x,P,1.0) << endl);
113
114 ASSERT(fabs(getFs(x,P,1.0) - getNs(x,P)) <= precision, "Test of signal events.");
115 }
116 }
117
118 return 0;
119}
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#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
Utility class to parse command line options.
Definition JParser.hh:1698
double Gamma(const double a, const double x)
Incomplete gamma function.
size_t getNs(const double background, const double P)
Get minimal number of events to exceed Poisson probability given number of background events.
double getFs(const double background, const double P, const double precision)
Get minimal number of events to exceed Poisson probability given number of background events.
double Poisson(const size_t n, const double mu)
Poisson cumulative density distribition.
double binomial(const size_t n, const size_t k)
Binomial function.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
const int n
Definition JPolint.hh:791
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Auxiliary data structure for floating point format specification.
Definition JManip.hh:488