ROOT   Reference Guide
lego.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_geom
3/// Drawing a figure, made of lego block, 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 lego.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_lego.png width=800px
14/// \macro_code
15///
16/// \author Soon Gi Kwon(1116won@hanmail.net), Dept. of Physics, Univ. of Seoul
17
18#include "TSystem.h"
19#include "TGeoManager.h"
20
21void lego()
22{
23 TGeoManager *geom = new TGeoManager("geom","My first 3D geometry");
24
25
26 TGeoMaterial *vacuum=new TGeoMaterial("vacuum",0,0,0);
27 TGeoMaterial *Fe=new TGeoMaterial("Fe",55.845,26,7.87);
28
29
30
31 TGeoMedium *Air=new TGeoMedium("Vacuum",0,vacuum);
32 TGeoMedium *Iron=new TGeoMedium("Iron",1,Fe);
33
34
35 // create volume
36 TGeoVolume *top=geom->MakeBox("top",Air,100,100,100);
37 geom->SetTopVolume(top);
38 geom->SetTopVisible(0);
39 // If you want to see the boundary, please input the number, 1 instead of 0.
40 // Like this, geom->SetTopVisible(1);
41
42//----------------------------------------------------------------------
43
44 TGeoVolume *ha1=geom->MakeSphere("ha1",Iron,0,10,80,90,0,360);
45 ha1->SetLineColor(41);
47
48 TGeoVolume *ha2=geom->MakeSphere("ha2",Iron,0,7,90,180,0,360);
49 ha2->SetLineColor(41);
51
52 TGeoVolume *ha3=geom->MakeSphere("ha3",Iron,0,7.3,80,90,0,360);
53 ha3->SetLineColor(2);
55
56
57 TGeoVolume *h1=geom->MakeTubs("h1",Iron,0,6,4.5,0,0);
58 h1->SetLineColor(5);
60
61 TGeoVolume *h2=geom->MakeSphere("h2",Iron,0,7.5,0,52.5,0,360);
62 h2->SetLineColor(5);
64
65 TGeoVolume *h3=geom->MakeSphere("h3",Iron,0,7.5,0,52.5,0,360);
66 h3->SetLineColor(5);
68
69 TGeoVolume *h4=geom->MakeTubs("h4",Iron,2.5,3.5,1.5,0,0);
70 h4->SetLineColor(5);
72
73
74
75 TGeoVolume *t1_1=geom->MakeTubs("t1_1",Iron,0,0.8,1,0,360);
76 t1_1->SetLineColor(12);
78
79 TGeoVolume *t2_1=geom->MakeTubs("t2_1",Iron,0,0.8,1,0,360);
80 t2_1->SetLineColor(12);
82
83 TGeoVolume *fb1=geom->MakeTubs("fb1",Iron,2,2.3,1,100,260);
84 fb1->SetLineColor(12);
86
87
88
89 TGeoVolume *m1=geom->MakeBox("m1",Iron,7,8,4);
90 m1->SetLineColor(2);
92
93 TGeoVolume *m2=geom->MakeTubs("m2",Iron,0,1,7,90,180);
94 m2->SetLineColor(2);
96
97 TGeoVolume *m3=geom->MakeTubs("m3",Iron,0,1,7,0,90);
98 m3->SetLineColor(2);
100
101 TGeoVolume *m4=geom->MakeBox("m4",Iron,3,7,0.5);
102 m4->SetLineColor(2);
104
105 TGeoVolume *m5=geom->MakeTubs("m5",Iron,0,1.5,1.2,0,0);
106 m5->SetLineColor(5);
108
109 TGeoVolume *m6=geom->MakeTrd2("m6",Iron,4,4,0,2,8);
110 m6->SetLineColor(2);
112
113 TGeoVolume *m7=geom->MakeTrd2("m7",Iron,4,4,0,2,8);
114 m7->SetLineColor(2);
116
117
118 TGeoVolume *md1=geom->MakeBox("md1",Iron,4,8.5,0.7);
119 md1->SetLineColor(37);
121
122 TGeoVolume *md2=geom->MakeBox("md2",Iron,3,0.4,2);
123 md2->SetLineColor(37);
125
126 TGeoVolume *d1=geom->MakeTrd2("d1",Iron,3,4,4,4,7);
127 d1->SetLineColor(37);
129
130 TGeoVolume *d2=geom->MakeTrd2("d2",Iron,3,4,4,4,7);
131 d2->SetLineColor(37);
133
134 TGeoVolume *d3=geom->MakeTubs("d3",Iron,0,4,3.98,0,180);
135 d3->SetLineColor(37);
137
138 TGeoVolume *d4=geom->MakeTubs("d4",Iron,0,4,3.98,0,180);
139 d4->SetLineColor(37);
141
142 TGeoVolume *d5=geom->MakeBox("d5",Iron,4,4,1);
143 d5->SetLineColor(37);
145
146 TGeoVolume *d6=geom->MakeBox("d6",Iron,4,4,1);
147 d6->SetLineColor(37);
149
150
151
152 TGeoVolume *a1=geom->MakeTubs("a1",Iron,0,1.5,4,0,0);
153 a1->SetLineColor(1);
155
156 TGeoVolume *a2=geom->MakeSphere("a2",Iron,0,1.48,0,180,0,200);
157 a2->SetLineColor(1);
159
160 TGeoVolume *a3=geom->MakeTubs("a3",Iron,0,1.5,2.2,0,0);
161 a3->SetLineColor(1);
163
164 TGeoVolume *a4=geom->MakeTubs("a4",Iron,0,1,1,0,0);
165 a4->SetLineColor(5);
167
168 TGeoVolume *a5=geom->MakeTubs("a5",Iron,1.5,2.5,2,0,270);
169 a5->SetLineColor(5);
171
172
173
174
175 TGeoVolume *a1_1=geom->MakeTubs("a1_1",Iron,0,1.5,4,0,0);
176 a1_1->SetLineColor(1);
178
179 TGeoVolume *a2_1=geom->MakeSphere("a2_1",Iron,0,1.48,0,180,0,200);
180 a2_1->SetLineColor(1);
182
183 TGeoVolume *a3_1=geom->MakeTubs("a3_1",Iron,0,1.5,2.2,0,0);
184 a3_1->SetLineColor(1);
186
187 TGeoVolume *a4_1=geom->MakeTubs("a4_1",Iron,0,1,1,0,0);
188 a4_1->SetLineColor(5);
190
191 a5=geom->MakeTubs("a5_1",Iron,1.5,2.5,2,0,270);
192 a5->SetLineColor(5);
194
195
196 //**********************************NO,2******************
197
198
199 TGeoVolume *ha_1=geom->MakeSphere("ha_1",Iron,0,10,80,90,0,360);
200 ha_1->SetLineColor(6);
202
203 TGeoVolume *ha_2=geom->MakeTubs("ha_2",Iron,0,6,5,0,0);
204 ha_2->SetLineColor(6);
206
207 TGeoVolume *ha_3=geom->MakeTubs("ha_3",Iron,0,1,12,0,0);
208 ha_3->SetLineColor(28);
210
211 TGeoVolume *ha_4=geom->MakeTubs("ha_4",Iron,0,1,3,0,0);
212 ha_4->SetLineColor(28);
214
215 TGeoVolume *ha_5=geom->MakeTubs("ha_5",Iron,0,1,3,0,0);
216 ha_5->SetLineColor(28);
218
219 TGeoVolume *ha_6=geom->MakeTubs("ha_6",Iron,0,1,3,0,0);
220 ha_6->SetLineColor(28);
222
223 TGeoVolume *ha_7=geom->MakeTubs("ha_7",Iron,0,1,3,0,0);
224 ha_7->SetLineColor(28);
226
227 TGeoVolume *ha_8=geom->MakeBox("ha_8",Iron,2,0.5,2);
228 ha_8->SetLineColor(19);
230
231
232 TGeoVolume *ha_9=geom->MakeBox("ha_9",Iron,2,0.5,2);
233 ha_9->SetLineColor(19);
235
236
237
238 TGeoVolume *h_1=geom->MakeTubs("h_1",Iron,0,6,4.5,0,0);
239 h_1->SetLineColor(5);
241
242 TGeoVolume *h_2=geom->MakeSphere("h_2",Iron,0,7.5,0,52.5,0,360);
243 h_2->SetLineColor(5);
245
246 TGeoVolume *h_3=geom->MakeSphere("h_3",Iron,0,7.5,0,52.5,0,360);
247 h_3->SetLineColor(5);
249
250 TGeoVolume *h_4=geom->MakeTubs("h_4",Iron,2.5,3.5,1.5,0,0);
251 h_4->SetLineColor(5);
253
254
255 TGeoVolume *fa1=geom->MakeTubs("fa1",Iron,0,0.5,1,0,360);
256 fa1->SetLineColor(12);
258
259 TGeoVolume *fa2=geom->MakeTubs("fa2",Iron,0,0.5,1,0,360);
260 fa2->SetLineColor(12);
262
263 TGeoVolume *fa1_1=geom->MakeTubs("fa1_1",Iron,1,1.2,1,0,360);
264 fa1_1->SetLineColor(12);
266
267 TGeoVolume *fa2_1=geom->MakeTubs("fa2_1",Iron,1,1.2,1,0,360);
268 fa2_1->SetLineColor(12);
270
271 TGeoVolume *fa3=geom->MakeTubs("fa3",Iron,2,2.3,1,90,270);
272 fa3->SetLineColor(12);
274
275
276
277 TGeoVolume *m_1=geom->MakeBox("m_1",Iron,7,8,4);
278 m_1->SetLineColor(25);
280
281 TGeoVolume *m_2=geom->MakeTubs("m_2",Iron,0,1,7,90,180);
282 m_2->SetLineColor(25);
284
285 TGeoVolume *m_3=geom->MakeTubs("m_3",Iron,0,1,7,0,90);
286 m_3->SetLineColor(25);
288
289 TGeoVolume *m_4=geom->MakeBox("m_4",Iron,3,7,0.5);
290 m_4->SetLineColor(25);
292
293 TGeoVolume *m_5=geom->MakeTubs("m_5",Iron,0,1.5,1.2,0,0);
294 m_5->SetLineColor(5);
296
297 TGeoVolume *m_6=geom->MakeTrd2("m_6",Iron,4,4,0,2,8);
298 m_6->SetLineColor(25);
300
301 TGeoVolume *m_7=geom->MakeTrd2("m_7",Iron,4,4,0,2,8);
302 m_7->SetLineColor(25);
304
305
306 TGeoVolume *md_1=geom->MakeBox("md_1",Iron,4,8.5,0.7);
307 md_1->SetLineColor(48);
309
310 TGeoVolume *md_2=geom->MakeBox("md_2",Iron,3,0.4,2);
311 md_2->SetLineColor(48);
313
314 TGeoVolume *d_1=geom->MakeTrd2("d_1",Iron,3,4,4,4,7);
315 d_1->SetLineColor(48);
317
318 TGeoVolume *d_2=geom->MakeTrd2("d_2",Iron,3,4,4,4,7);
319 d_2->SetLineColor(48);
321
322 TGeoVolume *d_3=geom->MakeTubs("d_3",Iron,0,4,3.98,0,180);
323 d_3->SetLineColor(48);
325
326 TGeoVolume *d_4=geom->MakeTubs("d_4",Iron,0,4,3.98,0,180);
327 d_4->SetLineColor(48);
329
330 TGeoVolume *d_5=geom->MakeBox("d_5",Iron,4,4,1);
331 d_5->SetLineColor(48);
333
334 TGeoVolume *d_6=geom->MakeBox("d_6",Iron,4,4,1);
335 d_6->SetLineColor(48);
337
338
339 TGeoVolume *a_1=geom->MakeTubs("a_1",Iron,0,1.5,4,0,0);
340 a_1->SetLineColor(45);
342
343 TGeoVolume *a_2=geom->MakeSphere("a_2",Iron,0,1.48,0,180,0,200);
344 a_2->SetLineColor(45);
346
347 TGeoVolume *a_3=geom->MakeTubs("a_3",Iron,0,1.5,2.2,0,0);
348 a_3->SetLineColor(45);
350
351 TGeoVolume *a_4=geom->MakeTubs("a_4",Iron,0,1,1,0,0);
352 a_4->SetLineColor(12);
354
355 TGeoVolume *a_5=geom->MakeTubs("a_5",Iron,1.5,2.5,2,0,270);
356 a_5->SetLineColor(12);
358
359
360
361
362 TGeoVolume *Aa1=geom->MakeTubs("Aa1",Iron,0,1.5,4,0,0);
363 Aa1->SetLineColor(45);
365
366 TGeoVolume *Aa2=geom->MakeSphere("Aa2",Iron,0,1.48,0,180,0,200);
367 Aa2->SetLineColor(45);
369
370 TGeoVolume *Aa3=geom->MakeTubs("Aa3",Iron,0,1.5,2.2,0,0);
371 Aa3->SetLineColor(45);
373
374 TGeoVolume *Aa4=geom->MakeTubs("Aa4",Iron,0,1,1,0,0);
375 Aa4->SetLineColor(12);
377
378 TGeoVolume *Aa5=geom->MakeTubs("Aa5",Iron,1.5,2.5,2,0,270);
379 Aa5->SetLineColor(12);
381
382
383
384 TGeoVolume *bag1=geom->MakeBox("bag1",Iron,10,4,6);
385 bag1->SetLineColor(19);
387
388 TGeoVolume *bag2=geom->MakeTubs("bag2",Iron,3,4,1,180,360);
389 bag2->SetLineColor(19);
391
392
393 TGeoVolume *well=geom->MakeBox("well",Iron,5,10,3);
394 well->SetLineColor(18);
396
397
398 TGeoVolume *K5=geom->MakeTubs("K5",Iron,0,3,3,0,0);
399 K5->SetLineColor(18);
401
402 TGeoVolume *K4=geom->MakeTubs("K4",Iron,0,3,3,0,0);
403 K4->SetLineColor(18);
405
406
407
408 //==============Board=========
409 char nB[100];
410 int Z=0,Y=0;
411 TGeoVolume *bo1;
412
413 while(Y<6){
414 while(Z<10){
415 sprintf(nB,"B%d_Y%d",Z,Y);
416 bo1=geom->MakeTubs(nB,Iron,0,3,3,0,0);
417 bo1->SetLineColor(8);
419 Z++;
420 }
421 Y++; Z=0;
422 }
423
424
425 TGeoVolume *bo2=geom->MakeBox("bo2",Iron,27,45,3);
426 bo2->SetLineColor(8);
428
429
430 top->SetVisibility(0);
431 geom->CloseGeometry();
432
433 top->Draw("ogl");
434}
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
Class describing rotation + translation.
Definition: TGeoMatrix.h:292
The manager class for any TGeo geometry.
Definition: TGeoManager.h:45
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
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:49
virtual void AddNodeOverlap(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=nullptr, Option_t *option="")
Add a TGeoNode to the list of nodes.
Definition: TGeoVolume.cxx:997
virtual void SetVisibility(Bool_t vis=kTRUE)
set visibility of this volume
virtual void Draw(Option_t *option="")
draw top volume according to option
virtual void SetLineColor(Color_t lcolor)
Set the line color.
void lego()
Definition: lego.C:31
TH1F * h1
Definition: legend1.C:5
static constexpr double m3
static constexpr double m2