{ "cells": [ { "cell_type": "markdown", "id": "d096799c", "metadata": {}, "source": [ "# hist008_TH1_zoom\n", "\n", "Image produced by `.x ZoomHistogram.C`\n", "\n", "This demonstrates how to zoom into a histogram by\n", "changing the range on one of the axes (or both).\n", "\n", "\n", "\n", "\n", "**Author:** Advait Dhingra \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:11 PM." ] }, { "cell_type": "markdown", "id": "dd0a6e18", "metadata": {}, "source": [ "Create and fill a histogram" ] }, { "cell_type": "code", "execution_count": 1, "id": "7a09d11a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:03.051517Z", "iopub.status.busy": "2026-05-19T20:12:03.051368Z", "iopub.status.idle": "2026-05-19T20:12:03.359774Z", "shell.execute_reply": "2026-05-19T20:12:03.359123Z" } }, "outputs": [], "source": [ "TH1F *orig = new TH1F(\"Normal Histogram\", \"Normal Histogram\", 100, 0, 100);\n", "\n", "TRandom3 rng;\n", "for (int i = 0; i < 1000; ++i) {\n", " double x = rng.Gaus(50, 10);\n", " orig->Fill(x);\n", "}" ] }, { "cell_type": "markdown", "id": "80bfa60c", "metadata": {}, "source": [ "Clone the histogram into one called \"zoom\"" ] }, { "cell_type": "code", "execution_count": 2, "id": "b8ea04ee", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:03.361232Z", "iopub.status.busy": "2026-05-19T20:12:03.361110Z", "iopub.status.idle": "2026-05-19T20:12:03.564503Z", "shell.execute_reply": "2026-05-19T20:12:03.563843Z" } }, "outputs": [], "source": [ "TH1F *zoom = static_cast(orig->Clone(\"zoom\"));\n", "zoom->SetTitle(\"Zoomed-in Histogram\");" ] }, { "cell_type": "markdown", "id": "7e7663ad", "metadata": {}, "source": [ "\"Zoom\" in the histogram by setting a new range to the X axis" ] }, { "cell_type": "code", "execution_count": 3, "id": "68e4b47c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:03.565964Z", "iopub.status.busy": "2026-05-19T20:12:03.565837Z", "iopub.status.idle": "2026-05-19T20:12:03.769779Z", "shell.execute_reply": "2026-05-19T20:12:03.769176Z" } }, "outputs": [], "source": [ "zoom->GetXaxis()->SetRangeUser(50, 100);" ] }, { "cell_type": "markdown", "id": "99b00943", "metadata": {}, "source": [ "Draw both histograms to a canvas" ] }, { "cell_type": "code", "execution_count": 4, "id": "dd7ef4ed", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:03.771236Z", "iopub.status.busy": "2026-05-19T20:12:03.771117Z", "iopub.status.idle": "2026-05-19T20:12:03.975094Z", "shell.execute_reply": "2026-05-19T20:12:03.974586Z" } }, "outputs": [], "source": [ "TCanvas *c1 = new TCanvas(\"c1\", \"Histogram\", 1500, 700);" ] }, { "cell_type": "markdown", "id": "9b494f27", "metadata": {}, "source": [ "split the canvas horizontally in 2" ] }, { "cell_type": "code", "execution_count": 5, "id": "fe7d44af", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:03.976953Z", "iopub.status.busy": "2026-05-19T20:12:03.976827Z", "iopub.status.idle": "2026-05-19T20:12:04.180743Z", "shell.execute_reply": "2026-05-19T20:12:04.180182Z" } }, "outputs": [], "source": [ "int nsubdivX = 2;\n", "int nsubdivY = 1;\n", "c1->Divide(nsubdivX, nsubdivY);\n", "\n", "c1->cd(1);\n", "orig->Draw();\n", "c1->cd(2);\n", "zoom->Draw();" ] }, { "cell_type": "markdown", "id": "2522706d", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 6, "id": "6d1d458a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:04.182156Z", "iopub.status.busy": "2026-05-19T20:12:04.182014Z", "iopub.status.idle": "2026-05-19T20:12:04.401762Z", "shell.execute_reply": "2026-05-19T20:12:04.401247Z" } }, "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 }