]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliSimulation.cxx
ApplyDisplacements method renamed to ApplyAlignObjsToGeom. Automatic check of overlap...
[u/mrichter/AliRoot.git] / STEER / AliSimulation.cxx
index 7e3812cf61bc76ec86b0195dbee91fa8949f2e6f..898db856c31108289dfed3e6c5116ab5e2d8e75f 100644 (file)
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
+#include <TGeoManager.h>
 #include <TObjString.h>
 #include <TStopwatch.h>
 #include <TSystem.h>
+#include <TFile.h>
 
-#include "AliLog.h"
+#include "AliCDBStorage.h"
+#include "AliCDBEntry.h"
+#include "AliCDBManager.h"
+#include "AliAlignObj.h"
+#include "AliCentralTrigger.h"
+#include "AliDAQConfig.h"
 #include "AliDigitizer.h"
 #include "AliGenerator.h"
+#include "AliLog.h"
 #include "AliModule.h"
 #include "AliRun.h"
 #include "AliRunDigitizer.h"
 #include "AliRunLoader.h"
 #include "AliSimulation.h"
 #include "AliVertexGenFile.h"
-
-#include "AliDAQConfig.h"
-#include "AliAlignObj.h"
-#include "AliAlignObjAngles.h"
-#include "AliAlignObjMatrix.h"
+#include "AliCentralTrigger.h"
 
 ClassImp(AliSimulation)
 
@@ -136,6 +140,7 @@ AliSimulation::AliSimulation(const char* configFileName,
   fRunSimulation(kTRUE),
   fMakeSDigits("ALL"),
   fMakeDigits("ALL"),
+  fMakeTrigger(""),
   fMakeDigitsFromHits(""),
   fWriteRawData(""),
   fRawDataFileName(""),
@@ -147,6 +152,7 @@ AliSimulation::AliSimulation(const char* configFileName,
   fGAliceFileName("galice.root"),
   fEventsPerFile(),
   fBkgrdFileNames(NULL),
+  fAlignObjArray(NULL),
   fUseBkgrdVertex(kTRUE),
   fRegionOfInterest(kFALSE)
 {
@@ -163,6 +169,7 @@ AliSimulation::AliSimulation(const AliSimulation& sim) :
   fRunSimulation(sim.fRunSimulation),
   fMakeSDigits(sim.fMakeSDigits),
   fMakeDigits(sim.fMakeDigits),
+  fMakeTrigger(sim.fMakeTrigger),
   fMakeDigitsFromHits(sim.fMakeDigitsFromHits),
   fWriteRawData(sim.fWriteRawData),
   fRawDataFileName(""),
@@ -174,6 +181,7 @@ AliSimulation::AliSimulation(const AliSimulation& sim) :
   fGAliceFileName(sim.fGAliceFileName),
   fEventsPerFile(),
   fBkgrdFileNames(NULL),
+  fAlignObjArray(NULL),
   fUseBkgrdVertex(sim.fUseBkgrdVertex),
   fRegionOfInterest(sim.fRegionOfInterest)
 {
@@ -261,7 +269,7 @@ void AliSimulation::SetEventsPerFile(const char* detector, const char* type,
 }
 
 //_____________________________________________________________________________
-Bool_t AliSimulation::ApplyDisplacements(const char* fileName, const char* ClArrayName)
+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
@@ -274,52 +282,19 @@ Bool_t AliSimulation::ApplyDisplacements(const char* fileName, const char* ClArr
     return kFALSE;
   }
 
-  TClonesArray* AlObjArray = ((TClonesArray*) inFile->Get(ClArrayName));
+  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 AliSimulation::ApplyDisplacements(AlObjArray);
+  return gAlice->ApplyAlignObjsToGeom(alObjArray);
 
 }
 
 //_____________________________________________________________________________
-Bool_t AliSimulation::ApplyDisplacements(TClonesArray* AlObjArray)
-{
-  // Read collection of alignment objects (AliAlignObj derived) saved
-  // in the TClonesArray ClArrayName and apply them to the geometry
-  // manager singleton.
-  //
-  Int_t nvols = AlObjArray->GetEntriesFast();
-
-  AliAlignObj::ELayerID layerId; // unique identity for volume in the alobj
-  Int_t modId; // unique identity for volume in the alobj
-  Bool_t ispathvalid; // false if volume path for alobj is not valid for TGeo
-
-  TGeoHMatrix dm;
-
-  for(Int_t j=0; j<nvols; j++)
-    {
-      AliAlignObj* alobj = (AliAlignObj*) AlObjArray->UncheckedAt(j);
-      const char* volpath = alobj->GetVolPath();
-      TGeoPhysicalNode* node = (TGeoPhysicalNode*) gGeoManager->MakePhysicalNode(volpath);
-      alobj->GetMatrix(dm);
-      alobj->GetVolUID(layerId, modId);
-      ispathvalid = gGeoManager->cd(volpath);
-      if(!ispathvalid){
-       AliWarningClass(Form("Volume path %s not valid!",volpath));
-       return kFALSE;
-      }
-      TGeoHMatrix* hm = gGeoManager->GetCurrentMatrix();
-      hm->MultiplyLeft(&dm);
-      AliInfoClass(Form("Aligning volume %s of detector layer %d with local ID %d",volpath,layerId,modId));
-      node->Align(hm);
-    }
-
-  return kTRUE;
-
-}
-
-//_____________________________________________________________________________
-Bool_t AliSimulation::ApplyDisplacements(AliCDBParam* param, AliCDBId& Id)
+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
@@ -331,12 +306,12 @@ Bool_t AliSimulation::ApplyDisplacements(AliCDBParam* param, AliCDBId& Id)
   AliCDBEntry* entry = storage->Get(Id);
   TClonesArray* AlObjArray = ((TClonesArray*) entry->GetObject());
 
-  return AliSimulation::ApplyDisplacements(AlObjArray);
+  return gAlice->ApplyAlignObjsToGeom(AlObjArray);
 
 }
 
 //_____________________________________________________________________________
-Bool_t AliSimulation::ApplyDisplacements(const char* uri, const char* path, Int_t runnum, Int_t version, Int_t sversion)
+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
@@ -347,7 +322,7 @@ Bool_t AliSimulation::ApplyDisplacements(const char* uri, const char* path, Int_
   AliCDBParam* param = AliCDBManager::Instance()->CreateParameter(uri);
   AliCDBId id(path, runnum, runnum, version, sversion);
 
-  return ApplyDisplacements(param, id);
+  return ApplyAlignObjsToGeom(param, id);
 
 }
 
@@ -368,6 +343,18 @@ Bool_t AliSimulation::Run(Int_t nEvents)
 {
 // run the generation, simulation and digitization
 
+  // First check if we have any CDB storage set, because it is used 
+  // to retrieve the calibration and alignment constants
+
+  AliCDBManager* man = AliCDBManager::Instance();
+  if (!man->IsDefaultStorageSet())
+  {
+    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliWarning("No default CDB storage set, so I will use $ALICE_ROOT");
+    AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    man->SetDefaultStorage("local://$ALICE_ROOT");
+  }  
+
   if (nEvents > 0) fNEvents = nEvents;
 
   // generation and simulation -> hits
@@ -400,6 +387,13 @@ Bool_t AliSimulation::Run(Int_t nEvents)
     }
   }
 
+  // digits -> trigger
+  if (!fMakeTrigger.IsNull()) {
+    if (!RunTrigger(fMakeTrigger)) {
+      if (fStopOnError) return kFALSE;
+    }
+  }
+
   // digits -> raw data
   if (!fWriteRawData.IsNull()) {
     if (!WriteRawData(fWriteRawData, fRawDataFileName, 
@@ -411,6 +405,84 @@ Bool_t AliSimulation::Run(Int_t nEvents)
   return kTRUE;
 }
 
+//_____________________________________________________________________________
+Bool_t AliSimulation::RunTrigger(const char* descriptors)
+{
+  // run the trigger
+
+  TStopwatch stopwatch;
+  stopwatch.Start();
+
+  AliRunLoader* runLoader = LoadRun("READ");
+  if (!runLoader) return kFALSE;
+  TString des = descriptors;
+  // Load Descriptors
+  AliCentralTrigger* aCTP = new AliCentralTrigger( des );
+
+  // digits -> trigger
+  if( !aCTP->RunTrigger( runLoader ) ) {
+    if (fStopOnError) {
+      delete aCTP;
+      return kFALSE;
+    }
+  }
+
+/*
+  // Process each event
+  for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
+    AliInfo(Form("processing event %d", iEvent));
+    runLoader->GetEvent(iEvent);
+
+    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)) {
+        AliInfo(Form("triggering from digits for %s", det->GetName()));
+
+     //   AliLoader* loader = fLoader[iDet];
+     //   loader->LoadDigits("read");
+     //   TTree* digitsTree = loader->TreeD();
+     //   det->Trigger( digitsTree );
+     // or
+        AliTriggerDetector* tdet = det->CreateTriggerDetector();
+        TObjArray* detInp = dtrg->GetTriggerInputs();
+        for( Int_t i=0; i<detInp->GetEntriesFast(); i++ )
+               fInputs.AddLast( detInp->At(i) );
+
+        AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
+                det->GetName(),stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
+      }
+    }
+
+    if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
+      AliError(Form("the following detectors were not found: %s",
+                    detStr.Data()));
+      if (fStopOnError) {
+         delete centralTP;
+         return kFALSE;
+      }
+    }
+
+    // Check trigger conditions
+    centralTP->TriggerConditions();
+
+    // Write trigger ????
+    centralTP->Write();
+
+  } */
+
+  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
+               stopwatch.RealTime(),stopwatch.CpuTime()));
+
+  delete aCTP;
+  delete runLoader;
+
+  return kTRUE;
+}
+
+
+
 //_____________________________________________________________________________
 Bool_t AliSimulation::RunSimulation(Int_t nEvents)
 {
@@ -433,6 +505,26 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
   StdoutToAliInfo(StderrToAliError(
     gAlice->Init(fConfigFileName.Data());
   ););
+
+  // 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 (gAlice->ApplyAlignObjsToGeom(fAlignObjArray) == kFALSE) {
+       AliError("The application of misalignment failed! Restart aliroot and try again. ");
+       return kFALSE;
+      }
+    }
+    else {
+      AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
+      return kFALSE;
+    }
+  }
+
+  // Export TGeo geometry
+  if (gGeoManager) gGeoManager->Export("geometry.root");
+
   AliRunLoader* runLoader = gAlice->GetRunLoader();
   if (!runLoader) {
     AliError(Form("gAlice has no run loader object. "