ROOT   Reference Guide
tank.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_geom
3/// Drawing a fine tank, using ROOT geometry class.
4///
5/// Reviewed by Sunman Kim (sunman98@hanmail.net)
6/// Supervisor: Prof. Inkyu Park (icpark@physics.uos.ac.kr)
7///
8/// How to run: .x tank.C in ROOT terminal, then use OpenGL
9///
10/// This macro was created for the evaluation of Computational Physics course in 2006.
11/// We thank to Prof. Inkyu Park for his special lecture on ROOT and to all of ROOT team
12///
13/// \image html geom_tank.png width=800px
14/// \macro_code
15///
16/// \author Dong Gyu Lee (ravirus@hanmail.net), Dept. of Physics, Univ. of Seoul
17
18#include "TGeoManager.h"
19
20void tank()
21{
22 TGeoManager *geom = new TGeoManager("geom","My 3D Project");
23
24//------------------Creat materials-----------------------------
25 TGeoMaterial *vacuum = new TGeoMaterial("vacuum",0,0,0);
26 TGeoMaterial *Fe = new TGeoMaterial("Fe",55.84,26.7,7.87);
27 TGeoMaterial *Cu = new TGeoMaterial("Cu",63.549,29,8.92);
28
29//------------------Creat media----------------------------------
30 TGeoMedium *Air = new TGeoMedium("Air",0,vacuum);
31 TGeoMedium *Iron = new TGeoMedium("Iron",1,Fe);
32
33//------------------Create TOP volume----------------------------
34 TGeoVolume *top = geom->MakeBox("top",Air,100,100,100);
35 geom->SetTopVolume(top);
36 geom->SetTopVisible(0);
37 // If you want to see the boundary, please input the number, 1 instead of 0.
38 // Like this, geom->SetTopVisible(1);
39
40
41//-----------------Create Object volume--------------------------
42
43
44//Now, we start real shape
45
46//UpperBody
47 TGeoVolume *pl=geom->MakeBox("pl",Iron,210,93,20);
48 pl->SetLineColor(42);
49 TGeoVolume *pl1=geom->MakeBox("pl1",Iron,217,50,5);
50 pl1->SetLineColor(42);
51 TGeoVolume *pl2=geom->MakeTrd2("pl2",Iron,219,150,50,40,10);
52 pl2->SetLineColor(42);
53 TGeoVolume *plu=geom->MakeTrd2("plu",Iron,210,70,100,100,5);
54 plu->SetLineColor(42);
56 TGeoVolume *sp=geom->MakeTubs("sp",Iron,30,40,50,10,60);//Small Plate front
57 sp->SetLineColor(42);
58
59//Top which will have the gun
60 TGeoVolume *tp=geom->MakeSphere("tp",Iron,0,100,67,90,0,360);//tp is Top with gun
61 tp->SetLineColor(12);
62 TGeoVolume *tp1=geom->MakeSphere("tp1",Iron,90,190,0,29,0,360);//tp1 is Top with roof
63 tp1->SetLineColor(12);
64 TGeoVolume *mgg=geom->MakeTubs("mgg",Iron,0,25,30,42,136);//Main Gun Guard
65 mgg->SetLineColor(12);
66 TGeoVolume *mgg1=geom->MakeTrd2("mgg1",Iron,30.5,45,19,30,35);
67 mgg1->SetLineColor(12);
68
71
72//Small Top infront Top
73 TGeoVolume *stp=geom->MakeSphere("stp",Iron,0,30,67,90,0,360);//Top for driver
74 stp->SetLineColor(12);
75 TGeoVolume *stp1=geom->MakeSphere("stp1",Iron,115,120,0,12,0,360);//Top with roof
76 stp1->SetLineColor(12);
77 TGeoVolume *stpo1=geom->MakeBox("stpo1",Iron,3,1,5);
78 stpo1->SetLineColor(42);//Small T P Option 1
79
84
86 TGeoVolume *mg1=geom->MakeCone("mg1",Iron,160,4,5,4,7);
87 mg1->SetLineColor(12);
89 TGeoVolume *mg1o1=geom->MakeCone("mg1o1",Iron,40,4.1,8,4.1,8);
90 mg1o1->SetLineColor(12);//
92
93
94//Underbody
95 TGeoVolume *underbody=geom->MakeTrd2("underbody",Iron,160,210,93,93,30);
96 underbody->SetLineColor(28);
97 TGeoVolume *bs=geom->MakeTubs("bs",Iron,0,20,93,10,270);
98 bs->SetLineColor(42);
99 TGeoVolume *bsp=geom->MakeTubs("bsp",Iron,0,20,30,10,270);
100 bsp->SetLineColor(42);
101
102 TGeoVolume *Tip=geom->MakeCone("Tip",Iron,21,0,24,0,24); //Tip is wheel
103 Tip->SetLineColor(12);
104 TGeoVolume *Tip1=geom->MakeCone("Tip1",Iron,10,23,30,25,30);
105 Tip1->SetLineColor(14);
106 TGeoVolume *Tip2=geom->MakeCone("Tip2",Iron,30,0,7,0,7);
107 Tip2->SetLineColor(42);
108
109 TGeoVolume *wheel=geom->MakeCone("wheel",Iron,30,0,7,0,7);
110 wheel->SetLineColor(42);
111 TGeoVolume *wheel1=geom->MakeCone("wheel1",Iron,21,0,16,0,16); //innner wheel
112 wheel1->SetLineColor(14);
113 TGeoVolume *wheel2=geom->MakeCone("wheel2",Iron,10,15,22,15,22); //outter wheel
114 wheel2->SetLineColor(12);
115
116 TGeoVolume *Tip0=geom->MakeCone("Tip0",Iron,30,0,7,0,7);
117 Tip0->SetLineColor(12);
118 TGeoVolume *Tip01=geom->MakeCone("Tip01",Iron,10,7,10.5,7,10.5);
119 Tip0->SetLineColor(14);
120
122 char name[50];
123 TGeoVolume *WH;//piece of chain
124 TGeoVolume *whp;
125 TGeoVolume *who;
126
127 //consist upper chain
128 for(int i=0;i<26;i++){
129 sprintf(name,"wh%d",i);
130 WH = geom->MakeBox(name,Iron,5.5,22,2);
131 whp = geom->MakeBox(name,Iron,5,2.1,4);
132 who = geom->MakeBox(name,Iron,2,6,1);
133 WH->SetLineColor(12);
134 whp->SetLineColor(14);
135 who->SetLineColor(42);
138
141
146
147 }
148 //chain connector
149 TGeoVolume *WHl = geom->MakeBox(name,Iron,187.5,5,1);
150 WHl->SetLineColor(12);
155
156 //just one side
161
166
171
176
181
186//--------------------------
191
196
197
198 TGeoVolume *chc0=geom->MakeTubs("chc0",Iron,24.5,26.5,5,-34,0);//Small Plate front
199 chc0->SetLineColor(12);
200 TGeoVolume *chc1=geom->MakeTubs("chc1",Iron,24.5,26.5,5,-68,-34);//Small Plate front
201 chc1->SetLineColor(12);
202 TGeoVolume *chc2=geom->MakeTubs("chc2",Iron,24.5,26.5,5,-102,-68);//Small Plate front
203 chc2->SetLineColor(12);
204 TGeoVolume *chc3=geom->MakeTubs("chc3",Iron,24.5,26.5,5,-136,-102);//Small Plate front
205 chc3->SetLineColor(12);
206
211
216
217 TGeoVolume *chcl=geom->MakeBox("chcl",Iron,5,5,1);
218 chcl->SetLineColor(12);
223
228
229 TGeoVolume *chc4=geom->MakeTubs("chc4",Iron,31.5,34.5,5,-175,-145);//Small Plate front
230 chc4->SetLineColor(12);
233
238
243
244
249
254
255
260
265//-------------------------
270
275
276
277 TGeoVolume *chc0i=geom->MakeTubs("chc0i",Iron,24.5,26.5,5,0,34);//Small Plate front
278 chc0i->SetLineColor(12);
279 TGeoVolume *chc1i=geom->MakeTubs("chc1i",Iron,24.5,26.5,5,34,68);//Small Plate front
280 chc1i->SetLineColor(12);
281 TGeoVolume *chc2i=geom->MakeTubs("chc2i",Iron,24.5,26.5,5,68,102);//Small Plate front
282 chc2i->SetLineColor(12);
283 TGeoVolume *chc3i=geom->MakeTubs("chc3i",Iron,24.5,26.5,5,102,136);//Small Plate front
284 chc3i->SetLineColor(12);
285
290
295
300
305
306 TGeoVolume *chc4i=geom->MakeTubs("chc4i",Iron,31.5,33,5,145,175);//Small Plate front
307 chc4i->SetLineColor(12);
310
311
312//just other side
313
314
319
324
329
334
339
344//--------------------------
349
354
355
360
365
370
375
376
381
386
391
396
397
402
407//-------------------------
412
417
418
423
428
433
438
439 //consist under chain
440 for(int i=0;i<20;i++){
441 sprintf(name,"wh%d",i);
444
447
452 }
453 TGeoVolume *WHlu = geom->MakeBox(name,Iron,140,5,1);//chain connetor in under
454 WHlu->SetLineColor(12);
459
460
461
462
463//Now, we put real shape
464
476
477
482
487
492
498
509
515
524
527
532
537
542
548
559
565
574
577 top->SetVisibility(0);
578 geom->CloseGeometry();
579
580
581//------------------draw on GL viewer-------------------------------
582 top->Draw("ogl");
583
584}
char name[80]
Definition: TGX11.cxx:110
double cos(double)
double sin(double)
Class describing rotation + translation.
Definition: TGeoMatrix.h:292
The manager class for any TGeo geometry.
Definition: TGeoManager.h:45
TGeoVolume * MakeCone(const char *name, TGeoMedium *medium, Double_t dz, Double_t rmin1, Double_t rmax1, Double_t rmin2, Double_t rmax2)
Make in one step a volume pointing to a cone shape with given medium.
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
TGeoVolume * MakeTrd2(const char *name, TGeoMedium *medium, Double_t dx1, Double_t dx2, Double_t dy1, Double_t dy2, Double_t dz)
Make in one step a volume pointing to a TGeoTrd2 shape with given medium.
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.
TGeoVolume * MakeSphere(const char *name, TGeoMedium *medium, Double_t rmin, Double_t rmax, Double_t themin=0, Double_t themax=180, Double_t phimin=0, Double_t phimax=360)
Make in one step a volume pointing to a sphere shape with given medium.
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
void SetTopVisible(Bool_t vis=kTRUE)
make top volume visible on screen
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.
Base class describing materials.
Definition: TGeoMaterial.h:36
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition: TGeoMedium.h:24
Class describing rotations.
Definition: TGeoMatrix.h:175
Class describing translations.
Definition: TGeoMatrix.h:122
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:49
virtual void SetVisibility(Bool_t vis=kTRUE)
set visibility of this volume
virtual void AddNodeOverlap(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a TGeoNode to the list of nodes.
Definition: TGeoVolume.cxx:997
virtual void Draw(Option_t *option="")
draw top volume according to option
virtual void SetLineColor(Color_t lcolor)
Set the line color.