gdetector
Loading...
Searching...
No Matches
gdetectorConstruction.h
Go to the documentation of this file.
1#pragma once
2
3// geant4
4#include "G4VUserDetectorConstruction.hh"
5
6// gemc
7#include <gemc/goptions/goptions.h>
8#include <gemc/g4system/g4world.h>
9#include <gemc/gfields/gmagneto.h>
10#include <gemc/gsd/gsd.h>
11#include <gemc/gbase/gbase.h>
12
13// c++
14#include <map>
15#include <string>
16#include <vector>
17
61class GDetectorConstruction : public GBase<GDetectorConstruction>, public G4VUserDetectorConstruction {
62public:
72 explicit GDetectorConstruction(std::shared_ptr<GOptions> gopts);
73
74public:
86 G4VPhysicalVolume* Construct() override;
87
98 void ConstructSDandField() override;
99
108 [[nodiscard]] bool is_empty() const { return g4world->is_empty(); }
109
122
132
145 std::shared_ptr<GDynamicDigitization> get_digitization_routines_for_sdname(const std::string &sd_name) const {
146 return digitization_routines_map->at(sd_name);
147 }
148
157 std::shared_ptr<gdynamicdigitization::dRoutinesMap> get_digitization_routines_map() const {
158 return digitization_routines_map;
159 }
160
167 [[nodiscard]] bool has_built_geometry() const {
168 return g4world != nullptr;
169 }
170
178 [[nodiscard]] std::unordered_map<std::string, G4Volume*> get_g4volumes_map() const {
179 if (g4world == nullptr) {
180 log->error(ERR_G4VOLUMEBUILDFAILED, "No g4world ");
181 }
182 return g4world->get_g4volumes_map();
183 }
184
194 [[nodiscard]] std::unordered_map<std::string, const GVolume*> get_gvolumes_flat_map() const {
195 std::unordered_map<std::string, const GVolume*> result;
196 if (!gworld) return result;
197 for (const auto& [sysName, sysPtr] : *gworld->getSystemsMap()) {
198 for (const auto& [volName, volPtr] : sysPtr->getGVolumesMap()) {
199 const std::string g4name = volPtr->getG4Name();
200 if (!g4name.empty())
201 result[g4name] = volPtr.get();
202 }
203 }
204 return result;
205 }
206
207private:
213 std::shared_ptr<GOptions> gopt; // need options inside Constructs() methods
214
220 std::shared_ptr<GWorld> gworld;
221
227 std::shared_ptr<G4World> g4world;
228
235 std::shared_ptr<gdynamicdigitization::dRoutinesMap> digitization_routines_map;
236
243 static G4ThreadLocal GMagneto* gmagneto;
244
256 static G4ThreadLocal std::map<std::string, GSensitiveDetector*>* tlSDMap;
257
265 void loadDigitizationPlugins();
266
275 bool digiplugins_need_reload = true;
276
284 [[nodiscard]] SystemList cloneSystemDescriptors(const SystemList& systems) const;
285
293 SystemList gsystems;
294};
std::unordered_map< std::string, G4Volume * > get_g4volumes_map() const
bool is_empty() const noexcept
std::shared_ptr< GLogger > log
Builds and (optionally) reloads the Geant4 geometry from GEMC world definitions.
GDetectorConstruction(std::shared_ptr< GOptions > gopts)
Constructs a detector builder configured by the provided options.
void reload_geometry(SystemList sl)
Reloads the geometry using a new list of GSystem objects.
std::unordered_map< std::string, const GVolume * > get_gvolumes_flat_map() const
Returns a flat map of GEMC volume descriptors indexed by their G4 names.
std::unordered_map< std::string, G4Volume * > get_g4volumes_map() const
Returns a map of built Geant4 volumes indexed by their GEMC/G4World names.
G4VPhysicalVolume * Construct() override
Geant4 geometry construction hook.
std::shared_ptr< GDynamicDigitization > get_digitization_routines_for_sdname(const std::string &sd_name) const
Returns the digitization routine for a given sensitive detector name.
void ConstructSDandField() override
Geant4 SD/field construction hook.
std::shared_ptr< gdynamicdigitization::dRoutinesMap > get_digitization_routines_map() const
Returns the full map of digitization routines.
void prepare_geometry_for_run()
Reinitializes geometry through Geant4 before running events.
bool has_built_geometry() const
Return whether a Geant4 world has been built.
bool is_empty() const
Returns whether the currently built geometry is empty.
void error(int exit_code, Args &&... args) const
SystemMap * getSystemsMap() const
#define ERR_G4VOLUMEBUILDFAILED
std::vector< SystemPtr > SystemList