9#include "G4ThreeVector.hh"
62 explicit GMagneto(
const std::shared_ptr<GOptions>& gopts,
63 const std::set<std::string>& required_fields = {});
76 const std::shared_ptr<GOptions>& gopts,
double& field_polarity,
77 std::shared_ptr<GLogger> caller_log =
nullptr);
86 const std::shared_ptr<GField>& magnetic_field,
const G4ThreeVector&
position);
89 using gFieldMap = std::unordered_map<std::string, std::shared_ptr<GField>>;
90 using gFieldMgrMap = std::unordered_map<std::string, std::shared_ptr<G4FieldManager>>;
93 std::shared_ptr<gFieldMap> fields_map;
96 std::shared_ptr<gFieldMgrMap> fields_manager;
104 bool isField(
const std::string& name)
const {
return fields_map->find(name) != fields_map->end(); }
119 std::shared_ptr<GField>
getField(std::string name) {
120 bool not_found = (fields_map->find(name) == fields_map->end());
123 return fields_map->at(name);
136 for (
const auto& [key, value] : *fields_manager) {
137 log->
info(2,
"GFieldManager >", key,
"< >", value);
140 if (fields_manager->find(name) == fields_manager->end()) {
144 return fields_manager->at(name);
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
Manager for magnetic fields and their associated G4FieldManager objects.
GMagneto(const std::shared_ptr< GOptions > &gopts, const std::set< std::string > &required_fields={})
Construct and initialize the magnetic field registry.
std::shared_ptr< G4FieldManager > getFieldMgr(std::string name)
Retrieve the G4FieldManager associated with a given field name.
std::shared_ptr< GField > getField(std::string name)
Retrieve a field object by name.
bool isField(const std::string &name) const
Check whether a field with the given name exists.
static double magnetic_field_magnitude_tesla(const std::shared_ptr< GField > &magnetic_field, const G4ThreeVector &position)
Return the magnetic-field magnitude at a position in Tesla.
std::vector< std::string > getFieldNames() const
Return the configured field names.
static std::shared_ptr< GField > initialize_magnetic_field(const std::shared_ptr< GOptions > &gopts, double &field_polarity, std::shared_ptr< GLogger > caller_log=nullptr)
Load the configured global magnetic field for code that needs direct field probes.
#define ERR_WRONG_FIELD_NOT_FOUND