{ "cells": [ { "cell_type": "markdown", "id": "f2e2bea7", "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 Sunday, December 21, 2025 at 02:39 PM." ] }, { "cell_type": "markdown", "id": "a315792a", "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": "4d35d0bf", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-21T13:39:18.743881Z", "iopub.status.busy": "2025-12-21T13:39:18.743724Z", "iopub.status.idle": "2025-12-21T13:39:19.457602Z", "shell.execute_reply": "2025-12-21T13:39:19.452990Z" } }, "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": "84fc1ab5", "metadata": {}, "source": [ "We prepare an input tree to run on" ] }, { "cell_type": "code", "execution_count": 2, "id": "d5cbadad", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-21T13:39:19.470012Z", "iopub.status.busy": "2025-12-21T13:39:19.469828Z", "iopub.status.idle": "2025-12-21T13:39:20.729669Z", "shell.execute_reply": "2025-12-21T13:39:20.725428Z" } }, "outputs": [], "source": [ "auto fileName = \"df005_fillAnyObject.root\";\n", "auto treeName = \"myTree\";\n", "fill_tree(treeName, fileName);" ] }, { "cell_type": "markdown", "id": "a77e22ba", "metadata": {}, "source": [ "We read the tree from the file and create a RDataFrame." ] }, { "cell_type": "code", "execution_count": 3, "id": "bb4dc7fb", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-21T13:39:20.736743Z", "iopub.status.busy": "2025-12-21T13:39:20.736601Z", "iopub.status.idle": "2025-12-21T13:39:20.943814Z", "shell.execute_reply": "2025-12-21T13:39:20.943239Z" } }, "outputs": [], "source": [ "ROOT::RDataFrame d(treeName, fileName);" ] }, { "cell_type": "markdown", "id": "d01bf9ce", "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": "b05ccc0a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-21T13:39:20.945987Z", "iopub.status.busy": "2025-12-21T13:39:20.945851Z", "iopub.status.idle": "2025-12-21T13:39:22.662442Z", "shell.execute_reply": "2025-12-21T13:39:22.661846Z" } }, "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": "650288f5", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 5, "id": "06b30034", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-21T13:39:22.666799Z", "iopub.status.busy": "2025-12-21T13:39:22.666657Z", "iopub.status.idle": "2025-12-21T13:39:22.886780Z", "shell.execute_reply": "2025-12-21T13:39:22.886157Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\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 }