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.17 2001/08/29 14:28:33 morsch
19 Use visibility flags -1 and 3 instead of 0 and 1.
21 Revision 1.16 2001/05/16 14:57:22 alibrary
22 New files for folders and Stack
24 Revision 1.15 2001/03/20 06:36:28 alibrary
25 100 parameters now allowed for geant shapes
27 Revision 1.14 2001/01/26 19:58:48 hristov
28 Major upgrade of AliRoot code
30 Revision 1.13 2000/11/30 07:12:49 alibrary
31 Introducing new Rndm and QA classes
33 Revision 1.12 2000/10/02 21:28:14 fca
34 Removal of useless dependecies via forward declarations
36 Revision 1.11 2000/07/12 08:56:25 fca
37 Coding convention correction and warning removal
39 Revision 1.10 2000/07/11 18:24:59 fca
40 Coding convention corrections + few minor bug fixes
42 Revision 1.9 2000/05/16 08:45:08 fca
43 Correct dtor, thanks to J.Belikov
45 Revision 1.8 2000/02/23 16:25:22 fca
46 AliVMC and AliGeant3 classes introduced
47 ReadEuclid moved from AliRun to AliModule
49 Revision 1.7 1999/09/29 09:24:29 fca
50 Introduction of the Copyright and cvs Log
54 ///////////////////////////////////////////////////////////////////////////////
56 // Base class for ALICE modules. Both sensitive modules (Modules) and //
57 // non-sensitive ones are described by this base class. This class //
58 // supports the hit and digit trees produced by the simulation and also //
59 // the objects produced by the reconstruction. //
61 // This class is also responsible for building the geometry of the //
66 <img src="picts/AliModuleClass.gif">
70 ///////////////////////////////////////////////////////////////////////////////
74 #include "AliModule.h"
78 #include "AliConfig.h"
82 //_____________________________________________________________________________
83 AliModule::AliModule()
86 // Default constructor for the AliModule class
96 //_____________________________________________________________________________
97 AliModule::AliModule(const char* name,const char *title):TNamed(name,title)
100 // Normal constructor invoked by all Modules.
101 // Create the list for Module specific histograms
102 // Add this Module to the global list of Modules in Run.
105 // Initialises the histogram list
106 fHistograms = new TList();
108 // Initialises the list of ROOT TNodes
109 fNodes = new TList();
111 // Get the Module numeric ID
112 Int_t id = gAlice->GetModuleID(name);
114 // Module already added !
115 Warning("Ctor","Module: %s already present at %d\n",name,id);
119 // Add this Module to the list of Modules
120 gAlice->Modules()->Add(this);
125 // Allocate space for tracking media and material indexes
126 fIdtmed = new TArrayI(100);
127 fIdmate = new TArrayI(100);
128 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
130 // Prepare to find the tracking media range
134 AliConfig::Instance()->Add(this);
136 SetDebug(gAlice->GetDebug());
141 //_____________________________________________________________________________
142 AliModule::AliModule(const AliModule &mod)
150 //_____________________________________________________________________________
151 AliModule::~AliModule()
158 // Delete ROOT geometry
164 // Delete TArray objects
169 //_____________________________________________________________________________
170 void AliModule::Copy(AliModule & /* mod */) const
173 // Copy *this onto mod, not implemented for AliModule
175 Fatal("Copy","Not implemented!\n");
178 //_____________________________________________________________________________
179 void AliModule::Disable()
182 // Disable Module on viewer
188 // Loop through geometry to disable all
189 // nodes for this Module
190 while((node = (TNode*)next())) {
191 node->SetVisibility(-1);
195 //_____________________________________________________________________________
196 Int_t AliModule::DistancetoPrimitive(Int_t, Int_t)
199 // Return distance from mouse pointer to object
200 // Dummy routine for the moment
205 //_____________________________________________________________________________
206 void AliModule::Enable()
209 // Enable Module on the viewver
215 // Loop through geometry to enable all
216 // nodes for this Module
217 while((node = (TNode*)next())) {
218 node->SetVisibility(3);
222 //_____________________________________________________________________________
223 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
224 Float_t z, Float_t dens, Float_t radl,
225 Float_t absl, Float_t *buf, Int_t nwbuf) const
228 // Store the parameters for a material
230 // imat the material index will be stored in (*fIdmate)[imat]
231 // name material name
235 // radl radiation length
236 // absl absorbtion length
237 // buf adress of an array user words
238 // nwbuf number of user words
241 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
242 (*fIdmate)[imat]=kmat;
245 //_____________________________________________________________________________
246 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
247 Float_t &z, Float_t &dens, Float_t &radl,
251 // Store the parameters for a material
253 // imat the material index will be stored in (*fIdmate)[imat]
254 // name material name
258 // radl radiation length
259 // absl absorbtion length
260 // buf adress of an array user words
261 // nwbuf number of user words
266 kmat=(*fIdmate)[imat];
267 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
271 //_____________________________________________________________________________
272 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
273 Float_t *z, Float_t dens, Int_t nlmat,
277 // Defines mixture or compound imat as composed by
278 // nlmat materials defined by arrays a, z and wmat
280 // If nlmat > 0 wmat contains the proportion by
281 // weights of each basic material in the mixture
283 // If nlmat < 0 wmat contains the number of atoms
284 // of eack kind in the molecule of the compound
285 // In this case, wmat is changed on output to the relative weigths.
287 // imat the material index will be stored in (*fIdmate)[imat]
288 // name material name
289 // a array of atomic masses
290 // z array of atomic numbers
292 // nlmat number of components
293 // wmat array of concentrations
296 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
297 (*fIdmate)[imat]=kmat;
300 //_____________________________________________________________________________
301 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
302 Int_t isvol, Int_t ifield, Float_t fieldm,
303 Float_t tmaxfd, Float_t stemax, Float_t deemax,
304 Float_t epsil, Float_t stmin, Float_t *ubuf,
308 // Store the parameters of a tracking medium
310 // numed the medium number is stored into (*fIdtmed)[numed]
312 // nmat the material number is stored into (*fIdmate)[nmat]
313 // isvol sensitive volume if isvol!=0
314 // ifield magnetic field flag (see below)
315 // fieldm maximum magnetic field
316 // tmaxfd maximum deflection angle due to magnetic field
317 // stemax maximum step allowed
318 // deemax maximum fractional energy loss in one step
319 // epsil tracking precision in cm
320 // stmin minimum step due to continuous processes
322 // ifield = 0 no magnetic field
323 // = -1 user decision in guswim
324 // = 1 tracking performed with Runge Kutta
325 // = 2 tracking performed with helix
326 // = 3 constant magnetic field along z
329 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
330 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
331 (*fIdtmed)[numed]=kmed;
334 //_____________________________________________________________________________
335 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
336 Float_t theta2, Float_t phi2, Float_t theta3,
340 // Define a rotation matrix. Angles are in degrees.
342 // nmat on output contains the number assigned to the rotation matrix
343 // theta1 polar angle for axis I
344 // phi1 azimuthal angle for axis I
345 // theta2 polar angle for axis II
346 // phi2 azimuthal angle for axis II
347 // theta3 polar angle for axis III
348 // phi3 azimuthal angle for axis III
350 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
353 //_____________________________________________________________________________
354 AliModule& AliModule::operator=(const AliModule &mod)
360 //_____________________________________________________________________________
361 Float_t AliModule::ZMin() const
366 //_____________________________________________________________________________
367 Float_t AliModule::ZMax() const
372 //_____________________________________________________________________________
373 void AliModule::SetEuclidFile(char* material, char* geometry)
376 // Sets the name of the Euclid file
378 fEuclidMaterial=material;
380 fEuclidGeometry=geometry;
382 char* name = new char[strlen(material)];
383 strcpy(name,material);
384 strcpy(&name[strlen(name)-4],".euc");
385 fEuclidGeometry=name;
390 //_____________________________________________________________________________
391 void AliModule::ReadEuclid(const char* filnam, char* topvol)
394 // read in the geometry of the detector in euclid file format
396 // id_det : the detector identification (2=its,...)
397 // topvol : return parameter describing the name of the top
398 // volume of geometry.
403 // several changes have been made by miroslav helbich
404 // subroutine is rewrited to follow the new established way of memory
405 // booking for tracking medias and rotation matrices.
406 // all used tracking media have to be defined first, for this you can use
407 // subroutine greutmed.
408 // top volume is searched as only volume not positioned into another
411 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
412 Int_t ndvmx, nr, flag;
413 char key[5], card[77], natmed[21];
414 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
417 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
419 const Int_t kMaxRot=5000;
420 Int_t idrot[kMaxRot],istop[7000];
423 // *** The input filnam name will be with extension '.euc'
424 filtmp=gSystem->ExpandPathName(filnam);
425 lun=fopen(filtmp,"r");
428 Error("ReadEuclid","Could not open file %s\n",filnam);
431 //* --- definition of rotation matrix 0 ---
432 TArrayI &idtmed = *fIdtmed;
433 for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
437 for(i=0;i<77;i++) card[i]=0;
438 iret=fscanf(lun,"%77[^\n]",card);
439 if(iret<=0) goto L20;
444 if (!strcmp(key,"TMED")) {
445 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
446 if( itmed<0 || itmed>=100 ) {
447 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
450 //Pad the string with blanks
453 while(i<20) natmed[i++]=' ';
456 if( idtmed[itmed]<=0 ) {
457 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
460 gMC->Gckmat(idtmed[itmed],natmed);
462 } else if (!strcmp(key,"ROTM")) {
463 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
464 if( irot<=0 || irot>=kMaxRot ) {
465 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
468 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
470 } else if (!strcmp(key,"VOLU")) {
471 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
473 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
476 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
477 //* save the defined volumes
478 strcpy(volst[++nvol],name);
481 } else if (!strcmp(key,"DIVN")) {
482 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
483 gMC->Gsdvn ( name, mother, ndiv, iaxe );
485 } else if (!strcmp(key,"DVN2")) {
486 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
487 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
489 } else if (!strcmp(key,"DIVT")) {
490 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
491 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
493 } else if (!strcmp(key,"DVT2")) {
494 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
495 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
497 } else if (!strcmp(key,"POSI")) {
498 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
499 if( irot<0 || irot>=kMaxRot ) {
500 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
503 if( idrot[irot] == -99) {
504 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
507 //*** volume name cannot be the top volume
508 for(i=1;i<=nvol;i++) {
509 if (!strcmp(volst[i],name)) istop[i]=0;
512 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
514 } else if (!strcmp(key,"POSP")) {
515 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
516 if( irot<0 || irot>=kMaxRot ) {
517 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
520 if( idrot[irot] == -99) {
521 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
525 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
528 //*** volume name cannot be the top volume
529 for(i=1;i<=nvol;i++) {
530 if (!strcmp(volst[i],name)) istop[i]=0;
533 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
536 if (strcmp(key,"END")) goto L10;
537 //* find top volume in the geometry
539 for(i=1;i<=nvol;i++) {
540 if (istop[i] && flag) {
541 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
543 if (istop[i] && !flag) {
544 strcpy(topvol,volst[i]);
545 if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol);
550 Warning("ReadEuclid","top volume not found\n");
554 //* commented out only for the not cernlib version
555 if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam);
560 Error("ReadEuclid","reading error or premature end of file\n");
563 //_____________________________________________________________________________
564 void AliModule::ReadEuclidMedia(const char* filnam)
567 // read in the materials and tracking media for the detector
568 // in euclid file format
570 // filnam: name of the input file
571 // id_det: id_det is the detector identification (2=its,...)
573 // author : miroslav helbich
575 Float_t sxmgmx = gAlice->Field()->Max();
576 Int_t isxfld = gAlice->Field()->Integ();
577 Int_t end, i, iret, itmed;
578 char key[5], card[130], natmed[21], namate[21];
583 Int_t nwbuf, isvol, ifield, nmat;
584 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
587 for(i=0;i<end;i++) if(filnam[i]=='.') {
592 // *** The input filnam name will be with extension '.euc'
593 if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug
594 filtmp=gSystem->ExpandPathName(filnam);
595 lun=fopen(filtmp,"r");
598 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
602 // Retrieve Mag Field parameters
603 Int_t globField=gAlice->Field()->Integ();
604 Float_t globMaxField=gAlice->Field()->Max();
605 // TArrayI &idtmed = *fIdtmed;
608 for(i=0;i<130;i++) card[i]=0;
609 iret=fscanf(lun,"%4s %[^\n]",key,card);
610 if(iret<=0) goto L20;
614 if (!strcmp(key,"MATE")) {
615 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
616 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
617 //Pad the string with blanks
620 while(i<20) namate[i++]=' ';
623 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
624 //* read tracking medium
625 } else if (!strcmp(key,"TMED")) {
626 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
627 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
628 &stemax,&deemax,&epsil,&stmin,&nwbuf);
629 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
630 if (ifield<0) ifield=isxfld;
631 if (fieldm<0) fieldm=sxmgmx;
632 //Pad the string with blanks
635 while(i<20) natmed[i++]=' ';
638 AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
639 stemax,deemax,epsil,stmin,ubuf,nwbuf);
640 // (*fImedia)[idtmed[itmed]-1]=id_det;
644 if (strcmp(key,"END")) goto L10;
647 //* commented out only for the not cernlib version
648 if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n",
654 Warning("ReadEuclidMedia","reading error or premature end of file\n");