ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rootgeom.C
Go to the documentation of this file.
1 void rootgeom()
2 {
3 //Definition of a simple geometry (the 4 ROOT characters)
4 //Author: Andrei Gheata
5 
6  // gStyle->SetCanvasPreferGL(true);
7  gSystem->Load("libGeom");
8  TGeoManager *geom = new TGeoManager("simple1", "Simple geometry");
9 
10  //--- define some materials
11  TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0);
12  TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7);
13 // //--- define some media
14  TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum);
15  TGeoMedium *Al = new TGeoMedium("Root Material",2, matAl);
16 
17  //--- define the transformations
18  TGeoTranslation *tr1 = new TGeoTranslation(20., 0, 0.);
19  TGeoTranslation *tr2 = new TGeoTranslation(10., 0., 0.);
20  TGeoTranslation *tr3 = new TGeoTranslation(10., 20., 0.);
21  TGeoTranslation *tr4 = new TGeoTranslation(5., 10., 0.);
22  TGeoTranslation *tr5 = new TGeoTranslation(20., 0., 0.);
23  TGeoTranslation *tr6 = new TGeoTranslation(-5., 0., 0.);
24  TGeoTranslation *tr7 = new TGeoTranslation(7.5, 7.5, 0.);
25  TGeoRotation *rot1 = new TGeoRotation("rot1", 90., 0., 90., 270., 0., 0.);
26  TGeoCombiTrans *combi1 = new TGeoCombiTrans(7.5, -7.5, 0., rot1);
27  TGeoTranslation *tr8 = new TGeoTranslation(7.5, -5., 0.);
28  TGeoTranslation *tr9 = new TGeoTranslation(7.5, 20., 0.);
29  TGeoTranslation *tr10 = new TGeoTranslation(85., 0., 0.);
30  TGeoTranslation *tr11 = new TGeoTranslation(35., 0., 0.);
31  TGeoTranslation *tr12 = new TGeoTranslation(-15., 0., 0.);
32  TGeoTranslation *tr13 = new TGeoTranslation(-65., 0., 0.);
33 
34  TGeoTranslation *tr14 = new TGeoTranslation(0,0,-100);
35  TGeoCombiTrans *combi2 = new TGeoCombiTrans(0,0,100,
36  new TGeoRotation("rot2",90,180,90,90,180,0));
37  TGeoCombiTrans *combi3 = new TGeoCombiTrans(100,0,0,
38  new TGeoRotation("rot3",90,270,0,0,90,180));
39  TGeoCombiTrans *combi4 = new TGeoCombiTrans(-100,0,0,
40  new TGeoRotation("rot4",90,90,0,0,90,0));
41  TGeoCombiTrans *combi5 = new TGeoCombiTrans(0,100,0,
42  new TGeoRotation("rot5",0,0,90,180,90,270));
43  TGeoCombiTrans *combi6 = new TGeoCombiTrans(0,-100,0,
44  new TGeoRotation("rot6",180,0,90,180,90,90));
45 
46  //--- make the top container volume
47  Double_t worldx = 110.;
48  Double_t worldy = 50.;
49  Double_t worldz = 5.;
50  TGeoVolume *top = geom->MakeBox("TOP", Vacuum, 270., 270., 120.);
51  geom->SetTopVolume(top);
52  TGeoVolume *replica = geom->MakeBox("REPLICA", Vacuum,120,120,120);
53  replica->SetVisibility(kFALSE);
54  TGeoVolume *rootbox = geom->MakeBox("ROOT", Vacuum, 110., 50., 5.);
55  rootbox->SetVisibility(kFALSE);
56 
57  //--- make letter 'R'
58  TGeoVolume *R = geom->MakeBox("R", Vacuum, 25., 25., 5.);
60  TGeoVolume *bar1 = geom->MakeBox("bar1", Al, 5., 25, 5.);
61  bar1->SetLineColor(kRed);
62  R->AddNode(bar1, 1, tr1);
63  TGeoVolume *bar2 = geom->MakeBox("bar2", Al, 5., 5., 5.);
64  bar2->SetLineColor(kRed);
65  R->AddNode(bar2, 1, tr2);
66  R->AddNode(bar2, 2, tr3);
67  TGeoVolume *tub1 = geom->MakeTubs("tub1", Al, 5., 15., 5., 90., 270.);
68  tub1->SetLineColor(kRed);
69  R->AddNode(tub1, 1, tr4);
70  TGeoVolume *bar3 = geom->MakeArb8("bar3", Al, 5.);
71  bar3->SetLineColor(kRed);
72  TGeoArb8 *arb = (TGeoArb8*)bar3->GetShape();
73  arb->SetVertex(0, 15., -5.);
74  arb->SetVertex(1, 0., -25.);
75  arb->SetVertex(2, -10., -25.);
76  arb->SetVertex(3, 5., -5.);
77  arb->SetVertex(4, 15., -5.);
78  arb->SetVertex(5, 0., -25.);
79  arb->SetVertex(6, -10., -25.);
80  arb->SetVertex(7, 5., -5.);
81  R->AddNode(bar3, 1, gGeoIdentity);
82 
83  //--- make letter 'O'
84  TGeoVolume *O = geom->MakeBox("O", Vacuum, 25., 25., 5.);
86  TGeoVolume *bar4 = geom->MakeBox("bar4", Al, 5., 7.5, 5.);
87  bar4->SetLineColor(kYellow);
88  O->AddNode(bar4, 1, tr5);
89  O->AddNode(bar4, 2, tr6);
90  TGeoVolume *tub2 = geom->MakeTubs("tub1", Al, 7.5, 17.5, 5., 0., 180.);
91  tub2->SetLineColor(kYellow);
92  O->AddNode(tub2, 1, tr7);
93  O->AddNode(tub2, 2, combi1);
94 
95  //--- make letter 'T'
96  TGeoVolume *T = geom->MakeBox("T", Vacuum, 25., 25., 5.);
98  TGeoVolume *bar5 = geom->MakeBox("bar5", Al, 5., 20., 5.);
99  bar5->SetLineColor(kBlue);
100  T->AddNode(bar5, 1, tr8);
101  TGeoVolume *bar6 = geom->MakeBox("bar6", Al, 17.5, 5., 5.);
102  bar6->SetLineColor(kBlue);
103  T->AddNode(bar6, 1, tr9);
104 
105 
106 
107  rootbox->AddNode(R, 1, tr10);
108  rootbox->AddNode(O, 1, tr11);
109  rootbox->AddNode(O, 2, tr12);
110  rootbox->AddNode(T, 1, tr13);
111 
112  replica->AddNode(rootbox, 1, tr14);
113  replica->AddNode(rootbox, 2, combi2);
114  replica->AddNode(rootbox, 3, combi3);
115  replica->AddNode(rootbox, 4, combi4);
116  replica->AddNode(rootbox, 5, combi5);
117  replica->AddNode(rootbox, 6, combi6);
118 
119  top->AddNode(replica, 1, new TGeoTranslation(-150, -150, 0));
120  top->AddNode(replica, 2, new TGeoTranslation(150, -150, 0));
121  top->AddNode(replica, 3, new TGeoTranslation(150, 150, 0));
122  top->AddNode(replica, 4, new TGeoTranslation(-150, 150, 0));
123 
124  //--- close the geometry
125  geom->CloseGeometry();
126 
127  //--- draw the ROOT box.
128  // by default the picture will appear in the standard ROOT TPad.
129  //if you have activated the following line in system.rootrc,
130  //it will appear in the GL viewer
131  //#Viewer3D.DefaultDrawOption: ogl
132 
133  geom->SetVisLevel(4);
134  top->Draw("ogle");
135 }
136 
Definition: Rtypes.h:61
virtual void Draw(Option_t *option="")
draw top volume according to option
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1766
const Bool_t kFALSE
Definition: Rtypes.h:92
Definition: Rtypes.h:61
TTree * T
TGeoVolume * MakeBox(const char *name, TGeoMedium *medium, Double_t dx, Double_t dy, Double_t dz)
Make in one step a volume pointing to a box shape with given medium.
virtual void SetVertex(Int_t vnum, Double_t x, Double_t y)
Set values for a given vertex.
Definition: TGeoArb8.cxx:1210
TGeoVolume * MakeArb8(const char *name, TGeoMedium *medium, Double_t dz, Double_t *vertices=0)
Make an TGeoArb8 volume.
virtual void AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a TGeoNode to the list of nodes.
Definition: TGeoVolume.cxx:948
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
void rootgeom()
Definition: rootgeom.C:1
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
TGeoShape * GetShape() const
Definition: TGeoVolume.h:204
TGeoVolume * MakeTubs(const char *name, TGeoMedium *medium, Double_t rmin, Double_t rmax, Double_t dz, Double_t phi1, Double_t phi2)
Make in one step a volume pointing to a tube segment shape with given medium.
double Double_t
Definition: RtypesCore.h:55
virtual void SetVisibility(Bool_t vis=kTRUE)
set visibility of this volume
virtual void SetLineColor(Color_t lcolor)
Set the line color.
R__EXTERN TGeoIdentity * gGeoIdentity
Definition: TGeoMatrix.h:466
void SetVisLevel(Int_t level=3)
set default level down to which visualization is performed
Definition: Rtypes.h:61
TRandom3 R
a TMatrixD.
Definition: testIO.cxx:28