Removing the module from the list of modules in the destructor
[u/mrichter/AliRoot.git] / STEER / AliModule.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
acd84897 16/* $Id$ */
4c039060 17
8494b010 18///////////////////////////////////////////////////////////////////////////////
19// //
20// Base class for ALICE modules. Both sensitive modules (Modules) and //
21// non-sensitive ones are described by this base class. This class //
22// supports the hit and digit trees produced by the simulation and also //
23// the objects produced by the reconstruction. //
24// //
25// This class is also responsible for building the geometry of the //
26// Modules. //
27// //
28//Begin_Html
29/*
1439f98e 30<img src="picts/AliModuleClass.gif">
8494b010 31*/
32//End_Html
33// //
34///////////////////////////////////////////////////////////////////////////////
94de3818 35#include <TNode.h>
116cbefd 36#include <TObjArray.h>
37#include <TSystem.h>
94de3818 38
8494b010 39#include "AliModule.h"
40#include "AliRun.h"
94de3818 41#include "AliMagF.h"
9e1a0ddb 42#include "AliConfig.h"
8494b010 43
44ClassImp(AliModule)
45
e2afb3b6 46//_______________________________________________________________________
47AliModule::AliModule():
48 fEuclidMaterial(""),
49 fEuclidGeometry(""),
50 fIdtmed(0),
51 fIdmate(0),
52 fLoMedium(0),
53 fHiMedium(0),
54 fActive(0),
55 fHistograms(0),
56 fNodes(0),
57 fDebug(0),
58 fEnable(1)
8494b010 59{
60 //
61 // Default constructor for the AliModule class
62 //
8494b010 63}
64
e2afb3b6 65//_______________________________________________________________________
66AliModule::AliModule(const char* name,const char *title):
67 TNamed(name,title),
68 fEuclidMaterial(""),
69 fEuclidGeometry(""),
70 fIdtmed(new TArrayI(100)),
71 fIdmate(new TArrayI(100)),
72 fLoMedium(65536),
73 fHiMedium(0),
74 fActive(0),
75 fHistograms(new TList()),
76 fNodes(new TList()),
77 fDebug(0),
78 fEnable(1)
8494b010 79{
80 //
81 // Normal constructor invoked by all Modules.
82 // Create the list for Module specific histograms
83 // Add this Module to the global list of Modules in Run.
84 //
8494b010 85 // Get the Module numeric ID
86 Int_t id = gAlice->GetModuleID(name);
02ca2762 87 if (id>=0) {
88 // Module already added !
89 Warning("Ctor","Module: %s already present at %d\n",name,id);
8494b010 90 return;
91 }
92 //
93 // Add this Module to the list of Modules
02ca2762 94 gAlice->Modules()->Add(this);
8494b010 95 //
96 //
97 SetMarkerColor(3);
98 //
e2afb3b6 99 // Clear space for tracking media and material indexes
100
8494b010 101 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
9e1a0ddb 102
103 AliConfig::Instance()->Add(this);
104
65fb704d 105 SetDebug(gAlice->GetDebug());
8494b010 106}
107
e2afb3b6 108//_______________________________________________________________________
109AliModule::AliModule(const AliModule &mod):
110 TNamed(mod),
111 TAttLine(mod),
112 TAttMarker(mod),
113 AliRndm(mod),
114 fEuclidMaterial(""),
115 fEuclidGeometry(""),
116 fIdtmed(0),
117 fIdmate(0),
118 fLoMedium(0),
119 fHiMedium(0),
120 fActive(0),
121 fHistograms(0),
122 fNodes(0),
123 fDebug(0),
124 fEnable(0)
aee8290b 125{
126 //
127 // Copy constructor
128 //
8918e700 129 mod.Copy(*this);
aee8290b 130}
131
e2afb3b6 132//_______________________________________________________________________
8494b010 133AliModule::~AliModule()
134{
135 //
136 // Destructor
137 //
e2afb3b6 138
bbcea4df 139 // Remove this Module from the list of Modules
140 gAlice->Modules()->Remove(this);
141
8494b010 142 // Delete ROOT geometry
bf9b027f 143 if(fNodes) {
144 fNodes->Clear();
145 delete fNodes;
146 }
8494b010 147 //
148 // Delete TArray objects
149 delete fIdtmed;
150 delete fIdmate;
151}
152
e2afb3b6 153//_______________________________________________________________________
8918e700 154void AliModule::Copy(AliModule & /* mod */) const
aee8290b 155{
156 //
157 // Copy *this onto mod, not implemented for AliModule
158 //
159 Fatal("Copy","Not implemented!\n");
160}
161
e2afb3b6 162//_______________________________________________________________________
8494b010 163void AliModule::Disable()
164{
165 //
166 // Disable Module on viewer
167 //
168 fActive = kFALSE;
169 TIter next(fNodes);
170 TNode *node;
171 //
172 // Loop through geometry to disable all
173 // nodes for this Module
e2afb3b6 174 while((node = dynamic_cast<TNode*>(next()))) {
5bef1017 175 node->SetVisibility(-1);
8494b010 176 }
177}
178
e2afb3b6 179//_______________________________________________________________________
116cbefd 180Int_t AliModule::DistancetoPrimitive(Int_t, Int_t) const
8494b010 181{
182 //
183 // Return distance from mouse pointer to object
184 // Dummy routine for the moment
185 //
186 return 9999;
187}
188
e2afb3b6 189//_______________________________________________________________________
8494b010 190void AliModule::Enable()
191{
192 //
193 // Enable Module on the viewver
194 //
195 fActive = kTRUE;
196 TIter next(fNodes);
197 TNode *node;
198 //
199 // Loop through geometry to enable all
200 // nodes for this Module
e2afb3b6 201 while((node = dynamic_cast<TNode*>(next()))) {
5bef1017 202 node->SetVisibility(3);
8494b010 203 }
204}
205
e2afb3b6 206//_______________________________________________________________________
8494b010 207void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
e2afb3b6 208 Float_t z, Float_t dens, Float_t radl,
209 Float_t absl, Float_t *buf, Int_t nwbuf) const
8494b010 210{
211 //
212 // Store the parameters for a material
213 //
214 // imat the material index will be stored in (*fIdmate)[imat]
215 // name material name
216 // a atomic mass
217 // z atomic number
218 // dens density
219 // radl radiation length
220 // absl absorbtion length
221 // buf adress of an array user words
222 // nwbuf number of user words
223 //
224 Int_t kmat;
cfce8870 225 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
8494b010 226 (*fIdmate)[imat]=kmat;
227}
228
e2afb3b6 229//_______________________________________________________________________
0afa509f 230void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
e2afb3b6 231 Float_t &z, Float_t &dens, Float_t &radl,
116cbefd 232 Float_t &absl) const
0afa509f 233{
234 //
235 // Store the parameters for a material
236 //
237 // imat the material index will be stored in (*fIdmate)[imat]
238 // name material name
239 // a atomic mass
240 // z atomic number
241 // dens density
242 // radl radiation length
243 // absl absorbtion length
244 // buf adress of an array user words
245 // nwbuf number of user words
246 //
247
248 Float_t buf[10];
249 Int_t nwbuf, kmat;
250 kmat=(*fIdmate)[imat];
251 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
252}
253
8494b010 254
e2afb3b6 255//_______________________________________________________________________
8494b010 256void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
e2afb3b6 257 Float_t *z, Float_t dens, Int_t nlmat,
258 Float_t *wmat) const
8494b010 259{
260 //
261 // Defines mixture or compound imat as composed by
262 // nlmat materials defined by arrays a, z and wmat
263 //
264 // If nlmat > 0 wmat contains the proportion by
265 // weights of each basic material in the mixture
266 //
267 // If nlmat < 0 wmat contains the number of atoms
268 // of eack kind in the molecule of the compound
269 // In this case, wmat is changed on output to the relative weigths.
270 //
271 // imat the material index will be stored in (*fIdmate)[imat]
272 // name material name
273 // a array of atomic masses
274 // z array of atomic numbers
275 // dens density
276 // nlmat number of components
277 // wmat array of concentrations
278 //
279 Int_t kmat;
cfce8870 280 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
8494b010 281 (*fIdmate)[imat]=kmat;
282}
283
e2afb3b6 284//_______________________________________________________________________
8494b010 285void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
e2afb3b6 286 Int_t isvol, Int_t ifield, Float_t fieldm,
287 Float_t tmaxfd, Float_t stemax, Float_t deemax,
288 Float_t epsil, Float_t stmin, Float_t *ubuf,
289 Int_t nbuf) const
8494b010 290{
291 //
292 // Store the parameters of a tracking medium
293 //
b13db077 294 // numed the medium number is stored into (*fIdtmed)[numed]
8494b010 295 // name medium name
296 // nmat the material number is stored into (*fIdmate)[nmat]
297 // isvol sensitive volume if isvol!=0
298 // ifield magnetic field flag (see below)
299 // fieldm maximum magnetic field
300 // tmaxfd maximum deflection angle due to magnetic field
301 // stemax maximum step allowed
302 // deemax maximum fractional energy loss in one step
303 // epsil tracking precision in cm
304 // stmin minimum step due to continuous processes
305 //
306 // ifield = 0 no magnetic field
307 // = -1 user decision in guswim
308 // = 1 tracking performed with Runge Kutta
309 // = 2 tracking performed with helix
310 // = 3 constant magnetic field along z
311 //
312 Int_t kmed;
cfce8870 313 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
8494b010 314 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
ad51aeb0 315 (*fIdtmed)[numed]=kmed;
8494b010 316}
317
e2afb3b6 318//_______________________________________________________________________
8494b010 319void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
e2afb3b6 320 Float_t theta2, Float_t phi2, Float_t theta3,
321 Float_t phi3) const
8494b010 322{
323 //
324 // Define a rotation matrix. Angles are in degrees.
325 //
326 // nmat on output contains the number assigned to the rotation matrix
327 // theta1 polar angle for axis I
328 // phi1 azimuthal angle for axis I
329 // theta2 polar angle for axis II
330 // phi2 azimuthal angle for axis II
331 // theta3 polar angle for axis III
332 // phi3 azimuthal angle for axis III
333 //
cfce8870 334 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
8494b010 335}
336
e2afb3b6 337//_______________________________________________________________________
65fb704d 338Float_t AliModule::ZMin() const
339{
340 return -500;
341}
342
e2afb3b6 343//_______________________________________________________________________
65fb704d 344Float_t AliModule::ZMax() const
345{
346 return 500;
347}
348
e2afb3b6 349//_______________________________________________________________________
8494b010 350void AliModule::SetEuclidFile(char* material, char* geometry)
351{
352 //
353 // Sets the name of the Euclid file
354 //
355 fEuclidMaterial=material;
356 if(geometry) {
357 fEuclidGeometry=geometry;
358 } else {
359 char* name = new char[strlen(material)];
360 strcpy(name,material);
361 strcpy(&name[strlen(name)-4],".euc");
362 fEuclidGeometry=name;
363 delete [] name;
364 }
365}
366
e2afb3b6 367//_______________________________________________________________________
b13db077 368void AliModule::ReadEuclid(const char* filnam, char* topvol)
369{
370 //
371 // read in the geometry of the detector in euclid file format
372 //
373 // id_det : the detector identification (2=its,...)
374 // topvol : return parameter describing the name of the top
375 // volume of geometry.
376 //
377 // author : m. maire
378 //
379 // 28.07.98
380 // several changes have been made by miroslav helbich
381 // subroutine is rewrited to follow the new established way of memory
382 // booking for tracking medias and rotation matrices.
383 // all used tracking media have to be defined first, for this you can use
384 // subroutine greutmed.
385 // top volume is searched as only volume not positioned into another
386 //
387
388 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
389 Int_t ndvmx, nr, flag;
390 char key[5], card[77], natmed[21];
391 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
392 char *filtmp;
d43b40e2 393 Float_t par[100];
b13db077 394 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
395 Float_t xo, yo, zo;
aee8290b 396 const Int_t kMaxRot=5000;
397 Int_t idrot[kMaxRot],istop[7000];
b13db077 398 FILE *lun;
399 //
400 // *** The input filnam name will be with extension '.euc'
401 filtmp=gSystem->ExpandPathName(filnam);
402 lun=fopen(filtmp,"r");
403 delete [] filtmp;
404 if(!lun) {
405 Error("ReadEuclid","Could not open file %s\n",filnam);
406 return;
407 }
408 //* --- definition of rotation matrix 0 ---
409 TArrayI &idtmed = *fIdtmed;
aee8290b 410 for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
b13db077 411 idrot[0]=0;
412 nvol=0;
413 L10:
414 for(i=0;i<77;i++) card[i]=0;
415 iret=fscanf(lun,"%77[^\n]",card);
416 if(iret<=0) goto L20;
417 fscanf(lun,"%*c");
418 //*
419 strncpy(key,card,4);
420 key[4]='\0';
421 if (!strcmp(key,"TMED")) {
422 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
423 if( itmed<0 || itmed>=100 ) {
424 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
425 exit(1);
426 }
427 //Pad the string with blanks
428 i=-1;
429 while(natmed[++i]);
430 while(i<20) natmed[i++]=' ';
431 natmed[i]='\0';
432 //
433 if( idtmed[itmed]<=0 ) {
434 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
435 exit(1);
436 }
437 gMC->Gckmat(idtmed[itmed],natmed);
438 //*
439 } else if (!strcmp(key,"ROTM")) {
440 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
aee8290b 441 if( irot<=0 || irot>=kMaxRot ) {
b13db077 442 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
443 exit(1);
444 }
445 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
446 //*
447 } else if (!strcmp(key,"VOLU")) {
448 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
449 if (npar>0) {
450 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
451 fscanf(lun,"%*c");
452 }
453 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
454 //* save the defined volumes
455 strcpy(volst[++nvol],name);
456 istop[nvol]=1;
457 //*
458 } else if (!strcmp(key,"DIVN")) {
459 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
460 gMC->Gsdvn ( name, mother, ndiv, iaxe );
461 //*
462 } else if (!strcmp(key,"DVN2")) {
463 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
464 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
465 //*
466 } else if (!strcmp(key,"DIVT")) {
467 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
468 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
469 //*
470 } else if (!strcmp(key,"DVT2")) {
471 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
472 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
473 //*
474 } else if (!strcmp(key,"POSI")) {
475 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
aee8290b 476 if( irot<0 || irot>=kMaxRot ) {
b13db077 477 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
478 exit(1);
479 }
480 if( idrot[irot] == -99) {
481 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
482 exit(1);
483 }
484 //*** volume name cannot be the top volume
485 for(i=1;i<=nvol;i++) {
486 if (!strcmp(volst[i],name)) istop[i]=0;
487 }
488 //*
489 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
490 //*
491 } else if (!strcmp(key,"POSP")) {
492 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
aee8290b 493 if( irot<0 || irot>=kMaxRot ) {
b13db077 494 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
495 exit(1);
496 }
497 if( idrot[irot] == -99) {
498 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
499 exit(1);
500 }
501 if (npar > 0) {
502 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
503 fscanf(lun,"%*c");
504 }
505 //*** volume name cannot be the top volume
506 for(i=1;i<=nvol;i++) {
507 if (!strcmp(volst[i],name)) istop[i]=0;
508 }
509 //*
510 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
511 }
512 //*
513 if (strcmp(key,"END")) goto L10;
514 //* find top volume in the geometry
515 flag=0;
516 for(i=1;i<=nvol;i++) {
517 if (istop[i] && flag) {
518 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
519 }
520 if (istop[i] && !flag) {
521 strcpy(topvol,volst[i]);
9e1a0ddb 522 if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol);
b13db077 523 flag=1;
524 }
525 }
526 if (!flag) {
527 Warning("ReadEuclid","top volume not found\n");
528 }
529 fclose (lun);
530 //*
531 //* commented out only for the not cernlib version
9e1a0ddb 532 if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam);
b13db077 533 //
534 return;
535 //*
536 L20:
537 Error("ReadEuclid","reading error or premature end of file\n");
538}
539
e2afb3b6 540//_______________________________________________________________________
b13db077 541void AliModule::ReadEuclidMedia(const char* filnam)
542{
543 //
544 // read in the materials and tracking media for the detector
545 // in euclid file format
546 //
547 // filnam: name of the input file
548 // id_det: id_det is the detector identification (2=its,...)
549 //
550 // author : miroslav helbich
551 //
552 Float_t sxmgmx = gAlice->Field()->Max();
553 Int_t isxfld = gAlice->Field()->Integ();
554 Int_t end, i, iret, itmed;
555 char key[5], card[130], natmed[21], namate[21];
556 Float_t ubuf[50];
557 char* filtmp;
558 FILE *lun;
559 Int_t imate;
560 Int_t nwbuf, isvol, ifield, nmat;
561 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
562 //
563 end=strlen(filnam);
564 for(i=0;i<end;i++) if(filnam[i]=='.') {
565 end=i;
566 break;
567 }
568 //
569 // *** The input filnam name will be with extension '.euc'
9e1a0ddb 570 if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug
b13db077 571 filtmp=gSystem->ExpandPathName(filnam);
572 lun=fopen(filtmp,"r");
573 delete [] filtmp;
574 if(!lun) {
575 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
576 return;
577 }
578 //
579 // Retrieve Mag Field parameters
aee8290b 580 Int_t globField=gAlice->Field()->Integ();
581 Float_t globMaxField=gAlice->Field()->Max();
b13db077 582 // TArrayI &idtmed = *fIdtmed;
583 //
584 L10:
585 for(i=0;i<130;i++) card[i]=0;
586 iret=fscanf(lun,"%4s %[^\n]",key,card);
587 if(iret<=0) goto L20;
588 fscanf(lun,"%*c");
589 //*
590 //* read material
591 if (!strcmp(key,"MATE")) {
592 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
593 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
594 //Pad the string with blanks
595 i=-1;
596 while(namate[++i]);
597 while(i<20) namate[i++]=' ';
598 namate[i]='\0';
599 //
600 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
601 //* read tracking medium
602 } else if (!strcmp(key,"TMED")) {
603 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
604 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
605 &stemax,&deemax,&epsil,&stmin,&nwbuf);
606 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
607 if (ifield<0) ifield=isxfld;
608 if (fieldm<0) fieldm=sxmgmx;
609 //Pad the string with blanks
610 i=-1;
611 while(natmed[++i]);
612 while(i<20) natmed[i++]=' ';
613 natmed[i]='\0';
614 //
aee8290b 615 AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
b13db077 616 stemax,deemax,epsil,stmin,ubuf,nwbuf);
617 // (*fImedia)[idtmed[itmed]-1]=id_det;
618 //*
619 }
620 //*
621 if (strcmp(key,"END")) goto L10;
622 fclose (lun);
623 //*
624 //* commented out only for the not cernlib version
9e1a0ddb 625 if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n",
626 ClassName(),filnam);
b13db077 627 //*
628 return;
629 //*
630 L20:
631 Warning("ReadEuclidMedia","reading error or premature end of file\n");
632}
633
8494b010 634