18#include "G4LogicalVolumeStore.hh"
19#include "G4Material.hh"
20#include "G4NistManager.hh"
21#include "G4PVPlacement.hh"
28 const std::string &backup_mat) {
35 std::unordered_map<std::string, G4Volume *> *g4s) {
36 auto it = g4s->find(vname);
37 return (it != g4s->end()) ? it->second->getSolid() :
nullptr;
42 std::unordered_map<std::string, G4Volume *> *g4s) {
43 auto it = g4s->find(volume_name);
44 return (it != g4s->end()) ? it->second->getLogical() :
nullptr;
49 std::unordered_map<std::string, G4Volume *> *g4s) {
50 auto it = g4s->find(vname);
51 return (it != g4s->end()) ? it->second->getPhysical() :
nullptr;
56 std::string_view color = s->
getColor();
62 " resulted in RGB = (", g4color.GetRed(),
", ", g4color.GetGreen(),
", ", g4color.GetBlue(),
63 ", opacity: ", opacity,
")");
65 G4VisAttributes attr(g4color);
68 s->
isVisible() ? attr.SetVisibility(
true) : attr.SetVisibility(
false);
72 attr.SetForceWireframe(
true);
75 attr.SetForceSolid(
true);
78 attr.SetForceCloud(
true);
90 auto rot =
new G4RotationMatrix();
93 if (rotDef.size() == 3) {
95 rot->rotateX(pars[0]);
96 rot->rotateY(pars[1]);
97 rot->rotateZ(pars[2]);
105 G4ThreeVector pos(0., 0., 0.);
107 if (vec.size() == 3) pos.set(vec[0], vec[1], vec[2]);
112 if (shift.size() == 3) pos += G4ThreeVector(shift[0], shift[1], shift[2]);
118 std::unordered_map<std::string, G4Volume *> *g4s) {
119 const std::string g4name = s->
getG4Name();
123 if (thisG4Volume->getLogical())
return thisG4Volume->getLogical();
129 auto volume_copy =
gsystem +
"/" + copyOf;
131 if (copyG4Volume->getLogical() !=
nullptr) {
132 return copyG4Volume->getLogical();
139 auto *nist = G4NistManager::Instance();
140 auto *mat = nist->FindOrBuildMaterial(s->
getMaterial());
152 auto *logical =
new G4LogicalVolume(thisG4Volume->getSolid(),
157 thisG4Volume->setLogical(logical,
log);
162 std::unordered_map<std::string, G4Volume *> *g4s) {
169 const std::string g4name = s->
getG4Name();
171 auto logicalVolume = thisG4Volume->getLogical();
177 auto volume_copy =
gsystem +
"/" + copyOf;
179 if (copyG4Volume->getLogical() !=
nullptr) {
180 logicalVolume = copyG4Volume->getLogical();
185 if (!thisG4Volume->getPhysical()) {
186 G4RotationMatrix rotation_instance = *
getRotation(s);
187 G4ThreeVector translation_instance =
getPosition(s);
189 thisG4Volume->setPhysical(
new G4PVPlacement(G4Transform3D(rotation_instance, translation_instance),
198 return thisG4Volume->getPhysical();
202 std::unordered_map<std::string, G4Volume *> *g4s) {
210 const bool okSolid = (sbuild !=
nullptr);
211 const bool okLogical = (lbuild !=
nullptr);
212 const bool okPhysical = (pbuild !=
nullptr);
213 const bool okAll = okSolid && okLogical && okPhysical;
217 ": solid: ", okSolid,
218 " logical: ", okLogical,
219 " physical: ", okPhysical);
G4Volume * getOrCreateG4Volume(const std::string &volume_name, std::unordered_map< std::string, G4Volume * > *g4s)
Get or create a G4Volume wrapper entry in the map.
virtual G4LogicalVolume * buildLogical(const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
Build or retrieve the G4LogicalVolume for a volume.
virtual G4VPhysicalVolume * buildPhysical(const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
Build or retrieve the G4VPhysicalVolume for a volume.
static G4VPhysicalVolume * getPhysicalFromMap(const std::string &volume_name, std::unordered_map< std::string, G4Volume * > *g4s)
Lookup physical volume in the g4s map.
bool build_g4volume(const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
Build (or retrieve) solid, logical, and physical volumes for a given GVolume.
static G4RotationMatrix * getRotation(const GVolume *s)
Parse rotation string and build a Geant4 rotation matrix.
virtual std::string_view className() const =0
Short, human-readable factory name for logging.
virtual G4VSolid * buildSolid(const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)=0
Build the G4VSolid for a volume.
bool checkPhysicalDependencies(const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
Verify prerequisites to build a physical placement.
static G4VSolid * getSolidFromMap(const std::string &volume_name, std::unordered_map< std::string, G4Volume * > *g4s)
Lookup solid in the g4s map.
static G4LogicalVolume * getLogicalFromMap(const std::string &volume_name, std::unordered_map< std::string, G4Volume * > *g4s)
Lookup logical volume in the g4s map.
void initialize_context(int checkOverlaps, const std::string &backupMaterial)
Configure overlap checking and backup material behavior for this factory.
static G4ThreeVector getPosition(const GVolume *s)
Parse position and optional shift strings to compute placement translation.
G4VisAttributes createVisualAttributes(const GVolume *s)
Build visualization attributes from the volume definition.
std::string backupMaterial
Backup material name used if the requested material is absent.
std::shared_ptr< GLogger > log
void warning(Args &&... args) const
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
std::string getRot() const
std::string getCopyOf() const
bool getExistence() const
std::string getPos() const
std::string getShift() const
std::string getMaterial() const
std::string getG4Name() const
std::string getSystem() const
std::string_view getColor() const
double getOpacity() const
std::string getG4MotherName() const
Abstract factory that converts a GEMC DB GVolume into Geant4 objects.
Conventions, labels, and error codes used by the g4system geometry/material layer.
#define ERR_G4MATERIALNOTFOUND
Material lookup failed and no fallback was available.
#define GSYSTEMNOMODIFIER
#define UNINITIALIZEDSTRINGQUANTITY
vector< double > getG4NumbersFromString(const string &vstring, bool warnIfNotUnit=false)
vector< string > getStringVectorFromStringWithDelimiter(const string &input, const string &x)
G4Colour makeG4Colour(std::string_view code, double opacity)
vector< double > getG4NumbersFromStringVector(const vector< string > &vstring, bool warnIfNotUnit=false)