25#include <G4Element.hh>
26#include <G4LogicalVolume.hh>
27#include <G4LogicalVolumeStore.hh>
28#include <G4Material.hh>
29#include <G4MaterialPropertiesTable.hh>
30#include <G4MaterialPropertyVector.hh>
31#include <G4PhysicalVolumeStore.hh>
32#include <G4UserLimits.hh>
33#include <G4VPhysicalVolume.hh>
35#include <G3EleTable.hh>
40#include <TGeoMatrix.h>
43#include "RootGM/volumes/Placement.h"
48#include <G4SystemOfUnits.hh>
76 "Cannot create two instances of singleton.");
107 if (G4StrUtil::contains(lvName, gSeparator))
115 G4double , G4double z,
const G4Element* element)
const
121 G4double ze = element->GetZ();
127 ax = 1.01 * g / mole;
150 G4double , G4double ,
const G4Element* )
const
161 G4int nofElements, G4double density,
const G4Material* material)
const
167 G4int ne = material->GetNumberOfElements();
170 G4double diff = std::abs(density - dm) / (density + dm) * 2.;
180 G4int nmat, G4double* a, G4double* wmat)
const
186 G4double* weight =
new G4double[abs(nmat)];
191 for (i = 0; i < abs(nmat); i++) {
193 aMol += wmat[i] * a[i];
197 "Total molecular weight = 0.");
199 for (i = 0; i < abs(nmat); i++) {
201 weight[i] = wmat[i] * a[i] / aMol;
205 for (G4int j = 0; j < nmat; j++) weight[j] = wmat[j];
227 if (!RootGM::Placement::GetIncludeAssembliesInNames())
return;
228 const char prefix = RootGM::Placement::GetNamePrefix();
229 const char separator = RootGM::Placement::GetNameSeparator();
231 const G4PhysicalVolumeStore* store = G4PhysicalVolumeStore::GetInstance();
233 for (G4VPhysicalVolume* pv : *store)
234 maxId = std::max(maxId, pv->GetInstanceID());
235 if (maxId < 0)
return;
238 for (G4VPhysicalVolume* pv : *store) {
239 const G4String& name = pv->GetName();
240 if (name.size() < 2 || name[0] != prefix)
continue;
243 for (std::size_t start = 1; start <= name.size();) {
244 const std::size_t sep = name.find(separator, start);
245 levels.
fNames.push_back(name.substr(
246 start, sep == G4String::npos ? G4String::npos : sep - start));
248 if (sep == G4String::npos)
break;
251 if (levels.
fNames.size() < 2)
continue;
254 for (std::size_t i = 0; i + 1 < levels.
fNames.size(); ++i) {
255 G4String& part = levels.
fNames[i];
256 const std::size_t us = part.rfind(
'_');
257 if (us == G4String::npos || us + 1 >= part.size())
continue;
258 if (part.find_first_not_of(
"0123456789", us + 1) != G4String::npos)
continue;
259 levels.
fCopyNos[i] = std::atoi(part.c_str() + us + 1);
266 G4cout <<
"### AssemblyLevels constructed." << G4endl;
273 const G4VPhysicalVolume* pv)
const
281 const G4int
id = pv->GetInstanceID();
289 Float_t* array, G4int size, G4bool copyValues)
const
294 G4double* doubleArray;
296 doubleArray =
new G4double[size];
298 for (G4int i = 0; i < size; i++) doubleArray[i] = array[i];
309 Double_t* array, G4int size, G4bool copyValues)
const
314 G4double* doubleArray;
316 doubleArray =
new G4double[size];
318 for (G4int i = 0; i < size; i++) doubleArray[i] = array[i];
332 G4String cutName = name;
333 G4int i = cutName.length();
334 while (cutName[--i] ==
' ') cutName = cutName.substr(0, i);
344 G4String cutName = name;
345 cutName = cutName.substr(0, cutName.find(
'$'));
352 const G4String& volumePath, G4String& volName, G4int& copyNo)
const
356 G4String path(volumePath);
358 G4int npos1 = path.find(
'/');
359 G4int npos2 = path.find(
'_');
360 G4int npos3 = path.find(
'/', 2);
361 if (npos3 < 0) npos3 = path.length();
363 volName = path.substr(npos1 + 1, npos2 - npos1 - 1);
364 G4String copyNoStr = path.substr(npos2 + 1, npos3 - npos2);
365 std::istringstream in(copyNoStr);
368 return path.substr(npos3, path.length() - npos3);
378 if (
fIsG3toG4 && G4StrUtil::contains(name, gSeparator)) {
379 fgBuffer = name.substr(0, name.find(gSeparator));
392 EMCOpSurfaceModel model)
const
398 case kGlisur:
return glisur;
399 case kUnified:
return unified;
400 case kLUT:
return LUT;
401 case kDAVIS:
return DAVIS;
402 case kdichroic:
return dichroic;
406 "Unknown optical surface model, return Glisur.");
418 case kDielectric_metal:
return dielectric_metal;
419 case kDielectric_dielectric:
return dielectric_dielectric;
420 case kDielectric_LUT:
return dielectric_LUT;
421 case kDielectric_LUTDAVIS:
return dielectric_LUTDAVIS;
422 case kDielectric_dichroic:
return dielectric_dichroic;
423 case kFirsov:
return firsov;
424 case kXray:
return x_ray;
428 "Unknown optical surface type, return dielectric_metal.");
429 return dielectric_metal;
435 EMCOpSurfaceFinish finish)
const
441 case kPolished:
return polished;
442 case kPolishedfrontpainted:
return polishedfrontpainted;
443 case kPolishedbackpainted:
return polishedbackpainted;
445 case kGround:
return ground;
446 case kGroundfrontpainted:
return groundfrontpainted;
447 case kGroundbackpainted:
return groundbackpainted;
449 case kPolishedlumirrorair:
return polishedlumirrorair;
450 case kPolishedlumirrorglue:
return polishedlumirrorglue;
452 case kPolishedair:
return polishedair;
453 case kPolishedteflonair:
return polishedteflonair;
454 case kPolishedtioair:
return polishedtioair;
455 case kPolishedtyvekair:
return polishedtyvekair;
456 case kPolishedvm2000air:
return polishedvm2000air;
457 case kPolishedvm2000glue:
return polishedvm2000glue;
459 case kEtchedlumirrorair:
return etchedlumirrorair;
460 case kEtchedlumirrorglue:
return etchedlumirrorglue;
461 case kEtchedair:
return etchedair;
462 case kEtchedteflonair:
return etchedteflonair;
463 case kEtchedtioair:
return etchedtioair;
464 case kEtchedtyvekair:
return etchedtyvekair;
465 case kEtchedvm2000air:
return etchedvm2000air;
466 case kEtchedvm2000glue:
return etchedvm2000glue;
467 case kGroundlumirrorair:
return groundlumirrorair;
468 case kGroundlumirrorglue:
return groundlumirrorglue;
469 case kGroundair:
return groundair;
470 case kGroundteflonair:
return groundteflonair;
471 case kGroundtioair:
return groundtioair;
472 case kGroundtyvekair:
return groundtyvekair;
473 case kGroundvm2000air:
return groundvm2000air;
474 case kGroundvm2000glue:
return groundvm2000glue;
476 case kRough_LUT:
return Rough_LUT;
477 case kRoughTeflon_LUT:
return RoughTeflon_LUT;
478 case kRoughESR_LUT:
return RoughESR_LUT;
479 case kRoughESRGrease_LUT:
return RoughESRGrease_LUT;
481 case kPolished_LUT:
return Polished_LUT;
482 case kPolishedTeflon_LUT:
return PolishedTeflon_LUT;
483 case kPolishedESR_LUT:
return PolishedESR_LUT;
484 case kPolishedESRGrease_LUT:
return PolishedESRGrease_LUT;
486 case kDetector_LUT:
return Detector_LUT;
490 "Unknown optical surface finish, return polished.");
497 const G4Transform3D& transform, TGeoHMatrix& matrix)
const
501 Double_t* translation =
new Double_t[3];
502 Double_t* rotation =
new Double_t[9];
503 for (G4int i = 0; i < 3; i++)
504 for (G4int j = 0; j < 3; j++) {
505 rotation[i * 3 + j] = transform(i, j);
506 translation[i] = transform(i, 3) / cm;
508 matrix.SetTranslation(translation);
509 matrix.SetRotation(rotation);
510 delete[] translation;
521 G4int nofMaterials = matNames.size();
522 if (nofMaterials != G4int(matWeights.size())) {
524 "Different number of material names and weigths.");
528 G4cout <<
"Nof of materials to be mixed: " << nofMaterials << G4endl;
532 std::vector<G4Material*> matVector;
534 for (im = 0; im < nofMaterials; im++) {
536 G4Material* material = G4Material::GetMaterial(matNames[im]);
537 matVector.push_back(material);
541 G4Material* mixture =
new G4Material(name, density, nofMaterials);
542 for (im = 0; im < nofMaterials; im++) {
543 G4Material* material = matVector[im];
544 G4double fraction = matWeights[im];
545 mixture->AddMaterial(material, fraction);
558 if (limits) limits->
Print();
571 G4cout << volumeName <<
" ";
575 G4cout <<
"has not the limits set." << G4endl;
586 G4cout <<
" GEANT4 Geometry statistics: " << G4endl <<
" "
589 <<
" physical volumes" << G4endl <<
" " << std::setw(5)
590 << G4Material::GetNumberOfMaterials() <<
" materials" << G4endl
592 <<
" user limits" << G4endl;
602 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
604 G4cout <<
"Logical volume store: " << G4endl;
606 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
608 G4LogicalVolume* lv = (*lvStore)[i];
610 void* address = lv->GetMaterial();
611 G4cout <<
"Logical volume: " << G4endl;
612 G4cout <<
" " << std::setw(5) << i <<
" " << lv <<
" " << lv->GetName()
613 <<
" " << std::setw(5) << lv->GetNoDaughters() <<
" daughters"
614 <<
" limits: " << lv->GetUserLimits()
615 <<
" material: " << lv->GetMaterial()->GetName() <<
" " << address
618 for (
size_t j = 0; j < lv->GetNoDaughters(); j++) {
619 void* addressd = lv->GetDaughter(j)->GetLogicalVolume()->GetMaterial();
620 G4cout <<
" Daughter: " << std::setw(5) << j <<
" "
621 << lv->GetDaughter(j) <<
" " << lv->GetDaughter(j)->GetName()
622 <<
" of LV: " << lv->GetDaughter(j)->GetLogicalVolume() <<
" "
623 << lv->GetDaughter(j)->GetLogicalVolume()->GetName()
624 <<
" copy no: " << lv->GetDaughter(j)->GetCopyNo()
626 << lv->GetDaughter(j)->GetLogicalVolume()->GetMaterial()->GetName()
627 <<
" " << addressd << G4endl;
637 G4PhysicalVolumeStore* pvStore = G4PhysicalVolumeStore::GetInstance();
639 for (G4int i = 0; i < G4int(pvStore->size()); i++) {
640 G4VPhysicalVolume* pv = (*pvStore)[i];
641 G4cout << i <<
"th volume name=" << pv->GetName()
643 <<
" copyNo=" << pv->GetCopyNo() << G4endl;
652 const G4ElementTable* elementTable = G4Element::GetElementTable();
654 G4cout <<
"Element table: " << G4endl;
656 for (G4int i = 0; i < G4int(elementTable->size()); i++) {
658 G4Element* element = (*elementTable)[i];
659 G4cout <<
" " << std::setw(5) << i <<
"th element:"
660 <<
" " << element << G4endl;
670 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
681 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
682 for (G4int i = 0; i < G4int(matTable->size()); i++) {
683 if ((*matTable)[i] && (*matTable)[i]->GetMaterialPropertiesTable()) {
685 G4cout << (*matTable)[i]->GetName()
686 <<
" material properties table: " << G4endl;
687 (*matTable)[i]->GetMaterialPropertiesTable()->DumpTable();
693 TG4OpSurfaceMap::const_iterator it;
695 if (it->second && it->second->GetMaterialPropertiesTable()) {
698 <<
" optical surface material properties table: " << G4endl;
699 it->second->GetMaterialPropertiesTable()->DumpTable();
721 TString(cutName.c_str()) +
" not defined.");
725 G4cout <<
"Cut " << cutName << G4endl;
726 G4cout <<
"Medium ID"
728 <<
"cutValue(MeV)" << G4endl;
729 for (G4int i = 0; i <
fMediumMap->GetNofMedia(); i++) {
734 G4cout << i + 1 <<
" " << cutValue << G4endl;
752 TString(controlName.c_str()) +
" not defined.");
756 G4cout <<
"Control " << controlName << G4endl;
757 G4cout <<
"Medium ID"
759 <<
"controlValue" << G4endl;
760 for (G4int i = 0; i <
fMediumMap->GetNofMedia(); i++) {
766 G4cout << i + 1 <<
" " << controlValue << G4endl;
777 gSeparator = separator;
796 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
799 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
800 G4LogicalVolume* lv = (*lvStore)[i];
812 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
813 return lvStore->size();
821 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
824 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
825 counter += ((*lvStore)[i])->GetNoDaughters();
836 if (!limits)
return 0;
841 "TG4GeometryServices",
"GetLimits(.)",
"Wrong limits type");
855 if (!limits)
return 0;
859 if (tg4Limits)
return tg4Limits;
864 tg4Limits =
new TG4Limits(*limits, cuts, controls);
870 "TG4GeometryServices",
"GetLimits(..)",
"Wrong limits type.");
876 const G4String& name, G4bool silent)
const
880 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
882 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
883 G4LogicalVolume* lv = (*lvStore)[i];
884 if (lv->GetName() == name)
return lv;
889 "Logical volume " + TString(name) +
" not found.");
896 const G4String& name, G4int copyNo, G4bool silent)
const
901 G4PhysicalVolumeStore* pvStore = G4PhysicalVolumeStore::GetInstance();
903 for (G4int i = 0; i < G4int(pvStore->size()); i++) {
904 G4VPhysicalVolume* pv = (*pvStore)[i];
910 if (
UserVolumeName(pv->GetName()) == name && pv->GetCopyNo() == copyNo)
916 "Physical volume " + TString(name) +
" not found.");
923 const G4String& name, G4int copyNo, G4LogicalVolume* mlv, G4bool silent)
const
928 for (
size_t i = 0; i < mlv->GetNoDaughters(); i++) {
929 G4VPhysicalVolume* dpv = mlv->GetDaughter(i);
930 if (
UserVolumeName(dpv->GetName()) == name && dpv->GetCopyNo() == copyNo)
936 "Physical volume " + TString(name) +
" not found.");
943 const G4String& name, G4bool silent)
const
947 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
949 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
950 G4LogicalVolume* lv = (*lvStore)[i];
952 if (limits && limits->
GetName() == name)
return limits;
957 "Limits " + TString(name) +
" not found.");
964 const G4String& name, G4bool silent)
const
969 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
971 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
972 G4LogicalVolume* lv = (*lvStore)[i];
973 if (!
dynamic_cast<TG4Limits*
>(lv->GetUserLimits())) {
977 if (limits && limits->
GetName() == name)
return limits;
982 "Limits " + TString(name) +
" not found.");
989 const G4Material* material, G4bool silent)
const
995 if (!medium)
return 0;
1008 if (!medium)
return 0;
1010 return medium->
GetID();
1020 G4int nofElements = material->GetNumberOfElements();
1021 if (nofElements > 1) {
1027 for (G4int i = 0; i < nofElements; i++) {
1028 G4double aOfElement = material->GetElement(i)->GetA();
1029 G4double massFraction = material->GetFractionVector()[i];
1034 a = material->GetA();
1047 G4int nofElements = material->GetNumberOfElements();
1048 if (nofElements > 1) {
1054 for (G4int i = 0; i < nofElements; i++) {
1055 G4double zOfElement = material->GetElement(i)->GetZ();
1056 G4double massFraction = material->GetFractionVector()[i];
1057 z += zOfElement * massFraction;
1061 z = material->GetZ();
1068 G4double a, G4double z, G4double density)
const
1073 const G4MaterialTable* kpMatTable = G4Material::GetMaterialTable();
1075 for (G4int i = 0; i < G4int(G4Material::GetNumberOfMaterials()); i++) {
1077 G4Material* material = (*kpMatTable)[i];
1090 G4double* a, G4double* z, G4double density, G4int nmat, G4double* wmat)
const
1098 G4Material* found = 0;
1099 for (G4int i = 0; i < G4int(G4Material::GetNumberOfMaterials()); i++) {
1101 G4Material* material = (*G4Material::GetMaterialTable())[i];
1102 G4int nofElements = material->GetNumberOfElements();
1107 G4bool equal =
true;
1108 for (G4int ie = 0; ie < nofElements; ie++) {
1110 G4double we = (material->GetFractionVector())[ie];
Definition of the TG4G3ControlVector class.
Definition of the TG4G3Units class.
Definition of the TG4GeometryServices class.
Definition of the TG4Globals class and basic container types.
Definition of the TG4IntMap class.
Definition of the TG4Limits class.
Definition of the TG4MediumMap class.
Definition of the TG4Medium class.
Definition of the TG4NameMap class.
Vector of control process values with convenient set/get methods.
static TG4G3Control GetControl(const G4String &controlName)
Vector of kinetic energy cut values with convenient set/get methods.
static TG4G3Cut GetCut(const G4String &cutName)
static G4double AtomicWeight()
static G4double InverseMassDensity()
static G4double InverseAtomicWeight()
Services for accessing to Geant4 geometry.
void PrintControls(const G4String &controlName) const
G4String CutVolumePath(const G4String &volumePath, G4String &volName, G4int ©No) const
void PrintLogicalVolumeStore() const
static const G4double fgkDensityTolerance
density tolerance (percentual)
static TG4GeometryServices * fgInstance
this instance
TG4OpSurfaceMap * fOpSurfaceMap
map of optical surfaces names to their objects
void PrintPhysicalVolumeStore() const
TG4MediumMap * fMediumMap
map of madia
TG4Limits * FindLimits(const G4String &name, G4bool silent=false) const
G4Material * FindMaterial(G4double a, G4double z, G4double density) const
virtual ~TG4GeometryServices()
G4OpticalSurfaceFinish SurfaceFinish(EMCOpSurfaceFinish finish) const
G4double * ConvertAtomWeight(G4int nmat, G4double *a, G4double *wmat) const
G4int GetMediumId(G4LogicalVolume *lv) const
void BuildAssemblyLevels()
Int_t NofG4PhysicalVolumes() const
G4Material * MixMaterials(G4String name, G4double density, const TG4StringVector &matNames, const TG4doubleVector &matWeights)
G4bool IsG3Volume(const G4String &lvName) const
G4double * CreateG4doubleArray(Float_t *array, G4int size, G4bool copyValues=true) const
void PrintStatistics(G4bool open, G4bool close) const
void PrintElementTable() const
G4LogicalVolume * FindLogicalVolume(const G4String &name, G4bool silent=false) const
const G4String & UserVolumeName(const G4String &name) const
G4String CutName(const char *name) const
G4SurfaceType SurfaceType(EMCOpSurfaceType surfType) const
TG4Limits * FindLimits2(const G4String &name, G4bool silent=false) const
Int_t NofG3Volumes() const
Int_t NofG4LogicalVolumes() const
void PrintMaterials() const
G4bool CompareElement(G4double a, G4double z, const G4Element *elem) const
std::vector< TG4AssemblyLevels > fAssemblyLevels
assembly levels per placement, indexed by its Geant4 instance id
void PrintLimits(const G4String &name) const
void PrintMaterialsProperties() const
G4bool fAccountAssemblyLevels
option to account assembly levels in the volume level hierarchy
G4VPhysicalVolume * FindPhysicalVolume(const G4String &name, G4int copyNo, G4bool silent=false) const
TG4Limits * GetLimits(G4UserLimits *limits) const
G4bool fIsG3toG4
info if user geometry is defined via G3toG4
G4VPhysicalVolume * FindDaughter(const G4String &name, G4int copyNo, G4LogicalVolume *mlv, G4bool silent=false) const
void SetG3toG4Separator(char separator)
G4VPhysicalVolume * fWorld
top physical volume (world)
G4bool fAssemblyLevelsBuilt
whether fAssemblyLevels has been filled
static const G4double fgkAZTolerance
A,Z tolerance.
G4double GetEffA(G4Material *material) const
G4bool CompareMaterial(G4int nofElements, G4double density, const G4Material *material) const
G4String CutMaterialName(const char *name) const
void PrintVolumeLimits(const G4String &volumeName) const
G4OpticalSurfaceModel SurfaceModel(EMCOpSurfaceModel model) const
void PrintCuts(const G4String &cutName) const
const TG4AssemblyLevels & GetAssemblyLevels(const G4VPhysicalVolume *pv) const
void Convert(const G4Transform3D &transform, TGeoHMatrix &matrix) const
G4double GetEffZ(G4Material *material) const
static G4String fgBuffer
string buffer
static void PrintStars(G4bool emptyLineFirst)
static void Warning(const TString &className, const TString &methodName, const TString &text)
static void Exception(const TString &className, const TString &methodName, const TString &text)
Extended G4UserLimits class.
const TG4G3CutVector * GetCutVector() const
static G4int GetNofLimits()
const TG4G3ControlVector * GetControlVector() const
The map of media to logical volumes.
Helper class to keep medium data.
G4UserLimits * GetLimits() const
virtual G4int VerboseLevel() const
TG4Verbose(const G4String &cmdName)
std::map< G4String, G4OpticalSurface * > TG4OpSurfaceMap
The map between optical surfaces names and their objects.
std::vector< G4String > TG4StringVector
std::vector< G4double > TG4doubleVector
TG4G3Cut
Enumeration for G3 types of kinetic energy cuts.
TG4G3Control
Enumeration for G3 types of physics processes controls.
@ kNoG3Cuts
Invalid value.
@ kNoG3Controls
No process control.
std::vector< G4int > fCopyNos
-1 where the Geant4 copy number applies
std::vector< G4String > fNames
outermost first; last is the placed volume