g4system
Loading...
Searching...
No Matches
g4objectsFactory.h
Go to the documentation of this file.
1#pragma once
17// c++
18#include <memory>
19#include <string>
20#include <string_view>
21#include <unordered_map>
22
23// gemc
24#include "gbase.h"
25#include "gvolume.h"
26
27// g4system
28#include "g4volume.h"
29#include "g4system_options.h"
30
31// geant4
32#include "G4LogicalVolume.hh"
33#include "G4PVPlacement.hh"
34#include "G4RotationMatrix.hh"
35#include "G4ThreeVector.hh"
36#include "G4VisAttributes.hh"
37
52class G4ObjectsFactory : public GBase<G4ObjectsFactory>
53{
54public:
56 ~G4ObjectsFactory() override = default;
57
62 explicit G4ObjectsFactory(const std::shared_ptr<GOptions>& g) : GBase(g, G4SFACTORY_LOGGER) {
63 }
64
76 const std::string& backupMaterial);
77
93 [[nodiscard]] bool build_g4volume(const GVolume* s,
94 std::unordered_map<std::string,
95 G4Volume*>* g4s);
96
101 [[nodiscard]] virtual std::string_view className() const = 0;
102
103protected:
104 // ──────── pure & virtual hooks for subclasses ──────────────────
105
116 virtual G4VSolid* buildSolid(const GVolume* s,
117 std::unordered_map<std::string, G4Volume*>* g4s) = 0;
118
133 virtual G4LogicalVolume* buildLogical(const GVolume* s,
134 std::unordered_map<std::string, G4Volume*>* g4s);
135
149 virtual G4VPhysicalVolume* buildPhysical(const GVolume* s,
150 std::unordered_map<std::string, G4Volume*>* g4s);
151
153 static G4VSolid* getSolidFromMap(const std::string& volume_name, std::unordered_map<std::string, G4Volume*>* g4s);
154
156 static G4LogicalVolume* getLogicalFromMap(const std::string& volume_name,
157 std::unordered_map<std::string, G4Volume*>* g4s);
158
160 static G4VPhysicalVolume* getPhysicalFromMap(const std::string& volume_name,
161 std::unordered_map<std::string, G4Volume*>* g4s);
162
173 G4Volume* getOrCreateG4Volume(const std::string& volume_name, std::unordered_map<std::string, G4Volume*>* g4s) {
174 if (auto it = g4s->find(volume_name); it != g4s->end()) { return it->second; }
175 else {
176 (*g4s)[volume_name] = new G4Volume();
177 return (*g4s)[volume_name];
178 }
179 }
180
186 G4VisAttributes createVisualAttributes(const GVolume* s);
187
201 bool checkSolidDependencies(const GVolume* s,
202 std::unordered_map<std::string, G4Volume*>* g4s);
203
214 static bool checkLogicalDependencies(const GVolume* s,
215 std::unordered_map<std::string, G4Volume*>* g4s);
216
231 std::unordered_map<std::string, G4Volume*>* g4s);
232
233 // ──────── geometric helpers ────────────────────────────────────
234
240 static G4RotationMatrix* getRotation(const GVolume* s);
241
247 static G4ThreeVector getPosition(const GVolume* s);
248
251
257 std::string backupMaterial;
258};
Base class orchestrating the conversion of a GVolume into a Geant4 representation.
G4Volume * getOrCreateG4Volume(const std::string &volume_name, std::unordered_map< std::string, G4Volume * > *g4s)
Get or create a G4Volume wrapper entry in the map.
bool checkSolidDependencies(const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
Check whether all prerequisites to build a solid are satisfied.
~G4ObjectsFactory() override=default
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.
G4ObjectsFactory(const std::shared_ptr< GOptions > &g)
Construct a factory using the global option set.
virtual std::string_view className() const =0
Short, human-readable factory name for logging.
static bool checkLogicalDependencies(const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
Logical dependency check placeholder.
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.
Convenience container holding a Geant4 solid, logical, and physical volume.
Definition g4volume.h:50
Option definitions for the g4system module (geometry/material construction layer).
constexpr const char * G4SFACTORY_LOGGER
Logger name used by object factories (e.g. G4ObjectsFactory derived classes).
Thin wrapper that stores the Geant4 solid/logical/physical triple for one GEMC volume.