#include <RVersion.h>
#include <TBrowser.h>
+#include <TClonesArray.h>
+#include <TGeoManager.h>
#include <TStopwatch.h>
#include <TSystem.h>
#include <TVirtualMC.h>
-#include <TGeoManager.h>
-
+#include <TROOT.h>
#include "AliLog.h"
#include "AliDetector.h"
#include "AliStack.h"
#include "AliMagF.h"
#include "AliTrackReference.h"
+#include "AliSimulation.h"
+#include "AliGeomManager.h"
+#include "AliCDBManager.h"
+#include "AliCDBStorage.h"
+#include "AliCDBEntry.h"
ClassImp(AliMC)
// at InitGeometry().
//
- if(gAlice->IsRootGeometry()){
- // Load geometry
- const char *geomfilename = gAlice->GetGeometryFileName();
- if(gSystem->ExpandPathName(geomfilename)){
- AliInfo(Form("Loading geometry from file:\n %40s\n\n",geomfilename));
- TGeoManager::Import(geomfilename);
+ if(gAlice->IsRootGeometry()){ //load geometry either from CDB or from file
+ if(gAlice->IsGeomFromCDB()){
+ AliInfo("Loading geometry from CDB default storage");
+ AliCDBPath path("GRP","Geometry","Data");
+ AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
+ if(!entry) AliFatal("Unable to load geometry from CDB!");
+ entry->SetOwner(0);
+ gGeoManager = (TGeoManager*) entry->GetObject();
+ if (!gGeoManager) AliFatal("TGeoManager object not found in the specified CDB entry!");
}else{
- AliInfo(Form("Geometry file %40s not found!\n",geomfilename));
- return;
+ // Load geometry
+ const char *geomfilename = gAlice->GetGeometryFileName();
+ if(gSystem->ExpandPathName(geomfilename)){
+ AliInfo(Form("Loading geometry from file:\n %40s",geomfilename));
+ TGeoManager::Import(geomfilename);
+ }else{
+ AliInfo(Form("Geometry file %40s not found!\n",geomfilename));
+ return;
+ }
}
}else{
// Create modules, materials, geometry
}
+//_______________________________________________________________________
+Bool_t AliMC::MisalignGeometry()
+{
+// Call misalignment code if AliSimulation object was defined.
+
+ if(!gAlice->IsRootGeometry()){
+ //Set alignable volumes for the whole geometry
+ SetAllAlignableVolumes();
+ }
+ // Misalign geometry via AliSimulation instance
+ if (!AliSimulation::GetInstance()) return kFALSE;
+ AliGeomManager::SetGeometry(gGeoManager);
+ return AliSimulation::GetInstance()->MisalignGeometry(gAlice->GetRunLoader());
+}
+
+//_______________________________________________________________________
+void AliMC::ConstructOpGeometry()
+{
+ //
+ // Loop all detector modules and call DefineOpticalProperties() method
+ //
+
+ TIter next(gAlice->Modules());
+ AliModule *detector;
+ AliInfo("Optical properties definition");
+ while((detector = dynamic_cast<AliModule*>(next()))) {
+ // Initialise detector optical properties
+ detector->DefineOpticalProperties();
+ }
+}
+
//_______________________________________________________________________
void AliMC::InitGeometry()
{
//
- // Initialize detectors and display geometry
+ // Initialize detectors
//
AliInfo("Initialisation:");
AliModule *detector;
while((detector = dynamic_cast<AliModule*>(next()))) {
stw.Start();
- // Initialise detector and display geometry
+ // Initialise detector geometry
if(gAlice->IsRootGeometry()) detector->CreateMaterials();
detector->Init();
- detector->BuildGeometry();
AliInfo(Form("%10s R:%.2fs C:%.2fs",
detector->GetName(),stw.RealTime(),stw.CpuTime()));
}
-
+}
+
+//_______________________________________________________________________
+void AliMC::SetAllAlignableVolumes()
+{
+ //
+ // Add alignable volumes (TGeoPNEntries) looping on all
+ // active modules
+ //
+
+ AliInfo(Form("Setting entries for all alignable volumes of active detectors"));
+ AliModule *detector;
+ TIter next(gAlice->Modules());
+ while((detector = dynamic_cast<AliModule*>(next()))) {
+ detector->AddAlignableVolumes();
+ }
}
//_______________________________________________________________________
//
// Load the event generator
//
- if(fGenerator)
- if(generator)
+ if(fGenerator) {
+ if(generator) {
AliWarning(Form("Replacing generator %s with %s",
- fGenerator->GetName(),generator->GetName()))
- else
+ fGenerator->GetName(),generator->GetName()));
+ }
+ else {
AliWarning(Form("Replacing generator %s with NULL",
fGenerator->GetName()));
+ }
+ }
fGenerator = generator;
}
//Call the appropriate stepping routine;
AliModule *det = dynamic_cast<AliModule*>(gAlice->Modules()->At(id));
if(det && det->StepManagerIsEnabled()) {
- fMCQA->StepManager(id);
+ if(AliLog::GetGlobalDebugLevel()>0) fMCQA->StepManager(id);
det->StepManager();
}
}
//=================Create Materials and geometry
gMC->Init();
+ // Set alignable volumes for the whole geometry (with old root)
+#if ROOT_VERSION_CODE < 331527
+ SetAllAlignableVolumes();
+#endif
//Read the cuts for all materials
ReadTransPar();
//Build the special IMEDIA table
//Compute cross-sections
gMC->BuildPhysics();
- //Write Geometry object to current file.
- gAlice->GetRunLoader()->WriteGeometry();
-
//Initialise geometry deposition table
fEventEnergy.Set(gMC->NofVolumes()+1);
fSummEnergy.Set(gMC->NofVolumes()+1);
b->Add(fMCQA,"AliMCQA");
}
-//PH
//_______________________________________________________________________
void AliMC::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
{
// 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);
- }
- }
+ Int_t nEntries = fTrackReferences->GetEntries();
+ for (Int_t i=0; i < nEntries; 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->SetBit(kNotDeleted,kFALSE);
+ fTrackReferences->RemoveAt(i);
+ }
+ } // if ref
}
fTrackReferences->Compress();
}