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);
69 s->
getStyle() ? attr.SetForceSolid(
true) : attr.SetForceWireframe(
true);
75 auto rot =
new G4RotationMatrix();
78 if (rotDef.size() == 3) {
80 rot->rotateX(pars[0]);
81 rot->rotateY(pars[1]);
82 rot->rotateZ(pars[2]);
90 G4ThreeVector pos(0., 0., 0.);
92 if (vec.size() == 3) pos.set(vec[0], vec[1], vec[2]);
97 if (shift.size() == 3) pos += G4ThreeVector(shift[0], shift[1], shift[2]);
103 std::unordered_map<std::string, G4Volume*>* g4s) {
104 const std::string g4name = s->
getG4Name();
108 if (thisG4Volume->getLogical())
return thisG4Volume->getLogical();
114 auto volume_copy =
gsystem +
"/" + copyOf;
116 if (copyG4Volume->getLogical() !=
nullptr) {
117 return copyG4Volume->getLogical();
124 auto* nist = G4NistManager::Instance();
125 auto* mat = nist->FindOrBuildMaterial(s->
getMaterial());
137 auto* logical =
new G4LogicalVolume(thisG4Volume->getSolid(),
142 thisG4Volume->setLogical(logical,
log);
147 std::unordered_map<std::string, G4Volume*>* g4s) {
154 const std::string g4name = s->
getG4Name();
156 auto logicalVolume = thisG4Volume->getLogical();
162 auto volume_copy =
gsystem +
"/" + copyOf;
164 if (copyG4Volume->getLogical() !=
nullptr) {
165 logicalVolume = copyG4Volume->getLogical();
170 if (!thisG4Volume->getPhysical()) {
171 G4RotationMatrix rotation_instance = *
getRotation(s);
172 G4ThreeVector translation_instance =
getPosition(s);
174 thisG4Volume->setPhysical(
new G4PVPlacement(G4Transform3D(rotation_instance, translation_instance),
183 return thisG4Volume->getPhysical();
187 std::unordered_map<std::string, G4Volume*>* g4s) {
195 const bool okSolid = (sbuild !=
nullptr);
196 const bool okLogical = (lbuild !=
nullptr);
197 const bool okPhysical = (pbuild !=
nullptr);
198 const bool okAll = okSolid && okLogical && okPhysical;
202 ": solid: ", okSolid,
203 " logical: ", okLogical,
204 " 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)