// $Id$
// Category: geometry
//
-// C++ interface to Geant3 basic routines
-// for building Geant4 geometry
+// Author: V. Berejnoi, I. Hrivnacova
//
-// by V. Berejnoi, 25.2.1999
+// Class TG4GeometryManager
+// ------------------------
+// See the class description in the header file.
+// C++ interface to Geant3 basic routines for building Geant4 geometry
+// by V. Berejnoi, 25.2.1999;
// materials, tracking media support
-// added by I.Hrivnacova, 27.5.1999
+// added by I.Hrivnacova, 27.5.1999.
#include "TG4GeometryManager.h"
#include "TG4GeometryOutputManager.h"
-#include "TG4PhysicsManager.h"
-#include "TG4VSensitiveDetector.h"
+#include "TG4GeometryServices.h"
#include "TG4Limits.h"
+#include "TG4G3Units.h"
+#include "TG4G3CutVector.h"
+#include "TG4G3ControlVector.h"
#include "TG4Globals.h"
-#include "TG3Units.h"
#include <G3toG4.hh>
+#include <G3toG4MANY.hh>
#include <G3toG4BuildTree.hh>
#include <G3VolTable.hh>
#include <G3RotTable.hh>
#include <G3MedTable.hh>
#include <G3SensVolVector.hh>
-#include <G4SDManager.hh>
-#include <G4VSensitiveDetector.hh>
#include <G4LogicalVolumeStore.hh>
#include <G4PVPlacement.hh>
#include <G4Material.hh>
#include <G4MaterialPropertiesTable.hh>
#include <G4Element.hh>
-#include <math.h>
-#include <ctype.h>
-
// extern global method from g3tog4
void G3CLRead(G4String &, char *);
TG4GeometryManager* TG4GeometryManager::fgInstance = 0;
+const G4double TG4GeometryManager::fgLimitDensity = 0.001*(g/cm3);
+const G4double TG4GeometryManager::fgMaxStep = 10*cm;
+//_____________________________________________________________________________
TG4GeometryManager::TG4GeometryManager()
- : fMediumCounter(0),
+ : TG4Verbose("geometryManager"),
+ fMediumCounter(0),
fMaterialCounter(0),
fMatrixCounter(0),
fUseG3TMLimits(false),
"TG4GeometryManager: attempt to create two instances of singleton.");
}
- fOutputManager = new TG4GeometryOutputManager();
+ fOutputManager
+ = new TG4GeometryOutputManager();
+
+ fGeometryServices
+ = new TG4GeometryServices(&fMediumMap, &fNameMap);
fgInstance = this;
//TG4ElementTable::Instance();
}
-TG4GeometryManager::TG4GeometryManager(const TG4GeometryManager& right) {
+//_____________________________________________________________________________
+TG4GeometryManager::TG4GeometryManager(const TG4GeometryManager& right)
+ : TG4Verbose("geometryManager") {
//
TG4Globals::Exception(
"Attempt to copy TG4GeometryManager singleton.");
}
+//_____________________________________________________________________________
TG4GeometryManager::~TG4GeometryManager() {
//
delete fOutputManager;
+ delete fGeometryServices;
}
-//==================================================================== =========
+//=============================================================================
//
// operators
//
-//==================================================================== =========
+//=============================================================================
+
+//_____________________________________________________________________________
TG4GeometryManager&
TG4GeometryManager::operator=(const TG4GeometryManager& right)
{
// private methods
//
//=============================================================================
-
-
-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::FillMediumMap()
{
-// Sets special tracking medium parameter.
-// It is applied to all logical volumes that use the specified
-// tracking medium.
+// Maps G3 tracking medium IDs to volumes names.
// ---
- // get medium from table
- G3MedTableEntry* medium = G3Med.get(itmed);
- if (!medium) {
- G4String text = "TG4GeometryManager::GstparCut: \n";
- text = text + " Medium not found.";
- G4Exception(text);
- }
- // get/create user limits
- G4UserLimits* limits = medium->GetLimits();
- TG4Limits* tg4Limits;
- if (limits) {
- tg4Limits = dynamic_cast<TG4Limits*> (limits);
- if (!tg4Limits)
- G4Exception("TG4GeometryManager::GstparCut: Wrong limits type.");
- }
- else {
- tg4Limits = new TG4Limits();
- medium->SetLimits(tg4Limits);
- // add verbose
- G4cout << "TG4GeometryManager::GstparCut: new TG4Limits() for medium "
- << itmed << " has been created." << endl;
- }
- // set parameter
- tg4Limits->SetG3Cut(par, parval*GeV);
-}
-
-
-void TG4GeometryManager::GstparFlag(G4int itmed, TG3Flag par, G4double parval)
-{
-// Sets special tracking medium parameter.
-// It is applied to all logical volumes that use the specified
-// tracking medium.
-// ---
+ static G4int done = 0;
+
+ G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
- // get medium from table
- G3MedTableEntry* medium = G3Med.get(itmed);
- if (!medium) {
- G4String text = "TG4GeometryManager::GstparFlag: \n";
- text = text + " Medium not found.";
- G4Exception(text);
- }
+ for (G4int i=done; i<lvStore->size(); i++) {
+ G4String name = ((*lvStore)[i])->GetName();
+
+ G4String g3Name(name);
+ if (name.find("_refl")) g3Name = g3Name.substr(0, g3Name.find("_refl"));
- // get/create user limits
- G4UserLimits* limits = medium->GetLimits();
- TG4Limits* tg4Limits;
- if (limits) {
- tg4Limits = dynamic_cast<TG4Limits*> (limits);
- if (!tg4Limits)
- G4Exception("TG4GeometryManager::GstparFlag: Wrong limits type.");
- }
- else {
- tg4Limits = new TG4Limits();
- medium->SetLimits(tg4Limits);
- // add verbose
- G4cout << "TG4GeometryManager::GstparFlag: new TG4Limits() for medium "
- << itmed << " has been created." << endl;
+ G4int mediumID = G3Vol.GetVTE(g3Name)->GetNmed();
+ fMediumMap.Add(name, mediumID);
}
- // set parameter
- tg4Limits->SetG3Flag(par, parval);
-}
-
-
-void TG4GeometryManager::FillMediumIdVector()
-{
-// The second index for materials (having its origin in
-// G4 tracking media concept) is stored in a vector of G4int
-// parallel to G4MaterialTable.
-// ---
-
- // initialize vector
- G4int nofMaterials = G4Material::GetNumberOfMaterials();
- G4int i;
- for (i=0; i<nofMaterials; i++)
- fMediumIdVector.push_back(0);
- // fill vector
- for (i=0; i<fMediumCounter; i++) {
- // material index (index in G4Material table)
- G3MedTableEntry* mte = G3Med.get(i+1);
- G4int materialIndex = mte->GetMaterial()->GetIndex();
-
- // medium index (ID of G3MedTableEntry)
- G4int mediumIndex = mte->GetID();
-
- // store medium index in the vector
- fMediumIdVector[materialIndex] = mediumIndex;
- }
-
- // add verbose
- G4cout << "Total nof materials: " << nofMaterials << endl;
- G4cout << "Total nof tracking medias: " << fMediumCounter << endl;
+ done = lvStore->size();
}
//=============================================================================
+//_____________________________________________________________________________
void TG4GeometryManager::Material(Int_t& kmat, const char* name, Float_t a,
Float_t z, Float_t dens, Float_t radl, Float_t absl, Float_t* buf,
Int_t nwbuf)
// ---
kmat = ++fMaterialCounter;
- G4double* bufin = CreateG4doubleArray(buf, nwbuf);
+ G4double* bufin = fGeometryServices->CreateG4doubleArray(buf, nwbuf);
+ G4String namein = fGeometryServices->CutMaterialName(name);
// write token to the output file
if (fWriteGeometry)
- fOutputManager->WriteGsmate(kmat, name, a, z, dens, radl, nwbuf, bufin);
-
- G4gsmate(kmat, name, a, z, dens, radl, nwbuf, bufin);
+ fOutputManager->WriteGsmate(kmat, namein, a, z, dens, radl, nwbuf, bufin);
+
+ // create new material only if it does not yet exist
+ G4Material* material = fGeometryServices->FindMaterial(a, z, dens);
+ if (material) {
+ // verbose
+ if (VerboseLevel() > 1) {
+ G4cout << "!!! Material " << namein << " already exists as "
+ << material->GetName() << G4endl;
+ }
+ G3Mat.put(kmat, material);
+ }
+ else
+ G4gsmate(kmat, namein, a, z, dens, radl, nwbuf, bufin);
+
+ // save the original material name
+ fMaterialNameVector.push_back(namein);
delete [] bufin;
if (nwbuf > 0) {
- G4String matName = name;
G4String text
= "TG4GeometryManager: user defined parameters for material ";
- text = text + matName;
+ text = text + namein;
text = text + " are ignored by Geant4.";
TG4Globals::Warning(text);
}
}
+//_____________________________________________________________________________
void TG4GeometryManager::Mixture(Int_t& kmat, const char *name, Float_t *a,
Float_t *z, Float_t dens, Int_t nlmat, Float_t *wmat)
{
// ---
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);
+ G4String namein = fGeometryServices->CutMaterialName(name);
kmat = ++fMaterialCounter;
// write token to the output file
if (fWriteGeometry)
- fOutputManager->WriteGsmixt(kmat, name, ain, zin, dens, nlmat, wmatin);
+ fOutputManager->WriteGsmixt(kmat, namein, ain, zin, dens, nlmat, wmatin);
+
+ // create new material only if it does not yet exist
+ G4Material* material
+ = fGeometryServices->FindMaterial(ain, zin, dens, nlmat, wmatin);
+ if (material) {
+ // verbose
+ if (VerboseLevel() > 1) {
+ G4cout << "!!! Material " << namein << " already exists as "
+ << material->GetName() << G4endl;
+ }
+ G3Mat.put(kmat, material);
+ }
+ else
+ G4gsmixt(kmat, namein, ain, zin, dens, nlmat, wmatin);
+
+ // save the original material name
+ fMaterialNameVector.push_back(namein);
- G4gsmixt(kmat, name, ain, zin, dens, nlmat, wmatin);
-
// !!! in Geant3:
// After a call with ratios by number (negative number of elements),
// the ratio array is changed to the ratio by weight, so all successive
delete [] wmatin;
}
+//_____________________________________________________________________________
void TG4GeometryManager::Medium(Int_t& kmed, const char *name, Int_t nmat,
Int_t isvol, Int_t ifield, Float_t fieldm, Float_t tmaxfd,
Float_t stemax, Float_t deemax, Float_t epsil,
// 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.
// performed with GHELIX; IFIELD = 3 if tracking performed with GHELX3.
// ---
+ G4String namein = fGeometryServices->CutMaterialName(name);
+
kmed = ++fMediumCounter;
// write token to the output file
epsil, stmin, 0, fUseG3TMLimits);
// !! instead of the nbuf argument the bool fIsG3Default is passed
+ // generate new unique name
+ G4String newName
+ = fGeometryServices
+ ->GenerateLimitsName(kmed, namein, fMaterialNameVector[nmat-1]);
+ fMediumNameVector.push_back(newName);
+
if (nbuf > 0) {
G4String medName = name;
G4String text
}
-void TG4GeometryManager::Matrix(Int_t& krot, Float_t thetaX, Float_t phiX,
- Float_t thetaY, Float_t phiY, Float_t thetaZ, Float_t phiZ)
+//_____________________________________________________________________________
+void TG4GeometryManager::Matrix(Int_t& krot, Double_t thetaX, Double_t phiX,
+ Double_t thetaY, Double_t phiY, Double_t thetaZ, Double_t phiZ)
{
// Creates G4RotationMatrix.
// ---
}
-G4Material* TG4GeometryManager::MixMaterials(G4String name, G4double density,
- TG4StringVector* matNames, TG4doubleVector* matWeights)
+//_____________________________________________________________________________
+void TG4GeometryManager::Matrix(Int_t& krot, Float_t thetaX, Float_t phiX,
+ Float_t thetaY, Float_t phiY, Float_t thetaZ, Float_t phiZ)
{
-// Creates a mixture of selected materials
+// Single precision interface.
// ---
- // 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;
-}
+ //TG4Globals::Warning("TG4GeometryManager::Matrix in single precision.");
+
+ Double_t dthetaX = thetaX;
+ Double_t dphiX = phiX;
+ Double_t dthetaY = thetaY;
+ Double_t dphiY = phiY;
+ Double_t dthetaZ = thetaZ;
+ Double_t dphiZ = phiZ;
+
+ Matrix(krot, dthetaX, dphiX, dthetaY, dphiY, dthetaZ, dphiZ);
+}
+
-
+//_____________________________________________________________________________
void TG4GeometryManager::Ggclos()
-{
+{
// Sets the top VTE in temporary G3 volume table.
// Close geometry output file (if fWriteGeometry is set true).
//
}
+//_____________________________________________________________________________
void TG4GeometryManager::Gfmate(Int_t imat, char *name, Float_t &a,
Float_t &z, Float_t &dens, Float_t &radl, Float_t &absl,
Float_t* ubuf, Int_t& nbuf)
// !! 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.;
}
+//_____________________________________________________________________________
void TG4GeometryManager::Gstpar(Int_t itmed, const char *param,
Float_t parval)
{
-// 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
-// is performed with respect to G3 default values.)
-// When any cut/flag parameter is set in limits
-// the physics manager is locked and the physics setup
-// cannot be changed.
-// Applying this TG4Limits to particles and physical
-// processes is still in development.
-//
-// Geant3 desription:
-// ==================
-// To change the value of cut or mechanism "CHPAR"
-// to a new value PARVAL for tracking medium ITMED
-// The data structure JTMED contains the standard tracking
-// parameters (CUTS and flags to control the physics processes) which
-// are used by default for all tracking media. It is possible to
-// redefine individually with GSTPAR any of these parameters for a
-// given tracking medium.
-// ITMED tracking medium number
-// CHPAR is a character string (variable name)
-// PARVAL must be given as a floating point.
+// Write token to the output file only,
+// the method is performed by TG4PhysicsManager.
// ---
- // write token to the output file
if (fWriteGeometry)
fOutputManager->WriteGstpar(itmed, param, parval);
-
- // get physics setup
- TG4PhysicsManager* physicsManager = TG4PhysicsManager::Instance();
- //TG4CutVector* cutVector = physicsManager->GetCutVector();
- //TG4FlagVector* flagVector = physicsManager->GetFlagVector();
-
- G4String name = CutName(param);
- TG3Cut g3Cut;
- if (physicsManager->CheckCutWithCutVector(name, parval, g3Cut)) {
- GstparCut(itmed, g3Cut, parval);
- physicsManager->Lock();
- }
- else {
- TG3Flag g3Flag;
- if (physicsManager->CheckFlagWithFlagVector(name, parval, g3Flag)) {
- GstparFlag(itmed, g3Flag, parval);
- physicsManager->Lock();
- }
- else if (g3Cut==kNoG3Cuts && g3Flag==kNoG3Flags) {
- G4String text = "TG4GeometryManager::Gstpar:";
- text = text + name;
- text = text + " parameter is not yet implemented.";
- TG4Globals::Warning(text);
- }
- }
}
-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:
// 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
// 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);
}
// set material properties table
material->SetMaterialPropertiesTable(table);
- G4cout << "The tables for UV photon tracking set for "
- << material->GetName() << endl;
+ // verbose
+ if (VerboseLevel() > 0) {
+ G4cout << "The tables for UV photon tracking set for "
+ << 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;
}
+//_____________________________________________________________________________
void TG4GeometryManager::Gsdvn(const char *name, const char *mother,
Int_t ndiv, Int_t iaxis)
{
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));
}
+//_____________________________________________________________________________
void TG4GeometryManager::Gsdvn2(const char *name, const char *mother,
- Int_t ndiv, Int_t iaxis, Float_t c0i, Int_t numed)
+ Int_t ndiv, Int_t iaxis, Double_t c0i, Int_t numed)
{
// Geant3 desription:
// ==================
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));
+}
+
+
+//_____________________________________________________________________________
+void TG4GeometryManager::Gsdvn2(const char *name, const char *mother,
+ Int_t ndiv, Int_t iaxis, Float_t c0i, Int_t numed)
+{
+// Single precision interface.
+// ---
+
+ //TG4Globals::Warning("TG4GeometryManager::Gsdvn2 in single precision.");
+
+ G4double dc0i = c0i;
+
+ Gsdvn2(name, mother, ndiv, iaxis, dc0i, numed);
}
+//_____________________________________________________________________________
void TG4GeometryManager::Gsdvt(const char *name, const char *mother,
- Float_t step, Int_t iaxis, Int_t numed, Int_t ndvmx)
+ Double_t step, Int_t iaxis, Int_t numed, Int_t ndvmx)
{
// Geant3 desription:
// ==================
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));
}
+//_____________________________________________________________________________
+void TG4GeometryManager::Gsdvt(const char *name, const char *mother,
+ Float_t step, Int_t iaxis, Int_t numed, Int_t ndvmx)
+{
+// Single precision interface.
+// ---
+
+ //TG4Globals::Warning("TG4GeometryManager::Gsdvt in single precision.");
+
+ G4double dstep = step;
+
+ Gsdvt(name, mother, dstep, iaxis, numed, ndvmx);
+}
+
+
+//_____________________________________________________________________________
void TG4GeometryManager::Gsdvt2(const char *name, const char *mother,
- Float_t step, Int_t iaxis, Float_t c0, Int_t numed, Int_t ndvmx)
+ Double_t step, Int_t iaxis, Double_t c0, Int_t numed, Int_t ndvmx)
{
// Geant3 desription:
// ==================
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));
}
+//_____________________________________________________________________________
+void TG4GeometryManager::Gsdvt2(const char *name, const char *mother,
+ Float_t step, Int_t iaxis, Float_t c0, Int_t numed, Int_t ndvmx)
+{
+// Single precision interface.
+// ---
+
+ //TG4Globals::Warning("TG4GeometryManager::Gsdvt2 in single precision.");
+
+ G4double dstep = step;
+ G4double dc0 = c0;
+
+ Gsdvt2(name, mother, dstep, iaxis, dc0, numed, ndvmx);
+}
+
+
+//_____________________________________________________________________________
void TG4GeometryManager::Gsord(const char *name, Int_t iax)
{
// No corresponding action in G4.
}
+//_____________________________________________________________________________
void TG4GeometryManager::Gspos(const char *vname, Int_t num,
- const char *vmoth, Float_t x, Float_t y, Float_t z, Int_t irot,
+ const char *vmoth, Double_t x, Double_t y, Double_t z, Int_t irot,
const char *vonly)
{
// Geant3 desription:
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));
+}
+
+
+//_____________________________________________________________________________
+void TG4GeometryManager::Gspos(const char *vname, Int_t num,
+ const char *vmoth, Float_t x, Float_t y, Float_t z, Int_t irot,
+ const char *vonly)
+{
+// Single precision interface.
+// ---
+
+ //TG4Globals::Warning("TG4GeometryManager::Gspos in single precision.");
+
+ G4double dx = x;
+ G4double dy = y;
+ G4double dz = z;
+
+ Gspos(vname, num, vmoth, dx, dy, dz, irot, vonly);
}
+//_____________________________________________________________________________
void TG4GeometryManager::Gsposp(const char *name, Int_t nr,
- const char *mother, Float_t x, Float_t y, Float_t z, Int_t irot,
- const char *konly, Float_t *upar, Int_t np )
+ const char *mother, Double_t x, Double_t y, Double_t z, Int_t irot,
+ const char *konly, Double_t *upar, Int_t np )
{
// Geant3 desription:
// ==================
// NR inside MOTHER, with its parameters UPAR(1..NP)
// ---
- G4double* parin = CreateG4doubleArray(upar, np);
-
// write token to the output file
if (fWriteGeometry)
- fOutputManager->WriteGsposp(name, nr, mother, x, y, z, irot, konly, parin, np);
+ fOutputManager->WriteGsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
- G4gsposp(CutName(name), nr, CutName(mother), x, y, z, irot, konly,
- parin, np);
+ G4gsposp(fGeometryServices->CutName(name), nr,
+ fGeometryServices->CutName(mother), x, y, z, irot, konly,
+ upar, np);
+
+ // register name in name map
+ fNameMap.AddName(fGeometryServices->CutName(name));
+}
+
+
+//_____________________________________________________________________________
+void TG4GeometryManager::Gsposp(const char *name, Int_t nr,
+ const char *mother, Float_t x, Float_t y, Float_t z, Int_t irot,
+ const char *konly, Float_t *upar, Int_t np )
+{
+// Single precision interface.
+// ---
+
+ //TG4Globals::Warning("TG4GeometryManager::Gsposp in single precision.");
+
+ G4double dx = x;
+ G4double dy = y;
+ G4double dz = z;
+ G4double* parin = fGeometryServices->CreateG4doubleArray(upar, np);
+
+ Gsposp(name, nr, mother, dx, dy, dz, irot, konly, parin, np);
delete [] parin;
+}
+
+
+//_____________________________________________________________________________
+void TG4GeometryManager::Gsbool(const char* onlyVolName,
+ const char* manyVolName)
+{
+// Helps for resolving MANY.
+// Specifies the ONLY volume that overlaps with the
+// specified MANY and has to be substracted.
+// ---
- // register name in name map
- fNameMap.AddName(CutName(name));
+ // write token to the output file
+ //if (fWriteGeometry)
+ // fOutputManager->WriteGsbool(onlyVolName, manyVolName);
+
+ G4gsbool(onlyVolName, manyVolName);
}
+//_____________________________________________________________________________
Int_t TG4GeometryManager::Gsvolu(const char *name, const char *shape,
- Int_t nmed, Float_t *upar, Int_t npar)
+ Int_t nmed, Double_t *upar, Int_t npar)
{
// Geant3 desription:
// ==================
// It creates a new volume in the JVOLUM data structure.
// ---
- G4double* parin = 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);
+ fOutputManager->WriteGsvolu(name, shape, nmed, upar, npar);
- delete [] parin;
+ G4gsvolu(fGeometryServices->CutName(name),
+ fGeometryServices->CutName(shape), nmed, upar, npar);
// register name in name map
- fNameMap.AddName(CutName(name));
+ fNameMap.AddName(fGeometryServices->CutName(name));
return 0;
}
+//_____________________________________________________________________________
+Int_t TG4GeometryManager::Gsvolu(const char *name, const char *shape,
+ Int_t nmed, Float_t *upar, Int_t npar)
+{
+// Single precision interface.
+// ---
+
+ //TG4Globals::Warning("TG4GeometryManager::Gsvolu in single precision.");
+
+ G4double* parin = fGeometryServices->CreateG4doubleArray(upar, npar);
+
+ G4int result
+ = Gsvolu(name, shape, nmed, parin, npar);
+
+ delete [] parin;
+
+ return result;
+}
+
+
+//_____________________________________________________________________________
void TG4GeometryManager::WriteEuclid(const char* fileName,
const char* topVolName, Int_t number, Int_t nlevel)
{
}
-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;
-}
-
-
-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 "";
-}
-
-
-Int_t TG4GeometryManager::NofVolumes() const
-{
-// Returns the total number of sensitive detectors.
-// ---
-
- return NofSensitiveDetectors();
-}
-
-
-void TG4GeometryManager::ReadG3Geometry(G4String filePath)
-{
-// Processes g3calls.dat file and fills G3 tables.
-// ---
-
- // add verbose
- G4cout << "Reading the call list file " << filePath << "..." << endl;
- G3CLRead(filePath, NULL);
- G4cout << "Call list file read completed. Build geometry" << endl;
-}
-
-
//=============================================================================
//
// public methods - Geant4 only
//=============================================================================
+//_____________________________________________________________________________
G4VPhysicalVolume* TG4GeometryManager::CreateG4Geometry()
{
// Creates G4 geometry objects according to the G3VolTable
-// and returns the top physical volume in case it was created
-// (return zero otherwise).
+// and returns the world physical volume.
// ---
// set the first entry in the G3Vol table
Ggclos();
G3VolTableEntry* first = G3Vol.GetFirstVTE();
- // close g3calls.dat
- if (fWriteGeometry) fOutputManager->CloseFile();
-
+ // transform MANY to Boolean solids
+ G3toG4MANY(first);
+
// create G4 geometry
G3toG4BuildTree(first,0);
+
+ // fill medium map
+ FillMediumMap();
// print G3 volume table statistics
G3Vol.VTEStat();
// print G4 geometry statistics
- G4cout << "G4 Stat: instantiated "
- << NofG4LogicalVolumes() << " logical volumes \n"
- << " "
- << NofG4PhysicalVolumes() << " physical volumes" << endl;
+ if (VerboseLevel() > 0) {
+ G4cout << "G4 Stat: instantiated "
+ << fGeometryServices->NofG4LogicalVolumes()
+ << " logical volumes \n"
+ << " "
+ << fGeometryServices->NofG4PhysicalVolumes()
+ << " physical volumes" << G4endl;
+ }
// position the first entry
// (in Geant3 the top volume cannot be positioned)
//
- G4VPhysicalVolume* top = 0;
- if (first->GetLV()->GetNoDaughters() == 0) {
- top = new G4PVPlacement(0, G4ThreeVector(), first->GetName(),
- first->GetLV(), 0, false, 0);
+ if (!fGeometryServices->GetWorld()) {
+ G4VPhysicalVolume* world
+ = new G4PVPlacement(0, G4ThreeVector(), first->GetName(),
+ first->GetLV(), 0, false, 0);
+ fGeometryServices->SetWorld(world);
}
- return top;
+ return fGeometryServices->GetWorld();
+}
+
+
+//_____________________________________________________________________________
+void TG4GeometryManager::SetUserLimits(const TG4G3CutVector& cuts,
+ const TG4G3ControlVector& controls) const
+{
+// Sets user limits defined in G3MedTable for all logical volumes.
+// ---
+
+ G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
+
+ for (G4int i=0; i<lvStore->size(); i++) {
+ G4LogicalVolume* lv = (*lvStore)[i];
+
+ // get limits from G3Med
+ G4int mediumIndex = fGeometryServices->GetMediumId(lv);
+ G4UserLimits* limits = G3Med.get(mediumIndex)->GetLimits();
+ TG4Limits* tg4Limits = fGeometryServices->GetLimits(limits);
+
+ // get tracking medium name
+ G4String name = fMediumNameVector[mediumIndex-1];
+
+ if (tg4Limits)
+ tg4Limits->SetName(name);
+ else {
+ tg4Limits = fGeometryServices->FindLimits(name, true);
+ if (!tg4Limits)
+ tg4Limits = new TG4Limits(name, cuts, controls);
+ }
+
+ // limit max step for low density materials (< AIR)
+ if (lv->GetMaterial()->GetDensity() < fgLimitDensity )
+ tg4Limits->SetMaxAllowedStep(fgMaxStep);
+
+ // update controls in limits according to the setup
+ // in the passed vector
+ tg4Limits->Update(controls);
+
+ // set limits to logical volume
+ lv->SetUserLimits(tg4Limits);
+ //NO TG4 lv->SetUserLimits(0);
+ }
+}
+
+//_____________________________________________________________________________
+void TG4GeometryManager::ReadG3Geometry(G4String filePath)
+{
+// Processes g3calls.dat file and fills G3 tables.
+// ---
+
+ // verbose
+ if (VerboseLevel() > 0) {
+ G4cout << "Reading the call list file " << filePath << "..." << G4endl;
+ }
+
+ G3CLRead(filePath, NULL);
+
+ if (VerboseLevel() > 0) {
+ G4cout << "Call list file read completed. Build geometry" << G4endl;
+ }
}
+//_____________________________________________________________________________
void TG4GeometryManager::UseG3TrackingMediaLimits()
{
// Sets fUseG3TMLimits option.
}
+//_____________________________________________________________________________
void TG4GeometryManager::ClearG3Tables()
{
// Clears G3 volumes, materials, rotations(?) tables
G3Vol.PutVTE(keep);
// clear other tables
- G3Mat.Clear();
//G3Rot.Clear();
G3SensVol.clear();
}
+//_____________________________________________________________________________
void TG4GeometryManager::ClearG3TablesFinal()
{
// Clears G3 medias and volumes tables
// (the top volume is removed from the vol table)
// ---
- // fill medium id vector
- FillMediumIdVector();
-
+ G3Mat.Clear();
G3Med.Clear();
G3Vol.Clear();
-
- // reset medium counter
- //fMaterialCounter = 0;
- fMediumCounter = 0;
}
+//_____________________________________________________________________________
void TG4GeometryManager::OpenOutFile(G4String filePath)
{
// Opens output file.
}
-void TG4GeometryManager::PrintNameMap()
-{
-// Prints the map of volumes names to second names.
+//_____________________________________________________________________________
+void TG4GeometryManager::CloseOutFile()
+{
+// Closes output file.
// ---
- fNameMap.PrintAll();
+ fOutputManager->CloseFile();
}
+//_____________________________________________________________________________
void TG4GeometryManager::SetWriteGeometry(G4bool writeGeometry)
{
// Controls geometry output.
}
+//_____________________________________________________________________________
void TG4GeometryManager::SetMapSecond(const G4String& name)
{
// Sets the second name for the map of volumes names.
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;
-}