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
153 gAlice->Modules()->Remove(this);
155 // Delete ROOT geometry
161 // Delete TArray objects
166 //_______________________________________________________________________
167 void AliModule::Copy(AliModule & /* mod */) const
170 // Copy *this onto mod, not implemented for AliModule
172 Fatal("Copy","Not implemented!\n");
175 //_______________________________________________________________________
176 void AliModule::Disable()
179 // Disable Module on viewer
185 // Loop through geometry to disable all
186 // nodes for this Module
187 while((node = dynamic_cast<TNode*>(next()))) {
188 node->SetVisibility(-1);
192 //_______________________________________________________________________
193 Int_t AliModule::DistancetoPrimitive(Int_t, Int_t) const
196 // Return distance from mouse pointer to object
197 // Dummy routine for the moment
202 //_______________________________________________________________________
203 void AliModule::Enable()
206 // Enable Module on the viewver
212 // Loop through geometry to enable all
213 // nodes for this Module
214 while((node = dynamic_cast<TNode*>(next()))) {
215 node->SetVisibility(3);
219 //_______________________________________________________________________
220 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
221 Float_t z, Float_t dens, Float_t radl,
222 Float_t absl, Float_t *buf, Int_t nwbuf) const
225 // Store the parameters for a material
227 // imat the material index will be stored in (*fIdmate)[imat]
228 // name material name
232 // radl radiation length
233 // absl absorbtion length
234 // buf adress of an array user words
235 // nwbuf number of user words
238 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
239 (*fIdmate)[imat]=kmat;
242 //_______________________________________________________________________
243 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
244 Float_t &z, Float_t &dens, Float_t &radl,
248 // Store the parameters for a material
250 // imat the material index will be stored in (*fIdmate)[imat]
251 // name material name
255 // radl radiation length
256 // absl absorbtion length
257 // buf adress of an array user words
258 // nwbuf number of user words
263 kmat=(*fIdmate)[imat];
264 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
268 //_______________________________________________________________________
269 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
270 Float_t *z, Float_t dens, Int_t nlmat,
274 // Defines mixture or compound imat as composed by
275 // nlmat materials defined by arrays a, z and wmat
277 // If nlmat > 0 wmat contains the proportion by
278 // weights of each basic material in the mixture
280 // If nlmat < 0 wmat contains the number of atoms
281 // of eack kind in the molecule of the compound
282 // In this case, wmat is changed on output to the relative weigths.
284 // imat the material index will be stored in (*fIdmate)[imat]
285 // name material name
286 // a array of atomic masses
287 // z array of atomic numbers
289 // nlmat number of components
290 // wmat array of concentrations
293 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
294 (*fIdmate)[imat]=kmat;
297 //_______________________________________________________________________
298 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
299 Int_t isvol, Int_t ifield, Float_t fieldm,
300 Float_t tmaxfd, Float_t stemax, Float_t deemax,
301 Float_t epsil, Float_t stmin, Float_t *ubuf,
305 // Store the parameters of a tracking medium
307 // numed the medium number is stored into (*fIdtmed)[numed]
309 // nmat the material number is stored into (*fIdmate)[nmat]
310 // isvol sensitive volume if isvol!=0
311 // ifield magnetic field flag (see below)
312 // fieldm maximum magnetic field
313 // tmaxfd maximum deflection angle due to magnetic field
314 // stemax maximum step allowed
315 // deemax maximum fractional energy loss in one step
316 // epsil tracking precision in cm
317 // stmin minimum step due to continuous processes
319 // ifield = 0 no magnetic field
320 // = -1 user decision in guswim
321 // = 1 tracking performed with Runge Kutta
322 // = 2 tracking performed with helix
323 // = 3 constant magnetic field along z
326 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
327 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
328 (*fIdtmed)[numed]=kmed;
331 //_______________________________________________________________________
332 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
333 Float_t theta2, Float_t phi2, Float_t theta3,
337 // Define a rotation matrix. Angles are in degrees.
339 // nmat on output contains the number assigned to the rotation matrix
340 // theta1 polar angle for axis I
341 // phi1 azimuthal angle for axis I
342 // theta2 polar angle for axis II
343 // phi2 azimuthal angle for axis II
344 // theta3 polar angle for axis III
345 // phi3 azimuthal angle for axis III
347 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
350 //_______________________________________________________________________
351 Float_t AliModule::ZMin() const
356 //_______________________________________________________________________
357 Float_t AliModule::ZMax() const
362 //_______________________________________________________________________
363 void AliModule::SetEuclidFile(char* material, char* geometry)
366 // Sets the name of the Euclid file
368 fEuclidMaterial=material;
370 fEuclidGeometry=geometry;
372 char* name = new char[strlen(material)];
373 strcpy(name,material);
374 strcpy(&name[strlen(name)-4],".euc");
375 fEuclidGeometry=name;
380 //_______________________________________________________________________
381 void AliModule::ReadEuclid(const char* filnam, char* topvol)
384 // read in the geometry of the detector in euclid file format
386 // id_det : the detector identification (2=its,...)
387 // topvol : return parameter describing the name of the top
388 // volume of geometry.
393 // several changes have been made by miroslav helbich
394 // subroutine is rewrited to follow the new established way of memory
395 // booking for tracking medias and rotation matrices.
396 // all used tracking media have to be defined first, for this you can use
397 // subroutine greutmed.
398 // top volume is searched as only volume not positioned into another
401 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
402 Int_t ndvmx, nr, flag;
403 char key[5], card[77], natmed[21];
404 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
407 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
409 const Int_t kMaxRot=5000;
410 Int_t idrot[kMaxRot],istop[7000];
413 // *** The input filnam name will be with extension '.euc'
414 filtmp=gSystem->ExpandPathName(filnam);
415 lun=fopen(filtmp,"r");
418 Error("ReadEuclid","Could not open file %s\n",filnam);
421 //* --- definition of rotation matrix 0 ---
422 TArrayI &idtmed = *fIdtmed;
423 for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
427 for(i=0;i<77;i++) card[i]=0;
428 iret=fscanf(lun,"%77[^\n]",card);
429 if(iret<=0) goto L20;
434 if (!strcmp(key,"TMED")) {
435 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
436 if( itmed<0 || itmed>=100 ) {
437 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
440 //Pad the string with blanks
443 while(i<20) natmed[i++]=' ';
446 if( idtmed[itmed]<=0 ) {
447 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
450 gMC->Gckmat(idtmed[itmed],natmed);
452 } else if (!strcmp(key,"ROTM")) {
453 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
454 if( irot<=0 || irot>=kMaxRot ) {
455 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
458 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
460 } else if (!strcmp(key,"VOLU")) {
461 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
463 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
466 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
467 //* save the defined volumes
468 strcpy(volst[++nvol],name);
471 } else if (!strcmp(key,"DIVN")) {
472 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
473 gMC->Gsdvn ( name, mother, ndiv, iaxe );
475 } else if (!strcmp(key,"DVN2")) {
476 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
477 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
479 } else if (!strcmp(key,"DIVT")) {
480 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
481 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
483 } else if (!strcmp(key,"DVT2")) {
484 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
485 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
487 } else if (!strcmp(key,"POSI")) {
488 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
489 if( irot<0 || irot>=kMaxRot ) {
490 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
493 if( idrot[irot] == -99) {
494 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
497 //*** volume name cannot be the top volume
498 for(i=1;i<=nvol;i++) {
499 if (!strcmp(volst[i],name)) istop[i]=0;
502 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
504 } else if (!strcmp(key,"POSP")) {
505 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
506 if( irot<0 || irot>=kMaxRot ) {
507 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
510 if( idrot[irot] == -99) {
511 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
515 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
518 //*** volume name cannot be the top volume
519 for(i=1;i<=nvol;i++) {
520 if (!strcmp(volst[i],name)) istop[i]=0;
523 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
526 if (strcmp(key,"END")) goto L10;
527 //* find top volume in the geometry
529 for(i=1;i<=nvol;i++) {
530 if (istop[i] && flag) {
531 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
533 if (istop[i] && !flag) {
534 strcpy(topvol,volst[i]);
535 if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol);
540 Warning("ReadEuclid","top volume not found\n");
544 //* commented out only for the not cernlib version
545 if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam);
550 Error("ReadEuclid","reading error or premature end of file\n");
553 //_______________________________________________________________________
554 void AliModule::ReadEuclidMedia(const char* filnam)
557 // read in the materials and tracking media for the detector
558 // in euclid file format
560 // filnam: name of the input file
561 // id_det: id_det is the detector identification (2=its,...)
563 // author : miroslav helbich
565 Float_t sxmgmx = gAlice->Field()->Max();
566 Int_t isxfld = gAlice->Field()->Integ();
567 Int_t end, i, iret, itmed;
568 char key[5], card[130], natmed[21], namate[21];
573 Int_t nwbuf, isvol, ifield, nmat;
574 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
577 for(i=0;i<end;i++) if(filnam[i]=='.') {
582 // *** The input filnam name will be with extension '.euc'
583 if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug
584 filtmp=gSystem->ExpandPathName(filnam);
585 lun=fopen(filtmp,"r");
588 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
592 // Retrieve Mag Field parameters
593 Int_t globField=gAlice->Field()->Integ();
594 Float_t globMaxField=gAlice->Field()->Max();
595 // TArrayI &idtmed = *fIdtmed;
598 for(i=0;i<130;i++) card[i]=0;
599 iret=fscanf(lun,"%4s %[^\n]",key,card);
600 if(iret<=0) goto L20;
604 if (!strcmp(key,"MATE")) {
605 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
606 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
607 //Pad the string with blanks
610 while(i<20) namate[i++]=' ';
613 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
614 //* read tracking medium
615 } else if (!strcmp(key,"TMED")) {
616 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
617 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
618 &stemax,&deemax,&epsil,&stmin,&nwbuf);
619 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
620 if (ifield<0) ifield=isxfld;
621 if (fieldm<0) fieldm=sxmgmx;
622 //Pad the string with blanks
625 while(i<20) natmed[i++]=' ';
628 AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
629 stemax,deemax,epsil,stmin,ubuf,nwbuf);
630 // (*fImedia)[idtmed[itmed]-1]=id_det;
634 if (strcmp(key,"END")) goto L10;
637 //* commented out only for the not cernlib version
638 if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n",
644 Warning("ReadEuclidMedia","reading error or premature end of file\n");
647 //_______________________________________________________________________
648 void AliModule::RemapTrackReferencesIDs(Int_t *map)
651 // Remapping track reference
652 // Called at finish primary
654 if (!fTrackReferences) return;
655 for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
656 AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
658 Int_t newID = map[ref->GetTrack()];
659 if (newID>=0) ref->SetTrack(newID);
660 else ref->SetTrack(-1);
667 //_______________________________________________________________________
668 AliTrackReference* AliModule::FirstTrackReference(Int_t track)
671 // Initialise the hit iterator
672 // Return the address of the first hit for track
673 // If track>=0 the track is read from disk
674 // while if track<0 the first hit of the current
678 gAlice->ResetTrackReferences();
679 gAlice->TreeTR()->GetEvent(track);
682 fMaxIterTrackRef = fTrackReferences->GetEntriesFast();
683 fCurrentIterTrackRef = 0;
684 if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0));
688 //_______________________________________________________________________
689 AliTrackReference* AliModule::NextTrackReference()
692 // Return the next hit for the current track
694 if(fMaxIterTrackRef) {
695 if(++fCurrentIterTrackRef<fMaxIterTrackRef)
696 return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef));
700 printf("* AliDetector::NextTrackReference * TrackReference Iterator called without calling FistTrackReference before\n");
706 //_______________________________________________________________________
707 void AliModule::ResetTrackReferences()
710 // Reset number of hits and the hits array
712 fMaxIterTrackRef = 0;
713 if (fTrackReferences) fTrackReferences->Clear();
718 void AliModule::SetTreeAddress()
721 // Set branch address for the Hits and Digits Trees
725 sprintf(branchname,"%s",GetName());
726 // Branch address for track reference tree
727 TTree *treeTR = gAlice->TreeTR();
728 if (treeTR && fTrackReferences) {
729 branch = treeTR->GetBranch(branchname);
730 if (branch) branch->SetAddress(&fTrackReferences);
734 void AliModule::AddTrackReference(Int_t label){
736 // add a trackrefernce to the list
737 if (!fTrackReferences) {
738 cerr<<"Container trackrefernce not active\n";
741 Int_t nref = fTrackReferences->GetEntriesFast();
742 TClonesArray &lref = *fTrackReferences;
743 new(lref[nref]) AliTrackReference(label);
747 void AliModule::MakeBranchTR(Option_t *option, const char *file)
750 // Makes branch in treeTR
753 sprintf(name,"%s",GetName());
756 printf("* MakeBranch * Making Branch %s \n",name);
758 TDirectory *cwd = gDirectory;
760 TTree* tree = gAlice->TreeTR();
762 branch = tree->Branch(name, &fTrackReferences, 1600);
764 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
765 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
766 branch->SetFile(outFile);
767 TIter next( branch->GetListOfBranches());
768 while ((branch=dynamic_cast<TBranch*>(next()))) {
769 branch->SetFile(outFile);
776 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);