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.11 2000/07/12 08:56:25 fca
19 Coding convention correction and warning removal
21 Revision 1.10 2000/07/11 18:24:59 fca
22 Coding convention corrections + few minor bug fixes
24 Revision 1.9 2000/05/16 08:45:08 fca
25 Correct dtor, thanks to J.Belikov
27 Revision 1.8 2000/02/23 16:25:22 fca
28 AliVMC and AliGeant3 classes introduced
29 ReadEuclid moved from AliRun to AliModule
31 Revision 1.7 1999/09/29 09:24:29 fca
32 Introduction of the Copyright and cvs Log
36 ///////////////////////////////////////////////////////////////////////////////
38 // Base class for ALICE modules. Both sensitive modules (Modules) and //
39 // non-sensitive ones are described by this base class. This class //
40 // supports the hit and digit trees produced by the simulation and also //
41 // the objects produced by the reconstruction. //
43 // This class is also responsible for building the geometry of the //
48 <img src="picts/AliModuleClass.gif">
52 ///////////////////////////////////////////////////////////////////////////////
58 #include "AliModule.h"
61 #include "AliPoints.h"
67 //_____________________________________________________________________________
68 AliModule::AliModule()
71 // Default constructor for the AliModule class
79 //_____________________________________________________________________________
80 AliModule::AliModule(const char* name,const char *title):TNamed(name,title)
83 // Normal constructor invoked by all Modules.
84 // Create the list for Module specific histograms
85 // Add this Module to the global list of Modules in Run.
88 // Initialises the histogram list
89 fHistograms = new TList();
91 // Initialises the list of ROOT TNodes
94 // Get the Module numeric ID
95 Int_t id = gAlice->GetModuleID(name);
97 // Module already added !
98 Warning("Ctor","Module: %s already present at %d\n",name,id);
102 // Add this Module to the list of Modules
103 gAlice->Modules()->Add(this);
108 // Allocate space for tracking media and material indexes
109 fIdtmed = new TArrayI(100);
110 fIdmate = new TArrayI(100);
111 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
113 // Prepare to find the tracking media range
118 //_____________________________________________________________________________
119 AliModule::AliModule(const AliModule &mod)
127 //_____________________________________________________________________________
128 AliModule::~AliModule()
135 // Delete ROOT geometry
141 // Delete TArray objects
146 //_____________________________________________________________________________
147 void AliModule::Copy(AliModule & /* mod */) const
150 // Copy *this onto mod, not implemented for AliModule
152 Fatal("Copy","Not implemented!\n");
155 //_____________________________________________________________________________
156 void AliModule::Disable()
159 // Disable Module on viewer
165 // Loop through geometry to disable all
166 // nodes for this Module
167 while((node = (TNode*)next())) {
168 node->SetVisibility(0);
172 //_____________________________________________________________________________
173 Int_t AliModule::DistancetoPrimitive(Int_t, Int_t)
176 // Return distance from mouse pointer to object
177 // Dummy routine for the moment
182 //_____________________________________________________________________________
183 void AliModule::Enable()
186 // Enable Module on the viewver
192 // Loop through geometry to enable all
193 // nodes for this Module
194 while((node = (TNode*)next())) {
195 node->SetVisibility(1);
199 //_____________________________________________________________________________
200 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
201 Float_t z, Float_t dens, Float_t radl,
202 Float_t absl, Float_t *buf, Int_t nwbuf) const
205 // Store the parameters for a material
207 // imat the material index will be stored in (*fIdmate)[imat]
208 // name material name
212 // radl radiation length
213 // absl absorbtion length
214 // buf adress of an array user words
215 // nwbuf number of user words
218 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
219 (*fIdmate)[imat]=kmat;
222 //_____________________________________________________________________________
223 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
224 Float_t &z, Float_t &dens, Float_t &radl,
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
243 kmat=(*fIdmate)[imat];
244 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
248 //_____________________________________________________________________________
249 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
250 Float_t *z, Float_t dens, Int_t nlmat,
254 // Defines mixture or compound imat as composed by
255 // nlmat materials defined by arrays a, z and wmat
257 // If nlmat > 0 wmat contains the proportion by
258 // weights of each basic material in the mixture
260 // If nlmat < 0 wmat contains the number of atoms
261 // of eack kind in the molecule of the compound
262 // In this case, wmat is changed on output to the relative weigths.
264 // imat the material index will be stored in (*fIdmate)[imat]
265 // name material name
266 // a array of atomic masses
267 // z array of atomic numbers
269 // nlmat number of components
270 // wmat array of concentrations
273 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
274 (*fIdmate)[imat]=kmat;
277 //_____________________________________________________________________________
278 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
279 Int_t isvol, Int_t ifield, Float_t fieldm,
280 Float_t tmaxfd, Float_t stemax, Float_t deemax,
281 Float_t epsil, Float_t stmin, Float_t *ubuf,
285 // Store the parameters of a tracking medium
287 // numed the medium number is stored into (*fIdtmed)[numed]
289 // nmat the material number is stored into (*fIdmate)[nmat]
290 // isvol sensitive volume if isvol!=0
291 // ifield magnetic field flag (see below)
292 // fieldm maximum magnetic field
293 // tmaxfd maximum deflection angle due to magnetic field
294 // stemax maximum step allowed
295 // deemax maximum fractional energy loss in one step
296 // epsil tracking precision in cm
297 // stmin minimum step due to continuous processes
299 // ifield = 0 no magnetic field
300 // = -1 user decision in guswim
301 // = 1 tracking performed with Runge Kutta
302 // = 2 tracking performed with helix
303 // = 3 constant magnetic field along z
306 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
307 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
308 (*fIdtmed)[numed]=kmed;
311 //_____________________________________________________________________________
312 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
313 Float_t theta2, Float_t phi2, Float_t theta3,
317 // Define a rotation matrix. Angles are in degrees.
319 // nmat on output contains the number assigned to the rotation matrix
320 // theta1 polar angle for axis I
321 // phi1 azimuthal angle for axis I
322 // theta2 polar angle for axis II
323 // phi2 azimuthal angle for axis II
324 // theta3 polar angle for axis III
325 // phi3 azimuthal angle for axis III
327 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
330 //_____________________________________________________________________________
331 AliModule& AliModule::operator=(const AliModule &mod)
337 //_____________________________________________________________________________
338 void AliModule::SetEuclidFile(char* material, char* geometry)
341 // Sets the name of the Euclid file
343 fEuclidMaterial=material;
345 fEuclidGeometry=geometry;
347 char* name = new char[strlen(material)];
348 strcpy(name,material);
349 strcpy(&name[strlen(name)-4],".euc");
350 fEuclidGeometry=name;
355 //_____________________________________________________________________________
356 void AliModule::ReadEuclid(const char* filnam, char* topvol)
359 // read in the geometry of the detector in euclid file format
361 // id_det : the detector identification (2=its,...)
362 // topvol : return parameter describing the name of the top
363 // volume of geometry.
368 // several changes have been made by miroslav helbich
369 // subroutine is rewrited to follow the new established way of memory
370 // booking for tracking medias and rotation matrices.
371 // all used tracking media have to be defined first, for this you can use
372 // subroutine greutmed.
373 // top volume is searched as only volume not positioned into another
376 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
377 Int_t ndvmx, nr, flag;
378 char key[5], card[77], natmed[21];
379 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
382 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
384 const Int_t kMaxRot=5000;
385 Int_t idrot[kMaxRot],istop[7000];
388 // *** The input filnam name will be with extension '.euc'
389 filtmp=gSystem->ExpandPathName(filnam);
390 lun=fopen(filtmp,"r");
393 Error("ReadEuclid","Could not open file %s\n",filnam);
396 //* --- definition of rotation matrix 0 ---
397 TArrayI &idtmed = *fIdtmed;
398 for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
402 for(i=0;i<77;i++) card[i]=0;
403 iret=fscanf(lun,"%77[^\n]",card);
404 if(iret<=0) goto L20;
409 if (!strcmp(key,"TMED")) {
410 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
411 if( itmed<0 || itmed>=100 ) {
412 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
415 //Pad the string with blanks
418 while(i<20) natmed[i++]=' ';
421 if( idtmed[itmed]<=0 ) {
422 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
425 gMC->Gckmat(idtmed[itmed],natmed);
427 } else if (!strcmp(key,"ROTM")) {
428 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
429 if( irot<=0 || irot>=kMaxRot ) {
430 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
433 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
435 } else if (!strcmp(key,"VOLU")) {
436 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
438 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
441 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
442 //* save the defined volumes
443 strcpy(volst[++nvol],name);
446 } else if (!strcmp(key,"DIVN")) {
447 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
448 gMC->Gsdvn ( name, mother, ndiv, iaxe );
450 } else if (!strcmp(key,"DVN2")) {
451 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
452 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
454 } else if (!strcmp(key,"DIVT")) {
455 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
456 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
458 } else if (!strcmp(key,"DVT2")) {
459 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
460 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
462 } else if (!strcmp(key,"POSI")) {
463 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
464 if( irot<0 || irot>=kMaxRot ) {
465 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
468 if( idrot[irot] == -99) {
469 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
472 //*** volume name cannot be the top volume
473 for(i=1;i<=nvol;i++) {
474 if (!strcmp(volst[i],name)) istop[i]=0;
477 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
479 } else if (!strcmp(key,"POSP")) {
480 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
481 if( irot<0 || irot>=kMaxRot ) {
482 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
485 if( idrot[irot] == -99) {
486 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
490 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
493 //*** volume name cannot be the top volume
494 for(i=1;i<=nvol;i++) {
495 if (!strcmp(volst[i],name)) istop[i]=0;
498 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
501 if (strcmp(key,"END")) goto L10;
502 //* find top volume in the geometry
504 for(i=1;i<=nvol;i++) {
505 if (istop[i] && flag) {
506 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
508 if (istop[i] && !flag) {
509 strcpy(topvol,volst[i]);
510 printf(" *** GREUCL *** volume %s taken as a top volume\n",topvol);
515 Warning("ReadEuclid","top volume not found\n");
519 //* commented out only for the not cernlib version
520 printf(" *** GREUCL *** file: %s is now read in\n",filnam);
525 Error("ReadEuclid","reading error or premature end of file\n");
528 //_____________________________________________________________________________
529 void AliModule::ReadEuclidMedia(const char* filnam)
532 // read in the materials and tracking media for the detector
533 // in euclid file format
535 // filnam: name of the input file
536 // id_det: id_det is the detector identification (2=its,...)
538 // author : miroslav helbich
540 Float_t sxmgmx = gAlice->Field()->Max();
541 Int_t isxfld = gAlice->Field()->Integ();
542 Int_t end, i, iret, itmed;
543 char key[5], card[130], natmed[21], namate[21];
548 Int_t nwbuf, isvol, ifield, nmat;
549 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
552 for(i=0;i<end;i++) if(filnam[i]=='.') {
557 // *** The input filnam name will be with extension '.euc'
558 printf("The file name is %s\n",filnam); //Debug
559 filtmp=gSystem->ExpandPathName(filnam);
560 lun=fopen(filtmp,"r");
563 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
567 // Retrieve Mag Field parameters
568 Int_t globField=gAlice->Field()->Integ();
569 Float_t globMaxField=gAlice->Field()->Max();
570 // TArrayI &idtmed = *fIdtmed;
573 for(i=0;i<130;i++) card[i]=0;
574 iret=fscanf(lun,"%4s %[^\n]",key,card);
575 if(iret<=0) goto L20;
579 if (!strcmp(key,"MATE")) {
580 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
581 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
582 //Pad the string with blanks
585 while(i<20) namate[i++]=' ';
588 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
589 //* read tracking medium
590 } else if (!strcmp(key,"TMED")) {
591 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
592 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
593 &stemax,&deemax,&epsil,&stmin,&nwbuf);
594 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
595 if (ifield<0) ifield=isxfld;
596 if (fieldm<0) fieldm=sxmgmx;
597 //Pad the string with blanks
600 while(i<20) natmed[i++]=' ';
603 AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
604 stemax,deemax,epsil,stmin,ubuf,nwbuf);
605 // (*fImedia)[idtmed[itmed]-1]=id_det;
609 if (strcmp(key,"END")) goto L10;
612 //* commented out only for the not cernlib version
613 Warning("ReadEuclidMedia","file: %s is now read in\n",filnam);
618 Warning("ReadEuclidMedia","reading error or premature end of file\n");
621 //_____________________________________________________________________________
622 void AliModule::Streamer(TBuffer &R__b)
625 // Stream an object of class Module.
627 if (R__b.IsReading()) {
628 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
629 TNamed::Streamer(R__b);
630 TAttLine::Streamer(R__b);
631 TAttMarker::Streamer(R__b);
632 fEuclidMaterial.Streamer(R__b);
633 fEuclidGeometry.Streamer(R__b);
637 // Stream the pointers but not the TClonesArrays
638 R__b >> fNodes; // diff
640 R__b.WriteVersion(AliModule::IsA());
641 TNamed::Streamer(R__b);
642 TAttLine::Streamer(R__b);
643 TAttMarker::Streamer(R__b);
644 fEuclidMaterial.Streamer(R__b);
645 fEuclidGeometry.Streamer(R__b);
649 // Stream the pointers but not the TClonesArrays
650 R__b << fNodes; // diff