57 using namespace RooFit;
58 using namespace RooStats;
60 void IntervalExamples()
68 RooRandom::randomGenerator()->SetSeed(3001);
71 RooWorkspace *wspace =
new RooWorkspace();
72 wspace->factory(
"Gaussian::normal(x[-10,10],mu[-1,1],sigma[1])");
73 wspace->defineSet(
"poi",
"mu");
74 wspace->defineSet(
"obs",
"x");
77 ModelConfig *modelConfig =
new ModelConfig(
"Example G(x|mu,1)");
78 modelConfig->SetWorkspace(*wspace);
79 modelConfig->SetPdf(*wspace->pdf(
"normal"));
80 modelConfig->SetParametersOfInterest(*wspace->set(
"poi"));
81 modelConfig->SetObservables(*wspace->set(
"obs"));
84 RooDataSet *data = wspace->pdf(
"normal")->generate(*wspace->set(
"obs"), 100);
88 RooRealVar *x = wspace->var(
"x");
89 RooRealVar *mu = wspace->var(
"mu");
92 double confidenceLevel = 0.95;
95 ProfileLikelihoodCalculator plc(*data, *modelConfig);
96 plc.SetConfidenceLevel(confidenceLevel);
97 LikelihoodInterval *plInt = plc.GetInterval();
100 FeldmanCousins fc(*data, *modelConfig);
101 fc.SetConfidenceLevel(confidenceLevel);
103 fc.UseAdaptiveSampling(
true);
107 fc.FluctuateNumDataEntries(
false);
115 PointSetInterval *interval = (PointSetInterval *)fc.GetInterval();
119 wspace->factory(
"Uniform::prior(mu)");
120 modelConfig->SetPriorPdf(*wspace->pdf(
"prior"));
123 BayesianCalculator bc(*data, *modelConfig);
124 bc.SetConfidenceLevel(confidenceLevel);
125 SimpleInterval *bcInt = bc.GetInterval();
128 MCMCCalculator mc(*data, *modelConfig);
129 mc.SetConfidenceLevel(confidenceLevel);
132 mc.SetNumBurnInSteps(500);
133 mc.SetNumIters(100000);
134 mc.SetLeftSideTailFraction(0.5);
135 MCMCInterval *mcInt = mc.GetInterval();
139 data->mean(*x) + ROOT::Math::normal_quantile((1 - confidenceLevel) / 2, 1) / sqrt(data->numEntries());
141 data->mean(*x) + ROOT::Math::normal_quantile_c((1 - confidenceLevel) / 2, 1) / sqrt(data->numEntries());
144 std::cout <<
"expected interval is [" << expectedLL <<
", " << expectedUL <<
"]" << endl;
146 cout <<
"plc interval is [" << plInt->LowerLimit(*mu) <<
", " << plInt->UpperLimit(*mu) <<
"]" << endl;
148 std::cout <<
"fc interval is [" << interval->LowerLimit(*mu) <<
" , " << interval->UpperLimit(*mu) <<
"]" << endl;
150 cout <<
"bc interval is [" << bcInt->LowerLimit() <<
", " << bcInt->UpperLimit() <<
"]" << endl;
152 cout <<
"mc interval is [" << mcInt->LowerLimit(*mu) <<
", " << mcInt->UpperLimit(*mu) <<
"]" << endl;
155 cout <<
"is mu=0 in the interval? " << plInt->IsInInterval(RooArgSet(*mu)) << endl;
158 gStyle->SetCanvasColor(0);
159 gStyle->SetCanvasBorderMode(0);
160 gStyle->SetPadBorderMode(0);
161 gStyle->SetPadColor(0);
162 gStyle->SetCanvasColor(0);
163 gStyle->SetTitleFillColor(0);
164 gStyle->SetFillColor(0);
165 gStyle->SetFrameFillColor(0);
166 gStyle->SetStatColor(0);
169 TCanvas *canvas =
new TCanvas(
"canvas");
170 canvas->Divide(2, 2);
174 RooPlot *frame = x->frame();
181 LikelihoodIntervalPlot plot(plInt);
186 MCMCIntervalPlot *mcPlot =
new MCMCIntervalPlot(*mcInt);
187 mcPlot->SetLineColor(kGreen);
188 mcPlot->SetLineWidth(2);
192 RooPlot *bcPlot = bc.GetPosteriorPlot();