42 using namespace RooFit;
43 using namespace RooStats;
45 struct ProfileLikelihoodOptions {
47 double confLevel = 0.95;
49 bool plotAsTF1 =
false;
50 double poiMinPlot = 1;
51 double poiMaxPlot = 0;
52 bool doHypoTest =
false;
56 ProfileLikelihoodOptions optPL;
58 void StandardProfileLikelihoodDemo(
const char *infile =
"",
const char *workspaceName =
"combined",
59 const char *modelConfigName =
"ModelConfig",
const char *dataName =
"obsData")
62 double confLevel = optPL.confLevel;
63 double nScanPoints = optPL.nScanPoints;
64 bool plotAsTF1 = optPL.plotAsTF1;
65 double poiXMin = optPL.poiMinPlot;
66 double poiXMax = optPL.poiMaxPlot;
67 bool doHypoTest = optPL.doHypoTest;
68 double nullParamValue = optPL.nullValue;
73 const char *filename =
"";
74 if (!strcmp(infile,
"")) {
75 filename =
"results/example_combined_GaussExample_model.root";
76 bool fileExist = !gSystem->AccessPathName(filename);
80 cout <<
"HistFactory file cannot be generated on Windows - exit" << endl;
84 cout <<
"will run standard hist2workspace example" << endl;
85 gROOT->ProcessLine(
".! prepareHistFactory .");
86 gROOT->ProcessLine(
".! hist2workspace config/example.xml");
87 cout <<
"\n\n---------------------" << endl;
88 cout <<
"Done creating example input" << endl;
89 cout <<
"---------------------\n\n" << endl;
96 TFile *file = TFile::Open(filename);
100 cout <<
"StandardRooStatsDemoMacro: Input file " << filename <<
" is not found" << endl;
109 RooWorkspace *w = (RooWorkspace *)file->Get(workspaceName);
111 cout <<
"workspace not found" << endl;
116 ModelConfig *mc = (ModelConfig *)w->obj(modelConfigName);
119 RooAbsData *data = w->data(dataName);
124 cout <<
"data or ModelConfig was not found" << endl;
133 ProfileLikelihoodCalculator pl(*data, *mc);
134 pl.SetConfidenceLevel(confLevel);
135 LikelihoodInterval *interval = pl.GetInterval();
138 RooRealVar *firstPOI = (RooRealVar *)mc->GetParametersOfInterest()->first();
139 cout <<
"\n>>>> RESULT : " << confLevel * 100 <<
"% interval on " << firstPOI->GetName() <<
" is : ["
140 << interval->LowerLimit(*firstPOI) <<
", " << interval->UpperLimit(*firstPOI) <<
"]\n " << endl;
144 cout <<
"making a plot of the profile likelihood function ....(if it is taking a lot of time use less points or the "
145 "TF1 drawing option)\n";
146 LikelihoodIntervalPlot plot(interval);
147 plot.SetNPoints(nScanPoints);
148 if (poiXMin < poiXMax)
149 plot.SetRange(poiXMin, poiXMax);
152 opt += TString(
"tf1");
157 RooArgSet nullparams(
"nullparams");
158 nullparams.addClone(*firstPOI);
159 nullparams.setRealValue(firstPOI->GetName(), nullParamValue);
160 pl.SetNullParameters(nullparams);
161 std::cout <<
"Perform Test of Hypothesis : null Hypothesis is " << firstPOI->GetName() << nullParamValue
163 auto result = pl.GetHypoTest();
164 std::cout <<
"\n>>>> Hypotheis Test Result \n";