ROOT
v6-26
Reference Guide
Loading...
Searching...
No Matches
demo.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_pyroot
3
## To run, do "python <path-to>/demo.py"
4
##
5
## \macro_code
6
##
7
## \author Wim Lavrijsen, Enric Tejedor
8
9
import
os, sys
10
import
ROOT
11
12
# To run, do "python <path-to>/demo.py"
13
14
# enable running from another directory than the one where demo.py resides
15
workdir = os.path.dirname( sys.argv[0] )
16
if
workdir:
17
os.chdir( workdir )
18
19
# This macro generates a Controlbar menu.
20
# To execute an item, click with the left mouse button.
21
# To see the HELP of a button, click on the right mouse button.
22
23
ROOT.gStyle.SetScreenFactor(1)
# if you have a large screen, select 1.2 or 1.4
24
25
bar = ROOT.TControlBar(
'vertical'
,
'Demos'
, 10, 10 )
26
27
# The callbacks to python work by having CLING call the python interpreter through
28
# the "TPython" class. Note the use of "raw strings."
29
if
sys.version_info[0] > 2:
30
to_run =
'exec(open(\'{}\').read())'
31
else
:
32
to_run =
'execfile(\'{}\')'
33
34
bar.AddButton(
'Help on Demos'
,
r'TPython::Exec( "'
+ to_run.format(
'demoshelp.py'
) +
'" );'
,
'Click Here For Help on Running the Demos'
)
35
bar.AddButton(
'browser'
,
r'TPython::Exec( "b = ROOT.TBrowser()" );'
,
'Start the ROOT browser'
)
36
bar.AddButton(
'framework'
,
r'TPython::Exec( "'
+ to_run.format(
'../legacy/pyroot/framework.py'
) +
'" );'
,
'An Example of Object Oriented User Interface'
)
37
bar.AddButton(
'first'
,
r'TPython::Exec( "'
+ to_run.format(
'../legacy/pyroot/first.py'
) +
'" );'
,
'An Example of Slide with Root'
)
38
bar.AddButton(
'hsimple'
,
r'TPython::Exec( "'
+ to_run.format(
'hsimple.py'
) +
'" );'
,
'Creating histograms/Ntuples on file'
,
"button"
)
39
bar.AddButton(
'hsum'
,
r'TPython::Exec( "'
+ to_run.format(
'hsum.py'
) +
'" );'
,
'Filling Histograms and Some Graphics Options'
)
40
bar.AddButton(
'formula1'
,
r'TPython::Exec( "'
+ to_run.format(
'formula1.py'
) +
'" );'
,
'Simple Formula and Functions'
)
41
bar.AddButton(
'surfaces'
,
r'TPython::Exec( "'
+ to_run.format(
'surfaces.py'
) +
'" );'
,
'Surface Drawing Options'
)
42
bar.AddButton(
'fillrandom'
,
r'TPython::Exec( "'
+ to_run.format(
'fillrandom.py'
) +
'" );'
,
'Histograms with Random Numbers from a Function'
)
43
bar.AddButton(
'fit1'
,
r'TPython::Exec( "'
+ to_run.format(
'fit1.py'
) +
'" );'
,
'A Simple Fitting Example'
)
44
bar.AddButton(
'multifit'
,
r'TPython::Exec( "'
+ to_run.format(
'multifit.py'
) +
'" );'
,
'Fitting in Subranges of Histograms'
)
45
bar.AddButton(
'h1draw'
,
r'TPython::Exec( "'
+ to_run.format(
'h1ReadAndDraw.py'
) +
'" );'
,
'Drawing Options for 1D Histograms'
)
46
bar.AddButton(
'graph'
,
r'TPython::Exec( "'
+ to_run.format(
'graph.py'
) +
'" );'
,
'Example of a Simple Graph'
)
47
bar.AddButton(
'gerrors'
,
r'TPython::Exec( "'
+ to_run.format(
'gerrors.py'
) +
'" );'
,
'Example of a Graph with Error Bars'
)
48
bar.AddButton(
'tornado'
,
r'TPython::Exec( "'
+ to_run.format(
'tornado.py'
) +
'" );'
,
'Examples of 3-D PolyMarkers'
)
49
bar.AddButton(
'shapes'
,
r'TPython::Exec( "'
+ to_run.format(
'shapes.py'
) +
'" );'
,
'The Geometry Shapes'
)
50
bar.AddButton(
'geometry'
,
r'TPython::Exec( "'
+ to_run.format(
'geometry.py'
) +
'" );'
,
'Creation of the NA49 Geometry File'
)
51
bar.AddButton(
'na49view'
,
r'TPython::Exec( "'
+ to_run.format(
'na49view.py'
) +
'" );'
,
'Two Views of the NA49 Detector Geometry'
)
52
bar.AddButton(
'file'
,
r'TPython::Exec( "'
+ to_run.format(
'../legacy/pyroot/file.py'
) +
'" );'
,
'The ROOT File Format'
)
53
bar.AddButton(
'fildir'
,
r'TPython::Exec( "'
+ to_run.format(
'../legacy/pyroot/fildir.py'
) +
'" );'
,
'The ROOT File, Directories and Keys'
)
54
bar.AddButton(
'tree'
,
r'TPython::Exec( "'
+ to_run.format(
'../legacy/pyroot/tree.py'
) +
'" );'
,
'The Tree Data Structure'
)
55
bar.AddButton(
'ntuple1'
,
r'TPython::Exec( "'
+ to_run.format(
'ntuple1.py'
) +
'" );'
,
'Ntuples and Selections'
)
56
bar.AddButton(
'rootmarks'
,
r'TPython::Exec( "'
+ to_run.format(
'../legacy/pyroot/rootmarks.py'
) +
'" );'
,
'Prints an Estimated ROOTMARKS for Your Machine'
)
57
bar.AddSeparator()
# not implemented
58
bar.AddButton(
'make ntuple'
,
r'TPython::Exec( "'
+ to_run.format(
'mrt.py'
) +
'" );'
,
'Convert a text file to an ntuple'
)
59
60
bar.Show()
61
62
ROOT.gROOT.SaveContext()
63
64
65
## wait for input to keep the GUI (which lives on a ROOT event dispatcher) alive
66
if
__name__ ==
'__main__'
:
67
rep =
''
68
while
not
rep
in
[
'q'
,
'Q'
]:
69
# Check if we are in Python 2 or 3
70
if
sys.version_info[0] > 2:
71
rep = input(
'enter "q" to quit: '
)
72
else
:
73
rep = raw_input(
'enter "q" to quit: '
)
74
if
1 < len(rep):
75
rep = rep[0]
tutorials
pyroot
demo.py
ROOT v6-26 - Reference Guide Generated on Mon Sep 11 2023 21:03:03 (GVA Time) using Doxygen 1.9.8