{ "cells": [ { "cell_type": "markdown", "id": "51145d15", "metadata": {}, "source": [ "# hist028_THStack_multicolor\n", "```cpp\n", " root > .x multicolor.C\n", " root > .x multicolor.C(1)\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": "markdown", "id": "1de6b4bd", "metadata": {}, "source": [ " Arguments are defined. " ] }, { "cell_type": "code", "execution_count": 1, "id": "fbbf7b4b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:33.379411Z", "iopub.status.busy": "2026-05-19T20:12:33.379299Z", "iopub.status.idle": "2026-05-19T20:12:33.701728Z", "shell.execute_reply": "2026-05-19T20:12:33.700587Z" } }, "outputs": [], "source": [ "Int_t isStack = 0;" ] }, { "cell_type": "code", "execution_count": 2, "id": "8136cce7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:33.710782Z", "iopub.status.busy": "2026-05-19T20:12:33.710643Z", "iopub.status.idle": "2026-05-19T20:12:33.913928Z", "shell.execute_reply": "2026-05-19T20:12:33.913235Z" } }, "outputs": [], "source": [ "TCanvas *c1 = new TCanvas;\n", "Int_t nbins = 20;\n", "TH2F *h1 = new TH2F(\"h1\", \"h1\", nbins, -4, 4, nbins, -4, 4);\n", "h1->SetFillColor(kBlue);\n", "TH2F *h2 = new TH2F(\"h2\", \"h2\", nbins, -4, 4, nbins, -4, 4);\n", "h2->SetFillColor(kRed);\n", "TH2F *h3 = new TH2F(\"h3\", \"h3\", nbins, -4, 4, nbins, -4, 4);\n", "h3->SetFillColor(kYellow);\n", "THStack *hs = new THStack(\"hs\", \"three plots\");\n", "hs->Add(h1);\n", "hs->Add(h2);\n", "hs->Add(h3);\n", "TRandom r;\n", "Int_t i;\n", "for (i = 0; i < 20000; i++)\n", " h1->Fill(r.Gaus(), r.Gaus());\n", "for (i = 0; i < 200; i++) {\n", " Int_t ix = (Int_t)r.Uniform(0, nbins);\n", " Int_t iy = (Int_t)r.Uniform(0, nbins);\n", " Int_t bin = h1->GetBin(ix, iy);\n", " Double_t val = h1->GetBinContent(bin);\n", " if (val <= 0)\n", " continue;\n", " if (!isStack)\n", " h1->SetBinContent(bin, 0);\n", " if (r.Rndm() > 0.5) {\n", " if (!isStack)\n", " h2->SetBinContent(bin, 0);\n", " h3->SetBinContent(bin, val);\n", " } else {\n", " if (!isStack)\n", " h3->SetBinContent(bin, 0);\n", " h2->SetBinContent(bin, val);\n", " }\n", "}\n", "hs->Draw(\"lego1\");" ] }, { "cell_type": "markdown", "id": "215d1ff5", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 3, "id": "fd5411c7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:33.929370Z", "iopub.status.busy": "2026-05-19T20:12:33.929241Z", "iopub.status.idle": "2026-05-19T20:12:34.138202Z", "shell.execute_reply": "2026-05-19T20:12:34.137431Z" } }, "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 }