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