Logo ROOT   6.07/09
Reference Guide
Namespaces
ntuple1.py File Reference

Namespaces

 ntuple1
 

Detailed Description

View in nbviewer Open in SWAN Ntuple drawing example.

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

Definition in file ntuple1.py.