]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STRUCT/AliALIFE.cxx
Decay_t moved to AliDecayer.h
[u/mrichter/AliRoot.git] / STRUCT / AliALIFE.cxx
CommitLineData
660eb9a2 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/*
17$Log$
886e839a 18Revision 1.1 2000/07/26 15:10:57 morsch
19Helper class to write geometry in ALIFE format in parallel with Geant geometry definition.
20
660eb9a2 21*/
22
23#include <AliALIFE.h>
24
25ClassImp(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
53void 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
66void 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
76void 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
114void 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");
886e839a 166 strcpy(nameRin,nameRou);
660eb9a2 167 }
168}
169
170
171void 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 if (rmax1 >= 0. && rmax2 >= 0.) {
195 if (rmax1!=rmax2) {
196 if (rmax1 > rmax2) {
197 pos[2]=zmin;
198 r1=rmax1;
199 r2=rmax2;
200 } else {
201 d=-d;
202 pos[2]=zmax;
203 r1=rmax2;
204 r2=rmax1;
205 }
206 sprintf(nameCou, "C%4.4d", fNBodies++);
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 sprintf(nameCou, "C%4.4d", fNBodies++);
212 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
213 nameCou, pos[0], pos[1], rmax1);
214 }
215 }else {
216 strcpy(nameCou,fDefaultVolume1);
217 }
218
219
220
221// inner radius
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 sprintf(nameCin, "C%4.4d", fNBodies++);
237 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
238 nameCin, pos[0], pos[1], pos[2], 0., 0., d);
239 fprintf(fFile1," %10.3f%10.3f\n",r1,r2);
240 }
241 } else {
242 sprintf(nameCin, "C%4.4d", fNBodies++);
243 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
244 nameCin, pos[0], pos[1], rmin1);
245 }
246 }else {
247 strcpy(nameCin,fDefaultVolume2);
248 }
249
250
251
252//
253// Volumes
254// ^^^^^^^
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);
260 } else {
261 fprintf(fFile2,"+%s+%s-%s\n", nameCou, nameZou, nameZin);
262 }
263 fprintf(fFile2,"\n");
264}
265
266void 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,
269 char** Cuts)
270{
271// Concentric cones
272//
273 char nameCin[6], nameCou[6], nameZin[6], nameZou[6];
274//
275// Bodies
276// ^^^^^^
277 Float_t ri1, ri2, ro1, ro2, d;
278
279// z-max
280 sprintf(nameZou, "Z%4.4d", fNBodies++);
281 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
282// z-min
283 sprintf(nameZin, "Z%4.4d", fNBodies++);
284 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
285
286// inner radius
287 d=zmax-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.) {
292 if (r1[0]!=r2[0]) {
293 hasInner=kTRUE;
294 if (r1[0] > r2[0]) {
295 pos[2]=zmin;
296 ri1=r1[0];
297 ri2=r2[0];
298 } else {
299 d=-d;
300 pos[2]=zmax;
301 ri1=r2[0];
302 ri2=r1[0];
303 }
304 sprintf(nameCin, "C%4.4d", fNBodies++);
305 nameCin[5]='\0';
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);
309 } else {
310 isCylinder=kTRUE;
311 sprintf(nameCin, "C%4.4d", fNBodies++);
312 nameCin[5]='\0';
313 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
314 nameCin, pos[0], pos[1], r1[0]);
315 }
316 }
317 } else {
318 strcpy(nameCin,fDefaultVolume1);
319 }
320
321
322
323// outer radius
324 Int_t i;
325 for (i=1; i<nr; i++) {
326 if (r1[i] >= 0. && r2[i] >=0) {
327 if (r1[i]!=r2[i]) {
328 d=zmax-zmin;
329 if (r1[i] > r2[i]) {
330 pos[2]=zmin;
331 ro1=r1[i];
332 ro2=r2[i];
333 } else {
334 pos[2]=zmax;
335 ro1=r2[i];
336 ro2=r1[i];
337 d=-d;
338 }
339 sprintf(nameCou, "C%4.4d", fNBodies++);
340 nameCou[5]='\0';
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);
344 } else {
345 isCylinder=kTRUE;
346 sprintf(nameCou, "C%4.4d", fNBodies++);
347 nameCou[5]='\0';
348 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
349 nameCou, pos[0], pos[1], r1[i]);
350 }
351 } else {
352 strcpy(nameCou,fDefaultVolume1);
353 }
354
355// Volumes
356// ^^^^^^^
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]);
361 } else {
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");
365 }
366 if (hasInner) {
367 fprintf(fFile2,"+%5s-%5s+%5s-%5s\n",
368 nameCou, nameCin, nameZou, nameZin);
369 } else {
370 fprintf(fFile2,"+%5s\n", nameCou);
371 hasInner=kTRUE;
372 }
373 fprintf(fFile2,"\n");
886e839a 374 strcpy(nameCin,nameCou);
660eb9a2 375 }
376}
377
378
379void 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
395void AliALIFE::OnionPolyCone(Float_t** r, Float_t* z,
396 Int_t nr, Int_t nz,
397 Float_t pos[3],
886e839a 398 char** Materials, char** Fields, char** Cuts)
660eb9a2 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
420void AliALIFE::Comment(char* Comment)
421{
422// Insert comment line
423 fprintf(fFile1,"*%s\n", Comment);
424 fprintf(fFile2,"*%s\n", Comment);
425}
426
427
428void 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