1#ifndef __JMATHSUPPORTKIT__
2#define __JMATHSUPPORTKIT__
19namespace JPP {
using namespace JMATH; }
32 inline long long int factorial(
const long long int n)
52 inline long long int factorial(
const long long int n,
const long long int m)
54 if (n < 0 || m < 0 || n < m) {
74 inline double gauss(
const double x,
const double sigma)
76 const double u = x / sigma;
93 inline double gauss(
const double x,
const double x0,
const double sigma)
95 return gauss(x - x0, sigma);
106 inline double Gauss(
const double x,
const double sigma)
108 return gauss(x, sigma) / sqrt(2.0*PI) / sigma;
120 inline double Gauss(
const double x,
const double x0,
const double sigma)
122 return Gauss(x - x0, sigma);
137 inline double Gamma(
const double a,
const double x)
141 const int max = 1000000;
146 const double gln = lgamma(a);
159 double sum = 1.0 / a;
162 for (
int i = 0; i != max; ++i) {
168 if (fabs(del) < fabs(sum)*numeric_limits<double>::epsilon()) {
169 return sum*exp(-x + a*log(x) - gln);
177 const double FPMIN = numeric_limits<double>::min() / numeric_limits<double>::epsilon();
179 double b = x + 1.0 - a;
180 double c = 1.0 / FPMIN;
184 for (
int i = 1; i != max; ++i) {
186 const double an = -i * (i-a);
191 if (fabs(d) < FPMIN) {
197 if (fabs(c) < FPMIN) {
203 const double del = d*c;
207 if (fabs(del - 1.0) < numeric_limits<double>::epsilon()) {
208 return 1.0 - exp(-x + a*log(x) - gln) * h;
224 inline double legendre(
const size_t n,
const double x)
240 for (
size_t i = 2; i <= n; ++i) {
243 p2 = ((2*i-1) * x*
p1 - (i-1) * p0) / i;
259 inline double binomial(
const size_t n,
const size_t k)
261 if (n == 0 || n < k) {
265 if (k == 0 || n == k) {
269 const int k1 = std::min(k, n - k);
270 const int k2 = n - k1;
272 double value = k2 + 1;
274 for (
int i = k1; i != 1; --i) {
275 value *= (double) (k2 + i) / (double) i;
289 inline double poisson(
const size_t n,
const double mu)
296 return exp(n*log(mu) - lgamma(n+1) - mu);
299 }
else if (mu == 0.0) {
301 return (n == 0 ? 1.0 : 0.0);
315 inline double Poisson(
const size_t n,
const double mu)
317 return 1.0 -
Gamma(n + 1, mu);
327 inline double getP(
const double stdev)
331 erfc(stdev / sqrt(2.0)));
342 inline size_t getNs(
const double background,
345 double y = exp(-background);
349 for ( ; Y < 1.0 - P; ++k) {
350 y *= background / (double) k;
368 inline double getFs(
const double background,
370 const double precision)
372 double u = 1.0 + floor(background);
374 for ( ;
Gamma(u, background) > P; u += precision) {}
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Exception for accessing a value in a collection that is outside of its range.
Auxiliary classes and methods for mathematical operations.
double Gamma(const double a, const double x)
Incomplete gamma function.
double Gauss(const double x, const double sigma)
Normalised Gauss function.
long long int factorial(const long long int n)
Determine factorial.
double poisson(const size_t n, const double mu)
Poisson probability density distribition.
size_t getNs(const double background, const double P)
Get minimal number of events to exceed Poisson probability given number of background events.
double getP(const double stdev)
Get single-sided Gaussian probability for given number of standard deviations.
double gauss(const double x, const double sigma)
Gauss function (normalised to 1 at x = 0).
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 legendre(const size_t n, const double x)
Legendre polynome.
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).