Logo ROOT  
Reference Guide
fit1.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_pyroot
3## \notebook
4## Fit example.
5##
6## \macro_image
7## \macro_output
8## \macro_code
9##
10## \author Wim Lavrijsen
11
12import ROOT
13from os import path
14from ROOT import TCanvas, TFile, TPaveText
15from ROOT import gROOT, gBenchmark
16
17c1 = TCanvas( 'c1', 'The Fit Canvas', 200, 10, 700, 500 )
18c1.SetGridx()
19c1.SetGridy()
20c1.GetFrame().SetFillColor( 21 )
21c1.GetFrame().SetBorderMode(-1 )
22c1.GetFrame().SetBorderSize( 5 )
23
24gBenchmark.Start( 'fit1' )
25#
26# We connect the ROOT file generated in a previous tutorial
27#
28File = "py-fillrandom.root"
29if (ROOT.gSystem.AccessPathName(File)) :
30 ROOT.Info("fit1.py", File+" does not exist")
31 exit()
32
33fill = TFile(File)
34
35#
36# The function "ls()" lists the directory contents of this file
37#
38fill.ls()
39
40#
41# Get object "sqroot" from the file.
42#
43
44sqroot = gROOT.FindObject( 'sqroot' )
45sqroot.Print()
46
47#
48# Now fit histogram h1f with the function sqroot
49#
50h1f = gROOT.FindObject( 'h1f' )
51h1f.SetFillColor( 45 )
52h1f.Fit( 'sqroot' )
53
54# We now annotate the picture by creating a PaveText object
55# and displaying the list of commands in this macro
56#
57fitlabel = TPaveText( 0.6, 0.3, 0.9, 0.80, 'NDC' )
58fitlabel.SetTextAlign( 12 )
59fitlabel.SetFillColor( 42 )
60fitlabel.ReadFile(path.join(str(gROOT.GetTutorialDir()), 'pyroot', 'fit1_py.py'))
61fitlabel.Draw()
62c1.Update()
63gBenchmark.Show( 'fit1' )
Option_t Option_t SetFillColor
The Canvas class.
Definition: TCanvas.h:23
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:21
c SetBorderSize(2)