47 using namespace RooFit;
48 using namespace RooStats;
50 struct BayesianMCMCOptions {
52 double confLevel = 0.95;
56 int numIters = 100000;
57 int numBurnInSteps = 100;
60 BayesianMCMCOptions optMCMC;
62 void StandardBayesianMCMCDemo(
const char *infile =
"",
const char *workspaceName =
"combined",
63 const char *modelConfigName =
"ModelConfig",
const char *dataName =
"obsData")
70 const char *filename =
"";
71 if (!strcmp(infile,
"")) {
72 filename =
"results/example_combined_GaussExample_model.root";
73 bool fileExist = !gSystem->AccessPathName(filename);
77 cout <<
"HistFactory file cannot be generated on Windows - exit" << endl;
81 cout <<
"will run standard hist2workspace example" << endl;
82 gROOT->ProcessLine(
".! prepareHistFactory .");
83 gROOT->ProcessLine(
".! hist2workspace config/example.xml");
84 cout <<
"\n\n---------------------" << endl;
85 cout <<
"Done creating example input" << endl;
86 cout <<
"---------------------\n\n" << endl;
93 TFile *file = TFile::Open(filename);
97 cout <<
"StandardRooStatsDemoMacro: Input file " << filename <<
" is not found" << endl;
106 RooWorkspace *w = (RooWorkspace *)file->Get(workspaceName);
108 cout <<
"workspace not found" << endl;
113 ModelConfig *mc = (ModelConfig *)w->obj(modelConfigName);
116 RooAbsData *data = w->data(dataName);
121 cout <<
"data or ModelConfig was not found" << endl;
140 SequentialProposal sp(0.1);
146 MCMCCalculator mcmc(*data, *mc);
147 mcmc.SetConfidenceLevel(optMCMC.confLevel);
149 mcmc.SetProposalFunction(sp);
150 mcmc.SetNumIters(optMCMC.numIters);
151 mcmc.SetNumBurnInSteps(optMCMC.numBurnInSteps);
154 if (optMCMC.intervalType == 0)
155 mcmc.SetIntervalType(MCMCInterval::kShortest);
156 if (optMCMC.intervalType == 1)
157 mcmc.SetLeftSideTailFraction(0.5);
158 if (optMCMC.intervalType == 2)
159 mcmc.SetLeftSideTailFraction(0.);
161 RooRealVar *firstPOI = (RooRealVar *)mc->GetParametersOfInterest()->first();
162 if (optMCMC.minPOI != -999)
163 firstPOI->setMin(optMCMC.minPOI);
164 if (optMCMC.maxPOI != -999)
165 firstPOI->setMax(optMCMC.maxPOI);
167 MCMCInterval *interval = mcmc.GetInterval();
171 auto c1 =
new TCanvas(
"IntervalPlot");
172 MCMCIntervalPlot plot(*interval);
175 TCanvas *c2 =
new TCanvas(
"extraPlots");
176 const RooArgSet *list = mc->GetNuisanceParameters();
177 if (list->getSize() > 1) {
178 double n = list->getSize();
179 int ny = TMath::CeilNint(sqrt(n));
180 int nx = TMath::CeilNint(
double(n) / ny);
185 TIterator *it = mc->GetNuisanceParameters()->createIterator();
186 RooRealVar *nuis = NULL;
188 while ((nuis = (RooRealVar *)it->Next())) {
190 plot.DrawChainScatter(*firstPOI, *nuis);
194 cout <<
"\n>>>> RESULT : " << optMCMC.confLevel * 100 <<
"% interval on " << firstPOI->GetName() <<
" is : ["
195 << interval->LowerLimit(*firstPOI) <<
", " << interval->UpperLimit(*firstPOI) <<
"] " << endl;