54 using namespace RooFit;
55 using namespace RooStats;
58 void rs_bernsteinCorrection()
62 Double_t lowRange = -1, highRange = 5;
65 RooRealVar x(
"x",
"x", lowRange, highRange);
68 RooGaussian narrow(
"narrow",
"", x, RooConst(0.), RooConst(.8));
69 RooGaussian wide(
"wide",
"", x, RooConst(0.), RooConst(2.));
70 RooAddPdf reality(
"reality",
"", RooArgList(narrow, wide), RooConst(0.8));
72 RooDataSet *data = reality.generate(x, 1000);
75 RooRealVar sigma(
"sigma",
"", 1., 0, 10);
76 RooGaussian nominal(
"nominal",
"", x, RooConst(0.), sigma);
78 RooWorkspace *wks =
new RooWorkspace(
"myWorksspace");
80 wks->import(*data, Rename(
"data"));
83 if (TClass::GetClass(
"ROOT::Minuit2::Minuit2Minimizer")) {
85 ROOT::Math::MinimizerOptions::SetDefaultMinimizer(
"Minuit2");
91 Double_t tolerance = 0.05;
92 BernsteinCorrection bernsteinCorrection(tolerance);
93 Int_t degree = bernsteinCorrection.ImportCorrectedPdf(wks,
"nominal",
"x",
"data");
96 Error(
"rs_bernsteinCorrection",
"Bernstein correction failed ! ");
100 cout <<
" Correction based on Bernstein Poly of degree " << degree << endl;
102 RooPlot *frame = x.frame();
105 TString minimType = ROOT::Math::MinimizerOptions::DefaultMinimizerType();
106 nominal.fitTo(*data, PrintLevel(0), Minimizer(minimType));
107 nominal.plotOn(frame);
110 RooAbsPdf *corrected = wks->pdf(
"corrected");
115 corrected->fitTo(*data, PrintLevel(0), Minimizer(minimType));
116 corrected->plotOn(frame, LineColor(kRed));
120 RooAbsPdf *poly = wks->pdf(
"poly");
122 poly->plotOn(frame, LineColor(kGreen), LineStyle(kDashed));
131 bool checkSamplingDist =
true;
134 TCanvas *c1 =
new TCanvas();
135 if (checkSamplingDist) {
142 if (checkSamplingDist) {
144 ROOT::Math::MinimizerOptions::SetDefaultPrintLevel(-1);
145 TH1F *samplingDist =
new TH1F(
"samplingDist",
"", 20, 0, 10);
146 TH1F *samplingDistExtra =
new TH1F(
"samplingDistExtra",
"", 20, 0, 10);
147 bernsteinCorrection.CreateQSamplingDist(wks,
"nominal",
"x",
"data", samplingDist, samplingDistExtra, degree,
151 samplingDistExtra->SetLineColor(kRed);
152 samplingDistExtra->Draw();
153 samplingDist->Draw(
"same");