{ "cells": [ { "cell_type": "markdown", "id": "f14b7f25", "metadata": {}, "source": [ "# hist014_TH1_cumulative\n", "\n", "\n", "\n", "\n", "**Author:** M. Schiller \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:12 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "a1f7cdd9", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:11.724101Z", "iopub.status.busy": "2026-05-19T20:12:11.723990Z", "iopub.status.idle": "2026-05-19T20:12:12.182338Z", "shell.execute_reply": "2026-05-19T20:12:12.181878Z" } }, "outputs": [], "source": [ "TH1 *h = new TH1D(\"h\", \"h\", 100, -5., 5.);\n", "gRandom->SetSeed();\n", "h->FillRandom(\"gaus\", 1u << 16);" ] }, { "cell_type": "markdown", "id": "1546f2c6", "metadata": {}, "source": [ "get the cumulative of h" ] }, { "cell_type": "code", "execution_count": 2, "id": "6443984d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:12.194373Z", "iopub.status.busy": "2026-05-19T20:12:12.194231Z", "iopub.status.idle": "2026-05-19T20:12:12.398178Z", "shell.execute_reply": "2026-05-19T20:12:12.397762Z" } }, "outputs": [], "source": [ "TH1 *hc = h->GetCumulative();" ] }, { "cell_type": "markdown", "id": "e2942cb4", "metadata": {}, "source": [ "check that c has the \"right\" contents" ] }, { "cell_type": "code", "execution_count": 3, "id": "0039166f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:12.405449Z", "iopub.status.busy": "2026-05-19T20:12:12.405289Z", "iopub.status.idle": "2026-05-19T20:12:12.611936Z", "shell.execute_reply": "2026-05-19T20:12:12.607641Z" } }, "outputs": [], "source": [ "Double_t *integral = h->GetIntegral();\n", "for (Int_t i = 1; i <= hc->GetNbinsX(); ++i) {\n", " assert(std::abs(integral[i] * h->GetEntries() - hc->GetBinContent(i)) < 1e-7);\n", "}" ] }, { "cell_type": "markdown", "id": "832e2649", "metadata": {}, "source": [ "draw histogram together with its cumulative distribution" ] }, { "cell_type": "code", "execution_count": 4, "id": "32b6f066", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:12.645266Z", "iopub.status.busy": "2026-05-19T20:12:12.645106Z", "iopub.status.idle": "2026-05-19T20:12:12.850943Z", "shell.execute_reply": "2026-05-19T20:12:12.850564Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "TCanvas *c = new TCanvas;\n", "c->Divide(1, 2);\n", "c->cd(1);\n", "h->Draw();\n", "c->cd(2);\n", "hc->Draw();\n", "c->Update();" ] }, { "cell_type": "markdown", "id": "255d322d", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 5, "id": "55bca871", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:12.863336Z", "iopub.status.busy": "2026-05-19T20:12:12.863202Z", "iopub.status.idle": "2026-05-19T20:12:13.069015Z", "shell.execute_reply": "2026-05-19T20:12:13.068635Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%jsroot on\n", "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 }