]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TGeant4/TG4GeometryManager.cxx
new files for merging/digitization
[u/mrichter/AliRoot.git] / TGeant4 / TG4GeometryManager.cxx
index f22b8ae2c4aa9e5161e35cf1be1300f17617dc74..4bc5b2d2674a409f9c5a6692a8157a11181cb16c 100644 (file)
 
 #include "TG4GeometryManager.h"
 #include "TG4GeometryOutputManager.h"
-#include "TG4PhysicsManager.h"
+#include "TG4GeometryServices.h"
+#include "TG4G3PhysicsManager.h"
+#include "TG4G3Units.h"
 #include "TG4VSensitiveDetector.h"
 #include "TG4Limits.h"
 #include "TG4Globals.h"
-#include "TG3Units.h"
 
 #include <G3toG4.hh> 
 #include <G3toG4BuildTree.hh>
@@ -25,7 +26,6 @@
 #include <G3MedTable.hh>
 #include <G3SensVolVector.hh>
 
-#include <G4SDManager.hh>
 #include <G4VSensitiveDetector.hh>
 #include <G4LogicalVolumeStore.hh>
 #include <G4PVPlacement.hh>
@@ -33,9 +33,6 @@
 #include <G4MaterialPropertiesTable.hh>
 #include <G4Element.hh> 
 
-#include <math.h>
-#include <ctype.h>
-
 // extern global method from g3tog4
 void G3CLRead(G4String &, char *);
 
@@ -56,6 +53,8 @@ TG4GeometryManager::TG4GeometryManager()
 
   fOutputManager = new TG4GeometryOutputManager();
 
+  fGeometryServices = new TG4GeometryServices(&fMediumIdVector, &fNameMap);
+
   fgInstance = this;
       
   // instantiate the default element table
@@ -72,6 +71,7 @@ TG4GeometryManager::TG4GeometryManager(const TG4GeometryManager& right) {
 TG4GeometryManager::~TG4GeometryManager() {
 //
   delete fOutputManager;
+  delete fGeometryServices;
 }
 
 //==================================================================== =========
@@ -100,39 +100,7 @@ TG4GeometryManager::operator=(const TG4GeometryManager& right)
 //=============================================================================
 
 
-G4double* TG4GeometryManager::CreateG4doubleArray(Float_t* array, 
-               G4int size) const
-{
-// Converts Float_t* array to G4double*,
-// !! The new array has to be deleted by user.
-// ---
-
-  G4double* doubleArray;
-  if (size>0) {
-    doubleArray = new G4double[size]; 
-    for (G4int i=0; i<size; i++) doubleArray[i] = array[i];
-  }
-  else {
-    doubleArray = 0; 
-  }  
-  return doubleArray;
-}
-
-
-G4String TG4GeometryManager::CutName(const char* name) const
-{
-// Removes spaces after the name if present.
-// ---
-
-  G4String cutName = name;
-  G4int i = cutName.length();
-  while (cutName(--i) == ' ') cutName = cutName(0,i);
-
-  return cutName;
-}  
-
-
-void TG4GeometryManager::GstparCut(G4int itmed, TG3Cut par, G4double parval)
+void TG4GeometryManager::GstparCut(G4int itmed, TG4G3Cut par, G4double parval)
 {
 // Sets special tracking medium parameter. 
 // It is applied to all logical volumes that use the specified 
@@ -155,19 +123,21 @@ void TG4GeometryManager::GstparCut(G4int itmed, TG3Cut par, G4double parval)
     if (!tg4Limits)
       G4Exception("TG4GeometryManager::GstparCut: Wrong limits type.");
   }    
-  else {     
+  else {
     tg4Limits = new TG4Limits();
     medium->SetLimits(tg4Limits);
+
     // add verbose 
     G4cout << "TG4GeometryManager::GstparCut: new TG4Limits() for medium " 
-           << itmed << " has been created." << endl;  
+           << itmed << " has been created." << G4endl;  
   }       
   // set parameter
   tg4Limits->SetG3Cut(par, parval*GeV);
 }
 
 
-void TG4GeometryManager::GstparFlag(G4int itmed, TG3Flag par, G4double parval)
+void TG4GeometryManager::GstparControl(G4int itmed, TG4G3Control par, 
+                                       G4double parval)
 {
 // Sets special tracking medium parameter. 
 // It is applied to all logical volumes that use the specified 
@@ -177,7 +147,7 @@ void TG4GeometryManager::GstparFlag(G4int itmed, TG3Flag par, G4double parval)
   // get medium from table
   G3MedTableEntry* medium = G3Med.get(itmed);
   if (!medium) {
-    G4String text = "TG4GeometryManager::GstparFlag: \n";
+    G4String text = "TG4GeometryManager::GstparControl: \n";
     text = text + "    Medium not found."; 
     G4Exception(text);
   }  
@@ -188,17 +158,18 @@ void TG4GeometryManager::GstparFlag(G4int itmed, TG3Flag par, G4double parval)
   if (limits) {
     tg4Limits = dynamic_cast<TG4Limits*> (limits);
     if (!tg4Limits)
-      G4Exception("TG4GeometryManager::GstparFlag: Wrong limits type.");
+      G4Exception("TG4GeometryManager::GstparControl: Wrong limits type.");
   }    
   else {     
     tg4Limits = new TG4Limits();
     medium->SetLimits(tg4Limits);
+
     // add verbose 
-    G4cout << "TG4GeometryManager::GstparFlag: new TG4Limits() for medium 
-           << itmed << " has been created." << endl;  
+    G4cout << "TG4GeometryManager::GstparControl: new TG4Limits() for medium
+           << itmed << " has been created." << G4endl;  
   }
   // set parameter
-  tg4Limits->SetG3Flag(par, parval);
+  tg4Limits->SetG3Control(par, parval);
 }
 
  
@@ -229,8 +200,8 @@ void TG4GeometryManager::FillMediumIdVector()
   }  
 
   // add verbose
-  G4cout << "Total nof materials: " << nofMaterials << endl;
-  G4cout << "Total nof tracking medias: " << fMediumCounter << endl;  
+  G4cout << "Total nof materials: " << nofMaterials << G4endl;
+  G4cout << "Total nof tracking medias: " << fMediumCounter << G4endl;  
 }    
 
 
@@ -252,7 +223,7 @@ void TG4GeometryManager::Material(Int_t& kmat, const char* name, Float_t a,
 // ---
 
     kmat = ++fMaterialCounter;
-    G4double* bufin = CreateG4doubleArray(buf, nwbuf); 
+    G4double* bufin = fGeometryServices->CreateG4doubleArray(buf, nwbuf); 
 
     // write token to the output file
     if (fWriteGeometry) 
@@ -283,9 +254,9 @@ void TG4GeometryManager::Mixture(Int_t& kmat, const char *name, Float_t *a,
 // ---
 
    Int_t npar = abs(nlmat);
-   G4double *ain = CreateG4doubleArray(a, npar); 
-   G4double *zin = CreateG4doubleArray(z, npar); 
-   G4double *wmatin = CreateG4doubleArray(wmat, npar); 
+   G4double *ain = fGeometryServices->CreateG4doubleArray(a, npar); 
+   G4double *zin = fGeometryServices->CreateG4doubleArray(z, npar); 
+   G4double *wmatin = fGeometryServices->CreateG4doubleArray(wmat, npar); 
 
    kmat = ++fMaterialCounter;
 
@@ -317,7 +288,7 @@ void TG4GeometryManager::Medium(Int_t& kmed, const char *name, Int_t nmat,
 // Creates a temporary "medium" that is used for 
 // assigning corresponding parameters to G4 objects:
 // NTMED is stored as a second material index;
-// ISVOL is used for builing TG3SensVolVector;
+// ISVOL is used for builing G3SensVolVector;
 // STEMAX is passed in TG4Limits (if fUseG3TMLimits is set true);
 // !! The other parameters (IFIELD, FIELDM, TMAXFD, DEEMAX, EPSIL, STMIN)
 // are ignored by Geant4.
@@ -380,43 +351,6 @@ void TG4GeometryManager::Matrix(Int_t& krot, Float_t thetaX, Float_t phiX,
 }
   
 
-G4Material* TG4GeometryManager::MixMaterials(G4String name, G4double density, 
-        TG4StringVector* matNames, TG4doubleVector* matWeights)
-{
-// Creates a mixture of selected materials
-// ---
-
-  // number of materials to be mixed  
-  G4int nofMaterials = matNames->entries();
-  if (nofMaterials != matWeights->entries()) {
-    G4String text = "TG4GeometryManager::MixMaterials: ";
-    text = text +  "different number of material names and weigths.";
-    TG4Globals::Exception(text);
-  }    
-  // add verbose
-  // G4cout << "Nof of materials to be mixed: " << nofMaterials << endl;
-
-  // fill vector of materials
-  TG4MaterialVector matVector;  
-  G4int im;
-  for (im=0; im< nofMaterials; im++) {
-    // material
-    G4Material* material = G4Material::GetMaterial((*matNames)[im]);
-    matVector.insert(material);
-  } 
-
-  // create the mixed material
-  G4Material* mixture = new G4Material(name, density, nofMaterials);
-  for (im=0; im< nofMaterials; im++) {
-    G4Material* material = matVector[im];
-    G4double fraction = (*matWeights)[im];
-    mixture->AddMaterial(material, fraction);
-  }
-
-  return mixture;
-}  
-
 void TG4GeometryManager::Ggclos() 
 { 
 // Sets the top VTE in temporary G3 volume table.
@@ -449,14 +383,14 @@ void TG4GeometryManager::Gfmate(Int_t imat, char *name, Float_t &a,
     // !! unsafe conversion
     const char* chName = material->GetName();
     name = (char*)chName;
-    a = GetEffA(material);
-    z = GetEffZ(material);
+    a = fGeometryServices->GetEffA(material);
+    z = fGeometryServices->GetEffZ(material);
     
     dens = material->GetDensity();
-    dens /= TG3Units::MassDensity();
+    dens /= TG4G3Units::MassDensity();
 
     radl = material->GetRadlen();
-    radl /= TG3Units::Length();
+    radl /= TG4G3Units::Length();
 
     // the following parameters are not defined in Geant4
     absl = 0.; 
@@ -476,9 +410,9 @@ void  TG4GeometryManager::Gstpar(Int_t itmed, const char *param,
 // Passes the tracking medium parameter to TG4Limits.
 // The tracking medium parameter is set only in case
 // its value is different from the "global" physics setup.
-// (If: CheckCut/FlagWithG3Defaults is used checking
+// (If: CheckCut/ControlWithG3Defaults is used checking
 //  is performed with respect to G3 default values.)
-// When any cut/flag parameter is set in limits
+// When any cut/control parameter is set in limits
 // the physics manager is locked and the physics setup
 // cannot be changed.
 // Applying this TG4Limits to particles and physical
@@ -502,24 +436,22 @@ void  TG4GeometryManager::Gstpar(Int_t itmed, const char *param,
   if (fWriteGeometry) 
     fOutputManager->WriteGstpar(itmed, param, parval); 
 
-  // get physics setup
-  TG4PhysicsManager* physicsManager = TG4PhysicsManager::Instance();
-  //TG4CutVector* cutVector = physicsManager->GetCutVector();
-  //TG4FlagVector* flagVector = physicsManager->GetFlagVector();
+  // get G3 physics setup
+  TG4G3PhysicsManager* g3PhysicsManager = TG4G3PhysicsManager::Instance();
 
-  G4String name = CutName(param); 
-  TG3Cut g3Cut;
-  if (physicsManager->CheckCutWithCutVector(name, parval, g3Cut)) {
-      GstparCut(itmed, g3Cut, parval);
-      physicsManager->Lock();
+  G4String name = fGeometryServices->CutName(param); 
+  TG4G3Cut cut;
+  if (g3PhysicsManager->CheckCutWithTheVector(name, parval, cut)) {
+      GstparCut(itmed, cut, parval);
+      g3PhysicsManager->Lock();
   }  
   else {
-    TG3Flag g3Flag;
-    if (physicsManager->CheckFlagWithFlagVector(name, parval, g3Flag)) {
-      GstparFlag(itmed, g3Flag, parval);
-      physicsManager->Lock();
+    TG4G3Control control;
+    if (g3PhysicsManager->CheckControlWithTheVector(name, parval, control)) {
+      GstparControl(itmed, control, parval);
+      g3PhysicsManager->Lock();
     } 
-    else if (g3Cut==kNoG3Cuts && g3Flag==kNoG3Flags) { 
+    else if (cut==kNoG3Cuts && control==kNoG3Controls) { 
       G4String text = "TG4GeometryManager::Gstpar:";
       text = text + name;
       text = text + " parameter is not yet implemented.";
@@ -529,8 +461,9 @@ void  TG4GeometryManager::Gstpar(Int_t itmed, const char *param,
 } 
  
  
-void  TG4GeometryManager::Gsckov(Int_t itmed, Int_t npckov, Float_t* ppckov,
-                        Float_t* absco, Float_t* effic, Float_t* rindex)
+void  TG4GeometryManager::SetCerenkov(Int_t itmed, Int_t npckov, 
+                             Float_t* ppckov, Float_t* absco, Float_t* effic, 
+                            Float_t* rindex)
 {
 //
 //  Geant3 desription:
@@ -551,16 +484,16 @@ void  TG4GeometryManager::Gsckov(Int_t itmed, Int_t npckov, Float_t* ppckov,
 //       RINDEX      Refraction index (if=0 metal)
 // ---
 
-  G4double* ppckovDbl = CreateG4doubleArray(ppckov, npckov); 
-  G4double* abscoDbl  = CreateG4doubleArray(absco, npckov); 
-  G4double* efficDbl  = CreateG4doubleArray(effic, npckov); 
-  G4double* rindexDbl = CreateG4doubleArray(rindex, npckov); 
+  G4double* ppckovDbl = fGeometryServices->CreateG4doubleArray(ppckov, npckov); 
+  G4double* abscoDbl  = fGeometryServices->CreateG4doubleArray(absco, npckov); 
+  G4double* efficDbl  = fGeometryServices->CreateG4doubleArray(effic, npckov); 
+  G4double* rindexDbl = fGeometryServices->CreateG4doubleArray(rindex, npckov); 
   
   // add units
   G4int i;
   for (i=0; i<npckov; i++) {
-    ppckovDbl[i] = ppckovDbl[i]*TG3Units::Energy();
-    abscoDbl[i]  = abscoDbl[i]*TG3Units::Length();
+    ppckovDbl[i] = ppckovDbl[i]*TG4G3Units::Energy();
+    abscoDbl[i]  = abscoDbl[i]*TG4G3Units::Length();
   }  
 
   // create material properties table
@@ -575,7 +508,7 @@ void  TG4GeometryManager::Gsckov(Int_t itmed, Int_t npckov, Float_t* ppckov,
   // get material of medium from table
   G3MedTableEntry* medium = G3Med.get(itmed);
   if (!medium) {
-    G4String text = "TG4GeometryManager::Gsckov: \n";
+    G4String text = "TG4GeometryManager::SetCerenkov: \n";
     text = text + "    Medium not found."; 
     G4Exception(text);
   }  
@@ -585,9 +518,9 @@ void  TG4GeometryManager::Gsckov(Int_t itmed, Int_t npckov, Float_t* ppckov,
   material->SetMaterialPropertiesTable(table);
 
   G4cout << "The tables for UV photon tracking set for "
-         << material->GetName() << endl;
+         << material->GetName() << G4endl;
   for (i=0; i<npckov; i++)
-    G4cout << ppckovDbl[i] << " " << rindexDbl[i] << endl;
+    G4cout << ppckovDbl[i] << " " << rindexDbl[i] << G4endl;
         
   delete ppckovDbl;
   delete abscoDbl;
@@ -614,10 +547,11 @@ void  TG4GeometryManager::Gsdvn(const char *name, const char *mother,
     if (fWriteGeometry) 
       fOutputManager->WriteGsdvn(name, mother, ndiv, iaxis);
 
-    G4gsdvn(CutName(name), CutName(mother), ndiv, iaxis);
+    G4gsdvn(fGeometryServices->CutName(name), 
+            fGeometryServices->CutName(mother), ndiv, iaxis);
 
     // register name in name map
-    fNameMap.AddName(CutName(name));
+    fNameMap.AddName(fGeometryServices->CutName(name));
 } 
  
  
@@ -635,10 +569,11 @@ void  TG4GeometryManager::Gsdvn2(const char *name, const char *mother,
     if (fWriteGeometry) 
       fOutputManager->WriteGsdvn2(name, mother, ndiv, iaxis, c0i, numed);
 
-    G4gsdvn2(CutName(name),CutName(mother), ndiv, iaxis, c0i, numed);
+    G4gsdvn2(fGeometryServices->CutName(name),
+             fGeometryServices->CutName(mother), ndiv, iaxis, c0i, numed);
 
     // register name in name map
-    fNameMap.AddName(CutName(name));
+    fNameMap.AddName(fGeometryServices->CutName(name));
 } 
  
  
@@ -660,10 +595,11 @@ void  TG4GeometryManager::Gsdvt(const char *name, const char *mother,
     if (fWriteGeometry) 
       fOutputManager->WriteGsdvt(name, mother, step, iaxis, numed, ndvmx);
 
-    G4gsdvt(CutName(name), CutName(mother), step, iaxis, numed, ndvmx);
+    G4gsdvt(fGeometryServices->CutName(name), 
+            fGeometryServices->CutName(mother), step, iaxis, numed, ndvmx);
 
     // register name in name map
-    fNameMap.AddName(CutName(name));
+    fNameMap.AddName(fGeometryServices->CutName(name));
 } 
  
  
@@ -687,10 +623,11 @@ void  TG4GeometryManager::Gsdvt2(const char *name, const char *mother,
     if (fWriteGeometry) 
       fOutputManager->WriteGsdvt2(name, mother, step, iaxis, c0, numed, ndvmx);
 
-    G4gsdvt2(CutName(name), CutName(mother), step, iaxis, c0, numed, ndvmx);
+    G4gsdvt2(fGeometryServices->CutName(name), 
+             fGeometryServices->CutName(mother), step, iaxis, c0, numed, ndvmx);
 
     // register name in name map
-    fNameMap.AddName(CutName(name));
+    fNameMap.AddName(fGeometryServices->CutName(name));
 } 
  
  
@@ -741,10 +678,11 @@ void  TG4GeometryManager::Gspos(const char *vname, Int_t num,
    if (fWriteGeometry) 
      fOutputManager->WriteGspos(vname, num, vmoth, x, y, z, irot, vonly);
 
-   G4gspos(CutName(vname), num, CutName(vmoth), x, y, z, irot, vonly);
+   G4gspos(fGeometryServices->CutName(vname), num,
+           fGeometryServices->CutName(vmoth), x, y, z, irot, vonly);
 
    // register name in name map
-   fNameMap.AddName(CutName(vname));
+   fNameMap.AddName(fGeometryServices->CutName(vname));
 } 
  
  
@@ -758,19 +696,20 @@ void  TG4GeometryManager::Gsposp(const char *name, Int_t nr,
 //      NR inside MOTHER, with its parameters UPAR(1..NP)
 // ---
 
-   G4double* parin = CreateG4doubleArray(upar, np); 
+   G4double* parin = fGeometryServices->CreateG4doubleArray(upar, np); 
 
    // write token to the output file
    if (fWriteGeometry) 
      fOutputManager->WriteGsposp(name, nr, mother, x, y, z, irot, konly, parin, np);
 
-   G4gsposp(CutName(name), nr, CutName(mother), x, y, z, irot, konly, 
+   G4gsposp(fGeometryServices->CutName(name), nr, 
+            fGeometryServices->CutName(mother), x, y, z, irot, konly, 
              parin, np);
 
    delete [] parin;
 
    // register name in name map
-   fNameMap.AddName(CutName(name));
+   fNameMap.AddName(fGeometryServices->CutName(name));
 } 
  
  
@@ -788,25 +727,26 @@ Int_t TG4GeometryManager::Gsvolu(const char *name, const char *shape,
 //  It creates a new volume in the JVOLUM data structure.
 // ---  
 
-  G4double* parin = CreateG4doubleArray(upar, npar); 
+  G4double* parin = fGeometryServices->CreateG4doubleArray(upar, npar); 
 
   // write token to the output file
   if (fWriteGeometry) 
     fOutputManager->WriteGsvolu(name, shape, nmed, parin, npar);    
 
-  G4gsvolu(CutName(name), CutName(shape), nmed, parin, npar);
+  G4gsvolu(fGeometryServices->CutName(name), 
+           fGeometryServices->CutName(shape), nmed, parin, npar);
 
   delete [] parin;
   
   // register name in name map
-  fNameMap.AddName(CutName(name));
+  fNameMap.AddName(fGeometryServices->CutName(name));
 
   return 0;
 } 
 
 
-void TG4GeometryManager::WriteEuclid(const char* filnam, const char* topvol,
-         Int_t number, Int_t nlevel)
+void TG4GeometryManager::WriteEuclid(const char* fileName, 
+          const char* topVolName, Int_t number, Int_t nlevel)
 {
 //  Geant3 desription:
 //  ==================
@@ -843,70 +783,18 @@ void TG4GeometryManager::WriteEuclid(const char* filnam, const char* topvol,
 Int_t TG4GeometryManager::VolId(const Text_t* volName) const
 { 
 // Returns the sensitive detector identifier.
-// !! Gives exception in case logical volume is not associated with 
-// a sensitive detector.
 // ---
 
-  G4String g4VolName = CutName(volName);
-  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
-  
-  for (G4int i=0; i<pLVStore->entries(); i++) {
-    G4LogicalVolume* lv = pLVStore->at(i);
-    G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
-  
-    if ((sd) && (sd->GetName()==g4VolName)) {
-      TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd);
-      if (tsd)
-        return tsd->GetID();
-      else {
-        TG4Globals::Exception(
-          "TG4GeometryManager::VolId: Unknown sensitive detector type");
-        return 0;
-      }        
-    }   
-  }
-
-  G4String text = "TG4GeometryManager::VolId: Sensitive detector ";
-  text = text + g4VolName;
-  text = text + " is not defined.\n"; 
-  text = text + "    Set /alDet/setAllSensitive true in PreInit.";
-  TG4Globals::Exception(text);
-  return 0;
+  return fGeometryServices->GetVolumeID(volName);
 }
 
 
 const char* TG4GeometryManager::VolName(Int_t id) const
 {
 // Returns the name of the sensitive detector with the given identifier.
-// !! Gives exception in case logical volume is not associated with 
-// a sensitive detector.
 // ---
 
-  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
-  
-  for (G4int i=0; i<pLVStore->entries(); i++) {
-    G4LogicalVolume* lv = pLVStore->at(i);
-    G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
-    
-    if (sd) {
-      G4int sdID;
-      TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd);
-      if (tsd)
-        sdID = tsd->GetID();
-      else {
-        TG4Globals::Exception(
-          "TG4GeometryManager::VolId: Unknown sensitive detector type");
-        return 0;
-      }   
-      if (sdID == id) return sd->GetName();
-    }  
-  }
-
-  G4String text = "TG4GeometryManager::VolName:\n";
-  text = text + "    Sensitive detector with given id is not defined. \n";
-  text = text + "    Set /alDet/setAllSensitive true in PreInit.";
-  TG4Globals::Exception(text);
-  return "";                    
+  return fGeometryServices->GetVolumeName(id);
 }
 
 
@@ -915,22 +803,19 @@ Int_t TG4GeometryManager::NofVolumes() const
 // Returns the total number of sensitive detectors.
 // ---
 
-  return NofSensitiveDetectors();
+  return fGeometryServices->NofSensitiveDetectors();
 }
 
  
-void TG4GeometryManager::ReadG3Geometry(G4String filePath)
+Int_t TG4GeometryManager::VolId2Mate(Int_t volumeId)  const
 {
-// Processes g3calls.dat file and fills G3 tables.
+// Return the material number for a given volume id
 // ---
 
-  // add verbose
-  G4cout << "Reading the call list file " << filePath << "..." << endl;
-  G3CLRead(filePath, NULL);
-  G4cout << "Call list file read completed. Build geometry" << endl;
+  return fGeometryServices->GetMediumId(volumeId);                      
 }
-
  
+
 //=============================================================================
 //
 // public methods - Geant4 only
@@ -948,9 +833,6 @@ G4VPhysicalVolume* TG4GeometryManager::CreateG4Geometry()
   // set the first entry in the G3Vol table
   Ggclos();
   G3VolTableEntry* first = G3Vol.GetFirstVTE();
-  
-  // close g3calls.dat
-  if (fWriteGeometry) fOutputManager->CloseFile();  
 
   // create G4 geometry
   G3toG4BuildTree(first,0);  
@@ -960,9 +842,11 @@ G4VPhysicalVolume* TG4GeometryManager::CreateG4Geometry()
 
   // print G4 geometry statistics
   G4cout << "G4 Stat: instantiated " 
-         << NofG4LogicalVolumes()  << " logical volumes \n"
+         << fGeometryServices->NofG4LogicalVolumes()  
+        << " logical volumes \n"
         << "                      " 
-        << NofG4PhysicalVolumes() << " physical volumes" << endl;
+        << fGeometryServices->NofG4PhysicalVolumes() 
+        << " physical volumes" << G4endl;
 
   // position the first entry 
   // (in Geant3 the top volume cannot be positioned)
@@ -976,6 +860,18 @@ G4VPhysicalVolume* TG4GeometryManager::CreateG4Geometry()
 }
 
  
+void TG4GeometryManager::ReadG3Geometry(G4String filePath)
+{
+// Processes g3calls.dat file and fills G3 tables.
+// ---
+
+  // add verbose
+  G4cout << "Reading the call list file " << filePath << "..." << G4endl;
+  G3CLRead(filePath, NULL);
+  G4cout << "Call list file read completed. Build geometry" << G4endl;
+}
+
 void TG4GeometryManager::UseG3TrackingMediaLimits()
 {
 // Sets fUseG3TMLimits option.
@@ -1027,9 +923,6 @@ void TG4GeometryManager::ClearG3TablesFinal()
 // (the top volume is removed from the vol table)
 // ---
 
-  // fill medium id vector
-  FillMediumIdVector();
-
   G3Med.Clear();
   G3Vol.Clear();  
 
@@ -1048,6 +941,15 @@ void TG4GeometryManager::OpenOutFile(G4String filePath)
 }
 
  
+void TG4GeometryManager::CloseOutFile()
+{ 
+// Closes output file.
+// ---
+
+  fOutputManager->CloseFile();
+}
+
 void TG4GeometryManager::PrintNameMap()
 {
 // Prints the map of volumes names to second names.
@@ -1073,158 +975,3 @@ void TG4GeometryManager::SetMapSecond(const G4String& name)
 
   fNameMap.SetSecond(name);
 }
-
-
-Int_t TG4GeometryManager::NofG3Volumes() const
-{
-// Returns the total number of logical volumes corresponding
-// to G3 volumes. (
-// The logical volume that were created by Gsposp method 
-// with a generic name (name_copyNo) are NOT included.
-// ---
-
-  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
-
-  G4int counter = 0;  
-  for (G4int i=0; i<pLVStore->entries(); i++) {
-    G4LogicalVolume* lv = (*pLVStore)[i];
-    if (IsG3Volume(lv->GetName())) counter++;
-  }
-  
-  return counter;  
-}
-
-
-Int_t TG4GeometryManager::NofG4LogicalVolumes() const
-{
-// Returns the total number of logical volumes in the geometry.
-// ---
-
-  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
-  return pLVStore->entries();
-}
-
-
-Int_t TG4GeometryManager::NofG4PhysicalVolumes() const
-{
-// Returns the total number of physical volumes in the geometry.
-// ---
-
-  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
-
-  G4int counter = 0;
-  for (G4int i=0; i<pLVStore->entries(); i++) {
-    counter += ((*pLVStore)[i])->GetNoDaughters();
-  }
-  
-  return counter;  
-}
-
-
-Int_t TG4GeometryManager::NofSensitiveDetectors() const
-{
-// Returns the total number of sensitive detectors.
-// ---
-
-  return TG4VSensitiveDetector::GetTotalNofSensitiveDetectors();
-}
-
-G4bool TG4GeometryManager::IsG3Volume(G4String lvName) const
-{
-// Returns true if the logical volume of given volumeName
-// was not created by Gsposp method with a generic name 
-// (name_copyNo).
-// ---
-
-  if (lvName.contains(gSeparator))
-    return false;  
-  else
-    return true;   
-}
-
-void TG4GeometryManager::G4ToG3VolumeName(G4String& name) const
-{
-// Cuts _copyNo extension added to logical volume name in case 
-// the logical volume was created by Gsposp method.
-// ---
-
-  if (name.contains(gSeparator)) 
-  name = name(0,name.first(gSeparator));
-}
-
-const G4String& TG4GeometryManager::GetMapSecond(const G4String& name)
-{ 
-// Returns the second string associated with the name in
-// the name map.
-// ---
-
-  return fNameMap.GetSecond(name); 
-}
-
-G4int TG4GeometryManager::GetMediumId(G4Material* material) const
-{
-// Returns the second index for materials (having its origin in
-// G4 tracking media concept)
-// ---
-
-  return fMediumIdVector[material->GetIndex()];
-}  
-
-
-G4double TG4GeometryManager::GetEffA(G4Material* material) const
-{
-// Returns A or effective A=sum(pi*Ai) (if compound/mixture)
-// of given material.
-// ---
-
-  G4double a = 0.;
-  G4int nofElements = material->GetNumberOfElements();
-  if (nofElements > 1) {
-    G4String text = "Effective A for material mixture (";
-    text = text + material->GetName();
-    text = text + ") is used.";
-    //TG4Globals::Warning(text);
-
-    for (G4int i=0; i<nofElements; i++) {
-      G4double aOfElement = material->GetElement(i)->GetA();
-      G4double massFraction = material->GetFractionVector()[i];      
-      a += aOfElement*massFraction /(TG3Units::AtomicWeight());
-    }
-  }
-  else { 
-    a = material->GetA();
-    a /= TG3Units::AtomicWeight();
-  }
-  return a;
-}
-
-
-G4double TG4GeometryManager::GetEffZ(G4Material* material) const
-{
-// Returns Z or effective Z=sum(pi*Zi) (if compound/mixture)
-// of given material.
-// ---
-
-  G4double z = 0.;
-  G4int nofElements = material->GetNumberOfElements();
-  if (nofElements > 1) {
-    G4String text = "Effective Z for material mixture (";
-    text = text + material->GetName();
-    text = text + ") is used.";
-    //TG4Globals::Warning(text);
-
-    for (G4int i=0; i<nofElements; i++) {
-      G4double zOfElement = material->GetElement(i)->GetZ();
-      G4double massFraction = material->GetFractionVector()[i];
-      z += zOfElement*massFraction;
-    }
-  }
-  else { 
-    z = material->GetZ(); 
-  }  
-  return z;
-}