{ "cells": [ { "cell_type": "markdown", "id": "4b6735d3", "metadata": {}, "source": [ "# hsumanim\n", "This script is a slightly modified version of hsum.C.\n", "\n", "Uncomment the two `c1->Print(...);` lines in order to produce\n", "an animated gif file. The option \"++\" makes an infinite animation.\n", "The animated file `hsumanim.gif` can be visualized within a web browser\n", "\n", "\n", "\n", "\n", "**Author:** Rene Brun, Valeriy Onuchin \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:38 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "ed6418d1", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:38.108783Z", "iopub.status.busy": "2026-05-19T20:38:38.108660Z", "iopub.status.idle": "2026-05-19T20:38:38.452057Z", "shell.execute_reply": "2026-05-19T20:38:38.451303Z" } }, "outputs": [], "source": [ "auto c1 = new TCanvas(\"c1\", \"The HSUM example\", 200, 10, 600, 400);\n", "c1->SetGrid();\n", "\n", "gBenchmark->Start(\"hsum\");" ] }, { "cell_type": "markdown", "id": "d1649af3", "metadata": {}, "source": [ "Create some histograms." ] }, { "cell_type": "code", "execution_count": 2, "id": "0e6e1df4", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:38.453990Z", "iopub.status.busy": "2026-05-19T20:38:38.453868Z", "iopub.status.idle": "2026-05-19T20:38:38.661765Z", "shell.execute_reply": "2026-05-19T20:38:38.661175Z" } }, "outputs": [], "source": [ "auto total = new TH1F(\"total\", \"This is the total distribution\", 100, -4, 4);\n", "auto main = new TH1F(\"main\", \"Main contributor\", 100, -4, 4);\n", "auto s1 = new TH1F(\"s1\", \"This is the first signal\", 100, -4, 4);\n", "auto s2 = new TH1F(\"s2\", \"This is the second signal\", 100, -4, 4);\n", "total->Sumw2(); // this makes sure that the sum of squares of weights will be stored\n", "total->SetMarkerStyle(21);\n", "total->SetMarkerSize(0.7);\n", "main->SetFillColor(16);\n", "s1->SetFillColor(42);\n", "s2->SetFillColor(46);\n", "TSlider *slider = 0;\n", "gSystem->Unlink(\"hsumanim.gif\"); // delete old file" ] }, { "cell_type": "markdown", "id": "eaac65ae", "metadata": {}, "source": [ "Fill histograms randomly" ] }, { "cell_type": "code", "execution_count": 3, "id": "d252dc1e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:38.663801Z", "iopub.status.busy": "2026-05-19T20:38:38.663668Z", "iopub.status.idle": "2026-05-19T20:38:38.875917Z", "shell.execute_reply": "2026-05-19T20:38:38.875388Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "i = 500\n", "i = 1000\n", "i = 1500\n", "i = 2000\n", "i = 2500\n", "i = 3000\n", "i = 3500\n", "i = 4000\n", "i = 4500\n", "i = 5000\n", "i = 5500\n", "i = 6000\n", "i = 6500\n", "i = 7000\n", "i = 7500\n", "i = 8000\n", "i = 8500\n", "i = 9000\n", "i = 9500\n" ] } ], "source": [ "gRandom->SetSeed();\n", "const Int_t kUPDATE = 500;\n", "Float_t xs1, xs2, xmain;\n", "Int_t gifcnt = 0;\n", "for (Int_t i = 0; i < 10000; i++) {\n", " xmain = gRandom->Gaus(-1, 1.5);\n", " xs1 = gRandom->Gaus(-0.5, 0.5);\n", " xs2 = gRandom->Landau(1, 0.15);\n", " main->Fill(xmain);\n", " s1->Fill(xs1, 0.3);\n", " s2->Fill(xs2, 0.2);\n", " total->Fill(xmain);\n", " total->Fill(xs1, 0.3);\n", " total->Fill(xs2, 0.2);\n", " if (i && (i % kUPDATE) == 0) {\n", " if (i == kUPDATE) {\n", " total->Draw(\"e1p\");\n", " main->Draw(\"same\");\n", " s1->Draw(\"same\");\n", " s2->Draw(\"same\");\n", " c1->Update();\n", " slider = new TSlider(\"slider\", \"test\", 4.2, 0, 4.6, total->GetMaximum(), 38);\n", " slider->SetFillColor(46);\n", " }\n", " if (slider)\n", " slider->SetRange(0, Float_t(i) / 10000.);\n", " c1->Modified();\n", " c1->Update();\n", " if (gROOT->IsBatch()) {\n", " // c1->Print(\"hsumanim.gif+\");\n", " printf(\"i = %d\\n\", i);\n", " } else {\n", " if (gSystem->ProcessEvents())\n", " break;\n", " }\n", " }\n", "}\n", "slider->SetRange(0, 1);\n", "total->Draw(\"sameaxis\"); // to redraw axis hidden by the fill area\n", "c1->Modified();" ] }, { "cell_type": "markdown", "id": "681f4bc2", "metadata": {}, "source": [ "c1->Print(\"hsumanim.gif++\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "99601cbf", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:38.877404Z", "iopub.status.busy": "2026-05-19T20:38:38.877284Z", "iopub.status.idle": "2026-05-19T20:38:39.085054Z", "shell.execute_reply": "2026-05-19T20:38:39.084593Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hsum : Real Time = 0.68 seconds Cpu Time = 0.39 seconds\n" ] } ], "source": [ "gBenchmark->Show(\"hsum\");" ] }, { "cell_type": "markdown", "id": "1d8a8363", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 5, "id": "28c0d446", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:39.086578Z", "iopub.status.busy": "2026-05-19T20:38:39.086460Z", "iopub.status.idle": "2026-05-19T20:38:39.298619Z", "shell.execute_reply": "2026-05-19T20:38:39.297979Z" } }, "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 }