#!/usr/bin/env python # coding: utf-8 # # fit1 # Fit example. # # # # # **Author:** Wim Lavrijsen # This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, April 17, 2024 at 11:16 AM. # In[1]: import ROOT from os import path from ROOT import TCanvas, TFile, TPaveText from ROOT import gROOT, gBenchmark c1 = TCanvas( 'c1', 'The Fit Canvas', 200, 10, 700, 500 ) c1.SetGridx() c1.SetGridy() c1.GetFrame().SetFillColor( 21 ) c1.GetFrame().SetBorderMode(-1 ) c1.GetFrame().SetBorderSize( 5 ) gBenchmark.Start( 'fit1' ) # We connect the ROOT file generated in a previous tutorial # In[2]: File = "py-fillrandom.root" if (ROOT.gSystem.AccessPathName(File)) : ROOT.Info("fit1.py", File+" does not exist") exit() fill = TFile(File) # The function "ls()" lists the directory contents of this file # In[3]: fill.ls() # Get object "sqroot" from the file. # In[4]: sqroot = gROOT.FindObject( 'sqroot' ) sqroot.Print() # Now fit histogram h1f with the function sqroot # In[5]: h1f = gROOT.FindObject( 'h1f' ) h1f.SetFillColor( 45 ) h1f.Fit( 'sqroot' ) # We now annotate the picture by creating a PaveText object # and displaying the list of commands in this macro # In[6]: fitlabel = TPaveText( 0.6, 0.3, 0.9, 0.80, 'NDC' ) fitlabel.SetTextAlign( 12 ) fitlabel.SetFillColor( 42 ) fitlabel.ReadFile(path.join(str(gROOT.GetTutorialDir()), 'pyroot', 'fit1_py.py')) fitlabel.Draw() c1.Update() gBenchmark.Show( 'fit1' ) # Draw all canvases # In[7]: from ROOT import gROOT gROOT.GetListOfCanvases().Draw()