{
"cells": [
{
"cell_type": "markdown",
"id": "d1c990e5",
"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, March 19, 2024 at 07:17 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "cdf192cf",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:17:27.355066Z",
"iopub.status.busy": "2024-03-19T19:17:27.354638Z",
"iopub.status.idle": "2024-03-19T19:17:27.387653Z",
"shell.execute_reply": "2024-03-19T19:17:27.386360Z"
}
},
"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": "b18b86f1",
"metadata": {},
"source": [
"Define observables and decay pdf\n",
"---------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "ae1c69e9",
"metadata": {},
"source": [
"Declare observables"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "39952887",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:17:27.393060Z",
"iopub.status.busy": "2024-03-19T19:17:27.392727Z",
"iopub.status.idle": "2024-03-19T19:17:27.986905Z",
"shell.execute_reply": "2024-03-19T19:17:27.985120Z"
}
},
"outputs": [],
"source": [
"RooRealVar t(\"t\", \"t\", 0, 5);"
]
},
{
"cell_type": "markdown",
"id": "df23b377",
"metadata": {},
"source": [
"Make pdf"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "015b0e71",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:17:27.998939Z",
"iopub.status.busy": "2024-03-19T19:17:27.998521Z",
"iopub.status.idle": "2024-03-19T19:17:28.215239Z",
"shell.execute_reply": "2024-03-19T19:17:28.213785Z"
}
},
"outputs": [],
"source": [
"RooRealVar tau(\"tau\", \"tau\", -1.54, -4, -0.1);\n",
"RooExponential model(\"model\", \"model\", t, tau);"
]
},
{
"cell_type": "markdown",
"id": "1c703415",
"metadata": {},
"source": [
"Define efficiency function\n",
"---------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "dba43ce3",
"metadata": {},
"source": [
"Use error function to simulate turn-on slope"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "5f245c8f",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:17:28.220384Z",
"iopub.status.busy": "2024-03-19T19:17:28.220058Z",
"iopub.status.idle": "2024-03-19T19:17:28.531104Z",
"shell.execute_reply": "2024-03-19T19:17:28.530115Z"
}
},
"outputs": [],
"source": [
"RooFormulaVar eff(\"eff\", \"0.5*(TMath::Erf((t-1)/0.5)+1)\", t);"
]
},
{
"cell_type": "markdown",
"id": "f756e3db",
"metadata": {},
"source": [
"Define decay pdf with efficiency\n",
"---------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "d6b90d25",
"metadata": {},
"source": [
"Multiply pdf(t) with efficiency in t"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "c09e91ba",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:17:28.536517Z",
"iopub.status.busy": "2024-03-19T19:17:28.536156Z",
"iopub.status.idle": "2024-03-19T19:17:28.752062Z",
"shell.execute_reply": "2024-03-19T19:17:28.750816Z"
}
},
"outputs": [],
"source": [
"RooEffProd modelEff(\"modelEff\", \"model with efficiency\", model, eff);"
]
},
{
"cell_type": "markdown",
"id": "4e7aff94",
"metadata": {},
"source": [
"Plot efficiency, pdf\n",
"----------------------------------------"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "131c66cc",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:17:28.773958Z",
"iopub.status.busy": "2024-03-19T19:17:28.772997Z",
"iopub.status.idle": "2024-03-19T19:17:29.047386Z",
"shell.execute_reply": "2024-03-19T19:17:29.045848Z"
}
},
"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": "d5cdda2c",
"metadata": {},
"source": [
"Generate toy data, fit modelEff to data\n",
"------------------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "78b9d584",
"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": "5c434e3f",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:17:29.087800Z",
"iopub.status.busy": "2024-03-19T19:17:29.087385Z",
"iopub.status.idle": "2024-03-19T19:17:29.543867Z",
"shell.execute_reply": "2024-03-19T19:17:29.542779Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_56: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": "bad06dab",
"metadata": {},
"source": [
"Fit pdf. The normalization integral is calculated numerically."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "ee16a2d9",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:17:29.548612Z",
"iopub.status.busy": "2024-03-19T19:17:29.548302Z",
"iopub.status.idle": "2024-03-19T19:17:29.764865Z",
"shell.execute_reply": "2024-03-19T19:17:29.763858Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_57:2:18: error: reference to 'data' is ambiguous\n",
" modelEff.fitTo(*data, PrintLevel(-1));\n",
" ^\n",
"input_line_56:2:30: note: candidate found by name lookup is 'data'\n",
" std::unique_ptr data{modelEff.generate(t, 10000)};\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'\n",
" data(initializer_list<_Tp> __il) noexcept\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'\n",
" data(_Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'\n",
" data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:309: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": "a740ba4f",
"metadata": {},
"source": [
"Plot generated data and overlay fitted pdf"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "4e4d9458",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:17:29.769860Z",
"iopub.status.busy": "2024-03-19T19:17:29.769559Z",
"iopub.status.idle": "2024-03-19T19:17:30.004417Z",
"shell.execute_reply": "2024-03-19T19:17:29.997730Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_58:3:1: error: reference to 'data' is ambiguous\n",
"data->plotOn(frame3);\n",
"^\n",
"input_line_56:2:30: note: candidate found by name lookup is 'data'\n",
" std::unique_ptr data{modelEff.generate(t, 10000)};\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'\n",
" data(initializer_list<_Tp> __il) noexcept\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'\n",
" data(_Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'\n",
" data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n",
" ^\n",
"/usr/include/c++/9/bits/range_access.h:309: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": "3c0677fc",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "3d3ff84e",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:17:30.010053Z",
"iopub.status.busy": "2024-03-19T19:17:30.009713Z",
"iopub.status.idle": "2024-03-19T19:17:30.298829Z",
"shell.execute_reply": "2024-03-19T19:17:30.297409Z"
}
},
"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
}