{ "cells": [ { "cell_type": "markdown", "id": "9b7c69ed", "metadata": {}, "source": [ "# df031_Stats\n", "Use the Stats action to extract the statistics of a column.\n", "\n", "Extract the statistics relative to RDataFrame columns and store them\n", "in TStatistic instances.\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:10 PM." ] }, { "cell_type": "markdown", "id": "d3933bd1", "metadata": {}, "source": [ "Create a data frame and add two columns: one for the values and one for the weight." ] }, { "cell_type": "code", "execution_count": 1, "id": "10330357", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:10:07.056562Z", "iopub.status.busy": "2026-05-19T20:10:07.056442Z", "iopub.status.idle": "2026-05-19T20:10:07.840019Z", "shell.execute_reply": "2026-05-19T20:10:07.839316Z" } }, "outputs": [], "source": [ "ROOT::RDataFrame r(256);\n", "auto rr = r.Define(\"v\", [](ULong64_t e){return e;}, {\"rdfentry_\"})\n", " .Define(\"w\", [](ULong64_t e){return 1./(e+1);}, {\"v\"});" ] }, { "cell_type": "markdown", "id": "c9fadc4f", "metadata": {}, "source": [ "Now extract the statistics, weighted, unweighted - with and without explicit types." ] }, { "cell_type": "code", "execution_count": 2, "id": "4980899f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:10:07.845332Z", "iopub.status.busy": "2026-05-19T20:10:07.845203Z", "iopub.status.idle": "2026-05-19T20:10:09.121854Z", "shell.execute_reply": "2026-05-19T20:10:09.121338Z" } }, "outputs": [], "source": [ "auto stats_eu = rr.Stats(\"v\");\n", "auto stats_ew = rr.Stats(\"v\", \"w\");\n", "auto stats_iu = rr.Stats(\"v\");\n", "auto stats_iw = rr.Stats(\"v\", \"w\");" ] }, { "cell_type": "markdown", "id": "26acd488", "metadata": {}, "source": [ "Now print them: they are all identical of course!" ] }, { "cell_type": "code", "execution_count": 3, "id": "8d74f09c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:10:09.123758Z", "iopub.status.busy": "2026-05-19T20:10:09.123632Z", "iopub.status.idle": "2026-05-19T20:10:09.725637Z", "shell.execute_reply": "2026-05-19T20:10:09.725290Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " OBJ: TStatistic\t \t Mean = 127.5 +- 4.628 \t RMS = 74.045 \t Count = 256 \t Min = 0 \t Max = 255\n", " OBJ: TStatistic\t \t Mean = 40.8 +- 12.86 \t RMS = 60.318 \t Count = 256 \t Min = 0 \t Max = 255\n", " OBJ: TStatistic\t \t Mean = 127.5 +- 4.628 \t RMS = 74.045 \t Count = 256 \t Min = 0 \t Max = 255\n", " OBJ: TStatistic\t \t Mean = 40.8 +- 12.86 \t RMS = 60.318 \t Count = 256 \t Min = 0 \t Max = 255\n" ] } ], "source": [ "stats_eu->Print();\n", "stats_ew->Print();\n", "stats_iu->Print();\n", "stats_iw->Print();" ] }, { "cell_type": "markdown", "id": "770b625f", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 4, "id": "86bc4262", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:10:09.732484Z", "iopub.status.busy": "2026-05-19T20:10:09.732355Z", "iopub.status.idle": "2026-05-19T20:10:09.935894Z", "shell.execute_reply": "2026-05-19T20:10:09.934733Z" } }, "outputs": [], "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 }