]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliSimulation.cxx
Calling MisalignGeometry in case of old Root versions (Andrei)
[u/mrichter/AliRoot.git] / STEER / AliSimulation.cxx
index 4ef68b1772e45d7dbff549c118a8b8ca717cd10a..f7a3a0cc27c29b60e5fa2ba4d3c63a2677337f9a 100644 (file)
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
+#include <TVirtualMCApplication.h>
 #include <TGeoManager.h>
 #include <TObjString.h>
 #include <TStopwatch.h>
 #include "AliCDBStorage.h"
 #include "AliCDBEntry.h"
 #include "AliCDBManager.h"
+#include "AliGeomManager.h"
 #include "AliAlignObj.h"
 #include "AliCentralTrigger.h"
 #include "AliDAQ.h"
 #include "AliESD.h"
 #include "AliHeader.h"
 #include "AliGenEventHeader.h"
+#include "AliMC.h"
 
 ClassImp(AliSimulation)
 
+AliSimulation *AliSimulation::fgInstance = 0;
 
 //_____________________________________________________________________________
 AliSimulation::AliSimulation(const char* configFileName, const char* cdbUri,
@@ -144,7 +148,7 @@ AliSimulation::AliSimulation(const char* configFileName, const char* cdbUri,
   fRunGeneration(kTRUE),
   fRunSimulation(kTRUE),
   fLoadAlignFromCDB(kTRUE),
-  fLoadAlignData("ALL"),
+  fLoadAlObjsListOfDets("ALL"),
   fMakeSDigits("ALL"),
   fMakeDigits("ALL"),
   fMakeTrigger(""),
@@ -167,7 +171,7 @@ AliSimulation::AliSimulation(const char* configFileName, const char* cdbUri,
   fEmbeddingFlag(kFALSE)
 {
 // create simulation object with default parameters
-
+  fgInstance = this;
   SetGAliceFile("galice.root");
 }
 
@@ -178,7 +182,7 @@ AliSimulation::AliSimulation(const AliSimulation& sim) :
   fRunGeneration(sim.fRunGeneration),
   fRunSimulation(sim.fRunSimulation),
   fLoadAlignFromCDB(sim.fLoadAlignFromCDB),
-  fLoadAlignData(sim.fLoadAlignData),
+  fLoadAlObjsListOfDets(sim.fLoadAlObjsListOfDets),
   fMakeSDigits(sim.fMakeSDigits),
   fMakeDigits(sim.fMakeDigits),
   fMakeTrigger(sim.fMakeTrigger),
@@ -216,7 +220,7 @@ AliSimulation::AliSimulation(const AliSimulation& sim) :
   for (Int_t i = 0; i < sim.fSpecCDBUri.GetEntriesFast(); i++) {
     if (sim.fSpecCDBUri[i]) fSpecCDBUri.Add(sim.fSpecCDBUri[i]->Clone());
   }
-
+  fgInstance = this;
 }
 
 //_____________________________________________________________________________
@@ -244,6 +248,7 @@ AliSimulation::~AliSimulation()
   }
 
   fSpecCDBUri.Delete();
+  if (fgInstance==this) fgInstance = 0;
 }
 
 
@@ -272,9 +277,9 @@ void AliSimulation::InitCDBStorage()
     fCDBUri = "";
   }
   else {
-    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-    AliWarning(Form("Default CDB storage is set to: %s",fCDBUri.Data()));
-    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data()));
+    AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
     man->SetDefaultStorage(fCDBUri);
   }
 
@@ -282,10 +287,10 @@ void AliSimulation::InitCDBStorage()
   for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
     TObject* obj = fSpecCDBUri[i];
     if (!obj) continue;
-    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-    AliWarning(Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
-    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-    man->SetSpecificStorage(obj->GetName(),obj->GetTitle());
+    AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
+    AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
   }
   man->Print();
 }
@@ -300,13 +305,19 @@ void AliSimulation::SetDefaultStorage(const char* uri) {
 }
 
 //_____________________________________________________________________________
-void AliSimulation::SetSpecificStorage(const char* detName, const char* uri) {
+void AliSimulation::SetSpecificStorage(const char* calibType, const char* uri) {
 // Store a detector-specific CDB storage location
 // Activate it later within the Run() method
 
-  TObject* obj = fSpecCDBUri.FindObject(detName);
+  AliCDBPath aPath(calibType);
+  if(!aPath.IsValid()){
+       AliError(Form("Not a valid path: %s", calibType));
+       return;
+  }
+
+  TObject* obj = fSpecCDBUri.FindObject(calibType);
   if (obj) fSpecCDBUri.Remove(obj);
-  fSpecCDBUri.Add(new TNamed(detName, uri));
+  fSpecCDBUri.Add(new TNamed(calibType, uri));
 
 }
 
@@ -347,148 +358,6 @@ void AliSimulation::SetEventsPerFile(const char* detector, const char* type,
   fEventsPerFile.Add(obj);
 }
 
-//_____________________________________________________________________________
-Bool_t AliSimulation::ApplyAlignObjsToGeom(TObjArray* alObjArray)
-{
-  // Read collection of alignment objects (AliAlignObj derived) saved
-  // in the TClonesArray ClArrayName and apply them to the geometry
-  // manager singleton.
-  //
-  alObjArray->Sort();
-  Int_t nvols = alObjArray->GetEntriesFast();
-
-  Bool_t flag = kTRUE;
-
-  for(Int_t j=0; j<nvols; j++)
-    {
-      AliAlignObj* alobj = (AliAlignObj*) alObjArray->UncheckedAt(j);
-      if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE;
-    }
-
-  if (AliDebugLevelClass() >= 1) {
-    gGeoManager->GetTopNode()->CheckOverlaps(20);
-    TObjArray* ovexlist = gGeoManager->GetListOfOverlaps();
-    if(ovexlist->GetEntriesFast()){  
-      AliError("The application of alignment objects to the geometry caused huge overlaps/extrusions!");
-   }
-  }
-
-  return flag;
-
-}
-
-//_____________________________________________________________________________
-Bool_t AliSimulation::ApplyAlignObjsToGeom(const char* fileName, const char* clArrayName)
-{
-  // read collection of alignment objects (AliAlignObj derived) saved
-  // in the TClonesArray ClArrayName in the file fileName and apply
-  // them to the TGeo geometry passed as argument
-  //
-
-  TFile* inFile = TFile::Open(fileName,"READ");
-  if (!inFile || !inFile->IsOpen()) {
-    AliErrorClass(Form("Could not open file %s !",fileName));
-    return kFALSE;
-  }
-
-  TClonesArray* alObjArray = ((TClonesArray*) inFile->Get(clArrayName));
-  inFile->Close();
-  if (!alObjArray) {
-    AliErrorClass(Form("Could not get array (%s) from file (%s) !",clArrayName,fileName));
-    return kFALSE;
-  }
-
-  return ApplyAlignObjsToGeom(alObjArray);
-
-}
-
-//_____________________________________________________________________________
-Bool_t AliSimulation::ApplyAlignObjsToGeom(AliCDBParam* param, AliCDBId& Id)
-{
-  // read collection of alignment objects (AliAlignObj derived) saved
-  // in the TClonesArray ClArrayName in the AliCDBEntry identified by
-  // param (to get the AliCDBStorage) and Id; apply the alignment objects
-  // to the TGeo geometry passed as argument
-  //
-
-  AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage(param);
-  AliCDBEntry* entry = storage->Get(Id);
-  TClonesArray* AlObjArray = ((TClonesArray*) entry->GetObject());
-
-  return ApplyAlignObjsToGeom(AlObjArray);
-
-}
-
-//_____________________________________________________________________________
-Bool_t AliSimulation::ApplyAlignObjsToGeom(const char* uri, const char* path, Int_t runnum, Int_t version, Int_t sversion)
-{
-  // read collection of alignment objects (AliAlignObj derived) saved
-  // in the TClonesArray ClArrayName in the AliCDBEntry identified by
-  // param (to get the AliCDBStorage) and Id; apply the alignment objects
-  // to the TGeo geometry passed as argument
-  //
-
-  AliCDBParam* param = AliCDBManager::Instance()->CreateParameter(uri);
-  AliCDBId id(path, runnum, runnum, version, sversion);
-
-  return ApplyAlignObjsToGeom(param, id);
-
-}
-
-//_____________________________________________________________________________
-Bool_t AliSimulation::ApplyAlignObjsToGeom(const char* detName, Int_t runnum, Int_t version, Int_t sversion)
-{
-  // read collection of alignment objects (AliAlignObj derived) saved
-  // in the TClonesArray ClArrayName in the AliCDBEntry identified by
-  // param (to get the AliCDBStorage) and Id; apply the alignment objects
-  // to the TGeo geometry passed as argument
-  //
-
-  AliCDBPath path(detName,"Align","Data");
-  AliCDBEntry* entry = AliCDBManager::Instance()->Get(path.GetPath(),runnum,version,sversion);
-
-  if(!entry) return kFALSE;
-  TClonesArray* AlObjArray = ((TClonesArray*) entry->GetObject());
-
-  return ApplyAlignObjsToGeom(AlObjArray);
-}
-
-//_____________________________________________________________________________
-Bool_t AliSimulation::SetAlignObjArraySingleDet(const char* detName)
-{
-  // Fills array of single detector's alignable objects from CDB
-  
-  AliDebug(2, Form("Loading alignment data for detector: %s",detName));
-  
-  AliCDBEntry *entry;
-       
-  AliCDBPath path(detName,"Align","Data");
-       
-  entry=AliCDBManager::Instance()->Get(path.GetPath());
-  if(!entry){ 
-       AliDebug(2,Form("Couldn't load alignment data for detector %s",detName));
-       return kFALSE;
-  }
-  entry->SetOwner(1);
-  TClonesArray *alignArray = (TClonesArray*) entry->GetObject();       
-  alignArray->SetOwner(0);
-  AliDebug(2,Form("Found %d alignment objects for %s",
-                       alignArray->GetEntries(),detName));
-
-  AliAlignObj *alignObj=0;
-  TIter iter(alignArray);
-       
-  // loop over align objects in detector
-  while( ( alignObj=(AliAlignObj *) iter.Next() ) ){
-       fAlignObjArray->Add(alignObj);
-  }
-  // delete entry --- Don't delete, it is cached!
-       
-  AliDebug(2, Form("fAlignObjArray entries: %d",fAlignObjArray->GetEntries() ));
-  return kTRUE;
-
-}
-
 //_____________________________________________________________________________
 Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
 {
@@ -507,63 +376,49 @@ Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
     delRunLoader = kTRUE;
   }
 
-  // Load alignment data from CDB and fill fAlignObjArray 
+  // Export ideal geometry 
+  if (gGeoManager) gGeoManager->Export("geometry.root");
+
+  // Load alignment data from CDB and apply to geometry through AliGeomManager
   if(fLoadAlignFromCDB){
-       if(!fAlignObjArray) fAlignObjArray = new TObjArray();
-       
-       //fAlignObjArray->RemoveAll(); 
-       fAlignObjArray->Clear();        
-       fAlignObjArray->SetOwner(0);
-       TString detStr = fLoadAlignData;
-       TString dataNotLoaded="";
-       TString dataLoaded="";
-  
-       TObjArray* detArray = runLoader->GetAliRun()->Detectors();
-       for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
-               AliModule* det = (AliModule*) detArray->At(iDet);
-               if (!det) continue;
-               if (IsSelected(det->GetName(), detStr)) {
-                       if(!SetAlignObjArraySingleDet(det->GetName())){
-                               dataNotLoaded += det->GetName();
-                               dataNotLoaded += " ";
-                       } else {
-                               dataLoaded += det->GetName();
-                               dataLoaded += " ";
-                       }
-               }
-       } // end loop over detectors
-  
-       if ((detStr.CompareTo("ALL") == 0)) detStr = "";
-       dataNotLoaded += detStr;
-       AliInfo(Form("Alignment data loaded for: %s",
-                         dataLoaded.Data()));
-       AliInfo(Form("Didn't/couldn't load alignment data for: %s",
-                         dataNotLoaded.Data()));
-  } // fLoadAlignFromCDB flag
-  // Check if the array with alignment objects was
-  // provided by the user. If yes, apply the objects
-  // to the present TGeo geometry
-  if (fAlignObjArray) {
-    if (gGeoManager && gGeoManager->IsClosed()) {
-      if (ApplyAlignObjsToGeom(fAlignObjArray) == kFALSE) {
-       AliError("The misalignment of one or more volumes failed!"
-                "Compare the list of simulated detectors and the list of detector alignment data!");
+    
+    TString detStr = fLoadAlObjsListOfDets;
+    TString loadAlObjsListOfDets = "";
+    
+    TObjArray* detArray = runLoader->GetAliRun()->Detectors();
+    for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
+      AliModule* det = (AliModule*) detArray->At(iDet);
+      if (!det || !det->IsActive()) continue;
+      if (IsSelected(det->GetName(), detStr)) {
+       //add det to list of dets to be aligned from CDB
+       loadAlObjsListOfDets += det->GetName();
+       loadAlObjsListOfDets += " ";
+      }
+    } // end loop over detectors
+    (AliGeomManager::Instance())->ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
+  }else{
+    // Check if the array with alignment objects was
+    // provided by the user. If yes, apply the objects
+    // to the present TGeo geometry
+    if (fAlignObjArray) {
+      if (gGeoManager && gGeoManager->IsClosed()) {
+       if ((AliGeomManager::Instance())->ApplyAlignObjsToGeom(fAlignObjArray) == kFALSE) {
+         AliError("The misalignment of one or more volumes failed!"
+                  "Compare the list of simulated detectors and the list of detector alignment data!");
+         if (delRunLoader) delete runLoader;
+         return kFALSE;
+       }
+      }
+      else {
+       AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
        if (delRunLoader) delete runLoader;
        return kFALSE;
       }
     }
-    else {
-      AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
-      if (delRunLoader) delete runLoader;
-      return kFALSE;
-    }
   }
 
-
   // Update the internal geometry of modules (ITS needs it)
-  TString detStr = fLoadAlignData;
+  TString detStr = fLoadAlObjsListOfDets;
   TObjArray* detArray = runLoader->GetAliRun()->Detectors();
   for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
 
@@ -577,6 +432,9 @@ Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
 
   if (delRunLoader) delete runLoader;
 
+  // Update the TGeoPhysicalNodes
+  gGeoManager->RefreshPhysicalNodes();
+
   return kTRUE;
 }
 
@@ -634,13 +492,14 @@ Bool_t AliSimulation::Run(Int_t nEvents)
   // Set run number in CDBManager (if it is not already set in RunSimulation)
   if (!SetRunNumber()) if (fStopOnError) return kFALSE;
 
-  // Load and misalign the geometry
+  // If RunSimulation was not called, load the geometry and misalign it
   if (!gGeoManager) {
     TGeoManager::Import("geometry.root");
     if (!gGeoManager) if (fStopOnError) return kFALSE;
-    if (!MisalignGeometry()) if (fStopOnError) return kFALSE;
+    // Initialize the geometry manager (if not already done)
+    if(!MisalignGeometry()) if (fStopOnError) return kFALSE;
   }
-  
+
   // hits -> summable digits
   if (!fMakeSDigits.IsNull()) {
     if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
@@ -704,7 +563,7 @@ Bool_t AliSimulation::RunTrigger(const char* descriptors)
      }
    }
 
-   runLoader->MakeTree( "CT" );
+   runLoader->MakeTree( "GG" );
    AliCentralTrigger* aCTP = runLoader->GetTrigger();
   // Load Descriptors
    aCTP->LoadDescriptor( des );
@@ -782,15 +641,10 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
   }
   SetGAliceFile(runLoader->GetFileName());
  
-  // Export ideal geometry 
-  if (gGeoManager) gGeoManager->Export("geometry.root");
-
   // Misalign geometry
-//   if (!MisalignGeometry(runLoader)) {
-//     delete runLoader;
-//     return kFALSE;
-//   }
+#if ROOT_VERSION_CODE < 331527
   MisalignGeometry(runLoader);
+#endif
 
   // Export (mis)aligned geometry 
   if (gGeoManager) gGeoManager->Export("misaligned_geometry.root");
@@ -1131,7 +985,9 @@ Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName)
 
   AliInfo(Form("converting raw data DDL files to DATE file %s", dateFileName));
   char command[256];
-  sprintf(command, "dateStream -D -o %s -# %d -C", 
+  // Note the option -s. It is used in order to avoid
+  // the generation of SOR/EOR events.
+  sprintf(command, "dateStream -s -D -o %s -# %d -C", 
          dateFileName, runLoader->GetNumberOfEvents());
   FILE* pipe = gSystem->OpenPipe(command, "w");
 
@@ -1182,10 +1038,10 @@ Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
 // convert a DATE file to a root file with the program "alimdc"
 
   // ALIMDC setup
-  const Int_t kDBSize = 1000000000;
+  const Int_t kDBSize = 2000000000;
   const Int_t kTagDBSize = 1000000000;
   const Bool_t kFilter = kFALSE;
-  const Int_t kCompression = 1;
+  const Int_t kCompression = 0;
 
   char* path = gSystem->Which(gSystem->Getenv("PATH"), "alimdc");
   if (!path) {
@@ -1200,7 +1056,6 @@ Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
 
   const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
   const char* tagDBFS    = "/tmp/mdc1/tags";
-  const char* runDBFS    = "/tmp/mdc1/meta";
 
   // User defined file system locations
   if (gSystem->Getenv("ALIMDC_RAWDB1")) 
@@ -1209,18 +1064,14 @@ Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
     rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
   if (gSystem->Getenv("ALIMDC_TAGDB")) 
     tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
-  if (gSystem->Getenv("ALIMDC_RUNDB")) 
-    runDBFS = gSystem->Getenv("ALIMDC_RUNDB");
 
   gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
   gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
   gSystem->Exec(Form("rm -rf %s",tagDBFS));
-  gSystem->Exec(Form("rm -rf %s",runDBFS));
 
   gSystem->Exec(Form("mkdir %s",rawDBFS[0]));
   gSystem->Exec(Form("mkdir %s",rawDBFS[1]));
   gSystem->Exec(Form("mkdir %s",tagDBFS));
-  gSystem->Exec(Form("mkdir %s",runDBFS));
 
   Int_t result = gSystem->Exec(Form("alimdc %d %d %d %d %s", 
                                    kDBSize, kTagDBSize, kFilter, kCompression, dateFileName));
@@ -1229,7 +1080,6 @@ Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
   gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
   gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
   gSystem->Exec(Form("rm -rf %s",tagDBFS));
-  gSystem->Exec(Form("rm -rf %s",runDBFS));
 
   return (result == 0);
 }