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 ///////////////////////////////////////////////////////////////////////////////
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. //
25 // This class is also responsible for building the geometry of the //
30 <img src="picts/AliModuleClass.gif">
34 ///////////////////////////////////////////////////////////////////////////////
36 #include <TObjArray.h>
37 #include <TClonesArray.h>
40 #include <TDirectory.h>
42 #include "AliModule.h"
45 #include "AliConfig.h"
46 #include "AliTrackReference.h"
50 //_______________________________________________________________________
51 AliModule::AliModule():
65 fCurrentIterTrackRef(0)
68 // Default constructor for the AliModule class
72 //_______________________________________________________________________
73 AliModule::AliModule(const char* name,const char *title):
77 fIdtmed(new TArrayI(100)),
78 fIdmate(new TArrayI(100)),
82 fHistograms(new TList()),
86 fTrackReferences(new TClonesArray("AliTrackReference", 100)),
88 fCurrentIterTrackRef(0)
91 // Normal constructor invoked by all Modules.
92 // Create the list for Module specific histograms
93 // Add this Module to the global list of Modules in Run.
95 // Get the Module numeric ID
96 Int_t id = gAlice->GetModuleID(name);
98 // Module already added !
99 Warning("Ctor","Module: %s already present at %d\n",name,id);
103 // Add this Module to the list of Modules
104 gAlice->Modules()->Add(this);
109 // Clear space for tracking media and material indexes
111 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
113 AliConfig::Instance()->Add(this);
115 SetDebug(gAlice->GetDebug());
118 //_______________________________________________________________________
119 AliModule::AliModule(const AliModule &mod):
137 fCurrentIterTrackRef(0)
145 //_______________________________________________________________________
146 AliModule::~AliModule()
152 // Remove this Module from the list of Modules
154 TObjArray * modules = gAlice->Modules();
155 if (modules) modules->Remove(this);
157 // Delete ROOT geometry
163 // Delete TArray objects
168 //_______________________________________________________________________
169 void AliModule::Copy(AliModule & /* mod */) const
172 // Copy *this onto mod, not implemented for AliModule
174 Fatal("Copy","Not implemented!\n");
177 //_______________________________________________________________________
178 void AliModule::Disable()
181 // Disable Module on viewer
187 // Loop through geometry to disable all
188 // nodes for this Module
189 while((node = dynamic_cast<TNode*>(next()))) {
190 node->SetVisibility(-1);
194 //_______________________________________________________________________
195 Int_t AliModule::DistancetoPrimitive(Int_t, Int_t) const
198 // Return distance from mouse pointer to object
199 // Dummy routine for the moment
204 //_______________________________________________________________________
205 void AliModule::Enable()
208 // Enable Module on the viewver
214 // Loop through geometry to enable all
215 // nodes for this Module
216 while((node = dynamic_cast<TNode*>(next()))) {
217 node->SetVisibility(3);
221 //_______________________________________________________________________
222 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
223 Float_t z, Float_t dens, Float_t radl,
224 Float_t absl, Float_t *buf, Int_t nwbuf) const
227 // Store the parameters for a material
229 // imat the material index will be stored in (*fIdmate)[imat]
230 // name material name
234 // radl radiation length
235 // absl absorbtion length
236 // buf adress of an array user words
237 // nwbuf number of user words
240 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
241 (*fIdmate)[imat]=kmat;
244 //_______________________________________________________________________
245 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
246 Float_t &z, Float_t &dens, Float_t &radl,
250 // Store the parameters for a material
252 // imat the material index will be stored in (*fIdmate)[imat]
253 // name material name
257 // radl radiation length
258 // absl absorbtion length
259 // buf adress of an array user words
260 // nwbuf number of user words
265 kmat=(*fIdmate)[imat];
266 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
270 //_______________________________________________________________________
271 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
272 Float_t *z, Float_t dens, Int_t nlmat,
276 // Defines mixture or compound imat as composed by
277 // nlmat materials defined by arrays a, z and wmat
279 // If nlmat > 0 wmat contains the proportion by
280 // weights of each basic material in the mixture
282 // If nlmat < 0 wmat contains the number of atoms
283 // of eack kind in the molecule of the compound
284 // In this case, wmat is changed on output to the relative weigths.
286 // imat the material index will be stored in (*fIdmate)[imat]
287 // name material name
288 // a array of atomic masses
289 // z array of atomic numbers
291 // nlmat number of components
292 // wmat array of concentrations
295 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
296 (*fIdmate)[imat]=kmat;
299 //_______________________________________________________________________
300 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
301 Int_t isvol, Int_t ifield, Float_t fieldm,
302 Float_t tmaxfd, Float_t stemax, Float_t deemax,
303 Float_t epsil, Float_t stmin, Float_t *ubuf,
307 // Store the parameters of a tracking medium
309 // numed the medium number is stored into (*fIdtmed)[numed]
311 // nmat the material number is stored into (*fIdmate)[nmat]
312 // isvol sensitive volume if isvol!=0
313 // ifield magnetic field flag (see below)
314 // fieldm maximum magnetic field
315 // tmaxfd maximum deflection angle due to magnetic field
316 // stemax maximum step allowed
317 // deemax maximum fractional energy loss in one step
318 // epsil tracking precision in cm
319 // stmin minimum step due to continuous processes
321 // ifield = 0 no magnetic field
322 // = -1 user decision in guswim
323 // = 1 tracking performed with Runge Kutta
324 // = 2 tracking performed with helix
325 // = 3 constant magnetic field along z
328 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
329 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
330 (*fIdtmed)[numed]=kmed;
333 //_______________________________________________________________________
334 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
335 Float_t theta2, Float_t phi2, Float_t theta3,
339 // Define a rotation matrix. Angles are in degrees.
341 // nmat on output contains the number assigned to the rotation matrix
342 // theta1 polar angle for axis I
343 // phi1 azimuthal angle for axis I
344 // theta2 polar angle for axis II
345 // phi2 azimuthal angle for axis II
346 // theta3 polar angle for axis III
347 // phi3 azimuthal angle for axis III
349 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
352 //_______________________________________________________________________
353 Float_t AliModule::ZMin() const
358 //_______________________________________________________________________
359 Float_t AliModule::ZMax() const
364 //_______________________________________________________________________
365 void AliModule::SetEuclidFile(char* material, char* geometry)
368 // Sets the name of the Euclid file
370 fEuclidMaterial=material;
372 fEuclidGeometry=geometry;
374 char* name = new char[strlen(material)];
375 strcpy(name,material);
376 strcpy(&name[strlen(name)-4],".euc");
377 fEuclidGeometry=name;
382 //_______________________________________________________________________
383 void AliModule::ReadEuclid(const char* filnam, char* topvol)
386 // read in the geometry of the detector in euclid file format
388 // id_det : the detector identification (2=its,...)
389 // topvol : return parameter describing the name of the top
390 // volume of geometry.
395 // several changes have been made by miroslav helbich
396 // subroutine is rewrited to follow the new established way of memory
397 // booking for tracking medias and rotation matrices.
398 // all used tracking media have to be defined first, for this you can use
399 // subroutine greutmed.
400 // top volume is searched as only volume not positioned into another
403 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
404 Int_t ndvmx, nr, flag;
405 char key[5], card[77], natmed[21];
406 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
409 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
411 const Int_t kMaxRot=5000;
412 Int_t idrot[kMaxRot],istop[7000];
415 // *** The input filnam name will be with extension '.euc'
416 filtmp=gSystem->ExpandPathName(filnam);
417 lun=fopen(filtmp,"r");
420 Error("ReadEuclid","Could not open file %s\n",filnam);
423 //* --- definition of rotation matrix 0 ---
424 TArrayI &idtmed = *fIdtmed;
425 for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
429 for(i=0;i<77;i++) card[i]=0;
430 iret=fscanf(lun,"%77[^\n]",card);
431 if(iret<=0) goto L20;
436 if (!strcmp(key,"TMED")) {
437 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
438 if( itmed<0 || itmed>=100 ) {
439 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
442 //Pad the string with blanks
445 while(i<20) natmed[i++]=' ';
448 if( idtmed[itmed]<=0 ) {
449 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
452 gMC->Gckmat(idtmed[itmed],natmed);
454 } else if (!strcmp(key,"ROTM")) {
455 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
456 if( irot<=0 || irot>=kMaxRot ) {
457 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
460 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
462 } else if (!strcmp(key,"VOLU")) {
463 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
465 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
468 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
469 //* save the defined volumes
470 strcpy(volst[++nvol],name);
473 } else if (!strcmp(key,"DIVN")) {
474 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
475 gMC->Gsdvn ( name, mother, ndiv, iaxe );
477 } else if (!strcmp(key,"DVN2")) {
478 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
479 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
481 } else if (!strcmp(key,"DIVT")) {
482 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
483 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
485 } else if (!strcmp(key,"DVT2")) {
486 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
487 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
489 } else if (!strcmp(key,"POSI")) {
490 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
491 if( irot<0 || irot>=kMaxRot ) {
492 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
495 if( idrot[irot] == -99) {
496 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
499 //*** volume name cannot be the top volume
500 for(i=1;i<=nvol;i++) {
501 if (!strcmp(volst[i],name)) istop[i]=0;
504 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
506 } else if (!strcmp(key,"POSP")) {
507 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
508 if( irot<0 || irot>=kMaxRot ) {
509 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
512 if( idrot[irot] == -99) {
513 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
517 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
520 //*** volume name cannot be the top volume
521 for(i=1;i<=nvol;i++) {
522 if (!strcmp(volst[i],name)) istop[i]=0;
525 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
528 if (strcmp(key,"END")) goto L10;
529 //* find top volume in the geometry
531 for(i=1;i<=nvol;i++) {
532 if (istop[i] && flag) {
533 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
535 if (istop[i] && !flag) {
536 strcpy(topvol,volst[i]);
537 if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol);
542 Warning("ReadEuclid","top volume not found\n");
546 //* commented out only for the not cernlib version
547 if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam);
552 Error("ReadEuclid","reading error or premature end of file\n");
555 //_______________________________________________________________________
556 void AliModule::ReadEuclidMedia(const char* filnam)
559 // read in the materials and tracking media for the detector
560 // in euclid file format
562 // filnam: name of the input file
563 // id_det: id_det is the detector identification (2=its,...)
565 // author : miroslav helbich
567 Float_t sxmgmx = gAlice->Field()->Max();
568 Int_t isxfld = gAlice->Field()->Integ();
569 Int_t end, i, iret, itmed;
570 char key[5], card[130], natmed[21], namate[21];
575 Int_t nwbuf, isvol, ifield, nmat;
576 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
579 for(i=0;i<end;i++) if(filnam[i]=='.') {
584 // *** The input filnam name will be with extension '.euc'
585 if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug
586 filtmp=gSystem->ExpandPathName(filnam);
587 lun=fopen(filtmp,"r");
590 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
594 // Retrieve Mag Field parameters
595 Int_t globField=gAlice->Field()->Integ();
596 Float_t globMaxField=gAlice->Field()->Max();
597 // TArrayI &idtmed = *fIdtmed;
600 for(i=0;i<130;i++) card[i]=0;
601 iret=fscanf(lun,"%4s %[^\n]",key,card);
602 if(iret<=0) goto L20;
606 if (!strcmp(key,"MATE")) {
607 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
608 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
609 //Pad the string with blanks
612 while(i<20) namate[i++]=' ';
615 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
616 //* read tracking medium
617 } else if (!strcmp(key,"TMED")) {
618 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
619 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
620 &stemax,&deemax,&epsil,&stmin,&nwbuf);
621 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
622 if (ifield<0) ifield=isxfld;
623 if (fieldm<0) fieldm=sxmgmx;
624 //Pad the string with blanks
627 while(i<20) natmed[i++]=' ';
630 AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
631 stemax,deemax,epsil,stmin,ubuf,nwbuf);
632 // (*fImedia)[idtmed[itmed]-1]=id_det;
636 if (strcmp(key,"END")) goto L10;
639 //* commented out only for the not cernlib version
640 if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n",
646 Warning("ReadEuclidMedia","reading error or premature end of file\n");
649 //_______________________________________________________________________
650 void AliModule::RemapTrackReferencesIDs(Int_t *map)
653 // Remapping track reference
654 // Called at finish primary
656 if (!fTrackReferences) return;
657 for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
658 AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
660 Int_t newID = map[ref->GetTrack()];
661 if (newID>=0) ref->SetTrack(newID);
662 else ref->SetTrack(-1);
669 //_______________________________________________________________________
670 AliTrackReference* AliModule::FirstTrackReference(Int_t track)
673 // Initialise the hit iterator
674 // Return the address of the first hit for track
675 // If track>=0 the track is read from disk
676 // while if track<0 the first hit of the current
680 gAlice->ResetTrackReferences();
681 gAlice->TreeTR()->GetEvent(track);
684 fMaxIterTrackRef = fTrackReferences->GetEntriesFast();
685 fCurrentIterTrackRef = 0;
686 if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0));
690 //_______________________________________________________________________
691 AliTrackReference* AliModule::NextTrackReference()
694 // Return the next hit for the current track
696 if(fMaxIterTrackRef) {
697 if(++fCurrentIterTrackRef<fMaxIterTrackRef)
698 return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef));
702 printf("* AliDetector::NextTrackReference * TrackReference Iterator called without calling FistTrackReference before\n");
708 //_______________________________________________________________________
709 void AliModule::ResetTrackReferences()
712 // Reset number of hits and the hits array
714 fMaxIterTrackRef = 0;
715 if (fTrackReferences) fTrackReferences->Clear();
720 void AliModule::SetTreeAddress()
723 // Set branch address for the Hits and Digits Trees
727 sprintf(branchname,"%s",GetName());
728 // Branch address for track reference tree
729 TTree *treeTR = gAlice->TreeTR();
730 if (treeTR && fTrackReferences) {
731 branch = treeTR->GetBranch(branchname);
732 if (branch) branch->SetAddress(&fTrackReferences);
736 void AliModule::AddTrackReference(Int_t label){
738 // add a trackrefernce to the list
739 if (!fTrackReferences) {
740 cerr<<"Container trackrefernce not active\n";
743 Int_t nref = fTrackReferences->GetEntriesFast();
744 TClonesArray &lref = *fTrackReferences;
745 new(lref[nref]) AliTrackReference(label);
749 void AliModule::MakeBranchTR(Option_t *option, const char *file)
752 // Makes branch in treeTR
755 sprintf(name,"%s",GetName());
758 printf("* MakeBranch * Making Branch %s \n",name);
760 TDirectory *cwd = gDirectory;
762 TTree* tree = gAlice->TreeTR();
764 branch = tree->Branch(name, &fTrackReferences, 1600);
766 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
767 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
768 branch->SetFile(outFile);
769 TIter next( branch->GetListOfBranches());
770 while ((branch=dynamic_cast<TBranch*>(next()))) {
771 branch->SetFile(outFile);
778 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);