{ "cells": [ { "cell_type": "markdown", "id": "168de751", "metadata": {}, "source": [ "# fitslicesy\n", "Illustrates how to use the TH1::FitSlicesY function\n", "It uses the TH2F histogram generated in macro hsimple.C\n", "It invokes FitSlicesY and draw the fitted \"mean\" and \"sigma\"\n", "in 2 sepate pads.\n", "This macro shows also how to annotate a picture, change\n", "some pad parameters.\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:06 PM." ] }, { "cell_type": "markdown", "id": "d68d7d8b", "metadata": {}, "source": [ "Change some default parameters in the current style" ] }, { "cell_type": "code", "execution_count": 1, "id": "88f5e9bb", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:25.637745Z", "iopub.status.busy": "2026-05-19T20:06:25.637561Z", "iopub.status.idle": "2026-05-19T20:06:26.071076Z", "shell.execute_reply": "2026-05-19T20:06:26.070575Z" } }, "outputs": [], "source": [ "gStyle->SetLabelSize(0.06,\"x\");\n", "gStyle->SetLabelSize(0.06,\"y\");\n", "gStyle->SetFrameFillColor(38);\n", "gStyle->SetTitleW(0.6);\n", "gStyle->SetTitleH(0.1);" ] }, { "cell_type": "markdown", "id": "99056698", "metadata": {}, "source": [ "Connect the input file and get the 2-d histogram in memory" ] }, { "cell_type": "code", "execution_count": 2, "id": "ccc1ac34", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:26.089300Z", "iopub.status.busy": "2026-05-19T20:06:26.089148Z", "iopub.status.idle": "2026-05-19T20:06:26.727079Z", "shell.execute_reply": "2026-05-19T20:06:26.720471Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "TString dir = gROOT->GetTutorialDir();\n", "dir.Append(\"/hsimple.C\");\n", "dir.ReplaceAll(\"/./\",\"/\");\n", "if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());\n", "TFile *hsimpleFile = (TFile*)gROOT->ProcessLineFast(\"hsimple(1)\");\n", "if (!hsimpleFile) return;\n", "TH2F *hpxpy = (TH2F*)hsimpleFile->Get(\"hpxpy\");" ] }, { "cell_type": "markdown", "id": "67cb6cbd", "metadata": {}, "source": [ "Create a canvas and divide it" ] }, { "cell_type": "code", "execution_count": 3, "id": "2870d099", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:26.737324Z", "iopub.status.busy": "2026-05-19T20:06:26.737179Z", "iopub.status.idle": "2026-05-19T20:06:26.960974Z", "shell.execute_reply": "2026-05-19T20:06:26.960440Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Warning in : Deleting canvas with same name: c1\n" ] } ], "source": [ "TCanvas *c1 = new TCanvas(\"c1\",\"c1\",700,500);\n", "c1->SetFillColor(42);\n", "c1->Divide(2,1);\n", "TPad *leftPad = (TPad*)c1->cd(1);;\n", "leftPad->Divide(1,2);" ] }, { "cell_type": "markdown", "id": "dfabda9b", "metadata": {}, "source": [ "Draw 2-d original histogram" ] }, { "cell_type": "code", "execution_count": 4, "id": "f6aea917", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:26.962173Z", "iopub.status.busy": "2026-05-19T20:06:26.962052Z", "iopub.status.idle": "2026-05-19T20:06:27.188913Z", "shell.execute_reply": "2026-05-19T20:06:27.186254Z" } }, "outputs": [], "source": [ "leftPad->cd(1);\n", "gPad->SetTopMargin(0.12);\n", "gPad->SetFillColor(33);\n", "hpxpy->Draw();\n", "hpxpy->GetXaxis()->SetLabelSize(0.06);\n", "hpxpy->GetYaxis()->SetLabelSize(0.06);\n", "hpxpy->SetMarkerColor(kYellow);" ] }, { "cell_type": "markdown", "id": "aa82775b", "metadata": {}, "source": [ "Fit slices projected along Y fron bins in X [7,32] with more than 20 bins in Y filled" ] }, { "cell_type": "code", "execution_count": 5, "id": "a78e650d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:27.219229Z", "iopub.status.busy": "2026-05-19T20:06:27.219072Z", "iopub.status.idle": "2026-05-19T20:06:27.557746Z", "shell.execute_reply": "2026-05-19T20:06:27.557340Z" } }, "outputs": [], "source": [ "hpxpy->FitSlicesY(nullptr,7,32,20);" ] }, { "cell_type": "markdown", "id": "35075147", "metadata": {}, "source": [ "Show fitted \"mean\" for each slice" ] }, { "cell_type": "code", "execution_count": 6, "id": "771dc794", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:27.590437Z", "iopub.status.busy": "2026-05-19T20:06:27.590284Z", "iopub.status.idle": "2026-05-19T20:06:27.804087Z", "shell.execute_reply": "2026-05-19T20:06:27.803647Z" } }, "outputs": [], "source": [ "leftPad->cd(2);\n", "gPad->SetFillColor(33);\n", "TH2F *hpxpy_0 = (TH2F*)hsimpleFile->Get(\"hpxpy_0\");\n", "hpxpy_0->Draw();\n", "TPad *rightPad = (TPad*)c1->cd(2);\n", "rightPad->Divide(1,2);\n", "rightPad->cd(1);\n", "gPad->SetTopMargin(0.12);\n", "gPad->SetLeftMargin(0.15);\n", "gPad->SetFillColor(33);\n", "TH2F *hpxpy_1 = (TH2F*)hsimpleFile->Get(\"hpxpy_1\");\n", "hpxpy_1->Draw();" ] }, { "cell_type": "markdown", "id": "01da599c", "metadata": {}, "source": [ "Show fitted \"sigma\" for each slice" ] }, { "cell_type": "code", "execution_count": 7, "id": "2e7531dd", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:27.826231Z", "iopub.status.busy": "2026-05-19T20:06:27.826082Z", "iopub.status.idle": "2026-05-19T20:06:28.028150Z", "shell.execute_reply": "2026-05-19T20:06:28.027701Z" } }, "outputs": [], "source": [ "rightPad->cd(2);\n", "gPad->SetTopMargin(0.12);\n", "gPad->SetLeftMargin(0.15);\n", "gPad->SetFillColor(33);\n", "TH2F *hpxpy_2 = (TH2F*)hsimpleFile->Get(\"hpxpy_2\");\n", "hpxpy_2->SetMinimum(0.8);\n", "hpxpy_2->Draw();" ] }, { "cell_type": "markdown", "id": "dc1c3644", "metadata": {}, "source": [ "attributes" ] }, { "cell_type": "code", "execution_count": 8, "id": "e5db1e07", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:28.036117Z", "iopub.status.busy": "2026-05-19T20:06:28.035986Z", "iopub.status.idle": "2026-05-19T20:06:28.242509Z", "shell.execute_reply": "2026-05-19T20:06:28.241855Z" } }, "outputs": [], "source": [ "hpxpy_0->SetLineColor(5);\n", "hpxpy_1->SetLineColor(5);\n", "hpxpy_2->SetLineColor(5);\n", "hpxpy_0->SetMarkerColor(2);\n", "hpxpy_1->SetMarkerColor(2);\n", "hpxpy_2->SetMarkerColor(2);\n", "hpxpy_0->SetMarkerStyle(21);\n", "hpxpy_1->SetMarkerStyle(21);\n", "hpxpy_2->SetMarkerStyle(21);\n", "hpxpy_0->SetMarkerSize(0.6);\n", "hpxpy_1->SetMarkerSize(0.6);\n", "hpxpy_2->SetMarkerSize(0.6);" ] }, { "cell_type": "markdown", "id": "3c1f5fbd", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 9, "id": "aa2cc288", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:28.252999Z", "iopub.status.busy": "2026-05-19T20:06:28.252862Z", "iopub.status.idle": "2026-05-19T20:06:28.484636Z", "shell.execute_reply": "2026-05-19T20:06:28.483916Z" } }, "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 }