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