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 fFile1(fopen(fBodyFile,"w")),
34 fFile2(fopen(fVolumeFile,"w")),
35 fDefaultVolume1("DEFAU1"),
36 fDefaultVolume2("DEFAU2")
46 fBodyFile("FlukaBody.inp"),
47 fVolumeFile("FlukaVolume.inp"),
48 fFile1(fopen(fBodyFile,"w")),
49 fFile2(fopen(fVolumeFile,"w")),
50 fDefaultVolume1("DEFAU1"),
51 fDefaultVolume2("DEFAU2")
53 // Default constructor
59 AliALIFE::AliALIFE(const AliALIFE &rhs):
74 void AliALIFE::BodyHeader()
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");
87 void AliALIFE::VolumeHeader()
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");
97 void AliALIFE:: Cylinder(Float_t rmin, Float_t rmax,
98 Float_t zmin, Float_t zmax,
100 const char* Material,
108 char name1[6], name2[6], name3[6], name4[6];
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);
116 sprintf(name3, "Z%4.4d", fNBodies++);
117 fprintf(fFile1,"%5s XYP%10.3f\n",name3, zmax);
119 sprintf(name4, "Z%4.4d", fNBodies++);
120 fprintf(fFile1,"%5s XYP%10.3f\n",name4, zmin);
125 fprintf(fFile2,">%s:%s\n", Material, Field);
126 fprintf(fFile2,"EMFCUT=%s\n", Cuts);
127 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts);
129 fprintf(fFile2,"+%s-%s+%s-%s\n", name1, name2, name3, name4);
131 fprintf(fFile2,"+%s+%s-%s\n", name1, name3, name4);
134 fprintf(fFile2,"\n");
137 void AliALIFE::OnionCylinder(Float_t* r, Int_t nr, Float_t zmin, Float_t zmax,
138 Float_t pos[3], const char** Materials,
139 const char** Fields, const char** Cuts)
142 // Concentric cylinders
147 char nameRin[6], nameRou[6], nameZin[6], nameZou[6];
150 sprintf(nameZou, "Z%4.4d", fNBodies++);
153 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
155 sprintf(nameZin, "Z%4.4d", fNBodies++);
157 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
160 sprintf(nameRin, "R%4.4d", fNBodies++);
162 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",nameRin, pos[0], pos[1], r[0]);
165 for (i=1; i<nr; i++) {
167 sprintf(nameRou, "R%4.4d", fNBodies++);
169 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
170 nameRou, pos[0], pos[1], r[i]);
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]);
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");
184 fprintf(fFile2,"+%5s-%5s+%5s-%5s\n", nameZou, nameZin, nameRou, nameRin);
186 fprintf(fFile2,"+%5s-%5s+%5s\n", nameZou, nameZin, nameRou);
188 fprintf(fFile2,"\n");
189 strcpy(nameRin,nameRou);
194 void AliALIFE::Cone(Float_t rmin1, Float_t rmin2,
195 Float_t rmax1, Float_t rmax2,
196 Float_t zmin, Float_t zmax,
198 const char* Material,
207 char nameCou[6], nameCin[6];
209 char nameZin[6], nameZou[6];
211 sprintf(nameZou, "Z%4.4d", fNBodies++);
212 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
214 sprintf(nameZin, "Z%4.4d", fNBodies++);
215 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
219 sprintf(nameCou, "C%4.4d", fNBodies++);
220 if (rmax1 >= 0. && rmax2 >= 0.) {
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);
236 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
237 nameCou, pos[0], pos[1], rmax1);
240 fDefaultVolume1 = nameCou;
246 sprintf(nameCin, "C%4.4d", fNBodies++);
247 if (rmin1 >= 0. && rmin2 >= 0.) {
249 if (rmin1 != 0 && rmin2 !=0) {
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);
266 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
267 nameCin, pos[0], pos[1], rmin1);
270 fDefaultVolume2 = nameCin;
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);
284 fprintf(fFile2,"+%s+%s-%s\n", nameCou, nameZou, nameZin);
286 fprintf(fFile2,"\n");
289 void AliALIFE::OnionCone (Float_t* r1, Float_t* r2, Int_t nr,
290 Float_t zmin, Float_t zmax,
291 Float_t pos[3], const char** Materials,
292 const char** Fields, const char** Cuts)
296 char nameCin[6], nameCou[6], nameZin[6], nameZou[6];
300 Float_t ri1, ri2, ro1, ro2, d;
303 sprintf(nameZou, "Z%4.4d", fNBodies++);
304 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
306 sprintf(nameZin, "Z%4.4d", fNBodies++);
307 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, 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.) {
327 sprintf(nameCin, "C%4.4d", fNBodies++);
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);
334 sprintf(nameCin, "C%4.4d", fNBodies++);
336 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
337 nameCin, pos[0], pos[1], r1[0]);
341 fDefaultVolume1 = nameCin;
348 for (i=1; i<nr; i++) {
349 if (r1[i] >= 0. && r2[i] >=0) {
362 sprintf(nameCou, "C%4.4d", fNBodies++);
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);
369 sprintf(nameCou, "C%4.4d", fNBodies++);
371 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
372 nameCou, pos[0], pos[1], r1[i]);
375 fDefaultVolume1 = nameCou;
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]);
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");
389 if (hasInner || isCylinder) {
390 if (!isCylinder) fprintf(fFile2,"+%5s-%5s+%5s-%5s\n",
391 nameCou, nameCin, nameZou, nameZin);
392 if (isCylinder) fprintf(fFile2,"+%5s+%5s-%5s\n",
393 nameCou, nameZou, nameZin);
395 fprintf(fFile2,"+%5s\n", nameCou);
398 fprintf(fFile2,"\n");
399 strcpy(nameCin,nameCou);
404 void AliALIFE::PolyCone(Float_t* rmin, Float_t* rmax, Float_t* z,
407 const char* Material,
412 // Equivalent to the Geant3 PCON
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);
422 void AliALIFE::OnionPolyCone(Float_t** r, Float_t* z,
425 const char** Materials,
426 const char** Fields,const char** Cuts)
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],
438 Materials[i], Fields[i], Cuts[i]);
440 Cone(r[i][j], r[i+1][j], r[i][j+1], r[i+1][j+1],
448 void AliALIFE::Comment(const char* Comment)
450 // Insert comment line
451 fprintf(fFile1,"*%s\n", Comment);
452 fprintf(fFile2,"*%s\n", Comment);
456 void AliALIFE::Finish(Bool_t iremove)
458 // Finish geometry definition
460 fprintf(fFile1," END\n");
462 fFile2=fopen(fVolumeFile,"r");
463 while (fgets(s, BUFSIZ, fFile2)) {
475 void AliALIFE::Copy(TObject&) const
480 Fatal("Copy","Not implemented!\n");