g4system
Loading...
Searching...
No Matches
g4world.h
Go to the documentation of this file.
1#pragma once
22// gemc
23#include "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
66 // ────── lookup / mutators ────────────────────────────────────────
67
74 [[nodiscard]] const G4Volume* getG4Volume(const std::string& volumeName) const;
75
87 void setFieldManagerForVolume(const std::string& volumeName,
88 G4FieldManager* fm,
89 bool forceToAllDaughters);
90
95 [[nodiscard]] bool is_empty() const noexcept { return g4volumesMap.empty(); }
96
101 [[nodiscard]] std::size_t number_of_volumes() const noexcept { return g4volumesMap.size(); }
102
112 [[nodiscard]] G4ObjectsFactory* get_factory(const std::string& factoryName) {
113 auto it = g4systemFactory.find(factoryName);
114 if (it != g4systemFactory.end()) return it->second;
115 else {
117 "G4World: factory <", factoryName, "> not found.");
118 }
119 }
120
127 [[nodiscard]] std::unordered_map<std::string, G4Volume*> get_g4volumes_map() const {
128 return g4volumesMap;
129 }
130
131private:
132 // ────── helper functions ─────────────────────────────────────────
133
144 std::string g4FactoryNameFromSystemFactory(const std::string& factory) const;
145
156 bool createG4Material(const std::shared_ptr<GMaterial>& gmaterial);
157
165 void buildDefaultMaterialsElementsAndIsotopes();
166
171 void buildMaterials(SystemMap* system_map);
172
185 void createG4SystemFactory(const std::shared_ptr<GOptions>& gopts,
186 SystemMap* gsystemsMap,
187 const std::string& backup_material,
188 int check_overlaps);
189
197 bool build_g4volume(const GVolume* s, G4ObjectsFactory* objectFactory);
198
199 // ────── dependency helpers ──────────────────────────────────────
200 // These pointers are cached so that multiple predefined materials can reuse the same element instances.
201 G4Element* Deuterium = nullptr;
202 G4Element* Helium3 = nullptr;
203 G4Element* Tritium = nullptr;
204
205 // ────── data members ────────────────────────────────────────────
206
208 std::unordered_map<std::string, G4ObjectsFactory*> g4systemFactory;
209
211 std::unordered_map<std::string, G4Volume*> g4volumesMap;
212
220 std::unordered_map<std::string, G4Material*> g4materialsMap;
221};
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:127
G4World(const GWorld *gworld, const std::shared_ptr< GOptions > &gopts)
Construct and build the Geant4 world from a GEMC world.
Definition g4world.cc:32
std::size_t number_of_volumes() const noexcept
Number of volumes stored so far.
Definition g4world.h:101
void setFieldManagerForVolume(const std::string &volumeName, G4FieldManager *fm, bool forceToAllDaughters)
Attach a G4FieldManager to the logical volume of a named volume.
Definition g4world.cc:131
bool is_empty() const noexcept
Check whether the world currently has no cached volumes.
Definition g4world.h:95
G4ObjectsFactory * get_factory(const std::string &factoryName)
Retrieve a registered factory by name.
Definition g4world.h:112
const G4Volume * getG4Volume(const std::string &volumeName) const
Return the G4Volume wrapper for a volume name.
Definition g4world.cc:126
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