00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "TFile.h"
00028 #include "TROOT.h"
00029 #include "RooWorkspace.h"
00030 #include "RooAbsData.h"
00031
00032 #include "RooStats/ModelConfig.h"
00033 #include "RooStats/MCMCCalculator.h"
00034 #include "RooStats/MCMCInterval.h"
00035 #include "RooStats/MCMCIntervalPlot.h"
00036
00037 using namespace RooFit;
00038 using namespace RooStats;
00039
00040 void StandardBayesianMCMCDemo(const char* infile = "",
00041 const char* workspaceName = "proto",
00042 const char* modelConfigName = "ModelConfig",
00043 const char* dataName = "expData"){
00044
00045
00046
00047
00048
00049 const char* filename = "";
00050 if (!strcmp(infile,""))
00051 filename = "results/example_channel1_GammaExample_model.root";
00052 else
00053 filename = infile;
00054
00055 TFile *file = TFile::Open(filename);
00056
00057
00058 if(!file && strcmp(infile,"")){
00059 cout <<"file not found" << endl;
00060 return;
00061 }
00062
00063
00064 if(!file ){
00065
00066 cout <<"will run standard hist2workspace example"<<endl;
00067 gROOT->ProcessLine(".! prepareHistFactory .");
00068 gROOT->ProcessLine(".! hist2workspace config/example.xml");
00069 cout <<"\n\n---------------------"<<endl;
00070 cout <<"Done creating example input"<<endl;
00071 cout <<"---------------------\n\n"<<endl;
00072 }
00073
00074
00075 file = TFile::Open(filename);
00076 if(!file){
00077
00078 cout << "Not able to run hist2workspace to create example input" <<endl;
00079 return;
00080 }
00081
00082
00083
00084
00085
00086
00087
00088 RooWorkspace* w = (RooWorkspace*) file->Get(workspaceName);
00089 if(!w){
00090 cout <<"workspace not found" << endl;
00091 return;
00092 }
00093
00094
00095 ModelConfig* mc = (ModelConfig*) w->obj(modelConfigName);
00096
00097
00098 RooAbsData* data = w->data(dataName);
00099
00100
00101 if(!data || !mc){
00102 w->Print();
00103 cout << "data or ModelConfig was not found" <<endl;
00104 return;
00105 }
00106
00107
00108
00109
00110
00111
00112 MCMCCalculator mcmc(*data,*mc);
00113 mcmc.SetConfidenceLevel(0.95);
00114 mcmc.SetNumIters(1000000);
00115 mcmc.SetNumBurnInSteps(500);
00116
00117
00118 mcmc.SetLeftSideTailFraction(0.5);
00119
00120 MCMCInterval* interval = mcmc.GetInterval();
00121
00122
00123 MCMCIntervalPlot plot(*interval);
00124 plot.Draw();
00125
00126
00127 RooRealVar* firstPOI = (RooRealVar*) mc->GetParametersOfInterest()->first();
00128 cout << "\n95% interval on " <<firstPOI->GetName()<<" is : ["<<
00129 interval->LowerLimit(*firstPOI) << ", "<<
00130 interval->UpperLimit(*firstPOI) <<"] "<<endl;
00131
00132 }