g4system
Loading...
Searching...
No Matches
g4world.h
Go to the documentation of this file.
1#pragma once
22// gemc
23#include <gemc/gsystem/gworld.h>
24
25// g4system
26#include "g4volume.h"
29
30// c++
31#include <memory>
32#include <string>
33#include <unordered_map>
34
35// geant4
36#include "G4NistManager.hh"
37
49class G4World : public GBase<G4World>
50{
51public:
64 G4World(const GWorld* gworld, const std::shared_ptr<GOptions>& gopts);
65
69 for (auto& [name, vol] : g4volumesMap) { delete vol; }
70 }
71
72 // G4World now owns the raw G4Volume* wrappers (freed in the destructor). It is only ever held
73 // by shared_ptr, so forbid copy/move to avoid a shallow copy double-freeing the wrappers.
74 G4World(const G4World&) = delete;
75 G4World& operator=(const G4World&) = delete;
76 G4World(G4World&&) = delete;
78
79 // ────── lookup / mutators ────────────────────────────────────────
80
87 [[nodiscard]] const G4Volume* getG4Volume(const std::string& volumeName) const;
88
100 void setFieldManagerForVolume(const std::string& volumeName,
101 G4FieldManager* fm,
102 bool forceToAllDaughters);
103
108 [[nodiscard]] bool is_empty() const noexcept { return g4volumesMap.empty(); }
109
114 [[nodiscard]] std::size_t number_of_volumes() const noexcept { return g4volumesMap.size(); }
115
125 [[nodiscard]] G4ObjectsFactory* get_factory(const std::string& factoryName) {
126 auto it = g4systemFactory.find(factoryName);
127 if (it != g4systemFactory.end()) return it->second;
128 else {
130 "G4World: factory <", factoryName, "> not found.");
131 }
132 }
133
140 [[nodiscard]] std::unordered_map<std::string, G4Volume*> get_g4volumes_map() const {
141 return g4volumesMap;
142 }
143
144private:
145 // ────── helper functions ─────────────────────────────────────────
146
157 std::string g4FactoryNameFromSystemFactory(const std::string& factory) const;
158
169 bool createG4Material(const std::shared_ptr<GMaterial>& gmaterial);
170
178 void buildDefaultMaterialsElementsAndIsotopes();
179
184 void buildMaterials(SystemMap* system_map);
185
198 void createG4SystemFactory(const std::shared_ptr<GOptions>& gopts,
199 SystemMap* gsystemsMap,
200 const std::string& backup_material,
201 int check_overlaps);
202
210 bool build_g4volume(const GVolume* s, G4ObjectsFactory* objectFactory);
211
212 // ────── dependency helpers ──────────────────────────────────────
213 // These pointers are cached so that multiple predefined materials can reuse the same element instances.
214 G4Element* Deuterium = nullptr;
215 G4Element* Helium3 = nullptr;
216 G4Element* Tritium = nullptr;
217
218 // ────── data members ────────────────────────────────────────────
219
221 std::unordered_map<std::string, G4ObjectsFactory*> g4systemFactory;
222
224 std::unordered_map<std::string, G4Volume*> g4volumesMap;
225
233 std::unordered_map<std::string, G4Material*> g4materialsMap;
234};
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:50
Builds a full Geant4 geometry "world" from a GEMC GWorld description.
Definition g4world.h:50
std::unordered_map< std::string, G4Volume * > get_g4volumes_map() const
Return a copy of the current volume map (name → wrapper pointer).
Definition g4world.h:140
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:114
void setFieldManagerForVolume(const std::string &volumeName, G4FieldManager *fm, bool forceToAllDaughters)
Attach a G4FieldManager to the logical volume of a named volume.
Definition g4world.cc:125
bool is_empty() const noexcept
Check whether the world currently has no cached volumes.
Definition g4world.h:108
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:125
const G4Volume * getG4Volume(const std::string &volumeName) const
Return the G4Volume wrapper for a volume name.
Definition g4world.cc:120
~G4World()
Definition g4world.h:68
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