# rf703_effpdfprod¶

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, November 30, 2022 at 11:24 AM.

In [1]:
%%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;


## Define observables and decay pdf¶

Declare observables

In [2]:
RooRealVar t("t", "t", 0, 5);


Make pdf

In [3]:
RooRealVar tau("tau", "tau", -1.54, -4, -0.1);
RooExponential model("model", "model", t, tau);


## Define efficiency function¶

Use error function to simulate turn-on slope

In [4]:
RooFormulaVar eff("eff", "0.5*(TMath::Erf((t-1)/0.5)+1)", t);


## Define decay pdf with efficiency¶

Multiply pdf(t) with efficiency in t

In [5]:
RooEffProd modelEff("modelEff", "model with efficiency", model, eff);


## Plot efficiency, pdf¶

In [6]:
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 toy data, fit modelEff to data¶

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.

In [7]:
RooDataSet *data = modelEff.generate(t, 10000);

input_line_58:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration
RooDataSet *data = modelEff.generate(t, 10000);
^


Fit pdf. The normalization integral is calculated numerically.

In [8]:
modelEff.fitTo(*data);

input_line_59:2:18: error: reference to 'data' is ambiguous
modelEff.fitTo(*data);
^
input_line_58:2:14: note: candidate found by name lookup is '__cling_N526::data'
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

In [9]:
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);
frame1->GetYaxis()->SetTitleOffset(1.4);
frame1->Draw();
c->cd(2);
frame2->GetYaxis()->SetTitleOffset(1.6);
frame2->Draw();
c->cd(3);
frame3->GetYaxis()->SetTitleOffset(1.6);
frame3->Draw();

input_line_60:3:1: error: reference to 'data' is ambiguous
data->plotOn(frame3);
^
input_line_58:2:14: note: candidate found by name lookup is '__cling_N526::data'
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

In [10]:
%jsroot on
gROOT->GetListOfCanvases()->Draw()