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.19 2002/10/29 14:26:49 hristov
19 Code clean-up (F.Carminati)
21 Revision 1.18 2001/12/19 14:46:26 morsch
22 Add possibility to disable StepManager() for each module separately.
24 Revision 1.17 2001/08/29 14:28:33 morsch
25 Use visibility flags -1 and 3 instead of 0 and 1.
27 Revision 1.16 2001/05/16 14:57:22 alibrary
28 New files for folders and Stack
30 Revision 1.15 2001/03/20 06:36:28 alibrary
31 100 parameters now allowed for geant shapes
33 Revision 1.14 2001/01/26 19:58:48 hristov
34 Major upgrade of AliRoot code
36 Revision 1.13 2000/11/30 07:12:49 alibrary
37 Introducing new Rndm and QA classes
39 Revision 1.12 2000/10/02 21:28:14 fca
40 Removal of useless dependecies via forward declarations
42 Revision 1.11 2000/07/12 08:56:25 fca
43 Coding convention correction and warning removal
45 Revision 1.10 2000/07/11 18:24:59 fca
46 Coding convention corrections + few minor bug fixes
48 Revision 1.9 2000/05/16 08:45:08 fca
49 Correct dtor, thanks to J.Belikov
51 Revision 1.8 2000/02/23 16:25:22 fca
52 AliVMC and AliGeant3 classes introduced
53 ReadEuclid moved from AliRun to AliModule
55 Revision 1.7 1999/09/29 09:24:29 fca
56 Introduction of the Copyright and cvs Log
60 ///////////////////////////////////////////////////////////////////////////////
62 // Base class for ALICE modules. Both sensitive modules (Modules) and //
63 // non-sensitive ones are described by this base class. This class //
64 // supports the hit and digit trees produced by the simulation and also //
65 // the objects produced by the reconstruction. //
67 // This class is also responsible for building the geometry of the //
72 <img src="picts/AliModuleClass.gif">
76 ///////////////////////////////////////////////////////////////////////////////
80 #include "AliModule.h"
83 #include "AliConfig.h"
87 //_______________________________________________________________________
88 AliModule::AliModule():
102 // Default constructor for the AliModule class
106 //_______________________________________________________________________
107 AliModule::AliModule(const char* name,const char *title):
111 fIdtmed(new TArrayI(100)),
112 fIdmate(new TArrayI(100)),
116 fHistograms(new TList()),
122 // Normal constructor invoked by all Modules.
123 // Create the list for Module specific histograms
124 // Add this Module to the global list of Modules in Run.
126 // Get the Module numeric ID
127 Int_t id = gAlice->GetModuleID(name);
129 // Module already added !
130 Warning("Ctor","Module: %s already present at %d\n",name,id);
134 // Add this Module to the list of Modules
135 gAlice->Modules()->Add(this);
140 // Clear space for tracking media and material indexes
142 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
144 AliConfig::Instance()->Add(this);
146 SetDebug(gAlice->GetDebug());
149 //_______________________________________________________________________
150 AliModule::AliModule(const AliModule &mod):
173 //_______________________________________________________________________
174 AliModule::~AliModule()
180 // Delete ROOT geometry
186 // Delete TArray objects
191 //_______________________________________________________________________
192 void AliModule::Copy(AliModule & /* mod */) const
195 // Copy *this onto mod, not implemented for AliModule
197 Fatal("Copy","Not implemented!\n");
200 //_______________________________________________________________________
201 void AliModule::Disable()
204 // Disable Module on viewer
210 // Loop through geometry to disable all
211 // nodes for this Module
212 while((node = dynamic_cast<TNode*>(next()))) {
213 node->SetVisibility(-1);
217 //_______________________________________________________________________
218 Int_t AliModule::DistancetoPrimitive(Int_t, Int_t)
221 // Return distance from mouse pointer to object
222 // Dummy routine for the moment
227 //_______________________________________________________________________
228 void AliModule::Enable()
231 // Enable Module on the viewver
237 // Loop through geometry to enable all
238 // nodes for this Module
239 while((node = dynamic_cast<TNode*>(next()))) {
240 node->SetVisibility(3);
244 //_______________________________________________________________________
245 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
246 Float_t z, Float_t dens, Float_t radl,
247 Float_t absl, Float_t *buf, Int_t nwbuf) const
250 // Store the parameters for a material
252 // imat the material index will be stored in (*fIdmate)[imat]
253 // name material name
257 // radl radiation length
258 // absl absorbtion length
259 // buf adress of an array user words
260 // nwbuf number of user words
263 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
264 (*fIdmate)[imat]=kmat;
267 //_______________________________________________________________________
268 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
269 Float_t &z, Float_t &dens, Float_t &radl,
273 // Store the parameters for a material
275 // imat the material index will be stored in (*fIdmate)[imat]
276 // name material name
280 // radl radiation length
281 // absl absorbtion length
282 // buf adress of an array user words
283 // nwbuf number of user words
288 kmat=(*fIdmate)[imat];
289 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
293 //_______________________________________________________________________
294 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
295 Float_t *z, Float_t dens, Int_t nlmat,
299 // Defines mixture or compound imat as composed by
300 // nlmat materials defined by arrays a, z and wmat
302 // If nlmat > 0 wmat contains the proportion by
303 // weights of each basic material in the mixture
305 // If nlmat < 0 wmat contains the number of atoms
306 // of eack kind in the molecule of the compound
307 // In this case, wmat is changed on output to the relative weigths.
309 // imat the material index will be stored in (*fIdmate)[imat]
310 // name material name
311 // a array of atomic masses
312 // z array of atomic numbers
314 // nlmat number of components
315 // wmat array of concentrations
318 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
319 (*fIdmate)[imat]=kmat;
322 //_______________________________________________________________________
323 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
324 Int_t isvol, Int_t ifield, Float_t fieldm,
325 Float_t tmaxfd, Float_t stemax, Float_t deemax,
326 Float_t epsil, Float_t stmin, Float_t *ubuf,
330 // Store the parameters of a tracking medium
332 // numed the medium number is stored into (*fIdtmed)[numed]
334 // nmat the material number is stored into (*fIdmate)[nmat]
335 // isvol sensitive volume if isvol!=0
336 // ifield magnetic field flag (see below)
337 // fieldm maximum magnetic field
338 // tmaxfd maximum deflection angle due to magnetic field
339 // stemax maximum step allowed
340 // deemax maximum fractional energy loss in one step
341 // epsil tracking precision in cm
342 // stmin minimum step due to continuous processes
344 // ifield = 0 no magnetic field
345 // = -1 user decision in guswim
346 // = 1 tracking performed with Runge Kutta
347 // = 2 tracking performed with helix
348 // = 3 constant magnetic field along z
351 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
352 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
353 (*fIdtmed)[numed]=kmed;
356 //_______________________________________________________________________
357 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
358 Float_t theta2, Float_t phi2, Float_t theta3,
362 // Define a rotation matrix. Angles are in degrees.
364 // nmat on output contains the number assigned to the rotation matrix
365 // theta1 polar angle for axis I
366 // phi1 azimuthal angle for axis I
367 // theta2 polar angle for axis II
368 // phi2 azimuthal angle for axis II
369 // theta3 polar angle for axis III
370 // phi3 azimuthal angle for axis III
372 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
375 //_______________________________________________________________________
376 Float_t AliModule::ZMin() const
381 //_______________________________________________________________________
382 Float_t AliModule::ZMax() const
387 //_______________________________________________________________________
388 void AliModule::SetEuclidFile(char* material, char* geometry)
391 // Sets the name of the Euclid file
393 fEuclidMaterial=material;
395 fEuclidGeometry=geometry;
397 char* name = new char[strlen(material)];
398 strcpy(name,material);
399 strcpy(&name[strlen(name)-4],".euc");
400 fEuclidGeometry=name;
405 //_______________________________________________________________________
406 void AliModule::ReadEuclid(const char* filnam, char* topvol)
409 // read in the geometry of the detector in euclid file format
411 // id_det : the detector identification (2=its,...)
412 // topvol : return parameter describing the name of the top
413 // volume of geometry.
418 // several changes have been made by miroslav helbich
419 // subroutine is rewrited to follow the new established way of memory
420 // booking for tracking medias and rotation matrices.
421 // all used tracking media have to be defined first, for this you can use
422 // subroutine greutmed.
423 // top volume is searched as only volume not positioned into another
426 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
427 Int_t ndvmx, nr, flag;
428 char key[5], card[77], natmed[21];
429 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
432 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
434 const Int_t kMaxRot=5000;
435 Int_t idrot[kMaxRot],istop[7000];
438 // *** The input filnam name will be with extension '.euc'
439 filtmp=gSystem->ExpandPathName(filnam);
440 lun=fopen(filtmp,"r");
443 Error("ReadEuclid","Could not open file %s\n",filnam);
446 //* --- definition of rotation matrix 0 ---
447 TArrayI &idtmed = *fIdtmed;
448 for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
452 for(i=0;i<77;i++) card[i]=0;
453 iret=fscanf(lun,"%77[^\n]",card);
454 if(iret<=0) goto L20;
459 if (!strcmp(key,"TMED")) {
460 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
461 if( itmed<0 || itmed>=100 ) {
462 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
465 //Pad the string with blanks
468 while(i<20) natmed[i++]=' ';
471 if( idtmed[itmed]<=0 ) {
472 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
475 gMC->Gckmat(idtmed[itmed],natmed);
477 } else if (!strcmp(key,"ROTM")) {
478 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
479 if( irot<=0 || irot>=kMaxRot ) {
480 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
483 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
485 } else if (!strcmp(key,"VOLU")) {
486 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
488 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
491 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
492 //* save the defined volumes
493 strcpy(volst[++nvol],name);
496 } else if (!strcmp(key,"DIVN")) {
497 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
498 gMC->Gsdvn ( name, mother, ndiv, iaxe );
500 } else if (!strcmp(key,"DVN2")) {
501 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
502 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
504 } else if (!strcmp(key,"DIVT")) {
505 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
506 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
508 } else if (!strcmp(key,"DVT2")) {
509 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
510 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
512 } else if (!strcmp(key,"POSI")) {
513 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
514 if( irot<0 || irot>=kMaxRot ) {
515 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
518 if( idrot[irot] == -99) {
519 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
522 //*** volume name cannot be the top volume
523 for(i=1;i<=nvol;i++) {
524 if (!strcmp(volst[i],name)) istop[i]=0;
527 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
529 } else if (!strcmp(key,"POSP")) {
530 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
531 if( irot<0 || irot>=kMaxRot ) {
532 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
535 if( idrot[irot] == -99) {
536 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
540 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
543 //*** volume name cannot be the top volume
544 for(i=1;i<=nvol;i++) {
545 if (!strcmp(volst[i],name)) istop[i]=0;
548 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
551 if (strcmp(key,"END")) goto L10;
552 //* find top volume in the geometry
554 for(i=1;i<=nvol;i++) {
555 if (istop[i] && flag) {
556 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
558 if (istop[i] && !flag) {
559 strcpy(topvol,volst[i]);
560 if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol);
565 Warning("ReadEuclid","top volume not found\n");
569 //* commented out only for the not cernlib version
570 if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam);
575 Error("ReadEuclid","reading error or premature end of file\n");
578 //_______________________________________________________________________
579 void AliModule::ReadEuclidMedia(const char* filnam)
582 // read in the materials and tracking media for the detector
583 // in euclid file format
585 // filnam: name of the input file
586 // id_det: id_det is the detector identification (2=its,...)
588 // author : miroslav helbich
590 Float_t sxmgmx = gAlice->Field()->Max();
591 Int_t isxfld = gAlice->Field()->Integ();
592 Int_t end, i, iret, itmed;
593 char key[5], card[130], natmed[21], namate[21];
598 Int_t nwbuf, isvol, ifield, nmat;
599 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
602 for(i=0;i<end;i++) if(filnam[i]=='.') {
607 // *** The input filnam name will be with extension '.euc'
608 if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug
609 filtmp=gSystem->ExpandPathName(filnam);
610 lun=fopen(filtmp,"r");
613 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
617 // Retrieve Mag Field parameters
618 Int_t globField=gAlice->Field()->Integ();
619 Float_t globMaxField=gAlice->Field()->Max();
620 // TArrayI &idtmed = *fIdtmed;
623 for(i=0;i<130;i++) card[i]=0;
624 iret=fscanf(lun,"%4s %[^\n]",key,card);
625 if(iret<=0) goto L20;
629 if (!strcmp(key,"MATE")) {
630 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
631 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
632 //Pad the string with blanks
635 while(i<20) namate[i++]=' ';
638 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
639 //* read tracking medium
640 } else if (!strcmp(key,"TMED")) {
641 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
642 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
643 &stemax,&deemax,&epsil,&stmin,&nwbuf);
644 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
645 if (ifield<0) ifield=isxfld;
646 if (fieldm<0) fieldm=sxmgmx;
647 //Pad the string with blanks
650 while(i<20) natmed[i++]=' ';
653 AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
654 stemax,deemax,epsil,stmin,ubuf,nwbuf);
655 // (*fImedia)[idtmed[itmed]-1]=id_det;
659 if (strcmp(key,"END")) goto L10;
662 //* commented out only for the not cernlib version
663 if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n",
669 Warning("ReadEuclidMedia","reading error or premature end of file\n");