{
"cells": [
{
"cell_type": "markdown",
"id": "6c043ea9",
"metadata": {},
"source": [
"# df005_fillAnyObject\n",
"Using the generic Fill action.\n",
"\n",
"This tutorial shows how to fill any object the class of which exposes a\n",
"`Fill` method.\n",
"\n",
"\n",
"\n",
"\n",
"**Author:** Danilo Piparo (CERN) \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:09 PM."
]
},
{
"cell_type": "markdown",
"id": "8e9d68d3",
"metadata": {},
"source": [
" A simple helper function to fill a test tree: this makes the example\n",
"stand-alone.\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "498d1611",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:09:27.885529Z",
"iopub.status.busy": "2026-05-19T20:09:27.885414Z",
"iopub.status.idle": "2026-05-19T20:09:28.557830Z",
"shell.execute_reply": "2026-05-19T20:09:28.557204Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"void fill_tree(const char *treeName, const char *fileName)\n",
"{\n",
" ROOT::RDataFrame d(100);\n",
" auto i = 0.;\n",
" d.Define(\"b1\", [&i]() { return i; })\n",
" .Define(\"b2\",\n",
" [&i]() {\n",
" float j = i * i;\n",
" ++i;\n",
" return j;\n",
" })\n",
" .Snapshot(treeName, fileName);\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "c6cf8d03",
"metadata": {},
"source": [
"We prepare an input tree to run on"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "b9d6db8b",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:09:28.560800Z",
"iopub.status.busy": "2026-05-19T20:09:28.560654Z",
"iopub.status.idle": "2026-05-19T20:09:29.729829Z",
"shell.execute_reply": "2026-05-19T20:09:29.729254Z"
}
},
"outputs": [],
"source": [
"auto fileName = \"df005_fillAnyObject.root\";\n",
"auto treeName = \"myTree\";\n",
"fill_tree(treeName, fileName);"
]
},
{
"cell_type": "markdown",
"id": "6ff35384",
"metadata": {},
"source": [
"We read the tree from the file and create a RDataFrame."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "1707c239",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:09:29.734536Z",
"iopub.status.busy": "2026-05-19T20:09:29.734416Z",
"iopub.status.idle": "2026-05-19T20:09:29.937016Z",
"shell.execute_reply": "2026-05-19T20:09:29.936485Z"
}
},
"outputs": [],
"source": [
"ROOT::RDataFrame d(treeName, fileName);"
]
},
{
"cell_type": "markdown",
"id": "baba259f",
"metadata": {},
"source": [
"## Filling any object\n",
"We now fill some objects which are instances of classes which expose a\n",
"`Fill` method with some input arguments."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "c44ee3f8",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:09:29.939245Z",
"iopub.status.busy": "2026-05-19T20:09:29.939127Z",
"iopub.status.idle": "2026-05-19T20:09:31.508377Z",
"shell.execute_reply": "2026-05-19T20:09:31.507820Z"
}
},
"outputs": [],
"source": [
"auto th1d = d.Fill(TH1D(\"th1d\", \"th1d\", 64, 0, 128), {\"b1\"});\n",
"auto th1i = d.Fill(TH1I(\"th1i\", \"th1i\", 64, 0, 128), {\"b2\"});\n",
"auto th2d = d.Fill(TH2D(\"th2d\", \"th2d\", 64, 0, 128, 64, 0, 1024), {\"b1\", \"b2\"});\n",
"\n",
"auto c1 = new TCanvas();\n",
"th1d->DrawClone();\n",
"\n",
"auto c2 = new TCanvas();\n",
"th1i->DrawClone();\n",
"\n",
"auto c3 = new TCanvas();\n",
"th2d->DrawClone(\"COLZ\");\n",
"\n",
"return 0;"
]
},
{
"cell_type": "markdown",
"id": "7e364b59",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "ff909f57",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:09:31.520116Z",
"iopub.status.busy": "2026-05-19T20:09:31.519949Z",
"iopub.status.idle": "2026-05-19T20:09:31.736002Z",
"shell.execute_reply": "2026-05-19T20:09:31.735457Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"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
}