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.15 2001/03/20 06:36:28 alibrary
19 100 parameters now allowed for geant shapes
21 Revision 1.14 2001/01/26 19:58:48 hristov
22 Major upgrade of AliRoot code
24 Revision 1.13 2000/11/30 07:12:49 alibrary
25 Introducing new Rndm and QA classes
27 Revision 1.12 2000/10/02 21:28:14 fca
28 Removal of useless dependecies via forward declarations
30 Revision 1.11 2000/07/12 08:56:25 fca
31 Coding convention correction and warning removal
33 Revision 1.10 2000/07/11 18:24:59 fca
34 Coding convention corrections + few minor bug fixes
36 Revision 1.9 2000/05/16 08:45:08 fca
37 Correct dtor, thanks to J.Belikov
39 Revision 1.8 2000/02/23 16:25:22 fca
40 AliVMC and AliGeant3 classes introduced
41 ReadEuclid moved from AliRun to AliModule
43 Revision 1.7 1999/09/29 09:24:29 fca
44 Introduction of the Copyright and cvs Log
48 ///////////////////////////////////////////////////////////////////////////////
50 // Base class for ALICE modules. Both sensitive modules (Modules) and //
51 // non-sensitive ones are described by this base class. This class //
52 // supports the hit and digit trees produced by the simulation and also //
53 // the objects produced by the reconstruction. //
55 // This class is also responsible for building the geometry of the //
60 <img src="picts/AliModuleClass.gif">
64 ///////////////////////////////////////////////////////////////////////////////
68 #include "AliModule.h"
72 #include "AliConfig.h"
76 //_____________________________________________________________________________
77 AliModule::AliModule()
80 // Default constructor for the AliModule class
89 //_____________________________________________________________________________
90 AliModule::AliModule(const char* name,const char *title):TNamed(name,title)
93 // Normal constructor invoked by all Modules.
94 // Create the list for Module specific histograms
95 // Add this Module to the global list of Modules in Run.
98 // Initialises the histogram list
99 fHistograms = new TList();
101 // Initialises the list of ROOT TNodes
102 fNodes = new TList();
104 // Get the Module numeric ID
105 Int_t id = gAlice->GetModuleID(name);
107 // Module already added !
108 Warning("Ctor","Module: %s already present at %d\n",name,id);
112 // Add this Module to the list of Modules
113 gAlice->Modules()->Add(this);
118 // Allocate space for tracking media and material indexes
119 fIdtmed = new TArrayI(100);
120 fIdmate = new TArrayI(100);
121 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
123 // Prepare to find the tracking media range
127 AliConfig::Instance()->Add(this);
129 SetDebug(gAlice->GetDebug());
132 //_____________________________________________________________________________
133 AliModule::AliModule(const AliModule &mod)
141 //_____________________________________________________________________________
142 AliModule::~AliModule()
149 // Delete ROOT geometry
155 // Delete TArray objects
160 //_____________________________________________________________________________
161 void AliModule::Copy(AliModule & /* mod */) const
164 // Copy *this onto mod, not implemented for AliModule
166 Fatal("Copy","Not implemented!\n");
169 //_____________________________________________________________________________
170 void AliModule::Disable()
173 // Disable Module on viewer
179 // Loop through geometry to disable all
180 // nodes for this Module
181 while((node = (TNode*)next())) {
182 node->SetVisibility(0);
186 //_____________________________________________________________________________
187 Int_t AliModule::DistancetoPrimitive(Int_t, Int_t)
190 // Return distance from mouse pointer to object
191 // Dummy routine for the moment
196 //_____________________________________________________________________________
197 void AliModule::Enable()
200 // Enable Module on the viewver
206 // Loop through geometry to enable all
207 // nodes for this Module
208 while((node = (TNode*)next())) {
209 node->SetVisibility(1);
213 //_____________________________________________________________________________
214 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
215 Float_t z, Float_t dens, Float_t radl,
216 Float_t absl, Float_t *buf, Int_t nwbuf) const
219 // Store the parameters for a material
221 // imat the material index will be stored in (*fIdmate)[imat]
222 // name material name
226 // radl radiation length
227 // absl absorbtion length
228 // buf adress of an array user words
229 // nwbuf number of user words
232 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
233 (*fIdmate)[imat]=kmat;
236 //_____________________________________________________________________________
237 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
238 Float_t &z, Float_t &dens, Float_t &radl,
242 // Store the parameters for a material
244 // imat the material index will be stored in (*fIdmate)[imat]
245 // name material name
249 // radl radiation length
250 // absl absorbtion length
251 // buf adress of an array user words
252 // nwbuf number of user words
257 kmat=(*fIdmate)[imat];
258 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
262 //_____________________________________________________________________________
263 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
264 Float_t *z, Float_t dens, Int_t nlmat,
268 // Defines mixture or compound imat as composed by
269 // nlmat materials defined by arrays a, z and wmat
271 // If nlmat > 0 wmat contains the proportion by
272 // weights of each basic material in the mixture
274 // If nlmat < 0 wmat contains the number of atoms
275 // of eack kind in the molecule of the compound
276 // In this case, wmat is changed on output to the relative weigths.
278 // imat the material index will be stored in (*fIdmate)[imat]
279 // name material name
280 // a array of atomic masses
281 // z array of atomic numbers
283 // nlmat number of components
284 // wmat array of concentrations
287 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
288 (*fIdmate)[imat]=kmat;
291 //_____________________________________________________________________________
292 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
293 Int_t isvol, Int_t ifield, Float_t fieldm,
294 Float_t tmaxfd, Float_t stemax, Float_t deemax,
295 Float_t epsil, Float_t stmin, Float_t *ubuf,
299 // Store the parameters of a tracking medium
301 // numed the medium number is stored into (*fIdtmed)[numed]
303 // nmat the material number is stored into (*fIdmate)[nmat]
304 // isvol sensitive volume if isvol!=0
305 // ifield magnetic field flag (see below)
306 // fieldm maximum magnetic field
307 // tmaxfd maximum deflection angle due to magnetic field
308 // stemax maximum step allowed
309 // deemax maximum fractional energy loss in one step
310 // epsil tracking precision in cm
311 // stmin minimum step due to continuous processes
313 // ifield = 0 no magnetic field
314 // = -1 user decision in guswim
315 // = 1 tracking performed with Runge Kutta
316 // = 2 tracking performed with helix
317 // = 3 constant magnetic field along z
320 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
321 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
322 (*fIdtmed)[numed]=kmed;
325 //_____________________________________________________________________________
326 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
327 Float_t theta2, Float_t phi2, Float_t theta3,
331 // Define a rotation matrix. Angles are in degrees.
333 // nmat on output contains the number assigned to the rotation matrix
334 // theta1 polar angle for axis I
335 // phi1 azimuthal angle for axis I
336 // theta2 polar angle for axis II
337 // phi2 azimuthal angle for axis II
338 // theta3 polar angle for axis III
339 // phi3 azimuthal angle for axis III
341 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
344 //_____________________________________________________________________________
345 AliModule& AliModule::operator=(const AliModule &mod)
351 //_____________________________________________________________________________
352 Float_t AliModule::ZMin() const
357 //_____________________________________________________________________________
358 Float_t AliModule::ZMax() const
363 //_____________________________________________________________________________
364 void AliModule::SetEuclidFile(char* material, char* geometry)
367 // Sets the name of the Euclid file
369 fEuclidMaterial=material;
371 fEuclidGeometry=geometry;
373 char* name = new char[strlen(material)];
374 strcpy(name,material);
375 strcpy(&name[strlen(name)-4],".euc");
376 fEuclidGeometry=name;
381 //_____________________________________________________________________________
382 void AliModule::ReadEuclid(const char* filnam, char* topvol)
385 // read in the geometry of the detector in euclid file format
387 // id_det : the detector identification (2=its,...)
388 // topvol : return parameter describing the name of the top
389 // volume of geometry.
394 // several changes have been made by miroslav helbich
395 // subroutine is rewrited to follow the new established way of memory
396 // booking for tracking medias and rotation matrices.
397 // all used tracking media have to be defined first, for this you can use
398 // subroutine greutmed.
399 // top volume is searched as only volume not positioned into another
402 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
403 Int_t ndvmx, nr, flag;
404 char key[5], card[77], natmed[21];
405 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
408 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
410 const Int_t kMaxRot=5000;
411 Int_t idrot[kMaxRot],istop[7000];
414 // *** The input filnam name will be with extension '.euc'
415 filtmp=gSystem->ExpandPathName(filnam);
416 lun=fopen(filtmp,"r");
419 Error("ReadEuclid","Could not open file %s\n",filnam);
422 //* --- definition of rotation matrix 0 ---
423 TArrayI &idtmed = *fIdtmed;
424 for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
428 for(i=0;i<77;i++) card[i]=0;
429 iret=fscanf(lun,"%77[^\n]",card);
430 if(iret<=0) goto L20;
435 if (!strcmp(key,"TMED")) {
436 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
437 if( itmed<0 || itmed>=100 ) {
438 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
441 //Pad the string with blanks
444 while(i<20) natmed[i++]=' ';
447 if( idtmed[itmed]<=0 ) {
448 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
451 gMC->Gckmat(idtmed[itmed],natmed);
453 } else if (!strcmp(key,"ROTM")) {
454 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
455 if( irot<=0 || irot>=kMaxRot ) {
456 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
459 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
461 } else if (!strcmp(key,"VOLU")) {
462 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
464 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
467 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
468 //* save the defined volumes
469 strcpy(volst[++nvol],name);
472 } else if (!strcmp(key,"DIVN")) {
473 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
474 gMC->Gsdvn ( name, mother, ndiv, iaxe );
476 } else if (!strcmp(key,"DVN2")) {
477 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
478 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
480 } else if (!strcmp(key,"DIVT")) {
481 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
482 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
484 } else if (!strcmp(key,"DVT2")) {
485 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
486 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
488 } else if (!strcmp(key,"POSI")) {
489 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
490 if( irot<0 || irot>=kMaxRot ) {
491 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
494 if( idrot[irot] == -99) {
495 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
498 //*** volume name cannot be the top volume
499 for(i=1;i<=nvol;i++) {
500 if (!strcmp(volst[i],name)) istop[i]=0;
503 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
505 } else if (!strcmp(key,"POSP")) {
506 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
507 if( irot<0 || irot>=kMaxRot ) {
508 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
511 if( idrot[irot] == -99) {
512 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
516 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
519 //*** volume name cannot be the top volume
520 for(i=1;i<=nvol;i++) {
521 if (!strcmp(volst[i],name)) istop[i]=0;
524 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
527 if (strcmp(key,"END")) goto L10;
528 //* find top volume in the geometry
530 for(i=1;i<=nvol;i++) {
531 if (istop[i] && flag) {
532 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
534 if (istop[i] && !flag) {
535 strcpy(topvol,volst[i]);
536 if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol);
541 Warning("ReadEuclid","top volume not found\n");
545 //* commented out only for the not cernlib version
546 if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam);
551 Error("ReadEuclid","reading error or premature end of file\n");
554 //_____________________________________________________________________________
555 void AliModule::ReadEuclidMedia(const char* filnam)
558 // read in the materials and tracking media for the detector
559 // in euclid file format
561 // filnam: name of the input file
562 // id_det: id_det is the detector identification (2=its,...)
564 // author : miroslav helbich
566 Float_t sxmgmx = gAlice->Field()->Max();
567 Int_t isxfld = gAlice->Field()->Integ();
568 Int_t end, i, iret, itmed;
569 char key[5], card[130], natmed[21], namate[21];
574 Int_t nwbuf, isvol, ifield, nmat;
575 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
578 for(i=0;i<end;i++) if(filnam[i]=='.') {
583 // *** The input filnam name will be with extension '.euc'
584 if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug
585 filtmp=gSystem->ExpandPathName(filnam);
586 lun=fopen(filtmp,"r");
589 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
593 // Retrieve Mag Field parameters
594 Int_t globField=gAlice->Field()->Integ();
595 Float_t globMaxField=gAlice->Field()->Max();
596 // TArrayI &idtmed = *fIdtmed;
599 for(i=0;i<130;i++) card[i]=0;
600 iret=fscanf(lun,"%4s %[^\n]",key,card);
601 if(iret<=0) goto L20;
605 if (!strcmp(key,"MATE")) {
606 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
607 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
608 //Pad the string with blanks
611 while(i<20) namate[i++]=' ';
614 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
615 //* read tracking medium
616 } else if (!strcmp(key,"TMED")) {
617 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
618 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
619 &stemax,&deemax,&epsil,&stmin,&nwbuf);
620 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
621 if (ifield<0) ifield=isxfld;
622 if (fieldm<0) fieldm=sxmgmx;
623 //Pad the string with blanks
626 while(i<20) natmed[i++]=' ';
629 AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
630 stemax,deemax,epsil,stmin,ubuf,nwbuf);
631 // (*fImedia)[idtmed[itmed]-1]=id_det;
635 if (strcmp(key,"END")) goto L10;
638 //* commented out only for the not cernlib version
639 if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n",
645 Warning("ReadEuclidMedia","reading error or premature end of file\n");