00001 #ifndef __BCMODEL__H
00002 #define __BCMODEL__H
00003
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <vector>
00029 #include <string>
00030
00031 #include "BAT/BCIntegrate.h"
00032
00033
00034 class TH2D;
00035 class TGraph;
00036 class TCanvas;
00037 class TPostscript;
00038
00039
00040 class BCDataPoint;
00041 class BCDataSet;
00042 class BCParameter;
00043 class BCH1D;
00044 class BCH2D;
00045
00046 const int MAXNDATAPOINTVALUES = 20;
00047
00048
00049
00050 class BCModel : public BCIntegrate
00051 {
00052
00053 public:
00054
00056
00057
00060 BCModel();
00061
00065 BCModel(const char * name);
00066
00069 virtual ~BCModel();
00070
00071
00072
00074
00075
00078 std::string GetName()
00079 { return fName; };
00080
00083 int GetIndex()
00084 { return fIndex; };
00085
00088 double GetModelAPrioriProbability()
00089 { return fModelAPriori; };
00090
00093 double GetModelAPosterioriProbability()
00094 { return fModelAPosteriori; };
00095
00098 double GetNormalization()
00099 { return fNormalization; };
00100
00103 BCDataSet* GetDataSet()
00104 { return fDataSet; };
00105
00108 BCDataPoint* GetDataPointLowerBoundaries()
00109 { return fDataPointLowerBoundaries; };
00110
00113 BCDataPoint* GetDataPointUpperBoundaries()
00114 { return fDataPointUpperBoundaries; };
00115
00119 double GetDataPointLowerBoundary(unsigned int index)
00120 { return fDataPointLowerBoundaries -> GetValue(index); };
00121
00125 double GetDataPointUpperBoundary(unsigned int index)
00126 { return fDataPointUpperBoundaries -> GetValue(index); };
00127
00128
00129
00130
00131 bool GetFlagBoundaries();
00132
00135 int GetNDataPoints();
00136
00140 BCDataPoint * GetDataPoint(unsigned int index);
00141
00144 unsigned int GetNDataPointsMinimum()
00145 { return fNDataPointsMinimum; };
00146
00149 unsigned int GetNDataPointsMaximum()
00150 { return fNDataPointsMaximum; };
00151
00154 unsigned int GetNParameters()
00155 { return fParameterSet ? fParameterSet -> size() : 0; };
00156
00160 BCParameter* GetParameter(int index);
00161
00165 BCParameter * GetParameter(const char * name);
00166
00169 BCParameterSet * GetParameterSet()
00170 { return fParameterSet; };
00171
00177 double GetBestFitParameter(unsigned int index)
00178 { return fBestFitParameters[index]; };
00179
00184 std::vector <double> GetBestFitParameters()
00185 { return fBestFitParameters; };
00186
00192 double GetBestFitParameterMarginalized(unsigned int index)
00193 { return fBestFitParametersMarginalized[index]; };
00194
00199 std::vector <double> GetBestFitParametersMarginalized()
00200 { return fBestFitParametersMarginalized; };
00201
00204 TH2D * GetErrorBandXY()
00205 { return fErrorBandXY; };
00206
00207 TH2D * GetErrorBandXY_yellow(double level=.68, int nsmooth=0);
00208
00213 std::vector <double> GetErrorBand(double level);
00214
00215 TGraph * GetErrorBandGraph(double level1, double level2);
00216
00217 TGraph * GetFitFunctionGraph(std::vector <double> parameters);
00218
00219 TGraph * GetFitFunctionGraph()
00220 { return this -> GetFitFunctionGraph(this -> GetBestFitParameters()); };
00221
00222 TGraph * GetFitFunctionGraph(std::vector <double> parameters, double xmin, double xmax, int n=1000);
00223
00224 bool GetFixedDataAxis(unsigned int index);
00225
00226
00227
00229
00230
00234 void SetName(const char * name)
00235 { fName = name; };
00236
00240 void SetIndex(int index)
00241 { fIndex = index; };
00242
00246 void SetParameterSet( BCParameterSet * parset )
00247 { fParameterSet = parset; };
00248
00253 void SetModelAPrioriProbability(double probability)
00254 { fModelAPriori = probability; };
00255
00260 void SetModelAPosterioriProbability(double probability)
00261 { fModelAPosteriori = probability; };
00262
00267 void SetNormalization(double norm)
00268 { fNormalization = norm; };
00269
00273 void SetDataSet(BCDataSet* dataset)
00274 { fDataSet = dataset; fNormalization = -1.0; };
00275
00279 void SetSingleDataPoint(BCDataPoint * datapoint);
00280
00281 void SetSingleDataPoint(BCDataSet * dataset, unsigned int index);
00282
00285 void SetNDataPointsMinimum(unsigned int minimum)
00286 { fNDataPointsMinimum = minimum; };
00287
00290 void SetNDataPointsMaximum(unsigned int maximum)
00291 { fNDataPointsMaximum = maximum; };
00292
00293 void SetDataBoundaries(unsigned int index, double lowerboundary, double upperboundary, bool fixed=false);
00294
00297 void SetErrorBandContinuous(bool flag);
00298
00303 void SetNbins(const char * parname, int nbins);
00304
00305
00306
00308
00309
00316 int AddParameter(const char * name, double lowerlimit, double upperlimit);
00317
00322 int AddParameter(BCParameter* parameter);
00323
00329 double APrioriProbability(std::vector <double> parameters)
00330 { return exp( this->LogAPrioriProbability(parameters) ); };
00331
00338 virtual double LogAPrioriProbability(std::vector <double> parameters)
00339 { return 0.; };
00340
00345 double Likelihood(std::vector <double> parameter)
00346 { return exp( this->LogLikelihood(parameter) ); };
00347
00353 virtual double LogLikelihood(std::vector <double> parameter);
00354
00359 double ProbabilityNN(std::vector <double> parameter)
00360 { return exp( this->LogProbabilityNN(parameter) ); };
00361
00367 double LogProbabilityNN(std::vector <double> parameter);
00368
00373 double Probability(std::vector <double> parameter)
00374 { return exp( this->LogProbability(parameter) ); };
00375
00380 double LogProbability(std::vector <double> parameter);
00381
00389 double ConditionalProbabilityEntry(BCDataPoint * datapoint, std::vector <double> parameters)
00390 { return exp( this->LogConditionalProbabilityEntry(datapoint, parameters) ); };
00391
00399 virtual double LogConditionalProbabilityEntry(BCDataPoint * datapoint, std::vector <double> parameters)
00400 { flag_ConditionalProbabilityEntry = false; return 0.; };
00401
00407 virtual double SamplingFunction(std::vector <double> parameters);
00408
00411 double Eval(std::vector <double> parameters)
00412 { return exp( this->LogEval(parameters) ); };
00413
00416 double LogEval(std::vector <double> parameters);
00417
00420 double EvalSampling(std::vector <double> parameters);
00421
00424 double Normalize();
00425
00431 int CheckParameters(std::vector <double> parameters);
00432
00450 void FindMode(std::vector<double> start = std::vector<double>(0));
00451
00454 void WriteMode(const char * file);
00455
00458 int ReadMode(const char * file);
00459
00462 int ReadMarginalizedFromFile(const char * file);
00463
00466 int ReadErrorBandFromFile(const char * file);
00467
00473 int MarginalizeAll();
00474
00480 BCH1D * GetMarginalized(BCParameter * parameter);
00481
00482 BCH1D * GetMarginalized(const char * name)
00483 { return this -> GetMarginalized(this -> GetParameter(name)); };
00484
00491 BCH2D * GetMarginalized(BCParameter * parameter1, BCParameter * parameter2);
00492
00493 BCH2D * GetMarginalized(const char * name1, const char * name2)
00494 { return this -> GetMarginalized(this -> GetParameter(name1), this -> GetParameter(name2)); };
00495
00498 int PrintAllMarginalized1D(const char * filebase);
00499 int PrintAllMarginalized2D(const char * filebase);
00500 int PrintAllMarginalized(const char * file, unsigned int hdiv=1, unsigned int ndiv=1);
00501
00505 virtual void CorrelateDataPointValues(std::vector<double> &x);
00506
00512 double GetPvalueFromChi2(std::vector<double> par, int sigma_index);
00513
00514 BCH1D * CalculatePValue(std::vector<double> par, bool flag_histogram=false);
00515
00516
00517
00518 double GetPValue()
00519 { return fPValue; };
00520
00521
00522
00523
00524 void SetGoFNIterationsMax(int n)
00525 { fGoFNIterationsMax=n; };
00526
00527
00528
00529
00530 void SetGoFNIterationsRun(int n)
00531 { fGoFNIterationsRun=n; };
00532
00533
00534
00535
00536 void SetGoFNChains(int n)
00537 { fGoFNChains=n; };
00538
00544 double HessianMatrixElement(BCParameter * parameter1, BCParameter * parameter2, std::vector<double> point);
00545
00548 void PrintSummary();
00549
00552 void PrintResults(const char * file);
00553
00556 void PrintShortFitSummary();
00557
00561 void PrintHessianMatrix(std::vector<double> parameters);
00562
00563 void FixDataAxis(unsigned int index, bool fixed);
00564
00565
00566
00567 protected:
00568
00571 int fIndex;
00572
00575 std::string fName;
00576
00579 double fModelAPriori;
00580
00583 double fModelAPosteriori;
00584
00587 BCParameterSet * fParameterSet;
00588
00591 BCDataSet * fDataSet;
00592
00595 unsigned int fNDataPointsMinimum;
00596
00599 unsigned int fNDataPointsMaximum;
00600
00603 bool flag_ConditionalProbabilityEntry;
00604
00607 double fPValue;
00608
00609
00610
00611
00612 int fGoFNIterationsMax;
00613
00614
00615
00616
00617 int fGoFNIterationsRun;
00618
00619
00620
00621
00622 int fGoFNChains;
00623
00624 private:
00625
00628 BCDataPoint * VectorToDataPoint(std::vector<double> data);
00629
00632 int CompareStrings(const char * string1, const char * string2);
00633
00636 double fNormalization;
00637
00638 };
00639
00640
00641
00642 typedef std::vector<BCModel*> BCModelContainer;
00643
00644
00645
00646 #endif