]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliSimulation.cxx
Updated buspatch and DDL numbers for station 345 and started buspatch at 1
[u/mrichter/AliRoot.git] / STEER / AliSimulation.cxx
index 39c55c66574b44e1f22b5aa2db1a32d0c4422b19..0ca530ad38e63e8d03f00d6c280756acbae68e45 100644 (file)
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
+#include <TVirtualMCApplication.h>
 #include <TGeoManager.h>
 #include <TObjString.h>
 #include <TStopwatch.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,
@@ -168,7 +171,7 @@ AliSimulation::AliSimulation(const char* configFileName, const char* cdbUri,
   fEmbeddingFlag(kFALSE)
 {
 // create simulation object with default parameters
-
+  fgInstance = this;
   SetGAliceFile("galice.root");
 }
 
@@ -217,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;
 }
 
 //_____________________________________________________________________________
@@ -245,6 +248,7 @@ AliSimulation::~AliSimulation()
   }
 
   fSpecCDBUri.Delete();
+  if (fgInstance==this) fgInstance = 0;
 }
 
 
@@ -365,6 +369,10 @@ Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
   // then applied to the TGeo geometry.
   // Finally an overlaps check is performed.
 
+  if (!gGeoManager || !gGeoManager->IsClosed()) {
+    AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
+    return kFALSE;
+  }  
   Bool_t delRunLoader = kFALSE;
   if (!runLoader) {
     runLoader = LoadRun("READ");
@@ -372,6 +380,9 @@ Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
     delRunLoader = kTRUE;
   }
 
+  // Export ideal geometry 
+  gGeoManager->Export("geometry.root");
+
   // Load alignment data from CDB and apply to geometry through AliGeomManager
   if(fLoadAlignFromCDB){
     
@@ -383,29 +394,22 @@ Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
       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 += " ";
+        //add det to list of dets to be aligned from CDB
+        loadAlObjsListOfDets += det->GetName();
+        loadAlObjsListOfDets += " ";
       }
     } // end loop over detectors
-    (AliGeomManager::Instance())->ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
+    AliGeomManager::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;
+      if (AliGeomManager::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;
       }
     }
   }
@@ -425,9 +429,6 @@ Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
 
   if (delRunLoader) delete runLoader;
 
-  // Update the TGeoPhysicalNodes
-  gGeoManager->RefreshPhysicalNodes();
-
   return kTRUE;
 }
 
@@ -487,7 +488,7 @@ Bool_t AliSimulation::Run(Int_t nEvents)
 
   // If RunSimulation was not called, load the geometry and misalign it
   if (!gGeoManager) {
-    TGeoManager::Import("geometry.root");
+    AliGeomManager::LoadGeometry("geometry.root");
     if (!gGeoManager) if (fStopOnError) return kFALSE;
     // Initialize the geometry manager (if not already done)
     if(!MisalignGeometry()) if (fStopOnError) return kFALSE;
@@ -623,7 +624,6 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
     gAlice->SetTriggerDescriptor(fMakeTrigger.Data());
 
   // Set run number in CDBManager
-  AliCDBManager::Instance()->SetRun(gAlice->GetRunNumber());
   AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
 
   AliRunLoader* runLoader = gAlice->GetRunLoader();
@@ -634,14 +634,10 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
   }
   SetGAliceFile(runLoader->GetFileName());
  
-  // Export ideal geometry 
-  if (gGeoManager) gGeoManager->Export("geometry.root");
-
   // Misalign geometry
+#if ROOT_VERSION_CODE < 331527
   MisalignGeometry(runLoader);
-
-  // Export (mis)aligned geometry 
-  if (gGeoManager) gGeoManager->Export("misaligned_geometry.root");
+#endif
 
 //   AliRunLoader* runLoader = gAlice->GetRunLoader();
 //   if (!runLoader) {