1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //----------------------------------------------------------------------
19 // Helper class to write geometry in ALIFE format
20 // in parallel with Geant geometry definition.
22 //----------------------------------------------------------------------
28 AliALIFE::AliALIFE(const char* file1, const char* file2)
33 fBodyFile = file1; // File for Fluka bodies
35 fFile1=fopen(fBodyFile,"w");
36 fFile2=fopen(fVolumeFile,"w");
39 fDefaultVolume1 = "DEFAU1";
40 fDefaultVolume2 = "DEFAU2";
45 // Default constructor
46 fBodyFile = "FlukaBody.inp";
47 fVolumeFile = "FlukaVolume.inp";
48 fFile1=fopen(fBodyFile,"w");
49 fFile2=fopen(fVolumeFile,"w");
54 void AliALIFE::BodyHeader()
56 // Write header for body definitions
57 fprintf(fFile1,"*\n");
58 fprintf(fFile1,"GEOBEGIN COMBINAT\n");
59 fprintf(fFile1," 0 0 AliRoot Generated\n");
60 fprintf(fFile1,"*\n");
61 fprintf(fFile1,"*== Body Definitions ================================================\n");
62 fprintf(fFile1,"*\n");
67 void AliALIFE::VolumeHeader()
69 // Write header for region (volume) definitions
70 fprintf(fFile2,"REGIONS\n");
71 fprintf(fFile2,"*\n");
72 fprintf(fFile2,"*== Region Definitions =================================================\n");
73 fprintf(fFile2,"*\n");
77 void AliALIFE:: Cylinder(Float_t rmin, Float_t rmax,
78 Float_t zmin, Float_t zmax,
80 char* Material, char* Field, char* Cuts)
86 char name1[5], name2[5], name3[5], name4[5];
89 sprintf(name1, "R%4.4d", fNBodies++);
90 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",name1, pos[0], pos[1], rmax); // inner radius
91 sprintf(name2, "R%4.4d", fNBodies++);
92 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",name2, pos[0], pos[1], rmin);
94 sprintf(name3, "Z%4.4d", fNBodies++);
95 fprintf(fFile1,"%5s XYP%10.3f\n",name3, zmax);
97 sprintf(name4, "Z%4.4d", fNBodies++);
98 fprintf(fFile1,"%5s XYP%10.3f\n",name4, zmin);
103 fprintf(fFile2,">%s:%s\n", Material, Field);
104 fprintf(fFile2,"EMFCUT=%s\n", Cuts);
105 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts);
107 fprintf(fFile2,"+%s-%s+%s-%s\n", name1, name2, name3, name4);
109 fprintf(fFile2,"+%s+%s-%s\n", name1, name3, name4);
112 fprintf(fFile2,"\n");
115 void AliALIFE::OnionCylinder(Float_t* r, Int_t nr, Float_t zmin, Float_t zmax,
116 Float_t pos[3], char** Materials,
117 char** Fields, char** Cuts)
120 // Concentric cylinders
125 char nameRin[6], nameRou[6], nameZin[6], nameZou[6];
128 sprintf(nameZou, "Z%4.4d", fNBodies++);
131 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
133 sprintf(nameZin, "Z%4.4d", fNBodies++);
135 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
138 sprintf(nameRin, "R%4.4d", fNBodies++);
140 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",nameRin, pos[0], pos[1], r[0]);
143 for (i=1; i<nr; i++) {
145 sprintf(nameRou, "R%4.4d", fNBodies++);
147 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
148 nameRou, pos[0], pos[1], r[i]);
152 if (Fields && Cuts) {
153 fprintf(fFile2,">%s:%s\n", Materials[i-1], Fields[i-1]);
154 fprintf(fFile2,"EMFCUT=%s\n", Cuts[i-1]);
155 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts[i-1]);
157 fprintf(fFile2,">%s:%s\n", Materials[i-1], "MF");
158 fprintf(fFile2,"EMFCUT=%s\n", "$UNSHIELDED");
159 fprintf(fFile2,"WW-FACTOR=%s\n", "$UNSHIELDED");
162 fprintf(fFile2,"+%5s-%5s+%5s-%5s\n", nameZou, nameZin, nameRou, nameRin);
164 fprintf(fFile2,"+%5s-%5s+%5s\n", nameZou, nameZin, nameRou);
166 fprintf(fFile2,"\n");
167 strcpy(nameRin,nameRou);
172 void AliALIFE::Cone(Float_t rmin1, Float_t rmin2,
173 Float_t rmax1, Float_t rmax2,
174 Float_t zmin, Float_t zmax,
176 char* Material, char* Field, char* Cuts)
183 char nameCou[6], nameCin[6];
185 char nameZin[6], nameZou[6];
187 sprintf(nameZou, "Z%4.4d", fNBodies++);
188 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
190 sprintf(nameZin, "Z%4.4d", fNBodies++);
191 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
195 sprintf(nameCou, "C%4.4d", fNBodies++);
196 if (rmax1 >= 0. && rmax2 >= 0.) {
208 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
209 nameCou, pos[0], pos[1], pos[2], 0., 0., d);
210 fprintf(fFile1," %10.3f%10.3f\n",r1,r2);
212 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
213 nameCou, pos[0], pos[1], rmax1);
216 fDefaultVolume1 = nameCou;
222 sprintf(nameCin, "C%4.4d", fNBodies++);
223 if (rmin1 >= 0. && rmin2 >= 0.) {
225 if (rmin1 != 0 && rmin2 !=0) {
237 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
238 nameCin, pos[0], pos[1], pos[2], 0., 0., d);
239 fprintf(fFile1," %10.3f%10.3f\n",r1,r2);
242 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
243 nameCin, pos[0], pos[1], rmin1);
246 fDefaultVolume2 = nameCin;
254 fprintf(fFile2,">%s:%s\n", Material, Field);
255 fprintf(fFile2,"EMFCUT=%s\n", Cuts);
256 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts);
257 if (rmin1 != 0 && rmin2 !=0) {
258 fprintf(fFile2,"+%s-%s+%s-%s\n", nameCou, nameCin, nameZou, nameZin);
260 fprintf(fFile2,"+%s+%s-%s\n", nameCou, nameZou, nameZin);
262 fprintf(fFile2,"\n");
265 void AliALIFE::OnionCone (Float_t* r1, Float_t* r2, Int_t nr,
266 Float_t zmin, Float_t zmax,
267 Float_t pos[3], char** Materials, char** Fields,
272 char nameCin[6], nameCou[6], nameZin[6], nameZou[6];
276 Float_t ri1, ri2, ro1, ro2, d;
279 sprintf(nameZou, "Z%4.4d", fNBodies++);
280 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
282 sprintf(nameZin, "Z%4.4d", fNBodies++);
283 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
287 Bool_t hasInner=kFALSE;
288 Bool_t isCylinder=kFALSE;
289 if (r1[0]>=0 && r2[0]>=0) {
290 if (r1[0] != 0. && r2[0] !=0.) {
303 sprintf(nameCin, "C%4.4d", fNBodies++);
305 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
306 nameCin, pos[0], pos[1], pos[2], 0., 0., d);
307 fprintf(fFile1," %10.3f%10.3f\n",ri1,ri2);
310 sprintf(nameCin, "C%4.4d", fNBodies++);
312 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
313 nameCin, pos[0], pos[1], r1[0]);
317 fDefaultVolume1 = nameCin;
324 for (i=1; i<nr; i++) {
325 if (r1[i] >= 0. && r2[i] >=0) {
338 sprintf(nameCou, "C%4.4d", fNBodies++);
340 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
341 nameCou, pos[0], pos[1], pos[2], 0., 0., d);
342 fprintf(fFile1," %10.3f%10.3f\n",ro1,ro2);
345 sprintf(nameCou, "C%4.4d", fNBodies++);
347 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
348 nameCou, pos[0], pos[1], r1[i]);
351 fDefaultVolume1 = nameCou;
356 if (Fields && Cuts) {
357 fprintf(fFile2,">%s:%s\n", Materials[i-1], Fields[i-1]);
358 fprintf(fFile2,"EMFCUT=%s\n", Cuts[i-1]);
359 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts[i-1]);
361 fprintf(fFile2,">%s:%s\n", Materials[i-1], "MF");
362 fprintf(fFile2,"EMFCUT=%s\n", "$UNSHIELDED");
363 fprintf(fFile2,"WW-FACTOR=%s\n", "$UNSHIELDED");
365 if (hasInner || isCylinder) {
366 if (!isCylinder) fprintf(fFile2,"+%5s-%5s+%5s-%5s\n",
367 nameCou, nameCin, nameZou, nameZin);
368 if (isCylinder) fprintf(fFile2,"+%5s+%5s-%5s\n",
369 nameCou, nameZou, nameZin);
371 fprintf(fFile2,"+%5s\n", nameCou);
374 fprintf(fFile2,"\n");
375 strcpy(nameCin,nameCou);
380 void AliALIFE::PolyCone(Float_t* rmin, Float_t* rmax, Float_t* z,
383 char* Material, char* Field, char* Cuts)
386 // Equivalent to the Geant3 PCON
388 for (i=0; i<nz-1; i++) {
389 // skip (z_i = z_i+1)
390 if (z[i] == z[i+1]) continue;
391 Cone(rmin[i], rmin[i+1], rmax[i], rmax[i+1], z[i], z[i+1], pos,
392 Material, Field, Cuts);
396 void AliALIFE::OnionPolyCone(Float_t** r, Float_t* z,
399 char** Materials, char** Fields, char** Cuts)
404 for (i=0; i<nz-1; i++) {
405 // skip (z_i = z_i+1)
406 if (z[i] == z[i+1]) continue;
407 for (j=0; j<nr-1; j++) {
408 if (Fields && Cuts) {
409 Cone(r[i][j], r[i+1][j], r[i][j+1], r[i+1][j+1],
411 Materials[i], Fields[i], Cuts[i]);
413 Cone(r[i][j], r[i+1][j], r[i][j+1], r[i+1][j+1],
421 void AliALIFE::Comment(char* Comment)
423 // Insert comment line
424 fprintf(fFile1,"*%s\n", Comment);
425 fprintf(fFile2,"*%s\n", Comment);
429 void AliALIFE::Finish()
431 // Finish geometry definition
433 fprintf(fFile1," END\n");
435 fFile2=fopen(fVolumeFile,"r");
436 while (fgets(s, BUFSIZ, fFile2)) {