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 ///////////////////////////////////////////////////////////////////////////////
37 #include <TObjArray.h>
38 #include <TClonesArray.h>
41 #include <TDirectory.h>
43 #include "AliConfig.h"
44 #include "AliLoader.h"
46 #include "AliModule.h"
48 #include "AliTrackReference.h"
52 //_______________________________________________________________________
53 AliModule::AliModule():
67 fCurrentIterTrackRef(0)
70 // Default constructor for the AliModule class
74 //_______________________________________________________________________
75 AliModule::AliModule(const char* name,const char *title):
79 fIdtmed(new TArrayI(100)),
80 fIdmate(new TArrayI(100)),
84 fHistograms(new TList()),
88 fTrackReferences(new TClonesArray("AliTrackReference", 100)),
90 fCurrentIterTrackRef(0)
93 // Normal constructor invoked by all Modules.
94 // Create the list for Module specific histograms
95 // Add this Module to the global list of Modules in Run.
97 // Get the Module numeric ID
98 Int_t id = gAlice->GetModuleID(name);
100 // Module already added !
101 Warning("Ctor","Module: %s already present at %d\n",name,id);
105 // Add this Module to the list of Modules
107 gAlice->AddModule(this);
111 // Clear space for tracking media and material indexes
113 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
116 SetDebug(gAlice->GetDebug());
119 //_______________________________________________________________________
120 AliModule::AliModule(const AliModule &mod):
138 fCurrentIterTrackRef(0)
146 //_______________________________________________________________________
147 AliModule::~AliModule()
153 // Remove this Module from the list of Modules
155 TObjArray * modules = gAlice->Modules();
156 if (modules) modules->Remove(this);
158 // Delete ROOT geometry
166 fHistograms->Clear();
170 // Delete track references
171 if (fTrackReferences) {
172 fTrackReferences->Delete();
173 delete fTrackReferences;
174 fTrackReferences = 0;
176 // Delete TArray objects
182 //_______________________________________________________________________
183 void AliModule::Copy(AliModule & /* mod */) const
186 // Copy *this onto mod, not implemented for AliModule
188 Fatal("Copy","Not implemented!\n");
191 //_______________________________________________________________________
192 void AliModule::Disable()
195 // Disable Module on viewer
201 // Loop through geometry to disable all
202 // nodes for this Module
203 while((node = dynamic_cast<TNode*>(next()))) {
204 node->SetVisibility(-1);
208 //_______________________________________________________________________
209 Int_t AliModule::DistancetoPrimitive(Int_t, Int_t) const
212 // Return distance from mouse pointer to object
213 // Dummy routine for the moment
218 //_______________________________________________________________________
219 void AliModule::Enable()
222 // Enable Module on the viewver
228 // Loop through geometry to enable all
229 // nodes for this Module
230 while((node = dynamic_cast<TNode*>(next()))) {
231 node->SetVisibility(3);
235 //_______________________________________________________________________
236 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
237 Float_t z, Float_t dens, Float_t radl,
238 Float_t absl, Float_t *buf, Int_t nwbuf) const
241 // Store the parameters for a material
243 // imat the material index will be stored in (*fIdmate)[imat]
244 // name material name
248 // radl radiation length
249 // absl absorbtion length
250 // buf adress of an array user words
251 // nwbuf number of user words
254 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
255 (*fIdmate)[imat]=kmat;
258 //_______________________________________________________________________
259 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
260 Float_t &z, Float_t &dens, Float_t &radl,
264 // Store the parameters for a material
266 // imat the material index will be stored in (*fIdmate)[imat]
267 // name material name
271 // radl radiation length
272 // absl absorbtion length
273 // buf adress of an array user words
274 // nwbuf number of user words
279 kmat=(*fIdmate)[imat];
280 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
284 //_______________________________________________________________________
285 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
286 Float_t *z, Float_t dens, Int_t nlmat,
290 // Defines mixture or compound imat as composed by
291 // nlmat materials defined by arrays a, z and wmat
293 // If nlmat > 0 wmat contains the proportion by
294 // weights of each basic material in the mixture
296 // If nlmat < 0 wmat contains the number of atoms
297 // of eack kind in the molecule of the compound
298 // In this case, wmat is changed on output to the relative weigths.
300 // imat the material index will be stored in (*fIdmate)[imat]
301 // name material name
302 // a array of atomic masses
303 // z array of atomic numbers
305 // nlmat number of components
306 // wmat array of concentrations
309 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
310 (*fIdmate)[imat]=kmat;
313 //_______________________________________________________________________
314 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
315 Int_t isvol, Int_t ifield, Float_t fieldm,
316 Float_t tmaxfd, Float_t stemax, Float_t deemax,
317 Float_t epsil, Float_t stmin, Float_t *ubuf,
321 // Store the parameters of a tracking medium
323 // numed the medium number is stored into (*fIdtmed)[numed]
325 // nmat the material number is stored into (*fIdmate)[nmat]
326 // isvol sensitive volume if isvol!=0
327 // ifield magnetic field flag (see below)
328 // fieldm maximum magnetic field
329 // tmaxfd maximum deflection angle due to magnetic field
330 // stemax maximum step allowed
331 // deemax maximum fractional energy loss in one step
332 // epsil tracking precision in cm
333 // stmin minimum step due to continuous processes
335 // ifield = 0 no magnetic field
336 // = -1 user decision in guswim
337 // = 1 tracking performed with Runge Kutta
338 // = 2 tracking performed with helix
339 // = 3 constant magnetic field along z
342 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
343 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
344 (*fIdtmed)[numed]=kmed;
347 //_______________________________________________________________________
348 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
349 Float_t theta2, Float_t phi2, Float_t theta3,
353 // Define a rotation matrix. Angles are in degrees.
355 // nmat on output contains the number assigned to the rotation matrix
356 // theta1 polar angle for axis I
357 // phi1 azimuthal angle for axis I
358 // theta2 polar angle for axis II
359 // phi2 azimuthal angle for axis II
360 // theta3 polar angle for axis III
361 // phi3 azimuthal angle for axis III
363 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
366 //_______________________________________________________________________
367 Float_t AliModule::ZMin() const
372 //_______________________________________________________________________
373 Float_t AliModule::ZMax() const
378 //_______________________________________________________________________
379 void AliModule::SetEuclidFile(char* material, char* geometry)
382 // Sets the name of the Euclid file
384 fEuclidMaterial=material;
386 fEuclidGeometry=geometry;
388 char* name = new char[strlen(material)];
389 strcpy(name,material);
390 strcpy(&name[strlen(name)-4],".euc");
391 fEuclidGeometry=name;
396 //_______________________________________________________________________
397 void AliModule::ReadEuclid(const char* filnam, char* topvol)
400 // read in the geometry of the detector in euclid file format
402 // id_det : the detector identification (2=its,...)
403 // topvol : return parameter describing the name of the top
404 // volume of geometry.
409 // several changes have been made by miroslav helbich
410 // subroutine is rewrited to follow the new established way of memory
411 // booking for tracking medias and rotation matrices.
412 // all used tracking media have to be defined first, for this you can use
413 // subroutine greutmed.
414 // top volume is searched as only volume not positioned into another
417 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
418 Int_t ndvmx, nr, flag;
419 char key[5], card[77], natmed[21];
420 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
423 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
425 const Int_t kMaxRot=5000;
426 Int_t idrot[kMaxRot],istop[7000];
429 // *** The input filnam name will be with extension '.euc'
430 filtmp=gSystem->ExpandPathName(filnam);
431 lun=fopen(filtmp,"r");
434 Error("ReadEuclid","Could not open file %s\n",filnam);
437 //* --- definition of rotation matrix 0 ---
438 TArrayI &idtmed = *fIdtmed;
439 for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
443 for(i=0;i<77;i++) card[i]=0;
444 iret=fscanf(lun,"%77[^\n]",card);
445 if(iret<=0) goto L20;
450 if (!strcmp(key,"TMED")) {
451 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
452 if( itmed<0 || itmed>=100 ) {
453 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
456 //Pad the string with blanks
459 while(i<20) natmed[i++]=' ';
462 if( idtmed[itmed]<=0 ) {
463 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
466 gMC->Gckmat(idtmed[itmed],natmed);
468 } else if (!strcmp(key,"ROTM")) {
469 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
470 if( irot<=0 || irot>=kMaxRot ) {
471 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
474 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
476 } else if (!strcmp(key,"VOLU")) {
477 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
479 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
482 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
483 //* save the defined volumes
484 strcpy(volst[++nvol],name);
487 } else if (!strcmp(key,"DIVN")) {
488 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
489 gMC->Gsdvn ( name, mother, ndiv, iaxe );
491 } else if (!strcmp(key,"DVN2")) {
492 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
493 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
495 } else if (!strcmp(key,"DIVT")) {
496 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
497 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
499 } else if (!strcmp(key,"DVT2")) {
500 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
501 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
503 } else if (!strcmp(key,"POSI")) {
504 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
505 if( irot<0 || irot>=kMaxRot ) {
506 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
509 if( idrot[irot] == -99) {
510 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
513 //*** volume name cannot be the top volume
514 for(i=1;i<=nvol;i++) {
515 if (!strcmp(volst[i],name)) istop[i]=0;
518 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
520 } else if (!strcmp(key,"POSP")) {
521 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
522 if( irot<0 || irot>=kMaxRot ) {
523 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
526 if( idrot[irot] == -99) {
527 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
531 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
534 //*** volume name cannot be the top volume
535 for(i=1;i<=nvol;i++) {
536 if (!strcmp(volst[i],name)) istop[i]=0;
539 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
542 if (strcmp(key,"END")) goto L10;
543 //* find top volume in the geometry
545 for(i=1;i<=nvol;i++) {
546 if (istop[i] && flag) {
547 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
549 if (istop[i] && !flag) {
550 strcpy(topvol,volst[i]);
551 if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol);
556 Warning("ReadEuclid","top volume not found\n");
560 //* commented out only for the not cernlib version
561 if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam);
566 Error("ReadEuclid","reading error or premature end of file\n");
569 //_______________________________________________________________________
570 void AliModule::ReadEuclidMedia(const char* filnam)
573 // read in the materials and tracking media for the detector
574 // in euclid file format
576 // filnam: name of the input file
577 // id_det: id_det is the detector identification (2=its,...)
579 // author : miroslav helbich
581 Float_t sxmgmx = gAlice->Field()->Max();
582 Int_t isxfld = gAlice->Field()->Integ();
583 Int_t end, i, iret, itmed;
584 char key[5], card[130], natmed[21], namate[21];
589 Int_t nwbuf, isvol, ifield, nmat;
590 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
593 for(i=0;i<end;i++) if(filnam[i]=='.') {
598 // *** The input filnam name will be with extension '.euc'
599 if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug
600 filtmp=gSystem->ExpandPathName(filnam);
601 lun=fopen(filtmp,"r");
604 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
608 // Retrieve Mag Field parameters
609 Int_t globField=gAlice->Field()->Integ();
610 Float_t globMaxField=gAlice->Field()->Max();
611 // TArrayI &idtmed = *fIdtmed;
614 for(i=0;i<130;i++) card[i]=0;
615 iret=fscanf(lun,"%4s %[^\n]",key,card);
616 if(iret<=0) goto L20;
620 if (!strcmp(key,"MATE")) {
621 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
622 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
623 //Pad the string with blanks
626 while(i<20) namate[i++]=' ';
629 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
630 //* read tracking medium
631 } else if (!strcmp(key,"TMED")) {
632 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
633 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
634 &stemax,&deemax,&epsil,&stmin,&nwbuf);
635 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
636 if (ifield<0) ifield=isxfld;
637 if (fieldm<0) fieldm=sxmgmx;
638 //Pad the string with blanks
641 while(i<20) natmed[i++]=' ';
644 AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
645 stemax,deemax,epsil,stmin,ubuf,nwbuf);
646 // (*fImedia)[idtmed[itmed]-1]=id_det;
650 if (strcmp(key,"END")) goto L10;
653 //* commented out only for the not cernlib version
654 if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n",
660 Warning("ReadEuclidMedia","reading error or premature end of file\n");
663 //_______________________________________________________________________
664 void AliModule::RemapTrackReferencesIDs(Int_t *map)
667 // Remapping track reference
668 // Called at finish primary
670 if (!fTrackReferences) return;
671 for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
672 AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
674 Int_t newID = map[ref->GetTrack()];
675 if (newID>=0) ref->SetTrack(newID);
676 else ref->SetTrack(-1);
683 //_______________________________________________________________________
684 AliTrackReference* AliModule::FirstTrackReference(Int_t track)
687 // Initialise the hit iterator
688 // Return the address of the first hit for track
689 // If track>=0 the track is read from disk
690 // while if track<0 the first hit of the current
695 AliRunLoader* rl = AliRunLoader::GetRunLoader();
697 rl->GetAliRun()->ResetTrackReferences();
698 rl->TreeTR()->GetEvent(track);
700 Fatal("FirstTrackReference","AliRunLoader not initialized. Can not proceed");
703 fMaxIterTrackRef = fTrackReferences->GetEntriesFast();
704 fCurrentIterTrackRef = 0;
705 if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0));
709 //_______________________________________________________________________
710 AliTrackReference* AliModule::NextTrackReference()
713 // Return the next hit for the current track
715 if(fMaxIterTrackRef) {
716 if(++fCurrentIterTrackRef<fMaxIterTrackRef)
717 return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef));
721 printf("* AliModule::NextTrackReference * TrackReference Iterator called without calling FistTrackReference before\n");
727 //_______________________________________________________________________
728 void AliModule::ResetTrackReferences()
731 // Reset number of hits and the hits array
733 fMaxIterTrackRef = 0;
734 if (fTrackReferences) fTrackReferences->Clear();
737 //_____________________________________________________________________________
739 AliLoader* AliModule::MakeLoader(const char* topfoldername)
744 //PH Merged with v3-09-08 |
746 //_____________________________________________________________________________
748 void AliModule::SetTreeAddress()
751 // Set branch address for track reference Tree
756 // Branch address for track reference tree
757 TTree *treeTR = TreeTR();
759 if (treeTR && fTrackReferences) {
760 branch = treeTR->GetBranch(GetName());
764 Info("SetTreeAddress","(%s) Setting for TrackRefs",GetName());
765 branch->SetAddress(&fTrackReferences);
769 //can be called before MakeBranch and than does not make sense to issue the warning
771 Warning("SetTreeAddress",
772 "(%s) Failed for Track References. Can not find branch in tree.",
778 //_____________________________________________________________________________
779 void AliModule::AddTrackReference(Int_t label){
781 // add a trackrefernce to the list
782 if (!fTrackReferences) {
783 cerr<<"Container trackrefernce not active\n";
786 Int_t nref = fTrackReferences->GetEntriesFast();
787 TClonesArray &lref = *fTrackReferences;
788 new(lref[nref]) AliTrackReference(label);
792 //_____________________________________________________________________________
793 void AliModule::MakeBranchTR(Option_t *option)
796 // Makes branch in treeTR
798 if(GetDebug()) Info("MakeBranchTR","Making Track Refs. Branch for %s",GetName());
799 TTree * tree = TreeTR();
800 if (fTrackReferences && tree)
802 TBranch *branch = tree->GetBranch(GetName());
805 if(GetDebug()) Info("MakeBranch","Branch %s is already in tree.",GetName());
809 branch = tree->Branch(GetName(),&fTrackReferences);
814 Info("MakeBranchTR","FAILED for %s: tree=%#x fTrackReferences=%#x",
815 GetName(),tree,fTrackReferences);
819 //_____________________________________________________________________________
820 TTree* AliModule::TreeTR()
822 AliRunLoader* rl = AliRunLoader::GetRunLoader();
826 Error("TreeTR","Can not get the run loader");
830 TTree* tree = rl->TreeTR();