1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.18 2001/12/19 14:46:26 morsch
19 Add possibility to disable StepManager() for each module separately.
21 Revision 1.17 2001/08/29 14:28:33 morsch
22 Use visibility flags -1 and 3 instead of 0 and 1.
24 Revision 1.16 2001/05/16 14:57:22 alibrary
25 New files for folders and Stack
27 Revision 1.15 2001/03/20 06:36:28 alibrary
28 100 parameters now allowed for geant shapes
30 Revision 1.14 2001/01/26 19:58:48 hristov
31 Major upgrade of AliRoot code
33 Revision 1.13 2000/11/30 07:12:49 alibrary
34 Introducing new Rndm and QA classes
36 Revision 1.12 2000/10/02 21:28:14 fca
37 Removal of useless dependecies via forward declarations
39 Revision 1.11 2000/07/12 08:56:25 fca
40 Coding convention correction and warning removal
42 Revision 1.10 2000/07/11 18:24:59 fca
43 Coding convention corrections + few minor bug fixes
45 Revision 1.9 2000/05/16 08:45:08 fca
46 Correct dtor, thanks to J.Belikov
48 Revision 1.8 2000/02/23 16:25:22 fca
49 AliVMC and AliGeant3 classes introduced
50 ReadEuclid moved from AliRun to AliModule
52 Revision 1.7 1999/09/29 09:24:29 fca
53 Introduction of the Copyright and cvs Log
57 ///////////////////////////////////////////////////////////////////////////////
59 // Base class for ALICE modules. Both sensitive modules (Modules) and //
60 // non-sensitive ones are described by this base class. This class //
61 // supports the hit and digit trees produced by the simulation and also //
62 // the objects produced by the reconstruction. //
64 // This class is also responsible for building the geometry of the //
69 <img src="picts/AliModuleClass.gif">
73 ///////////////////////////////////////////////////////////////////////////////
77 #include "AliModule.h"
81 #include "AliConfig.h"
85 //_______________________________________________________________________
86 AliModule::AliModule():
100 // Default constructor for the AliModule class
104 //_______________________________________________________________________
105 AliModule::AliModule(const char* name,const char *title):
109 fIdtmed(new TArrayI(100)),
110 fIdmate(new TArrayI(100)),
114 fHistograms(new TList()),
120 // Normal constructor invoked by all Modules.
121 // Create the list for Module specific histograms
122 // Add this Module to the global list of Modules in Run.
124 // Get the Module numeric ID
125 Int_t id = gAlice->GetModuleID(name);
127 // Module already added !
128 Warning("Ctor","Module: %s already present at %d\n",name,id);
132 // Add this Module to the list of Modules
133 gAlice->Modules()->Add(this);
138 // Clear space for tracking media and material indexes
140 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
142 AliConfig::Instance()->Add(this);
144 SetDebug(gAlice->GetDebug());
147 //_______________________________________________________________________
148 AliModule::AliModule(const AliModule &mod):
171 //_______________________________________________________________________
172 AliModule::~AliModule()
178 // Delete ROOT geometry
184 // Delete TArray objects
189 //_______________________________________________________________________
190 void AliModule::Copy(AliModule & /* mod */) const
193 // Copy *this onto mod, not implemented for AliModule
195 Fatal("Copy","Not implemented!\n");
198 //_______________________________________________________________________
199 void AliModule::Disable()
202 // Disable Module on viewer
208 // Loop through geometry to disable all
209 // nodes for this Module
210 while((node = dynamic_cast<TNode*>(next()))) {
211 node->SetVisibility(-1);
215 //_______________________________________________________________________
216 Int_t AliModule::DistancetoPrimitive(Int_t, Int_t)
219 // Return distance from mouse pointer to object
220 // Dummy routine for the moment
225 //_______________________________________________________________________
226 void AliModule::Enable()
229 // Enable Module on the viewver
235 // Loop through geometry to enable all
236 // nodes for this Module
237 while((node = dynamic_cast<TNode*>(next()))) {
238 node->SetVisibility(3);
242 //_______________________________________________________________________
243 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
244 Float_t z, Float_t dens, Float_t radl,
245 Float_t absl, Float_t *buf, Int_t nwbuf) const
248 // Store the parameters for a material
250 // imat the material index will be stored in (*fIdmate)[imat]
251 // name material name
255 // radl radiation length
256 // absl absorbtion length
257 // buf adress of an array user words
258 // nwbuf number of user words
261 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
262 (*fIdmate)[imat]=kmat;
265 //_______________________________________________________________________
266 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
267 Float_t &z, Float_t &dens, Float_t &radl,
271 // Store the parameters for a material
273 // imat the material index will be stored in (*fIdmate)[imat]
274 // name material name
278 // radl radiation length
279 // absl absorbtion length
280 // buf adress of an array user words
281 // nwbuf number of user words
286 kmat=(*fIdmate)[imat];
287 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
291 //_______________________________________________________________________
292 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
293 Float_t *z, Float_t dens, Int_t nlmat,
297 // Defines mixture or compound imat as composed by
298 // nlmat materials defined by arrays a, z and wmat
300 // If nlmat > 0 wmat contains the proportion by
301 // weights of each basic material in the mixture
303 // If nlmat < 0 wmat contains the number of atoms
304 // of eack kind in the molecule of the compound
305 // In this case, wmat is changed on output to the relative weigths.
307 // imat the material index will be stored in (*fIdmate)[imat]
308 // name material name
309 // a array of atomic masses
310 // z array of atomic numbers
312 // nlmat number of components
313 // wmat array of concentrations
316 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
317 (*fIdmate)[imat]=kmat;
320 //_______________________________________________________________________
321 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
322 Int_t isvol, Int_t ifield, Float_t fieldm,
323 Float_t tmaxfd, Float_t stemax, Float_t deemax,
324 Float_t epsil, Float_t stmin, Float_t *ubuf,
328 // Store the parameters of a tracking medium
330 // numed the medium number is stored into (*fIdtmed)[numed]
332 // nmat the material number is stored into (*fIdmate)[nmat]
333 // isvol sensitive volume if isvol!=0
334 // ifield magnetic field flag (see below)
335 // fieldm maximum magnetic field
336 // tmaxfd maximum deflection angle due to magnetic field
337 // stemax maximum step allowed
338 // deemax maximum fractional energy loss in one step
339 // epsil tracking precision in cm
340 // stmin minimum step due to continuous processes
342 // ifield = 0 no magnetic field
343 // = -1 user decision in guswim
344 // = 1 tracking performed with Runge Kutta
345 // = 2 tracking performed with helix
346 // = 3 constant magnetic field along z
349 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
350 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
351 (*fIdtmed)[numed]=kmed;
354 //_______________________________________________________________________
355 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
356 Float_t theta2, Float_t phi2, Float_t theta3,
360 // Define a rotation matrix. Angles are in degrees.
362 // nmat on output contains the number assigned to the rotation matrix
363 // theta1 polar angle for axis I
364 // phi1 azimuthal angle for axis I
365 // theta2 polar angle for axis II
366 // phi2 azimuthal angle for axis II
367 // theta3 polar angle for axis III
368 // phi3 azimuthal angle for axis III
370 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
373 //_______________________________________________________________________
374 Float_t AliModule::ZMin() const
379 //_______________________________________________________________________
380 Float_t AliModule::ZMax() const
385 //_______________________________________________________________________
386 void AliModule::SetEuclidFile(char* material, char* geometry)
389 // Sets the name of the Euclid file
391 fEuclidMaterial=material;
393 fEuclidGeometry=geometry;
395 char* name = new char[strlen(material)];
396 strcpy(name,material);
397 strcpy(&name[strlen(name)-4],".euc");
398 fEuclidGeometry=name;
403 //_______________________________________________________________________
404 void AliModule::ReadEuclid(const char* filnam, char* topvol)
407 // read in the geometry of the detector in euclid file format
409 // id_det : the detector identification (2=its,...)
410 // topvol : return parameter describing the name of the top
411 // volume of geometry.
416 // several changes have been made by miroslav helbich
417 // subroutine is rewrited to follow the new established way of memory
418 // booking for tracking medias and rotation matrices.
419 // all used tracking media have to be defined first, for this you can use
420 // subroutine greutmed.
421 // top volume is searched as only volume not positioned into another
424 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
425 Int_t ndvmx, nr, flag;
426 char key[5], card[77], natmed[21];
427 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
430 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
432 const Int_t kMaxRot=5000;
433 Int_t idrot[kMaxRot],istop[7000];
436 // *** The input filnam name will be with extension '.euc'
437 filtmp=gSystem->ExpandPathName(filnam);
438 lun=fopen(filtmp,"r");
441 Error("ReadEuclid","Could not open file %s\n",filnam);
444 //* --- definition of rotation matrix 0 ---
445 TArrayI &idtmed = *fIdtmed;
446 for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
450 for(i=0;i<77;i++) card[i]=0;
451 iret=fscanf(lun,"%77[^\n]",card);
452 if(iret<=0) goto L20;
457 if (!strcmp(key,"TMED")) {
458 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
459 if( itmed<0 || itmed>=100 ) {
460 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
463 //Pad the string with blanks
466 while(i<20) natmed[i++]=' ';
469 if( idtmed[itmed]<=0 ) {
470 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
473 gMC->Gckmat(idtmed[itmed],natmed);
475 } else if (!strcmp(key,"ROTM")) {
476 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
477 if( irot<=0 || irot>=kMaxRot ) {
478 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
481 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
483 } else if (!strcmp(key,"VOLU")) {
484 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
486 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
489 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
490 //* save the defined volumes
491 strcpy(volst[++nvol],name);
494 } else if (!strcmp(key,"DIVN")) {
495 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
496 gMC->Gsdvn ( name, mother, ndiv, iaxe );
498 } else if (!strcmp(key,"DVN2")) {
499 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
500 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
502 } else if (!strcmp(key,"DIVT")) {
503 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
504 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
506 } else if (!strcmp(key,"DVT2")) {
507 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
508 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
510 } else if (!strcmp(key,"POSI")) {
511 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
512 if( irot<0 || irot>=kMaxRot ) {
513 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
516 if( idrot[irot] == -99) {
517 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
520 //*** volume name cannot be the top volume
521 for(i=1;i<=nvol;i++) {
522 if (!strcmp(volst[i],name)) istop[i]=0;
525 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
527 } else if (!strcmp(key,"POSP")) {
528 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
529 if( irot<0 || irot>=kMaxRot ) {
530 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
533 if( idrot[irot] == -99) {
534 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
538 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
541 //*** volume name cannot be the top volume
542 for(i=1;i<=nvol;i++) {
543 if (!strcmp(volst[i],name)) istop[i]=0;
546 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
549 if (strcmp(key,"END")) goto L10;
550 //* find top volume in the geometry
552 for(i=1;i<=nvol;i++) {
553 if (istop[i] && flag) {
554 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
556 if (istop[i] && !flag) {
557 strcpy(topvol,volst[i]);
558 if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol);
563 Warning("ReadEuclid","top volume not found\n");
567 //* commented out only for the not cernlib version
568 if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam);
573 Error("ReadEuclid","reading error or premature end of file\n");
576 //_______________________________________________________________________
577 void AliModule::ReadEuclidMedia(const char* filnam)
580 // read in the materials and tracking media for the detector
581 // in euclid file format
583 // filnam: name of the input file
584 // id_det: id_det is the detector identification (2=its,...)
586 // author : miroslav helbich
588 Float_t sxmgmx = gAlice->Field()->Max();
589 Int_t isxfld = gAlice->Field()->Integ();
590 Int_t end, i, iret, itmed;
591 char key[5], card[130], natmed[21], namate[21];
596 Int_t nwbuf, isvol, ifield, nmat;
597 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
600 for(i=0;i<end;i++) if(filnam[i]=='.') {
605 // *** The input filnam name will be with extension '.euc'
606 if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug
607 filtmp=gSystem->ExpandPathName(filnam);
608 lun=fopen(filtmp,"r");
611 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
615 // Retrieve Mag Field parameters
616 Int_t globField=gAlice->Field()->Integ();
617 Float_t globMaxField=gAlice->Field()->Max();
618 // TArrayI &idtmed = *fIdtmed;
621 for(i=0;i<130;i++) card[i]=0;
622 iret=fscanf(lun,"%4s %[^\n]",key,card);
623 if(iret<=0) goto L20;
627 if (!strcmp(key,"MATE")) {
628 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
629 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
630 //Pad the string with blanks
633 while(i<20) namate[i++]=' ';
636 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
637 //* read tracking medium
638 } else if (!strcmp(key,"TMED")) {
639 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
640 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
641 &stemax,&deemax,&epsil,&stmin,&nwbuf);
642 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
643 if (ifield<0) ifield=isxfld;
644 if (fieldm<0) fieldm=sxmgmx;
645 //Pad the string with blanks
648 while(i<20) natmed[i++]=' ';
651 AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
652 stemax,deemax,epsil,stmin,ubuf,nwbuf);
653 // (*fImedia)[idtmed[itmed]-1]=id_det;
657 if (strcmp(key,"END")) goto L10;
660 //* commented out only for the not cernlib version
661 if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n",
667 Warning("ReadEuclidMedia","reading error or premature end of file\n");