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>
42 #include <TVirtualMC.h>
44 #include "AliConfig.h"
45 #include "AliLoader.h"
47 #include "AliModule.h"
49 #include "AliTrackReference.h"
54 //_______________________________________________________________________
55 AliModule::AliModule():
69 fCurrentIterTrackRef(0),
73 // Default constructor for the AliModule class
77 //_______________________________________________________________________
78 AliModule::AliModule(const char* name,const char *title):
82 fIdtmed(new TArrayI(100)),
83 fIdmate(new TArrayI(100)),
87 fHistograms(new TList()),
91 fTrackReferences(new TClonesArray("AliTrackReference", 100)),
93 fCurrentIterTrackRef(0),
97 // Normal constructor invoked by all Modules.
98 // Create the list for Module specific histograms
99 // Add this Module to the global list of Modules in Run.
101 // Get the Module numeric ID
102 Int_t id = gAlice->GetModuleID(name);
104 // Module already added !
105 Warning("Ctor","Module: %s already present at %d\n",name,id);
109 // Add this Module to the list of Modules
111 gAlice->AddModule(this);
115 // Clear space for tracking media and material indexes
117 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
120 SetDebug(gAlice->GetDebug());
123 //_______________________________________________________________________
124 AliModule::AliModule(const AliModule &mod):
142 fCurrentIterTrackRef(0),
151 //_______________________________________________________________________
152 AliModule::~AliModule()
158 // Remove this Module from the list of Modules
160 TObjArray * modules = gAlice->Modules();
161 if (modules) modules->Remove(this);
163 // Delete ROOT geometry
171 fHistograms->Clear();
175 // Delete track references
176 if (fTrackReferences) {
177 fTrackReferences->Delete();
178 delete fTrackReferences;
179 fTrackReferences = 0;
181 // Delete TArray objects
187 //_______________________________________________________________________
188 void AliModule::Copy(TObject & /* mod */) const
191 // Copy *this onto mod, not implemented for AliModule
193 Fatal("Copy","Not implemented!\n");
196 //_______________________________________________________________________
197 void AliModule::Disable()
200 // Disable Module on viewer
206 // Loop through geometry to disable all
207 // nodes for this Module
208 while((node = dynamic_cast<TNode*>(next()))) {
209 node->SetVisibility(-1);
213 //_______________________________________________________________________
214 void AliModule::Enable()
217 // Enable Module on the viewver
223 // Loop through geometry to enable all
224 // nodes for this Module
225 while((node = dynamic_cast<TNode*>(next()))) {
226 node->SetVisibility(3);
230 //_______________________________________________________________________
231 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
232 Float_t z, Float_t dens, Float_t radl,
233 Float_t absl, Float_t *buf, Int_t nwbuf) const
236 // Store the parameters for a material
238 // imat the material index will be stored in (*fIdmate)[imat]
239 // name material name
243 // radl radiation length
244 // absl absorbtion length
245 // buf adress of an array user words
246 // nwbuf number of user words
249 gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
250 (*fIdmate)[imat]=kmat;
253 //_______________________________________________________________________
254 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
255 Float_t &z, Float_t &dens, Float_t &radl,
259 // Store the parameters for a material
261 // imat the material index will be stored in (*fIdmate)[imat]
262 // name material name
266 // radl radiation length
267 // absl absorbtion length
268 // buf adress of an array user words
269 // nwbuf number of user words
274 kmat=(*fIdmate)[imat];
275 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
279 //_______________________________________________________________________
280 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
281 Float_t *z, Float_t dens, Int_t nlmat,
285 // Defines mixture or compound imat as composed by
286 // nlmat materials defined by arrays a, z and wmat
288 // If nlmat > 0 wmat contains the proportion by
289 // weights of each basic material in the mixture
291 // If nlmat < 0 wmat contains the number of atoms
292 // of eack kind in the molecule of the compound
293 // In this case, wmat is changed on output to the relative weigths.
295 // imat the material index will be stored in (*fIdmate)[imat]
296 // name material name
297 // a array of atomic masses
298 // z array of atomic numbers
300 // nlmat number of components
301 // wmat array of concentrations
304 gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
305 (*fIdmate)[imat]=kmat;
308 //_______________________________________________________________________
309 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
310 Int_t isvol, Int_t ifield, Float_t fieldm,
311 Float_t tmaxfd, Float_t stemax, Float_t deemax,
312 Float_t epsil, Float_t stmin, Float_t *ubuf,
316 // Store the parameters of a tracking medium
318 // numed the medium number is stored into (*fIdtmed)[numed]
320 // nmat the material number is stored into (*fIdmate)[nmat]
321 // isvol sensitive volume if isvol!=0
322 // ifield magnetic field flag (see below)
323 // fieldm maximum magnetic field
324 // tmaxfd maximum deflection angle due to magnetic field
325 // stemax maximum step allowed
326 // deemax maximum fractional energy loss in one step
327 // epsil tracking precision in cm
328 // stmin minimum step due to continuous processes
330 // ifield = 0 no magnetic field
331 // = -1 user decision in guswim
332 // = 1 tracking performed with Runge Kutta
333 // = 2 tracking performed with helix
334 // = 3 constant magnetic field along z
337 gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
338 tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
339 (*fIdtmed)[numed]=kmed;
342 //_______________________________________________________________________
343 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
344 Float_t theta2, Float_t phi2, Float_t theta3,
348 // Define a rotation matrix. Angles are in degrees.
350 // nmat on output contains the number assigned to the rotation matrix
351 // theta1 polar angle for axis I
352 // phi1 azimuthal angle for axis I
353 // theta2 polar angle for axis II
354 // phi2 azimuthal angle for axis II
355 // theta3 polar angle for axis III
356 // phi3 azimuthal angle for axis III
358 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
361 //_______________________________________________________________________
362 Float_t AliModule::ZMin() const
367 //_______________________________________________________________________
368 Float_t AliModule::ZMax() const
373 //_______________________________________________________________________
374 void AliModule::SetEuclidFile(char* material, char* geometry)
377 // Sets the name of the Euclid file
379 fEuclidMaterial=material;
381 fEuclidGeometry=geometry;
383 char* name = new char[strlen(material)];
384 strcpy(name,material);
385 strcpy(&name[strlen(name)-4],".euc");
386 fEuclidGeometry=name;
391 //_______________________________________________________________________
392 void AliModule::ReadEuclid(const char* filnam, char* topvol)
395 // read in the geometry of the detector in euclid file format
397 // id_det : the detector identification (2=its,...)
398 // topvol : return parameter describing the name of the top
399 // volume of geometry.
404 // several changes have been made by miroslav helbich
405 // subroutine is rewrited to follow the new established way of memory
406 // booking for tracking medias and rotation matrices.
407 // all used tracking media have to be defined first, for this you can use
408 // subroutine greutmed.
409 // top volume is searched as only volume not positioned into another
412 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
413 Int_t ndvmx, nr, flag;
414 char key[5], card[77], natmed[21];
415 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
418 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
420 const Int_t kMaxRot=5000;
421 Int_t idrot[kMaxRot],istop[7000];
424 // *** The input filnam name will be with extension '.euc'
425 filtmp=gSystem->ExpandPathName(filnam);
426 lun=fopen(filtmp,"r");
429 Error("ReadEuclid","Could not open file %s\n",filnam);
432 //* --- definition of rotation matrix 0 ---
433 TArrayI &idtmed = *fIdtmed;
434 for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
438 for(i=0;i<77;i++) card[i]=0;
439 iret=fscanf(lun,"%77[^\n]",card);
440 if(iret<=0) goto L20;
445 if (!strcmp(key,"TMED")) {
446 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
447 if( itmed<0 || itmed>=100 ) {
448 Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
451 //Pad the string with blanks
454 while(i<20) natmed[i++]=' ';
457 if( idtmed[itmed]<=0 ) {
458 Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
461 gMC->Gckmat(idtmed[itmed],natmed);
463 } else if (!strcmp(key,"ROTM")) {
464 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
465 if( irot<=0 || irot>=kMaxRot ) {
466 Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
469 AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
471 } else if (!strcmp(key,"VOLU")) {
472 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
474 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
477 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
478 //* save the defined volumes
479 strcpy(volst[++nvol],name);
482 } else if (!strcmp(key,"DIVN")) {
483 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
484 gMC->Gsdvn ( name, mother, ndiv, iaxe );
486 } else if (!strcmp(key,"DVN2")) {
487 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
488 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
490 } else if (!strcmp(key,"DIVT")) {
491 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
492 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
494 } else if (!strcmp(key,"DVT2")) {
495 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
496 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
498 } else if (!strcmp(key,"POSI")) {
499 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
500 if( irot<0 || irot>=kMaxRot ) {
501 Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
504 if( idrot[irot] == -99) {
505 Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
508 //*** volume name cannot be the top volume
509 for(i=1;i<=nvol;i++) {
510 if (!strcmp(volst[i],name)) istop[i]=0;
513 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
515 } else if (!strcmp(key,"POSP")) {
516 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
517 if( irot<0 || irot>=kMaxRot ) {
518 Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
521 if( idrot[irot] == -99) {
522 Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
526 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
529 //*** volume name cannot be the top volume
530 for(i=1;i<=nvol;i++) {
531 if (!strcmp(volst[i],name)) istop[i]=0;
534 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
537 if (strcmp(key,"END")) goto L10;
538 //* find top volume in the geometry
540 for(i=1;i<=nvol;i++) {
541 if (istop[i] && flag) {
542 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
544 if (istop[i] && !flag) {
545 strcpy(topvol,volst[i]);
546 if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol);
551 Warning("ReadEuclid","top volume not found\n");
555 //* commented out only for the not cernlib version
556 if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam);
561 Error("ReadEuclid","reading error or premature end of file\n");
564 //_______________________________________________________________________
565 void AliModule::ReadEuclidMedia(const char* filnam)
568 // read in the materials and tracking media for the detector
569 // in euclid file format
571 // filnam: name of the input file
572 // id_det: id_det is the detector identification (2=its,...)
574 // author : miroslav helbich
576 Float_t sxmgmx = gAlice->Field()->Max();
577 Int_t isxfld = gAlice->Field()->Integ();
578 Int_t end, i, iret, itmed;
579 char key[5], card[130], natmed[21], namate[21];
584 Int_t nwbuf, isvol, ifield, nmat;
585 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
588 for(i=0;i<end;i++) if(filnam[i]=='.') {
593 // *** The input filnam name will be with extension '.euc'
594 if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug
595 filtmp=gSystem->ExpandPathName(filnam);
596 lun=fopen(filtmp,"r");
599 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
603 // Retrieve Mag Field parameters
604 Int_t globField=gAlice->Field()->Integ();
605 Float_t globMaxField=gAlice->Field()->Max();
606 // TArrayI &idtmed = *fIdtmed;
609 for(i=0;i<130;i++) card[i]=0;
610 iret=fscanf(lun,"%4s %[^\n]",key,card);
611 if(iret<=0) goto L20;
615 if (!strcmp(key,"MATE")) {
616 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
617 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
618 //Pad the string with blanks
621 while(i<20) namate[i++]=' ';
624 AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
625 //* read tracking medium
626 } else if (!strcmp(key,"TMED")) {
627 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
628 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
629 &stemax,&deemax,&epsil,&stmin,&nwbuf);
630 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
631 if (ifield<0) ifield=isxfld;
632 if (fieldm<0) fieldm=sxmgmx;
633 //Pad the string with blanks
636 while(i<20) natmed[i++]=' ';
639 AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
640 stemax,deemax,epsil,stmin,ubuf,nwbuf);
641 // (*fImedia)[idtmed[itmed]-1]=id_det;
645 if (strcmp(key,"END")) goto L10;
648 //* commented out only for the not cernlib version
649 if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n",
655 Warning("ReadEuclidMedia","reading error or premature end of file\n");
658 //_______________________________________________________________________
659 void AliModule::RemapTrackReferencesIDs(Int_t *map)
662 // Remapping track reference
663 // Called at finish primary
665 if (!fTrackReferences) return;
666 for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
667 AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
669 Int_t newID = map[ref->GetTrack()];
670 if (newID>=0) ref->SetTrack(newID);
673 ref->SetBit(kNotDeleted,kFALSE);
674 fTrackReferences->RemoveAt(i);
678 fTrackReferences->Compress();
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 if (fRunLoader == 0x0)
696 Fatal("FirstTrackReference","AliRunLoader not initialized. Can not proceed");
697 fRunLoader->GetAliRun()->GetMCApp()->ResetTrackReferences();
698 fRunLoader->TreeTR()->GetEvent(track);
701 fMaxIterTrackRef = fTrackReferences->GetEntriesFast();
702 fCurrentIterTrackRef = 0;
703 if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0));
707 //_______________________________________________________________________
708 AliTrackReference* AliModule::NextTrackReference()
711 // Return the next hit for the current track
713 if(fMaxIterTrackRef) {
714 if(++fCurrentIterTrackRef<fMaxIterTrackRef)
715 return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef));
719 printf("* AliModule::NextTrackReference * TrackReference Iterator called without calling FistTrackReference before\n");
725 //_______________________________________________________________________
726 void AliModule::ResetTrackReferences()
729 // Reset number of hits and the hits array
731 fMaxIterTrackRef = 0;
732 if (fTrackReferences) fTrackReferences->Clear();
735 //_____________________________________________________________________________
737 AliLoader* AliModule::MakeLoader(const char* /*topfoldername*/)
742 //PH Merged with v3-09-08 |
744 //_____________________________________________________________________________
746 void AliModule::SetTreeAddress()
749 // Set branch address for track reference Tree
754 // Branch address for track reference tree
755 TTree *treeTR = TreeTR();
757 if (treeTR && fTrackReferences) {
758 branch = treeTR->GetBranch(GetName());
762 Info("SetTreeAddress","(%s) Setting for TrackRefs",GetName());
763 branch->SetAddress(&fTrackReferences);
767 //can be called before MakeBranch and than does not make sense to issue the warning
769 Warning("SetTreeAddress",
770 "(%s) Failed for Track References. Can not find branch in tree.",
776 //_____________________________________________________________________________
777 void AliModule::AddTrackReference(Int_t label){
779 // add a trackrefernce to the list
780 if (!fTrackReferences) {
781 cerr<<"Container trackrefernce not active\n";
784 Int_t nref = fTrackReferences->GetEntriesFast();
785 TClonesArray &lref = *fTrackReferences;
786 new(lref[nref]) AliTrackReference(label);
790 //_____________________________________________________________________________
791 void AliModule::MakeBranchTR(Option_t */*option*/)
794 // Makes branch in treeTR
796 if(GetDebug()) Info("MakeBranchTR","Making Track Refs. Branch for %s",GetName());
797 TTree * tree = TreeTR();
798 if (fTrackReferences && tree)
800 TBranch *branch = tree->GetBranch(GetName());
803 if(GetDebug()) Info("MakeBranch","Branch %s is already in tree.",GetName());
807 branch = tree->Branch(GetName(),&fTrackReferences);
812 Info("MakeBranchTR","FAILED for %s: tree=%#x fTrackReferences=%#x",
813 GetName(),tree,fTrackReferences);
817 //_____________________________________________________________________________
818 TTree* AliModule::TreeTR()
820 if ( fRunLoader == 0x0)
822 Error("TreeTR","Can not get the run loader");
826 TTree* tree = fRunLoader->TreeTR();