]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - AliGeant4/AliDetConstruction.cxx
Some additional changes related to the previous changes. AliL3Transform
[u/mrichter/AliRoot.git] / AliGeant4 / AliDetConstruction.cxx
index d096573e7c731f1304f18abfd8b255b9db3b58b8..a82484b51071d6ca2cac10f7039865c86f82e5a6 100644 (file)
@@ -1,75 +1,77 @@
 // $Id$
 // Category: geometry
 //
+// Author: I. Hrivnacova
+//
+// Class AliDetConstruction
+// ------------------------
 // See the class description in the header file.
 
 #include "AliDetConstruction.h"
-#include "AliSingleModuleConstruction.h"
+#include "AliDetSwitch.h"
+#include "AliLVTree.h"
 #include "AliGlobals.h"
+#include "AliFiles.h"
 #include "AliRun.h"
 #include "AliModule.h"
 
+#include "TG4XMLGeometryGenerator.h"
+#include "TG4GeometryServices.h"
+
+#include <G4VPhysicalVolume.hh>
+
+//_____________________________________________________________________________
 AliDetConstruction::AliDetConstruction()
-  : fTopVolumeName("ALIC")
+  : AliModulesComposition()
 {
   // initialize det switch vector: 
-  // moduleName nofVersions defaultVersion [type isStandalone]     
-        // det switch objects are deleted in
-       // tbe base class (AliModulesCompositions) destructor
-
-  AliDetSwitch* detSwitch;
-  detSwitch = new AliDetSwitch("ABSO",   1, 0, kStructure);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("DIPO",   3, 2, kStructure);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("FRAME",  2, 1, kStructure, false);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("HALL",   1, 0, kStructure);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("MAG",    1, 0, kStructure);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("PIPE",   4, 0, kStructure);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("SHIL",   1, 0, kStructure);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("CASTOR", 2, 1);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("FMD",    2, 1);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("ITS",    6, 5);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("MUON",   2, 0);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("PHOS",   5, 1);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("PMD",    3, 0);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("RICH",   3, 1);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("START",  2, 0);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("TOF",    5, 1, kDetector, false);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("TPC",    4, 1);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("TRD",    2, 0, kDetector, false);
-  AddDetSwitch(detSwitch); 
-  detSwitch = new AliDetSwitch("ZDC",    2, 1);
-  AddDetSwitch(detSwitch);  
+  // moduleName nofVersions defaultVersion [type]
+        // det switch objects are deleted in fDetSwitchVector destructor
+
+  fDetSwitchVector.Add(new AliDetSwitch("MAG",    1, 0, kStructure));
+  fDetSwitchVector.Add(new AliDetSwitch("ABSO",   1, 0, kStructure));
+  fDetSwitchVector.Add(new AliDetSwitch("DIPO",   3, 2, kStructure));
+  fDetSwitchVector.Add(new AliDetSwitch("FRAME",  3, 2, kStructure));
+  fDetSwitchVector.Add(new AliDetSwitch("HALL",   1, 0, kStructure));
+  fDetSwitchVector.Add(new AliDetSwitch("PIPE",   5, 0, kStructure));
+  fDetSwitchVector.Add(new AliDetSwitch("SHIL",   2, 1, kStructure));
+  fDetSwitchVector.Add(new AliDetSwitch("CASTOR", 2, 1));
+  fDetSwitchVector.Add(new AliDetSwitch("FMD",    2, 1));
+  fDetSwitchVector.Add(new AliDetSwitch("ITS",    7, 5));
+  fDetSwitchVector.Add(new AliDetSwitch("MUON",   2, 1));
+  fDetSwitchVector.Add(new AliDetSwitch("PHOS",   2, 1));
+  fDetSwitchVector.Add(new AliDetSwitch("PMD",    3, 1));
+  fDetSwitchVector.Add(new AliDetSwitch("RICH",   3, 1));
+  fDetSwitchVector.Add(new AliDetSwitch("START",  2, 1));
+  fDetSwitchVector.Add(new AliDetSwitch("TOF",    5, 2));
+  fDetSwitchVector.Add(new AliDetSwitch("TPC",    4, 2));
+  fDetSwitchVector.Add(new AliDetSwitch("TRD",    2, 1));
+  fDetSwitchVector.Add(new AliDetSwitch("ZDC",    3, 2));
+
+  // update messenger
+  fDetSwitchVector.UpdateMessenger();
+
+  // instantiate LVtree browser
+  AliLVTree::Instance();
 }
 
+//_____________________________________________________________________________
 AliDetConstruction::AliDetConstruction(const AliDetConstruction& right)
   : AliModulesComposition(right)
 {
   // AliModuleComposition is protected from copying
 }  
 
-AliDetConstruction::~AliDetConstruction() {
-//
+//_____________________________________________________________________________
+AliDetConstruction::~AliDetConstruction() 
+{
+  // delete LVtree browser
+  delete AliLVTree::Instance();
 }
 
 // operators
 
+//_____________________________________________________________________________
 AliDetConstruction& 
 AliDetConstruction::operator=(const AliDetConstruction& right)
 {
@@ -85,6 +87,7 @@ AliDetConstruction::operator=(const AliDetConstruction& right)
           
 // private methods
 
+//_____________________________________________________________________________
 void AliDetConstruction::BuildDetectors()
 {
 // Create module constructions for AliModules 
@@ -102,25 +105,28 @@ void AliDetConstruction::BuildDetectors()
     text = text + module->GetName() + " has been found.";
     AliGlobals::Exception(text);
   }  
-  AddSingleModuleConstruction("BODY", 0, kStructure);
+  AddModule("BODY", 0, kStructure);
 
   G4bool first = true;
   while ((module = (AliModule*)next())) {
+  
     // register moduleConstruction in fDetSwitchVector
-    // in order to keep availability of /AlDet/list command
+    // in order to keep availability of /aliDet/list command
     G4String modName = module->GetName();
     G4int modVersion = module->IsVersion();
     if (first)
       // skip registering of the top volume 
       first = false;
     else 
-      SwitchDetOn(modName, modVersion);
+      fDetSwitchVector.SwitchDetOn(modName, modVersion);
  
     // all modules will be processed alltogether
-    AddMoreModuleConstruction(modName, modVersion);
+    AddModule(modName, modVersion, fDetSwitchVector.GetDetSwitch(modName)->GetType());
 
-    G4cout << "Created module construction for " 
-           << modName << "v" << modVersion << "." << G4endl;   
+    if (VerboseLevel() > 0) {
+      G4cout << "Created module construction for " 
+             << modName << "v" << modVersion << "." << G4endl;   
+    }       
   }
   
   // do not process Config.C 
@@ -128,6 +134,7 @@ void AliDetConstruction::BuildDetectors()
   SetProcessConfigToModules(false);    
 }
 
+//_____________________________________________________________________________
 void AliDetConstruction::CreateDetectors()
 {
 // Creates AliModules and their module constructions 
@@ -135,135 +142,64 @@ void AliDetConstruction::CreateDetectors()
 // ---
 
   // add top volume (AliBODY) construction first
-  AddSingleModuleConstruction("BODY", 0, kStructure);
+  AddModule("BODY", 0, kStructure);
 
   // add modules constructions
-  const G4RWTPtrOrderedVector<AliDetSwitch>& krDetSwitchVector 
-    = GetDetSwitchVector();
-  for (G4int id=0; id<krDetSwitchVector.entries(); id++)
+  for (G4int i=0; i<fDetSwitchVector.GetSize(); i++)
   {
-    G4String detName = krDetSwitchVector[id]->GetDetName();
-    G4int version = krDetSwitchVector[id]->GetSwitchedVersion();
-    G4bool isStandalone = krDetSwitchVector[id]->IsStandalone();
-    AliModuleType type = krDetSwitchVector[id]->GetType();
+    AliDetSwitch* detSwitch = fDetSwitchVector.GetDetSwitch(i);
+    G4String detName = detSwitch->GetDetName();
+    G4int version = detSwitch->GetSwitchedVersion();
+    AliModuleType type = detSwitch->GetType();
     
     if (version > -1)
-      if (isStandalone)
-        AddSingleModuleConstruction(detName, version, type);
-      else
-        AddMoreModuleConstruction(detName, version, type);
+      AddModule(detName, version, type);
   }    
 }
 
-void AliDetConstruction::CheckDetDependencies()
+//_____________________________________________________________________________
+void AliDetConstruction::CheckDependence(const G4String& master, 
+                                         const G4String& slave)
 {
-// Checks modules dependencies.
-// Dependent modules FRAME, TOF, TRD 
-// TOF always requires FRAMEv1
-// TRD can be built with both (??)
+// Checks modules dependence.
+// If master is switch on and slave off, the default version
+// of slave is switched on and a  warning is issued.
 // ---
 
-  const G4RWTPtrOrderedVector<AliDetSwitch>& krDetSwitchVector 
-    = GetDetSwitchVector();
-
-  // get switched versions of dependent modules
-  G4int nofDets = krDetSwitchVector.entries();
-  G4int verFRAME = -1; 
-  G4int verTOF = -1; 
-  G4int verTRD = -1; 
-  AliDetSwitch* detSwitchFRAME = 0;
-  for (G4int id=0; id<nofDets; id++) {  
-    G4String detName = krDetSwitchVector[id]->GetDetName();
-    if (detName == "FRAME") { 
-      verFRAME = krDetSwitchVector[id]->GetSwitchedVersion();  
-      detSwitchFRAME = krDetSwitchVector[id];
-    }  
-    if (detName == "TOF")  
-      verTOF = krDetSwitchVector[id]->GetSwitchedVersion();  
-    if (detName == "TRD")  
-      verTRD = krDetSwitchVector[id]->GetSwitchedVersion();  
+  AliDetSwitch* masterSwitch = fDetSwitchVector.GetDetSwitch(master);
+  AliDetSwitch* slaveSwitch = fDetSwitchVector.GetDetSwitch(slave);
+
+  if ( masterSwitch->GetSwitchedVersion() > -1 && 
+       slaveSwitch->GetSwitchedVersion() < 0 ) {
+     
+    slaveSwitch->SwitchOnDefault();
+    
+    // warning
+    G4String text = "AliDetConstruction::CheckDetDependence: \n";
+    text = text + "    Switched " + master + " requires " + slave + ".\n"; 
+    text = text + "    The det switch for " + slave + " has been changed."; 
+    AliGlobals::Warning(text);
   }
+}  
   
-  // check dependencies  
-  if (verTRD > -1 && verTOF > -1) {
-    // both TRD and TOF 
-    if (verFRAME != 1) {
-      detSwitchFRAME->SwitchOn(1);
-      G4String text = "AliDetConstruction::CheckDetDependencies: \n";
-      text = text + "    Switched TOF and TRD require FRAME v1.\n"; 
-      text = text + "    The det switch for FRAME has been changed."; 
-      AliGlobals::Warning(text);
-    }  
-  }
-  else if (verTRD > -1 && verTOF == -1)   {
-    // only TRD
-    if (verFRAME < 0) {
-      detSwitchFRAME->SwitchOn(1);
-      G4String text = "AliDetConstruction::CheckDetDependencies: \n";
-      text = text + "    Switched TRD require FRAME.\n"; 
-      text = text + "    The det switch for FRAME has been changed."; 
-      AliGlobals::Warning(text);
-    }  
-  }  
-  else if (verTRD == -1 && verTOF > -1)   {
-    // only TOF
-    if (verFRAME != 1) {
-      detSwitchFRAME->SwitchOn(1);
-      G4String text = "AliDetConstruction::CheckDetDependencies: \n";
-      text = text + "    Switched TOF requires FRAME v1.\n"; 
-      text = text + "    The det switch for FRAME has been changed."; 
-      AliGlobals::Warning(text);
-    }  
-  }
-/*  
-  if (verTRD > -1 && verTOF > -1) {
-    // both TRD and TOF 
-    if (verTOF == 2 || verTOF == 3 || verTOF == 5 || verTOF == 6) {
-      G4String text = "AliDetConstruction::CheckDetDependencies: \n";
-      text = text + "    Switched TOF and TRD require different FRAME versions."; 
-      AliGlobals::Exception(text);
-    }  
-    if (verFRAME != 0) {
-      detSwitchFRAME->SwitchOn(0);
-      G4String text = "AliDetConstruction::CheckDetDependencies: \n";
-      text = text + "    Switched TOF and TRD require FRAME v0.\n"; 
-      text = text + "    The det switch for FRAME has been changed."; 
-      AliGlobals::Warning(text);
-    }  
-  }
-  else if (verTRD > -1 && verTOF == -1)   {
-    // only TRD
-    if (verFRAME != 0) {
-      detSwitchFRAME->SwitchOn(0);
-      G4String text = "AliDetConstruction::CheckDetDependencies: \n";
-      text = text + "    Switched TRD requires FRAME v0.\n"; 
-      text = text + "    The det switch for FRAME has been changed."; 
-      AliGlobals::Warning(text);
-    }          
-  }  
-  else if (verTRD == -1 && verTOF > -1)   {
-    // only TOF
-    if ((verTOF == 0 || verTOF == 1 || verTOF == 4) && (verFRAME !=0)) {
-      detSwitchFRAME->SwitchOn(0);
-      G4String text = "AliDetConstruction::CheckDetDependencies: \n";
-      text = text + "    Switched TOF requires FRAME v0.\n"; 
-      text = text + "    The det switch for FRAME has been changed."; 
-      AliGlobals::Warning(text);
-    }
-    if ((verTOF == 2 || verTOF == 3 || verTOF == 5 || verTOF == 6) &&
-        (verFRAME != 1)) {
-      detSwitchFRAME->SwitchOn(1);
-      G4String text = "AliDetConstruction::CheckDetDependencies: \n";
-      text = text + "    Switched TOF requires FRAME v1.\n"; 
-      text = text + "    The det switch for FRAME has been changed."; 
-      AliGlobals::Warning(text);
-    }
-  }
-*/    
+//_____________________________________________________________________________
+void AliDetConstruction::CheckDetDependencies()
+{
+// Checks modules dependencies.
+// ---
+
+  CheckDependence("MUON", "DIPO");
+  CheckDependence("TOF", "FRAME");
+  CheckDependence("TRD", "FRAME");
+  CheckDependence("ZDC", "PIPE");
+  CheckDependence("ZDC", "ABSO");
+  CheckDependence("ZDC", "DIPO");
+  CheckDependence("ZDC", "SHIL");
 }  
 
 // public methods
 
+//_____________________________________________________________________________
 G4VPhysicalVolume* AliDetConstruction::Construct()
 {
 // Constructs geometry.
@@ -284,6 +220,56 @@ G4VPhysicalVolume* AliDetConstruction::Construct()
   // construct modules geometry
   ConstructModules();
 
-  return AliSingleModuleConstruction::GetWorld();      
+  return TG4GeometryServices::Instance()->GetWorld();      
 }
 
+//_____________________________________________________________________________
+void AliDetConstruction::GenerateXMLGeometry() const 
+{
+// Generates XML geometry file from the top volume.
+// The file name is set according the last switched detector
+// registered in the det switch vector.
+// ---
+
+  G4VPhysicalVolume* world = TG4GeometryServices::Instance()->GetWorld();
+
+  // XML filename
+  // according to last switched detector
+  G4String detName;
+  G4String detVersion = "";
+  G4int version = -1;
+  for (G4int i=fDetSwitchVector.GetSize()-1; i>=0; i--) {
+    version = fDetSwitchVector.GetDetSwitch(i)->GetSwitchedVersion();
+    if (version > -1) {
+      detName = fDetSwitchVector.GetDetSwitch(i)->GetDetName();
+      AliGlobals::AppendNumberToString(detVersion,version); 
+      break;
+    }  
+  }  
+  G4String filePath 
+    = AliFiles::Instance()->GetXMLFilePath(detName, version);
+  
+  // set top volume name
+  G4String topName = world->GetName() + "_comp";
+  
+  // generate XML
+  
+  TG4XMLGeometryGenerator xml;
+  xml.OpenFile(filePath);
+
+  // generate materials 
+  // not implemented
+  // xml.GenerateMaterials(version, "today", "Generated from G4",
+  //                       "v4", world->GetLogicalVolume());
+
+  // generate volumes tree
+  xml.GenerateSection(detName, detVersion, "today", "Generated from Geant4",
+                      topName, world->GetLogicalVolume());
+  xml.CloseFile();
+  
+  if (VerboseLevel() > 0) {
+    G4cout << "File " << detName << "v" << version << ".xml has been generated." 
+           << G4endl;
+  }       
+}  
+