{ "cells": [ { "cell_type": "markdown", "id": "8b72a87e", "metadata": {}, "source": [ "# fit2a\n", "Fitting a 2-D histogram (a variant)\n", "This tutorial illustrates :\n", " - how to create a 2-d function\n", " - fill a 2-d histogram randomly from this function\n", " - fit the histogram\n", " - display the fitted function on top of the histogram (lego-plot)\n", " using a surface plot in a sub-range of the histogram.\n", "\n", "This example can be executed via the interpreter or/and the compiler\n", "\n", "```cpp\n", " root > .x fit2a.C\n", " root > .x fit2a.C++\n", "```\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": "680e4b49", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 1, "id": "17da207e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:43.996549Z", "iopub.status.busy": "2026-05-19T20:24:43.996387Z", "iopub.status.idle": "2026-05-19T20:24:44.001122Z", "shell.execute_reply": "2026-05-19T20:24:44.000502Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "\n", "#include \"TF2.h\"\n", "#include \"TH2.h\"\n", "#include \"TCutG.h\"\n", "#include \"TMath.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TStyle.h\"\n", "\n", "double g2(double *x, double *par) {\n", " double r1 = double((x[0]-par[1])/par[2]);\n", " double r2 = double((x[1]-par[3])/par[4]);\n", " return par[0]*TMath::Exp(-0.5*(r1*r1+r2*r2));\n", "}" ] }, { "cell_type": "markdown", "id": "207c30ae", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 2, "id": "a6380d8d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:44.002748Z", "iopub.status.busy": "2026-05-19T20:24:44.002612Z", "iopub.status.idle": "2026-05-19T20:24:44.005713Z", "shell.execute_reply": "2026-05-19T20:24:44.005238Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "double fun2(double *x, double *par) {\n", " double *p1 = &par[0];\n", " double *p2 = &par[5];\n", " double *p3 = &par[10];\n", " double result = g2(x,p1) + g2(x,p2) + g2(x,p3);\n", " return result;\n", "}" ] }, { "cell_type": "code", "execution_count": 3, "id": "5ad11233", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:24:44.007215Z", "iopub.status.busy": "2026-05-19T20:24:44.007092Z", "iopub.status.idle": "2026-05-19T20:24:44.456438Z", "shell.execute_reply": "2026-05-19T20:24:44.456018Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "