g4system
Loading...
Searching...
No Matches
g4objectsFactory.h
Go to the documentation of this file.
1#pragma once
16
17// c++
18#include <memory>
19#include <optional>
20#include <string>
21#include <string_view>
22#include <unordered_map>
23
24// gemc
25#include <gemc/gbase/gbase.h>
26#include <gemc/gsystem/gvolume.h>
27
28// g4system
31
32// geant4
33#include "G4LogicalVolume.hh"
34#include "G4PVPlacement.hh"
35#include "G4RotationMatrix.hh"
36#include "G4ThreeVector.hh"
37#include "G4VisAttributes.hh"
38
53class G4ObjectsFactory : public GBase<G4ObjectsFactory>
54{
55public:
57 ~G4ObjectsFactory() override = default;
58
63 explicit G4ObjectsFactory(const std::shared_ptr<GOptions>& g) : GBase(g, G4SFACTORY_LOGGER) {
64 }
65
77 const std::optional<std::string>& backupMaterial);
78
94 [[nodiscard]] bool build_g4volume(const GVolume* s,
95 std::unordered_map<std::string,
96 G4Volume*>* g4s);
97
102 [[nodiscard]] virtual std::string_view className() const = 0;
103
104protected:
105 // ──────── pure & virtual hooks for subclasses ──────────────────
106
117 virtual G4VSolid* buildSolid(const GVolume* s,
118 std::unordered_map<std::string, G4Volume*>* g4s) = 0;
119
134 virtual G4LogicalVolume* buildLogical(const GVolume* s,
135 std::unordered_map<std::string, G4Volume*>* g4s);
136
150 virtual G4VPhysicalVolume* buildPhysical(const GVolume* s,
151 std::unordered_map<std::string, G4Volume*>* g4s);
152
154 static G4VSolid* getSolidFromMap(const std::string& volume_name, std::unordered_map<std::string, G4Volume*>* g4s);
155
157 static G4LogicalVolume* getLogicalFromMap(const std::string& volume_name,
158 std::unordered_map<std::string, G4Volume*>* g4s);
159
161 static G4VPhysicalVolume* getPhysicalFromMap(const std::string& volume_name,
162 std::unordered_map<std::string, G4Volume*>* g4s);
163
174 G4Volume* getOrCreateG4Volume(const std::string& volume_name, std::unordered_map<std::string, G4Volume*>* g4s) {
175 if (auto it = g4s->find(volume_name); it != g4s->end()) { return it->second; }
176 else {
177 (*g4s)[volume_name] = new G4Volume();
178 return (*g4s)[volume_name];
179 }
180 }
181
187 G4VisAttributes createVisualAttributes(const GVolume* s);
188
202 bool checkSolidDependencies(const GVolume* s,
203 std::unordered_map<std::string, G4Volume*>* g4s);
204
215 static bool checkLogicalDependencies(const GVolume* s,
216 std::unordered_map<std::string, G4Volume*>* g4s);
217
232 std::unordered_map<std::string, G4Volume*>* g4s);
233
234 // ──────── geometric helpers ────────────────────────────────────
235
241 static G4RotationMatrix* getRotation(const GVolume* s);
242
248 static G4ThreeVector getPosition(const GVolume* s);
249
252
258 std::optional<std::string> backupMaterial;
259};
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.
std::optional< std::string > backupMaterial
Backup material name used if the requested material is absent.
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.
void initialize_context(int checkOverlaps, const std::optional< std::string > &backupMaterial)
Configure overlap checking and backup material behavior for this factory.
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.
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.
Convenience container holding a Geant4 solid, logical, and physical volume.
Definition g4volume.h:52
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
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.