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,
89 char name1[5], name2[5], name3[5], name4[5];
92 sprintf(name1, "R%4.4d", fNBodies++);
93 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",name1, pos[0], pos[1], rmax); // inner radius
94 sprintf(name2, "R%4.4d", fNBodies++);
95 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",name2, pos[0], pos[1], rmin);
97 sprintf(name3, "Z%4.4d", fNBodies++);
98 fprintf(fFile1,"%5s XYP%10.3f\n",name3, zmax);
100 sprintf(name4, "Z%4.4d", fNBodies++);
101 fprintf(fFile1,"%5s XYP%10.3f\n",name4, zmin);
106 fprintf(fFile2,">%s:%s\n", Material, Field);
107 fprintf(fFile2,"EMFCUT=%s\n", Cuts);
108 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts);
110 fprintf(fFile2,"+%s-%s+%s-%s\n", name1, name2, name3, name4);
112 fprintf(fFile2,"+%s+%s-%s\n", name1, name3, name4);
115 fprintf(fFile2,"\n");
118 void AliALIFE::OnionCylinder(Float_t* r, Int_t nr, Float_t zmin, Float_t zmax,
119 Float_t pos[3], const char** Materials,
120 const char** Fields, const char** Cuts)
123 // Concentric cylinders
128 char nameRin[6], nameRou[6], nameZin[6], nameZou[6];
131 sprintf(nameZou, "Z%4.4d", fNBodies++);
134 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
136 sprintf(nameZin, "Z%4.4d", fNBodies++);
138 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
141 sprintf(nameRin, "R%4.4d", fNBodies++);
143 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",nameRin, pos[0], pos[1], r[0]);
146 for (i=1; i<nr; i++) {
148 sprintf(nameRou, "R%4.4d", fNBodies++);
150 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
151 nameRou, pos[0], pos[1], r[i]);
155 if (Fields && Cuts) {
156 fprintf(fFile2,">%s:%s\n", Materials[i-1], Fields[i-1]);
157 fprintf(fFile2,"EMFCUT=%s\n", Cuts[i-1]);
158 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts[i-1]);
160 fprintf(fFile2,">%s:%s\n", Materials[i-1], "MF");
161 fprintf(fFile2,"EMFCUT=%s\n", "$UNSHIELDED");
162 fprintf(fFile2,"WW-FACTOR=%s\n", "$UNSHIELDED");
165 fprintf(fFile2,"+%5s-%5s+%5s-%5s\n", nameZou, nameZin, nameRou, nameRin);
167 fprintf(fFile2,"+%5s-%5s+%5s\n", nameZou, nameZin, nameRou);
169 fprintf(fFile2,"\n");
170 strcpy(nameRin,nameRou);
175 void AliALIFE::Cone(Float_t rmin1, Float_t rmin2,
176 Float_t rmax1, Float_t rmax2,
177 Float_t zmin, Float_t zmax,
179 const char* Material,
188 char nameCou[6], nameCin[6];
190 char nameZin[6], nameZou[6];
192 sprintf(nameZou, "Z%4.4d", fNBodies++);
193 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
195 sprintf(nameZin, "Z%4.4d", fNBodies++);
196 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
200 sprintf(nameCou, "C%4.4d", fNBodies++);
201 if (rmax1 >= 0. && rmax2 >= 0.) {
213 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
214 nameCou, pos[0], pos[1], pos[2], 0., 0., d);
215 fprintf(fFile1," %10.3f%10.3f\n",r1,r2);
217 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
218 nameCou, pos[0], pos[1], rmax1);
221 fDefaultVolume1 = nameCou;
227 sprintf(nameCin, "C%4.4d", fNBodies++);
228 if (rmin1 >= 0. && rmin2 >= 0.) {
230 if (rmin1 != 0 && rmin2 !=0) {
242 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
243 nameCin, pos[0], pos[1], pos[2], 0., 0., d);
244 fprintf(fFile1," %10.3f%10.3f\n",r1,r2);
247 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
248 nameCin, pos[0], pos[1], rmin1);
251 fDefaultVolume2 = nameCin;
259 fprintf(fFile2,">%s:%s\n", Material, Field);
260 fprintf(fFile2,"EMFCUT=%s\n", Cuts);
261 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts);
262 if (rmin1 != 0 && rmin2 !=0) {
263 fprintf(fFile2,"+%s-%s+%s-%s\n", nameCou, nameCin, nameZou, nameZin);
265 fprintf(fFile2,"+%s+%s-%s\n", nameCou, nameZou, nameZin);
267 fprintf(fFile2,"\n");
270 void AliALIFE::OnionCone (Float_t* r1, Float_t* r2, Int_t nr,
271 Float_t zmin, Float_t zmax,
272 Float_t pos[3], const char** Materials,
273 const char** Fields, const char** Cuts)
277 char nameCin[6], nameCou[6], nameZin[6], nameZou[6];
281 Float_t ri1, ri2, ro1, ro2, d;
284 sprintf(nameZou, "Z%4.4d", fNBodies++);
285 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
287 sprintf(nameZin, "Z%4.4d", fNBodies++);
288 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
292 Bool_t hasInner=kFALSE;
293 Bool_t isCylinder=kFALSE;
294 if (r1[0]>=0 && r2[0]>=0) {
295 if (r1[0] != 0. && r2[0] !=0.) {
308 sprintf(nameCin, "C%4.4d", fNBodies++);
310 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
311 nameCin, pos[0], pos[1], pos[2], 0., 0., d);
312 fprintf(fFile1," %10.3f%10.3f\n",ri1,ri2);
315 sprintf(nameCin, "C%4.4d", fNBodies++);
317 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
318 nameCin, pos[0], pos[1], r1[0]);
322 fDefaultVolume1 = nameCin;
329 for (i=1; i<nr; i++) {
330 if (r1[i] >= 0. && r2[i] >=0) {
343 sprintf(nameCou, "C%4.4d", fNBodies++);
345 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
346 nameCou, pos[0], pos[1], pos[2], 0., 0., d);
347 fprintf(fFile1," %10.3f%10.3f\n",ro1,ro2);
350 sprintf(nameCou, "C%4.4d", fNBodies++);
352 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
353 nameCou, pos[0], pos[1], r1[i]);
356 fDefaultVolume1 = nameCou;
361 if (Fields && Cuts) {
362 fprintf(fFile2,">%s:%s\n", Materials[i-1], Fields[i-1]);
363 fprintf(fFile2,"EMFCUT=%s\n", Cuts[i-1]);
364 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts[i-1]);
366 fprintf(fFile2,">%s:%s\n", Materials[i-1], "MF");
367 fprintf(fFile2,"EMFCUT=%s\n", "$UNSHIELDED");
368 fprintf(fFile2,"WW-FACTOR=%s\n", "$UNSHIELDED");
370 if (hasInner || isCylinder) {
371 if (!isCylinder) fprintf(fFile2,"+%5s-%5s+%5s-%5s\n",
372 nameCou, nameCin, nameZou, nameZin);
373 if (isCylinder) fprintf(fFile2,"+%5s+%5s-%5s\n",
374 nameCou, nameZou, nameZin);
376 fprintf(fFile2,"+%5s\n", nameCou);
379 fprintf(fFile2,"\n");
380 strcpy(nameCin,nameCou);
385 void AliALIFE::PolyCone(Float_t* rmin, Float_t* rmax, Float_t* z,
388 const char* Material,
393 // Equivalent to the Geant3 PCON
395 for (i=0; i<nz-1; i++) {
396 // skip (z_i = z_i+1)
397 if (z[i] == z[i+1]) continue;
398 Cone(rmin[i], rmin[i+1], rmax[i], rmax[i+1], z[i], z[i+1], pos,
399 Material, Field, Cuts);
403 void AliALIFE::OnionPolyCone(Float_t** r, Float_t* z,
406 const char** Materials,
407 const char** Fields,const char** Cuts)
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],
419 Materials[i], Fields[i], Cuts[i]);
421 Cone(r[i][j], r[i+1][j], r[i][j+1], r[i+1][j+1],
429 void AliALIFE::Comment(const char* Comment)
431 // Insert comment line
432 fprintf(fFile1,"*%s\n", Comment);
433 fprintf(fFile2,"*%s\n", Comment);
437 void AliALIFE::Finish(Bool_t iremove)
439 // Finish geometry definition
441 fprintf(fFile1," END\n");
443 fFile2=fopen(fVolumeFile,"r");
444 while (fgets(s, BUFSIZ, fFile2)) {
456 void AliALIFE::Copy(TObject&) const
461 Fatal("Copy","Not implemented!\n");