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 ///////////////////////////////////////////////////////////////////////////////
20 // Base class for ALICE modules. Both sensitive modules (Modules) and //
21 // non-sensitive ones are described by this base class. This class //
22 // supports the hit and digit trees produced by the simulation and also //
23 // the objects produced by the reconstruction. //
25 // This class is also responsible for building the geometry of the //
30 <img src="picts/AliModuleClass.gif">
34 ///////////////////////////////////////////////////////////////////////////////
36 #include <TObjArray.h>
39 #include "AliModule.h"
42 #include "AliConfig.h"
46 //_______________________________________________________________________
47 AliModule::AliModule():
61 // Default constructor for the AliModule class
65 //_______________________________________________________________________
66 AliModule::AliModule(const char* name,const char *title):
70 fIdtmed(new TArrayI(100)),
71 fIdmate(new TArrayI(100)),
75 fHistograms(new TList()),
81 // Normal constructor invoked by all Modules.
82 // Create the list for Module specific histograms
83 // Add this Module to the global list of Modules in Run.
85 // Get the Module numeric ID
86 Int_t id = gAlice->GetModuleID(name);
88 // Module already added !
89 Warning("Ctor","Module: %s already present at %d\n",name,id);
93 // Add this Module to the list of Modules
94 gAlice->Modules()->Add(this);
99 // Clear space for tracking media and material indexes
101 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
103 AliConfig::Instance()->Add(this);
105 SetDebug(gAlice->GetDebug());
108 //_______________________________________________________________________
109 AliModule::AliModule(const AliModule &mod):
132 //_______________________________________________________________________
133 AliModule::~AliModule()
139 // Remove this Module from the list of Modules
140 gAlice->Modules()->Remove(this);
142 // Delete ROOT geometry
148 // Delete TArray objects
153 //_______________________________________________________________________
154 void AliModule::Copy(AliModule & /* mod */) const
157 // Copy *this onto mod, not implemented for AliModule
159 Fatal("Copy","Not implemented!\n");
162 //_______________________________________________________________________
163 void AliModule::Disable()
166 // Disable Module on viewer
172 // Loop through geometry to disable all
173 // nodes for this Module
174 while((node = dynamic_cast<TNode*>(next()))) {
175 node->SetVisibility(-1);
179 //_______________________________________________________________________
180 Int_t AliModule::DistancetoPrimitive(Int_t, Int_t) const
183 // Return distance from mouse pointer to object
184 // Dummy routine for the moment
189 //_______________________________________________________________________
190 void AliModule::Enable()
193 // Enable Module on the viewver
199 // Loop through geometry to enable all
200 // nodes for this Module
201 while((node = dynamic_cast<TNode*>(next()))) {
202 node->SetVisibility(3);
206 //_______________________________________________________________________
207 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
208 Float_t z, Float_t dens, Float_t radl,
209 Float_t absl, Float_t *buf, Int_t nwbuf) const
212 // Store the parameters for a material
214 // imat the material index will be stored in (*fIdmate)[imat]
215 // name material name
219 // radl radiation length
220 // absl absorbtion length
221 // buf adress of an array user words
222 // nwbuf number of user words
225 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
226 (*fIdmate)[imat]=kmat;
229 //_______________________________________________________________________
230 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
231 Float_t &z, Float_t &dens, Float_t &radl,
235 // Store the parameters for a material
237 // imat the material index will be stored in (*fIdmate)[imat]
238 // name material name
242 // radl radiation length
243 // absl absorbtion length
244 // buf adress of an array user words
245 // nwbuf number of user words
250 kmat=(*fIdmate)[imat];
251 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
255 //_______________________________________________________________________
256 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
257 Float_t *z, Float_t dens, Int_t nlmat,
261 // Defines mixture or compound imat as composed by
262 // nlmat materials defined by arrays a, z and wmat
264 // If nlmat > 0 wmat contains the proportion by
265 // weights of each basic material in the mixture
267 // If nlmat < 0 wmat contains the number of atoms
268 // of eack kind in the molecule of the compound
269 // In this case, wmat is changed on output to the relative weigths.
271 // imat the material index will be stored in (*fIdmate)[imat]
272 // name material name
273 // a array of atomic masses
274 // z array of atomic numbers
276 // nlmat number of components
277 // wmat array of concentrations
280 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
281 (*fIdmate)[imat]=kmat;
284 //_______________________________________________________________________
285 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
286 Int_t isvol, Int_t ifield, Float_t fieldm,
287 Float_t tmaxfd, Float_t stemax, Float_t deemax,
288 Float_t epsil, Float_t stmin, Float_t *ubuf,
292 // Store the parameters of a tracking medium
294 // numed the medium number is stored into (*fIdtmed)[numed]
296 // nmat the material number is stored into (*fIdmate)[nmat]
297 // isvol sensitive volume if isvol!=0
298 // ifield magnetic field flag (see below)
299 // fieldm maximum magnetic field
300 // tmaxfd maximum deflection angle due to magnetic field
301 // stemax maximum step allowed
302 // deemax maximum fractional energy loss in one step
303 // epsil tracking precision in cm
304 // stmin minimum step due to continuous processes
306 // ifield = 0 no magnetic field
307 // = -1 user decision in guswim
308 // = 1 tracking performed with Runge Kutta
309 // = 2 tracking performed with helix
310 // = 3 constant magnetic field along z
313 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
314 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
315 (*fIdtmed)[numed]=kmed;
318 //_______________________________________________________________________
319 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
320 Float_t theta2, Float_t phi2, Float_t theta3,
324 // Define a rotation matrix. Angles are in degrees.
326 // nmat on output contains the number assigned to the rotation matrix
327 // theta1 polar angle for axis I
328 // phi1 azimuthal angle for axis I
329 // theta2 polar angle for axis II
330 // phi2 azimuthal angle for axis II
331 // theta3 polar angle for axis III
332 // phi3 azimuthal angle for axis III
334 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
337 //_______________________________________________________________________
338 Float_t AliModule::ZMin() const
343 //_______________________________________________________________________
344 Float_t AliModule::ZMax() const
349 //_______________________________________________________________________
350 void AliModule::SetEuclidFile(char* material, char* geometry)
353 // Sets the name of the Euclid file
355 fEuclidMaterial=material;
357 fEuclidGeometry=geometry;
359 char* name = new char[strlen(material)];
360 strcpy(name,material);
361 strcpy(&name[strlen(name)-4],".euc");
362 fEuclidGeometry=name;
367 //_______________________________________________________________________
368 void AliModule::ReadEuclid(const char* filnam, char* topvol)
371 // read in the geometry of the detector in euclid file format
373 // id_det : the detector identification (2=its,...)
374 // topvol : return parameter describing the name of the top
375 // volume of geometry.
380 // several changes have been made by miroslav helbich
381 // subroutine is rewrited to follow the new established way of memory
382 // booking for tracking medias and rotation matrices.
383 // all used tracking media have to be defined first, for this you can use
384 // subroutine greutmed.
385 // top volume is searched as only volume not positioned into another
388 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
389 Int_t ndvmx, nr, flag;
390 char key[5], card[77], natmed[21];
391 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
394 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
396 const Int_t kMaxRot=5000;
397 Int_t idrot[kMaxRot],istop[7000];
400 // *** The input filnam name will be with extension '.euc'
401 filtmp=gSystem->ExpandPathName(filnam);
402 lun=fopen(filtmp,"r");
405 Error("ReadEuclid","Could not open file %s\n",filnam);
408 //* --- definition of rotation matrix 0 ---
409 TArrayI &idtmed = *fIdtmed;
410 for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
414 for(i=0;i<77;i++) card[i]=0;
415 iret=fscanf(lun,"%77[^\n]",card);
416 if(iret<=0) goto L20;
421 if (!strcmp(key,"TMED")) {
422 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
423 if( itmed<0 || itmed>=100 ) {
424 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
427 //Pad the string with blanks
430 while(i<20) natmed[i++]=' ';
433 if( idtmed[itmed]<=0 ) {
434 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
437 gMC->Gckmat(idtmed[itmed],natmed);
439 } else if (!strcmp(key,"ROTM")) {
440 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
441 if( irot<=0 || irot>=kMaxRot ) {
442 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
445 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
447 } else if (!strcmp(key,"VOLU")) {
448 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
450 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
453 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
454 //* save the defined volumes
455 strcpy(volst[++nvol],name);
458 } else if (!strcmp(key,"DIVN")) {
459 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
460 gMC->Gsdvn ( name, mother, ndiv, iaxe );
462 } else if (!strcmp(key,"DVN2")) {
463 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
464 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
466 } else if (!strcmp(key,"DIVT")) {
467 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
468 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
470 } else if (!strcmp(key,"DVT2")) {
471 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
472 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
474 } else if (!strcmp(key,"POSI")) {
475 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
476 if( irot<0 || irot>=kMaxRot ) {
477 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
480 if( idrot[irot] == -99) {
481 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
484 //*** volume name cannot be the top volume
485 for(i=1;i<=nvol;i++) {
486 if (!strcmp(volst[i],name)) istop[i]=0;
489 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
491 } else if (!strcmp(key,"POSP")) {
492 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
493 if( irot<0 || irot>=kMaxRot ) {
494 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
497 if( idrot[irot] == -99) {
498 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
502 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
505 //*** volume name cannot be the top volume
506 for(i=1;i<=nvol;i++) {
507 if (!strcmp(volst[i],name)) istop[i]=0;
510 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
513 if (strcmp(key,"END")) goto L10;
514 //* find top volume in the geometry
516 for(i=1;i<=nvol;i++) {
517 if (istop[i] && flag) {
518 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
520 if (istop[i] && !flag) {
521 strcpy(topvol,volst[i]);
522 if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol);
527 Warning("ReadEuclid","top volume not found\n");
531 //* commented out only for the not cernlib version
532 if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam);
537 Error("ReadEuclid","reading error or premature end of file\n");
540 //_______________________________________________________________________
541 void AliModule::ReadEuclidMedia(const char* filnam)
544 // read in the materials and tracking media for the detector
545 // in euclid file format
547 // filnam: name of the input file
548 // id_det: id_det is the detector identification (2=its,...)
550 // author : miroslav helbich
552 Float_t sxmgmx = gAlice->Field()->Max();
553 Int_t isxfld = gAlice->Field()->Integ();
554 Int_t end, i, iret, itmed;
555 char key[5], card[130], natmed[21], namate[21];
560 Int_t nwbuf, isvol, ifield, nmat;
561 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
564 for(i=0;i<end;i++) if(filnam[i]=='.') {
569 // *** The input filnam name will be with extension '.euc'
570 if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug
571 filtmp=gSystem->ExpandPathName(filnam);
572 lun=fopen(filtmp,"r");
575 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
579 // Retrieve Mag Field parameters
580 Int_t globField=gAlice->Field()->Integ();
581 Float_t globMaxField=gAlice->Field()->Max();
582 // TArrayI &idtmed = *fIdtmed;
585 for(i=0;i<130;i++) card[i]=0;
586 iret=fscanf(lun,"%4s %[^\n]",key,card);
587 if(iret<=0) goto L20;
591 if (!strcmp(key,"MATE")) {
592 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
593 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
594 //Pad the string with blanks
597 while(i<20) namate[i++]=' ';
600 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
601 //* read tracking medium
602 } else if (!strcmp(key,"TMED")) {
603 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
604 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
605 &stemax,&deemax,&epsil,&stmin,&nwbuf);
606 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
607 if (ifield<0) ifield=isxfld;
608 if (fieldm<0) fieldm=sxmgmx;
609 //Pad the string with blanks
612 while(i<20) natmed[i++]=' ';
615 AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
616 stemax,deemax,epsil,stmin,ubuf,nwbuf);
617 // (*fImedia)[idtmed[itmed]-1]=id_det;
621 if (strcmp(key,"END")) goto L10;
624 //* commented out only for the not cernlib version
625 if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n",
631 Warning("ReadEuclidMedia","reading error or premature end of file\n");