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)
32
33#
34# Change default style for the statistics box
38
39#
40# Display a function of one ntuple column imposing a condition
41# on another column.
42pad1.cd()
46ntuple = gROOT.FindObject('ntuple')
50ntuple.Draw('3*px+2','px**2+py**2>1')
52ntuple.Draw('2*px+2','pz>2','same')
54ntuple.Draw('1.3*px+2','(px^2+py^2>4) && py>0','same')
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()
64ntuple.Draw('pz:px>>hprofs','','goffprofs')
65hprofs = gROOT.FindObject('hprofs')
69hprofs.Fit('pol2')
70
71#
72# Get pointer to fitted function and modify its attributes
73fpol2 = hprofs.GetFunction('pol2')
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()
85ntuple.Draw('py:px','pz>1')
87ntuple.Draw('py:px','pz<1','same')
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)')
95ntuple.Draw('pz:py:px','pz<6 && pz>4','same')
97ntuple.Draw('pz:py:px','pz<4 && pz>3','same')
98l4 = TPaveText(-0.9,0.5,0.9,0.95)
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()
111gBenchmark.Show('ntuple1')
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t SetFillColor
The Canvas class.
Definition TCanvas.h:23
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
The most important graphics class in the ROOT system.
Definition TPad.h:28
A Pave (see TPave) with text, lines or/and boxes inside.
Definition TPaveText.h:21
c SetBorderSize(2)