Geant4 11.3.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4FieldSetup Class Reference

The class for constructing magnetic, electromagnetic and gravity fields which strength is defined via G4Field. More...

#include <G4FieldSetup.hh>

Public Member Functions

 G4FieldSetup (const G4FieldParameters &parameters, G4Field *field, G4LogicalVolume *lv=nullptr)
 Standard constructor.
 
 ~G4FieldSetup ()
 Destructor.
 
void Clear ()
 Clear previously created setup.
 
void Update ()
 Update field setup with new field parameters.
 
void PrintInfo (G4int verboseLevel, const G4String about="created")
 Print information.
 
void SetG4Field (G4Field *field)
 Set G4 field.
 
G4FieldGetG4Field () const
 Return the instantiated field.
 
G4LogicalVolumeGetLogicalVolume () const
 Return the logical vol;ume.
 
G4EquationOfMotionGetEquation () const
 Return the equation of motion.
 
G4MagIntegratorStepperGetStepper () const
 Return the magnetic integrator stepper.
 
G4VIntegrationDriverGetIntegrationDriver () const
 Return the magnetic integrator driver.
 

Detailed Description

The class for constructing magnetic, electromagnetic and gravity fields which strength is defined via G4Field.

The equation of motion of a particle in a field and the integration method is set according to the selection in G4FieldParameters, as well as other accuracy parameters. The default values in G4FieldParameters correspond to defaults set in Geant4 (taken from Geant4 9.3 release.) As Geant4 classes to not provide access methods for these defaults, the defaults have to be checked with each new Geant4 release. TO DO: unify defaults in G4 classes and G4 parameters

Author
I. Hrivnacova; IJClab, Orsay

Definition at line 69 of file G4FieldSetup.hh.

Constructor & Destructor Documentation

◆ G4FieldSetup()

G4FieldSetup::G4FieldSetup ( const G4FieldParameters & parameters,
G4Field * field,
G4LogicalVolume * lv = nullptr )

Standard constructor.

Definition at line 85 of file G4FieldSetup.cc.

87 : fParameters(parameters), fG4Field(field), fLogicalVolume(lv)
88{
89 // Standard constructor
90
91 fMessenger = new G4FieldSetupMessenger(this);
92
93 // Get or create field manager
94 if (fLogicalVolume == nullptr) {
95 // global field
97 }
98 else {
99 // local field
100 fFieldManager = new G4FieldManager();
101 G4bool overwriteDaughtersField = true;
102 // TO DO: this parameter should be made optional for users
103 fLogicalVolume->SetFieldManager(fFieldManager, overwriteDaughtersField);
104 }
105}
bool G4bool
Definition G4Types.hh:86
static G4FieldManager * GetGlobalFieldManager()

Referenced by G4FieldSetup(), and GetIntegrationDriver().

◆ ~G4FieldSetup()

G4FieldSetup::~G4FieldSetup ( )

Destructor.

Definition at line 108 of file G4FieldSetup.cc.

109{
110 // Destructor
111 delete fG4Field;
112 delete fChordFinder;
113 delete fStepper;
114}

Member Function Documentation

◆ Clear()

void G4FieldSetup::Clear ( )

Clear previously created setup.

Definition at line 450 of file G4FieldSetup.cc.

451{
452 // First clean up previous state.
453 delete fChordFinder;
454 fChordFinder = nullptr;
455
456 if (fG4Field == nullptr) {
457 // G4cout << "fG4Field == nullptr: go to clean-up " << G4endl;
458 delete fEquation;
459 delete fDriver;
460 delete fStepper;
461 delete fChordFinder;
462 fEquation = nullptr;
463 fDriver = nullptr;
464 fStepper = nullptr;
465 fChordFinder = nullptr;
466 fFieldManager->SetChordFinder(fChordFinder);
467 fFieldManager->SetDetectorField(fG4Field);
468 }
469}

Referenced by Update().

◆ GetEquation()

G4EquationOfMotion * G4FieldSetup::GetEquation ( ) const
inline

Return the equation of motion.

Definition at line 184 of file G4FieldSetup.hh.

185{
186 // Return the equation of motion
187 return fEquation;
188}

◆ GetG4Field()

G4Field * G4FieldSetup::GetG4Field ( ) const
inline

Return the instantiated field.

Definition at line 172 of file G4FieldSetup.hh.

173{
174 // Return the instantiated field
175 return fG4Field;
176}

◆ GetIntegrationDriver()

G4VIntegrationDriver * G4FieldSetup::GetIntegrationDriver ( ) const

Return the magnetic integrator driver.

◆ GetLogicalVolume()

G4LogicalVolume * G4FieldSetup::GetLogicalVolume ( ) const
inline

Return the logical vol;ume.

Definition at line 178 of file G4FieldSetup.hh.

179{
180 // Return the logical vol;ume
181 return fLogicalVolume;
182}

◆ GetStepper()

G4MagIntegratorStepper * G4FieldSetup::GetStepper ( ) const
inline

Return the magnetic integrator stepper.

Definition at line 190 of file G4FieldSetup.hh.

191{
192 // Return the magnetic integrator stepper
193 return fStepper;
194}

◆ PrintInfo()

void G4FieldSetup::PrintInfo ( G4int verboseLevel,
const G4String about = "created" )

Print information.

Definition at line 489 of file G4FieldSetup.cc.

490{
491 if (verboseLevel == 0) return;
492
493 auto fieldType = G4FieldParameters::FieldTypeName(fParameters.GetFieldType());
494 auto isCachedMagneticField = (fParameters.GetConstDistance() > 0.);
495 if (fLogicalVolume == nullptr) {
496 fieldType = "Global";
497 }
498 else {
499 fieldType = "Local (in ";
500 fieldType.append(fLogicalVolume->GetName());
501 fieldType.append(")");
502 }
503 if (isCachedMagneticField) {
504 fieldType.append(" cached");
505 }
506
507 G4cout << fieldType << " field " << about << " with stepper ";
509 fParameters.GetStepperType())
510 << G4endl;
511
512 if (verboseLevel > 1) {
513 fParameters.PrintParameters();
514 }
515}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4String StepperTypeName(G4StepperType stepper)
Return the stepper type as a string.
static G4String FieldTypeName(G4FieldType field)
Return the field type as a string.

◆ SetG4Field()

void G4FieldSetup::SetG4Field ( G4Field * field)
inline

Set G4 field.

Definition at line 166 of file G4FieldSetup.hh.

167{
168 // Set G4 field
169 fG4Field = field;
170}

◆ Update()

void G4FieldSetup::Update ( )

Update field setup with new field parameters.

Definition at line 472 of file G4FieldSetup.cc.

473{
474 // Update field with new field parameters
475
476 Clear();
477 if (fG4Field == nullptr) {
478 // No further update needed
479 return;
480 }
481
482 CreateCachedField();
483 CreateStepper();
484 CreateChordFinder();
485 UpdateFieldManager();
486}
void Clear()
Clear previously created setup.

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