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