{ "cells": [ { "cell_type": "markdown", "id": "53b1cdef", "metadata": {}, "source": [ "# fit2d\n", "Example illustrating how to fit a 2-d histogram of type y=f(x)\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:24 PM." ] }, { "cell_type": "markdown", "id": "b76f3871", "metadata": {}, "source": [ "generate a 2-d histogram using a TCutG" ] }, { "cell_type": "code", "execution_count": 1, "id": "213efeb1", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:44.082385Z", "iopub.status.busy": "2026-05-19T20:24:44.082258Z", "iopub.status.idle": "2026-05-19T20:24:44.432126Z", "shell.execute_reply": "2026-05-19T20:24:44.431743Z" } }, "outputs": [], "source": [ "const int n = 6;\n", "float x[n] = {0.092,0.83,0.94,0.81,0.12,0.1};\n", "float y[n] = {0.71,9.4,9,8,0.3,0.71};\n", "TCutG *cut = new TCutG(\"cut\",n,x,y);\n", "TH2F *h2 = new TH2F(\"h2\",\"h2\",40,0,1,40,0,10);\n", "float u,v;\n", "for (int i=0;i<100000;i++) {\n", " u = gRandom->Rndm();\n", " v = 10*gRandom->Rndm();\n", " if (cut->IsInside(u,v)) h2->Fill(u,v);\n", "}\n", "TCanvas *c1 = new TCanvas(\"c1\",\"show profile\",600,900);\n", "c1->Divide(1,2);\n", "c1->cd(1);\n", "h2->Draw();\n", "c1->cd(2);" ] }, { "cell_type": "markdown", "id": "dc65622d", "metadata": {}, "source": [ "use a TProfile to convert the 2-d to 1-d problem" ] }, { "cell_type": "code", "execution_count": 2, "id": "04e519ce", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:44.434334Z", "iopub.status.busy": "2026-05-19T20:24:44.434216Z", "iopub.status.idle": "2026-05-19T20:24:44.665087Z", "shell.execute_reply": "2026-05-19T20:24:44.664439Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "****************************************\n", "Minimizer is Linear / Migrad\n", "Chi2 = 4501.58\n", "NDf = 33\n", "p0 = -0.47055 +/- 0.00713644 \n", "p1 = 10.8033 +/- 0.0124078 \n" ] } ], "source": [ "TProfile *prof = h2->ProfileX();\n", "prof->Fit(\"pol1\");" ] }, { "cell_type": "markdown", "id": "a8b3d1c5", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 3, "id": "ae561303", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:44.666821Z", "iopub.status.busy": "2026-05-19T20:24:44.666699Z", "iopub.status.idle": "2026-05-19T20:24:44.903864Z", "shell.execute_reply": "2026-05-19T20:24:44.903334Z" } }, "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 }