Logo ROOT   6.08/07
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 
12 from os import path
13 from ROOT import TCanvas, TFile, TPaveText
14 from ROOT import gROOT, gBenchmark
15 
16 c1 = TCanvas( 'c1', 'The Fit Canvas', 200, 10, 700, 500 )
17 c1.SetGridx()
18 c1.SetGridy()
19 c1.GetFrame().SetFillColor( 21 )
20 c1.GetFrame().SetBorderMode(-1 )
21 c1.GetFrame().SetBorderSize( 5 )
22 
23 gBenchmark.Start( 'fit1' )
24 #
25 # We connect the ROOT file generated in a previous tutorial
26 #
27 fill = TFile( 'py-fillrandom.root' )
28 
29 #
30 # The function "ls()" lists the directory contents of this file
31 #
32 fill.ls()
33 
34 #
35 # Get object "sqroot" from the file.
36 #
37 
38 sqroot = gROOT.FindObject( 'sqroot' )
39 sqroot.Print()
40 
41 #
42 # Now fit histogram h1f with the function sqroot
43 #
44 h1f = gROOT.FindObject( 'h1f' )
45 h1f.SetFillColor( 45 )
46 h1f.Fit( 'sqroot' )
47 
48 # We now annotate the picture by creating a PaveText object
49 # and displaying the list of commands in this macro
50 #
51 fitlabel = TPaveText( 0.6, 0.3, 0.9, 0.80, 'NDC' )
52 fitlabel.SetTextAlign( 12 )
53 fitlabel.SetFillColor( 42 )
54 fitlabel.ReadFile(path.join(gROOT.GetTutorialsDir(), 'pyroot', 'fit1_py.py'))
55 fitlabel.Draw()
56 c1.Update()
57 gBenchmark.Show( 'fit1' )
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
c SetBorderSize(2)
h1 SetFillColor(kGreen)
The Canvas class.
Definition: TCanvas.h:41
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:27