{ "cells": [ { "cell_type": "markdown", "id": "2f482aae", "metadata": {}, "source": [ "# hist037_TH2Poly_boxes\n", "This tutorial illustrates how to create an histogram with polygonal\n", "bins (TH2Poly). The bins are boxes.\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:12 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "41a64773", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:52.745276Z", "iopub.status.busy": "2026-05-19T20:12:52.745171Z", "iopub.status.idle": "2026-05-19T20:12:53.234493Z", "shell.execute_reply": "2026-05-19T20:12:53.233862Z" } }, "outputs": [], "source": [ "TCanvas *ch2p2 = new TCanvas(\"ch2p2\", \"ch2p2\", 600, 400);\n", "gStyle->SetPalette(57);\n", "TH2Poly *h2p = new TH2Poly();\n", "h2p->SetName(\"Boxes\");\n", "h2p->SetTitle(\"Boxes\");\n", "\n", "Int_t i, j;\n", "Int_t nx = 40;\n", "Int_t ny = 40;\n", "Double_t xval1, yval1, xval2, yval2;\n", "Double_t dx = 0.2, dy = 0.1;\n", "xval1 = 0.;\n", "xval2 = dx;\n", "\n", "for (i = 0; i < nx; i++) {\n", " yval1 = 0.;\n", " yval2 = dy;\n", " for (j = 0; j < ny; j++) {\n", " h2p->AddBin(xval1, yval1, xval2, yval2);\n", " yval1 = yval2;\n", " yval2 = yval2 + yval2 * dy;\n", " }\n", " xval1 = xval2;\n", " xval2 = xval2 + xval2 * dx;\n", "}\n", "\n", "TRandom ran;\n", "for (i = 0; i < 300000; i++) {\n", " h2p->Fill(50 * ran.Gaus(2., 1), ran.Gaus(2., 1));\n", "}\n", "\n", "h2p->Draw(\"COLZ\");" ] }, { "cell_type": "markdown", "id": "4d863dbf", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 2, "id": "e7b6b104", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:53.236663Z", "iopub.status.busy": "2026-05-19T20:12:53.236508Z", "iopub.status.idle": "2026-05-19T20:12:53.543377Z", "shell.execute_reply": "2026-05-19T20:12:53.542318Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "