Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GlobalMagFieldMessenger.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// Class G4GlobalMagFieldMessenger implementation
27//
28// Author: Ivana Hrivnacova (IN2P3/IJCLab Orsay), 28 August 2013
29// --------------------------------------------------------------------
30
32#include "G4UniformMagField.hh"
33#include "G4FieldManager.hh"
35#include "G4UIdirectory.hh"
38#include "G4UnitsTable.hh"
39#include "G4SystemOfUnits.hh"
40
41//______________________________________________________________________________
42
44{
45 fDirectory = new G4UIdirectory("/globalField/");
46 fDirectory->SetGuidance("Global uniform magnetic field UI commands");
47
48 fSetValueCmd = new G4UIcmdWith3VectorAndUnit("/globalField/setValue",this);
49 fSetValueCmd->SetGuidance("Set uniform magnetic field value.");
50 fSetValueCmd->SetParameterName("Bx", "By", "By", false);
51 fSetValueCmd->SetUnitCategory("Magnetic flux density");
52 fSetValueCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
53
54 fSetVerboseCmd = new G4UIcmdWithAnInteger("/globalField/verbose",this);
55 fSetVerboseCmd->SetGuidance("Set verbose level: ");
56 fSetVerboseCmd->SetGuidance(" 0: no output");
57 fSetVerboseCmd->SetGuidance(" 1: printing new field value");
58 fSetVerboseCmd->SetParameterName("globalFieldVerbose", false);
59 fSetVerboseCmd->SetRange("globalFieldVerbose>=0");
60 fSetVerboseCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
61
62 // Create field
63 fMagField = new G4UniformMagField(value);
64
65 // Set field value (the field is not activated if value is zero)
66 SetField(value, "G4GlobalMagFieldMessenger::G4GlobalMagFieldMessenger");
67}
68
69//______________________________________________________________________________
70
72{
73 delete fMagField;
74 delete fSetValueCmd;
75 delete fSetVerboseCmd;
76 delete fDirectory;
77}
78
79//______________________________________________________________________________
80
81void G4GlobalMagFieldMessenger::SetField(const G4ThreeVector& value,
82 const G4String& /*inFunction*/)
83{
84 // Get field manager (or create it if it does not yet exist)
85 G4FieldManager* fieldManager
87
88 // Inactivate field if its value is zero
89 if ( value == G4ThreeVector() )
90 {
91 fieldManager->SetDetectorField(nullptr);
92 fieldManager->CreateChordFinder(nullptr);
93
94 if ( fVerboseLevel > 0 )
95 {
96 G4cout << "Magnetic field is inactive, fieldValue = (0,0,0)." << G4endl;
97 }
98 }
99 else
100 {
101 fMagField->SetFieldValue(value);
102 fieldManager->SetDetectorField(fMagField);
103 fieldManager->CreateChordFinder(fMagField);
104
105 if ( fVerboseLevel > 0 )
106 {
107 G4cout << "Magnetic field is active, fieldValue = ("
108 << G4BestUnit(value, "Magnetic flux density")
109 << ")." << G4endl;
110 }
111 }
112}
113
114//______________________________________________________________________________
115
117{
118 if ( command == fSetValueCmd )
119 {
120 SetField(fSetValueCmd->GetNew3VectorValue(newValue),
121 "G4GlobalMagFieldMessenger::SetNewValue");
122 }
123 else if ( command == fSetVerboseCmd )
124 {
125 SetVerboseLevel(fSetVerboseCmd->GetNewIntValue(newValue));
126 }
127}
128
129//______________________________________________________________________________
130
132{
133 SetField(value, "G4GlobalMagFieldMessenger::SetFieldValue");
134}
135
136//______________________________________________________________________________
137
139{
140 if ( fMagField != nullptr ) { return fMagField->GetConstantFieldValue(); }
141
142 return {};
143}
@ G4State_Idle
@ G4State_PreInit
#define G4BestUnit(a, b)
CLHEP::Hep3Vector G4ThreeVector
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4FieldManager is a manager (store) for a pointer to the Field subclass that describes the field of a...
G4bool SetDetectorField(G4Field *detectorField, G4int failMode=0)
void CreateChordFinder(G4MagneticField *detectorMagField)
void SetVerboseLevel(G4int verboseLevel)
void SetNewValue(G4UIcommand *, G4String) override
G4GlobalMagFieldMessenger(const G4ThreeVector &value=G4ThreeVector())
void SetFieldValue(const G4ThreeVector &value)
static G4TransportationManager * GetTransportationManager()
G4FieldManager * GetFieldManager() const
G4UniformMagField is a class for defining a uniform magnetic field.