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#include "G4UserLimits.hh"
6
7// gemc
8#include <gemc/goptions/goptions.h>
9#include <gemc/g4system/g4world.h>
10#include <gemc/gfields/gmagneto.h>
11#include <gemc/gsd/gsd.h>
12#include <gemc/gbase/gbase.h>
13
14// c++
15#include <map>
16#include <string>
17#include <vector>
18
29
62class GDetectorConstruction : public GBase<GDetectorConstruction>, public G4VUserDetectorConstruction {
63public:
73 explicit GDetectorConstruction(std::shared_ptr<GOptions> gopts);
74
75public:
87 G4VPhysicalVolume* Construct() override;
88
99 void ConstructSDandField() override;
100
109 [[nodiscard]] bool is_empty() const { return g4world->is_empty(); }
110
123
133
146 std::shared_ptr<GDynamicDigitization> get_digitization_routines_for_sdname(const std::string &sd_name) const {
147 return digitization_routines_map->at(sd_name);
148 }
149
158 std::shared_ptr<gdynamicdigitization::dRoutinesMap> get_digitization_routines_map() const {
159 return digitization_routines_map;
160 }
161
168 [[nodiscard]] bool has_built_geometry() const {
169 return g4world != nullptr;
170 }
171
179 [[nodiscard]] std::unordered_map<std::string, G4Volume*> get_g4volumes_map() const {
180 if (g4world == nullptr) {
181 log->error(g4system::ERR_G4VOLUMEBUILDFAILED, "No g4world ");
182 }
183 return g4world->get_g4volumes_map();
184 }
185
195 [[nodiscard]] std::unordered_map<std::string, const GVolume*> get_gvolumes_flat_map() const {
196 std::unordered_map<std::string, const GVolume*> result;
197 if (!gworld) return result;
198 for (const auto& [sysName, sysPtr] : *gworld->getSystemsMap()) {
199 for (const auto& [volName, volPtr] : sysPtr->getGVolumesMap()) {
200 const std::string g4name = volPtr->getG4Name();
201 if (!g4name.empty())
202 result[g4name] = volPtr.get();
203 }
204 }
205 return result;
206 }
207
216 [[nodiscard]] std::unordered_map<std::string, const GMirror*> get_gmirrors_flat_map() const {
217 std::unordered_map<std::string, const GMirror*> result;
218 if (!gworld) return result;
219 for (const auto& [sysName, sysPtr] : *gworld->getSystemsMap()) {
220 for (const auto& [mirrorName, mirrorPtr] : sysPtr->getGMirrorsMap()) {
221 result[sysName + "/" + mirrorName] = mirrorPtr.get();
222 }
223 }
224 return result;
225 }
226
227private:
233 std::shared_ptr<GOptions> gopt; // need options inside Constructs() methods
234
240 std::shared_ptr<GWorld> gworld;
241
247 std::shared_ptr<G4World> g4world;
248
255 std::shared_ptr<gdynamicdigitization::dRoutinesMap> digitization_routines_map;
256
263 static G4ThreadLocal GMagneto* gmagneto;
264
276 static G4ThreadLocal std::map<std::string, GSensitiveDetector*>* tlSDMap;
277
285 void loadDigitizationPlugins();
286
293 void assignUserLimits();
294
301 std::vector<std::unique_ptr<G4UserLimits>> user_limits;
302
310 bool digiplugins_need_reload = true;
311
319 [[nodiscard]] SystemList cloneSystemDescriptors(const SystemList& systems) const;
320
328 SystemList gsystems;
329};
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
std::shared_ptr< GLogger > log
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::unordered_map< std::string, const GMirror * > get_gmirrors_flat_map() const
Returns a flat map of GEMC mirror descriptors indexed by their qualified names.
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.
std::vector< SystemPtr > SystemList
constexpr int ERR_G4VOLUMEBUILDFAILED