{ "cells": [ { "cell_type": "markdown", "id": "674c8c9b", "metadata": {}, "source": [ "# df000_simple\n", "Simple RDataFrame example in C++.\n", "\n", "This tutorial shows a minimal example of RDataFrame. It starts without input\n", "data, generates a new column `x` with random numbers, and finally draws\n", "a histogram for `x`.\n", "\n", "\n", "\n", "\n", "**Author:** Enric Tejedor (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": "32b66416", "metadata": {}, "source": [ "Create a data frame with 100 rows" ] }, { "cell_type": "code", "execution_count": 1, "id": "99ac5161", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:18.592775Z", "iopub.status.busy": "2026-05-19T20:09:18.592664Z", "iopub.status.idle": "2026-05-19T20:09:18.939913Z", "shell.execute_reply": "2026-05-19T20:09:18.939365Z" } }, "outputs": [], "source": [ "ROOT::RDataFrame rdf(100);" ] }, { "cell_type": "markdown", "id": "52372a60", "metadata": {}, "source": [ "Define a new column `x` that contains random numbers" ] }, { "cell_type": "code", "execution_count": 2, "id": "660909c4", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:18.945818Z", "iopub.status.busy": "2026-05-19T20:09:18.945679Z", "iopub.status.idle": "2026-05-19T20:09:19.450690Z", "shell.execute_reply": "2026-05-19T20:09:19.436672Z" } }, "outputs": [], "source": [ "auto rdf_x = rdf.Define(\"x\", [](){ return gRandom->Rndm(); });" ] }, { "cell_type": "markdown", "id": "9a79576f", "metadata": {}, "source": [ "Create a histogram from `x`" ] }, { "cell_type": "code", "execution_count": 3, "id": "7d96d5e4", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:19.463368Z", "iopub.status.busy": "2026-05-19T20:09:19.463217Z", "iopub.status.idle": "2026-05-19T20:09:19.820074Z", "shell.execute_reply": "2026-05-19T20:09:19.819655Z" } }, "outputs": [], "source": [ "auto h = rdf_x.Histo1D(\"x\");" ] }, { "cell_type": "markdown", "id": "462250bc", "metadata": {}, "source": [ "At the end of this function, the histogram pointed to by `h` will be deleted.\n", "Draw a copy of the histogram object instead:" ] }, { "cell_type": "code", "execution_count": 4, "id": "60250783", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:19.831019Z", "iopub.status.busy": "2026-05-19T20:09:19.830889Z", "iopub.status.idle": "2026-05-19T20:09:21.027133Z", "shell.execute_reply": "2026-05-19T20:09:21.026806Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Info in : created default TCanvas with name c1\n" ] } ], "source": [ "h->DrawClone();" ] }, { "cell_type": "markdown", "id": "1e94ea89", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 5, "id": "4e11730b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:21.035278Z", "iopub.status.busy": "2026-05-19T20:09:21.035155Z", "iopub.status.idle": "2026-05-19T20:09:21.237386Z", "shell.execute_reply": "2026-05-19T20:09:21.237064Z" } }, "outputs": [ { "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 }