Go to the documentation of this file.00001 #ifndef __BCMODELHISTOGRAMFITTER__H
00002 #define __BCMODELHISTOGRAMFITTER__H
00003
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <vector>
00025
00026 #include "../../BAT/BCModel.h"
00027
00028 class BCHistogramFitterToyDataInterface;
00029
00030
00031 class TH1D;
00032 class TF1;
00033
00034
00035
00036 class BCHistogramFitter : public BCModel
00037 {
00038 public:
00039
00041
00042
00045 BCHistogramFitter();
00046
00050 BCHistogramFitter(const char * name);
00051
00056 BCHistogramFitter(TH1D * hist, TF1 * func);
00057
00063 BCHistogramFitter(const char * name, TH1D * hist, TF1 * func);
00064
00067 ~BCHistogramFitter();
00068
00069
00070
00072
00073
00076 TH1D * GetHistogram()
00077 { return fHistogram; };
00078
00081 TH1D * GetHistogramExpected()
00082 { return fHistogramExpected; };
00083
00084
00087 TF1 * GetFitFunction()
00088 { return fFitFunction; };
00089
00092 TGraph * GetErrorBand()
00093 { return fErrorBand; };
00094
00097 TGraph * GetGraphFitFunction()
00098 { return fGraphFitFunction; };
00099
00100
00101
00103
00104
00109 int SetHistogram(TH1D * hist);
00110
00115 int SetHistogramExpected(const std::vector<double>& parameters);
00116
00121 int SetFitFunction(TF1 * func);
00122
00127 void SetFlagIntegration(bool flag)
00128 { fFlagIntegration = flag; };
00129
00130
00132
00133
00137
00138
00142 virtual double LogLikelihood(const std::vector<double> & parameters);
00143
00152
00153
00159 double FitFunction(const std::vector<double> & x, const std::vector<double> & parameters);
00160
00164 int Fit();
00165
00171 int Fit(TH1D * hist, TF1 * func);
00172
00175 void DrawFit(const char * options = "HIST", bool flaglegend = false);
00176
00184 int CalculatePValueFast(const std::vector<double> & par, double &pvalue, int nIterations = 100000);
00185
00196 int CalculatePValueFast(const std::vector<double> & par, BCHistogramFitterToyDataInterface* callback,
00197 double &pvalue, int nIterations = 100000);
00198
00206 int CalculatePValueLikelihood(const std::vector<double> &par, double &pvalue);
00207
00218 int CalculatePValueLeastSquares(const std::vector<double> &par, double &pvalue, bool weightExpect=true);
00219
00227 int CalculatePValueKolmogorov(const std::vector<double> &par, double &pvalue);
00228
00229
00230 double CDF(const std::vector<double>& parameters, int index, bool lower=false);
00231
00232
00233
00234 private:
00235
00239 TH1D * fHistogram;
00240
00243 TF1 * fFitFunction;
00244
00248 bool fFlagIntegration;
00249
00252 TGraph * fErrorBand;
00253
00256 TGraph * fGraphFitFunction;
00257
00261 TH1D * fHistogramExpected;
00262
00263 };
00264
00265
00266
00272 class BCHistogramFitterToyDataInterface
00273 {
00274 public:
00281 virtual void operator()(const std::vector<double>& expectation, const std::vector<int>& toyData)=0;
00282
00284 virtual ~BCHistogramFitterToyDataInterface(){}
00285 };
00286
00287 #endif