Minor changes (R.Barbera)
[u/mrichter/AliRoot.git] / STEER / AliModule.cxx
CommitLineData
4c039060 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$
d43b40e2 18Revision 1.14 2001/01/26 19:58:48 hristov
19Major upgrade of AliRoot code
20
2ab0c725 21Revision 1.13 2000/11/30 07:12:49 alibrary
22Introducing new Rndm and QA classes
23
65fb704d 24Revision 1.12 2000/10/02 21:28:14 fca
25Removal of useless dependecies via forward declarations
26
94de3818 27Revision 1.11 2000/07/12 08:56:25 fca
28Coding convention correction and warning removal
29
8918e700 30Revision 1.10 2000/07/11 18:24:59 fca
31Coding convention corrections + few minor bug fixes
32
aee8290b 33Revision 1.9 2000/05/16 08:45:08 fca
34Correct dtor, thanks to J.Belikov
35
bf9b027f 36Revision 1.8 2000/02/23 16:25:22 fca
37AliVMC and AliGeant3 classes introduced
38ReadEuclid moved from AliRun to AliModule
39
b13db077 40Revision 1.7 1999/09/29 09:24:29 fca
41Introduction of the Copyright and cvs Log
42
4c039060 43*/
44
8494b010 45///////////////////////////////////////////////////////////////////////////////
46// //
47// Base class for ALICE modules. Both sensitive modules (Modules) and //
48// non-sensitive ones are described by this base class. This class //
49// supports the hit and digit trees produced by the simulation and also //
50// the objects produced by the reconstruction. //
51// //
52// This class is also responsible for building the geometry of the //
53// Modules. //
54// //
55//Begin_Html
56/*
1439f98e 57<img src="picts/AliModuleClass.gif">
8494b010 58*/
59//End_Html
60// //
61///////////////////////////////////////////////////////////////////////////////
94de3818 62#include <TNode.h>
94de3818 63#include "TSystem.h"
64
8494b010 65#include "AliModule.h"
66#include "AliRun.h"
94de3818 67#include "AliMagF.h"
68#include "AliMC.h"
8494b010 69
70ClassImp(AliModule)
71
72//_____________________________________________________________________________
73AliModule::AliModule()
74{
75 //
76 // Default constructor for the AliModule class
77 //
78 fHistograms = 0;
79 fNodes = 0;
aee8290b 80 fIdtmed = 0;
81 fIdmate = 0;
8494b010 82}
83
84//_____________________________________________________________________________
85AliModule::AliModule(const char* name,const char *title):TNamed(name,title)
86{
87 //
88 // Normal constructor invoked by all Modules.
89 // Create the list for Module specific histograms
90 // Add this Module to the global list of Modules in Run.
91 //
92 //
93 // Initialises the histogram list
94 fHistograms = new TList();
95 //
96 // Initialises the list of ROOT TNodes
97 fNodes = new TList();
98 //
99 // Get the Module numeric ID
100 Int_t id = gAlice->GetModuleID(name);
02ca2762 101 if (id>=0) {
102 // Module already added !
103 Warning("Ctor","Module: %s already present at %d\n",name,id);
8494b010 104 return;
105 }
106 //
107 // Add this Module to the list of Modules
02ca2762 108 gAlice->Modules()->Add(this);
8494b010 109 //
110 //
111 SetMarkerColor(3);
112 //
113 // Allocate space for tracking media and material indexes
114 fIdtmed = new TArrayI(100);
115 fIdmate = new TArrayI(100);
116 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
117 //
118 // Prepare to find the tracking media range
119 fLoMedium = 65536;
120 fHiMedium = 0;
65fb704d 121 SetDebug(gAlice->GetDebug());
8494b010 122}
123
124//_____________________________________________________________________________
aee8290b 125AliModule::AliModule(const AliModule &mod)
126{
127 //
128 // Copy constructor
129 //
8918e700 130 mod.Copy(*this);
aee8290b 131}
132
133//_____________________________________________________________________________
8494b010 134AliModule::~AliModule()
135{
136 //
137 // Destructor
138 //
139 fHistograms = 0;
140 //
141 // Delete ROOT geometry
bf9b027f 142 if(fNodes) {
143 fNodes->Clear();
144 delete fNodes;
145 }
8494b010 146 //
147 // Delete TArray objects
148 delete fIdtmed;
149 delete fIdmate;
150}
151
152//_____________________________________________________________________________
8918e700 153void AliModule::Copy(AliModule & /* mod */) const
aee8290b 154{
155 //
156 // Copy *this onto mod, not implemented for AliModule
157 //
158 Fatal("Copy","Not implemented!\n");
159}
160
161//_____________________________________________________________________________
8494b010 162void AliModule::Disable()
163{
164 //
165 // Disable Module on viewer
166 //
167 fActive = kFALSE;
168 TIter next(fNodes);
169 TNode *node;
170 //
171 // Loop through geometry to disable all
172 // nodes for this Module
173 while((node = (TNode*)next())) {
174 node->SetVisibility(0);
175 }
176}
177
178//_____________________________________________________________________________
179Int_t AliModule::DistancetoPrimitive(Int_t, Int_t)
180{
181 //
182 // Return distance from mouse pointer to object
183 // Dummy routine for the moment
184 //
185 return 9999;
186}
187
188//_____________________________________________________________________________
189void AliModule::Enable()
190{
191 //
192 // Enable Module on the viewver
193 //
194 fActive = kTRUE;
195 TIter next(fNodes);
196 TNode *node;
197 //
198 // Loop through geometry to enable all
199 // nodes for this Module
200 while((node = (TNode*)next())) {
201 node->SetVisibility(1);
202 }
203}
204
205//_____________________________________________________________________________
206void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
207 Float_t z, Float_t dens, Float_t radl,
208 Float_t absl, Float_t *buf, Int_t nwbuf) const
209{
210 //
211 // Store the parameters for a material
212 //
213 // imat the material index will be stored in (*fIdmate)[imat]
214 // name material name
215 // a atomic mass
216 // z atomic number
217 // dens density
218 // radl radiation length
219 // absl absorbtion length
220 // buf adress of an array user words
221 // nwbuf number of user words
222 //
223 Int_t kmat;
cfce8870 224 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
8494b010 225 (*fIdmate)[imat]=kmat;
226}
227
0afa509f 228//_____________________________________________________________________________
229void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
230 Float_t &z, Float_t &dens, Float_t &radl,
231 Float_t &absl)
232{
233 //
234 // Store the parameters for a material
235 //
236 // imat the material index will be stored in (*fIdmate)[imat]
237 // name material name
238 // a atomic mass
239 // z atomic number
240 // dens density
241 // radl radiation length
242 // absl absorbtion length
243 // buf adress of an array user words
244 // nwbuf number of user words
245 //
246
247 Float_t buf[10];
248 Int_t nwbuf, kmat;
249 kmat=(*fIdmate)[imat];
250 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
251}
252
8494b010 253
254//_____________________________________________________________________________
255void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
256 Float_t *z, Float_t dens, Int_t nlmat,
257 Float_t *wmat) const
258{
259 //
260 // Defines mixture or compound imat as composed by
261 // nlmat materials defined by arrays a, z and wmat
262 //
263 // If nlmat > 0 wmat contains the proportion by
264 // weights of each basic material in the mixture
265 //
266 // If nlmat < 0 wmat contains the number of atoms
267 // of eack kind in the molecule of the compound
268 // In this case, wmat is changed on output to the relative weigths.
269 //
270 // imat the material index will be stored in (*fIdmate)[imat]
271 // name material name
272 // a array of atomic masses
273 // z array of atomic numbers
274 // dens density
275 // nlmat number of components
276 // wmat array of concentrations
277 //
278 Int_t kmat;
cfce8870 279 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
8494b010 280 (*fIdmate)[imat]=kmat;
281}
282
283//_____________________________________________________________________________
284void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
285 Int_t isvol, Int_t ifield, Float_t fieldm,
286 Float_t tmaxfd, Float_t stemax, Float_t deemax,
287 Float_t epsil, Float_t stmin, Float_t *ubuf,
288 Int_t nbuf) const
289{
290 //
291 // Store the parameters of a tracking medium
292 //
b13db077 293 // numed the medium number is stored into (*fIdtmed)[numed]
8494b010 294 // name medium name
295 // nmat the material number is stored into (*fIdmate)[nmat]
296 // isvol sensitive volume if isvol!=0
297 // ifield magnetic field flag (see below)
298 // fieldm maximum magnetic field
299 // tmaxfd maximum deflection angle due to magnetic field
300 // stemax maximum step allowed
301 // deemax maximum fractional energy loss in one step
302 // epsil tracking precision in cm
303 // stmin minimum step due to continuous processes
304 //
305 // ifield = 0 no magnetic field
306 // = -1 user decision in guswim
307 // = 1 tracking performed with Runge Kutta
308 // = 2 tracking performed with helix
309 // = 3 constant magnetic field along z
310 //
311 Int_t kmed;
cfce8870 312 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
8494b010 313 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
ad51aeb0 314 (*fIdtmed)[numed]=kmed;
8494b010 315}
316
317//_____________________________________________________________________________
318void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
319 Float_t theta2, Float_t phi2, Float_t theta3,
320 Float_t phi3) const
321{
322 //
323 // Define a rotation matrix. Angles are in degrees.
324 //
325 // nmat on output contains the number assigned to the rotation matrix
326 // theta1 polar angle for axis I
327 // phi1 azimuthal angle for axis I
328 // theta2 polar angle for axis II
329 // phi2 azimuthal angle for axis II
330 // theta3 polar angle for axis III
331 // phi3 azimuthal angle for axis III
332 //
cfce8870 333 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
8494b010 334}
335
336//_____________________________________________________________________________
aee8290b 337AliModule& AliModule::operator=(const AliModule &mod)
338{
339 mod.Copy(*this);
340 return (*this);
341}
342
343//_____________________________________________________________________________
65fb704d 344Float_t AliModule::ZMin() const
345{
346 return -500;
347}
348
349//_____________________________________________________________________________
350Float_t AliModule::ZMax() const
351{
352 return 500;
353}
354
355//_____________________________________________________________________________
8494b010 356void AliModule::SetEuclidFile(char* material, char* geometry)
357{
358 //
359 // Sets the name of the Euclid file
360 //
361 fEuclidMaterial=material;
362 if(geometry) {
363 fEuclidGeometry=geometry;
364 } else {
365 char* name = new char[strlen(material)];
366 strcpy(name,material);
367 strcpy(&name[strlen(name)-4],".euc");
368 fEuclidGeometry=name;
369 delete [] name;
370 }
371}
372
373//_____________________________________________________________________________
b13db077 374void AliModule::ReadEuclid(const char* filnam, char* topvol)
375{
376 //
377 // read in the geometry of the detector in euclid file format
378 //
379 // id_det : the detector identification (2=its,...)
380 // topvol : return parameter describing the name of the top
381 // volume of geometry.
382 //
383 // author : m. maire
384 //
385 // 28.07.98
386 // several changes have been made by miroslav helbich
387 // subroutine is rewrited to follow the new established way of memory
388 // booking for tracking medias and rotation matrices.
389 // all used tracking media have to be defined first, for this you can use
390 // subroutine greutmed.
391 // top volume is searched as only volume not positioned into another
392 //
393
394 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
395 Int_t ndvmx, nr, flag;
396 char key[5], card[77], natmed[21];
397 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
398 char *filtmp;
d43b40e2 399 Float_t par[100];
b13db077 400 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
401 Float_t xo, yo, zo;
aee8290b 402 const Int_t kMaxRot=5000;
403 Int_t idrot[kMaxRot],istop[7000];
b13db077 404 FILE *lun;
405 //
406 // *** The input filnam name will be with extension '.euc'
407 filtmp=gSystem->ExpandPathName(filnam);
408 lun=fopen(filtmp,"r");
409 delete [] filtmp;
410 if(!lun) {
411 Error("ReadEuclid","Could not open file %s\n",filnam);
412 return;
413 }
414 //* --- definition of rotation matrix 0 ---
415 TArrayI &idtmed = *fIdtmed;
aee8290b 416 for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
b13db077 417 idrot[0]=0;
418 nvol=0;
419 L10:
420 for(i=0;i<77;i++) card[i]=0;
421 iret=fscanf(lun,"%77[^\n]",card);
422 if(iret<=0) goto L20;
423 fscanf(lun,"%*c");
424 //*
425 strncpy(key,card,4);
426 key[4]='\0';
427 if (!strcmp(key,"TMED")) {
428 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
429 if( itmed<0 || itmed>=100 ) {
430 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
431 exit(1);
432 }
433 //Pad the string with blanks
434 i=-1;
435 while(natmed[++i]);
436 while(i<20) natmed[i++]=' ';
437 natmed[i]='\0';
438 //
439 if( idtmed[itmed]<=0 ) {
440 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
441 exit(1);
442 }
443 gMC->Gckmat(idtmed[itmed],natmed);
444 //*
445 } else if (!strcmp(key,"ROTM")) {
446 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
aee8290b 447 if( irot<=0 || irot>=kMaxRot ) {
b13db077 448 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
449 exit(1);
450 }
451 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
452 //*
453 } else if (!strcmp(key,"VOLU")) {
454 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
455 if (npar>0) {
456 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
457 fscanf(lun,"%*c");
458 }
459 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
460 //* save the defined volumes
461 strcpy(volst[++nvol],name);
462 istop[nvol]=1;
463 //*
464 } else if (!strcmp(key,"DIVN")) {
465 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
466 gMC->Gsdvn ( name, mother, ndiv, iaxe );
467 //*
468 } else if (!strcmp(key,"DVN2")) {
469 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
470 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
471 //*
472 } else if (!strcmp(key,"DIVT")) {
473 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
474 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
475 //*
476 } else if (!strcmp(key,"DVT2")) {
477 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
478 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
479 //*
480 } else if (!strcmp(key,"POSI")) {
481 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
aee8290b 482 if( irot<0 || irot>=kMaxRot ) {
b13db077 483 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
484 exit(1);
485 }
486 if( idrot[irot] == -99) {
487 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
488 exit(1);
489 }
490 //*** volume name cannot be the top volume
491 for(i=1;i<=nvol;i++) {
492 if (!strcmp(volst[i],name)) istop[i]=0;
493 }
494 //*
495 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
496 //*
497 } else if (!strcmp(key,"POSP")) {
498 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
aee8290b 499 if( irot<0 || irot>=kMaxRot ) {
b13db077 500 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
501 exit(1);
502 }
503 if( idrot[irot] == -99) {
504 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
505 exit(1);
506 }
507 if (npar > 0) {
508 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
509 fscanf(lun,"%*c");
510 }
511 //*** volume name cannot be the top volume
512 for(i=1;i<=nvol;i++) {
513 if (!strcmp(volst[i],name)) istop[i]=0;
514 }
515 //*
516 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
517 }
518 //*
519 if (strcmp(key,"END")) goto L10;
520 //* find top volume in the geometry
521 flag=0;
522 for(i=1;i<=nvol;i++) {
523 if (istop[i] && flag) {
524 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
525 }
526 if (istop[i] && !flag) {
527 strcpy(topvol,volst[i]);
528 printf(" *** GREUCL *** volume %s taken as a top volume\n",topvol);
529 flag=1;
530 }
531 }
532 if (!flag) {
533 Warning("ReadEuclid","top volume not found\n");
534 }
535 fclose (lun);
536 //*
537 //* commented out only for the not cernlib version
538 printf(" *** GREUCL *** file: %s is now read in\n",filnam);
539 //
540 return;
541 //*
542 L20:
543 Error("ReadEuclid","reading error or premature end of file\n");
544}
545
546//_____________________________________________________________________________
547void AliModule::ReadEuclidMedia(const char* filnam)
548{
549 //
550 // read in the materials and tracking media for the detector
551 // in euclid file format
552 //
553 // filnam: name of the input file
554 // id_det: id_det is the detector identification (2=its,...)
555 //
556 // author : miroslav helbich
557 //
558 Float_t sxmgmx = gAlice->Field()->Max();
559 Int_t isxfld = gAlice->Field()->Integ();
560 Int_t end, i, iret, itmed;
561 char key[5], card[130], natmed[21], namate[21];
562 Float_t ubuf[50];
563 char* filtmp;
564 FILE *lun;
565 Int_t imate;
566 Int_t nwbuf, isvol, ifield, nmat;
567 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
568 //
569 end=strlen(filnam);
570 for(i=0;i<end;i++) if(filnam[i]=='.') {
571 end=i;
572 break;
573 }
574 //
575 // *** The input filnam name will be with extension '.euc'
576 printf("The file name is %s\n",filnam); //Debug
577 filtmp=gSystem->ExpandPathName(filnam);
578 lun=fopen(filtmp,"r");
579 delete [] filtmp;
580 if(!lun) {
581 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
582 return;
583 }
584 //
585 // Retrieve Mag Field parameters
aee8290b 586 Int_t globField=gAlice->Field()->Integ();
587 Float_t globMaxField=gAlice->Field()->Max();
b13db077 588 // TArrayI &idtmed = *fIdtmed;
589 //
590 L10:
591 for(i=0;i<130;i++) card[i]=0;
592 iret=fscanf(lun,"%4s %[^\n]",key,card);
593 if(iret<=0) goto L20;
594 fscanf(lun,"%*c");
595 //*
596 //* read material
597 if (!strcmp(key,"MATE")) {
598 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
599 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
600 //Pad the string with blanks
601 i=-1;
602 while(namate[++i]);
603 while(i<20) namate[i++]=' ';
604 namate[i]='\0';
605 //
606 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
607 //* read tracking medium
608 } else if (!strcmp(key,"TMED")) {
609 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
610 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
611 &stemax,&deemax,&epsil,&stmin,&nwbuf);
612 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
613 if (ifield<0) ifield=isxfld;
614 if (fieldm<0) fieldm=sxmgmx;
615 //Pad the string with blanks
616 i=-1;
617 while(natmed[++i]);
618 while(i<20) natmed[i++]=' ';
619 natmed[i]='\0';
620 //
aee8290b 621 AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
b13db077 622 stemax,deemax,epsil,stmin,ubuf,nwbuf);
623 // (*fImedia)[idtmed[itmed]-1]=id_det;
624 //*
625 }
626 //*
627 if (strcmp(key,"END")) goto L10;
628 fclose (lun);
629 //*
630 //* commented out only for the not cernlib version
631 Warning("ReadEuclidMedia","file: %s is now read in\n",filnam);
632 //*
633 return;
634 //*
635 L20:
636 Warning("ReadEuclidMedia","reading error or premature end of file\n");
637}
638
8494b010 639