{
"cells": [
{
"cell_type": "markdown",
"id": "aa108a18",
"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, March 19, 2024 at 07:15 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "cee4f82c",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:11.365030Z",
"iopub.status.busy": "2024-03-19T19:15:11.362931Z",
"iopub.status.idle": "2024-03-19T19:15:11.446746Z",
"shell.execute_reply": "2024-03-19T19:15:11.433878Z"
}
},
"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": "c42afd63",
"metadata": {},
"source": [
"Setup model\n",
"---------------------"
]
},
{
"cell_type": "markdown",
"id": "a759c03f",
"metadata": {},
"source": [
"Create observables x,y"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "763e4404",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:11.459738Z",
"iopub.status.busy": "2024-03-19T19:15:11.459359Z",
"iopub.status.idle": "2024-03-19T19:15:11.977305Z",
"shell.execute_reply": "2024-03-19T19:15:11.976249Z"
}
},
"outputs": [],
"source": [
"RooRealVar x(\"x\", \"x\", -10, 10);"
]
},
{
"cell_type": "markdown",
"id": "7236fd5f",
"metadata": {},
"source": [
"Create pdf gaussx(x,-2,3)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "252b825e",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:11.982798Z",
"iopub.status.busy": "2024-03-19T19:15:11.982464Z",
"iopub.status.idle": "2024-03-19T19:15:12.195929Z",
"shell.execute_reply": "2024-03-19T19:15:12.194726Z"
}
},
"outputs": [],
"source": [
"RooGaussian gx(\"gx\", \"gx\", x, -2.0, 3.0);"
]
},
{
"cell_type": "markdown",
"id": "222c39d9",
"metadata": {},
"source": [
"Retrieve raw & normalized values of RooFit p.d.f.s\n",
"--------------------------------------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "06d70d52",
"metadata": {},
"source": [
"Return 'raw' unnormalized value of gx"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "edc509bd",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:12.201085Z",
"iopub.status.busy": "2024-03-19T19:15:12.200744Z",
"iopub.status.idle": "2024-03-19T19:15:12.426879Z",
"shell.execute_reply": "2024-03-19T19:15:12.425605Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"gx = 0.800737\n"
]
}
],
"source": [
"cout << \"gx = \" << gx.getVal() << endl;"
]
},
{
"cell_type": "markdown",
"id": "9da216c1",
"metadata": {},
"source": [
"Return value of gx normalized over x in range [-10,10]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "fbc7a7e4",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:12.436580Z",
"iopub.status.busy": "2024-03-19T19:15:12.436186Z",
"iopub.status.idle": "2024-03-19T19:15:12.665650Z",
"shell.execute_reply": "2024-03-19T19:15:12.664496Z"
}
},
"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": "7678c31c",
"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": "0b08d6a2",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:12.670316Z",
"iopub.status.busy": "2024-03-19T19:15:12.669917Z",
"iopub.status.idle": "2024-03-19T19:15:13.020870Z",
"shell.execute_reply": "2024-03-19T19:15:13.019856Z"
}
},
"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": "b5848d79",
"metadata": {},
"source": [
"Integrate normalized pdf over subrange\n",
"----------------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "c7bfdfc0",
"metadata": {},
"source": [
"Define a range named \"signal\" in x from -5,5"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "66d5aecd",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:13.031090Z",
"iopub.status.busy": "2024-03-19T19:15:13.030687Z",
"iopub.status.idle": "2024-03-19T19:15:13.245481Z",
"shell.execute_reply": "2024-03-19T19:15:13.244425Z"
}
},
"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": "6617ce2b",
"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": "e6ab54f5",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:13.251918Z",
"iopub.status.busy": "2024-03-19T19:15:13.251561Z",
"iopub.status.idle": "2024-03-19T19:15:13.478360Z",
"shell.execute_reply": "2024-03-19T19:15:13.468459Z"
}
},
"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": "bdef6aca",
"metadata": {},
"source": [
"Construct cumulative distribution function from pdf\n",
"-----------------------------------------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "5a32586e",
"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": "e60a3ceb",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:13.495694Z",
"iopub.status.busy": "2024-03-19T19:15:13.495325Z",
"iopub.status.idle": "2024-03-19T19:15:13.711332Z",
"shell.execute_reply": "2024-03-19T19:15:13.707286Z"
}
},
"outputs": [],
"source": [
"std::unique_ptr gx_cdf{gx.createCdf(x)};"
]
},
{
"cell_type": "markdown",
"id": "1b002937",
"metadata": {},
"source": [
"Plot cdf of gx versus x"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "71f06010",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:13.736547Z",
"iopub.status.busy": "2024-03-19T19:15:13.736156Z",
"iopub.status.idle": "2024-03-19T19:15:13.955760Z",
"shell.execute_reply": "2024-03-19T19:15:13.954779Z"
}
},
"outputs": [],
"source": [
"RooPlot *frame = x.frame(Title(\"cdf of Gaussian pdf\"));\n",
"gx_cdf->plotOn(frame);"
]
},
{
"cell_type": "markdown",
"id": "f948d729",
"metadata": {},
"source": [
"Draw plot on canvas"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "d86af41b",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:13.962029Z",
"iopub.status.busy": "2024-03-19T19:15:13.961418Z",
"iopub.status.idle": "2024-03-19T19:15:14.175064Z",
"shell.execute_reply": "2024-03-19T19:15:14.174013Z"
}
},
"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": "365eb651",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "60630873",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:15:14.185541Z",
"iopub.status.busy": "2024-03-19T19:15:14.184738Z",
"iopub.status.idle": "2024-03-19T19:15:14.610872Z",
"shell.execute_reply": "2024-03-19T19:15:14.609775Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\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
}