g4system
Loading...
Searching...
No Matches
g4world.h
Go to the documentation of this file.
1#pragma once
23// gemc
24#include <gemc/gsystem/gworld.h>
25
26// g4system
27#include "g4volume.h"
30
31// c++
32#include <memory>
33#include <string>
34#include <unordered_map>
35
36// geant4
37#include "G4NistManager.hh"
38
39class G4OpticalSurface;
40
52class G4World : public GBase<G4World>
53{
54public:
67 G4World(const GWorld* gworld, const std::shared_ptr<GOptions>& gopts);
68
72 for (auto& [name, vol] : g4volumesMap) { delete vol; }
73 }
74
75 // G4World now owns the raw G4Volume* wrappers (freed in the destructor). It is only ever held
76 // by shared_ptr, so forbid copy/move to avoid a shallow copy double-freeing the wrappers.
77 G4World(const G4World&) = delete;
78 G4World& operator=(const G4World&) = delete;
79 G4World(G4World&&) = delete;
81
82 // ────── lookup / mutators ────────────────────────────────────────
83
90 [[nodiscard]] const G4Volume* getG4Volume(const std::string& volumeName) const;
91
103 void setFieldManagerForVolume(const std::string& volumeName,
104 G4FieldManager* fm,
105 bool forceToAllDaughters);
106
111 [[nodiscard]] bool is_empty() const noexcept { return g4volumesMap.empty(); }
112
117 [[nodiscard]] std::size_t number_of_volumes() const noexcept { return g4volumesMap.size(); }
118
128 [[nodiscard]] G4ObjectsFactory* get_factory(const std::string& factoryName) {
129 auto it = g4systemFactory.find(factoryName);
130 if (it != g4systemFactory.end()) return it->second;
131 else {
133 "G4World: factory <", factoryName, "> not found.");
134 }
135 }
136
143 [[nodiscard]] std::unordered_map<std::string, G4Volume*> get_g4volumes_map() const {
144 return g4volumesMap;
145 }
146
147private:
148 // ────── helper functions ─────────────────────────────────────────
149
160 std::string g4FactoryNameFromSystemFactory(const std::string& factory) const;
161
172 bool createG4Material(const std::shared_ptr<GMaterial>& gmaterial);
173
181 void buildDefaultMaterialsElementsAndIsotopes();
182
187 void buildMaterials(SystemMap* system_map);
188
201 void createG4SystemFactory(const std::shared_ptr<GOptions>& gopts,
202 SystemMap* gsystemsMap,
203 const std::string& backup_material,
204 int check_overlaps);
205
213 bool build_g4volume(const GVolume* s, G4ObjectsFactory* objectFactory);
214
228 void buildOpticalSurfaces(SystemMap* system_map);
229
241 G4OpticalSurface* getOrCreateOpticalSurface(const std::string& systemName, const GMirror* gmirror);
242
243 // ────── dependency helpers ──────────────────────────────────────
244 // These pointers are cached so that multiple predefined materials can reuse the same element instances.
245 G4Element* Deuterium = nullptr;
246 G4Element* Helium3 = nullptr;
247 G4Element* Tritium = nullptr;
248
249 // ────── data members ────────────────────────────────────────────
250
252 std::unordered_map<std::string, G4ObjectsFactory*> g4systemFactory;
253
255 std::unordered_map<std::string, G4Volume*> g4volumesMap;
256
264 std::unordered_map<std::string, G4Material*> g4materialsMap;
265
274 std::unordered_map<std::string, G4OpticalSurface*> g4opticalSurfacesMap;
275};
Base class orchestrating the conversion of a GVolume into a Geant4 representation.
Convenience container holding a Geant4 solid, logical, and physical volume.
Definition g4volume.h:52
Builds a full Geant4 geometry "world" from a GEMC GWorld description.
Definition g4world.h:53
std::unordered_map< std::string, G4Volume * > get_g4volumes_map() const
Return a copy of the current volume map (name → wrapper pointer).
Definition g4world.h:143
G4World(const GWorld *gworld, const std::shared_ptr< GOptions > &gopts)
Construct and build the Geant4 world from a GEMC world.
Definition g4world.cc:27
std::size_t number_of_volumes() const noexcept
Number of volumes stored so far.
Definition g4world.h:117
void setFieldManagerForVolume(const std::string &volumeName, G4FieldManager *fm, bool forceToAllDaughters)
Attach a G4FieldManager to the logical volume of a named volume.
Definition g4world.cc:128
bool is_empty() const noexcept
Check whether the world currently has no cached volumes.
Definition g4world.h:111
G4World & operator=(const G4World &)=delete
G4World & operator=(G4World &&)=delete
G4World(G4World &&)=delete
G4World(const G4World &)=delete
G4ObjectsFactory * get_factory(const std::string &factoryName)
Retrieve a registered factory by name.
Definition g4world.h:128
const G4Volume * getG4Volume(const std::string &volumeName) const
Return the G4Volume wrapper for a volume name.
Definition g4world.cc:123
~G4World()
Definition g4world.h:71
std::shared_ptr< GLogger > log
void error(int exit_code, Args &&... args) 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_G4SYSTEMFACTORYNOTFOUND
A required Geant4 system factory was not found/mapped.
Thin wrapper that stores the Geant4 solid/logical/physical triple for one GEMC volume.
std::map< std::string, SystemPtr > SystemMap