BCMath.h
1 #ifndef __BCMATH__H
2 #define __BCMATH__H
3 
18 /*
19  * Copyright (C) 2007-2018, the BAT core developer team
20  * All rights reserved.
21  *
22  * For the licensing terms see doc/COPYING.
23  * For documentation see http://mpp.mpg.de/bat
24  */
25 
26 // ---------------------------------------------------------
27 #include <stdexcept>
28 #include <vector>
29 
30 class TRandom;
31 
32 namespace BCMath
33 {
34 
44 double LogGaus(double x, double mean = 0, double sigma = 1, bool norm = false);
45 
53 double LogSplitGaus(double x, double mode, double sigma_below, double sigma_above, bool norm = false);
54 
59 double LogPoisson(double x, double lambda);
60 
69 double LogApproxBinomial(unsigned n, unsigned k, double p);
70 
73 double LogBreitWignerNonRel(double x, double mean, double Gamma, bool norm = false);
74 
77 double LogBreitWignerRel(double x, double mean, double Gamma);
78 
83 double LogChi2(double x, int n);
84 
98 double LogVoigtian(double x, double sigma, double gamma);
99 
103 double LogGammaPDF(double x, double alpha, double beta);
104 
108 double LogLogNormal(double x, double mean = 0, double sigma = 1);
109 
119 double ApproxBinomial(unsigned n, unsigned k, double p);
120 
129 double LogBinomFactor(unsigned n, unsigned k);
130 
137 double ApproxLogFact(double x);
138 
141 double LogBinomFactorExact(unsigned n, unsigned k);
142 
145 double LogFact(unsigned n);
146 
148 unsigned CacheFactorials(unsigned n);
149 
152 int Nint(double x);
153 
165 double CorrectPValue(const double& pvalue, const unsigned& npar, const unsigned& nobservations);
166 
177 double FastPValue(const std::vector<unsigned>& observed, const std::vector<double>& expected,
178  unsigned nIterations = 1e5, unsigned seed = 0);
179 
184 namespace Random
185 {
194 double Chi2(TRandom* rng, double dof);
195 
209 double Gamma(TRandom* rng, double a, double b);
210 }
212 }
213 
214 // ---------------------------------------------------------
215 
216 #endif
double LogApproxBinomial(unsigned n, unsigned k, double p)
Calculates natural logarithm of the Binomial probability using approximations for factorial calculati...
Definition: BCMath.cxx:79
double LogFact(unsigned n)
Calculates natural logarithm of the n-factorial (n!)
Definition: BCMath.cxx:141
double LogBinomFactorExact(unsigned n, unsigned k)
Calculates natural logarithm of the Binomial factor "n over k".
Definition: BCMath.cxx:191
double FastPValue(const std::vector< unsigned > &observed, const std::vector< double > &expected, unsigned nIterations=1e5, unsigned seed=0)
Calculate the p value using fast MCMC for a histogram and the likelihood as test statistic.
Definition: BCMath.cxx:310
double LogBreitWignerNonRel(double x, double mean, double Gamma, bool norm=false)
Calculates the logarithm of the nonrelativistic Breit-Wigner distribution.
Definition: BCMath.cxx:214
double LogBreitWignerRel(double x, double mean, double Gamma)
Calculates the logarithm of the relativistic Breit-Wigner distribution.
Definition: BCMath.cxx:226
Some useful mathematic functions.
double LogBinomFactor(unsigned n, unsigned k)
Calculates natural logarithm of the Binomial factor "n over k" using approximations for factorial cal...
Definition: BCMath.cxx:111
double LogLogNormal(double x, double mean=0, double sigma=1)
Return the log of the log normal distribution.
Definition: BCMath.cxx:268
double LogChi2(double x, int n)
Calculates the logarithm of chi square function: chi2(double x; size_t n)
Definition: BCMath.cxx:233
double LogGammaPDF(double x, double alpha, double beta)
Returns the log of the Gamma PDF.
Definition: BCMath.cxx:262
double CorrectPValue(const double &pvalue, const unsigned &npar, const unsigned &nobservations)
Correct a p value by transforming to a chi^2 with dof=nobservations, then back to a pvalue with dof r...
Definition: BCMath.cxx:285
double ApproxLogFact(double x)
Calculates natural logarithm of the n-factorial (n!) using Srinivasa Ramanujan approximation log(n!) ...
Definition: BCMath.cxx:130
double LogVoigtian(double x, double sigma, double gamma)
Calculates the logarithm of normalized voigtian function: voigtian(double x, double sigma...
Definition: BCMath.cxx:251
int Nint(double x)
Returns the nearest integer of a double number.
Definition: BCMath.cxx:185
double LogSplitGaus(double x, double mode, double sigma_below, double sigma_above, bool norm=false)
Calculate the natural logarithm of a normal distribution function with different variances below and ...
Definition: BCMath.cxx:44
double LogGaus(double x, double mean=0, double sigma=1, bool norm=false)
Calculate the natural logarithm of a normal distribution function.
Definition: BCMath.cxx:24
double ApproxBinomial(unsigned n, unsigned k, double p)
Calculates Binomial probability using approximations for factorial calculations if calculation for nu...
Definition: BCMath.cxx:97
double LogPoisson(double x, double lambda)
Calculate the natural logarithm of a poisson distribution.
Definition: BCMath.cxx:53
unsigned CacheFactorials(unsigned n)
Cache factorials for first.
Definition: BCMath.cxx:156