Special pdf's: using a product of an (acceptance) efficiency and a pdf as pdf
Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, April 17, 2024 at 11:19 AM.
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooExponential.h"
#include "RooEffProd.h"
#include "RooFormulaVar.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit;
Declare observables
RooRealVar t("t", "t", 0, 5);
Make pdf
RooRealVar tau("tau", "tau", -1.54, -4, -0.1);
RooExponential model("model", "model", t, tau);
Use error function to simulate turn-on slope
RooFormulaVar eff("eff", "0.5*(TMath::Erf((t-1)/0.5)+1)", t);
Multiply pdf(t) with efficiency in t
RooEffProd modelEff("modelEff", "model with efficiency", model, eff);
RooPlot *frame1 = t.frame(Title("Efficiency"));
eff.plotOn(frame1, LineColor(kRed));
RooPlot *frame2 = t.frame(Title("Pdf with and without efficiency"));
model.plotOn(frame2, LineStyle(kDashed));
modelEff.plotOn(frame2);
[#1] INFO:NumericIntegration -- RooRealIntegral::init(modelEff_Int[t]) using numeric integrator RooIntegrator1D to calculate Int(t)
Generate events. If the input pdf has an internal generator, the internal generator is used and an accept/reject sampling on the efficiency is applied.
std::unique_ptr<RooDataSet> data{modelEff.generate(t, 10000)};
input_line_56:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration std::unique_ptr<RooDataSet> data{modelEff.generate(t, 10000)}; ^
Fit pdf. The normalization integral is calculated numerically.
modelEff.fitTo(*data, PrintLevel(-1));
input_line_57:2:18: error: reference to 'data' is ambiguous modelEff.fitTo(*data, PrintLevel(-1)); ^ input_line_56:2:30: note: candidate found by name lookup is 'data' std::unique_ptr<RooDataSet> data{modelEff.generate(t, 10000)}; ^ /usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data' data(initializer_list<_Tp> __il) noexcept ^ /usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data' data(_Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data' data(const _Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data' data(_Tp (&__array)[_Nm]) noexcept ^
Plot generated data and overlay fitted pdf
RooPlot *frame3 = t.frame(Title("Fitted pdf with efficiency"));
data->plotOn(frame3);
modelEff.plotOn(frame3);
TCanvas *c = new TCanvas("rf703_effpdfprod", "rf703_effpdfprod", 1200, 400);
c->Divide(3);
c->cd(1);
gPad->SetLeftMargin(0.15);
frame1->GetYaxis()->SetTitleOffset(1.4);
frame1->Draw();
c->cd(2);
gPad->SetLeftMargin(0.15);
frame2->GetYaxis()->SetTitleOffset(1.6);
frame2->Draw();
c->cd(3);
gPad->SetLeftMargin(0.15);
frame3->GetYaxis()->SetTitleOffset(1.6);
frame3->Draw();
input_line_58:3:1: error: reference to 'data' is ambiguous data->plotOn(frame3); ^ input_line_56:2:30: note: candidate found by name lookup is 'data' std::unique_ptr<RooDataSet> data{modelEff.generate(t, 10000)}; ^ /usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data' data(initializer_list<_Tp> __il) noexcept ^ /usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data' data(_Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data' data(const _Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data' data(_Tp (&__array)[_Nm]) noexcept ^
Draw all canvases
%jsroot on
gROOT->GetListOfCanvases()->Draw()