gfields
Loading...
Searching...
No Matches
GMagneto Class Reference

Manager for magnetic fields and their associated G4FieldManager objects. More...

#include <gmagneto.h>

Public Member Functions

 GMagneto (const std::shared_ptr< GOptions > &gopts, const std::set< std::string > &required_fields={})
 Construct and initialize the magnetic field registry.
 
bool isField (const std::string &name) const
 Check whether a field with the given name exists.
 
std::vector< std::string > getFieldNames () const
 Return the configured field names.
 
std::shared_ptr< GFieldgetField (std::string name)
 Retrieve a field object by name.
 
std::shared_ptr< G4FieldManager > getFieldMgr (std::string name)
 Retrieve the G4FieldManager associated with a given field name.
 
- Public Member Functions inherited from GBase< GMagneto >
 GBase (const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
 
 GBase (const std::shared_ptr< GLogger > &logger)
 
 GBase (const GBase &)=default
 
 GBase (GBase &&) noexcept=default
 
virtual ~GBase ()
 
GBaseoperator= (const GBase &)=default
 
GBaseoperator= (GBase &&) noexcept=default
 

Static Public Member Functions

static std::shared_ptr< GFieldinitialize_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.
 
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.
 

Additional Inherited Members

- Protected Attributes inherited from GBase< GMagneto >
std::shared_ptr< GLoggerlog
 

Detailed Description

Ownership model:

  • GMagneto owns a map of field objects (GField) created via dynamic plugin loading.
  • For each field it also owns a corresponding G4FieldManager created by create_FieldManager().

Lifecycle:

Definition at line 47 of file gmagneto.h.

Constructor & Destructor Documentation

◆ GMagneto()

GMagneto::GMagneto ( const std::shared_ptr< GOptions > & gopts,
const std::set< std::string > & required_fields = {} )
explicit
Parameters
goptsShared options used for configuration and logging.
required_fieldsOptional set of field names to load. When empty, every configured field is loaded; when non-empty, only the named fields have their plugin and map loaded (so fields no volume uses are skipped).

This constructor:

  1. Builds the list of GFieldDefinition objects from options,
  2. Loads each corresponding plugin library using the factory manager,
  3. Instantiates the field and calls load_field_definitions(),
  4. Creates and stores a G4FieldManager via create_FieldManager().

Definition at line 37 of file gmagneto.cc.

Member Function Documentation

◆ getField()

std::shared_ptr< GField > GMagneto::getField ( std::string name)
inline
Parameters
nameField name key.
Returns
Shared pointer to the requested GField instance.

If the field is not found, an error is logged and execution is terminated by the logger.

Definition at line 119 of file gmagneto.h.

◆ getFieldMgr()

std::shared_ptr< G4FieldManager > GMagneto::getFieldMgr ( std::string name)
inline
Parameters
nameField name key.
Returns
Shared pointer to the requested G4FieldManager.

If the field manager is not found, an error is logged and execution is terminated by the logger.

Definition at line 133 of file gmagneto.h.

◆ getFieldNames()

std::vector< std::string > GMagneto::getFieldNames ( ) const
Returns
Sorted list of field names loaded by this manager.

Definition at line 153 of file gmagneto.cc.

◆ initialize_magnetic_field()

std::shared_ptr< GField > GMagneto::initialize_magnetic_field ( const std::shared_ptr< GOptions > & gopts,
double & field_polarity,
std::shared_ptr< GLogger > caller_log = nullptr )
static
Parameters
goptsShared options used for configuration and logging.
field_polarityOutput torus polarity derived from the global field definition.
caller_logOptional caller logger used for diagnostics.
Returns
Shared pointer to the configured global field, or nullptr when no field should be used.

This helper honors = NO_FIELD_ALL before looking at GLOBAL_FIELD_OPTION, so digitization code sees the same no-field configuration as tracking.

Definition at line 85 of file gmagneto.cc.

◆ isField()

bool GMagneto::isField ( const std::string & name) const
inline
Parameters
nameField name key.
Returns
True if name is present in the internal field map.

Definition at line 104 of file gmagneto.h.

◆ magnetic_field_magnitude_tesla()

double GMagneto::magnetic_field_magnitude_tesla ( const std::shared_ptr< GField > & magnetic_field,
const G4ThreeVector & position )
static
Parameters
magnetic_fieldField returned by initialize_magnetic_field.
positionGlobal position.
Returns
Field magnitude in Tesla, or 0 when no field was configured.

Definition at line 140 of file gmagneto.cc.


The documentation for this class was generated from the following files: