{ "cells": [ { "cell_type": "markdown", "id": "576cd0b3", "metadata": {}, "source": [ "# df016_vecOps\n", "Process collections in RDataFrame with the help of RVec.\n", "\n", "This tutorial shows the potential of the VecOps approach for treating collections\n", "stored in datasets, a situation very common in HEP data analysis.\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": "code", "execution_count": 1, "id": "1c5dd1d6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:45.867566Z", "iopub.status.busy": "2026-05-19T20:09:45.867460Z", "iopub.status.idle": "2026-05-19T20:09:46.183010Z", "shell.execute_reply": "2026-05-19T20:09:46.181297Z" } }, "outputs": [], "source": [ "using namespace ROOT;" ] }, { "cell_type": "markdown", "id": "5513441c", "metadata": {}, "source": [ "We re-create a set of points in a square.\n", "This is a technical detail, just to create a dataset to play with!" ] }, { "cell_type": "code", "execution_count": 2, "id": "2547578f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:46.185239Z", "iopub.status.busy": "2026-05-19T20:09:46.185104Z", "iopub.status.idle": "2026-05-19T20:09:46.813567Z", "shell.execute_reply": "2026-05-19T20:09:46.812970Z" } }, "outputs": [], "source": [ "auto unifGen = [](double) { return gRandom->Uniform(-1.0, 1.0); };\n", "auto vGen = [&](int len) {\n", " RVecD v(len);\n", " std::transform(v.begin(), v.end(), v.begin(), unifGen);\n", " return v;\n", "};\n", "RDataFrame d(1024);\n", "auto d0 = d.Define(\"len\", []() { return (int)gRandom->Uniform(0, 16); })\n", " .Define(\"x\", vGen, {\"len\"})\n", " .Define(\"y\", vGen, {\"len\"});" ] }, { "cell_type": "markdown", "id": "15596183", "metadata": {}, "source": [ "Now we have in our hands d, a RDataFrame with two columns, x and y, which\n", "hold collections of coordinates. The sizes of these collections vary.\n", "Let's now define radii from the x and y coordinates. We'll do it treating\n", "the collections stored in the columns without looping on the individual elements." ] }, { "cell_type": "code", "execution_count": 3, "id": "c355279a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:46.816126Z", "iopub.status.busy": "2026-05-19T20:09:46.815988Z", "iopub.status.idle": "2026-05-19T20:09:47.032610Z", "shell.execute_reply": "2026-05-19T20:09:47.023047Z" } }, "outputs": [], "source": [ "auto d1 = d0.Define(\"r\", \"sqrt(x*x + y*y)\");" ] }, { "cell_type": "markdown", "id": "a6f8491c", "metadata": {}, "source": [ "Now we want to plot 2 quarters of a ring with radii .5 and 1.\n", "Note how the cuts are performed on RVecs, comparing them with integers and\n", "among themselves." ] }, { "cell_type": "code", "execution_count": 4, "id": "4386b24f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:47.048114Z", "iopub.status.busy": "2026-05-19T20:09:47.047944Z", "iopub.status.idle": "2026-05-19T20:09:48.295791Z", "shell.execute_reply": "2026-05-19T20:09:48.284649Z" } }, "outputs": [], "source": [ "auto ring_h = d1.Define(\"rInFig\", \"r > .5 && r < 1 && x*y < 0\")\n", " .Define(\"yFig\", \"y[rInFig]\")\n", " .Define(\"xFig\", \"x[rInFig]\")\n", " .Histo2D({\"fig\", \"Two quarters of a ring\", 64, -1.1, 1.1, 64, -1.1, 1.1}, \"xFig\", \"yFig\");\n", "\n", "auto cring = new TCanvas();\n", "ring_h->DrawCopy(\"Colz\");\n", "\n", "return 0;" ] }, { "cell_type": "markdown", "id": "931ff842", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 5, "id": "9462e14a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:48.305627Z", "iopub.status.busy": "2026-05-19T20:09:48.305477Z", "iopub.status.idle": "2026-05-19T20:09:48.509526Z", "shell.execute_reply": "2026-05-19T20:09:48.508808Z" } }, "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 }