]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STRUCT/AliALIFE.cxx
Macro to plot pathlengths of back-to-back jets. (A. Dainese)
[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
24 #include <AliALIFE.h>
25
26 ClassImp(AliALIFE)
27
28
29 AliALIFE::AliALIFE(const char* file1, const char* file2)
30 {  
31 // Constructor
32     fNBodies = 0; 
33     fNVolumes= 0; 
34     fBodyFile   = file1;   // File for Fluka bodies
35     fVolumeFile = file2;
36     fFile1=fopen(fBodyFile,"w");
37     fFile2=fopen(fVolumeFile,"w");
38     BodyHeader();
39     VolumeHeader();
40     fDefaultVolume1 = "DEFAU1";
41     fDefaultVolume2 = "DEFAU2";    
42 }
43
44 AliALIFE::AliALIFE()
45 {
46 // Default constructor
47     fBodyFile   = "FlukaBody.inp";  
48     fVolumeFile = "FlukaVolume.inp";
49     fFile1=fopen(fBodyFile,"w");
50     fFile2=fopen(fVolumeFile,"w");
51     BodyHeader();
52     VolumeHeader();
53 }
54
55 void AliALIFE::BodyHeader()
56 {
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");
64                             
65 }
66
67
68 void AliALIFE::VolumeHeader()
69 {
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");
75 }
76
77
78 void AliALIFE:: Cylinder(Float_t rmin, Float_t rmax, 
79                          Float_t zmin, Float_t zmax, 
80                          Float_t pos[3], 
81                          const char* Material,
82                          const char* Field,
83                          const char* Cuts) 
84 {
85 // Simple cylinder
86 //
87 // Bodies
88 // ^^^^^^
89     char name1[5], name2[5], name3[5], name4[5];
90
91 //  outer radius
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); 
96 // z-max
97     sprintf(name3, "Z%4.4d", fNBodies++);
98     fprintf(fFile1,"%5s XYP%10.3f\n",name3, zmax); 
99 // z-min
100     sprintf(name4, "Z%4.4d", fNBodies++);
101     fprintf(fFile1,"%5s XYP%10.3f\n",name4, zmin); 
102 //
103 // Volumes
104 // ^^^^^^^
105
106     fprintf(fFile2,">%s:%s\n", Material, Field);
107     fprintf(fFile2,"EMFCUT=%s\n", Cuts);
108     fprintf(fFile2,"WW-FACTOR=%s\n", Cuts);
109     if (rmin >0) {
110         fprintf(fFile2,"+%s-%s+%s-%s\n", name1, name2, name3, name4);
111     } else {
112         fprintf(fFile2,"+%s+%s-%s\n", name1, name3, name4);
113     }
114     
115     fprintf(fFile2,"\n");    
116 }
117
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) 
121 {
122 //
123 // Concentric cylinders
124 //
125
126 // Bodies
127 // ^^^^^^
128     char nameRin[6], nameRou[6], nameZin[6], nameZou[6];
129 // z-limits
130 // z-max
131     sprintf(nameZou, "Z%4.4d", fNBodies++);
132     nameZou[5]='\0';
133     
134     fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax); 
135 // z-min
136     sprintf(nameZin, "Z%4.4d", fNBodies++);
137     nameZin[5]='\0';
138     fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin); 
139
140 // inner radius
141     sprintf(nameRin, "R%4.4d", fNBodies++);
142     nameRin[5]='\0';
143     fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",nameRin, pos[0], pos[1], r[0]); 
144
145     Int_t i;
146     for (i=1; i<nr; i++) {
147 //  outer radius
148         sprintf(nameRou, "R%4.4d", fNBodies++);
149         nameRou[5]='\0';
150         fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
151                 nameRou, pos[0], pos[1], r[i]);         
152 //
153 // Volumes
154 // ^^^^^^^
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]);
159         } else {
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");
163         }
164         if (r[i-1] != 0.) {
165             fprintf(fFile2,"+%5s-%5s+%5s-%5s\n", nameZou, nameZin, nameRou, nameRin);
166         } else {
167             fprintf(fFile2,"+%5s-%5s+%5s\n", nameZou, nameZin, nameRou);
168         }
169         fprintf(fFile2,"\n");
170         strcpy(nameRin,nameRou);
171     }
172 }
173
174
175 void AliALIFE::Cone(Float_t rmin1, Float_t rmin2, 
176                      Float_t rmax1, Float_t rmax2,
177                      Float_t zmin, Float_t zmax, 
178                      Float_t pos[3], 
179                      const char* Material,
180                      const char* Field,
181                      const char* Cuts) 
182 {
183 // Simple cone 
184
185 //
186 // Bodies
187 // ^^^^^^
188     char nameCou[6], nameCin[6];
189     Float_t d, r1, r2;
190     char nameZin[6], nameZou[6];
191 // z-max
192     sprintf(nameZou, "Z%4.4d", fNBodies++);
193     fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax); 
194 // z-min
195     sprintf(nameZin, "Z%4.4d", fNBodies++);
196     fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin); 
197     
198 //  outer radius
199     d=zmax-zmin;
200     sprintf(nameCou, "C%4.4d", fNBodies++);
201     if (rmax1 >= 0. && rmax2 >= 0.) {
202         if (rmax1!=rmax2) {
203             if (rmax1 > rmax2) {
204                 pos[2]=zmin;
205                 r1=rmax1;
206                 r2=rmax2;
207             } else {
208                 d=-d;
209                 pos[2]=zmax;
210                 r1=rmax2;
211                 r2=rmax1;
212             }
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);
216         } else {
217             fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
218                     nameCou, pos[0], pos[1], rmax1); 
219         } 
220     }else {
221       fDefaultVolume1 = nameCou;
222     }
223
224     
225     
226 // inner radius
227     sprintf(nameCin, "C%4.4d", fNBodies++);
228     if (rmin1 >= 0. && rmin2 >= 0.) {
229         if (rmin1!=rmin2) {
230             if (rmin1 != 0 && rmin2 !=0) {
231                 d=zmax-zmin;
232                 if (rmin1 > rmin2) {
233                     pos[2]=zmin;
234                     r1=rmin1;
235                     r2=rmin2;
236                 } else {
237                     pos[2]=zmax;
238                     r1=rmin2;
239                     r2=rmin1;
240                     d=-d;
241                 }
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);
245             } 
246         } else {
247             fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
248                     nameCin, pos[0], pos[1], rmin1); 
249         } 
250     }else {
251       fDefaultVolume2 = nameCin;
252     }
253
254
255
256 //
257 // Volumes
258 // ^^^^^^^
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);
264     } else {
265         fprintf(fFile2,"+%s+%s-%s\n", nameCou, nameZou, nameZin);
266     }
267     fprintf(fFile2,"\n");        
268 }
269
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) 
274 {
275 // Concentric cones
276 //
277     char nameCin[6], nameCou[6], nameZin[6], nameZou[6];
278 //
279 // Bodies
280 // ^^^^^^
281     Float_t ri1, ri2, ro1, ro2, d;
282
283 // z-max
284     sprintf(nameZou, "Z%4.4d", fNBodies++);
285     fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax); 
286 // z-min
287     sprintf(nameZin, "Z%4.4d", fNBodies++);
288     fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin); 
289      
290 //  inner radius
291     d=zmax-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.) {
296             if (r1[0]!=r2[0]) {
297                 hasInner=kTRUE;
298                 if (r1[0] > r2[0]) {
299                     pos[2]=zmin;
300                     ri1=r1[0];
301                     ri2=r2[0];
302                 } else {
303                     d=-d;
304                     pos[2]=zmax;
305                     ri1=r2[0];
306                     ri2=r1[0];
307                 }
308                 sprintf(nameCin, "C%4.4d", fNBodies++);
309                 nameCin[5]='\0';
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);
313             } else {
314                 isCylinder=kTRUE;
315                 sprintf(nameCin, "C%4.4d", fNBodies++);
316                 nameCin[5]='\0';
317                 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
318                         nameCin, pos[0], pos[1], r1[0]); 
319             }
320         }
321     } else {
322       fDefaultVolume1 = nameCin;
323     }
324     
325     
326     
327 // outer radius
328     Int_t i;
329     for (i=1; i<nr; i++) {
330         if (r1[i] >= 0. && r2[i] >=0) {
331             if (r1[i]!=r2[i]) {
332                 d=zmax-zmin;
333                 if (r1[i] > r2[i]) {
334                     pos[2]=zmin;
335                     ro1=r1[i];
336                     ro2=r2[i];
337                 } else {
338                     pos[2]=zmax;
339                     ro1=r2[i];
340                     ro2=r1[i];
341                     d=-d;
342                 }
343                 sprintf(nameCou, "C%4.4d", fNBodies++);
344                 nameCou[5]='\0';
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);
348             } else {
349                 isCylinder=kTRUE;
350                 sprintf(nameCou, "C%4.4d", fNBodies++);
351                 nameCou[5]='\0';
352                 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
353                         nameCou, pos[0], pos[1], r1[i]); 
354             }
355         } else {
356           fDefaultVolume1 = nameCou;
357         }
358         
359 // Volumes
360 // ^^^^^^^
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]);
365         } else {
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");
369         }
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); 
375         } else {
376             fprintf(fFile2,"+%5s\n", nameCou);
377             hasInner=kTRUE;
378         }
379         fprintf(fFile2,"\n");        
380         strcpy(nameCin,nameCou);
381     }
382 }
383
384
385 void AliALIFE::PolyCone(Float_t* rmin, Float_t* rmax, Float_t* z, 
386                         Int_t nz,
387                         Float_t pos[3], 
388                         const char* Material,
389                         const char* Field,
390                         const char* Cuts) 
391 {
392 //
393 // Equivalent to the Geant3 PCON
394     Int_t i;
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);
400     }
401 }
402
403 void AliALIFE::OnionPolyCone(Float_t** r, Float_t* z,
404                              Int_t nr, Int_t nz,
405                              Float_t pos[3], 
406                              const char** Materials,
407                              const char** Fields,const  char** Cuts)
408 {
409 //
410 // Concentric PCONS
411     Int_t i, j;
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], 
418                      z[i], z[i+1], pos,
419                      Materials[i], Fields[i], Cuts[i]);
420             } else {
421                 Cone(r[i][j], r[i+1][j], r[i][j+1], r[i+1][j+1], 
422                      z[i], z[i+1], pos,
423                      Materials[i]);
424             }
425         }
426     }
427 }
428
429 void AliALIFE::Comment(const char* Comment)
430 {
431 // Insert comment line
432     fprintf(fFile1,"*%s\n", Comment);        
433     fprintf(fFile2,"*%s\n", Comment);        
434 }
435
436
437 void AliALIFE::Finish(Bool_t iremove)
438 {
439 // Finish geometry definition
440     char s[BUFSIZ];
441     fprintf(fFile1,"      END\n");
442     fclose(fFile2);
443     fFile2=fopen(fVolumeFile,"r");
444     while (fgets(s, BUFSIZ, fFile2)) {
445         fputs(s,fFile1);
446     }
447     
448     fclose(fFile1);
449     fclose(fFile2);    
450     if (iremove) {
451         remove(fVolumeFile);
452         remove(fBodyFile);
453     }
454 }
455
456 void AliALIFE::Copy(TObject&) const
457 {
458     //
459     // Copy 
460     //
461     Fatal("Copy","Not implemented!\n");
462 }
463
464
465
466
467
468
469
470
471
472