#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>
#include <G3MedTable.hh>
#include <G3SensVolVector.hh>
-#include <G4SDManager.hh>
#include <G4VSensitiveDetector.hh>
#include <G4LogicalVolumeStore.hh>
#include <G4PVPlacement.hh>
#include <G4MaterialPropertiesTable.hh>
#include <G4Element.hh>
-#include <math.h>
-#include <ctype.h>
-
// extern global method from g3tog4
void G3CLRead(G4String &, char *);
fOutputManager = new TG4GeometryOutputManager();
+ fGeometryServices = new TG4GeometryServices(&fMediumIdVector, &fNameMap);
+
fgInstance = this;
// instantiate the default element table
TG4GeometryManager::~TG4GeometryManager() {
//
delete fOutputManager;
+ delete fGeometryServices;
}
//==================================================================== =========
//=============================================================================
-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
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." << G4endl;
}
-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
// 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);
}
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 "
+ G4cout << "TG4GeometryManager::GstparControl: new TG4Limits() for medium"
<< itmed << " has been created." << G4endl;
}
// set parameter
- tg4Limits->SetG3Flag(par, parval);
+ tg4Limits->SetG3Control(par, parval);
}
// ---
kmat = ++fMaterialCounter;
- G4double* bufin = CreateG4doubleArray(buf, nwbuf);
+ G4double* bufin = fGeometryServices->CreateG4doubleArray(buf, nwbuf);
// write token to the output file
if (fWriteGeometry)
// ---
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;
// 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.
}
-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 << G4endl;
-
- // 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.
// !! 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.;
// 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
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.";
}
-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);
}
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));
}
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));
}
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));
}
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));
}
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));
}
// 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));
}
// 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;
}
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);
}
// 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 << "..." << G4endl;
- G3CLRead(filePath, NULL);
- G4cout << "Call list file read completed. Build geometry" << G4endl;
+ return fGeometryServices->GetMediumId(volumeId);
}
-
+
//=============================================================================
//
// public methods - Geant4 only
// print G4 geometry statistics
G4cout << "G4 Stat: instantiated "
- << NofG4LogicalVolumes() << " logical volumes \n"
+ << fGeometryServices->NofG4LogicalVolumes()
+ << " logical volumes \n"
<< " "
- << NofG4PhysicalVolumes() << " physical volumes" << G4endl;
+ << fGeometryServices->NofG4PhysicalVolumes()
+ << " physical volumes" << G4endl;
// position the first entry
// (in Geant3 the top volume cannot be positioned)
}
+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.
// (the top volume is removed from the vol table)
// ---
- // fill medium id vector
- FillMediumIdVector();
-
G3Med.Clear();
G3Vol.Clear();
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;
-}