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 //----------------------------------------------------------------------
29 AliALIFE::AliALIFE(const char* file1, const char* file2)
34 fBodyFile = file1; // File for Fluka bodies
36 fFile1=fopen(fBodyFile,"w");
37 fFile2=fopen(fVolumeFile,"w");
40 fDefaultVolume1 = "DEFAU1";
41 fDefaultVolume2 = "DEFAU2";
46 // Default constructor
47 fBodyFile = "FlukaBody.inp";
48 fVolumeFile = "FlukaVolume.inp";
49 fFile1=fopen(fBodyFile,"w");
50 fFile2=fopen(fVolumeFile,"w");
55 void AliALIFE::BodyHeader()
57 // Write header for body definitions
58 fprintf(fFile1,"*\n");
59 fprintf(fFile1,"GEOBEGIN COMBINAT\n");
60 fprintf(fFile1," 0 0 AliRoot Generated\n");
61 fprintf(fFile1,"*\n");
62 fprintf(fFile1,"*== Body Definitions ================================================\n");
63 fprintf(fFile1,"*\n");
68 void AliALIFE::VolumeHeader()
70 // Write header for region (volume) definitions
71 fprintf(fFile2,"REGIONS\n");
72 fprintf(fFile2,"*\n");
73 fprintf(fFile2,"*== Region Definitions =================================================\n");
74 fprintf(fFile2,"*\n");
78 void AliALIFE:: Cylinder(Float_t rmin, Float_t rmax,
79 Float_t zmin, Float_t zmax,
81 char* Material, char* Field, char* Cuts)
87 char name1[5], name2[5], name3[5], name4[5];
90 sprintf(name1, "R%4.4d", fNBodies++);
91 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",name1, pos[0], pos[1], rmax); // inner radius
92 sprintf(name2, "R%4.4d", fNBodies++);
93 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",name2, pos[0], pos[1], rmin);
95 sprintf(name3, "Z%4.4d", fNBodies++);
96 fprintf(fFile1,"%5s XYP%10.3f\n",name3, zmax);
98 sprintf(name4, "Z%4.4d", fNBodies++);
99 fprintf(fFile1,"%5s XYP%10.3f\n",name4, zmin);
104 fprintf(fFile2,">%s:%s\n", Material, Field);
105 fprintf(fFile2,"EMFCUT=%s\n", Cuts);
106 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts);
108 fprintf(fFile2,"+%s-%s+%s-%s\n", name1, name2, name3, name4);
110 fprintf(fFile2,"+%s+%s-%s\n", name1, name3, name4);
113 fprintf(fFile2,"\n");
116 void AliALIFE::OnionCylinder(Float_t* r, Int_t nr, Float_t zmin, Float_t zmax,
117 Float_t pos[3], char** Materials,
118 char** Fields, char** Cuts)
121 // Concentric cylinders
126 char nameRin[6], nameRou[6], nameZin[6], nameZou[6];
129 sprintf(nameZou, "Z%4.4d", fNBodies++);
132 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
134 sprintf(nameZin, "Z%4.4d", fNBodies++);
136 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
139 sprintf(nameRin, "R%4.4d", fNBodies++);
141 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",nameRin, pos[0], pos[1], r[0]);
144 for (i=1; i<nr; i++) {
146 sprintf(nameRou, "R%4.4d", fNBodies++);
148 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
149 nameRou, pos[0], pos[1], r[i]);
153 if (Fields && Cuts) {
154 fprintf(fFile2,">%s:%s\n", Materials[i-1], Fields[i-1]);
155 fprintf(fFile2,"EMFCUT=%s\n", Cuts[i-1]);
156 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts[i-1]);
158 fprintf(fFile2,">%s:%s\n", Materials[i-1], "MF");
159 fprintf(fFile2,"EMFCUT=%s\n", "$UNSHIELDED");
160 fprintf(fFile2,"WW-FACTOR=%s\n", "$UNSHIELDED");
163 fprintf(fFile2,"+%5s-%5s+%5s-%5s\n", nameZou, nameZin, nameRou, nameRin);
165 fprintf(fFile2,"+%5s-%5s+%5s\n", nameZou, nameZin, nameRou);
167 fprintf(fFile2,"\n");
168 strcpy(nameRin,nameRou);
173 void AliALIFE::Cone(Float_t rmin1, Float_t rmin2,
174 Float_t rmax1, Float_t rmax2,
175 Float_t zmin, Float_t zmax,
177 char* Material, char* Field, char* Cuts)
184 char nameCou[6], nameCin[6];
186 char nameZin[6], nameZou[6];
188 sprintf(nameZou, "Z%4.4d", fNBodies++);
189 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
191 sprintf(nameZin, "Z%4.4d", fNBodies++);
192 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
196 sprintf(nameCou, "C%4.4d", fNBodies++);
197 if (rmax1 >= 0. && rmax2 >= 0.) {
209 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
210 nameCou, pos[0], pos[1], pos[2], 0., 0., d);
211 fprintf(fFile1," %10.3f%10.3f\n",r1,r2);
213 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
214 nameCou, pos[0], pos[1], rmax1);
217 fDefaultVolume1 = nameCou;
223 sprintf(nameCin, "C%4.4d", fNBodies++);
224 if (rmin1 >= 0. && rmin2 >= 0.) {
226 if (rmin1 != 0 && rmin2 !=0) {
238 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
239 nameCin, pos[0], pos[1], pos[2], 0., 0., d);
240 fprintf(fFile1," %10.3f%10.3f\n",r1,r2);
243 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
244 nameCin, pos[0], pos[1], rmin1);
247 fDefaultVolume2 = nameCin;
255 fprintf(fFile2,">%s:%s\n", Material, Field);
256 fprintf(fFile2,"EMFCUT=%s\n", Cuts);
257 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts);
258 if (rmin1 != 0 && rmin2 !=0) {
259 fprintf(fFile2,"+%s-%s+%s-%s\n", nameCou, nameCin, nameZou, nameZin);
261 fprintf(fFile2,"+%s+%s-%s\n", nameCou, nameZou, nameZin);
263 fprintf(fFile2,"\n");
266 void AliALIFE::OnionCone (Float_t* r1, Float_t* r2, Int_t nr,
267 Float_t zmin, Float_t zmax,
268 Float_t pos[3], char** Materials, char** Fields,
273 char nameCin[6], nameCou[6], nameZin[6], nameZou[6];
277 Float_t ri1, ri2, ro1, ro2, d;
280 sprintf(nameZou, "Z%4.4d", fNBodies++);
281 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
283 sprintf(nameZin, "Z%4.4d", fNBodies++);
284 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
288 Bool_t hasInner=kFALSE;
289 Bool_t isCylinder=kFALSE;
290 if (r1[0]>=0 && r2[0]>=0) {
291 if (r1[0] != 0. && r2[0] !=0.) {
304 sprintf(nameCin, "C%4.4d", fNBodies++);
306 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
307 nameCin, pos[0], pos[1], pos[2], 0., 0., d);
308 fprintf(fFile1," %10.3f%10.3f\n",ri1,ri2);
311 sprintf(nameCin, "C%4.4d", fNBodies++);
313 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
314 nameCin, pos[0], pos[1], r1[0]);
318 fDefaultVolume1 = nameCin;
325 for (i=1; i<nr; i++) {
326 if (r1[i] >= 0. && r2[i] >=0) {
339 sprintf(nameCou, "C%4.4d", fNBodies++);
341 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
342 nameCou, pos[0], pos[1], pos[2], 0., 0., d);
343 fprintf(fFile1," %10.3f%10.3f\n",ro1,ro2);
346 sprintf(nameCou, "C%4.4d", fNBodies++);
348 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
349 nameCou, pos[0], pos[1], r1[i]);
352 fDefaultVolume1 = nameCou;
357 if (Fields && Cuts) {
358 fprintf(fFile2,">%s:%s\n", Materials[i-1], Fields[i-1]);
359 fprintf(fFile2,"EMFCUT=%s\n", Cuts[i-1]);
360 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts[i-1]);
362 fprintf(fFile2,">%s:%s\n", Materials[i-1], "MF");
363 fprintf(fFile2,"EMFCUT=%s\n", "$UNSHIELDED");
364 fprintf(fFile2,"WW-FACTOR=%s\n", "$UNSHIELDED");
366 if (hasInner || isCylinder) {
367 if (!isCylinder) fprintf(fFile2,"+%5s-%5s+%5s-%5s\n",
368 nameCou, nameCin, nameZou, nameZin);
369 if (isCylinder) fprintf(fFile2,"+%5s+%5s-%5s\n",
370 nameCou, nameZou, nameZin);
372 fprintf(fFile2,"+%5s\n", nameCou);
375 fprintf(fFile2,"\n");
376 strcpy(nameCin,nameCou);
381 void AliALIFE::PolyCone(Float_t* rmin, Float_t* rmax, Float_t* z,
384 char* Material, char* Field, char* Cuts)
387 // Equivalent to the Geant3 PCON
389 for (i=0; i<nz-1; i++) {
390 // skip (z_i = z_i+1)
391 if (z[i] == z[i+1]) continue;
392 Cone(rmin[i], rmin[i+1], rmax[i], rmax[i+1], z[i], z[i+1], pos,
393 Material, Field, Cuts);
397 void AliALIFE::OnionPolyCone(Float_t** r, Float_t* z,
400 char** Materials, char** Fields, char** Cuts)
405 for (i=0; i<nz-1; i++) {
406 // skip (z_i = z_i+1)
407 if (z[i] == z[i+1]) continue;
408 for (j=0; j<nr-1; j++) {
409 if (Fields && Cuts) {
410 Cone(r[i][j], r[i+1][j], r[i][j+1], r[i+1][j+1],
412 Materials[i], Fields[i], Cuts[i]);
414 Cone(r[i][j], r[i+1][j], r[i][j+1], r[i+1][j+1],
422 void AliALIFE::Comment(char* Comment)
424 // Insert comment line
425 fprintf(fFile1,"*%s\n", Comment);
426 fprintf(fFile2,"*%s\n", Comment);
430 void AliALIFE::Finish()
432 // Finish geometry definition
434 fprintf(fFile1," END\n");
436 fFile2=fopen(fVolumeFile,"r");
437 while (fgets(s, BUFSIZ, fFile2)) {
445 void AliALIFE::Copy(AliALIFE&) const
450 Fatal("Copy","Not implemented!\n");