BAT  0.9.4
The Bayesian analysis toolkit
 All Classes Namespaces Functions Variables Enumerations
BCHistogramFitter Class Reference

A class for fitting histograms with functions. More...

#include <BCHistogramFitter.h>

Inheritance diagram for BCHistogramFitter:
Collaboration diagram for BCHistogramFitter:

Public Member Functions

Constructors and destructors
 BCHistogramFitter ()
 
 BCHistogramFitter (const char *name)
 
 BCHistogramFitter (TH1D *hist, TF1 *func)
 
 BCHistogramFitter (const char *name, TH1D *hist, TF1 *func)
 
 ~BCHistogramFitter ()
 
Member functions (get)
TH1D * GetHistogram ()
 
TH1D * GetHistogramExpected ()
 
TF1 * GetFitFunction ()
 
TGraph * GetErrorBand ()
 
TGraph * GetGraphFitFunction ()
 
Member functions (set)
int SetHistogram (TH1D *hist)
 
int SetHistogramExpected (const std::vector< double > &parameters)
 
int SetFitFunction (TF1 *func)
 
void SetFlagIntegration (bool flag)
 
Member functions (miscellaneous methods)
virtual double LogLikelihood (const std::vector< double > &parameters)
 
double FitFunction (const std::vector< double > &x, const std::vector< double > &parameters)
 
int Fit ()
 
int Fit (TH1D *hist, TF1 *func)
 
void DrawFit (const char *options="HIST", bool flaglegend=false)
 
int CalculatePValueFast (const std::vector< double > &par, unsigned nIterations=100000)
 
int CalculatePValueLikelihood (const std::vector< double > &par)
 
int CalculatePValueLeastSquares (const std::vector< double > &par, bool weightExpect=true)
 
int CalculatePValueKolmogorov (const std::vector< double > &par)
 
double CDF (const std::vector< double > &parameters, int index, bool lower=false)
 
- Public Member Functions inherited from BCFitter
 BCFitter ()
 
 BCFitter (const char *name)
 
 ~BCFitter ()
 
TGraph * GetErrorBand ()
 
TH2D * GetErrorBandXY () const
 
TH2D * GetErrorBandXY_yellow (double level=.68, int nsmooth=0) const
 
std::vector< double > GetErrorBand (double level) const
 
TGraph * GetErrorBandGraph (double level1, double level2) const
 
TGraph * GetFitFunctionGraph (const std::vector< double > &parameters)
 
TGraph * GetFitFunctionGraph ()
 
TGraph * GetFitFunctionGraph (const std::vector< double > &parameters, double xmin, double xmax, int n=1000)
 
void FixDataAxis (unsigned int index, bool fixed)
 
bool GetFixedDataAxis (unsigned int index) const
 
void SetFillErrorBand (bool flag=true)
 
void SetErrorBandHisto (TH2D *h)
 
void UnsetFillErrorBand ()
 
void SetFitFunctionIndexX (int index)
 
void SetFitFunctionIndexY (int index)
 
void SetFitFunctionIndices (int indexx, int indexy)
 
void SetErrorBandContinuous (bool flag)
 
int ReadErrorBandFromFile (const char *file)
 
void MCMCIterationInterface ()
 
void MarginalizePreprocess ()
 
void MarginalizePostprocess ()
 
void FillErrorBand ()
 
- Public Member Functions inherited from BCModel
 BCModel (const char *name="model")
 
 BCModel (const BCModel &bcmodel)
 
virtual ~BCModel ()
 
BCModeloperator= (const BCModel &bcmodel)
 
const std::string & GetName () const
 
double GetModelAPrioriProbability () const
 
double GetModelAPosterioriProbability () const
 
BCDataSetGetDataSet () const
 
BCDataPointGetDataPointLowerBoundaries () const
 
BCDataPointGetDataPointUpperBoundaries () const
 
double GetDataPointLowerBoundary (unsigned int index) const
 
double GetDataPointUpperBoundary (unsigned int index) const
 
bool GetFlagBoundaries () const
 
unsigned GetNDataPoints () const
 
BCDataPointGetDataPoint (unsigned int index) const
 
void SetName (const char *name)
 
void SetModelAPrioriProbability (double probability)
 
void SetModelAPosterioriProbability (double probability)
 
virtual int AddParameter (BCParameter *parameter)
 
void SetDataSet (BCDataSet *dataset)
 
void SetSingleDataPoint (BCDataPoint *datapoint)
 
void SetSingleDataPoint (BCDataSet *dataset, unsigned int index)
 
void SetDataBoundaries (unsigned int index, double lowerboundary, double upperboundary, bool fixed=false)
 
void SetDataPointLowerBoundaries (BCDataPoint *datasetlowerboundaries)
 
void SetDataPointUpperBoundaries (BCDataPoint *datasetupperboundaries)
 
void SetDataPointLowerBoundary (int index, double lowerboundary)
 
void SetDataPointUpperBoundary (int index, double upperboundary)
 
int SetPrior (int index, TF1 *f)
 
int SetPrior (const char *name, TF1 *f)
 
int SetPriorDelta (int index, double value)
 
int SetPriorDelta (const char *name, double value)
 
int SetPriorGauss (int index, double mean, double sigma)
 
int SetPriorGauss (const char *name, double mean, double sigma)
 
int SetPriorGauss (int index, double mean, double sigmadown, double sigmaup)
 
int SetPriorGauss (const char *name, double mean, double sigmadown, double sigmaup)
 
int SetPrior (int index, TH1 *h, bool flag=false)
 
int SetPrior (const char *name, TH1 *h, bool flag=false)
 
int SetPriorConstant (int index)
 
int SetPriorConstant (const char *name)
 
int SetPriorConstantAll ()
 
void Copy (const BCModel &bcmodel)
 
double APrioriProbability (const std::vector< double > &parameters)
 
virtual double LogAPrioriProbability (const std::vector< double > &parameters)
 
virtual double Likelihood (const std::vector< double > &params)
 
double ProbabilityNN (const std::vector< double > &params)
 
double LogProbabilityNN (const std::vector< double > &parameters)
 
double Probability (const std::vector< double > &parameter)
 
double LogProbability (const std::vector< double > &parameter)
 
virtual double SamplingFunction (const std::vector< double > &parameters)
 
double Eval (const std::vector< double > &parameters)
 
virtual double LogEval (const std::vector< double > &parameters)
 
virtual void CorrelateDataPointValues (std::vector< double > &x)
 
double GetPvalueFromChi2 (const std::vector< double > &par, int sigma_index)
 
double GetPvalueFromKolmogorov (const std::vector< double > &par, int index)
 
double GetPvalueFromChi2NDoF (std::vector< double > par, int sigma_index)
 
BCH1DCalculatePValue (std::vector< double > par, bool flag_histogram=false)
 
double GetPValue ()
 
double GetPValueNDoF ()
 
double GetChi2NDoF ()
 
std::vector< double > GetChi2Runs (int dataIndex, int sigmaIndex)
 
void SetGoFNIterationsMax (int n)
 
void SetGoFNIterationsRun (int n)
 
void SetGoFNChains (int n)
 
double HessianMatrixElement (const BCParameter *parameter1, const BCParameter *parameter2, std::vector< double > point)
 
void PrintSummary ()
 
void PrintResults (const char *file)
 
void PrintShortFitSummary (int chi2flag=0)
 
void PrintHessianMatrix (std::vector< double > parameters)
 

Additional Inherited Members

- Protected Attributes inherited from BCFitter
TH2D * fErrorBandXY
 
- Protected Attributes inherited from BCModel
std::string fName
 
double fModelAPriori
 
double fModelAPosteriori
 
BCDataSetfDataSet
 
BCDataPointfDataPointLowerBoundaries
 
BCDataPointfDataPointUpperBoundaries
 
std::vector< bool > fDataFixedValues
 
double fPValue
 
double fChi2NDoF
 
double fPValueNDoF
 
bool flag_discrete
 
int fGoFNIterationsMax
 
int fGoFNIterationsRun
 
int fGoFNChains
 
std::vector< TNamed * > fPriorContainer
 
bool fPriorConstantAll
 
std::vector< bool > fPriorContainerConstant
 
std::vector< bool > fPriorContainerInterpolate
 

Detailed Description

A class for fitting histograms with functions.

Author
Daniel Kollar
Kevin Kröninger
Version
1.0
Date
11.2008 This class allows fitting of a TH1D histogram using a TF1 function.

Definition at line 35 of file BCHistogramFitter.h.

Constructor & Destructor Documentation

BCHistogramFitter::BCHistogramFitter ( )

The default constructor.

Definition at line 30 of file BCHistogramFitter.cxx.

BCHistogramFitter::BCHistogramFitter ( const char *  name)

Constructor

Parameters
namename of the model

Definition at line 48 of file BCHistogramFitter.cxx.

BCHistogramFitter::BCHistogramFitter ( TH1D *  hist,
TF1 *  func 
)

Constructor.

Parameters
histhistogram to fit
funcfit function

Definition at line 66 of file BCHistogramFitter.cxx.

BCHistogramFitter::BCHistogramFitter ( const char *  name,
TH1D *  hist,
TF1 *  func 
)

Constructor

Parameters
namename of the model
histhistogram to fit
funcfit function

Definition at line 86 of file BCHistogramFitter.cxx.

BCHistogramFitter::~BCHistogramFitter ( )

The default destructor.

Definition at line 259 of file BCHistogramFitter.cxx.

Member Function Documentation

int BCHistogramFitter::CalculatePValueFast ( const std::vector< double > &  par,
unsigned  nIterations = 100000 
)

Calculate the p-value using fast-MCMC and the likelihood as test statistic. The method is explained in the appendix of http://arxiv.org/abs/1011.1674

Note
Obtain the results with
See Also
BCModel::GetPValue and the value corrected for degrees of freedom with
BCModel::GetPValueNDoF
Parameters
parThe parameter values for which expectations are computed
nIterationsnumber of pseudo experiments generated by the Markov chain
Returns
An error code

Definition at line 442 of file BCHistogramFitter.cxx.

int BCHistogramFitter::CalculatePValueKolmogorov ( const std::vector< double > &  par)

Calculate the p-value using Kolmogorov-Smirnov test. Note that the reference distribution is known only asymptotically. Some explanation is given in http://root.cern.ch/root/htmldoc/TMath.html

Parameters
parThe set of parameter values used in the model, usually the best fit parameters
pvalueThe pvalue
Returns
An error code

Definition at line 554 of file BCHistogramFitter.cxx.

int BCHistogramFitter::CalculatePValueLeastSquares ( const std::vector< double > &  par,
bool  weightExpect = true 
)

Calculate the p-value using approximate chi^2 distribution of squared difference for conventional weights. Approximation is valid for bin contents >5 and not as as good for little data as CalculatePValueLikelihood, see eq. (32.13), PDG: Statistics, Monte Carlo, Group Theory. Physics Letters B 667, 316-339(2008).

Parameters
parThe set of parameter values used in the model, usually the best fit parameters
pvalueThe pvalue
weightuse the variance from the expected #counts (true) or the measured counts (false)
Returns
An error code

Definition at line 517 of file BCHistogramFitter.cxx.

int BCHistogramFitter::CalculatePValueLikelihood ( const std::vector< double > &  par)

Calculate the p-value using approximate chi^2 distribution of scaled likelihood. Approximation is valid for bin contents >5, see eq. (32.12), PDG: Statistics, Monte Carlo, Group Theory. Physics Letters B 667, 316-339(2008).

Parameters
parThe set of parameter values used in the model, usually the best fit parameters
pvalueThe pvalue
Returns
An error code

Definition at line 481 of file BCHistogramFitter.cxx.

double BCHistogramFitter::CDF ( const std::vector< double > &  ,
int  ,
bool  = false 
)
virtual

1dim cumulative distribution function of the probability to get the data f(x_i|param) for a single measurement, assumed to be of identical functional form for all measurements

Parameters
parametersThe parameter values at which point to compute the cdf
indexThe data point index starting at 0,1...N-1
loweronly needed for discrete distributions! Return the CDF for the count one less than actually observed, e.g. in Poisson process, if 3 actually observed, then CDF(2) is returned

Reimplemented from BCModel.

Definition at line 576 of file BCHistogramFitter.cxx.

void BCHistogramFitter::DrawFit ( const char *  options = "HIST",
bool  flaglegend = false 
)
virtual

Draw the fit in the current pad.

Implements BCFitter.

Definition at line 389 of file BCHistogramFitter.cxx.

int BCHistogramFitter::Fit ( )
virtual

Performs the fit.

Returns
An error code.

Implements BCFitter.

Definition at line 351 of file BCHistogramFitter.cxx.

int BCHistogramFitter::Fit ( TH1D *  hist,
TF1 *  func 
)

Performs the fit.

Parameters
histThe histogram (TH1D).
funcThe fit function.
Returns
An error code.

Definition at line 328 of file BCHistogramFitter.cxx.

double BCHistogramFitter::FitFunction ( const std::vector< double > &  x,
const std::vector< double > &  parameters 
)
virtual

Plots the histogram

Parameters
optionsOptions for plotting.
filenameName of the file which the histogram is printed into. The following options are available:
F : plots the fit function on top of the data E0 : plots the fit function and the 68% prob. uncertainty band of the fit function on top of the data E1 : plots the expectation from the fit function and the uncertainty bin-by-bin as error bars. Returns the y-value of the 1-dimensional fit function at an x and for a set of parameters.
xA vector with the x-value.
parametersA set of parameters.

Reimplemented from BCFitter.

Definition at line 318 of file BCHistogramFitter.cxx.

TGraph* BCHistogramFitter::GetErrorBand ( )
inline
Returns
pointer to the error band

Definition at line 91 of file BCHistogramFitter.h.

TF1* BCHistogramFitter::GetFitFunction ( )
inline
Returns
The fit function

Definition at line 86 of file BCHistogramFitter.h.

TGraph* BCHistogramFitter::GetGraphFitFunction ( )
inline
Returns
pointer to a graph for the fit function

Definition at line 96 of file BCHistogramFitter.h.

TH1D* BCHistogramFitter::GetHistogram ( )
inline
Returns
The data histogram

Definition at line 75 of file BCHistogramFitter.h.

TH1D* BCHistogramFitter::GetHistogramExpected ( )
inline
Returns
The histogram of expected counts

Definition at line 80 of file BCHistogramFitter.h.

double BCHistogramFitter::LogLikelihood ( const std::vector< double > &  parameters)
virtual

The log of the prior probability. Overloaded from BCModel.

Parameters
parametersA vector of doubles containing the parameter values. The log of the conditional probability. Overloaded from BCModel.
parametersA vector of doubles containing the parameter values.

Implements BCModel.

Definition at line 267 of file BCHistogramFitter.cxx.

int BCHistogramFitter::SetFitFunction ( TF1 *  func)
Parameters
funcThe fit function
Returns
An error code (1:pass, 0:fail).

Definition at line 220 of file BCHistogramFitter.cxx.

void BCHistogramFitter::SetFlagIntegration ( bool  flag)
inline

Sets the flag for integration.
true: use ROOT's TH1D::Integrate()
false: use linear interpolation

Definition at line 126 of file BCHistogramFitter.h.

int BCHistogramFitter::SetHistogram ( TH1D *  hist)
Parameters
histThe histogram containing the data
Returns
An error code (1:pass, 0:fail).

Definition at line 106 of file BCHistogramFitter.cxx.

int BCHistogramFitter::SetHistogramExpected ( const std::vector< double > &  parameters)
Parameters
histThe histogram with the expected counts (typically non-integer values!)
Returns
An error code (1:pass, 0:fail).

Definition at line 162 of file BCHistogramFitter.cxx.


The documentation for this class was generated from the following files: