{ "cells": [ { "cell_type": "markdown", "id": "48cf4beb", "metadata": {}, "source": [ "# hist010_TH1_two_scales\n", "with different scales in the \"same\" pad.\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": "f586032c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:05.885560Z", "iopub.status.busy": "2026-05-19T20:12:05.885453Z", "iopub.status.idle": "2026-05-19T20:12:06.224814Z", "shell.execute_reply": "2026-05-19T20:12:06.224274Z" } }, "outputs": [], "source": [ "TCanvas *c1 = new TCanvas(\"c1\", \"hists with different scales\", 600, 400);" ] }, { "cell_type": "markdown", "id": "64df84fe", "metadata": {}, "source": [ "create/fill draw h1" ] }, { "cell_type": "code", "execution_count": 2, "id": "f267881f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:06.226453Z", "iopub.status.busy": "2026-05-19T20:12:06.226318Z", "iopub.status.idle": "2026-05-19T20:12:06.559170Z", "shell.execute_reply": "2026-05-19T20:12:06.558677Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gStyle->SetOptStat(kFALSE);\n", "TH1D *h1 = new TH1D(\"h1\", \"my histogram\", 100, -3, 3);\n", "TRandom3 rng;\n", "for (int i = 0; i < 10000; i++)\n", " h1->Fill(rng.Gaus(0, 1));\n", "h1->Draw();\n", "c1->Update();" ] }, { "cell_type": "markdown", "id": "348fa85b", "metadata": {}, "source": [ "create hint1 filled with the bins integral of h1" ] }, { "cell_type": "code", "execution_count": 3, "id": "8061b7bb", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:06.560755Z", "iopub.status.busy": "2026-05-19T20:12:06.560632Z", "iopub.status.idle": "2026-05-19T20:12:06.762695Z", "shell.execute_reply": "2026-05-19T20:12:06.762096Z" } }, "outputs": [], "source": [ "TH1D *hint1 = new TH1D(\"hint1\", \"h1 bins integral\", 100, -3, 3);\n", "double sum = 0;\n", "for (int i = 1; i <= 100; i++) {\n", " sum += h1->GetBinContent(i);\n", " hint1->SetBinContent(i, sum);\n", "}" ] }, { "cell_type": "markdown", "id": "bf1bd7a8", "metadata": {}, "source": [ "scale hint1 to the pad coordinates" ] }, { "cell_type": "code", "execution_count": 4, "id": "f16b6824", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:06.764445Z", "iopub.status.busy": "2026-05-19T20:12:06.764258Z", "iopub.status.idle": "2026-05-19T20:12:06.967299Z", "shell.execute_reply": "2026-05-19T20:12:06.966857Z" } }, "outputs": [], "source": [ "double rightmax = 1.1 * hint1->GetMaximum();\n", "double scale = gPad->GetUymax() / rightmax;\n", "hint1->SetLineColor(kRed);\n", "hint1->Scale(scale);\n", "hint1->Draw(\"same\");" ] }, { "cell_type": "markdown", "id": "3dce5b98", "metadata": {}, "source": [ "draw an axis on the right side" ] }, { "cell_type": "code", "execution_count": 5, "id": "74c6fda5", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:06.970453Z", "iopub.status.busy": "2026-05-19T20:12:06.970330Z", "iopub.status.idle": "2026-05-19T20:12:07.189409Z", "shell.execute_reply": "2026-05-19T20:12:07.188763Z" } }, "outputs": [], "source": [ "TGaxis *axis =\n", " new TGaxis(gPad->GetUxmax(), gPad->GetUymin(), gPad->GetUxmax(), gPad->GetUymax(), 0, rightmax, 510, \"+L\");\n", "axis->SetLineColor(kRed);\n", "axis->SetLabelColor(kRed);\n", "axis->Draw();" ] }, { "cell_type": "markdown", "id": "8cea851f", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 6, "id": "2b8a154a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:07.191116Z", "iopub.status.busy": "2026-05-19T20:12:07.190993Z", "iopub.status.idle": "2026-05-19T20:12:07.414097Z", "shell.execute_reply": "2026-05-19T20:12:07.412745Z" } }, "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 }