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