{ "cells": [ { "cell_type": "markdown", "id": "0c174b7c", "metadata": {}, "source": [ "# hist023_THStack_simple\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": "d22d9746", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:26.494027Z", "iopub.status.busy": "2026-05-19T20:12:26.493918Z", "iopub.status.idle": "2026-05-19T20:12:26.806090Z", "shell.execute_reply": "2026-05-19T20:12:26.804845Z" } }, "outputs": [], "source": [ "auto hs = new THStack(\"hs\", \"Stacked 1D histograms\");" ] }, { "cell_type": "markdown", "id": "58a8553d", "metadata": {}, "source": [ "create three 1-d histograms" ] }, { "cell_type": "code", "execution_count": 2, "id": "74aec120", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:26.807819Z", "iopub.status.busy": "2026-05-19T20:12:26.807691Z", "iopub.status.idle": "2026-05-19T20:12:27.120925Z", "shell.execute_reply": "2026-05-19T20:12:27.120211Z" } }, "outputs": [], "source": [ "auto h1st = new TH1F(\"h1st\", \"test hstack\", 100, -4, 4);\n", "h1st->FillRandom(\"gaus\", 20000);\n", "h1st->SetFillColor(kRed);\n", "h1st->SetMarkerStyle(21);\n", "h1st->SetMarkerColor(kRed);\n", "hs->Add(h1st);\n", "auto h2st = new TH1F(\"h2st\", \"test hstack\", 100, -4, 4);\n", "h2st->FillRandom(\"gaus\", 15000);\n", "h2st->SetFillColor(kBlue);\n", "h2st->SetMarkerStyle(21);\n", "h2st->SetMarkerColor(kBlue);\n", "hs->Add(h2st);\n", "auto h3st = new TH1F(\"h3st\", \"test hstack\", 100, -4, 4);\n", "h3st->FillRandom(\"gaus\", 10000);\n", "h3st->SetFillColor(kGreen);\n", "h3st->SetMarkerStyle(21);\n", "h3st->SetMarkerColor(kGreen);\n", "hs->Add(h3st);\n", "\n", "auto cst = new TCanvas(\"cst\", \"stacked hists\", 10, 10, 700, 700);\n", "cst->Divide(2, 2);" ] }, { "cell_type": "markdown", "id": "e6c97315", "metadata": {}, "source": [ "in top left pad, draw the stack with defaults" ] }, { "cell_type": "code", "execution_count": 3, "id": "22484588", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:27.122815Z", "iopub.status.busy": "2026-05-19T20:12:27.122698Z", "iopub.status.idle": "2026-05-19T20:12:27.326741Z", "shell.execute_reply": "2026-05-19T20:12:27.326087Z" } }, "outputs": [], "source": [ "cst->cd(1);\n", "hs->Draw();" ] }, { "cell_type": "markdown", "id": "cb5e64b8", "metadata": {}, "source": [ "in top right pad, draw the stack in non-stack mode\n", "and errors option" ] }, { "cell_type": "code", "execution_count": 4, "id": "2b1a0aa8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:27.328874Z", "iopub.status.busy": "2026-05-19T20:12:27.328758Z", "iopub.status.idle": "2026-05-19T20:12:27.532105Z", "shell.execute_reply": "2026-05-19T20:12:27.531422Z" } }, "outputs": [], "source": [ "cst->cd(2);\n", "gPad->SetGrid();\n", "hs->Draw(\"nostack,e1p\");" ] }, { "cell_type": "markdown", "id": "d3ab0fea", "metadata": {}, "source": [ "in bottom left, draw in stack mode with \"lego1\" option" ] }, { "cell_type": "code", "execution_count": 5, "id": "049db95b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:27.534362Z", "iopub.status.busy": "2026-05-19T20:12:27.534242Z", "iopub.status.idle": "2026-05-19T20:12:27.738526Z", "shell.execute_reply": "2026-05-19T20:12:27.737687Z" } }, "outputs": [], "source": [ "cst->cd(3);\n", "gPad->SetFrameFillColor(17);\n", "gPad->SetTheta(3.77);\n", "gPad->SetPhi(2.9);\n", "hs->Draw(\"lego1\");\n", "\n", "cst->cd(4);" ] }, { "cell_type": "markdown", "id": "10896a5d", "metadata": {}, "source": [ "create two 2-D histograms and draw them in stack mode" ] }, { "cell_type": "code", "execution_count": 6, "id": "30c24a04", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:27.740879Z", "iopub.status.busy": "2026-05-19T20:12:27.740698Z", "iopub.status.idle": "2026-05-19T20:12:27.945512Z", "shell.execute_reply": "2026-05-19T20:12:27.944888Z" } }, "outputs": [], "source": [ "gPad->SetFrameFillColor(17);\n", "auto a = new THStack(\"a\", \"Stacked 2D histograms\");\n", "auto f1 = new TF2(\"f1\", \"xygaus + xygaus(5) + xylandau(10)\", -4, 4, -4, 4);\n", "Double_t params1[] = {130, -1.4, 1.8, 1.5, 1, 150, 2, 0.5, -2, 0.5, 3600, -2, 0.7, -3, 0.3};\n", "f1->SetParameters(params1);\n", "auto h2sta = new TH2F(\"h2sta\", \"h2sta\", 20, -4, 4, 20, -4, 4);\n", "h2sta->SetFillColor(38);\n", "h2sta->FillRandom(\"f1\", 4000);\n", "auto f2 = new TF2(\"f2\", \"xygaus + xygaus(5)\", -4, 4, -4, 4);\n", "Double_t params2[] = {100, -1.4, 1.9, 1.1, 2, 80, 2, 0.7, -2, 0.5};\n", "f2->SetParameters(params2);\n", "auto h2stb = new TH2F(\"h2stb\", \"h2stb\", 20, -4, 4, 20, -4, 4);\n", "h2stb->SetFillColor(46);\n", "h2stb->FillRandom(\"f2\", 3000);\n", "a->Add(h2sta);\n", "a->Add(h2stb);\n", "a->Draw();" ] }, { "cell_type": "markdown", "id": "c11c457d", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 7, "id": "c2625a74", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:27.947690Z", "iopub.status.busy": "2026-05-19T20:12:27.947555Z", "iopub.status.idle": "2026-05-19T20:12:28.151441Z", "shell.execute_reply": "2026-05-19T20:12:28.150820Z" } }, "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 }