{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d25d295c",
   "metadata": {},
   "source": [
    "# fit1\n",
    "Fit example.\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "**Author:** Wim Lavrijsen  \n",
    "<i><small>This notebook tutorial was automatically generated with <a href= \"https://github.com/root-project/root/blob/master/documentation/doxygen/converttonotebook.py\">ROOTBOOK-izer</a> from the macro found in the ROOT repository  on Tuesday, May 19, 2026 at 08:24 PM.</small></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "864c182d",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import ROOT\n",
    "from os import path\n",
    "from ROOT import TCanvas, TFile, TPaveText\n",
    "from ROOT import gROOT, gBenchmark\n",
    "\n",
    "c1 = TCanvas( 'c1', 'The Fit Canvas', 200, 10, 700, 500 )\n",
    "c1.SetGridx()\n",
    "c1.SetGridy()\n",
    "c1.GetFrame().SetFillColor( 21 )\n",
    "c1.GetFrame().SetBorderMode(-1 )\n",
    "c1.GetFrame().SetBorderSize( 5 )\n",
    "\n",
    "gBenchmark.Start( 'fit1' )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed676092",
   "metadata": {},
   "source": [
    "We connect the ROOT file generated in a previous tutorial"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83db12d9",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "File = \"fillrandom-py.root\"\n",
    "if (ROOT.gSystem.AccessPathName(File)) :\n",
    "    ROOT.Info(\"fit1.py\", File+\" does not exist\")\n",
    "    exit()\n",
    "\n",
    "fill = TFile(File)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "326ff058",
   "metadata": {},
   "source": [
    "The function \"ls()\" lists the directory contents of this file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "71400252",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "fill.ls()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8682c477",
   "metadata": {},
   "source": [
    "Get object \"sqroot\" from the file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ba57ba10",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "sqroot = gROOT.FindObject( 'sqroot' )\n",
    "sqroot.Print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ab86e99",
   "metadata": {},
   "source": [
    "Now fit histogram h1f with the function sqroot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f77941cc",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "h1f = gROOT.FindObject( 'h1f' )\n",
    "h1f.SetFillColor( 45 )\n",
    "h1f.Fit( 'sqroot' )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa0ca45e",
   "metadata": {},
   "source": [
    "We now annotate the picture by creating a PaveText object\n",
    "and displaying the list of commands in this macro"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0afdbefb",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "fitlabel = TPaveText( 0.6, 0.3, 0.9, 0.80, 'NDC' )\n",
    "fitlabel.SetTextAlign( 12 )\n",
    "fitlabel.SetFillColor( 42 )\n",
    "fitlabel.ReadFile(path.join(str(gROOT.GetTutorialDir()), 'math', 'fit', 'fit1_py.py'))\n",
    "fitlabel.Draw()\n",
    "c1.Update()\n",
    "gBenchmark.Show( 'fit1' )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48276b0b",
   "metadata": {},
   "source": [
    "Draw all canvases "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25bd89ee",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from ROOT import gROOT \n",
    "gROOT.GetListOfCanvases().Draw()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}