{ "cells": [ { "cell_type": "markdown", "id": "856f9c1c", "metadata": {}, "source": [ "# hist060_TH1_stats\n", "\n", "This example shows:\n", " - how to remove a stat element from the stat box\n", " - how to add a new one\n", "\n", "\n", "\n", "\n", "**Author:** Olivier Couet \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:13 PM." ] }, { "cell_type": "markdown", "id": "86ba6e28", "metadata": {}, "source": [ "Create and plot a test histogram with stats" ] }, { "cell_type": "code", "execution_count": 1, "id": "ca6923d3", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:13:09.498458Z", "iopub.status.busy": "2026-05-19T20:13:09.498346Z", "iopub.status.idle": "2026-05-19T20:13:10.131598Z", "shell.execute_reply": "2026-05-19T20:13:10.130847Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "TCanvas *se = new TCanvas;\n", "TH1F *h = new TH1F(\"h\", \"test\", 100, -3, 3);\n", "h->FillRandom(\"gaus\", 3000);\n", "gStyle->SetOptStat();\n", "h->Draw();\n", "se->Update();" ] }, { "cell_type": "markdown", "id": "02fd82f2", "metadata": {}, "source": [ "Retrieve the stat box" ] }, { "cell_type": "code", "execution_count": 2, "id": "071d0620", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:13:10.133770Z", "iopub.status.busy": "2026-05-19T20:13:10.133633Z", "iopub.status.idle": "2026-05-19T20:13:10.338377Z", "shell.execute_reply": "2026-05-19T20:13:10.337527Z" } }, "outputs": [], "source": [ "TPaveStats *ps = (TPaveStats *)se->GetPrimitive(\"stats\");\n", "ps->SetName(\"mystats\");\n", "TList *listOfLines = ps->GetListOfLines();" ] }, { "cell_type": "markdown", "id": "a00335b6", "metadata": {}, "source": [ "Remove the RMS line" ] }, { "cell_type": "code", "execution_count": 3, "id": "b0aed3b2", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:13:10.340574Z", "iopub.status.busy": "2026-05-19T20:13:10.340455Z", "iopub.status.idle": "2026-05-19T20:13:10.544997Z", "shell.execute_reply": "2026-05-19T20:13:10.544287Z" } }, "outputs": [], "source": [ "TText *tconst = ps->GetLineWith(\"RMS\");\n", "listOfLines->Remove(tconst);" ] }, { "cell_type": "markdown", "id": "1476327c", "metadata": {}, "source": [ "Add a new line in the stat box.\n", "Note that \"=\" is a control character" ] }, { "cell_type": "code", "execution_count": 4, "id": "0297c65f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:13:10.547238Z", "iopub.status.busy": "2026-05-19T20:13:10.547114Z", "iopub.status.idle": "2026-05-19T20:13:10.751628Z", "shell.execute_reply": "2026-05-19T20:13:10.750875Z" } }, "outputs": [], "source": [ "TLatex *myt = new TLatex(0, 0, \"Test = 10\");\n", "myt->SetTextFont(42);\n", "myt->SetTextSize(0.04);\n", "myt->SetTextColor(kRed);\n", "listOfLines->Add(myt);" ] }, { "cell_type": "markdown", "id": "88a3a3ba", "metadata": {}, "source": [ "the following line is needed to avoid that the automatic redrawing of stats" ] }, { "cell_type": "code", "execution_count": 5, "id": "9f52032f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:13:10.753911Z", "iopub.status.busy": "2026-05-19T20:13:10.753783Z", "iopub.status.idle": "2026-05-19T20:13:10.959292Z", "shell.execute_reply": "2026-05-19T20:13:10.958621Z" } }, "outputs": [], "source": [ "h->SetStats(0);\n", "\n", "se->Modified();" ] }, { "cell_type": "markdown", "id": "4e48e148", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 6, "id": "2f9cc310", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:13:10.970338Z", "iopub.status.busy": "2026-05-19T20:13:10.970198Z", "iopub.status.idle": "2026-05-19T20:13:11.181041Z", "shell.execute_reply": "2026-05-19T20:13:11.180428Z" } }, "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 }