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.8 2000/02/23 16:25:22 fca
19 AliVMC and AliGeant3 classes introduced
20 ReadEuclid moved from AliRun to AliModule
22 Revision 1.7 1999/09/29 09:24:29 fca
23 Introduction of the Copyright and cvs Log
27 ///////////////////////////////////////////////////////////////////////////////
29 // Base class for ALICE modules. Both sensitive modules (Modules) and //
30 // non-sensitive ones are described by this base class. This class //
31 // supports the hit and digit trees produced by the simulation and also //
32 // the objects produced by the reconstruction. //
34 // This class is also responsible for building the geometry of the //
39 <img src="picts/AliModuleClass.gif">
43 ///////////////////////////////////////////////////////////////////////////////
44 #include "AliModule.h"
47 #include "AliPoints.h"
54 //_____________________________________________________________________________
55 AliModule::AliModule()
58 // Default constructor for the AliModule class
64 //_____________________________________________________________________________
65 AliModule::AliModule(const char* name,const char *title):TNamed(name,title)
68 // Normal constructor invoked by all Modules.
69 // Create the list for Module specific histograms
70 // Add this Module to the global list of Modules in Run.
73 // Initialises the histogram list
74 fHistograms = new TList();
76 // Initialises the list of ROOT TNodes
79 // Get the Module numeric ID
80 Int_t id = gAlice->GetModuleID(name);
82 // Module already added !
83 Warning("Ctor","Module: %s already present at %d\n",name,id);
87 // Add this Module to the list of Modules
88 gAlice->Modules()->Add(this);
93 // Allocate space for tracking media and material indexes
94 fIdtmed = new TArrayI(100);
95 fIdmate = new TArrayI(100);
96 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
98 // Prepare to find the tracking media range
103 //_____________________________________________________________________________
104 AliModule::~AliModule()
111 // Delete ROOT geometry
117 // Delete TArray objects
122 //_____________________________________________________________________________
123 void AliModule::Disable()
126 // Disable Module on viewer
132 // Loop through geometry to disable all
133 // nodes for this Module
134 while((node = (TNode*)next())) {
135 node->SetVisibility(0);
139 //_____________________________________________________________________________
140 Int_t AliModule::DistancetoPrimitive(Int_t, Int_t)
143 // Return distance from mouse pointer to object
144 // Dummy routine for the moment
149 //_____________________________________________________________________________
150 void AliModule::Enable()
153 // Enable Module on the viewver
159 // Loop through geometry to enable all
160 // nodes for this Module
161 while((node = (TNode*)next())) {
162 node->SetVisibility(1);
166 //_____________________________________________________________________________
167 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
168 Float_t z, Float_t dens, Float_t radl,
169 Float_t absl, Float_t *buf, Int_t nwbuf) const
172 // Store the parameters for a material
174 // imat the material index will be stored in (*fIdmate)[imat]
175 // name material name
179 // radl radiation length
180 // absl absorbtion length
181 // buf adress of an array user words
182 // nwbuf number of user words
185 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
186 (*fIdmate)[imat]=kmat;
189 //_____________________________________________________________________________
190 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
191 Float_t &z, Float_t &dens, Float_t &radl,
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
210 kmat=(*fIdmate)[imat];
211 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
215 //_____________________________________________________________________________
216 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
217 Float_t *z, Float_t dens, Int_t nlmat,
221 // Defines mixture or compound imat as composed by
222 // nlmat materials defined by arrays a, z and wmat
224 // If nlmat > 0 wmat contains the proportion by
225 // weights of each basic material in the mixture
227 // If nlmat < 0 wmat contains the number of atoms
228 // of eack kind in the molecule of the compound
229 // In this case, wmat is changed on output to the relative weigths.
231 // imat the material index will be stored in (*fIdmate)[imat]
232 // name material name
233 // a array of atomic masses
234 // z array of atomic numbers
236 // nlmat number of components
237 // wmat array of concentrations
240 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
241 (*fIdmate)[imat]=kmat;
244 //_____________________________________________________________________________
245 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
246 Int_t isvol, Int_t ifield, Float_t fieldm,
247 Float_t tmaxfd, Float_t stemax, Float_t deemax,
248 Float_t epsil, Float_t stmin, Float_t *ubuf,
252 // Store the parameters of a tracking medium
254 // numed the medium number is stored into (*fIdtmed)[numed]
256 // nmat the material number is stored into (*fIdmate)[nmat]
257 // isvol sensitive volume if isvol!=0
258 // ifield magnetic field flag (see below)
259 // fieldm maximum magnetic field
260 // tmaxfd maximum deflection angle due to magnetic field
261 // stemax maximum step allowed
262 // deemax maximum fractional energy loss in one step
263 // epsil tracking precision in cm
264 // stmin minimum step due to continuous processes
266 // ifield = 0 no magnetic field
267 // = -1 user decision in guswim
268 // = 1 tracking performed with Runge Kutta
269 // = 2 tracking performed with helix
270 // = 3 constant magnetic field along z
273 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
274 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
275 (*fIdtmed)[numed]=kmed;
278 //_____________________________________________________________________________
279 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
280 Float_t theta2, Float_t phi2, Float_t theta3,
284 // Define a rotation matrix. Angles are in degrees.
286 // nmat on output contains the number assigned to the rotation matrix
287 // theta1 polar angle for axis I
288 // phi1 azimuthal angle for axis I
289 // theta2 polar angle for axis II
290 // phi2 azimuthal angle for axis II
291 // theta3 polar angle for axis III
292 // phi3 azimuthal angle for axis III
294 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
297 //_____________________________________________________________________________
298 void AliModule::SetEuclidFile(char* material, char* geometry)
301 // Sets the name of the Euclid file
303 fEuclidMaterial=material;
305 fEuclidGeometry=geometry;
307 char* name = new char[strlen(material)];
308 strcpy(name,material);
309 strcpy(&name[strlen(name)-4],".euc");
310 fEuclidGeometry=name;
315 //_____________________________________________________________________________
316 void AliModule::ReadEuclid(const char* filnam, char* topvol)
319 // read in the geometry of the detector in euclid file format
321 // id_det : the detector identification (2=its,...)
322 // topvol : return parameter describing the name of the top
323 // volume of geometry.
328 // several changes have been made by miroslav helbich
329 // subroutine is rewrited to follow the new established way of memory
330 // booking for tracking medias and rotation matrices.
331 // all used tracking media have to be defined first, for this you can use
332 // subroutine greutmed.
333 // top volume is searched as only volume not positioned into another
336 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
337 Int_t ndvmx, nr, flag;
338 char key[5], card[77], natmed[21];
339 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
342 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
344 const Int_t maxrot=5000;
345 Int_t idrot[maxrot],istop[7000];
348 // *** The input filnam name will be with extension '.euc'
349 filtmp=gSystem->ExpandPathName(filnam);
350 lun=fopen(filtmp,"r");
353 Error("ReadEuclid","Could not open file %s\n",filnam);
356 //* --- definition of rotation matrix 0 ---
357 TArrayI &idtmed = *fIdtmed;
358 for(i=1; i<maxrot; ++i) idrot[i]=-99;
362 for(i=0;i<77;i++) card[i]=0;
363 iret=fscanf(lun,"%77[^\n]",card);
364 if(iret<=0) goto L20;
369 if (!strcmp(key,"TMED")) {
370 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
371 if( itmed<0 || itmed>=100 ) {
372 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
375 //Pad the string with blanks
378 while(i<20) natmed[i++]=' ';
381 if( idtmed[itmed]<=0 ) {
382 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
385 gMC->Gckmat(idtmed[itmed],natmed);
387 } else if (!strcmp(key,"ROTM")) {
388 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
389 if( irot<=0 || irot>=maxrot ) {
390 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
393 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
395 } else if (!strcmp(key,"VOLU")) {
396 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
398 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
401 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
402 //* save the defined volumes
403 strcpy(volst[++nvol],name);
406 } else if (!strcmp(key,"DIVN")) {
407 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
408 gMC->Gsdvn ( name, mother, ndiv, iaxe );
410 } else if (!strcmp(key,"DVN2")) {
411 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
412 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
414 } else if (!strcmp(key,"DIVT")) {
415 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
416 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
418 } else if (!strcmp(key,"DVT2")) {
419 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
420 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
422 } else if (!strcmp(key,"POSI")) {
423 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
424 if( irot<0 || irot>=maxrot ) {
425 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
428 if( idrot[irot] == -99) {
429 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
432 //*** volume name cannot be the top volume
433 for(i=1;i<=nvol;i++) {
434 if (!strcmp(volst[i],name)) istop[i]=0;
437 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
439 } else if (!strcmp(key,"POSP")) {
440 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
441 if( irot<0 || irot>=maxrot ) {
442 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
445 if( idrot[irot] == -99) {
446 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
450 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
453 //*** volume name cannot be the top volume
454 for(i=1;i<=nvol;i++) {
455 if (!strcmp(volst[i],name)) istop[i]=0;
458 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
461 if (strcmp(key,"END")) goto L10;
462 //* find top volume in the geometry
464 for(i=1;i<=nvol;i++) {
465 if (istop[i] && flag) {
466 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
468 if (istop[i] && !flag) {
469 strcpy(topvol,volst[i]);
470 printf(" *** GREUCL *** volume %s taken as a top volume\n",topvol);
475 Warning("ReadEuclid","top volume not found\n");
479 //* commented out only for the not cernlib version
480 printf(" *** GREUCL *** file: %s is now read in\n",filnam);
485 Error("ReadEuclid","reading error or premature end of file\n");
488 //_____________________________________________________________________________
489 void AliModule::ReadEuclidMedia(const char* filnam)
492 // read in the materials and tracking media for the detector
493 // in euclid file format
495 // filnam: name of the input file
496 // id_det: id_det is the detector identification (2=its,...)
498 // author : miroslav helbich
500 Float_t sxmgmx = gAlice->Field()->Max();
501 Int_t isxfld = gAlice->Field()->Integ();
502 Int_t end, i, iret, itmed;
503 char key[5], card[130], natmed[21], namate[21];
508 Int_t nwbuf, isvol, ifield, nmat;
509 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
512 for(i=0;i<end;i++) if(filnam[i]=='.') {
517 // *** The input filnam name will be with extension '.euc'
518 printf("The file name is %s\n",filnam); //Debug
519 filtmp=gSystem->ExpandPathName(filnam);
520 lun=fopen(filtmp,"r");
523 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
527 // Retrieve Mag Field parameters
528 Int_t ISXFLD=gAlice->Field()->Integ();
529 Float_t SXMGMX=gAlice->Field()->Max();
530 // TArrayI &idtmed = *fIdtmed;
533 for(i=0;i<130;i++) card[i]=0;
534 iret=fscanf(lun,"%4s %[^\n]",key,card);
535 if(iret<=0) goto L20;
539 if (!strcmp(key,"MATE")) {
540 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
541 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
542 //Pad the string with blanks
545 while(i<20) namate[i++]=' ';
548 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
549 //* read tracking medium
550 } else if (!strcmp(key,"TMED")) {
551 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
552 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
553 &stemax,&deemax,&epsil,&stmin,&nwbuf);
554 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
555 if (ifield<0) ifield=isxfld;
556 if (fieldm<0) fieldm=sxmgmx;
557 //Pad the string with blanks
560 while(i<20) natmed[i++]=' ';
563 AliMedium(itmed,natmed,nmat,isvol,ISXFLD,SXMGMX,tmaxfd,
564 stemax,deemax,epsil,stmin,ubuf,nwbuf);
565 // (*fImedia)[idtmed[itmed]-1]=id_det;
569 if (strcmp(key,"END")) goto L10;
572 //* commented out only for the not cernlib version
573 Warning("ReadEuclidMedia","file: %s is now read in\n",filnam);
578 Warning("ReadEuclidMedia","reading error or premature end of file\n");
581 //_____________________________________________________________________________
582 void AliModule::Streamer(TBuffer &R__b)
585 // Stream an object of class Module.
587 if (R__b.IsReading()) {
588 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
589 TNamed::Streamer(R__b);
590 TAttLine::Streamer(R__b);
591 TAttMarker::Streamer(R__b);
592 fEuclidMaterial.Streamer(R__b);
593 fEuclidGeometry.Streamer(R__b);
597 // Stream the pointers but not the TClonesArrays
598 R__b >> fNodes; // diff
600 R__b.WriteVersion(AliModule::IsA());
601 TNamed::Streamer(R__b);
602 TAttLine::Streamer(R__b);
603 TAttMarker::Streamer(R__b);
604 fEuclidMaterial.Streamer(R__b);
605 fEuclidGeometry.Streamer(R__b);
609 // Stream the pointers but not the TClonesArrays
610 R__b << fNodes; // diff