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