{
"cells": [
{
"cell_type": "markdown",
"id": "e9e6e3c6",
"metadata": {},
"source": [
"# rf110_normintegration\n",
"Basic functionality: normalization and integration of pdfs, construction of cumulative distribution\n",
"monodimensional functions\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:29 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "6396d879",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:22.020571Z",
"iopub.status.busy": "2026-05-19T20:29:22.020426Z",
"iopub.status.idle": "2026-05-19T20:29:22.033880Z",
"shell.execute_reply": "2026-05-19T20:29:22.032965Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"#include \"RooRealVar.h\"\n",
"#include \"RooGaussian.h\"\n",
"#include \"RooAbsReal.h\"\n",
"#include \"RooPlot.h\"\n",
"#include \"TCanvas.h\"\n",
"#include \"TAxis.h\"\n",
"using namespace RooFit;"
]
},
{
"cell_type": "markdown",
"id": "44d65a57",
"metadata": {},
"source": [
"Setup model\n",
"---------------------"
]
},
{
"cell_type": "markdown",
"id": "a851c616",
"metadata": {},
"source": [
"Create observables x,y"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "7d3fec20",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:22.035347Z",
"iopub.status.busy": "2026-05-19T20:29:22.035224Z",
"iopub.status.idle": "2026-05-19T20:29:22.248481Z",
"shell.execute_reply": "2026-05-19T20:29:22.247840Z"
}
},
"outputs": [],
"source": [
"RooRealVar x(\"x\", \"x\", -10, 10);"
]
},
{
"cell_type": "markdown",
"id": "69a02dc6",
"metadata": {},
"source": [
"Create pdf gaussx(x,-2,3)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e405f429",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:22.250461Z",
"iopub.status.busy": "2026-05-19T20:29:22.250340Z",
"iopub.status.idle": "2026-05-19T20:29:22.457745Z",
"shell.execute_reply": "2026-05-19T20:29:22.457180Z"
}
},
"outputs": [],
"source": [
"RooGaussian gx(\"gx\", \"gx\", x, -2.0, 3.0);"
]
},
{
"cell_type": "markdown",
"id": "3dbb0d56",
"metadata": {},
"source": [
"Retrieve raw & normalized values of RooFit p.d.f.s\n",
"--------------------------------------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "48d34508",
"metadata": {},
"source": [
"Return 'raw' unnormalized value of gx"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "adc119f7",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:22.459851Z",
"iopub.status.busy": "2026-05-19T20:29:22.459729Z",
"iopub.status.idle": "2026-05-19T20:29:22.667664Z",
"shell.execute_reply": "2026-05-19T20:29:22.666773Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"gx = 0.800737\n"
]
}
],
"source": [
"cout << \"gx = \" << gx.getVal() << endl;"
]
},
{
"cell_type": "markdown",
"id": "4b8b2fd3",
"metadata": {},
"source": [
"Return value of gx normalized over x in range [-10,10]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "12b0e190",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:22.669218Z",
"iopub.status.busy": "2026-05-19T20:29:22.669097Z",
"iopub.status.idle": "2026-05-19T20:29:22.877119Z",
"shell.execute_reply": "2026-05-19T20:29:22.876245Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"gx_Norm[x] = 0.106896\n"
]
}
],
"source": [
"RooArgSet nset(x);\n",
"cout << \"gx_Norm[x] = \" << gx.getVal(&nset) << endl;"
]
},
{
"cell_type": "markdown",
"id": "3ea72b27",
"metadata": {},
"source": [
"Create object representing integral over gx\n",
"which is used to calculate gx_Norm[x] == gx / gx_Int[x]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "b2de063f",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:22.878688Z",
"iopub.status.busy": "2026-05-19T20:29:22.878545Z",
"iopub.status.idle": "2026-05-19T20:29:23.086282Z",
"shell.execute_reply": "2026-05-19T20:29:23.085695Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"gx_Int[x] = 7.49084\n"
]
}
],
"source": [
"std::unique_ptr igx{gx.createIntegral(x)};\n",
"cout << \"gx_Int[x] = \" << igx->getVal() << endl;"
]
},
{
"cell_type": "markdown",
"id": "9f17935d",
"metadata": {},
"source": [
"Integrate normalized pdf over subrange\n",
"----------------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "db3208cf",
"metadata": {},
"source": [
"Define a range named \"signal\" in x from -5,5"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "71392fc9",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:23.087998Z",
"iopub.status.busy": "2026-05-19T20:29:23.087879Z",
"iopub.status.idle": "2026-05-19T20:29:23.295736Z",
"shell.execute_reply": "2026-05-19T20:29:23.294928Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'signal' created with bounds [-5,5]\n"
]
}
],
"source": [
"x.setRange(\"signal\", -5, 5);"
]
},
{
"cell_type": "markdown",
"id": "a32318c8",
"metadata": {},
"source": [
"Create an integral of gx_Norm[x] over x in range \"signal\"\n",
"This is the fraction of of pdf gx_Norm[x] which is in the\n",
"range named \"signal\""
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "bcec6ec2",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:23.297359Z",
"iopub.status.busy": "2026-05-19T20:29:23.297238Z",
"iopub.status.idle": "2026-05-19T20:29:23.504804Z",
"shell.execute_reply": "2026-05-19T20:29:23.504336Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"gx_Int[x|signal]_Norm[x] = 0.834753\n"
]
}
],
"source": [
"std::unique_ptr igx_sig{gx.createIntegral(x, NormSet(x), Range(\"signal\"))};\n",
"cout << \"gx_Int[x|signal]_Norm[x] = \" << igx_sig->getVal() << endl;"
]
},
{
"cell_type": "markdown",
"id": "ca5ed1e0",
"metadata": {},
"source": [
"Construct cumulative distribution function from pdf\n",
"-----------------------------------------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "cb04497e",
"metadata": {},
"source": [
"Create the cumulative distribution function of gx\n",
"i.e. calculate Int[-10,x] gx(x') dx'"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "c6cea965",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:23.506635Z",
"iopub.status.busy": "2026-05-19T20:29:23.506492Z",
"iopub.status.idle": "2026-05-19T20:29:23.714466Z",
"shell.execute_reply": "2026-05-19T20:29:23.713421Z"
}
},
"outputs": [],
"source": [
"std::unique_ptr gx_cdf{gx.createCdf(x)};"
]
},
{
"cell_type": "markdown",
"id": "849d2bd7",
"metadata": {},
"source": [
"Plot cdf of gx versus x"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "1cd84db9",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:23.716133Z",
"iopub.status.busy": "2026-05-19T20:29:23.716008Z",
"iopub.status.idle": "2026-05-19T20:29:23.923789Z",
"shell.execute_reply": "2026-05-19T20:29:23.922814Z"
}
},
"outputs": [],
"source": [
"RooPlot *frame = x.frame(Title(\"cdf of Gaussian pdf\"));\n",
"gx_cdf->plotOn(frame);"
]
},
{
"cell_type": "markdown",
"id": "15914d74",
"metadata": {},
"source": [
"Draw plot on canvas"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "5aafd62f",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:23.925371Z",
"iopub.status.busy": "2026-05-19T20:29:23.925249Z",
"iopub.status.idle": "2026-05-19T20:29:24.133152Z",
"shell.execute_reply": "2026-05-19T20:29:24.132111Z"
}
},
"outputs": [],
"source": [
"new TCanvas(\"rf110_normintegration\", \"rf110_normintegration\", 600, 600);\n",
"gPad->SetLeftMargin(0.15);\n",
"frame->GetYaxis()->SetTitleOffset(1.6);\n",
"frame->Draw();"
]
},
{
"cell_type": "markdown",
"id": "014ed800",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "b5a506a8",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:24.134779Z",
"iopub.status.busy": "2026-05-19T20:29:24.134654Z",
"iopub.status.idle": "2026-05-19T20:29:24.362317Z",
"shell.execute_reply": "2026-05-19T20:29:24.361423Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"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
}