Jpp 21.0.0-rc.3
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.

Macros

#define PRINT(A)
 

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.

Macro Definition Documentation

◆ PRINT

#define PRINT ( A)
Value:
#A << " = " << SCIENTIFIC(12,3) << A << ';'

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 for (double a : { -1.0, +1.0, -1.0e-99, +1.0e-99, 0.0 }) {
119 for (double b : { -1.0, +1.0, -1.0e-99, +1.0e-99, 0.0 }) {
120 for (double c : { -1.0, +1.0, -1.0e-99, +1.0e-99, 0.0 }) {
121
122 auto f1 = [a,b,c](const double x) { return a*x*x + b*x + c; };
123
124 const roots_type rs = roots(a, b, c, precision);
125
126 const double x1 = rs.x1;
127 const double x2 = rs.x2;
128
129#define PRINT(A) #A << " = " << SCIENTIFIC(12,3) << A << ';'
130
131 if (rs.roots == roots_type::DOUBLE_t) {
132 ASSERT(fabs(f1(x1)) <= precision, PRINT(a) << ' ' << PRINT(b) << ' ' << PRINT(c) << ' ' << PRINT(x1) << " -> " << PRINT(f1(x1)));
133 ASSERT(fabs(f1(x1)) <= precision, PRINT(a) << ' ' << PRINT(b) << ' ' << PRINT(c) << ' ' << PRINT(x2) << " -> " << PRINT(f1(x2)));
134 }
135
136 if (rs.roots == roots_type::SINGLE_t) {
137 ASSERT(fabs(f1(x1)) <= precision, PRINT(a) << ' ' << PRINT(b) << ' ' << PRINT(c) << ' ' << PRINT(x1) << " -> " << PRINT(f1(x1)));
138 }
139 }
140 }
141 }
142
143 return 0;
144}
#define PRINT(A)
#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:74
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2107
Utility class to parse command line options.
Definition JParser.hh:1664
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.
roots_type roots(double a, double b, double c, const double precision)
Solution to quadratic equiation .
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 distribution.
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 solution of quadratic equation.
enum JMATH::roots_type::ROOT_t roots
type of solution
Auxiliary data structure for floating point format specification.
Definition JManip.hh:488