{ "cells": [ { "cell_type": "markdown", "id": "75c20094", "metadata": {}, "source": [ "# hist020_TH2_draw\n", "\n", "\n", "\n", "\n", "**Author:** Rene Brun \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": "0da68d50", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:21.840383Z", "iopub.status.busy": "2026-05-19T20:12:21.840269Z", "iopub.status.idle": "2026-05-19T20:12:22.149876Z", "shell.execute_reply": "2026-05-19T20:12:22.149145Z" } }, "outputs": [], "source": [ "gStyle->SetOptStat(0);\n", "gStyle->SetCanvasColor(33);\n", "gStyle->SetFrameFillColor(18);\n", "TF2 *f2 = new TF2(\"f2\", \"xygaus + xygaus(5) + xylandau(10)\", -4, 4, -4, 4);\n", "Double_t params[] = {130, -1.4, 1.8, 1.5, 1, 150, 2, 0.5, -2, 0.5, 3600, -2, 0.7, -3, 0.3};\n", "f2->SetParameters(params);\n", "auto h2 = new TH2F(\"h2\", \"xygaus + xygaus(5) + xylandau(10)\", 20, -4, 4, 20, -4, 4);\n", "h2->SetFillColor(46);\n", "h2->FillRandom(\"f2\", 40000);\n", "TPaveLabel pl;" ] }, { "cell_type": "markdown", "id": "7a55a8c3", "metadata": {}, "source": [ "basic 2-d options" ] }, { "cell_type": "code", "execution_count": 2, "id": "2e16849c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:22.151896Z", "iopub.status.busy": "2026-05-19T20:12:22.151685Z", "iopub.status.idle": "2026-05-19T20:12:22.378109Z", "shell.execute_reply": "2026-05-19T20:12:22.370087Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Float_t xMin = 0.67, yMin = 0.875, xMax = 0.85, yMax = 0.95;\n", "Int_t cancolor = 17;\n", "auto c2h = new TCanvas(\"c2h\", \"2-d options\", 10, 10, 800, 600);\n", "c2h->Divide(2, 2);\n", "c2h->SetFillColor(cancolor);\n", "c2h->cd(1);\n", "h2->Draw();\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"SCAT\", \"brNDC\");\n", "c2h->cd(2);\n", "h2->Draw(\"box\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"BOX\", \"brNDC\");\n", "c2h->cd(3);\n", "h2->Draw(\"arr\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"ARR\", \"brNDC\");\n", "c2h->cd(4);\n", "h2->Draw(\"colz\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"COLZ\", \"brNDC\");\n", "c2h->Update();" ] }, { "cell_type": "markdown", "id": "1c892324", "metadata": {}, "source": [ "text option" ] }, { "cell_type": "code", "execution_count": 3, "id": "89737996", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:22.379791Z", "iopub.status.busy": "2026-05-19T20:12:22.379657Z", "iopub.status.idle": "2026-05-19T20:12:22.583801Z", "shell.execute_reply": "2026-05-19T20:12:22.583159Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "auto ctext = new TCanvas(\"ctext\", \"text option\", 50, 50, 800, 600);\n", "gPad->SetGrid();\n", "ctext->SetFillColor(cancolor);\n", "ctext->SetGrid();\n", "h2->Draw(\"text\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"TEXT\", \"brNDC\");\n", "ctext->Update();" ] }, { "cell_type": "markdown", "id": "520eb6ad", "metadata": {}, "source": [ "contour options" ] }, { "cell_type": "code", "execution_count": 4, "id": "907dfa56", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:22.585635Z", "iopub.status.busy": "2026-05-19T20:12:22.585499Z", "iopub.status.idle": "2026-05-19T20:12:22.790142Z", "shell.execute_reply": "2026-05-19T20:12:22.789012Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "auto cont = new TCanvas(\"contours\", \"contours\", 100, 100, 800, 600);\n", "cont->Divide(2, 2);\n", "gPad->SetGrid();\n", "cont->SetFillColor(cancolor);\n", "cont->cd(1);\n", "h2->Draw(\"contz\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"CONTZ\", \"brNDC\");\n", "cont->cd(2);\n", "gPad->SetGrid();\n", "h2->Draw(\"cont1\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"CONT1\", \"brNDC\");\n", "cont->cd(3);\n", "gPad->SetGrid();\n", "h2->Draw(\"cont2\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"CONT2\", \"brNDC\");\n", "cont->cd(4);\n", "gPad->SetGrid();\n", "h2->Draw(\"cont3\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"CONT3\", \"brNDC\");\n", "cont->Update();" ] }, { "cell_type": "markdown", "id": "ee46288e", "metadata": {}, "source": [ "lego options" ] }, { "cell_type": "code", "execution_count": 5, "id": "a868e9ba", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:22.791847Z", "iopub.status.busy": "2026-05-19T20:12:22.791727Z", "iopub.status.idle": "2026-05-19T20:12:22.999281Z", "shell.execute_reply": "2026-05-19T20:12:22.998675Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "auto lego = new TCanvas(\"lego\", \"lego options\", 150, 150, 800, 600);\n", "lego->Divide(2, 2);\n", "lego->SetFillColor(cancolor);\n", "lego->cd(1);\n", "h2->Draw(\"lego\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"LEGO\", \"brNDC\");\n", "lego->cd(2);\n", "h2->Draw(\"lego1\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"LEGO1\", \"brNDC\");\n", "lego->cd(3);\n", "gPad->SetTheta(61);\n", "gPad->SetPhi(-82);\n", "h2->Draw(\"surf1pol\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax + 0.05, yMax, \"SURF1POL\", \"brNDC\");\n", "lego->cd(4);\n", "gPad->SetTheta(21);\n", "gPad->SetPhi(-90);\n", "h2->Draw(\"surf1cyl\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax + 0.05, yMax, \"SURF1CYL\", \"brNDC\");\n", "lego->Update();" ] }, { "cell_type": "markdown", "id": "c203b15d", "metadata": {}, "source": [ "surface options" ] }, { "cell_type": "code", "execution_count": 6, "id": "8a9ac696", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:23.001652Z", "iopub.status.busy": "2026-05-19T20:12:23.001508Z", "iopub.status.idle": "2026-05-19T20:12:23.205512Z", "shell.execute_reply": "2026-05-19T20:12:23.204896Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "auto surf = new TCanvas(\"surfopt\", \"surface options\", 200, 200, 800, 600);\n", "surf->Divide(2, 2);\n", "surf->SetFillColor(cancolor);\n", "surf->cd(1);\n", "h2->Draw(\"surf1\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"SURF1\", \"brNDC\");\n", "surf->cd(2);\n", "h2->Draw(\"surf2z\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"SURF2Z\", \"brNDC\");\n", "surf->cd(3);\n", "h2->Draw(\"surf3\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"SURF3\", \"brNDC\");\n", "surf->cd(4);\n", "h2->Draw(\"surf4\");\n", "pl.DrawPaveLabel(xMin, yMin, xMax, yMax, \"SURF4\", \"brNDC\");\n", "surf->Update();" ] }, { "cell_type": "markdown", "id": "bfab56db", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 7, "id": "04a4c070", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:23.207699Z", "iopub.status.busy": "2026-05-19T20:12:23.207555Z", "iopub.status.idle": "2026-05-19T20:12:23.411662Z", "shell.execute_reply": "2026-05-19T20:12:23.410978Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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 }