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
00172 double GetBestFitParameter(unsigned int index)
00173 { return fBestFitParameters[index]; };
00174
00179 std::vector <double> GetBestFitParameters()
00180 { return fBestFitParameters; };
00181
00187 double GetBestFitParameterMarginalized(unsigned int index)
00188 { return fBestFitParametersMarginalized[index]; };
00189
00194 std::vector <double> GetBestFitParametersMarginalized()
00195 { return fBestFitParametersMarginalized; };
00196
00199 TH2D * GetErrorBandXY()
00200 { return fErrorBandXY; };
00201
00202 TH2D * GetErrorBandXY_yellow(double level=.68, int nsmooth=0);
00203
00208 std::vector <double> GetErrorBand(double level);
00209
00210 TGraph * GetErrorBandGraph(double level1, double level2);
00211
00212 TGraph * GetFitFunctionGraph(std::vector <double> parameters);
00213
00214 TGraph * GetFitFunctionGraph()
00215 { return this -> GetFitFunctionGraph(this -> GetBestFitParameters()); };
00216
00217 TGraph * GetFitFunctionGraph(std::vector <double> parameters, double xmin, double xmax, int n=1000);
00218
00219 bool GetFixedDataAxis(unsigned int index);
00220
00221
00222
00224
00225
00229 void SetName(const char * name)
00230 { fName = name; };
00231
00235 void SetIndex(int index)
00236 { fIndex = index; };
00237
00242 void SetModelAPrioriProbability(double probability)
00243 { fModelAPriori = probability; };
00244
00249 void SetModelAPosterioriProbability(double probability)
00250 { fModelAPosteriori = probability; };
00251
00256 void SetNormalization(double norm)
00257 { fNormalization = norm; };
00258
00262 void SetDataSet(BCDataSet* dataset)
00263 { fDataSet = dataset; fNormalization = -1.0; };
00264
00268 void SetSingleDataPoint(BCDataPoint * datapoint);
00269
00270 void SetSingleDataPoint(BCDataSet * dataset, unsigned int index);
00271
00274 void SetNDataPointsMinimum(unsigned int minimum)
00275 { fNDataPointsMinimum = minimum; };
00276
00279 void SetNDataPointsMaximum(unsigned int maximum)
00280 { fNDataPointsMaximum = maximum; };
00281
00282 void SetDataBoundaries(unsigned int index, double lowerboundary, double upperboundary, bool fixed=false);
00283
00286 void SetErrorBandContinuous(bool flag);
00287
00288
00289
00291
00292
00299 int AddParameter(const char * name, double lowerlimit, double upperlimit);
00300
00305 int AddParameter(BCParameter* parameter);
00306
00310 virtual void DefineParameters()
00311 { ;};
00312
00318 double APrioriProbability(std::vector <double> parameters)
00319 { return exp( this->LogAPrioriProbability(parameters) ); };
00320
00327 virtual double LogAPrioriProbability(std::vector <double> parameters)
00328 { return 1.; };
00329
00334 double Likelihood(std::vector <double> parameter)
00335 { return exp( this->LogLikelihood(parameter) ); };
00336
00342 virtual double LogLikelihood(std::vector <double> parameter);
00343
00348 double ProbabilityNN(std::vector <double> parameter)
00349 { return exp( this->LogProbabilityNN(parameter) ); };
00350
00356 double LogProbabilityNN(std::vector <double> parameter);
00357
00362 double Probability(std::vector <double> parameter)
00363 { return exp( this->LogProbability(parameter) ); };
00364
00369 double LogProbability(std::vector <double> parameter);
00370
00378 double ConditionalProbabilityEntry(BCDataPoint * datapoint, std::vector <double> parameters)
00379 { return exp( this->LogConditionalProbabilityEntry(datapoint, parameters) ); };
00380
00388 virtual double LogConditionalProbabilityEntry(BCDataPoint * datapoint, std::vector <double> parameters)
00389 { flag_ConditionalProbabilityEntry = false; return 0.; };
00390
00396 virtual double SamplingFunction(std::vector <double> parameters);
00397
00400 double Eval(std::vector <double> parameters)
00401 { return exp( this->LogEval(parameters) ); };
00402
00405 double LogEval(std::vector <double> parameters);
00406
00409 double EvalSampling(std::vector <double> parameters);
00410
00413 double Normalize();
00414
00420 int CheckParameters(std::vector <double> parameters);
00421
00424 void FindMode();
00425
00428 void WriteMode(const char * file);
00429
00432 int ReadMode(const char * file);
00433
00436 int ReadMarginalizedFromFile(const char * file);
00437
00440 int ReadErrorBandFromFile(const char * file);
00441
00447 int MarginalizeAll();
00448
00454 BCH1D * GetMarginalized(BCParameter * parameter);
00455
00456 BCH1D * GetMarginalized(const char * name)
00457 { return this -> GetMarginalized(this -> GetParameter(name)); };
00458
00465 BCH2D * GetMarginalized(BCParameter * parameter1, BCParameter * parameter2);
00466
00467 BCH2D * GetMarginalized(const char * name1, const char * name2)
00468 { return this -> GetMarginalized(this -> GetParameter(name1), this -> GetParameter(name2)); };
00469
00472 int PrintAllMarginalized1D(const char * filebase);
00473 int PrintAllMarginalized2D(const char * filebase);
00474 int PrintAllMarginalized(const char * file, unsigned int hdiv=1, unsigned int ndiv=1);
00475
00479 virtual void CorrelateDataPointValues(std::vector<double> &x);
00480
00486 double GetPvalueFromChi2(std::vector<double> par, int sigma_index);
00487
00488 BCH1D * CalculatePValue(std::vector<double> par, bool flag_histogram=false);
00489
00490
00491
00492 double GetPValue()
00493 { return fPValue; };
00494
00495
00496
00497
00498 void SetGoFNIterationsMax(int n)
00499 { fGoFNIterationsMax=n; };
00500
00501
00502
00503
00504 void SetGoFNIterationsRun(int n)
00505 { fGoFNIterationsRun=n; };
00506
00507
00508
00509
00510 void SetGoFNChains(int n)
00511 { fGoFNChains=n; };
00512
00518 double HessianMatrixElement(BCParameter * parameter1, BCParameter * parameter2, std::vector<double> point);
00519
00522 void PrintSummary();
00523
00526 void PrintResults(const char * file);
00527
00530 void PrintShortFitSummary();
00531
00535 void PrintHessianMatrix(std::vector<double> parameters);
00536
00537 void FixDataAxis(unsigned int index, bool fixed);
00538
00539
00540
00541 protected:
00542
00545 int fIndex;
00546
00549 std::string fName;
00550
00553 double fModelAPriori;
00554
00557 double fModelAPosteriori;
00558
00561 BCParameterSet * fParameterSet;
00562
00565 BCDataSet * fDataSet;
00566
00569 unsigned int fNDataPointsMinimum;
00570
00573 unsigned int fNDataPointsMaximum;
00574
00577 bool flag_ConditionalProbabilityEntry;
00578
00581 double fPValue;
00582
00583
00584
00585
00586 int fGoFNIterationsMax;
00587
00588
00589
00590
00591 int fGoFNIterationsRun;
00592
00593
00594
00595
00596 int fGoFNChains;
00597
00598 private:
00599
00602 BCDataPoint * VectorToDataPoint(std::vector<double> data);
00603
00606 int CompareStrings(const char * string1, const char * string2);
00607
00610 double fNormalization;
00611
00612 };
00613
00614
00615
00616 typedef std::vector<BCModel*> BCModelContainer;
00617
00618
00619
00620 #endif