24{
27
28 double precision;
30
31 try {
32
34
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
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
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
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
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) <<
' ' <<
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.
#define ASSERT(A,...)
Assert macro.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Utility class to parse command line options.
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).
Auxiliary data structure for floating point format specification.
Auxiliary data structure for floating point format specification.