]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STRUCT/AliALIFE.cxx
Update and patch for reading AliITSgeom from the file
[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
eeacf08b 16/* $Id$ */
660eb9a2 17
eeacf08b 18//----------------------------------------------------------------------
19// Helper class to write geometry in ALIFE format
20// in parallel with Geant geometry definition.
21// Author: A.Morsch
22//----------------------------------------------------------------------
88cb7938 23
660eb9a2 24#include <AliALIFE.h>
25
26ClassImp(AliALIFE)
27
9b62c596 28
29AliALIFE::AliALIFE(const char* file1, const char* file2)
660eb9a2 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
9b62c596 44AliALIFE::AliALIFE()
660eb9a2 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
55void 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
68void 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
78void AliALIFE:: Cylinder(Float_t rmin, Float_t rmax,
79 Float_t zmin, Float_t zmax,
80 Float_t pos[3],
81 char* Material, char* Field, char* Cuts)
82{
83// Simple cylinder
84//
85// Bodies
86// ^^^^^^
87 char name1[5], name2[5], name3[5], name4[5];
88
89// outer radius
90 sprintf(name1, "R%4.4d", fNBodies++);
91 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",name1, pos[0], pos[1], rmax); // inner radius
92 sprintf(name2, "R%4.4d", fNBodies++);
93 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",name2, pos[0], pos[1], rmin);
94// z-max
95 sprintf(name3, "Z%4.4d", fNBodies++);
96 fprintf(fFile1,"%5s XYP%10.3f\n",name3, zmax);
97// z-min
98 sprintf(name4, "Z%4.4d", fNBodies++);
99 fprintf(fFile1,"%5s XYP%10.3f\n",name4, zmin);
100//
101// Volumes
102// ^^^^^^^
103
104 fprintf(fFile2,">%s:%s\n", Material, Field);
105 fprintf(fFile2,"EMFCUT=%s\n", Cuts);
106 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts);
107 if (rmin >0) {
108 fprintf(fFile2,"+%s-%s+%s-%s\n", name1, name2, name3, name4);
109 } else {
110 fprintf(fFile2,"+%s+%s-%s\n", name1, name3, name4);
111 }
112
113 fprintf(fFile2,"\n");
114}
115
116void AliALIFE::OnionCylinder(Float_t* r, Int_t nr, Float_t zmin, Float_t zmax,
117 Float_t pos[3], char** Materials,
118 char** Fields, char** Cuts)
119{
120//
121// Concentric cylinders
122//
123
124// Bodies
125// ^^^^^^
126 char nameRin[6], nameRou[6], nameZin[6], nameZou[6];
127// z-limits
128// z-max
129 sprintf(nameZou, "Z%4.4d", fNBodies++);
130 nameZou[5]='\0';
131
132 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
133// z-min
134 sprintf(nameZin, "Z%4.4d", fNBodies++);
135 nameZin[5]='\0';
136 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
137
138// inner radius
139 sprintf(nameRin, "R%4.4d", fNBodies++);
140 nameRin[5]='\0';
141 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",nameRin, pos[0], pos[1], r[0]);
142
143 Int_t i;
144 for (i=1; i<nr; i++) {
145// outer radius
146 sprintf(nameRou, "R%4.4d", fNBodies++);
147 nameRou[5]='\0';
148 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
149 nameRou, pos[0], pos[1], r[i]);
150//
151// Volumes
152// ^^^^^^^
153 if (Fields && Cuts) {
154 fprintf(fFile2,">%s:%s\n", Materials[i-1], Fields[i-1]);
155 fprintf(fFile2,"EMFCUT=%s\n", Cuts[i-1]);
156 fprintf(fFile2,"WW-FACTOR=%s\n", Cuts[i-1]);
157 } else {
158 fprintf(fFile2,">%s:%s\n", Materials[i-1], "MF");
159 fprintf(fFile2,"EMFCUT=%s\n", "$UNSHIELDED");
160 fprintf(fFile2,"WW-FACTOR=%s\n", "$UNSHIELDED");
161 }
162 if (r[i-1] != 0.) {
163 fprintf(fFile2,"+%5s-%5s+%5s-%5s\n", nameZou, nameZin, nameRou, nameRin);
164 } else {
165 fprintf(fFile2,"+%5s-%5s+%5s\n", nameZou, nameZin, nameRou);
166 }
167 fprintf(fFile2,"\n");
886e839a 168 strcpy(nameRin,nameRou);
660eb9a2 169 }
170}
171
172
173void AliALIFE::Cone(Float_t rmin1, Float_t rmin2,
174 Float_t rmax1, Float_t rmax2,
175 Float_t zmin, Float_t zmax,
176 Float_t pos[3],
177 char* Material, char* Field, char* Cuts)
178{
179// Simple cone
180
181//
182// Bodies
183// ^^^^^^
184 char nameCou[6], nameCin[6];
185 Float_t d, r1, r2;
186 char nameZin[6], nameZou[6];
187// z-max
188 sprintf(nameZou, "Z%4.4d", fNBodies++);
189 fprintf(fFile1,"%5s XYP%10.3f\n",nameZou, zmax);
190// z-min
191 sprintf(nameZin, "Z%4.4d", fNBodies++);
192 fprintf(fFile1,"%5s XYP%10.3f\n",nameZin, zmin);
193
194// outer radius
195 d=zmax-zmin;
eeacf08b 196 sprintf(nameCou, "C%4.4d", fNBodies++);
660eb9a2 197 if (rmax1 >= 0. && rmax2 >= 0.) {
198 if (rmax1!=rmax2) {
199 if (rmax1 > rmax2) {
200 pos[2]=zmin;
201 r1=rmax1;
202 r2=rmax2;
203 } else {
204 d=-d;
205 pos[2]=zmax;
206 r1=rmax2;
207 r2=rmax1;
208 }
660eb9a2 209 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
210 nameCou, pos[0], pos[1], pos[2], 0., 0., d);
211 fprintf(fFile1," %10.3f%10.3f\n",r1,r2);
212 } else {
660eb9a2 213 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
214 nameCou, pos[0], pos[1], rmax1);
215 }
216 }else {
b7fab4b5 217 fDefaultVolume1 = nameCou;
660eb9a2 218 }
219
220
221
222// inner radius
eeacf08b 223 sprintf(nameCin, "C%4.4d", fNBodies++);
660eb9a2 224 if (rmin1 >= 0. && rmin2 >= 0.) {
225 if (rmin1!=rmin2) {
226 if (rmin1 != 0 && rmin2 !=0) {
227 d=zmax-zmin;
228 if (rmin1 > rmin2) {
229 pos[2]=zmin;
230 r1=rmin1;
231 r2=rmin2;
232 } else {
233 pos[2]=zmax;
234 r1=rmin2;
235 r2=rmin1;
236 d=-d;
237 }
660eb9a2 238 fprintf(fFile1,"%5s TRC%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n",
239 nameCin, pos[0], pos[1], pos[2], 0., 0., d);
240 fprintf(fFile1," %10.3f%10.3f\n",r1,r2);
241 }
242 } else {
660eb9a2 243 fprintf(fFile1,"%5s ZCC%10.3f%10.3f%10.3f\n",
244 nameCin, pos[0], pos[1], rmin1);
245 }
246 }else {
b7fab4b5 247 fDefaultVolume2 = nameCin;
660eb9a2 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 {
b7fab4b5 318 fDefaultVolume1 = nameCin;
660eb9a2 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 {
b7fab4b5 352 fDefaultVolume1 = nameCou;
660eb9a2 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 }
38e826ad 366 if (hasInner || isCylinder) {
367 if (!isCylinder) fprintf(fFile2,"+%5s-%5s+%5s-%5s\n",
660eb9a2 368 nameCou, nameCin, nameZou, nameZin);
38e826ad 369 if (isCylinder) fprintf(fFile2,"+%5s+%5s-%5s\n",
370 nameCou, nameZou, nameZin);
660eb9a2 371 } else {
372 fprintf(fFile2,"+%5s\n", nameCou);
373 hasInner=kTRUE;
374 }
375 fprintf(fFile2,"\n");
886e839a 376 strcpy(nameCin,nameCou);
660eb9a2 377 }
378}
379
380
381void AliALIFE::PolyCone(Float_t* rmin, Float_t* rmax, Float_t* z,
382 Int_t nz,
383 Float_t pos[3],
384 char* Material, char* Field, char* Cuts)
385{
386//
387// Equivalent to the Geant3 PCON
388 Int_t i;
389 for (i=0; i<nz-1; i++) {
390// skip (z_i = z_i+1)
391 if (z[i] == z[i+1]) continue;
392 Cone(rmin[i], rmin[i+1], rmax[i], rmax[i+1], z[i], z[i+1], pos,
393 Material, Field, Cuts);
394 }
395}
396
397void AliALIFE::OnionPolyCone(Float_t** r, Float_t* z,
398 Int_t nr, Int_t nz,
399 Float_t pos[3],
886e839a 400 char** Materials, char** Fields, char** Cuts)
660eb9a2 401{
402//
403// Concentric PCONS
404 Int_t i, j;
405 for (i=0; i<nz-1; i++) {
406// skip (z_i = z_i+1)
407 if (z[i] == z[i+1]) continue;
408 for (j=0; j<nr-1; j++) {
409 if (Fields && Cuts) {
410 Cone(r[i][j], r[i+1][j], r[i][j+1], r[i+1][j+1],
411 z[i], z[i+1], pos,
412 Materials[i], Fields[i], Cuts[i]);
413 } else {
414 Cone(r[i][j], r[i+1][j], r[i][j+1], r[i+1][j+1],
415 z[i], z[i+1], pos,
416 Materials[i]);
417 }
418 }
419 }
420}
421
422void AliALIFE::Comment(char* Comment)
423{
424// Insert comment line
425 fprintf(fFile1,"*%s\n", Comment);
426 fprintf(fFile2,"*%s\n", Comment);
427}
428
429
e59713af 430void AliALIFE::Finish(Bool_t iremove)
660eb9a2 431{
432// Finish geometry definition
433 char s[BUFSIZ];
434 fprintf(fFile1," END\n");
435 fclose(fFile2);
436 fFile2=fopen(fVolumeFile,"r");
437 while (fgets(s, BUFSIZ, fFile2)) {
438 fputs(s,fFile1);
439 }
440
441 fclose(fFile1);
442 fclose(fFile2);
e59713af 443 if (iremove) {
444 remove(fVolumeFile);
445 remove(fBodyFile);
446 }
660eb9a2 447}
448
9b62c596 449void AliALIFE::Copy(AliALIFE&) const
450{
451 //
452 // Copy
453 //
454 Fatal("Copy","Not implemented!\n");
455}
660eb9a2 456
457
458
459
460
461
462
463
464
465