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.9 2000/05/16 08:45:08 fca
19 Correct dtor, thanks to J.Belikov
21 Revision 1.8 2000/02/23 16:25:22 fca
22 AliVMC and AliGeant3 classes introduced
23 ReadEuclid moved from AliRun to AliModule
25 Revision 1.7 1999/09/29 09:24:29 fca
26 Introduction of the Copyright and cvs Log
30 ///////////////////////////////////////////////////////////////////////////////
32 // Base class for ALICE modules. Both sensitive modules (Modules) and //
33 // non-sensitive ones are described by this base class. This class //
34 // supports the hit and digit trees produced by the simulation and also //
35 // the objects produced by the reconstruction. //
37 // This class is also responsible for building the geometry of the //
42 <img src="picts/AliModuleClass.gif">
46 ///////////////////////////////////////////////////////////////////////////////
47 #include "AliModule.h"
50 #include "AliPoints.h"
57 //_____________________________________________________________________________
58 AliModule::AliModule()
61 // Default constructor for the AliModule class
69 //_____________________________________________________________________________
70 AliModule::AliModule(const char* name,const char *title):TNamed(name,title)
73 // Normal constructor invoked by all Modules.
74 // Create the list for Module specific histograms
75 // Add this Module to the global list of Modules in Run.
78 // Initialises the histogram list
79 fHistograms = new TList();
81 // Initialises the list of ROOT TNodes
84 // Get the Module numeric ID
85 Int_t id = gAlice->GetModuleID(name);
87 // Module already added !
88 Warning("Ctor","Module: %s already present at %d\n",name,id);
92 // Add this Module to the list of Modules
93 gAlice->Modules()->Add(this);
98 // Allocate space for tracking media and material indexes
99 fIdtmed = new TArrayI(100);
100 fIdmate = new TArrayI(100);
101 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
103 // Prepare to find the tracking media range
108 //_____________________________________________________________________________
109 AliModule::AliModule(const AliModule &mod)
117 //_____________________________________________________________________________
118 AliModule::~AliModule()
125 // Delete ROOT geometry
131 // Delete TArray objects
136 //_____________________________________________________________________________
137 void AliModule::Copy(AliModule &mod) const
140 // Copy *this onto mod, not implemented for AliModule
142 Fatal("Copy","Not implemented!\n");
145 //_____________________________________________________________________________
146 void AliModule::Disable()
149 // Disable Module on viewer
155 // Loop through geometry to disable all
156 // nodes for this Module
157 while((node = (TNode*)next())) {
158 node->SetVisibility(0);
162 //_____________________________________________________________________________
163 Int_t AliModule::DistancetoPrimitive(Int_t, Int_t)
166 // Return distance from mouse pointer to object
167 // Dummy routine for the moment
172 //_____________________________________________________________________________
173 void AliModule::Enable()
176 // Enable Module on the viewver
182 // Loop through geometry to enable all
183 // nodes for this Module
184 while((node = (TNode*)next())) {
185 node->SetVisibility(1);
189 //_____________________________________________________________________________
190 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
191 Float_t z, Float_t dens, Float_t radl,
192 Float_t absl, Float_t *buf, Int_t nwbuf) const
195 // Store the parameters for a material
197 // imat the material index will be stored in (*fIdmate)[imat]
198 // name material name
202 // radl radiation length
203 // absl absorbtion length
204 // buf adress of an array user words
205 // nwbuf number of user words
208 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
209 (*fIdmate)[imat]=kmat;
212 //_____________________________________________________________________________
213 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
214 Float_t &z, Float_t &dens, Float_t &radl,
218 // Store the parameters for a material
220 // imat the material index will be stored in (*fIdmate)[imat]
221 // name material name
225 // radl radiation length
226 // absl absorbtion length
227 // buf adress of an array user words
228 // nwbuf number of user words
233 kmat=(*fIdmate)[imat];
234 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
238 //_____________________________________________________________________________
239 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
240 Float_t *z, Float_t dens, Int_t nlmat,
244 // Defines mixture or compound imat as composed by
245 // nlmat materials defined by arrays a, z and wmat
247 // If nlmat > 0 wmat contains the proportion by
248 // weights of each basic material in the mixture
250 // If nlmat < 0 wmat contains the number of atoms
251 // of eack kind in the molecule of the compound
252 // In this case, wmat is changed on output to the relative weigths.
254 // imat the material index will be stored in (*fIdmate)[imat]
255 // name material name
256 // a array of atomic masses
257 // z array of atomic numbers
259 // nlmat number of components
260 // wmat array of concentrations
263 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
264 (*fIdmate)[imat]=kmat;
267 //_____________________________________________________________________________
268 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
269 Int_t isvol, Int_t ifield, Float_t fieldm,
270 Float_t tmaxfd, Float_t stemax, Float_t deemax,
271 Float_t epsil, Float_t stmin, Float_t *ubuf,
275 // Store the parameters of a tracking medium
277 // numed the medium number is stored into (*fIdtmed)[numed]
279 // nmat the material number is stored into (*fIdmate)[nmat]
280 // isvol sensitive volume if isvol!=0
281 // ifield magnetic field flag (see below)
282 // fieldm maximum magnetic field
283 // tmaxfd maximum deflection angle due to magnetic field
284 // stemax maximum step allowed
285 // deemax maximum fractional energy loss in one step
286 // epsil tracking precision in cm
287 // stmin minimum step due to continuous processes
289 // ifield = 0 no magnetic field
290 // = -1 user decision in guswim
291 // = 1 tracking performed with Runge Kutta
292 // = 2 tracking performed with helix
293 // = 3 constant magnetic field along z
296 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
297 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
298 (*fIdtmed)[numed]=kmed;
301 //_____________________________________________________________________________
302 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
303 Float_t theta2, Float_t phi2, Float_t theta3,
307 // Define a rotation matrix. Angles are in degrees.
309 // nmat on output contains the number assigned to the rotation matrix
310 // theta1 polar angle for axis I
311 // phi1 azimuthal angle for axis I
312 // theta2 polar angle for axis II
313 // phi2 azimuthal angle for axis II
314 // theta3 polar angle for axis III
315 // phi3 azimuthal angle for axis III
317 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
320 //_____________________________________________________________________________
321 AliModule& AliModule::operator=(const AliModule &mod)
327 //_____________________________________________________________________________
328 void AliModule::SetEuclidFile(char* material, char* geometry)
331 // Sets the name of the Euclid file
333 fEuclidMaterial=material;
335 fEuclidGeometry=geometry;
337 char* name = new char[strlen(material)];
338 strcpy(name,material);
339 strcpy(&name[strlen(name)-4],".euc");
340 fEuclidGeometry=name;
345 //_____________________________________________________________________________
346 void AliModule::ReadEuclid(const char* filnam, char* topvol)
349 // read in the geometry of the detector in euclid file format
351 // id_det : the detector identification (2=its,...)
352 // topvol : return parameter describing the name of the top
353 // volume of geometry.
358 // several changes have been made by miroslav helbich
359 // subroutine is rewrited to follow the new established way of memory
360 // booking for tracking medias and rotation matrices.
361 // all used tracking media have to be defined first, for this you can use
362 // subroutine greutmed.
363 // top volume is searched as only volume not positioned into another
366 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
367 Int_t ndvmx, nr, flag;
368 char key[5], card[77], natmed[21];
369 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
372 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
374 const Int_t kMaxRot=5000;
375 Int_t idrot[kMaxRot],istop[7000];
378 // *** The input filnam name will be with extension '.euc'
379 filtmp=gSystem->ExpandPathName(filnam);
380 lun=fopen(filtmp,"r");
383 Error("ReadEuclid","Could not open file %s\n",filnam);
386 //* --- definition of rotation matrix 0 ---
387 TArrayI &idtmed = *fIdtmed;
388 for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
392 for(i=0;i<77;i++) card[i]=0;
393 iret=fscanf(lun,"%77[^\n]",card);
394 if(iret<=0) goto L20;
399 if (!strcmp(key,"TMED")) {
400 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
401 if( itmed<0 || itmed>=100 ) {
402 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
405 //Pad the string with blanks
408 while(i<20) natmed[i++]=' ';
411 if( idtmed[itmed]<=0 ) {
412 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
415 gMC->Gckmat(idtmed[itmed],natmed);
417 } else if (!strcmp(key,"ROTM")) {
418 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
419 if( irot<=0 || irot>=kMaxRot ) {
420 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
423 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
425 } else if (!strcmp(key,"VOLU")) {
426 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
428 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
431 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
432 //* save the defined volumes
433 strcpy(volst[++nvol],name);
436 } else if (!strcmp(key,"DIVN")) {
437 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
438 gMC->Gsdvn ( name, mother, ndiv, iaxe );
440 } else if (!strcmp(key,"DVN2")) {
441 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
442 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
444 } else if (!strcmp(key,"DIVT")) {
445 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
446 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
448 } else if (!strcmp(key,"DVT2")) {
449 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
450 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
452 } else if (!strcmp(key,"POSI")) {
453 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
454 if( irot<0 || irot>=kMaxRot ) {
455 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
458 if( idrot[irot] == -99) {
459 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
462 //*** volume name cannot be the top volume
463 for(i=1;i<=nvol;i++) {
464 if (!strcmp(volst[i],name)) istop[i]=0;
467 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
469 } else if (!strcmp(key,"POSP")) {
470 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
471 if( irot<0 || irot>=kMaxRot ) {
472 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
475 if( idrot[irot] == -99) {
476 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
480 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
483 //*** volume name cannot be the top volume
484 for(i=1;i<=nvol;i++) {
485 if (!strcmp(volst[i],name)) istop[i]=0;
488 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
491 if (strcmp(key,"END")) goto L10;
492 //* find top volume in the geometry
494 for(i=1;i<=nvol;i++) {
495 if (istop[i] && flag) {
496 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
498 if (istop[i] && !flag) {
499 strcpy(topvol,volst[i]);
500 printf(" *** GREUCL *** volume %s taken as a top volume\n",topvol);
505 Warning("ReadEuclid","top volume not found\n");
509 //* commented out only for the not cernlib version
510 printf(" *** GREUCL *** file: %s is now read in\n",filnam);
515 Error("ReadEuclid","reading error or premature end of file\n");
518 //_____________________________________________________________________________
519 void AliModule::ReadEuclidMedia(const char* filnam)
522 // read in the materials and tracking media for the detector
523 // in euclid file format
525 // filnam: name of the input file
526 // id_det: id_det is the detector identification (2=its,...)
528 // author : miroslav helbich
530 Float_t sxmgmx = gAlice->Field()->Max();
531 Int_t isxfld = gAlice->Field()->Integ();
532 Int_t end, i, iret, itmed;
533 char key[5], card[130], natmed[21], namate[21];
538 Int_t nwbuf, isvol, ifield, nmat;
539 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
542 for(i=0;i<end;i++) if(filnam[i]=='.') {
547 // *** The input filnam name will be with extension '.euc'
548 printf("The file name is %s\n",filnam); //Debug
549 filtmp=gSystem->ExpandPathName(filnam);
550 lun=fopen(filtmp,"r");
553 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
557 // Retrieve Mag Field parameters
558 Int_t globField=gAlice->Field()->Integ();
559 Float_t globMaxField=gAlice->Field()->Max();
560 // TArrayI &idtmed = *fIdtmed;
563 for(i=0;i<130;i++) card[i]=0;
564 iret=fscanf(lun,"%4s %[^\n]",key,card);
565 if(iret<=0) goto L20;
569 if (!strcmp(key,"MATE")) {
570 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
571 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
572 //Pad the string with blanks
575 while(i<20) namate[i++]=' ';
578 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
579 //* read tracking medium
580 } else if (!strcmp(key,"TMED")) {
581 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
582 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
583 &stemax,&deemax,&epsil,&stmin,&nwbuf);
584 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
585 if (ifield<0) ifield=isxfld;
586 if (fieldm<0) fieldm=sxmgmx;
587 //Pad the string with blanks
590 while(i<20) natmed[i++]=' ';
593 AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
594 stemax,deemax,epsil,stmin,ubuf,nwbuf);
595 // (*fImedia)[idtmed[itmed]-1]=id_det;
599 if (strcmp(key,"END")) goto L10;
602 //* commented out only for the not cernlib version
603 Warning("ReadEuclidMedia","file: %s is now read in\n",filnam);
608 Warning("ReadEuclidMedia","reading error or premature end of file\n");
611 //_____________________________________________________________________________
612 void AliModule::Streamer(TBuffer &R__b)
615 // Stream an object of class Module.
617 if (R__b.IsReading()) {
618 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
619 TNamed::Streamer(R__b);
620 TAttLine::Streamer(R__b);
621 TAttMarker::Streamer(R__b);
622 fEuclidMaterial.Streamer(R__b);
623 fEuclidGeometry.Streamer(R__b);
627 // Stream the pointers but not the TClonesArrays
628 R__b >> fNodes; // diff
630 R__b.WriteVersion(AliModule::IsA());
631 TNamed::Streamer(R__b);
632 TAttLine::Streamer(R__b);
633 TAttMarker::Streamer(R__b);
634 fEuclidMaterial.Streamer(R__b);
635 fEuclidGeometry.Streamer(R__b);
639 // Stream the pointers but not the TClonesArrays
640 R__b << fNodes; // diff