]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - AliGeant4/AliModulesComposition.cxx
Bug fix reported by Jiri. Make atoi input zero terminated in StepManager()
[u/mrichter/AliRoot.git] / AliGeant4 / AliModulesComposition.cxx
index ce1a4b7861463fecef2fae1f88a28f2d5f80d3e7..1f07bc9360f1d03f16a08ecbfa6e60ad0b3ed526 100644 (file)
@@ -1,51 +1,51 @@
 // $Id$
 // Category: geometry
 //
+// Author: I. Hrivnacova
+//
+// Class AliModulesComposition
+// ---------------------------
 // See the class description in the header file.
 
 #include "AliModulesComposition.h"
-#include "AliModulesCompositionMessenger.h"
-#include "AliSingleModuleConstruction.h"
-#include "AliMoreModulesConstruction.h"
+#include "AliModuleConstruction.h"
 #include "AliMagneticField.h"
 #include "AliGlobals.h"
+#include "AliFiles.h"
+#include "AliModule.h"
+
+#include "TG4GeometryManager.h"
 
-#include <G4UniformMagField.hh>
-#include <G4FieldManager.hh>
-#include <G4TransportationManager.hh>
+#include <G4Material.hh>
 
+//_____________________________________________________________________________
 AliModulesComposition::AliModulesComposition()
-  : fAllLVSensitive(false),
+  : AliVerbose("modulesComposition"),
     fReadGeometry(false),
-    fWriteGeometry(false)    
-{
+    fWriteGeometry(false),
+    fMagneticField(0),
+    fMessenger(this) {
 //
-  fMoreModulesConstruction = new AliMoreModulesConstruction();
-  fMagneticField = new AliMagneticField();
-  fMessenger = new AliModulesCompositionMessenger(this);
 }
 
+//_____________________________________________________________________________
 AliModulesComposition::AliModulesComposition(const AliModulesComposition& right)
+  : AliVerbose("modulesComposition"),
+    fMessenger(this)
 {
 //
   AliGlobals::Exception("AliModulesComposition is protected from copying.");  
 }
 
+//_____________________________________________________________________________
 AliModulesComposition::~AliModulesComposition() {
 //   
-  delete fMoreModulesConstruction;
   delete fMagneticField;
-  delete fMessenger; 
-  
-  // destroy det switch vector
-  fDetSwitchVector.clearAndDestroy();  
-  
-  // destroy det construction vector
-  fModuleConstructionVector.clearAndDestroy();
 }
 
 // operators
 
+//_____________________________________________________________________________
 AliModulesComposition& 
 AliModulesComposition::operator=(const AliModulesComposition& right)
 {
@@ -57,395 +57,206 @@ AliModulesComposition::operator=(const AliModulesComposition& right)
   return *this;  
 }    
           
-// protected methods
+//
+// private methods
+//
 
-void AliModulesComposition::AddDetSwitch(AliDetSwitch* detSwitch)
-{
-// Adds detSwitch to the detSwitch vector.
+//_____________________________________________________________________________
+void AliModulesComposition::Configure()
+{ 
+// Executes the detectors setup Root macros
+// (extracted from AliRoot Config.C) and
+// G4 macros.
 // ---
-
-  fDetSwitchVector.insert(detSwitch);
-  fMessenger->SetCandidates();
-}  
   
-void AliModulesComposition::AddSingleModuleConstruction(G4String moduleName, 
-                               G4int version, AliModuleType moduleType)
-{
-// Adds SingleModuleConstruction.
-// ---
-
-  AliSingleModuleConstruction* moduleConstruction
-    = new AliSingleModuleConstruction(moduleName, version, moduleType);
-  fModuleConstructionVector.insert(moduleConstruction);
-}  
-                 
-void AliModulesComposition::AddMoreModuleConstruction(G4String moduleName, 
-                               G4int version, AliModuleType moduleType)
-{
-// Adds module to MoreModulesConstruction (construction of dependent
-// modules.)
-// ---
+  // number of modules
+  G4int nofModules = fModuleConstructionVector.size();
 
-  fMoreModulesConstruction->AddModule(moduleName, version, moduleType);
-}  
-                                 
-void AliModulesComposition::ConstructModules()
-{
-// Construct geometry of all modules (both standalone and dependent.)
-// ---
-
-  // set common options
-  SetReadGeometryToModules(fReadGeometry);
-  SetWriteGeometryToModules(fWriteGeometry);
-  SetAllLVSensitiveToModules(fAllLVSensitive);
-     // common setAllLVSensitive is overridden by Config.in
-     // macro
+  if (nofModules == 0) {
+    AliGlobals::Warning(
+      "AliModulesComposition::Configure: No modules are defined.");
+    return;  
+  }
   
-  // one module constructions
-  G4int nofDets = fModuleConstructionVector.entries();
-  for (G4int i=0; i<nofDets; i++) {
-    G4cout << "Module " << fModuleConstructionVector[i]->GetDetName()
-           << " will be constructed now." << endl;
-    fModuleConstructionVector[i]->Construct();
-  }  
-    
-  // more modules construction
-  G4int nofModules = fMoreModulesConstruction->GetNofModules();
-  if (nofModules>0) {
-    G4cout << "Dependent modules will be constructed now." << endl;
-    fMoreModulesConstruction->Construct();
-  }  
-}  
-
-void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry)
-{
-// Sets readGeometry control to all modules.
-// ---
+  for (G4int i=0; i<nofModules; i++) 
+    fModuleConstructionVector[i]->Configure();
+}      
 
-  // single module constructions
-  G4int nofDets = fModuleConstructionVector.entries();
-  G4int i;
-  for (i=0; i<nofDets; i++)
-    fModuleConstructionVector[i]->SetReadGeometry(readGeometry);
 
-  // more modules construction
-  nofDets = fMoreModulesConstruction->GetNofModules();
-  for (i=0; i<nofDets; i++) { 
-    AliSingleModuleConstruction* moduleConstruction
-      = fMoreModulesConstruction->GetModuleConstruction(i);
-    moduleConstruction->SetReadGeometry(readGeometry);
-  }  
-}    
-  
-void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry)
-{
-// Sets writeGeometry control to all modules.
-// ---
+//_____________________________________________________________________________
+void AliModulesComposition::CreateG4Geometry()
+{ 
+// Constructs geometry.
+// G3 tables are process for all modules alltogether.
+// --
 
-  // single module constructions
-  G4int nofDets = fModuleConstructionVector.entries();
-  G4int i;
-  for (i=0; i<nofDets; i++)
-    fModuleConstructionVector[i]->SetWriteGeometry(writeGeometry);
+  // number of modules
+  G4int nofModules = fModuleConstructionVector.size();
 
-  // more modules construction
-  nofDets = fMoreModulesConstruction->GetNofModules();
-  for (i=0; i<nofDets; i++) { 
-    AliSingleModuleConstruction* moduleConstruction
-      = fMoreModulesConstruction->GetModuleConstruction(i);
-    moduleConstruction->SetWriteGeometry(writeGeometry);
-  }  
-}    
+  if (nofModules == 0) {
+    AliGlobals::Warning(
+      "AliModulesComposition::CreateG4Geometry: No modules are defined.");
+    return;  
+  }
 
-void AliModulesComposition::SetAllLVSensitiveToModules(G4bool allSensitive)
-{
-// Sets setAllSensitive control to all modules.
-// ---
+  // get geometry manager
+  TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
 
-  // single module constructions
-  G4int nofDets = fModuleConstructionVector.entries();
   G4int i;
-  for (i=0; i<nofDets; i++) {
-    AliSingleModuleConstruction* moduleConstruction
-      = dynamic_cast<AliSingleModuleConstruction*>(fModuleConstructionVector[i]);
-    if (!moduleConstruction) {
-      G4String text = "AliModulesComposition::SetProcessConfig: \n";
-      text = text + "    Unknown module construction type.";
-      AliGlobals::Exception(text);
-    }      
-    moduleConstruction->SetAllLVSensitive(allSensitive);
-  }  
-
-  // more modules construction
-  nofDets = fMoreModulesConstruction->GetNofModules();
-  for (i=0; i<nofDets; i++) { 
-    AliSingleModuleConstruction* moduleConstruction
-      = fMoreModulesConstruction->GetModuleConstruction(i);
-    moduleConstruction->SetAllLVSensitive(allSensitive);
-  }  
-}    
+  for (i=0; i<nofModules; i++) {
 
-void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig)
-{
-// Sets processConfig control to all modules.
-// ---
-
-  // single module constructions
-  G4int nofDets = fModuleConstructionVector.entries();
-  G4int i;
-  for (i=0; i<nofDets; i++) {
-    AliSingleModuleConstruction* moduleConstruction
-      = dynamic_cast<AliSingleModuleConstruction*>(fModuleConstructionVector[i]);
-    if (!moduleConstruction) {
-      G4String text = "AliModulesComposition::SetProcessConfig: \n";
-      text = text + "    Unknown module construction type.";
+    // fModuleConstructionVector[i]->Configure(files);
+  
+    // register module name in the name map
+    AliModule* module = fModuleConstructionVector[i]->GetAliModule();
+    pGeometryManager->SetMapSecond(module->GetName()); 
+
+    G4bool readGeometry = fModuleConstructionVector[i]->GetReadGeometry();
+    G4bool writeGeometry = fModuleConstructionVector[i]->GetWriteGeometry();
+    G4String dataFilePath = fModuleConstructionVector[i]->GetDataFilePath();
+
+    if (readGeometry) {
+      // TG4GeometryManager uses g3tog4 methods for reading
+      // g3calls.dat files - as these methods do not fill name map
+      // they cannot be used for constructing more modules
+      // together
+      //
+      // pGeometryManager->SetWriteGeometry(false);
+      // pGeometryManager->ReadG3Geometry(dataFilePath);
+       
+      G4String text = "AliModulesComposition::Construct - Limitation:\n";
+      text = text + "    Reading g3calls.dat is not implemented.";
       AliGlobals::Exception(text);
-    }      
-    moduleConstruction->SetProcessConfig(processConfig);
+    }
+    else {                 
+      // set geometry output stream for this module
+      pGeometryManager->SetWriteGeometry(writeGeometry);
+      if (writeGeometry) 
+        pGeometryManager->OpenOutFile(dataFilePath);
+        
+      // create geometry from AliRoot
+      
+      // construct materials
+      module->CreateMaterials();   
+
+      // construct G3 geometry
+      module->CreateGeometry();
+      
+      if (writeGeometry) 
+        pGeometryManager->CloseOutFile();
+    }  
   }  
   
-  // more modules construction
-  nofDets = fMoreModulesConstruction->GetNofModules();
-  for (i=0; i<nofDets; i++) { 
-    AliSingleModuleConstruction* moduleConstruction
-      = fMoreModulesConstruction->GetModuleConstruction(i);
-    moduleConstruction->SetProcessConfig(processConfig);
-  }    
-}    
-
-// public methods
-
-void AliModulesComposition::SwitchDetOn(G4String moduleNameVer)
-{ 
-// Switchs on module specified by name and version.
-// ---
-
-  G4int nofDets = fDetSwitchVector.entries(); 
-  if (moduleNameVer == "ALL") {
-    for (G4int id=0; id<nofDets; id++) {
-      G4int defaultVersion = fDetSwitchVector[id]->GetDefaultVersion();
-      fDetSwitchVector[id]->SwitchOn(defaultVersion); 
-    }  
-  }
-  else if (moduleNameVer == "NONE") {
-    for (G4int id=0; id<nofDets; id++)
-      fDetSwitchVector[id]->SwitchOff(); 
-  }
-  else {
-    // get version number
-    G4int len = moduleNameVer.length();
-    G4String moduleName = moduleNameVer(0, len-1);
-    G4String version = moduleNameVer(len-1, 1);
-    G4int iVersion = AliGlobals::StringToInt(version);
-
-    if (iVersion < 0) {
-      // in case the version number is not provided
-      // the default one is set
-      SwitchDetOnDefault(moduleNameVer);
-    }  
-    else 
-      SwitchDetOn(moduleName, iVersion);
-  }
-}
-
-void AliModulesComposition::SwitchDetOn(G4String moduleName, G4int version)
-{ 
-// Switchs on module specified by name and version.
-// ---
-
-  G4int nofDets = fDetSwitchVector.entries(); 
-  for (G4int id=0; id<nofDets; id++) {
-    G4String iDetName = fDetSwitchVector[id]->GetDetName();
-    if (iDetName == moduleName) {
-      fDetSwitchVector[id]->SwitchOn(version);
-      return;
-    }
-  }
-  AliGlobals::Exception(
-    "AliModulesComposition: Wrong detector name for " + moduleName + ".");
-}
+  // construct G4 geometry
+  pGeometryManager->CreateG4Geometry();
 
-void AliModulesComposition::SwitchDetOnDefault(G4String moduleName)
-{ 
-// Switchs on module specified by name with default version.
-// ---
+  // print name map
+  // pGeometryManager->PrintNameMap();
 
-  G4int nofDets = fDetSwitchVector.entries(); 
-  for (G4int id=0; id<nofDets; id++) {
-    G4String iDetName = fDetSwitchVector[id]->GetDetName();
-    if (iDetName == moduleName) {
-      fDetSwitchVector[id]->SwitchOnDefault();
-      return;
-    }
-  }
-  AliGlobals::Exception(
-    "AliModulesComposition: Wrong detector name for " + moduleName + ".");
-}
-
-void AliModulesComposition::SwitchDetOff(G4String moduleName)
-{ 
-// Switchs off module specified by name.
-// ---
+/*
+  // moved to AliSDConstruction
+  // to be performed after Init  (required for MUON)
+  
+  for (i=0; i<nofModules; i++) {
 
-  G4int nofDets = fDetSwitchVector.entries(); 
-  if (moduleName == "ALL") {
-    for (G4int id=0; id<nofDets; id++)
-      fDetSwitchVector[id]->SwitchOff(); 
-  }
-  else {
-    for (G4int id=0; id<nofDets; id++) {
-      G4String iDetName = fDetSwitchVector[id]->GetDetName();
-      if (iDetName == moduleName) { 
-        fDetSwitchVector[id]->SwitchOff();
-        return;
-      }
-    }
+    // construct geometry for display
+    fModuleConstructionVector[i]->GetAliModule()->BuildGeometry();
   }
-  AliGlobals::Exception(
-    "AliModulesComposition: Wrong detector name for " + moduleName + ".");
-}
-
-void AliModulesComposition::PrintSwitchedDets() const
-{ 
-// Lists switched detectors.
-// ---
+*/
 
-  G4String svList = GetSwitchedDetsList();
-    
-  G4cout << "Switched Alice detectors: " << endl;
-  G4cout << "--------------------------" << endl;
-  G4cout << svList << endl;
+  // reset TG4GeometryManager 
+  pGeometryManager->ClearG3Tables();
 }
 
-void AliModulesComposition::PrintAvailableDets() const
-{ 
-// Lists available detectors.
-// ---
-
-  G4String avList = GetAvailableDetsList();
-    
-  G4cout << "Available Alice detectors: " << endl;
-  G4cout << "---------------------------" << endl;
-  G4cout << avList << endl;
-}
-
-G4String AliModulesComposition::GetSwitchedDetsList() const
-{ 
-// Returns list of switched detectors.
+//_____________________________________________________________________________
+void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry)
+{
+// Sets readGeometry control to all modules.
 // ---
 
-  G4String svList = "";
+  for (G4int i=0; i<fModuleConstructionVector.size(); i++) 
+    fModuleConstructionVector[i]->SetReadGeometry(readGeometry);
+}    
   
-  G4int nofDets = fDetSwitchVector.entries(); 
-  G4int nofSwitchedDets = 0;
-  for (G4int id=0; id<nofDets; id++) {
-    G4int iVersion = fDetSwitchVector[id]->GetSwitchedVersion();
-    if (iVersion > -1) {
-      nofSwitchedDets++;
-      G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
-      AliGlobals::AppendNumberToString(moduleNameVer, iVersion);
-      svList += moduleNameVer;
-      svList += " "; 
-    }
-  }
-
-  if (nofSwitchedDets ==  nofDets) svList = "ALL: " + svList;
-  if (nofSwitchedDets ==  0)       svList = "NONE";   
-
-  return svList;
-}
-
-const G4RWTPtrOrderedVector<AliDetSwitch>& 
-AliModulesComposition::GetDetSwitchVector() const
+//_____________________________________________________________________________
+void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry)
 {
-// Returns detSwitch vector.
+// Sets writeGeometry control to all modules.
 // ---
 
-  //const AliDetSwitchVector& vector = fDetSwitchVector;
-  const G4RWTPtrOrderedVector<AliDetSwitch>& vector = fDetSwitchVector;
-  return vector;
-}  
+  for (G4int i=0; i<fModuleConstructionVector.size(); i++) 
+    fModuleConstructionVector[i]->SetWriteGeometry(writeGeometry);
+}    
 
-G4String AliModulesComposition::GetAvailableDetsList() const
-{ 
-// Returns list of available detectors.
-// ---
+//
+// protected methods
+//
 
-  G4String svList = "";
-  
-  G4int nofDets = fDetSwitchVector.entries(); 
-  for (G4int id=0; id<nofDets; id++) {
-    G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
-    for (G4int iv=0; iv<nofVersions; iv++) {
-      G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
-      AliGlobals::AppendNumberToString(moduleNameVer, iv);
-      svList += moduleNameVer;
-      svList += " ";
-    }
-  }
+//_____________________________________________________________________________
+void AliModulesComposition::AddModule(const G4String& name, 
+                                      G4int version, 
+                                     AliModuleType moduleType)
+{
+// Adds module to the module construction vector.
+// ---
 
-  return svList;
-}
+  AliModuleConstruction* moduleConstruction 
+    = new AliModuleConstruction(name, version, moduleType);
 
-G4String AliModulesComposition::GetAvailableDetsListWithCommas() const
-{ 
-// Returns list of available detectors with commas.
+  fModuleConstructionVector.push_back(moduleConstruction);
+}  
+                                 
+//_____________________________________________________________________________
+void AliModulesComposition::ConstructModules()
+{
+// Construct geometry of all modules (both standalone and dependent.)
 // ---
 
-  G4String svList = "";
+  // set common options
+  SetReadGeometryToModules(fReadGeometry);
+  SetWriteGeometryToModules(fWriteGeometry);
   
-  G4int nofDets = fDetSwitchVector.entries(); 
-  for (G4int id=0; id<nofDets; id++) {
-    G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
-    for (G4int iv=0; iv<nofVersions; iv++) {
-      G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
-      AliGlobals::AppendNumberToString(moduleNameVer, iv);
-      svList += moduleNameVer;
-      if (iv<nofVersions-1)    svList += "/";
-      else if (id < nofDets-1) svList += ", ";
-    }
-  }
+  // configure modules
+  Configure();
 
-  return svList;
-}
+  // construct dependent modules
+  CreateG4Geometry();
+}  
 
-G4String AliModulesComposition::GetDetNamesList() const
-{ 
-// Returns list of detector names.
+//_____________________________________________________________________________
+void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig)
+{
+// Sets processConfig control to all modules.
 // ---
 
-  G4String svList = "";
-  
-  G4int nofDets = fDetSwitchVector.entries(); 
-  for (G4int id=0; id<nofDets; id++) { 
-    svList += fDetSwitchVector[id]->GetDetName();
-    svList += " ";
-  }
+  for (G4int i=0; i<fModuleConstructionVector.size(); i++) 
+    fModuleConstructionVector[i]->SetProcessConfig(processConfig);
+}    
 
-  return svList;
-}
+//
+// public methods
+//
 
-G4String AliModulesComposition::GetDetNamesListWithCommas() const
-{ 
-// Returns list of detector names with commas.
+//_____________________________________________________________________________
+void AliModulesComposition::PrintMaterials() const
+{
+// Prints all materials.
 // ---
 
-  G4String svList = "";
-  
-  G4int nofDets = fDetSwitchVector.entries(); 
-  for (G4int id=0; id<nofDets; id++) { 
-    svList += fDetSwitchVector[id]->GetDetName();
-    if (id < nofDets-1) svList += ", ";
-  }
-
-  return svList;
+  const G4MaterialTable* matTable = G4Material::GetMaterialTable();
+  G4cout << *matTable;
 }
 
+//_____________________________________________________________________________
 void AliModulesComposition::SetMagField(G4double fieldValue)
 {
 // Sets uniform magnetic field to specified value.
 // ---
-  if (fMagneticField)
-    fMagneticField->SetFieldValue(fieldValue);
+
+  // create fields if it does not exist
+  if (!fMagneticField) fMagneticField = new AliMagneticField();
+  
+  // set value
+  fMagneticField->SetFieldValue(fieldValue);
 }