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

A class for fitting several templates to a data set. More...

#include <BCMTF.h>

Inheritance diagram for BCMTF:
Collaboration diagram for BCMTF:

Public Member Functions

Constructors and destructors
 BCMTF ()
 
 BCMTF (const char *name)
 
 ~BCMTF ()
 
Member functions (get)
int GetNChannels ()
 
int GetNProcesses ()
 
int GetNSystematics ()
 
int GetChannelIndex (const char *name)
 
int GetProcessIndex (const char *name)
 
int GetSystematicIndex (const char *name)
 
int GetParIndexProcess (int index)
 
int GetParIndexSystematic (int index)
 
BCMTFChannelGetChannel (int index)
 
BCMTFProcessGetProcess (int index)
 
BCMTFSystematicGetSystematic (int index)
 
Member functions (set)
int SetData (const char *channelname, TH1D hist, double minimum=-1, double maximum=-1)
 
int SetTemplate (const char *channelname, const char *processname, TH1D hist, double efficiency=1., double norm=1.)
 
int SetTemplate (const char *channelname, const char *processname, std::vector< TF1 * > *funccont, int nbins, double efficiency=1.)
 
void SetExpectationFunction (int parindex, TF1 *func)
 
int SetSystematicVariation (const char *channelname, const char *processname, const char *systematicname, double variation_up, double variation_down)
 
int SetSystematicVariation (const char *channelname, const char *processname, const char *systematicname, TH1D hist_up, TH1D hist_down)
 
int SetSystematicVariation (const char *channelname, const char *processname, const char *systematicname, TH1D hist, TH1D hist_up, TH1D hist_down)
 
void SetFlagEfficiencyConstraint (bool flag)
 
Member functions (miscellaneous methods)
int AddChannel (const char *name)
 
int AddProcess (const char *name, double nmin=0., double nmax=1., int color=-1, int fillstyle=-1, int linestyle=-1)
 
int AddSystematic (const char *name, double min=-5., double max=5.)
 
double Expectation (int channelindex, int binindex, const std::vector< double > &parameters)
 
double ExpectationFunction (int parindex, int channelindex, int processindex, const std::vector< double > &parameters)
 
double Efficiency (int channelindex, int processindex, int binindex, const std::vector< double > &parameters)
 
double Probability (int channelindex, int processindex, int binindex, const std::vector< double > &parameters)
 
double CalculateChi2 (int channelindex, const std::vector< double > &parameters)
 
double CalculateChi2 (const std::vector< double > &parameters)
 
double CalculateCash (int channelindex, const std::vector< double > &parameters)
 
double CalculateCash (const std::vector< double > &parameters)
 
double CalculatePValue (int channelindex, const std::vector< double > &parameters)
 
double CalculatePValue (const std::vector< double > &parameters)
 
Member functions (output methods)
int PrintSummary (const char *filename="summary.txt")
 
int PrintStack (int channelindex, const std::vector< double > &parameters, const char *filename="stack.pdf", const char *options="e1b0stack")
 
int PrintStack (const char *channelname, const std::vector< double > &parameters, const char *filename="stack.pdf", const char *options="e1b0stack")
 
Member functions (overloaded from BCModel)
double LogLikelihood (const std::vector< double > &parameters)
 
void MCMCUserIterationInterface ()
 
- 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)
 
virtual double CDF (const std::vector< double > &, int, bool)
 

Additional Inherited Members

- 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 several templates to a data set.

Author
Daniel Kollar
Kevin Kröninger
Version
1.1
Date
06.2012 This class can be used for fitting several template histograms to a data histogram. The templates are assumed to have no statistical uncertainty whereas the data are assumed to have Poissonian fluctuations in each bin. Several methods to judge the validity of the model are available.

Definition at line 38 of file BCMTF.h.

Constructor & Destructor Documentation

BCMTF::BCMTF ( )

The default constructor.

Definition at line 35 of file BCMTF.cxx.

BCMTF::BCMTF ( const char *  name)

A constructor.

Parameters
nameThe name of the model

Definition at line 44 of file BCMTF.cxx.

BCMTF::~BCMTF ( )

The default destructor.

Definition at line 53 of file BCMTF.cxx.

Member Function Documentation

int BCMTF::AddChannel ( const char *  name)

Add a channel

Parameters
nameThe channel name.
Returns
An error code.

Definition at line 282 of file BCMTF.cxx.

int BCMTF::AddProcess ( const char *  name,
double  nmin = 0.,
double  nmax = 1.,
int  color = -1,
int  fillstyle = -1,
int  linestyle = -1 
)

Add a process and the associated BAT parameter.

Parameters
nameThe process name
nminThe minimum number of expected events (lower limit on the BAT parameter values).
nmaxThe maximum number of expected events (upper limit on the BAT parameter values).
colorThe histogram color
fillstyleThe histogram fill style
linestyleThe histogram line style
Returns
An error code.

Definition at line 337 of file BCMTF.cxx.

int BCMTF::AddSystematic ( const char *  name,
double  min = -5.,
double  max = 5. 
)

Add a source of systematic uncertainty and the associated BAT (nuisance) parameter.

Parameters
nameThe systematic uncertainty name.
minThe lower limit on the BAT parameter values, typically -5 sigma if Gaussian constraint is used.
maxThe upper limit on the BAT parameter values, typically +5 sigma if Gaussian constraint is used.
Returns

Definition at line 395 of file BCMTF.cxx.

double BCMTF::CalculateCash ( int  channelindex,
const std::vector< double > &  parameters 
)

Calculate the Cash statistic for a single channel

Parameters
channelindexThe channel index.
parametersA reference to the parameters used to calculate the Cash statistic.
Returns
The Cash statistic.
See Also
CalculateCash(const std::vector<double> & parameters)

Definition at line 1098 of file BCMTF.cxx.

double BCMTF::CalculateCash ( const std::vector< double > &  parameters)

Calculate the Cash statistic for all channels

Parameters
parametersA reference to the parameters used to calculate the Cash statistic.
Returns
The Cash statistic.
See Also
CalculateCash(int channelindex, const std::vector<double> & parameters)

Definition at line 1142 of file BCMTF.cxx.

double BCMTF::CalculateChi2 ( int  channelindex,
const std::vector< double > &  parameters 
)

Calculate a chi2 for a single channel given a set of parameters.

Parameters
channelindexThe channel index.
parametersA reference to the parameters used to calculate the chi2.
Returns
A chi2 value.
See Also
CalculateChi2(const std::vector<double> & parameters)

Definition at line 1039 of file BCMTF.cxx.

double BCMTF::CalculateChi2 ( const std::vector< double > &  parameters)

Calculate a chi2 for all channels together given a set of parameters.

Parameters
parametersA reference to the parameters used to calculate the chi2.
Returns
A chi2 value.
See Also
CalculateChi2(int channelindex, const std::vector<double> & parameters)

Definition at line 1078 of file BCMTF.cxx.

double BCMTF::CalculatePValue ( int  channelindex,
const std::vector< double > &  parameters 
)

Calculates and returns the fast p-value for the total likelihood as test statistic.

See Also
BCMath::CorrectPValue for correcting the fitting bias
Parameters
channelindexThe channel index.
parametersA reference to the parameters for which the model expectations are computed.
Returns
the uncorrected p-value

Definition at line 1162 of file BCMTF.cxx.

double BCMTF::CalculatePValue ( const std::vector< double > &  parameters)

Calculates and returns the fast p-value for the total likelihood as test statistic.

Note
Obtain the results with
See Also
BCModel::GetPValue and the value corrected for degrees of freedom with
BCModel::GetPValueNDoF
Parameters
parametersA reference to the parameters for which the model expectations are computed.

Definition at line 1197 of file BCMTF.cxx.

double BCMTF::Efficiency ( int  channelindex,
int  processindex,
int  binindex,
const std::vector< double > &  parameters 
)

Return the efficiency for a process in a channel and for a particular bin.

Parameters
channelindexThe channel index.
processindexThe process index.
binindexThe bin index.
parametersA reference to the parameters used to calculate the efficiency.
Returns
The efficiency.

Definition at line 689 of file BCMTF.cxx.

double BCMTF::Expectation ( int  channelindex,
int  binindex,
const std::vector< double > &  parameters 
)

Return the expected number of events for a channel and bin.

Parameters
channelindexThe channel index.
binindexThe bin index.
parametersA reference to the parameters used to calculate the expectation.
Returns
The expectation value

Definition at line 642 of file BCMTF.cxx.

double BCMTF::ExpectationFunction ( int  parindex,
int  channelindex,
int  processindex,
const std::vector< double > &  parameters 
)

Return the function value of the expectation function for a parameter, channel and process.

Parameters
parindexThe parameter index.
channelindexThe channel index.
processindexThe process index.
Areference to the parameters used to calculate the expectation.
Returns
The expectation function value.

Definition at line 671 of file BCMTF.cxx.

BCMTFChannel* BCMTF::GetChannel ( int  index)
inline
Parameters
nameThe channel index.
Returns
The channel object.

Definition at line 108 of file BCMTF.h.

int BCMTF::GetChannelIndex ( const char *  name)
Parameters
nameThe name of the channel.
Returns
The channel index.

Definition at line 61 of file BCMTF.cxx.

int BCMTF::GetNChannels ( )
inline
Returns
The number of channels.

Definition at line 65 of file BCMTF.h.

int BCMTF::GetNProcesses ( )
inline
Returns
The number of processes.

Definition at line 70 of file BCMTF.h.

int BCMTF::GetNSystematics ( )
inline
Returns
The number of systematics.

Definition at line 75 of file BCMTF.h.

int BCMTF::GetParIndexProcess ( int  index)
inline
Parameters
indexThe parameter index (mtf counting) .
Returns
The parameter number corresponding to the parameter index (BAT counting).

Definition at line 96 of file BCMTF.h.

int BCMTF::GetParIndexSystematic ( int  index)
inline
Parameters
nameThe systematic uncertainty index (mtf counting).
Returns
The parameter number corresponding to the systematic uncertainty (BAT counting).

Definition at line 102 of file BCMTF.h.

BCMTFProcess* BCMTF::GetProcess ( int  index)
inline
Parameters
nameThe process index.
Returns
The process object.

Definition at line 114 of file BCMTF.h.

int BCMTF::GetProcessIndex ( const char *  name)
Parameters
nameThe name of the process.
Returns
The process index.

Definition at line 78 of file BCMTF.cxx.

BCMTFSystematic* BCMTF::GetSystematic ( int  index)
inline
Parameters
nameThe systematic ucnertainty index.
Returns
The systematic uncertainty object.

Definition at line 120 of file BCMTF.h.

int BCMTF::GetSystematicIndex ( const char *  name)
Parameters
nameThe name of the systematic.
Returns
The systematic uncertainty index.

Definition at line 95 of file BCMTF.cxx.

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

Calculates natural logarithm of the likelihood. Method needs to be overloaded by the user.

Parameters
paramsA set of parameter values
Returns
Natural logarithm of the likelihood

Implements BCModel.

Definition at line 1244 of file BCMTF.cxx.

void BCMTF::MCMCUserIterationInterface ( )

Method executed for every iteration of the MCMC. User's code should be provided via overloading in the derived class

Definition at line 1289 of file BCMTF.cxx.

int BCMTF::PrintStack ( int  channelindex,
const std::vector< double > &  parameters,
const char *  filename = "stack.pdf",
const char *  options = "e1b0stack" 
)

Print the stack of templates together with the data in a particular channel. Several plot options are available:
"logx" : plot the x-axis on a log scale
"logy" : plot the y-axis on a log scale
"bw" : plot in black and white
"sum" : draw a line corresponding to the sum of all templates
"stack" : draw the templates as a stack
"e0" : do not draw error bars
"e1" : draw error bars corresponding to sqrt(n)
"b0" : draw an error band on the expectation corresponding to the central 68% probability
"b1" : draw bands showing the probability to observe a certain number of events given the expectation. The green (yellow, red) bands correspond to the central 68% (95%, 99.8%) probability

Parameters
channelindexThe channel index.
parametersA reference to the parameters used to scale the templates.
optionsThe plotting options.
Returns
An error code.

Definition at line 766 of file BCMTF.cxx.

int BCMTF::PrintStack ( const char *  channelname,
const std::vector< double > &  parameters,
const char *  filename = "stack.pdf",
const char *  options = "e1b0stack" 
)

Print the stack of templates together with the data in a particular channel.

Parameters
channelnameThe name of the channel.
parametersA reference to the parameters used to scale the templates.
optionsThe plotting options.
Returns
An error code.
See Also
PrintStack(int channelindex, const std::vector<double> & parameters, const char * filename = "stack.pdf", const char * options = "e1b0stack")

Definition at line 758 of file BCMTF.cxx.

int BCMTF::PrintSummary ( const char *  filename = "summary.txt")

Print a summary of the fit into an ASCII file.

Parameters
filenameThe name of the file.
Returns
An error code

Definition at line 563 of file BCMTF.cxx.

double BCMTF::Probability ( int  channelindex,
int  processindex,
int  binindex,
const std::vector< double > &  parameters 
)

Return the probability for a process in a channel and for a particular bin. This corresponds to the (normalized) bin content of the template.

Parameters
channelindexThe channel index.
processindexThe process index.
binindexThe bin index.
parametersA reference to the parameters used to calculate the probability.
Returns
The probability.

Definition at line 737 of file BCMTF.cxx.

int BCMTF::SetData ( const char *  channelname,
TH1D  hist,
double  minimum = -1,
double  maximum = -1 
)

Set the data histogram in a particular channel.

Parameters
channelnameThe name of the channel.
histThe TH1D histogram.
minimumThe minimum number of expected events (used for calculation of uncertainty bands).
maximumThe maximum number of expected events (used for calculation of uncertainty bands).
Returns
An error code.

Definition at line 207 of file BCMTF.cxx.

void BCMTF::SetExpectationFunction ( int  parindex,
TF1 *  func 
)
inline

Set an expectation function.

Parameters
parindexThe index of the parameter
funcThe pointer to a TF1 function.
See Also
SetTemplate(const char * channelname, const char * processname, std::vector<TF1 *> * funccont, int nbins, double efficiency = 1.)

Definition at line 167 of file BCMTF.h.

void BCMTF::SetFlagEfficiencyConstraint ( bool  flag)
inline

Set a flag for the efficiency: if true then the total efficiency including all systematic uncertainties has to be between 0 and 1 at all times. Larger (smaller) values are set to 1 (0) during the calculation.

Parameters
flagThe flag

Definition at line 222 of file BCMTF.h.

int BCMTF::SetSystematicVariation ( const char *  channelname,
const char *  processname,
const char *  systematicname,
double  variation_up,
double  variation_down 
)

Set the impact of a source of systematic uncertainty for a particular source of systematic uncertainty and process in a given channel. The impact is the relative deviation between the varied and the nominal template, i.e., if the variation is set to 0.05 then the efficiency is multiplied by (1+0.05*eps), where eps is the corresponding nuisance parameter.

Parameters
channelnameThe name of the channel.
processnameThe name of the process.
systematicnameThe name of the source of systematic uncertainty.
variation_upThe relative shift between the up-variation and the nominal template: (up-nom)/nom.
variation_downThe relative shift between the down-variation and the nominal template: (nom-down)/nom.
Returns
An error code.

Definition at line 442 of file BCMTF.cxx.

int BCMTF::SetSystematicVariation ( const char *  channelname,
const char *  processname,
const char *  systematicname,
TH1D  hist_up,
TH1D  hist_down 
)

Set the impact of a source of systematic uncertainty for a particular source of systematic uncertainty and process in a given channel. The variation depends on x and is given as a histogram.

Parameters
channelnameThe name of the channel.
processnameThe name of the process.
systematicnameThe name of the source of systematic uncertainty.
hist_upThe TH1D histogram defining the relative shift between the up-variation and the nominal template: (up-nom)/nom.
hist_downThe TH1D histogram defining the relative shift between the down-variation and the nominal template: (nom-down)/nom.
Returns
An error code.
See Also
SetSystematicVariation(const char * channelname, const char * processname, const char * systematicname, double variation_up, double variation_down)

Definition at line 501 of file BCMTF.cxx.

int BCMTF::SetSystematicVariation ( const char *  channelname,
const char *  processname,
const char *  systematicname,
TH1D  hist,
TH1D  hist_up,
TH1D  hist_down 
)

Set the impact of a source of systematic uncertainty for a particular source of systematic uncertainty and process in a given channel. The variation depends on x. The histograms are the raw histograms after the shift and the variation wrt the nominal template will be calculated automatically.

Parameters
channelnameThe name of the channel.
processnameThe name of the process.
systematicnameThe name of the source of systematic uncertainty.
histThe histogram with the nominal template
hist_upThe TH1D histogram after up-scaling of the systematic uncertainty.
hist_downThe TH1D histogram after down-scaling of the systematic uncertainty.
Returns
An error code.
See Also
SetSystematicVariation(const char * channelname, const char * processname, const char * systematicname, double variation_up, double variation_down)

Definition at line 544 of file BCMTF.cxx.

int BCMTF::SetTemplate ( const char *  channelname,
const char *  processname,
TH1D  hist,
double  efficiency = 1.,
double  norm = 1. 
)

Set the template for a specific process in a particular channel.

Parameters
channelnameThe name of the channel.
processnameThe name of the process.
histThe TH1D histogram.
efficiencyThe efficiency of this process in this channel.
Returns
An error code.

Definition at line 112 of file BCMTF.cxx.

int BCMTF::SetTemplate ( const char *  channelname,
const char *  processname,
std::vector< TF1 * > *  funccont,
int  nbins,
double  efficiency = 1. 
)

Set the template for a specific process in a particular channel. This is an alternative way to describe the number of expected events. It is used in the rare case that processes cannot be summed directly, but interference effects have to be taken into account. The expected number of events is then parametrized as a function for each bin.

Parameters
channelnameThe name of the channel.
processnameThe name of the process.
funccontA vector of pointers of TF1 functions.
nbinsThe number of bins used for the histogram.
efficiencyThe efficiency of this process in this channel.
Returns
An error code.
See Also
SetTemplate(const char * channelname, const char * processname, TH1D hist, double efficiency = 1.)

Definition at line 170 of file BCMTF.cxx.


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