00001 #ifndef __BCMODEL__H
00002 #define __BCMODEL__H
00003
00025
00026
00027 #include <vector>
00028 #include <string>
00029
00030 #include "BCIntegrate.h"
00031
00032
00033 class TNamed;
00034 class TH1;
00035 class TH2D;
00036 class TGraph;
00037 class TCanvas;
00038 class TPostscript;
00039 class TF1;
00040
00041
00042 class BCDataPoint;
00043 class BCDataSet;
00044 class BCParameter;
00045 class BCH1D;
00046 class BCH2D;
00047
00048 const int MAXNDATAPOINTVALUES = 20;
00049
00050
00051
00052 class BCModel : public BCIntegrate
00053 {
00054
00055 public:
00056
00062 BCModel();
00063
00067 BCModel(const char * name);
00068
00071 BCModel(const BCModel & bcmodel);
00072
00075 virtual ~BCModel();
00076
00083 BCModel & operator = (const BCModel & bcmodel);
00084
00091 std::string GetName()
00092 { return fName; }
00093
00096 int GetIndex()
00097 { return fIndex; }
00098
00101 double GetModelAPrioriProbability()
00102 { return fModelAPriori; }
00103
00106 double GetModelAPosterioriProbability()
00107 { return fModelAPosteriori; }
00108
00111 double GetNormalization()
00112 { return fNormalization; }
00113
00116 BCDataSet* GetDataSet()
00117 { return fDataSet; }
00118
00121 BCDataPoint* GetDataPointLowerBoundaries()
00122 { return fDataPointLowerBoundaries; }
00123
00126 BCDataPoint* GetDataPointUpperBoundaries()
00127 { return fDataPointUpperBoundaries; }
00128
00132 double GetDataPointLowerBoundary(unsigned int index)
00133 { return fDataPointLowerBoundaries -> GetValue(index); }
00134
00138 double GetDataPointUpperBoundary(unsigned int index)
00139 { return fDataPointUpperBoundaries -> GetValue(index); }
00140
00144 bool GetFlagBoundaries();
00145
00148 int GetNDataPoints();
00149
00153 BCDataPoint * GetDataPoint(unsigned int index);
00154
00157 unsigned int GetNDataPointsMinimum()
00158 { return fNDataPointsMinimum; }
00159
00162 unsigned int GetNDataPointsMaximum()
00163 { return fNDataPointsMaximum; }
00164
00167 unsigned int GetNParameters()
00168 { return fParameterSet ? fParameterSet -> size() : 0; }
00169
00173 BCParameter * GetParameter(int index);
00174
00178 BCParameter * GetParameter(const char * name);
00179
00182 BCParameterSet * GetParameterSet()
00183 { return fParameterSet; }
00184
00190 double GetBestFitParameter(unsigned int index);
00191
00197 double GetBestFitParameterError(unsigned int index);
00198
00203 std::vector<double> GetBestFitParameters()
00204 { return fBestFitParameters; }
00205
00206 std::vector<double> GetBestFitParameterErrors()
00207 { return fBestFitParameterErrors; }
00208
00214 double GetBestFitParameterMarginalized(unsigned int index);
00215
00220 std::vector<double> GetBestFitParametersMarginalized()
00221 { return fBestFitParametersMarginalized; }
00222
00225 TH2D * GetErrorBandXY()
00226 { return fErrorBandXY; }
00227
00228 TH2D * GetErrorBandXY_yellow(double level=.68, int nsmooth=0);
00229
00234 std::vector<double> GetErrorBand(double level);
00235
00236 TGraph * GetErrorBandGraph(double level1, double level2);
00237
00238 TGraph * GetFitFunctionGraph(const std::vector<double> ¶meters);
00239
00240 TGraph * GetFitFunctionGraph()
00241 { return this -> GetFitFunctionGraph(this -> GetBestFitParameters()); }
00242
00243 TGraph * GetFitFunctionGraph(const std::vector<double> ¶meters, double xmin, double xmax, int n=1000);
00244
00245 bool GetFixedDataAxis(unsigned int index);
00246
00255 void SetName(const char * name)
00256 { fName = name; }
00257
00261 void SetIndex(int index)
00262 { fIndex = index; }
00263
00267 void SetParameterSet( BCParameterSet * parset )
00268 { fParameterSet = parset; }
00269
00276 int SetParameterRange(int index, double parmin, double parmax);
00277
00282 void SetModelAPrioriProbability(double probability)
00283 { fModelAPriori = probability; }
00284
00289 void SetModelAPosterioriProbability(double probability)
00290 { fModelAPosteriori = probability; }
00291
00296 void SetNormalization(double norm)
00297 { fNormalization = norm; }
00298
00302 void SetDataSet(BCDataSet* dataset)
00303 { fDataSet = dataset; fNormalization = -1.0; }
00304
00308 void SetSingleDataPoint(BCDataPoint * datapoint);
00309
00310 void SetSingleDataPoint(BCDataSet * dataset, unsigned int index);
00311
00314 void SetNDataPointsMinimum(unsigned int minimum)
00315 { fNDataPointsMinimum = minimum; }
00316
00319 void SetNDataPointsMaximum(unsigned int maximum)
00320 { fNDataPointsMaximum = maximum; }
00321
00322 void SetDataBoundaries(unsigned int index, double lowerboundary, double upperboundary, bool fixed=false);
00323
00326 void SetErrorBandContinuous(bool flag);
00327
00332 void SetNbins(const char * parname, int nbins);
00333
00340 int SetPrior(int index, TF1* f);
00341
00348 int SetPrior(const char* name, TF1* f);
00349
00358 int SetPriorDelta(int index, double value);
00359
00368 int SetPriorDelta(const char* name, double value);
00369
00377 int SetPriorGauss(int index, double mean, double sigma);
00378
00386 int SetPriorGauss(const char* name, double mean, double sigma);
00387
00396 int SetPriorGauss(int index, double mean, double sigmadown, double sigmaup);
00397
00406 int SetPriorGauss(const char* name, double mean, double sigmadown, double sigmaup);
00407
00415 int SetPrior(int index, TH1 * h, bool flag=false);
00416
00424 int SetPrior(const char* name, TH1 * h, bool flag=false);
00425
00431 int SetPriorConstant(int index);
00432
00438 int SetPriorConstant(const char* name);
00439
00448 int SetPriorConstantAll();
00449
00461 int AddParameter(const char * name, double lowerlimit, double upperlimit);
00462
00467 int AddParameter(BCParameter* parameter);
00468
00474 double APrioriProbability(const std::vector<double> ¶meters)
00475 { return exp( this->LogAPrioriProbability(parameters) ); }
00476
00483 virtual double LogAPrioriProbability(const std::vector<double> ¶meters);
00484
00489 double Likelihood(const std::vector<double> ¶ms)
00490 { return exp( this->LogLikelihood(params) ); }
00491
00497 virtual double LogLikelihood(const std::vector<double> ¶ms) = 0;
00498
00503 double ProbabilityNN(const std::vector<double> ¶ms)
00504 { return exp( this->LogProbabilityNN(params) ); }
00505
00511 double LogProbabilityNN(const std::vector<double> ¶meter);
00512
00517 double Probability(const std::vector<double> ¶meter)
00518 { return exp( this->LogProbability(parameter) ); }
00519
00524 double LogProbability(const std::vector<double> ¶meter);
00525
00531 virtual double SamplingFunction(const std::vector<double> ¶meters);
00532
00535 double Eval(const std::vector<double> ¶meters)
00536 { return exp( this->LogEval(parameters) ); }
00537
00540 double LogEval(const std::vector<double> ¶meters);
00541
00544 double EvalSampling(const std::vector<double> ¶meters);
00545
00548 double Normalize();
00549
00555 int CheckParameters(const std::vector<double> ¶meters);
00556
00574 void FindMode(std::vector<double> start = std::vector<double>(0));
00575
00581 void FindModeMinuit(std::vector<double> start = std::vector<double>(0), int printlevel = 1);
00582
00585 void WriteMode(const char * file);
00586
00589 int ReadMode(const char * file);
00590
00593 int ReadMarginalizedFromFile(const char * file);
00594
00597 int ReadErrorBandFromFile(const char * file);
00598
00604 int MarginalizeAll();
00605
00611 BCH1D * GetMarginalized(BCParameter * parameter);
00612
00613 BCH1D * GetMarginalized(const char * name)
00614 { return this -> GetMarginalized(this -> GetParameter(name)); }
00615
00622 BCH2D * GetMarginalized(BCParameter * parameter1, BCParameter * parameter2);
00623
00624 BCH2D * GetMarginalized(const char * name1, const char * name2)
00625 { return this -> GetMarginalized(this -> GetParameter(name1), this -> GetParameter(name2)); }
00626
00629 int PrintAllMarginalized1D(const char * filebase);
00630 int PrintAllMarginalized2D(const char * filebase);
00631 int PrintAllMarginalized(const char * file, unsigned int hdiv=1, unsigned int ndiv=1);
00632
00636 virtual void CorrelateDataPointValues(std::vector<double> &x);
00637
00643 double GetPvalueFromChi2(const std::vector<double> &par, int sigma_index);
00644
00651 double GetPvalueFromChi2Johnson(std::vector<double> par);
00652
00660 double GetPvalueFromKolmogorov(const std::vector<double>& par, int index);
00661
00662
00671 double GetChi2Johnson(std::vector<double> par, const int nBins=-1);
00672
00683 double GetAvalueFromChi2Johnson(TTree* tree, TH1D* distribution=0);
00684
00685 double GetPvalueFromChi2NDoF(std::vector<double> par, int sigma_index);
00686
00687 BCH1D * CalculatePValue(std::vector<double> par, bool flag_histogram=false);
00688
00691 double GetPValue()
00692 { return fPValue; }
00693
00694 double GetPValueNDoF()
00695 { return fPValueNDoF; }
00696
00697 double GetChi2NDoF()
00698 { return fChi2NDoF; }
00699
00705 std::vector<double> GetChi2Runs(int dataIndex, int sigmaIndex);
00706
00710 void SetGoFNIterationsMax(int n)
00711 { fGoFNIterationsMax=n; }
00712
00716 void SetGoFNIterationsRun(int n)
00717 { fGoFNIterationsRun=n; }
00718
00722 void SetGoFNChains(int n)
00723 { fGoFNChains=n; }
00724
00730 double HessianMatrixElement(BCParameter * parameter1, BCParameter * parameter2, std::vector<double> point);
00731
00734 void PrintSummary();
00735
00738 void PrintResults(const char * file);
00739
00742 void PrintShortFitSummary(int chi2flag=0);
00743
00747 void PrintHessianMatrix(std::vector<double> parameters);
00748
00749 void FixDataAxis(unsigned int index, bool fixed);
00750
00751
00761 virtual double CDF(const std::vector<double>& , int , bool )
00762 {return 0.0;}
00763
00764
00768 int ResetResults();
00769
00772 protected:
00773
00776 int fIndex;
00777
00780 std::string fName;
00781
00784 double fModelAPriori;
00785
00788 double fModelAPosteriori;
00789
00792 BCParameterSet * fParameterSet;
00793
00796 BCDataSet * fDataSet;
00797
00800 unsigned int fNDataPointsMinimum;
00801
00804 unsigned int fNDataPointsMaximum;
00805
00808 double fPValue;
00809
00810 double fChi2NDoF;
00811 double fPValueNDoF;
00812
00815 bool flag_discrete;
00816
00820 int fGoFNIterationsMax;
00821
00825 int fGoFNIterationsRun;
00826
00830 int fGoFNChains;
00831
00834
00835 std::vector<TNamed*> fPriorContainer;
00836
00839 bool fPriorConstantAll;
00840
00844 double fPriorConstantValue;
00845
00848 std::vector<bool> fPriorContainerConstant;
00849
00852 std::vector<bool> fPriorContainerInterpolate;
00853
00854 private:
00855
00858 double fNormalization;
00859
00862 int CompareStrings(const char * string1, const char * string2);
00863
00868 int NumberBins()
00869 { return (int) exp( 0.4 * log( (float)GetNDataPoints() ) ) + 2; }
00870
00873 void RecalculatePriorConstant();
00874
00878 void StoreMode();
00879
00882 BCDataPoint * VectorToDataPoint(const std::vector<double> &data);
00883 };
00884
00885
00886
00887 typedef std::vector<BCModel*> BCModelContainer;
00888
00889
00890
00891 #endif