660eb9a2 |
1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * |
3 | * * |
4 | * Author: The ALICE Off-line Project. * |
5 | * Contributors are mentioned in the code where appropriate. * |
6 | * * |
7 | * Permission to use, copy, modify and distribute this software and its * |
8 | * documentation strictly for non-commercial purposes is hereby granted * |
9 | * without fee, provided that the above copyright notice appears in all * |
10 | * copies and that both the copyright notice and this permission notice * |
11 | * appear in the supporting documentation. The authors make no claims * |
12 | * about the suitability of this software for any purpose. It is * |
13 | * provided "as is" without express or implied warranty. * |
14 | **************************************************************************/ |
15 | |
16 | /* |
17 | $Log$ |
b7fab4b5 |
18 | |
19 | Revision 1.3 2001/10/31 15:56:54 morsch |
20 | Correction in OnionCone. |
21 | |
38e826ad |
22 | Revision 1.2 2000/10/10 06:40:25 hristov |
23 | Bug fixes |
24 | |
886e839a |
25 | Revision 1.1 2000/07/26 15:10:57 morsch |
26 | Helper class to write geometry in ALIFE format in parallel with Geant geometry definition. |
27 | |
660eb9a2 |
28 | */ |
29 | |
30 | #include <AliALIFE.h> |
31 | |
32 | ClassImp(AliALIFE) |
33 | |
34 | AliALIFE::AliALIFE(const char* file1, const char* file2) |
35 | { |
36 | // Constructor |
37 | fNBodies = 0; |
38 | fNVolumes= 0; |
39 | fBodyFile = file1; // File for Fluka bodies |
40 | fVolumeFile = file2; |
41 | fFile1=fopen(fBodyFile,"w"); |
42 | fFile2=fopen(fVolumeFile,"w"); |
43 | BodyHeader(); |
44 | VolumeHeader(); |
45 | fDefaultVolume1 = "DEFAU1"; |
46 | fDefaultVolume2 = "DEFAU2"; |
47 | } |
48 | |
49 | AliALIFE::AliALIFE() |
50 | { |
51 | // Default constructor |
52 | fBodyFile = "FlukaBody.inp"; |
53 | fVolumeFile = "FlukaVolume.inp"; |
54 | fFile1=fopen(fBodyFile,"w"); |
55 | fFile2=fopen(fVolumeFile,"w"); |
56 | BodyHeader(); |
57 | VolumeHeader(); |
58 | } |
59 | |
60 | void AliALIFE::BodyHeader() |
61 | { |
62 | // Write header for body definitions |
63 | fprintf(fFile1,"*\n"); |
64 | fprintf(fFile1,"GEOBEGIN COMBINAT\n"); |
65 | fprintf(fFile1," 0 0 AliRoot Generated\n"); |
66 | fprintf(fFile1,"*\n"); |
67 | fprintf(fFile1,"*== Body Definitions ================================================\n"); |
68 | fprintf(fFile1,"*\n"); |
69 | |
70 | } |
71 | |
72 | |
73 | void AliALIFE::VolumeHeader() |
74 | { |
75 | // Write header for region (volume) definitions |
76 | fprintf(fFile2,"REGIONS\n"); |
77 | fprintf(fFile2,"*\n"); |
78 | fprintf(fFile2,"*== Region Definitions =================================================\n"); |
79 | fprintf(fFile2,"*\n"); |
80 | } |
81 | |
82 | |
83 | void AliALIFE:: Cylinder(Float_t rmin, Float_t rmax, |
84 | Float_t zmin, Float_t zmax, |
85 | Float_t pos[3], |
86 | char* Material, char* Field, char* Cuts) |
87 | { |
88 | // Simple cylinder |
89 | // |
90 | // Bodies |
91 | // ^^^^^^ |
92 | char name1[5], name2[5], name3[5], name4[5]; |
93 | |
94 | // outer radius |
95 | sprintf(name1, "R%4.4d", fNBodies++); |
96 | fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",name1, pos[0], pos[1], rmax); // inner radius |
97 | sprintf(name2, "R%4.4d", fNBodies++); |
98 | fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",name2, pos[0], pos[1], rmin); |
99 | // z-max |
100 | sprintf(name3, "Z%4.4d", fNBodies++); |
101 | fprintf(fFile1,"%5s XYP%10.3f\n",name3, zmax); |
102 | // z-min |
103 | sprintf(name4, "Z%4.4d", fNBodies++); |
104 | fprintf(fFile1,"%5s XYP%10.3f\n",name4, zmin); |
105 | // |
106 | // Volumes |
107 | // ^^^^^^^ |
108 | |
109 | fprintf(fFile2,">%s:%s\n", Material, Field); |
110 | fprintf(fFile2,"EMFCUT=%s\n", Cuts); |
111 | fprintf(fFile2,"WW-FACTOR=%s\n", Cuts); |
112 | if (rmin >0) { |
113 | fprintf(fFile2,"+%s-%s+%s-%s\n", name1, name2, name3, name4); |
114 | } else { |
115 | fprintf(fFile2,"+%s+%s-%s\n", name1, name3, name4); |
116 | } |
117 | |
118 | fprintf(fFile2,"\n"); |
119 | } |
120 | |
121 | void AliALIFE::OnionCylinder(Float_t* r, Int_t nr, Float_t zmin, Float_t zmax, |
122 | Float_t pos[3], char** Materials, |
123 | char** Fields, char** Cuts) |
124 | { |
125 | // |
126 | // Concentric cylinders |
127 | // |
128 | |
129 | // Bodies |
130 | // ^^^^^^ |
131 | char nameRin[6], nameRou[6], nameZin[6], nameZou[6]; |
132 | // z-limits |
133 | // z-max |
134 | sprintf(nameZou, "Z%4.4d", fNBodies++); |
135 | nameZou[5]='\0'; |
136 | |
137 | fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax); |
138 | // z-min |
139 | sprintf(nameZin, "Z%4.4d", fNBodies++); |
140 | nameZin[5]='\0'; |
141 | fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin); |
142 | |
143 | // inner radius |
144 | sprintf(nameRin, "R%4.4d", fNBodies++); |
145 | nameRin[5]='\0'; |
146 | fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",nameRin, pos[0], pos[1], r[0]); |
147 | |
148 | Int_t i; |
149 | for (i=1; i<nr; i++) { |
150 | // outer radius |
151 | sprintf(nameRou, "R%4.4d", fNBodies++); |
152 | nameRou[5]='\0'; |
153 | fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n", |
154 | nameRou, pos[0], pos[1], r[i]); |
155 | // |
156 | // Volumes |
157 | // ^^^^^^^ |
158 | if (Fields && Cuts) { |
159 | fprintf(fFile2,">%s:%s\n", Materials[i-1], Fields[i-1]); |
160 | fprintf(fFile2,"EMFCUT=%s\n", Cuts[i-1]); |
161 | fprintf(fFile2,"WW-FACTOR=%s\n", Cuts[i-1]); |
162 | } else { |
163 | fprintf(fFile2,">%s:%s\n", Materials[i-1], "MF"); |
164 | fprintf(fFile2,"EMFCUT=%s\n", "$UNSHIELDED"); |
165 | fprintf(fFile2,"WW-FACTOR=%s\n", "$UNSHIELDED"); |
166 | } |
167 | if (r[i-1] != 0.) { |
168 | fprintf(fFile2,"+%5s-%5s+%5s-%5s\n", nameZou, nameZin, nameRou, nameRin); |
169 | } else { |
170 | fprintf(fFile2,"+%5s-%5s+%5s\n", nameZou, nameZin, nameRou); |
171 | } |
172 | fprintf(fFile2,"\n"); |
886e839a |
173 | strcpy(nameRin,nameRou); |
660eb9a2 |
174 | } |
175 | } |
176 | |
177 | |
178 | void AliALIFE::Cone(Float_t rmin1, Float_t rmin2, |
179 | Float_t rmax1, Float_t rmax2, |
180 | Float_t zmin, Float_t zmax, |
181 | Float_t pos[3], |
182 | char* Material, char* Field, char* Cuts) |
183 | { |
184 | // Simple cone |
185 | |
186 | // |
187 | // Bodies |
188 | // ^^^^^^ |
189 | char nameCou[6], nameCin[6]; |
190 | Float_t d, r1, r2; |
191 | char nameZin[6], nameZou[6]; |
192 | // z-max |
193 | sprintf(nameZou, "Z%4.4d", fNBodies++); |
194 | fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax); |
195 | // z-min |
196 | sprintf(nameZin, "Z%4.4d", fNBodies++); |
197 | fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin); |
198 | |
199 | // outer radius |
200 | d=zmax-zmin; |
201 | if (rmax1 >= 0. && rmax2 >= 0.) { |
202 | if (rmax1!=rmax2) { |
203 | if (rmax1 > rmax2) { |
204 | pos[2]=zmin; |
205 | r1=rmax1; |
206 | r2=rmax2; |
207 | } else { |
208 | d=-d; |
209 | pos[2]=zmax; |
210 | r1=rmax2; |
211 | r2=rmax1; |
212 | } |
213 | sprintf(nameCou, "C%4.4d", fNBodies++); |
214 | fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n", |
215 | nameCou, pos[0], pos[1], pos[2], 0., 0., d); |
216 | fprintf(fFile1," %10.3f%10.3f\n",r1,r2); |
217 | } else { |
218 | sprintf(nameCou, "C%4.4d", fNBodies++); |
219 | fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n", |
220 | nameCou, pos[0], pos[1], rmax1); |
221 | } |
222 | }else { |
b7fab4b5 |
223 | fDefaultVolume1 = nameCou; |
660eb9a2 |
224 | } |
225 | |
226 | |
227 | |
228 | // inner radius |
229 | if (rmin1 >= 0. && rmin2 >= 0.) { |
230 | if (rmin1!=rmin2) { |
231 | if (rmin1 != 0 && rmin2 !=0) { |
232 | d=zmax-zmin; |
233 | if (rmin1 > rmin2) { |
234 | pos[2]=zmin; |
235 | r1=rmin1; |
236 | r2=rmin2; |
237 | } else { |
238 | pos[2]=zmax; |
239 | r1=rmin2; |
240 | r2=rmin1; |
241 | d=-d; |
242 | } |
243 | sprintf(nameCin, "C%4.4d", fNBodies++); |
244 | fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n", |
245 | nameCin, pos[0], pos[1], pos[2], 0., 0., d); |
246 | fprintf(fFile1," %10.3f%10.3f\n",r1,r2); |
247 | } |
248 | } else { |
249 | sprintf(nameCin, "C%4.4d", fNBodies++); |
250 | fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n", |
251 | nameCin, pos[0], pos[1], rmin1); |
252 | } |
253 | }else { |
b7fab4b5 |
254 | fDefaultVolume2 = nameCin; |
660eb9a2 |
255 | } |
256 | |
257 | |
258 | |
259 | // |
260 | // Volumes |
261 | // ^^^^^^^ |
262 | fprintf(fFile2,">%s:%s\n", Material, Field); |
263 | fprintf(fFile2,"EMFCUT=%s\n", Cuts); |
264 | fprintf(fFile2,"WW-FACTOR=%s\n", Cuts); |
265 | if (rmin1 != 0 && rmin2 !=0) { |
266 | fprintf(fFile2,"+%s-%s+%s-%s\n", nameCou, nameCin, nameZou, nameZin); |
267 | } else { |
268 | fprintf(fFile2,"+%s+%s-%s\n", nameCou, nameZou, nameZin); |
269 | } |
270 | fprintf(fFile2,"\n"); |
271 | } |
272 | |
273 | void AliALIFE::OnionCone (Float_t* r1, Float_t* r2, Int_t nr, |
274 | Float_t zmin, Float_t zmax, |
275 | Float_t pos[3], char** Materials, char** Fields, |
276 | char** Cuts) |
277 | { |
278 | // Concentric cones |
279 | // |
280 | char nameCin[6], nameCou[6], nameZin[6], nameZou[6]; |
281 | // |
282 | // Bodies |
283 | // ^^^^^^ |
284 | Float_t ri1, ri2, ro1, ro2, d; |
285 | |
286 | // z-max |
287 | sprintf(nameZou, "Z%4.4d", fNBodies++); |
288 | fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax); |
289 | // z-min |
290 | sprintf(nameZin, "Z%4.4d", fNBodies++); |
291 | fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin); |
292 | |
293 | // inner radius |
294 | d=zmax-zmin; |
295 | Bool_t hasInner=kFALSE; |
296 | Bool_t isCylinder=kFALSE; |
297 | if (r1[0]>=0 && r2[0]>=0) { |
298 | if (r1[0] != 0. && r2[0] !=0.) { |
299 | if (r1[0]!=r2[0]) { |
300 | hasInner=kTRUE; |
301 | if (r1[0] > r2[0]) { |
302 | pos[2]=zmin; |
303 | ri1=r1[0]; |
304 | ri2=r2[0]; |
305 | } else { |
306 | d=-d; |
307 | pos[2]=zmax; |
308 | ri1=r2[0]; |
309 | ri2=r1[0]; |
310 | } |
311 | sprintf(nameCin, "C%4.4d", fNBodies++); |
312 | nameCin[5]='\0'; |
313 | fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n", |
314 | nameCin, pos[0], pos[1], pos[2], 0., 0., d); |
315 | fprintf(fFile1," %10.3f%10.3f\n",ri1,ri2); |
316 | } else { |
317 | isCylinder=kTRUE; |
318 | sprintf(nameCin, "C%4.4d", fNBodies++); |
319 | nameCin[5]='\0'; |
320 | fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n", |
321 | nameCin, pos[0], pos[1], r1[0]); |
322 | } |
323 | } |
324 | } else { |
b7fab4b5 |
325 | fDefaultVolume1 = nameCin; |
660eb9a2 |
326 | } |
327 | |
328 | |
329 | |
330 | // outer radius |
331 | Int_t i; |
332 | for (i=1; i<nr; i++) { |
333 | if (r1[i] >= 0. && r2[i] >=0) { |
334 | if (r1[i]!=r2[i]) { |
335 | d=zmax-zmin; |
336 | if (r1[i] > r2[i]) { |
337 | pos[2]=zmin; |
338 | ro1=r1[i]; |
339 | ro2=r2[i]; |
340 | } else { |
341 | pos[2]=zmax; |
342 | ro1=r2[i]; |
343 | ro2=r1[i]; |
344 | d=-d; |
345 | } |
346 | sprintf(nameCou, "C%4.4d", fNBodies++); |
347 | nameCou[5]='\0'; |
348 | fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n", |
349 | nameCou, pos[0], pos[1], pos[2], 0., 0., d); |
350 | fprintf(fFile1," %10.3f%10.3f\n",ro1,ro2); |
351 | } else { |
352 | isCylinder=kTRUE; |
353 | sprintf(nameCou, "C%4.4d", fNBodies++); |
354 | nameCou[5]='\0'; |
355 | fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n", |
356 | nameCou, pos[0], pos[1], r1[i]); |
357 | } |
358 | } else { |
b7fab4b5 |
359 | fDefaultVolume1 = nameCou; |
660eb9a2 |
360 | } |
361 | |
362 | // Volumes |
363 | // ^^^^^^^ |
364 | if (Fields && Cuts) { |
365 | fprintf(fFile2,">%s:%s\n", Materials[i-1], Fields[i-1]); |
366 | fprintf(fFile2,"EMFCUT=%s\n", Cuts[i-1]); |
367 | fprintf(fFile2,"WW-FACTOR=%s\n", Cuts[i-1]); |
368 | } else { |
369 | fprintf(fFile2,">%s:%s\n", Materials[i-1], "MF"); |
370 | fprintf(fFile2,"EMFCUT=%s\n", "$UNSHIELDED"); |
371 | fprintf(fFile2,"WW-FACTOR=%s\n", "$UNSHIELDED"); |
372 | } |
38e826ad |
373 | if (hasInner || isCylinder) { |
374 | if (!isCylinder) fprintf(fFile2,"+%5s-%5s+%5s-%5s\n", |
660eb9a2 |
375 | nameCou, nameCin, nameZou, nameZin); |
38e826ad |
376 | if (isCylinder) fprintf(fFile2,"+%5s+%5s-%5s\n", |
377 | nameCou, nameZou, nameZin); |
660eb9a2 |
378 | } else { |
379 | fprintf(fFile2,"+%5s\n", nameCou); |
380 | hasInner=kTRUE; |
381 | } |
382 | fprintf(fFile2,"\n"); |
886e839a |
383 | strcpy(nameCin,nameCou); |
660eb9a2 |
384 | } |
385 | } |
386 | |
387 | |
388 | void AliALIFE::PolyCone(Float_t* rmin, Float_t* rmax, Float_t* z, |
389 | Int_t nz, |
390 | Float_t pos[3], |
391 | char* Material, char* Field, char* Cuts) |
392 | { |
393 | // |
394 | // Equivalent to the Geant3 PCON |
395 | Int_t i; |
396 | for (i=0; i<nz-1; i++) { |
397 | // skip (z_i = z_i+1) |
398 | if (z[i] == z[i+1]) continue; |
399 | Cone(rmin[i], rmin[i+1], rmax[i], rmax[i+1], z[i], z[i+1], pos, |
400 | Material, Field, Cuts); |
401 | } |
402 | } |
403 | |
404 | void AliALIFE::OnionPolyCone(Float_t** r, Float_t* z, |
405 | Int_t nr, Int_t nz, |
406 | Float_t pos[3], |
886e839a |
407 | char** Materials, char** Fields, char** Cuts) |
660eb9a2 |
408 | { |
409 | // |
410 | // Concentric PCONS |
411 | Int_t i, j; |
412 | for (i=0; i<nz-1; i++) { |
413 | // skip (z_i = z_i+1) |
414 | if (z[i] == z[i+1]) continue; |
415 | for (j=0; j<nr-1; j++) { |
416 | if (Fields && Cuts) { |
417 | Cone(r[i][j], r[i+1][j], r[i][j+1], r[i+1][j+1], |
418 | z[i], z[i+1], pos, |
419 | Materials[i], Fields[i], Cuts[i]); |
420 | } else { |
421 | Cone(r[i][j], r[i+1][j], r[i][j+1], r[i+1][j+1], |
422 | z[i], z[i+1], pos, |
423 | Materials[i]); |
424 | } |
425 | } |
426 | } |
427 | } |
428 | |
429 | void AliALIFE::Comment(char* Comment) |
430 | { |
431 | // Insert comment line |
432 | fprintf(fFile1,"*%s\n", Comment); |
433 | fprintf(fFile2,"*%s\n", Comment); |
434 | } |
435 | |
436 | |
437 | void AliALIFE::Finish() |
438 | { |
439 | // Finish geometry definition |
440 | char s[BUFSIZ]; |
441 | fprintf(fFile1," END\n"); |
442 | fclose(fFile2); |
443 | fFile2=fopen(fVolumeFile,"r"); |
444 | while (fgets(s, BUFSIZ, fFile2)) { |
445 | fputs(s,fFile1); |
446 | } |
447 | |
448 | fclose(fFile1); |
449 | fclose(fFile2); |
450 | } |
451 | |
452 | |
453 | |
454 | |
455 | |
456 | |
457 | |
458 | |
459 | |
460 | |
461 | |