{
"cells": [
{
"cell_type": "markdown",
"id": "fb6a587d",
"metadata": {},
"source": [
"# rf107_plotstyles\n",
"Basic functionality: various plotting styles of data, functions in a RooPlot\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": "ad7034f3",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:03.929602Z",
"iopub.status.busy": "2026-05-19T20:29:03.929496Z",
"iopub.status.idle": "2026-05-19T20:29:03.943176Z",
"shell.execute_reply": "2026-05-19T20:29:03.942742Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"#include \"RooRealVar.h\"\n",
"#include \"RooDataSet.h\"\n",
"#include \"RooGaussian.h\"\n",
"#include \"TCanvas.h\"\n",
"#include \"TAxis.h\"\n",
"#include \"RooPlot.h\"\n",
"using namespace RooFit;"
]
},
{
"cell_type": "markdown",
"id": "93c95428",
"metadata": {},
"source": [
"Setup model\n",
"---------------------"
]
},
{
"cell_type": "markdown",
"id": "04d21d29",
"metadata": {},
"source": [
"Create observables"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "f6be0609",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:03.944435Z",
"iopub.status.busy": "2026-05-19T20:29:03.944322Z",
"iopub.status.idle": "2026-05-19T20:29:04.155881Z",
"shell.execute_reply": "2026-05-19T20:29:04.155297Z"
}
},
"outputs": [],
"source": [
"RooRealVar x(\"x\", \"x\", -10, 10);"
]
},
{
"cell_type": "markdown",
"id": "815b66ae",
"metadata": {},
"source": [
"Create Gaussian"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5cbe771b",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:04.157636Z",
"iopub.status.busy": "2026-05-19T20:29:04.157486Z",
"iopub.status.idle": "2026-05-19T20:29:04.364977Z",
"shell.execute_reply": "2026-05-19T20:29:04.364421Z"
}
},
"outputs": [],
"source": [
"RooRealVar sigma(\"sigma\", \"sigma\", 3, 0.1, 10);\n",
"RooRealVar mean(\"mean\", \"mean\", -3, -10, 10);\n",
"RooGaussian gauss(\"gauss\", \"gauss\", x, mean, sigma);"
]
},
{
"cell_type": "markdown",
"id": "768c4fb0",
"metadata": {},
"source": [
"Generate a sample of 100 events with sigma=3"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e7db0701",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:04.366564Z",
"iopub.status.busy": "2026-05-19T20:29:04.366449Z",
"iopub.status.idle": "2026-05-19T20:29:04.573966Z",
"shell.execute_reply": "2026-05-19T20:29:04.573516Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_51: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{gauss.generate(x, 100)};\n",
" ^\n"
]
}
],
"source": [
"std::unique_ptr data{gauss.generate(x, 100)};"
]
},
{
"cell_type": "markdown",
"id": "4f133229",
"metadata": {},
"source": [
"Fit pdf to data"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "7c3c2377",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:04.575407Z",
"iopub.status.busy": "2026-05-19T20:29:04.575284Z",
"iopub.status.idle": "2026-05-19T20:29:04.783488Z",
"shell.execute_reply": "2026-05-19T20:29:04.783031Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_52:2:15: error: reference to 'data' is ambiguous\n",
" gauss.fitTo(*data, PrintLevel(-1));\n",
" ^\n",
"input_line_51:2:30: note: candidate found by name lookup is 'data'\n",
" std::unique_ptr data{gauss.generate(x, 100)};\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": [
"gauss.fitTo(*data, PrintLevel(-1));"
]
},
{
"cell_type": "markdown",
"id": "33082058",
"metadata": {},
"source": [
"Make plot frames\n",
"-------------------------------"
]
},
{
"cell_type": "markdown",
"id": "a9dd0152",
"metadata": {},
"source": [
"Make four plot frames to demonstrate various plotting features"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "762539a6",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:04.784917Z",
"iopub.status.busy": "2026-05-19T20:29:04.784792Z",
"iopub.status.idle": "2026-05-19T20:29:04.992102Z",
"shell.execute_reply": "2026-05-19T20:29:04.991576Z"
}
},
"outputs": [],
"source": [
"RooPlot *frame1 = x.frame(Name(\"xframe\"), Title(\"Red Curve / SumW2 Histo errors\"), Bins(20));\n",
"RooPlot *frame2 = x.frame(Name(\"xframe\"), Title(\"Dashed Curve / No XError bars\"), Bins(20));\n",
"RooPlot *frame3 = x.frame(Name(\"xframe\"), Title(\"Filled Curve / Blue Histo\"), Bins(20));\n",
"RooPlot *frame4 = x.frame(Name(\"xframe\"), Title(\"Partial Range / Filled Bar chart\"), Bins(20));"
]
},
{
"cell_type": "markdown",
"id": "9f88deb8",
"metadata": {},
"source": [
"Data plotting styles\n",
"---------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "f870cd12",
"metadata": {},
"source": [
"Use sqrt(sum(weights^2)) error instead of Poisson errors"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "c0977230",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:04.994254Z",
"iopub.status.busy": "2026-05-19T20:29:04.994130Z",
"iopub.status.idle": "2026-05-19T20:29:05.202305Z",
"shell.execute_reply": "2026-05-19T20:29:05.201866Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_54:2:2: error: reference to 'data' is ambiguous\n",
" data->plotOn(frame1, DataError(RooAbsData::SumW2));\n",
" ^\n",
"input_line_51:2:30: note: candidate found by name lookup is 'data'\n",
" std::unique_ptr data{gauss.generate(x, 100)};\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": [
"data->plotOn(frame1, DataError(RooAbsData::SumW2));"
]
},
{
"cell_type": "markdown",
"id": "6385f0d6",
"metadata": {},
"source": [
"Remove horizontal error bars"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "ce7c1ff1",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:05.203802Z",
"iopub.status.busy": "2026-05-19T20:29:05.203683Z",
"iopub.status.idle": "2026-05-19T20:29:05.411835Z",
"shell.execute_reply": "2026-05-19T20:29:05.411348Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_55:2:2: error: reference to 'data' is ambiguous\n",
" data->plotOn(frame2, XErrorSize(0));\n",
" ^\n",
"input_line_51:2:30: note: candidate found by name lookup is 'data'\n",
" std::unique_ptr data{gauss.generate(x, 100)};\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": [
"data->plotOn(frame2, XErrorSize(0));"
]
},
{
"cell_type": "markdown",
"id": "7d6185d4",
"metadata": {},
"source": [
"Blue markers and error bors"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "a1ac0396",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:05.413281Z",
"iopub.status.busy": "2026-05-19T20:29:05.413161Z",
"iopub.status.idle": "2026-05-19T20:29:05.621253Z",
"shell.execute_reply": "2026-05-19T20:29:05.620785Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_56:2:2: error: reference to 'data' is ambiguous\n",
" data->plotOn(frame3, MarkerColor(kBlue), LineColor(kBlue));\n",
" ^\n",
"input_line_51:2:30: note: candidate found by name lookup is 'data'\n",
" std::unique_ptr data{gauss.generate(x, 100)};\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": [
"data->plotOn(frame3, MarkerColor(kBlue), LineColor(kBlue));"
]
},
{
"cell_type": "markdown",
"id": "d74245ca",
"metadata": {},
"source": [
"Filled bar chart"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "b4b0fbbd",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:05.622763Z",
"iopub.status.busy": "2026-05-19T20:29:05.622642Z",
"iopub.status.idle": "2026-05-19T20:29:05.830834Z",
"shell.execute_reply": "2026-05-19T20:29:05.830356Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"input_line_57:2:2: error: reference to 'data' is ambiguous\n",
" data->plotOn(frame4, DrawOption(\"B\"), DataError(RooAbsData::None), XErrorSize(0), FillColor(kGray));\n",
" ^\n",
"input_line_51:2:30: note: candidate found by name lookup is 'data'\n",
" std::unique_ptr data{gauss.generate(x, 100)};\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": [
"data->plotOn(frame4, DrawOption(\"B\"), DataError(RooAbsData::None), XErrorSize(0), FillColor(kGray));"
]
},
{
"cell_type": "markdown",
"id": "0d2e6fbb",
"metadata": {},
"source": [
"Function plotting styles\n",
"-----------------------------------------------"
]
},
{
"cell_type": "markdown",
"id": "68d6a6b0",
"metadata": {},
"source": [
"Change line color to red"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "e4e483a8",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:05.832287Z",
"iopub.status.busy": "2026-05-19T20:29:05.832168Z",
"iopub.status.idle": "2026-05-19T20:29:06.039520Z",
"shell.execute_reply": "2026-05-19T20:29:06.038953Z"
}
},
"outputs": [],
"source": [
"gauss.plotOn(frame1, LineColor(kRed));"
]
},
{
"cell_type": "markdown",
"id": "7c24d5ec",
"metadata": {},
"source": [
"Change line style to dashed"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "7b5a239b",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:06.041172Z",
"iopub.status.busy": "2026-05-19T20:29:06.041047Z",
"iopub.status.idle": "2026-05-19T20:29:06.248774Z",
"shell.execute_reply": "2026-05-19T20:29:06.248274Z"
}
},
"outputs": [],
"source": [
"gauss.plotOn(frame2, LineStyle(kDashed));"
]
},
{
"cell_type": "markdown",
"id": "d99bfc71",
"metadata": {},
"source": [
"Filled shapes in green color"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "146b615c",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:06.250542Z",
"iopub.status.busy": "2026-05-19T20:29:06.250421Z",
"iopub.status.idle": "2026-05-19T20:29:06.458121Z",
"shell.execute_reply": "2026-05-19T20:29:06.457472Z"
}
},
"outputs": [],
"source": [
"gauss.plotOn(frame3, DrawOption(\"F\"), FillColor(kOrange), MoveToBack());"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "4c0a0326",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:06.459829Z",
"iopub.status.busy": "2026-05-19T20:29:06.459708Z",
"iopub.status.idle": "2026-05-19T20:29:06.667178Z",
"shell.execute_reply": "2026-05-19T20:29:06.666706Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[#1] INFO:Eval -- RooRealVar::setRange(x) new range named 'plotRange' created with bounds [-8,3]\n"
]
}
],
"source": [
"gauss.plotOn(frame4, Range(-8, 3), LineColor(kMagenta));\n",
"\n",
"TCanvas *c = new TCanvas(\"rf107_plotstyles\", \"rf107_plotstyles\", 800, 800);\n",
"c->Divide(2, 2);\n",
"c->cd(1);\n",
"gPad->SetLeftMargin(0.15);\n",
"frame1->GetYaxis()->SetTitleOffset(1.6);\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();\n",
"c->cd(4);\n",
"gPad->SetLeftMargin(0.15);\n",
"frame4->GetYaxis()->SetTitleOffset(1.6);\n",
"frame4->Draw();"
]
},
{
"cell_type": "markdown",
"id": "5b7e692d",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "be8529ff",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:29:06.680152Z",
"iopub.status.busy": "2026-05-19T20:29:06.680021Z",
"iopub.status.idle": "2026-05-19T20:29:06.907931Z",
"shell.execute_reply": "2026-05-19T20:29:06.907420Z"
}
},
"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
}