// //
///////////////////////////////////////////////////////////////////////////////
+#include <TVirtualMCApplication.h>
#include <TGeoManager.h>
#include <TObjString.h>
-#include <TStopwatch.h>
#include <TSystem.h>
#include <TFile.h>
+#include "AliCodeTimer.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,
fRunGeneration(kTRUE),
fRunSimulation(kTRUE),
fLoadAlignFromCDB(kTRUE),
- fLoadAlignData("ALL"),
+ fLoadAlObjsListOfDets("ALL"),
fMakeSDigits("ALL"),
fMakeDigits("ALL"),
fMakeTrigger(""),
fEmbeddingFlag(kFALSE)
{
// create simulation object with default parameters
-
+ fgInstance = this;
SetGAliceFile("galice.root");
}
fRunGeneration(sim.fRunGeneration),
fRunSimulation(sim.fRunSimulation),
fLoadAlignFromCDB(sim.fLoadAlignFromCDB),
- fLoadAlignData(sim.fLoadAlignData),
+ fLoadAlObjsListOfDets(sim.fLoadAlObjsListOfDets),
fMakeSDigits(sim.fMakeSDigits),
fMakeDigits(sim.fMakeDigits),
fMakeTrigger(sim.fMakeTrigger),
for (Int_t i = 0; i < sim.fSpecCDBUri.GetEntriesFast(); i++) {
if (sim.fSpecCDBUri[i]) fSpecCDBUri.Add(sim.fSpecCDBUri[i]->Clone());
}
-
+ fgInstance = this;
}
//_____________________________________________________________________________
}
fSpecCDBUri.Delete();
+ if (fgInstance==this) fgInstance = 0;
+
+ AliCodeTimer::Instance()->Print();
}
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(1);
- 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)
{
// then applied to the TGeo geometry.
// Finally an overlaps check is performed.
+ if (!AliGeomManager::GetGeometry() || !AliGeomManager::GetGeometry()->IsClosed()) {
+ AliError("Can't apply the misalignment! Geometry is not loaded or it is still opened!");
+ return kFALSE;
+ }
Bool_t delRunLoader = kFALSE;
if (!runLoader) {
runLoader = LoadRun("READ");
delRunLoader = kTRUE;
}
- // Load alignment data from CDB and fill fAlignObjArray
+ // Export ideal geometry
+ AliGeomManager::GetGeometry()->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 || !det->IsActive()) 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;
- if(!dataLoaded.IsNull()) AliInfo(Form("Alignment data loaded for: %s",
- dataLoaded.Data()));
- if(!dataNotLoaded.IsNull()) 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!");
- if (delRunLoader) delete runLoader;
- return kFALSE;
+
+ 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::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 (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;
}
- }
- 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++) {
if (delRunLoader) delete runLoader;
- // Update the TGeoPhysicalNodes
- gGeoManager->RefreshPhysicalNodes();
-
return kTRUE;
}
{
// run the generation, simulation and digitization
+ AliCodeTimerAuto("")
+
InitCDBStorage();
if (nEvents > 0) fNEvents = 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 (!gGeoManager) {
- TGeoManager::Import("geometry.root");
- if (!gGeoManager) if (fStopOnError) return kFALSE;
- if (!MisalignGeometry()) if (fStopOnError) return kFALSE;
+ // If RunSimulation was not called, load the geometry and misalign it
+ if (!AliGeomManager::GetGeometry()) {
+ // Initialize the geometry manager
+ AliGeomManager::LoadGeometry("geometry.root");
+ if (!AliGeomManager::GetGeometry()) if (fStopOnError) return kFALSE;
+ // Misalign geometry
+ if(!MisalignGeometry()) if (fStopOnError) return kFALSE;
}
-
+
// hits -> summable digits
if (!fMakeSDigits.IsNull()) {
if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
{
// run the trigger
- TStopwatch stopwatch;
- stopwatch.Start();
+ AliCodeTimerAuto("")
AliRunLoader* runLoader = LoadRun("READ");
if (!runLoader) return kFALSE;
}
}
- AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
- stopwatch.RealTime(),stopwatch.CpuTime()));
-
delete runLoader;
return kTRUE;
{
// run the generation and simulation
- TStopwatch stopwatch;
- stopwatch.Start();
+ AliCodeTimerAuto("")
if (!gAlice) {
AliError("no gAlice object. Restart aliroot and try again.");
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();
}
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
+ AliGeomManager::SetGeometry(gGeoManager);
MisalignGeometry(runLoader);
-
- // Export (mis)aligned geometry
- if (gGeoManager) gGeoManager->Export("misaligned_geometry.root");
+#endif
// AliRunLoader* runLoader = gAlice->GetRunLoader();
// if (!runLoader) {
delete runLoader;
- AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
- stopwatch.RealTime(),stopwatch.CpuTime()));
return kTRUE;
}
{
// run the digitization and produce summable digits
- TStopwatch stopwatch;
- stopwatch.Start();
+ AliCodeTimerAuto("")
AliRunLoader* runLoader = LoadRun();
if (!runLoader) return kFALSE;
if (!det || !det->IsActive()) continue;
if (IsSelected(det->GetName(), detStr)) {
AliInfo(Form("creating summable digits for %s", det->GetName()));
- TStopwatch stopwatchDet;
- stopwatchDet.Start();
+ AliCodeTimerAuto(Form("creating summable digits for %s", det->GetName()));
det->Hits2SDigits();
- AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
- det->GetName(),stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
}
}
delete runLoader;
- AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
- stopwatch.RealTime(),stopwatch.CpuTime()));
-
return kTRUE;
}
{
// run the digitization and produce digits from sdigits
- TStopwatch stopwatch;
- stopwatch.Start();
+ AliCodeTimerAuto("")
while (AliRunLoader::GetRunLoader()) delete AliRunLoader::GetRunLoader();
if (gAlice) delete gAlice;
delete manager;
- AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
- stopwatch.RealTime(),stopwatch.CpuTime()));
-
return kTRUE;
}
{
// run the digitization and produce digits from hits
- TStopwatch stopwatch;
- stopwatch.Start();
+ AliCodeTimerAuto("")
AliRunLoader* runLoader = LoadRun("READ");
if (!runLoader) return kFALSE;
//PH Temporary fix to avoid interference with the PHOS loder/getter
//PH The problem has to be solved in more general way 09/06/05
- AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
- stopwatch.RealTime(),stopwatch.CpuTime()));
-
return kTRUE;
}
// to a root file.
// If deleteIntermediateFiles is true, the DATE file is deleted afterwards.
- TStopwatch stopwatch;
- stopwatch.Start();
+ AliCodeTimerAuto("")
if (!WriteRawFiles(detectors)) {
if (fStopOnError) return kFALSE;
}
}
- AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
- stopwatch.RealTime(),stopwatch.CpuTime()));
-
return kTRUE;
}
{
// convert the digits to raw data DDL files
+ AliCodeTimerAuto("")
+
AliRunLoader* runLoader = LoadRun("READ");
if (!runLoader) return kFALSE;
}
delete runLoader;
+
return kTRUE;
}
{
// convert raw data DDL files to a DATE file with the program "dateStream"
+ AliCodeTimerAuto("")
+
char* path = gSystem->Which(gSystem->Getenv("PATH"), "dateStream");
if (!path) {
AliError("the program dateStream was not found");