Logo ROOT  
Reference Guide
shapes.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_pyroot
3## \notebook
4## Draw the geometry using the x3d viewver.
5## Note that this viewver may also be invoked from the "View" menu in
6## the canvas tool bar
7##
8## once in x3d viewer, type m to see the menu.
9## For example typing r will show a solid model of this geometry.
10##
11## \macro_code
12##
13## \author Wim Lavrijsen
14
15import ROOT
16
17c1 = ROOT.TCanvas( 'c1', 'Geometry Shapes', 200, 10, 700, 500 )
18
19# delete previous geometry objects in case this script is reexecuted
20if hasattr(ROOT, 'gGeometry') and ROOT.gGeometry:
21 ROOT.gGeometry.GetListOfNodes().Delete()
22 ROOT.gGeometry.GetListOfShapes().Delete()
23
24# Define some volumes
25brik = ROOT.TBRIK( 'BRIK', 'BRIK', 'void', 200, 150, 150 )
26trd1 = ROOT.TTRD1( 'TRD1', 'TRD1', 'void', 200, 50, 100, 100 )
27trd2 = ROOT.TTRD2( 'TRD2', 'TRD2', 'void', 200, 50, 200, 50, 100 )
28trap = ROOT.TTRAP( 'TRAP', 'TRAP', 'void', 190, 0, 0, 60, 40, 90, 15, 120, 80, 180, 15 )
29para = ROOT.TPARA( 'PARA', 'PARA', 'void', 100, 200, 200, 15, 30, 30 )
30gtra = ROOT.TGTRA( 'GTRA', 'GTRA', 'void', 390, 0, 0, 20, 60, 40, 90, 15, 120, 80, 180, 15 )
31tube = ROOT.TTUBE( 'TUBE', 'TUBE', 'void', 150, 200, 400 )
32tubs = ROOT.TTUBS( 'TUBS', 'TUBS', 'void', 80, 100, 100, 90, 235 )
33cone = ROOT.TCONE( 'CONE', 'CONE', 'void', 100, 50, 70, 120, 150 )
34cons = ROOT.TCONS( 'CONS', 'CONS', 'void', 50, 100, 100, 200, 300, 90, 270 )
35sphe = ROOT.TSPHE( 'SPHE', 'SPHE', 'void', 25, 340, 45, 135, 0, 270 )
36sphe1 = ROOT.TSPHE( 'SPHE1', 'SPHE1', 'void', 0, 140, 0, 180, 0, 360 )
37sphe2 = ROOT.TSPHE( 'SPHE2', 'SPHE2', 'void', 0, 200, 10, 120, 45, 145 )
38
39pcon = ROOT.TPCON( 'PCON', 'PCON', 'void', 180, 270, 4 )
40pcon.DefineSection( 0, -200, 50, 100 )
41pcon.DefineSection( 1, -50, 50, 80 )
42pcon.DefineSection( 2, 50, 50, 80 )
43pcon.DefineSection( 3, 200, 50, 100 )
44
45pgon = ROOT.TPGON( 'PGON', 'PGON', 'void', 180, 270, 8, 4 )
46pgon.DefineSection( 0, -200, 50, 100 )
47pgon.DefineSection( 1, -50, 50, 80 )
48pgon.DefineSection( 2, 50, 50, 80 )
49pgon.DefineSection( 3, 200, 50, 100 )
50
51# Set shapes attributes
52brik.SetLineColor( 1 )
53trd1.SetLineColor( 2 )
54trd2.SetLineColor( 3 )
55trap.SetLineColor( 4 )
56para.SetLineColor( 5 )
57gtra.SetLineColor( 7 )
58tube.SetLineColor( 6 )
59tubs.SetLineColor( 7 )
60cone.SetLineColor( 2 )
61cons.SetLineColor( 3 )
62pcon.SetLineColor( 6 )
63pgon.SetLineColor( 2 )
64sphe.SetLineColor( ROOT.kRed )
65sphe1.SetLineColor( ROOT.kBlack )
66sphe2.SetLineColor( ROOT.kBlue )
67
68# Build the geometry hierarchy
69node1 = ROOT.TNode( 'NODE1', 'NODE1', 'BRIK' )
70node1.cd()
71
72node2 = ROOT.TNode( 'NODE2', 'NODE2', 'TRD1', 0, 0, -1000 )
73node3 = ROOT.TNode( 'NODE3', 'NODE3', 'TRD2', 0, 0, 1000 )
74node4 = ROOT.TNode( 'NODE4', 'NODE4', 'TRAP', 0, -1000, 0 )
75node5 = ROOT.TNode( 'NODE5', 'NODE5', 'PARA', 0, 1000, 0 )
76node6 = ROOT.TNode( 'NODE6', 'NODE6', 'TUBE', -1000, 0, 0 )
77node7 = ROOT.TNode( 'NODE7', 'NODE7', 'TUBS', 1000, 0, 0 )
78node8 = ROOT.TNode( 'NODE8', 'NODE8', 'CONE', -300, -300, 0 )
79node9 = ROOT.TNode( 'NODE9', 'NODE9', 'CONS', 300, 300, 0 )
80node10 = ROOT.TNode( 'NODE10', 'NODE10', 'PCON', 0, -1000, -1000 )
81node11 = ROOT.TNode( 'NODE11', 'NODE11', 'PGON', 0, 1000, 1000 )
82node12 = ROOT.TNode( 'NODE12', 'NODE12', 'GTRA', 0, -400, 700 )
83node13 = ROOT.TNode( 'NODE13', 'NODE13', 'SPHE', 10, -400, 500 )
84node14 = ROOT.TNode( 'NODE14', 'NODE14', 'SPHE1', 10, 250, 300 )
85node15 = ROOT.TNode( 'NODE15', 'NODE15', 'SPHE2', 10, -100, -200 )
86
87# for memory management
88list_of_locals = dict(locals())
89for l, o in list_of_locals.items():
90 if isinstance( o, ROOT.TShape ) or isinstance( o, ROOT.TNode ):
91 ROOT.SetOwnership( o, False )
92
93# Draw this geometry in the current canvas
94node1.cd()
95node1.Draw( 'gl' )
96c1.Update()