00001 #ifndef __BCMODEL__H
00002 #define __BCMODEL__H
00003
00026
00027
00028 #include <vector>
00029 #include <string>
00030
00031 #include "BCIntegrate.h"
00032
00033
00034 class TNamed;
00035 class TH1;
00036 class TH2D;
00037 class TGraph;
00038 class TCanvas;
00039 class TPostscript;
00040 class TF1;
00041
00042
00043 class BCDataPoint;
00044 class BCDataSet;
00045 class BCParameter;
00046 class BCH1D;
00047 class BCH2D;
00048
00049 const int MAXNDATAPOINTVALUES = 20;
00050
00051
00052
00053 class BCModel : public BCIntegrate
00054 {
00055
00056 public:
00057
00063 BCModel();
00064
00068 BCModel(const char * name);
00069
00072 BCModel(const BCModel & bcmodel);
00073
00076 virtual ~BCModel();
00077
00084 BCModel & operator = (const BCModel & bcmodel);
00085
00092 std::string GetName()
00093 { return fName; }
00094
00097 int GetIndex()
00098 { return fIndex; }
00099
00102 double GetModelAPrioriProbability()
00103 { return fModelAPriori; }
00104
00107 double GetModelAPosterioriProbability()
00108 { return fModelAPosteriori; }
00109
00112 double GetNormalization()
00113 { return fNormalization; }
00114
00117 BCDataSet* GetDataSet()
00118 { return fDataSet; }
00119
00122 BCDataPoint* GetDataPointLowerBoundaries()
00123 { return fDataPointLowerBoundaries; }
00124
00127 BCDataPoint* GetDataPointUpperBoundaries()
00128 { return fDataPointUpperBoundaries; }
00129
00133 double GetDataPointLowerBoundary(unsigned int index)
00134 { return fDataPointLowerBoundaries -> GetValue(index); }
00135
00139 double GetDataPointUpperBoundary(unsigned int index)
00140 { return fDataPointUpperBoundaries -> GetValue(index); }
00141
00145 bool GetFlagBoundaries();
00146
00149 int GetNDataPoints();
00150
00154 BCDataPoint * GetDataPoint(unsigned int index);
00155
00158 unsigned int GetNDataPointsMinimum()
00159 { return fNDataPointsMinimum; }
00160
00163 unsigned int GetNDataPointsMaximum()
00164 { return fNDataPointsMaximum; }
00165
00168 unsigned int GetNParameters()
00169 { return fParameterSet ? fParameterSet -> size() : 0; }
00170
00174 BCParameter * GetParameter(int index);
00175
00179 BCParameter * GetParameter(const char * name);
00180
00183 BCParameterSet * GetParameterSet()
00184 { return fParameterSet; }
00185
00191 double GetBestFitParameter(unsigned int index);
00192
00198 double GetBestFitParameterError(unsigned int index);
00199
00204 std::vector <double> GetBestFitParameters()
00205 { return fBestFitParameters; }
00206
00207 std::vector <double> GetBestFitParameterErrors()
00208 { return fBestFitParameterErrors; }
00209
00215 double GetBestFitParameterMarginalized(unsigned int index);
00216
00221 std::vector <double> GetBestFitParametersMarginalized()
00222 { return fBestFitParametersMarginalized; }
00223
00226 TH2D * GetErrorBandXY()
00227 { return fErrorBandXY; }
00228
00229 TH2D * GetErrorBandXY_yellow(double level=.68, int nsmooth=0);
00230
00235 std::vector <double> GetErrorBand(double level);
00236
00237 TGraph * GetErrorBandGraph(double level1, double level2);
00238
00239 TGraph * GetFitFunctionGraph(std::vector <double> parameters);
00240
00241 TGraph * GetFitFunctionGraph()
00242 { return this -> GetFitFunctionGraph(this -> GetBestFitParameters()); }
00243
00244 TGraph * GetFitFunctionGraph(std::vector <double> parameters, double xmin, double xmax, int n=1000);
00245
00246 bool GetFixedDataAxis(unsigned int index);
00247
00256 void SetName(const char * name)
00257 { fName = name; }
00258
00262 void SetIndex(int index)
00263 { fIndex = index; }
00264
00268 void SetParameterSet( BCParameterSet * parset )
00269 { fParameterSet = parset; }
00270
00277 int SetParameterRange(int index, double parmin, double parmax);
00278
00283 void SetModelAPrioriProbability(double probability)
00284 { fModelAPriori = probability; }
00285
00290 void SetModelAPosterioriProbability(double probability)
00291 { fModelAPosteriori = probability; }
00292
00297 void SetNormalization(double norm)
00298 { fNormalization = norm; }
00299
00303 void SetDataSet(BCDataSet* dataset)
00304 { fDataSet = dataset; fNormalization = -1.0; }
00305
00309 void SetSingleDataPoint(BCDataPoint * datapoint);
00310
00311 void SetSingleDataPoint(BCDataSet * dataset, unsigned int index);
00312
00315 void SetNDataPointsMinimum(unsigned int minimum)
00316 { fNDataPointsMinimum = minimum; }
00317
00320 void SetNDataPointsMaximum(unsigned int maximum)
00321 { fNDataPointsMaximum = maximum; }
00322
00323 void SetDataBoundaries(unsigned int index, double lowerboundary, double upperboundary, bool fixed=false);
00324
00327 void SetErrorBandContinuous(bool flag);
00328
00333 void SetNbins(const char * parname, int nbins);
00334
00341 int SetPrior(int index, TF1* f);
00342
00349 int SetPrior(const char* name, TF1* f);
00350
00359 int SetPriorDelta(int index, double value);
00360
00369 int SetPriorDelta(const char* name, double value);
00370
00378 int SetPriorGauss(int index, double mean, double sigma);
00379
00387 int SetPriorGauss(const char* name, double mean, double sigma);
00388
00397 int SetPriorGauss(int index, double mean, double sigmadown, double sigmaup);
00398
00407 int SetPriorGauss(const char* name, double mean, double sigmadown, double sigmaup);
00408
00416 int SetPrior(int index, TH1 * h, bool flag=false);
00417
00425 int SetPrior(const char* name, TH1 * h, bool flag=false);
00426
00432 int SetPriorConstant(int index);
00433
00439 int SetPriorConstant(const char* name);
00440
00449 int SetPriorConstantAll();
00450
00462 int AddParameter(const char * name, double lowerlimit, double upperlimit);
00463
00468 int AddParameter(BCParameter* parameter);
00469
00475 double APrioriProbability(std::vector <double> parameters)
00476 { return exp( this->LogAPrioriProbability(parameters) ); }
00477
00484 virtual double LogAPrioriProbability(std::vector <double> parameters);
00485
00490 double Likelihood(std::vector <double> parameter)
00491 { return exp( this->LogLikelihood(parameter) ); }
00492
00498 virtual double LogLikelihood(std::vector <double> parameter);
00499
00504 double ProbabilityNN(std::vector <double> parameter)
00505 { return exp( this->LogProbabilityNN(parameter) ); }
00506
00512 double LogProbabilityNN(std::vector <double> parameter);
00513
00518 double Probability(std::vector <double> parameter)
00519 { return exp( this->LogProbability(parameter) ); }
00520
00525 double LogProbability(std::vector <double> parameter);
00526
00534 double ConditionalProbabilityEntry(BCDataPoint * datapoint, std::vector <double> parameters)
00535 { return exp( this->LogConditionalProbabilityEntry(datapoint, parameters) ); }
00536
00544 virtual double LogConditionalProbabilityEntry(BCDataPoint * , std::vector <double> )
00545 { flag_ConditionalProbabilityEntry = false; return 0.; }
00546
00552 virtual double SamplingFunction(std::vector <double> parameters);
00553
00556 double Eval(std::vector <double> parameters)
00557 { return exp( this->LogEval(parameters) ); }
00558
00561 double LogEval(std::vector <double> parameters);
00562
00565 double EvalSampling(std::vector <double> parameters);
00566
00569 double Normalize();
00570
00576 int CheckParameters(std::vector <double> parameters);
00577
00595 void FindMode(std::vector<double> start = std::vector<double>(0));
00596
00602 void FindModeMinuit(std::vector<double> start = std::vector<double>(0), int printlevel = 1);
00603
00606 void WriteMode(const char * file);
00607
00610 int ReadMode(const char * file);
00611
00614 int ReadMarginalizedFromFile(const char * file);
00615
00618 int ReadErrorBandFromFile(const char * file);
00619
00625 int MarginalizeAll();
00626
00632 BCH1D * GetMarginalized(BCParameter * parameter);
00633
00634 BCH1D * GetMarginalized(const char * name)
00635 { return this -> GetMarginalized(this -> GetParameter(name)); }
00636
00643 BCH2D * GetMarginalized(BCParameter * parameter1, BCParameter * parameter2);
00644
00645 BCH2D * GetMarginalized(const char * name1, const char * name2)
00646 { return this -> GetMarginalized(this -> GetParameter(name1), this -> GetParameter(name2)); }
00647
00650 int PrintAllMarginalized1D(const char * filebase);
00651 int PrintAllMarginalized2D(const char * filebase);
00652 int PrintAllMarginalized(const char * file, unsigned int hdiv=1, unsigned int ndiv=1);
00653
00657 virtual void CorrelateDataPointValues(std::vector<double> &x);
00658
00664 double GetPvalueFromChi2(std::vector<double> par, int sigma_index);
00665
00672 double GetPvalueFromChi2Johnson(std::vector<double> par);
00673
00681 double GetPvalueFromKolmogorov(const std::vector<double>& par, int index);
00682
00683
00692 double GetChi2Johnson(std::vector<double> par, const int nBins=-1);
00693
00704 double GetAvalueFromChi2Johnson(TTree* tree, TH1D* distribution=0);
00705
00706 double GetPvalueFromChi2NDoF(std::vector<double> par, int sigma_index);
00707
00708 BCH1D * CalculatePValue(std::vector<double> par, bool flag_histogram=false);
00709
00712 double GetPValue()
00713 { return fPValue; }
00714
00715 double GetPValueNDoF()
00716 { return fPValueNDoF; }
00717
00718 double GetChi2NDoF()
00719 { return fChi2NDoF; }
00720
00726 std::vector<double> GetChi2Runs(int dataIndex, int sigmaIndex);
00727
00731 void SetGoFNIterationsMax(int n)
00732 { fGoFNIterationsMax=n; }
00733
00737 void SetGoFNIterationsRun(int n)
00738 { fGoFNIterationsRun=n; }
00739
00743 void SetGoFNChains(int n)
00744 { fGoFNChains=n; }
00745
00751 double HessianMatrixElement(BCParameter * parameter1, BCParameter * parameter2, std::vector<double> point);
00752
00755 void PrintSummary();
00756
00759 void PrintResults(const char * file);
00760
00763 void PrintShortFitSummary(int chi2flag=0);
00764
00768 void PrintHessianMatrix(std::vector<double> parameters);
00769
00770 void FixDataAxis(unsigned int index, bool fixed);
00771
00772
00782 virtual double CDF(const std::vector<double>& , int , bool )
00783 {return 0.0;}
00784
00785
00789 int ResetResults();
00790
00793 protected:
00794
00797 int fIndex;
00798
00801 std::string fName;
00802
00805 double fModelAPriori;
00806
00809 double fModelAPosteriori;
00810
00813 BCParameterSet * fParameterSet;
00814
00817 BCDataSet * fDataSet;
00818
00821 unsigned int fNDataPointsMinimum;
00822
00825 unsigned int fNDataPointsMaximum;
00826
00829 bool flag_ConditionalProbabilityEntry;
00830
00833 double fPValue;
00834
00835 double fChi2NDoF;
00836 double fPValueNDoF;
00837
00840 bool flag_discrete;
00841
00845 int fGoFNIterationsMax;
00846
00850 int fGoFNIterationsRun;
00851
00855 int fGoFNChains;
00856
00859
00860 std::vector<TNamed*> fPriorContainer;
00861
00864 bool fPriorConstantAll;
00865
00869 double fPriorConstantValue;
00870
00873 std::vector<bool> fPriorContainerConstant;
00874
00877 std::vector<bool> fPriorContainerInterpolate;
00878
00879 private:
00880
00883 double fNormalization;
00884
00887 int CompareStrings(const char * string1, const char * string2);
00888
00893 int NumberBins()
00894 { return (int) exp( 0.4 * log( (float)GetNDataPoints() ) ) + 2; }
00895
00898 void RecalculatePriorConstant();
00899
00903 void StoreMode();
00904
00907 BCDataPoint * VectorToDataPoint(std::vector<double> data);
00908 };
00909
00910
00911
00912 typedef std::vector<BCModel*> BCModelContainer;
00913
00914
00915
00916 #endif