ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ntuple1.py
Go to the documentation of this file.
1 
2 from ROOT import TCanvas, TPad, TFile, TPaveText
3 from ROOT import gBenchmark, gStyle, gROOT
4 
5 #gROOT.Reset()
6 
7 c1 = TCanvas('c1','The Ntuple canvas',200,10,700,780)
8 
9 gBenchmark.Start('ntuple1')
10 
11 #
12 # Connect ROOT histogram/ntuple demonstration file
13 # generated by example hsimple.C.
14 f1 = TFile('hsimple.root')
15 
16 #
17 # Inside this canvas, we create 4 pads
18 pad1 = TPad('pad1','This is pad1',0.02,0.52,0.48,0.98,21)
19 pad2 = TPad('pad2','This is pad2',0.52,0.52,0.98,0.98,21)
20 pad3 = TPad('pad3','This is pad3',0.02,0.02,0.48,0.48,21)
21 pad4 = TPad('pad4','This is pad4',0.52,0.02,0.98,0.48,1)
22 pad1.Draw()
23 pad2.Draw()
24 pad3.Draw()
25 pad4.Draw()
26 
27 #
28 # Change default style for the statistics box
29 gStyle.SetStatW(0.30)
30 gStyle.SetStatH(0.20)
31 gStyle.SetStatColor(42)
32 
33 #
34 # Display a function of one ntuple column imposing a condition
35 # on another column.
36 pad1.cd()
37 pad1.SetGrid()
38 pad1.SetLogy()
39 pad1.GetFrame().SetFillColor(15)
40 ntuple = gROOT.FindObject('ntuple')
41 ntuple.SetLineColor(1)
42 ntuple.SetFillStyle(1001)
43 ntuple.SetFillColor(45)
44 ntuple.Draw('3*px+2','px**2+py**2>1')
45 ntuple.SetFillColor(38)
46 ntuple.Draw('2*px+2','pz>2','same')
47 ntuple.SetFillColor(5)
48 ntuple.Draw('1.3*px+2','(px^2+py^2>4) && py>0','same')
49 c1.Update()
50 
51 #
52 # Display the profile of two columns
53 # The profile histogram produced is saved in the current directory with
54 # the name hprofs
55 pad2.cd()
56 pad2.SetGrid()
57 pad2.GetFrame().SetFillColor(32)
58 ntuple.Draw('pz:px>>hprofs','','goffprofs')
59 hprofs = gROOT.FindObject('hprofs')
60 hprofs.SetMarkerColor(5)
61 hprofs.SetMarkerSize(0.7)
62 hprofs.SetMarkerStyle(21)
63 hprofs.Fit('pol2')
64 
65 #
66 # Get pointer to fitted function and modify its attributes
67 fpol2 = hprofs.GetFunction('pol2')
68 fpol2.SetLineWidth(4)
69 fpol2.SetLineColor(2)
70 c1.Update()
71 
72 #
73 # Display a scatter plot of two columns with a selection.
74 # Superimpose the result of another cut with a different marker color
75 pad3.cd()
76 pad3.GetFrame().SetFillColor(38)
77 pad3.GetFrame().SetBorderSize(8)
78 ntuple.SetMarkerColor(1)
79 ntuple.Draw('py:px','pz>1')
80 ntuple.SetMarkerColor(2)
81 ntuple.Draw('py:px','pz<1','same')
82 c1.Update()
83 
84 #
85 # Display a 3-D scatter plot of 3 columns. Superimpose a different selection.
86 pad4.cd()
87 ntuple.Draw('pz:py:px','(pz<10 && pz>6)+(pz<4 && pz>3)')
88 ntuple.SetMarkerColor(4)
89 ntuple.Draw('pz:py:px','pz<6 && pz>4','same')
90 ntuple.SetMarkerColor(5)
91 ntuple.Draw('pz:py:px','pz<4 && pz>3','same')
92 l4 = TPaveText(-0.9,0.5,0.9,0.95)
93 l4.SetFillColor(42)
94 l4.SetTextAlign(12)
95 l4.AddText('You can interactively rotate this view in 2 ways:')
96 l4.AddText(' - With the RotateCube in clicking in this pad')
97 l4.AddText(' - Selecting View with x3d in the View menu')
98 l4.Draw()
99 
100 #
101 # done
102 c1.cd()
103 c1.Update()
104 gStyle.SetStatColor(19)
105 gBenchmark.Show('ntuple1')
c SetBorderSize(2)
h1 SetFillColor(kGreen)