Logo ROOT  
Reference Guide
cheongwadae.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_geom
3/// Drawing the Cheongwadae building which is the Presidential Residence of the Republic of Korea, 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 cheongwadae.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/// \macro_code
14///
15/// \author Hee Jun Shin (s-heejun@hanmail.net), Dept. of Physics, Univ. of Seoul
16
17#include "TGeoManager.h"
18
19void cheongwadae()
20{
21 TGeoManager *geom = new TGeoManager("geom","My first 3D geometry");
22
23 //material
24 TGeoMaterial *vacuum = new TGeoMaterial("vacuum",0,0,0);
25 TGeoMaterial *Fe = new TGeoMaterial("Fe",55.845,26,7.87);
26
27 //creat media
28 TGeoMedium *Air = new TGeoMedium("Vacuum",0,vacuum);
29 TGeoMedium *Iron = new TGeoMedium("Iron",1,Fe);
30
31 //creat volume
32 TGeoVolume *top = geom->MakeBox("top",Air,300,300,300);
33 geom->SetTopVolume(top);
34 geom->SetTopVisible(0);
35 // If you want to see the boundary, please input the number, 1 instead of 0.
36 // Like this, geom->SetTopVisible(1);
37
38char nBlocks[100];
39int N = 0;
40int f=0;
41int di[2]; di[0] = 0; di[1] = 30;
42TGeoVolume *mBlock;
43
44 for(int k=0;k<7;k++){
45 for(int i=0;i<20;i++){
46 sprintf(nBlocks,"f%d_bg%d",f,N++);
47 mBlock = geom->MakeBox(nBlocks, Iron, 0.6,1.8,63);
48 mBlock->SetLineColor(20);
49 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-10.6-(2.6*i),-17.8+(6*k),0));
50
51 sprintf(nBlocks,"f%d_bg%d",f,N++);
52 mBlock = geom->MakeBox(nBlocks, Iron, 0.7,1.8,58);
53 mBlock->SetLineColor(12);
54 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-11.9-(2.6*i),-17.8+(6*k),0));
55 }
56 sprintf(nBlocks,"f%d_bg%d",f,N++);
57 mBlock = geom->MakeBox(nBlocks, Iron, 26,1.2,63);
58 mBlock->SetLineColor(20);
59 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-36,-14.8+(6*k),0));
60 }
61 sprintf(nBlocks,"f%d_bg%d",f,N++);
62 mBlock = geom->MakeBox(nBlocks, Iron, 26,2,63);
63 mBlock->SetLineColor(20);
64 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-36,-21.6,0));
65
66 for(int k=0;k<7;k++){
67 for(int i=0;i<20;i++){
68 sprintf(nBlocks,"f%d_bg%d",f,N++);
69 mBlock = geom->MakeBox(nBlocks, Iron, 0.6,1.8,63);
70 mBlock->SetLineColor(20);
71 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-10.6-(2.6*i),-17.8+(6*k),0));
72 sprintf(nBlocks,"f%d_bg%d",f,N++);
73 mBlock = geom->MakeBox(nBlocks, Iron, 0.7,1.8,58);
74 mBlock->SetLineColor(12);
75 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-11.9-(2.6*i),-17.8+(6*k),0));
76
77 }
78 sprintf(nBlocks,"f%d_bg%d",f,N++);
79 mBlock = geom->MakeBox(nBlocks, Iron, 26,1.2,63);
80 mBlock->SetLineColor(20);
81 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-36,-14.8+(6*k),0));
82 }
83
84 sprintf(nBlocks,"f%d_bg%d",f,N++);
85 mBlock = geom->MakeBox(nBlocks, Iron, 10,22,58);
86 mBlock->SetLineColor(2);
87 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,0,0));
88
89 sprintf(nBlocks,"f%d_bg%d",f,N++);
90 mBlock = geom->MakeBox(nBlocks, Iron, 3.5,8,0.1);
91 mBlock->SetLineColor(13);
92 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(4,-14,60));
93
94 sprintf(nBlocks,"f%d_bg%d",f,N++);
95 mBlock = geom->MakeBox(nBlocks, Iron, 3.5,8,0.1);
96 mBlock->SetLineColor(13);
97 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-4,-14,60));
98
99 sprintf(nBlocks,"f%d_bg%d",f,N++);
100 mBlock = geom->MakeBox(nBlocks, Iron, 10,0.2,0.1);
101 mBlock->SetLineColor(1);
102 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,20,60));
103
104 sprintf(nBlocks,"f%d_bg%d",f,N++);
105 mBlock = geom->MakeBox(nBlocks, Iron, 10,0.2,0.1);
106 mBlock->SetLineColor(1);
107 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,17,60));
108
109 sprintf(nBlocks,"f%d_bg%d",f,N++);
110 mBlock = geom->MakeBox(nBlocks, Iron, 10,0.2,0.1);
111 mBlock->SetLineColor(1);
112 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,14,60));
113
114 sprintf(nBlocks,"f%d_bg%d",f,N++);
115 mBlock = geom->MakeBox(nBlocks, Iron, 10,0.2,0.1);
116 mBlock->SetLineColor(1);
117 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,11,60));
118
119 sprintf(nBlocks,"f%d_bg%d",f,N++);
120 mBlock = geom->MakeBox(nBlocks, Iron, 10,0.2,0.1);
121 mBlock->SetLineColor(1);
122 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,8,60));
123
124 sprintf(nBlocks,"f%d_bg%d",f,N++);
125 mBlock = geom->MakeBox(nBlocks, Iron, 10,0.2,0.1);
126 mBlock->SetLineColor(1);
127 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,5,60));
128
129 sprintf(nBlocks,"f%d_bg%d",f,N++);
130 mBlock = geom->MakeBox(nBlocks, Iron, 10,0.2,0.1);
131 mBlock->SetLineColor(1);
132 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,2,60));
133
134 for(int k=0;k<7;k++){
135 for(int i=0;i<20;i++){
136 sprintf(nBlocks,"f%d_bg%d",f,N++);
137 mBlock = geom->MakeBox(nBlocks, Iron, 0.6,1.8,63);
138 mBlock->SetLineColor(20);
139 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(10.6+(2.6*i),-17.8+(6*k),0));
140 sprintf(nBlocks,"f%d_bg%d",f,N++);
141 mBlock = geom->MakeBox(nBlocks, Iron, 0.7,1.8,58);
142 mBlock->SetLineColor(12);
143 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(11.9+(2.6*i),-17.8+(6*k),0));
144
145 }
146 sprintf(nBlocks,"f%d_bg%d",f,N++);
147 mBlock = geom->MakeBox(nBlocks, Iron, 26,1.2,63);
148 mBlock->SetLineColor(20);
149 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(36,-14.8+(6*k),0));
150 }
151 sprintf(nBlocks,"f%d_bg%d",f,N++);
152 mBlock = geom->MakeBox(nBlocks, Iron, 26,2,63);
153 mBlock->SetLineColor(20);
154 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(36,-21.6,0));
155
156
157 sprintf(nBlocks,"f%d_bg%d",f,N++);
158 mBlock = geom->MakeBox(nBlocks, Iron, 82,2,82);
159 mBlock->SetLineColor(18);
160 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,24,0));
161
162 sprintf(nBlocks,"f%d_bg%d",f,N++);
163 mBlock = geom->MakeBox(nBlocks, Iron, 85,0.5,85);
164 mBlock->SetLineColor(18);
165 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,26,0));
166
167 sprintf(nBlocks,"f%d_bg%d",f,N++);
168 mBlock = geom->MakeBox(nBlocks, Iron, 88,2,88);
169 mBlock->SetLineColor(18);
170 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,-24,0));
171
172
173 sprintf(nBlocks,"f%d_bg%d",f,N++);
174 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 30, 0, 180, 0, 180);
175 mBlock->SetLineColor(32);
176 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,24,0));
177
178 sprintf(nBlocks,"ab%d",N++);
179 mBlock = geom->MakeBox(nBlocks,Iron, 0.1,30,0.1);
180 mBlock->SetLineColor(10);
181 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,40,0));
182
183 sprintf(nBlocks,"ab%d",N++);
184 mBlock = geom->MakeTubs(nBlocks,Iron, 0,30,4,360,360);
185 mBlock->SetLineColor(10);
186 top->AddNodeOverlap(mBlock,1,new TGeoCombiTrans(0,27,0, new TGeoRotation("r1",0,90,0)));
187
188 for(int i=0;i<8;i++){
189 sprintf(nBlocks,"ab%d",N++);
190 mBlock = geom->MakeBox(nBlocks,Iron, 2,22,2);
191 mBlock->SetLineColor(18);
192 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-70+(20*i),0,80));
193 }
194
195 for(int i=0;i<8;i++){
196 sprintf(nBlocks,"ab%d",N++);
197 mBlock = geom->MakeBox(nBlocks,Iron, 2,22,2);
198 mBlock->SetLineColor(18);
199 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-70+(20*i),0,-80));
200 }
201
202 for(int i=0;i<7;i++){
203 sprintf(nBlocks,"ab%d",N++);
204 mBlock = geom->MakeBox(nBlocks,Iron, 2,22,2);
205 mBlock->SetLineColor(18);
206 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-70,0,-80+(23*i)));
207 }
208
209 for(int i=0;i<7;i++){
210 sprintf(nBlocks,"ab%d",N++);
211 mBlock = geom->MakeBox(nBlocks,Iron, 2,22,2);
212 mBlock->SetLineColor(18);
213 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(70,0,-80+(23*i)));
214 }
215
216 sprintf(nBlocks,"f%d_bg%d",f,N++);
217 mBlock = geom->MakeBox(nBlocks, Iron, 100,0.5,160);
218 mBlock->SetLineColor(41);
219 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,-26,40));
220
221 sprintf(nBlocks,"f%d_bg%d",f,N++);
222 mBlock = geom->MakeBox(nBlocks, Iron, 10,0.01,160);
223 mBlock->SetLineColor(19);
224 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,-25,40));
225
226 sprintf(nBlocks,"f%d_bg%d",f,N++);
227 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
228 mBlock->SetLineColor(8);
229 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(15,-22,170));
230
231 sprintf(nBlocks,"f%d_bg%d",f,N++);
232 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
233 mBlock->SetLineColor(8);
234 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(15,-25,170));
235
236 sprintf(nBlocks,"f%d_bg%d",f,N++);
237 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
238 mBlock->SetLineColor(8);
239 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(15,-22,150));
240
241 sprintf(nBlocks,"f%d_bg%d",f,N++);
242 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
243 mBlock->SetLineColor(8);
244 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(15,-25,150));
245
246 sprintf(nBlocks,"f%d_bg%d",f,N++);
247 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
248 mBlock->SetLineColor(8);
249 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(15,-22,130));
250
251 sprintf(nBlocks,"f%d_bg%d",f,N++);
252 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
253 mBlock->SetLineColor(8);
254 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(15,-25,130));
255
256 sprintf(nBlocks,"f%d_bg%d",f,N++);
257 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
258 mBlock->SetLineColor(8);
259 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(15,-22,110));
260
261 sprintf(nBlocks,"f%d_bg%d",f,N++);
262 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
263 mBlock->SetLineColor(8);
264 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(15,-25,110));
265
266 sprintf(nBlocks,"f%d_bg%d",f,N++);
267 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
268 mBlock->SetLineColor(8);
269 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-15,-22,170));
270
271 sprintf(nBlocks,"f%d_bg%d",f,N++);
272 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
273 mBlock->SetLineColor(8);
274 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-15,-25,170));
275
276 sprintf(nBlocks,"f%d_bg%d",f,N++);
277 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
278 mBlock->SetLineColor(8);
279 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-15,-22,150));
280
281 sprintf(nBlocks,"f%d_bg%d",f,N++);
282 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
283 mBlock->SetLineColor(8);
284 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-15,-25,150));
285
286 sprintf(nBlocks,"f%d_bg%d",f,N++);
287 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
288 mBlock->SetLineColor(8);
289 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-15,-22,130));
290
291 sprintf(nBlocks,"f%d_bg%d",f,N++);
292 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
293 mBlock->SetLineColor(8);
294 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-15,-25,130));
295
296 sprintf(nBlocks,"f%d_bg%d",f,N++);
297 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
298 mBlock->SetLineColor(8);
299 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-15,-22,110));
300
301 sprintf(nBlocks,"f%d_bg%d",f,N++);
302 mBlock = geom->MakeSphere(nBlocks, Iron, 0, 5, 0, 180, 0, 180);
303 mBlock->SetLineColor(8);
304 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-15,-25,110));
305
306 sprintf(nBlocks,"ab%d",N++);
307 mBlock = geom->MakeBox(nBlocks,Iron, 0.1,10,0.1);
308 mBlock->SetLineColor(12);
309 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(20,-15,110));
310
311 sprintf(nBlocks,"ab%d",N++);
312 mBlock = geom->MakeBox(nBlocks,Iron, 5,3,0.1);
313 mBlock->SetLineColor(10);
314 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(25,-8,110));
315
316 sprintf(nBlocks,"ab%d",N++);
317 mBlock = geom->MakeBox(nBlocks,Iron, 0.1,10,0.1);
318 mBlock->SetLineColor(12);
319 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-20,-15,110));
320
321 sprintf(nBlocks,"ab%d",N++);
322 mBlock = geom->MakeBox(nBlocks,Iron, 5,3,0.1);
323 mBlock->SetLineColor(10);
324 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(-15,-8,110));
325
326 sprintf(nBlocks,"f%d_bg%d",f,N++);
327 mBlock = geom->MakeBox(nBlocks, Iron, 7,1.5,5);
328 mBlock->SetLineColor(18);
329 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,-24,88));
330
331 sprintf(nBlocks,"f%d_bg%d",f,N++);
332 mBlock = geom->MakeBox(nBlocks, Iron, 7,1,5);
333 mBlock->SetLineColor(18);
334 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,-24,92));
335
336 sprintf(nBlocks,"f%d_bg%d",f,N++);
337 mBlock = geom->MakeBox(nBlocks, Iron, 7,0.5,5);
338 mBlock->SetLineColor(18);
339 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,-24,96));
340
341 sprintf(nBlocks,"f%d_bg%d",f,N++);
342 mBlock = geom->MakeBox(nBlocks, Iron, 7,0.1,5);
343 mBlock->SetLineColor(18);
344 top->AddNodeOverlap(mBlock,1,new TGeoTranslation(0,-24,100));
345
346 geom->CloseGeometry();
347 top->SetVisibility(0);
348
349 top->Draw("ogl");
350}
#define f(i)
Definition: RSha256.hxx:104
#define N
Class describing rotation + translation.
Definition: TGeoMatrix.h:292
The manager class for any TGeo geometry.
Definition: TGeoManager.h:43
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
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:31
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:47
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:995
virtual void Draw(Option_t *option="")
draw top volume according to option
virtual void SetLineColor(Color_t lcolor)
Set the line color.