{ "cells": [ { "cell_type": "markdown", "id": "5fbd324e", "metadata": {}, "source": [ "# df003_profiles\n", "Use TProfiles with RDataFrame.\n", "\n", "This tutorial illustrates how to use TProfiles in combination with the\n", "RDataFrame. See the documentation of TProfile and TProfile2D to better\n", "understand the analogy of this code with the example one.\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": "0c3cd0b3", "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": "ec3d9aca", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:18.692355Z", "iopub.status.busy": "2026-05-19T20:09:18.692229Z", "iopub.status.idle": "2026-05-19T20:09:19.440760Z", "shell.execute_reply": "2026-05-19T20:09:19.440315Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "void fill_tree(const char *treeName, const char *fileName)\n", "{\n", " ROOT::RDataFrame d(25000);\n", " d.Define(\"px\", []() { return gRandom->Gaus(); })\n", " .Define(\"py\", []() { return gRandom->Gaus(); })\n", " .Define(\"pz\", [](double px, double py) { return sqrt(px * px + py * py); }, {\"px\", \"py\"})\n", " .Snapshot(treeName, fileName);\n", "}" ] }, { "cell_type": "markdown", "id": "d3af14e1", "metadata": {}, "source": [ "We prepare an input tree to run on" ] }, { "cell_type": "code", "execution_count": 2, "id": "cbfea04a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:19.449568Z", "iopub.status.busy": "2026-05-19T20:09:19.449433Z", "iopub.status.idle": "2026-05-19T20:09:20.698294Z", "shell.execute_reply": "2026-05-19T20:09:20.697644Z" } }, "outputs": [], "source": [ "auto fileName = \"df003_profiles.root\";\n", "auto treeName = \"myTree\";\n", "fill_tree(treeName, fileName);" ] }, { "cell_type": "markdown", "id": "94533bed", "metadata": {}, "source": [ "We read the tree from the file and create a RDataFrame." ] }, { "cell_type": "code", "execution_count": 3, "id": "76eef412", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:20.699939Z", "iopub.status.busy": "2026-05-19T20:09:20.699825Z", "iopub.status.idle": "2026-05-19T20:09:20.916418Z", "shell.execute_reply": "2026-05-19T20:09:20.915761Z" } }, "outputs": [], "source": [ "ROOT::RDataFrame d(treeName, fileName);" ] }, { "cell_type": "markdown", "id": "e6af46a1", "metadata": {}, "source": [ "Create the profiles" ] }, { "cell_type": "code", "execution_count": 4, "id": "78de3c4f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:20.919330Z", "iopub.status.busy": "2026-05-19T20:09:20.919215Z", "iopub.status.idle": "2026-05-19T20:09:21.271896Z", "shell.execute_reply": "2026-05-19T20:09:21.267384Z" } }, "outputs": [], "source": [ "auto hprof1d = d.Profile1D({\"hprof1d\", \"Profile of py versus px\", 64, -4, 4}, \"px\", \"py\");\n", "auto hprof2d =\n", " d.Profile2D({\"hprof2d\", \"Profile of pz versus px and py\", 40, -4, 4, 40, -4, 4, 0, 20}, \"px\", \"py\", \"pz\");" ] }, { "cell_type": "markdown", "id": "53e77293", "metadata": {}, "source": [ "And Draw" ] }, { "cell_type": "code", "execution_count": 5, "id": "676839d1", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:21.281358Z", "iopub.status.busy": "2026-05-19T20:09:21.281221Z", "iopub.status.idle": "2026-05-19T20:09:22.399614Z", "shell.execute_reply": "2026-05-19T20:09:22.399236Z" } }, "outputs": [], "source": [ "auto c1 = new TCanvas(\"c1\", \"Profile histogram example\", 200, 10, 700, 500);\n", "hprof1d->DrawClone();\n", "auto c2 = new TCanvas(\"c2\", \"Profile2D histogram example\", 200, 10, 700, 500);\n", "hprof2d->DrawClone(\"BOX\");" ] }, { "cell_type": "markdown", "id": "f24c8ec8", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 6, "id": "8311607a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:09:22.419361Z", "iopub.status.busy": "2026-05-19T20:09:22.419221Z", "iopub.status.idle": "2026-05-19T20:09:22.621507Z", "shell.execute_reply": "2026-05-19T20:09:22.621149Z" } }, "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" } ], "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 }