{ "cells": [ { "cell_type": "markdown", "id": "ac80b02c", "metadata": {}, "source": [ "# hist029_TRatioPlot_simple\n", "Two histograms are set up and filled with random numbers. The constructor of `TRatioPlot`\n", "takes the two histograms, name and title for the object, drawing options for the histograms\n", "(`hist` and `E` in this case) and a drawing option for the output graph.\n", "The histograms drawing options can be changed with `SetH1DrawOpt` and `SetH2DrawOpt`.\n", "\n", "\n", "\n", "\n", "**Author:** Paul Gessinger \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": "3c79141f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:33.607456Z", "iopub.status.busy": "2026-05-19T20:12:33.607313Z", "iopub.status.idle": "2026-05-19T20:12:34.095559Z", "shell.execute_reply": "2026-05-19T20:12:34.088344Z" } }, "outputs": [], "source": [ "gStyle->SetOptStat(0);\n", "auto C = new TCanvas(\"C\", \"A ratio example\");\n", "auto h1 = new TH1D(\"h1\", \"TRatioPlot Example; x; y\", 50, 0, 10);\n", "auto h2 = new TH1D(\"h2\", \"h2\", 50, 0, 10);\n", "auto f1 = new TF1(\"f1\", \"exp(- x/[0] )\");\n", "f1->SetParameter(0, 3);\n", "h1->FillRandom(\"f1\", 1900);\n", "h2->FillRandom(\"f1\", 2000);\n", "h1->Sumw2();\n", "h2->Scale(1.9 / 2.);\n", "h2->SetLineColor(kRed);" ] }, { "cell_type": "markdown", "id": "3860d559", "metadata": {}, "source": [ "Create and draw the ratio plot" ] }, { "cell_type": "code", "execution_count": 2, "id": "51c92ba8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:34.109281Z", "iopub.status.busy": "2026-05-19T20:12:34.109137Z", "iopub.status.idle": "2026-05-19T20:12:34.313297Z", "shell.execute_reply": "2026-05-19T20:12:34.312674Z" } }, "outputs": [], "source": [ "auto rp = new TRatioPlot(h1, h2);\n", "C->SetTicks(0, 1);\n", "rp->Draw();\n", "rp->GetLowYaxis()->SetNdivisions(505);" ] }, { "cell_type": "markdown", "id": "3bb06b05", "metadata": {}, "source": [ "Add a legend to the ratio plot" ] }, { "cell_type": "code", "execution_count": 3, "id": "63519a5a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:34.315418Z", "iopub.status.busy": "2026-05-19T20:12:34.315286Z", "iopub.status.idle": "2026-05-19T20:12:34.530129Z", "shell.execute_reply": "2026-05-19T20:12:34.529463Z" } }, "outputs": [], "source": [ "rp->GetUpperPad()->cd();\n", "TLegend *legend = new TLegend(0.3, 0.7, 0.7, 0.85);\n", "legend->AddEntry(\"h1\", \"First histogram\", \"l\");\n", "legend->AddEntry(\"h2\", \"Second histogram\", \"le\");\n", "legend->Draw();" ] }, { "cell_type": "markdown", "id": "424c2d92", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 4, "id": "71392bf8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:34.537338Z", "iopub.status.busy": "2026-05-19T20:12:34.537212Z", "iopub.status.idle": "2026-05-19T20:12:34.740973Z", "shell.execute_reply": "2026-05-19T20:12:34.740563Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "