BCMath Namespace Reference

Some useful mathematic functions. More...

Functions

double ApproxBinomial (unsigned n, unsigned k, double p)
 Calculates Binomial probability using approximations for factorial calculations if calculation for number greater than 20 required using the BCMath::ApproxLogFact function. More...
 
double ApproxLogFact (double x)
 Calculates natural logarithm of the n-factorial (n!) using Srinivasa Ramanujan approximation log(n!) = n*log(n) - n + log(n*(1. More...
 
unsigned CacheFactorials (unsigned n)
 Cache factorials for first. More...
 
double LogBinomFactor (unsigned n, unsigned k)
 Calculates natural logarithm of the Binomial factor "n over k" using approximations for factorial calculations if calculation for number greater than 20 required using the BCMath::ApproxLogFact function. More...
 
double LogBinomFactorExact (unsigned n, unsigned k)
 Calculates natural logarithm of the Binomial factor "n over k". More...
 
double LogFact (unsigned n)
 Calculates natural logarithm of the n-factorial (n!)
 
int Nint (double x)
 Returns the nearest integer of a double number. More...
 
Functions for log likelihoods
double LogGaus (double x, double mean=0, double sigma=1, bool norm=false)
 Calculate the natural logarithm of a normal distribution function. More...
 
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 above the mode. More...
 
double LogPoisson (double x, double lambda)
 Calculate the natural logarithm of a poisson distribution. More...
 
double LogApproxBinomial (unsigned n, unsigned k, double p)
 Calculates natural logarithm of the Binomial probability using approximations for factorial calculations if calculation for number greater than 20 required using the BCMath::ApproxLogFact function. More...
 
double LogBreitWignerNonRel (double x, double mean, double Gamma, bool norm=false)
 Calculates the logarithm of the nonrelativistic Breit-Wigner distribution. More...
 
double LogBreitWignerRel (double x, double mean, double Gamma)
 Calculates the logarithm of the relativistic Breit-Wigner distribution. More...
 
double LogChi2 (double x, int n)
 Calculates the logarithm of chi square function: chi2(double x; size_t n)
 
double LogVoigtian (double x, double sigma, double gamma)
 Calculates the logarithm of normalized voigtian function: voigtian(double x, double sigma, double gamma) More...
 
double LogGammaPDF (double x, double alpha, double beta)
 Returns the log of the Gamma PDF.
 
double LogLogNormal (double x, double mean=0, double sigma=1)
 Return the log of the log normal distribution.
 
p value methods
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 reduced by number of fit parameters. More...
 
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. More...
 

Detailed Description

Some useful mathematic functions.

Author
Frederik Beaujean
Daniel Greenwald
Daniel Kollar
Kevin Kröninger
Jing Liu
Version
1.0
Date
08.2008

A namespace which encapsulates some mathematical functions necessary for BAT.

Function Documentation

double BCMath::ApproxBinomial ( unsigned  n,
unsigned  k,
double  p 
)

Calculates Binomial probability using approximations for factorial calculations if calculation for number greater than 20 required using the BCMath::ApproxLogFact function.

Parameters
nnumber of trials.
knumber of successes.
pprobability of success in a trial.

Definition at line 97 of file BCMath.cxx.

double BCMath::ApproxLogFact ( double  x)

Calculates natural logarithm of the n-factorial (n!) using Srinivasa Ramanujan approximation log(n!) = n*log(n) - n + log(n*(1.

+4.*n*(1.+2.*n)))/6. + log(PI)/2. if n > 20. If n <= 20 it uses BCMath::LogFact to calculate it exactly.

Definition at line 130 of file BCMath.cxx.

unsigned BCMath::CacheFactorials ( unsigned  n)

Cache factorials for first.

  • n integers.

Definition at line 156 of file BCMath.cxx.

double BCMath::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 reduced by number of fit parameters.

Parameters
pvalueThe p value to correct.
nparThe number of fit parameters.
nobservationsThe number of data points.
Returns
corrected p value

Definition at line 285 of file BCMath.cxx.

double BCMath::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.

The method is explained in the appendix of http://arxiv.org/abs/1011.1674

Parameters
observedThe counts of observed events
expectedThe expected number of events (Poisson means)
nIterationsControls number of pseudo data sets
seedSet to nonzero value for reproducible results.
Returns
The p value

Definition at line 310 of file BCMath.cxx.

double BCMath::LogApproxBinomial ( unsigned  n,
unsigned  k,
double  p 
)

Calculates natural logarithm of the Binomial probability using approximations for factorial calculations if calculation for number greater than 20 required using the BCMath::ApproxLogFact function.

Parameters
nnumber of trials.
knumber of successes.
pprobability of success in a trial.

Definition at line 79 of file BCMath.cxx.

double BCMath::LogBinomFactor ( unsigned  n,
unsigned  k 
)

Calculates natural logarithm of the Binomial factor "n over k" using approximations for factorial calculations if calculation for number greater than 20 required using the BCMath::ApproxLogFact function.

Even for large numbers the calculation is performed precisely, if n-k < 5

Parameters
nupper value in binomial coefficient
klower value in binomial coefficient

Definition at line 111 of file BCMath.cxx.

double BCMath::LogBinomFactorExact ( unsigned  n,
unsigned  k 
)

Calculates natural logarithm of the Binomial factor "n over k".

Definition at line 191 of file BCMath.cxx.

double BCMath::LogBreitWignerNonRel ( double  x,
double  mean,
double  Gamma,
bool  norm = false 
)

Calculates the logarithm of the nonrelativistic Breit-Wigner distribution.

Definition at line 214 of file BCMath.cxx.

double BCMath::LogBreitWignerRel ( double  x,
double  mean,
double  Gamma 
)

Calculates the logarithm of the relativistic Breit-Wigner distribution.

Definition at line 226 of file BCMath.cxx.

double BCMath::LogGaus ( double  x,
double  mean = 0,
double  sigma = 1,
bool  norm = false 
)

Calculate the natural logarithm of a normal distribution function.

Parameters
xpoint to be evaluated.
meanMean.
sigmaStandard deviation.
normflag for including normalization constant 1/sqrt(2*pi)/sigma

Definition at line 24 of file BCMath.cxx.

double BCMath::LogPoisson ( double  x,
double  lambda 
)

Calculate the natural logarithm of a poisson distribution.

Parameters
xnumber of occurances.
lambdaexpected number of occurances.

Definition at line 53 of file BCMath.cxx.

double BCMath::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 above the mode.

Parameters
xpoint to be evaluated.
modeMode of the function.
sigma_belowStandard deviation below mode.
sigma_aboveStandard deviation above mode.
normflag for including normalization constant sqrt(2/pi)/(sigma_below+sigma_above)

Definition at line 44 of file BCMath.cxx.

double BCMath::LogVoigtian ( double  x,
double  sigma,
double  gamma 
)

Calculates the logarithm of normalized voigtian function: voigtian(double x, double sigma, double gamma)

voigtian is a convolution of the following two functions: gaussian(x) = 1/(sqrt(2*pi)*sigma) * exp(x*x/(2*sigma*sigma) and lorentz(x) = (1/pi)*(gamma/2) / (x*x + (gamma/2)*(gamma/2))

it is singly peaked at x=0. The width of the peak is decided by sigma and gamma, so they should be positive.

Definition at line 251 of file BCMath.cxx.

int BCMath::Nint ( double  x)

Returns the nearest integer of a double number.

Definition at line 185 of file BCMath.cxx.