{
"cells": [
{
"cell_type": "markdown",
"id": "4944dcdc",
"metadata": {},
"source": [
"# rf703_effpdfprod\n",
"Special pdf's: using a product of an (acceptance) efficiency and a pdf as pdf\n",
"\n",
"\n",
"\n",
"\n",
"**Author:** Wouter Verkerke \n",
"This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:34 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "1c08031c",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:34:28.159227Z",
"iopub.status.busy": "2026-05-19T20:34:28.159112Z",
"iopub.status.idle": "2026-05-19T20:34:28.174530Z",
"shell.execute_reply": "2026-05-19T20:34:28.173959Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"#include \"RooRealVar.h\"\n",
"#include \"RooDataSet.h\"\n",
"#include \"RooGaussian.h\"\n",
"#include \"RooConstVar.h\"\n",
"#include \"RooExponential.h\"\n",
"#include \"RooEffProd.h\"\n",
"#include \"RooFormulaVar.h\"\n",
"#include \"TCanvas.h\"\n",
"#include \"TAxis.h\"\n",
"#include \"RooPlot.h\"\n",
"using namespace RooFit;"
]
},
{
"cell_type": "markdown",
"id": "d168449b",
"metadata": {},
"source": [
"Define observables and decay pdf\n",
"---------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "9c214bc2",
"metadata": {},
"source": [
"Declare observables"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0b1015ce",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:34:28.176085Z",
"iopub.status.busy": "2026-05-19T20:34:28.175966Z",
"iopub.status.idle": "2026-05-19T20:34:28.498646Z",
"shell.execute_reply": "2026-05-19T20:34:28.497922Z"
}
},
"outputs": [],
"source": [
"RooRealVar t(\"t\", \"t\", 0, 5);"
]
},
{
"cell_type": "markdown",
"id": "a8dfb1be",
"metadata": {},
"source": [
"Make pdf"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "a6f7e422",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:34:28.500648Z",
"iopub.status.busy": "2026-05-19T20:34:28.500498Z",
"iopub.status.idle": "2026-05-19T20:34:28.709438Z",
"shell.execute_reply": "2026-05-19T20:34:28.708699Z"
}
},
"outputs": [],
"source": [
"RooRealVar tau(\"tau\", \"tau\", -1.54, -4, -0.1);\n",
"RooExponential model(\"model\", \"model\", t, tau);"
]
},
{
"cell_type": "markdown",
"id": "434368d4",
"metadata": {},
"source": [
"Define efficiency function\n",
"---------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "fdafddcd",
"metadata": {},
"source": [
"Use error function to simulate turn-on slope"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e5c668d5",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:34:28.717879Z",
"iopub.status.busy": "2026-05-19T20:34:28.717749Z",
"iopub.status.idle": "2026-05-19T20:34:28.952793Z",
"shell.execute_reply": "2026-05-19T20:34:28.952017Z"
}
},
"outputs": [],
"source": [
"RooFormulaVar eff(\"eff\", \"0.5*(TMath::Erf((t-1)/0.5)+1)\", t);"
]
},
{
"cell_type": "markdown",
"id": "0389f95b",
"metadata": {},
"source": [
"Define decay pdf with efficiency\n",
"---------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "46cfb870",
"metadata": {},
"source": [
"Multiply pdf(t) with efficiency in t"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "75683dd1",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:34:28.954526Z",
"iopub.status.busy": "2026-05-19T20:34:28.954406Z",
"iopub.status.idle": "2026-05-19T20:34:29.163304Z",
"shell.execute_reply": "2026-05-19T20:34:29.162629Z"
}
},
"outputs": [],
"source": [
"RooEffProd modelEff(\"modelEff\", \"model with efficiency\", model, eff);"
]
},
{
"cell_type": "markdown",
"id": "cdca80fe",
"metadata": {},
"source": [
"Plot efficiency, pdf\n",
"----------------------------------------"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "857e4b3b",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:34:29.165342Z",
"iopub.status.busy": "2026-05-19T20:34:29.165221Z",
"iopub.status.idle": "2026-05-19T20:34:29.374255Z",
"shell.execute_reply": "2026-05-19T20:34:29.373727Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[#1] INFO:NumericIntegration -- RooRealIntegral::init(modelEff_Int[t]) using numeric integrator RooIntegrator1D to calculate Int(t)\n"
]
}
],
"source": [
"RooPlot *frame1 = t.frame(Title(\"Efficiency\"));\n",
"eff.plotOn(frame1, LineColor(kRed));\n",
"\n",
"RooPlot *frame2 = t.frame(Title(\"Pdf with and without efficiency\"));\n",
"\n",
"model.plotOn(frame2, LineStyle(kDashed));\n",
"modelEff.plotOn(frame2);"
]
},
{
"cell_type": "markdown",
"id": "52e47c19",
"metadata": {},
"source": [
"Generate toy data, fit modelEff to data\n",
"------------------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "87d1524b",
"metadata": {},
"source": [
"Generate events. If the input pdf has an internal generator, the internal generator\n",
"is used and an accept/reject sampling on the efficiency is applied."
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "1137638d",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:34:29.376037Z",
"iopub.status.busy": "2026-05-19T20:34:29.375917Z",
"iopub.status.idle": "2026-05-19T20:34:29.585121Z",
"shell.execute_reply": "2026-05-19T20:34:29.584477Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_60:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration\n",
" std::unique_ptr data{modelEff.generate(t, 10000)};\n",
" ^\n"
]
}
],
"source": [
"std::unique_ptr data{modelEff.generate(t, 10000)};"
]
},
{
"cell_type": "markdown",
"id": "409e814a",
"metadata": {},
"source": [
"Fit pdf. The normalization integral is calculated numerically."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "1f36838a",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:34:29.586858Z",
"iopub.status.busy": "2026-05-19T20:34:29.586733Z",
"iopub.status.idle": "2026-05-19T20:34:29.796360Z",
"shell.execute_reply": "2026-05-19T20:34:29.795674Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_61:2:18: error: reference to 'data' is ambiguous\n",
" modelEff.fitTo(*data, PrintLevel(-1));\n",
" ^\n",
"input_line_60:2:30: note: candidate found by name lookup is 'data'\n",
" std::unique_ptr data{modelEff.generate(t, 10000)};\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n",
" data(initializer_list<_Tp> __il) noexcept\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n",
" data(_Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n",
" data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n",
" data(_Tp (&__array)[_Nm]) noexcept\n",
" ^\n"
]
}
],
"source": [
"modelEff.fitTo(*data, PrintLevel(-1));"
]
},
{
"cell_type": "markdown",
"id": "c62c219c",
"metadata": {},
"source": [
"Plot generated data and overlay fitted pdf"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "37ef7e8f",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:34:29.807782Z",
"iopub.status.busy": "2026-05-19T20:34:29.807638Z",
"iopub.status.idle": "2026-05-19T20:34:30.017324Z",
"shell.execute_reply": "2026-05-19T20:34:30.016719Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_62:3:1: error: reference to 'data' is ambiguous\n",
"data->plotOn(frame3);\n",
"^\n",
"input_line_60:2:30: note: candidate found by name lookup is 'data'\n",
" std::unique_ptr data{modelEff.generate(t, 10000)};\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n",
" data(initializer_list<_Tp> __il) noexcept\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n",
" data(_Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n",
" data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n",
" data(_Tp (&__array)[_Nm]) noexcept\n",
" ^\n"
]
}
],
"source": [
"RooPlot *frame3 = t.frame(Title(\"Fitted pdf with efficiency\"));\n",
"data->plotOn(frame3);\n",
"modelEff.plotOn(frame3);\n",
"\n",
"TCanvas *c = new TCanvas(\"rf703_effpdfprod\", \"rf703_effpdfprod\", 1200, 400);\n",
"c->Divide(3);\n",
"c->cd(1);\n",
"gPad->SetLeftMargin(0.15);\n",
"frame1->GetYaxis()->SetTitleOffset(1.4);\n",
"frame1->Draw();\n",
"c->cd(2);\n",
"gPad->SetLeftMargin(0.15);\n",
"frame2->GetYaxis()->SetTitleOffset(1.6);\n",
"frame2->Draw();\n",
"c->cd(3);\n",
"gPad->SetLeftMargin(0.15);\n",
"frame3->GetYaxis()->SetTitleOffset(1.6);\n",
"frame3->Draw();"
]
},
{
"cell_type": "markdown",
"id": "0ea179c9",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "b2ab9443",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:34:30.024399Z",
"iopub.status.busy": "2026-05-19T20:34:30.024253Z",
"iopub.status.idle": "2026-05-19T20:34:30.276103Z",
"shell.execute_reply": "2026-05-19T20:34:30.275281Z"
}
},
"outputs": [],
"source": [
"%jsroot on\n",
"gROOT->GetListOfCanvases()->Draw()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 5
}