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