Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // $Id: G4GlobalMagFieldMessenger.cc 66536 2012-12-19 14:32:36Z ihrivnac $
27 //
28 // class G4GlobalMagFieldMessenger
29 //
30 // Implementation
31 //
32 // Implementation of the G4GlobalMagFieldMessenger class
33 //
34 // Author: Ivana Hrivnacova, 28/08/2013 (ivana@ipno.in2p3.fr)
35 // --------------------------------------------------------------------
36 
38 #include "G4UniformMagField.hh"
39 #include "G4FieldManager.hh"
41 #include "G4UIdirectory.hh"
43 #include "G4UIcmdWithAnInteger.hh"
44 #include "G4UnitsTable.hh"
45 #include "G4SystemOfUnits.hh"
46 
47 //______________________________________________________________________________
48 
50  : G4UImessenger(),
51  fMagField(0),
52  fVerboseLevel(0),
53  fDirectory(0),
54  fSetValueCmd(0),
55  fSetVerboseCmd(0)
56 {
57  fDirectory = new G4UIdirectory("/globalField/");
58  fDirectory->SetGuidance("Global uniform magnetic field UI commands");
59 
60  fSetValueCmd = new G4UIcmdWith3VectorAndUnit("/globalField/setValue",this);
61  fSetValueCmd->SetGuidance("Set uniform magnetic field value.");
62  fSetValueCmd->SetParameterName("Bx", "By", "By", false);
63  fSetValueCmd->SetUnitCategory("Magnetic flux density");
65 
66  fSetVerboseCmd = new G4UIcmdWithAnInteger("/globalField/verbose",this);
67  fSetVerboseCmd->SetGuidance("Set verbose level: ");
68  fSetVerboseCmd->SetGuidance(" 0: no output");
69  fSetVerboseCmd->SetGuidance(" 1: printing new field value");
70  fSetVerboseCmd->SetParameterName("globalFieldVerbose", false);
71  fSetVerboseCmd->SetRange("globalFieldVerbose>=0");
73 
74  // Create field
75  fMagField = new G4UniformMagField(value);
76 
77  // Set field value (the field is not activated if value is zero)
78  SetField(value, "G4GlobalMagFieldMessenger::G4GlobalMagFieldMessenger");
79 }
80 
81 //______________________________________________________________________________
82 
84 {
85  delete fMagField;
86  delete fSetValueCmd;
87  delete fSetVerboseCmd;
88  delete fDirectory;
89 }
90 
91 //______________________________________________________________________________
92 
93 void G4GlobalMagFieldMessenger::SetField(const G4ThreeVector& value,
94  const G4String& /*inFunction*/)
95 {
96  // Get field manager (or create it if it does not yet exist)
97  G4FieldManager* fieldManager
99 
100  // Inactivate field if its value is zero
101  if ( value == G4ThreeVector() )
102  {
103  fieldManager->SetDetectorField(0);
104  fieldManager->CreateChordFinder(0);
105 
106  if ( fVerboseLevel > 0 )
107  {
108  G4cout << "Magnetic field is inactive, fieldValue = (0,0,0)." << G4endl;
109  }
110  }
111  else
112  {
113  fMagField->SetFieldValue(value);
114  fieldManager->SetDetectorField(fMagField);
115  fieldManager->CreateChordFinder(fMagField);
116 
117  if ( fVerboseLevel > 0 )
118  {
119  G4cout << "Magnetic field is active, fieldValue = ("
120  << G4BestUnit(value, "Magnetic flux density")
121  << ")." << G4endl;
122  }
123  }
124 }
125 
126 //______________________________________________________________________________
127 
129 {
130  if ( command == fSetValueCmd )
131  {
132  SetField(fSetValueCmd->GetNew3VectorValue(newValue),
133  "G4GlobalMagFieldMessenger::SetNewValue");
134  }
135  else if ( command == fSetVerboseCmd )
136  {
137  SetVerboseLevel(fSetVerboseCmd->GetNewIntValue(newValue));
138  }
139 }
140 
141 //______________________________________________________________________________
142 
144 {
145  SetField(value, "G4GlobalMagFieldMessenger::SetFieldValue");
146 }
147 
148 //______________________________________________________________________________
149 
151 {
152  if ( fMagField ) return fMagField->GetConstantFieldValue();
153 
154  return G4ThreeVector();
155 }
void SetVerboseLevel(G4int verboseLevel)
void SetFieldValue(const G4ThreeVector &newFieldValue)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
CLHEP::Hep3Vector G4ThreeVector
G4bool SetDetectorField(G4Field *detectorField)
G4GlobalMagFieldMessenger(const G4ThreeVector &value=G4ThreeVector())
static G4int GetNewIntValue(const char *paramString)
void SetUnitCategory(const char *unitCategory)
static G4ThreeVector GetNew3VectorValue(const char *paramString)
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
virtual void SetNewValue(G4UIcommand *, G4String)
G4GLOB_DLL std::ostream G4cout
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void SetFieldValue(const G4ThreeVector &value)
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
G4ThreeVector GetFieldValue() const
G4ThreeVector GetConstantFieldValue() const
static G4TransportationManager * GetTransportationManager()
G4FieldManager * GetFieldManager() const
const XML_Char int const XML_Char * value
#define G4endl
Definition: G4ios.hh:61
void CreateChordFinder(G4MagneticField *detectorMagField)