]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliModule.cxx
Using AliPHOSLoader instead of AliPHOSGetter
[u/mrichter/AliRoot.git] / STEER / AliModule.cxx
index c59c983f1439a456417fccabae73e61da204a938..fc3a2545df164fbf578b8c8be232231960db678b 100644 (file)
@@ -40,6 +40,8 @@
 #include <TSystem.h>
 #include <TDirectory.h>
 #include <TVirtualMC.h>
+#include <TGeoManager.h>
+#include <TString.h>
 
 #include "AliLog.h"
 #include "AliConfig.h"
 #include "AliRun.h"
 #include "AliTrackReference.h"
 #include "AliMC.h"
-#include "../RAW/AliRawDataHeader.h"
+#include "AliRawDataHeader.h"
+
+#include "AliDAQ.h"
 
 ClassImp(AliModule)
  
+Float_t AliModule::fgDensityFactor = 1.0;
 //_______________________________________________________________________
 AliModule::AliModule():
   fEuclidMaterial(""),
@@ -64,7 +70,6 @@ AliModule::AliModule():
   fActive(0),
   fHistograms(0),
   fNodes(0),
-  fDebug(0),
   fEnable(1),
   fTrackReferences(0),
   fMaxIterTrackRef(0),
@@ -88,7 +93,6 @@ AliModule::AliModule(const char* name,const char *title):
   fActive(0),
   fHistograms(new TList()),
   fNodes(new TList()),
-  fDebug(0),
   fEnable(1),
   fTrackReferences(new TClonesArray("AliTrackReference", 100)),
   fMaxIterTrackRef(0),
@@ -101,6 +105,7 @@ AliModule::AliModule(const char* name,const char *title):
   // Add this Module to the global list of Modules in Run.
   //
   // Get the Module numeric ID
+
   Int_t id = gAlice->GetModuleID(name);
   if (id>=0) {
     // Module already added !
@@ -112,41 +117,13 @@ AliModule::AliModule(const char* name,const char *title):
 
   gAlice->AddModule(this);
 
-  SetMarkerColor(3);
+  //PH  SetMarkerColor(3);
   //
   // Clear space for tracking media and material indexes
 
   for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
 }
  
-//_______________________________________________________________________
-AliModule::AliModule(const AliModule &mod):
-  TNamed(mod),
-  TAttLine(mod),
-  TAttMarker(mod),
-  AliRndm(mod),
-  fEuclidMaterial(""),
-  fEuclidGeometry(""),
-  fIdtmed(0),
-  fIdmate(0),
-  fLoMedium(0),
-  fHiMedium(0),
-  fActive(0),
-  fHistograms(0),
-  fNodes(0),
-  fDebug(0),
-  fEnable(0),
-  fTrackReferences(0),
-  fMaxIterTrackRef(0),
-  fCurrentIterTrackRef(0),
-  fRunLoader(0)
-{
-  //
-  // Copy constructor
-  //
-  mod.Copy(*this);
-}
-
 //_______________________________________________________________________
 AliModule::~AliModule()
 {
@@ -183,15 +160,6 @@ AliModule::~AliModule()
 
 }
  
-//_______________________________________________________________________
-void AliModule::Copy(TObject & /* mod */) const
-{
-  //
-  // Copy *this onto mod, not implemented for AliModule
-  //
-  AliFatal("Not implemented!");
-}
-
 //_______________________________________________________________________
 void AliModule::Disable()
 {
@@ -245,8 +213,21 @@ void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
   // nwbuf       number of user words
   //
   Int_t kmat;
-  gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
-  (*fIdmate)[imat]=kmat;
+  //Build the string uniquename as "DET_materialname"
+  TString uniquename = GetName();
+  uniquename.Append("_");
+  uniquename.Append(name);
+  //if geometry loaded from file only fill fIdmate, else create material too
+  if(gAlice->IsRootGeometry()){
+    TGeoMaterial *mat = gGeoManager->GetMaterial(uniquename.Data());
+    kmat = mat->GetUniqueID();
+    (*fIdmate)[imat]=kmat;
+  }else{
+    if (fgDensityFactor != 1.0)
+      AliWarning(Form("Material density multiplied by %.2f!", fgDensityFactor));
+    gMC->Material(kmat, uniquename.Data(), a, z, dens * fgDensityFactor, radl, absl, buf, nwbuf);
+    (*fIdmate)[imat]=kmat;
+  }
 }
   
 //_______________________________________________________________________
@@ -300,8 +281,21 @@ void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
   // wmat        array of concentrations
   //
   Int_t kmat;
-  gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
-  (*fIdmate)[imat]=kmat;
+  //Build the string uniquename as "DET_mixturename"
+  TString uniquename = GetName();
+  uniquename.Append("_");
+  uniquename.Append(name);
+  //if geometry loaded from file only fill fIdmate, else create mixture too
+  if(gAlice->IsRootGeometry()){
+    TGeoMaterial *mat = gGeoManager->GetMaterial(uniquename.Data());
+    kmat = mat->GetUniqueID();
+    (*fIdmate)[imat]=kmat;
+  }else{
+    if (fgDensityFactor != 1.0)
+      AliWarning(Form("Material density multiplied by %.2f!", fgDensityFactor));
+    gMC->Mixture(kmat, uniquename.Data(), a, z, dens * fgDensityFactor, nlmat, wmat);
+    (*fIdmate)[imat]=kmat;
+  }
 } 
  
 //_______________________________________________________________________
@@ -333,9 +327,20 @@ void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
   //        =  3       constant magnetic field along z
   //  
   Int_t kmed;
-  gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
-                        tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf); 
-  (*fIdtmed)[numed]=kmed;
+  //Build the string uniquename as "DET_mediumname"
+  TString uniquename = GetName();
+  uniquename.Append("_");
+  uniquename.Append(name);
+  //if geometry loaded from file only fill fIdtmed, else create medium too
+  if(gAlice->IsRootGeometry()){
+    TGeoMedium *med = gGeoManager->GetMedium(uniquename.Data());
+    kmed = med->GetId();
+    (*fIdtmed)[numed]=kmed;
+  }else{
+    gMC->Medium(kmed, uniquename.Data(), (*fIdmate)[nmat], isvol, ifield,
+                fieldm, tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
+    (*fIdtmed)[numed]=kmed;
+  }
 } 
  
 //_______________________________________________________________________
@@ -654,160 +659,72 @@ void AliModule::ReadEuclidMedia(const char* filnam)
 } 
 
 //_______________________________________________________________________
-void AliModule::RemapTrackReferencesIDs(Int_t *map)
+void AliModule::AddAlignableVolumes() const
 {
   // 
-  // Remapping track reference
-  // Called at finish primary
-  //
-  if (!fTrackReferences) return;
-  for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
-    AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
-    if (ref) {
-      Int_t newID = map[ref->GetTrack()];
-      if (newID>=0) ref->SetTrack(newID);
-      else {
-        //ref->SetTrack(-1);
-        ref->SetBit(kNotDeleted,kFALSE);
-        fTrackReferences->RemoveAt(i);  
-      }      
-    }
-  }
-  fTrackReferences->Compress();
-
-}
-
-
-//_______________________________________________________________________
-AliTrackReference* AliModule::FirstTrackReference(Int_t track)
-{
-  //
-  // Initialise the hit iterator
-  // Return the address of the first hit for track
-  // If track>=0 the track is read from disk
-  // while if track<0 the first hit of the current
-  // track is returned
-  // 
-  if(track>=0) 
-   {
-     if (fRunLoader == 0x0)
-       AliFatal("AliRunLoader not initialized. Can not proceed");
-     fRunLoader->GetAliRun()->GetMCApp()->ResetTrackReferences();
-     fRunLoader->TreeTR()->GetEvent(track);
-   }
-  //
-  fMaxIterTrackRef     = fTrackReferences->GetEntriesFast();
-  fCurrentIterTrackRef = 0;
-  if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0));
-  else            return 0;
-}
-
-//_______________________________________________________________________
-AliTrackReference* AliModule::NextTrackReference()
-{
-  //
-  // Return the next hit for the current track
-  //
-  if(fMaxIterTrackRef) {
-    if(++fCurrentIterTrackRef<fMaxIterTrackRef) 
-      return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef));
-    else        
-      return 0;
-  } else {
-    AliWarning("Iterator called without calling FistTrackReference before");
-    return 0;
-  }
+  if (IsActive())
+    AliWarning(Form(" %s still has to implement the AddAlignableVolumes method!",GetName()));
 }
 
-
 //_______________________________________________________________________
-void AliModule::ResetTrackReferences()
-{
-  //
-  // Reset number of hits and the hits array
-  //
-  fMaxIterTrackRef   = 0;
-  if (fTrackReferences)   fTrackReferences->Clear();
-}
-//_____________________________________________________________________________
 
 AliLoader*  AliModule::MakeLoader(const char* /*topfoldername*/)
 {
   return 0x0;
 }
  
-//PH Merged with v3-09-08 |
-//                        V
-//_____________________________________________________________________________
-
-void AliModule::SetTreeAddress()
-{
-  //
-  // Set branch address for track reference Tree
-  //
-
-  TBranch *branch;
-
-  // Branch address for track reference tree
-  TTree *treeTR = TreeTR();
-
-  if (treeTR && fTrackReferences) {
-     branch = treeTR->GetBranch(GetName());
-    if (branch) 
-     {
-       AliDebug(3, Form("(%s) Setting for TrackRefs",GetName()));
-       branch->SetAddress(&fTrackReferences);
-     }
-    else
-     { 
-     //can be called before MakeBranch and than does not make sense to issue the warning
-       AliDebug(1, Form("(%s) Failed for Track References. Can not find branch in tree.",
-                 GetName()));
-     }
-  }
-}
 
 //_____________________________________________________________________________
-void  AliModule::AddTrackReference(Int_t label){
+AliTrackReference*  AliModule::AddTrackReference(Int_t label, Int_t id){
   //
   // add a trackrefernce to the list
-  if (!fTrackReferences) {
-    AliError("Container trackrefernce not active");
-    return;
-  }
-  Int_t nref = fTrackReferences->GetEntriesFast();
-  TClonesArray &lref = *fTrackReferences;
-  new(lref[nref]) AliTrackReference(label);
+    return (gAlice->GetMCApp()->AddTrackReference(label, id));
 }
 
-
-//_____________________________________________________________________________
-void AliModule::MakeBranchTR(Option_t */*option*/)
-{ 
+ //_______________________________________________________________________
+AliTrackReference* AliModule::FirstTrackReference(Int_t track)
+{
     //
-    // Makes branch in treeTR
-    //  
-  AliDebug(2,Form("Making Track Refs. Branch for %s",GetName()));
-  TTree * tree = TreeTR();
-  if (fTrackReferences && tree) 
-   {
-      TBranch *branch = tree->GetBranch(GetName());
-     if (branch) 
-       {  
-        AliDebug(2,Form("Branch %s is already in tree.",GetName()));
-        return;
-       }
-  
-     branch = tree->Branch(GetName(),&fTrackReferences);
-   }
-  else
+    // Initialise the hit iterator
+    // Return the address of the first hit for track
+    // If track>=0 the track is read from disk
+    // while if track0 the first hit of the current
+    // track is returned
+    //
+    if(track>=0)
     {
-      AliDebug(2,Form("FAILED for %s: tree=%#x fTrackReferences=%#x",
-            GetName(),tree,fTrackReferences));
+       if (fRunLoader == 0x0)
+           AliFatal("AliRunLoader not initialized. Can not proceed");
+       fRunLoader->GetAliRun()->GetMCApp()->ResetTrackReferences();
+       fRunLoader->TreeTR()->GetEvent(track);
     }
+    //
+    fMaxIterTrackRef     = fTrackReferences->GetEntriesFast();
+    fCurrentIterTrackRef = 0;
+    if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0));
+    else            return 0;
 }
 
+ //_______________________________________________________________________
+AliTrackReference* AliModule::NextTrackReference()
+{
+    //
+    // Return the next hit for the current track
+    //
+    if(fMaxIterTrackRef) {
+       if(++fCurrentIterTrackRef < fMaxIterTrackRef)
+           return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef));
+       else
+           return 0;
+    } else {
+       AliWarning("Iterator called without calling FistTrackReference before");
+       return 0;
+    }
+}
+
+
+
+
 //_____________________________________________________________________________
 TTree* AliModule::TreeTR()
 {
@@ -833,17 +750,7 @@ void AliModule::Digits2Raw()
 
   AliWarning(Form("Dummy version called for %s", GetName()));
 
-  const Int_t kNDetectors = 17;
-  const char* kDetectors[kNDetectors] = {"TPC", "ITSSPD", "ITSSDD", "ITSSSD", "TRD", "TOF", "PHOS", "RICH", "EMCAL", "MUON", "MUTR", "ZDC", "PMD", "START", "VZERO", "CRT", "FMD"};
-  const Int_t kDetectorDDLs[kNDetectors] = {216, 20, 12, 16, 18, 72, 20, 20, 22, 20, 2, 1, 6, 1, 1, 1, 3};
-  Int_t nDDLs = 1;
-  Int_t ddlOffset = 0;
-  for (Int_t i = 0; i < kNDetectors; i++) {
-    if (strcmp(GetName(), kDetectors[i]) == 0) {
-      nDDLs = kDetectorDDLs[i];
-      ddlOffset = 0x100 * i;
-    }
-  }
+  Int_t nDDLs = AliDAQ::NumberOfDdls(GetName());
 
   if (!GetLoader()) return;
   fstream digitsFile(GetLoader()->GetDigitsFileName(), ios::in);
@@ -856,7 +763,7 @@ void AliModule::Digits2Raw()
 
   for (Int_t iDDL = 0; iDDL < nDDLs; iDDL++) {
     char fileName[20];
-    sprintf(fileName, "%s_%d.ddl", GetName(), iDDL + ddlOffset);
+    strcpy(fileName,AliDAQ::DdlFileName(GetName(),iDDL));
     fstream rawFile(fileName, ios::out);
     if (!rawFile) return;
 
@@ -872,11 +779,3 @@ void AliModule::Digits2Raw()
   digitsFile.close();
   delete[] buffer;
 }
-
-
-//_____________________________________________________________________________
-Int_t AliModule::GetDebug() const
-{
-  AliWarning("Don't use this method any more, use AliDebug instead");
-  return 0;
-}