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