QwGeant4
QweakSimMagneticField.hh
Go to the documentation of this file.
1 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
2 #ifndef QweakSimMagneticField_h
3 #define QweakSimMagneticField_h
4 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
5 
6 // system includes
7 #include <vector>
8 
9 // geant4 includes
10 #include "G4ios.hh"
11 #include "G4String.hh"
12 #include "G4ThreeVector.hh"
13 #include "G4MagneticField.hh"
14 
15 // user includes
16 #include "QweakSimSystemOfUnits.hh"
17 
18 // user classes
19 template <class value_t, unsigned int value_n>
20 class QweakSimFieldMap;
22 
23 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
24 class QweakSimMagneticField: public G4MagneticField
25 {
26  private:
27 
28  /// Number of field component in the map (x,y,z,r,phi)
29  static const unsigned int value_n = 3;
30 
31  /// Field map storage data type
32  typedef float value_t;
33 
34  /// Messenger
36 
37  public:
38 
39  /// Default constructor
41  /// Virtual destructor
42  virtual ~QweakSimMagneticField();
43 
44 
45  /// Get the field value
46  void GetFieldValue(const G4double point[4], G4double *field) const;
47 
48  /// Print the field value
49  void PrintFieldValue(const G4double point[4]) const;
50 
51 
52  /// Set the scale factor
53  void SetScaleFactor(const double scalefactor) {
54  fScaleFactor = scalefactor;
55  G4cout << "Magnetic field scale factor is now: " << fScaleFactor << G4endl;
56  };
57  /// Get the scale factor
58  double GetScaleFactor() const { return fScaleFactor; };
59 
60  /// Set the reference current
61  void SetReferenceCurrent(const double referencecurrent) {
62  fReferenceCurrent = referencecurrent;
63  G4cout << "Magnetic field reference current is now: " << fReferenceCurrent << G4endl;
64  if (fReferenceCurrent != 0)
66  };
67  /// Get the reference current
68  double GetReferenceCurrent() const { return fReferenceCurrent; };
69 
70  /// Set the actual current
71  void SetActualCurrent(const double actualcurrent) {
72  fActualCurrent = actualcurrent;
73  G4cout << "Magnetic field actual current is now: " << fActualCurrent << G4endl;
74  if (fReferenceCurrent != 0)
76  };
77  /// Get the actual current
78  double GetActualCurrent() const { return fActualCurrent; };
79 
80 
81  /// Set the field rotation around z
82  void SetRotation(const double rotation) {
83  fRotation = rotation;
84  fRotationCos = cos(rotation);
85  fRotationSin = sin(rotation);
86  G4cout << "Magnetic field rotation is now: " << fRotation/degree << " degree" << G4endl;
87  };
88  /// Get the field rotation around z
89  double GetRotation() const { return fRotation; };
90 
91  /// Set the field translation along z
92  void SetTranslation(const double translation) {
93  fTranslation = translation;
94  G4cout << "Magnetic field translation is now: " << fTranslation/cm << " cm" << G4endl;
95  };
96  /// Get the field translation along z
97  double GetTranslation() const { return fTranslation; };
98 
99  /// Set the field translation vector
100  void SetTranslationVector(const G4ThreeVector translationvector) {
101  fTranslationVector = translationvector;
102  G4cout << "Magnetic field translation is now: " << fTranslationVector/cm << " cm" << G4endl;
103  };
104  /// Get the field translation vector
105  G4ThreeVector GetTranslationVector() const { return fTranslationVector; };
106 
107 
108  /// Set the minimum
109  void SetMinimum(const double value, const int i) {
110  fMin.at(i) = value;
111  G4cout << "Magnetic field grid min " << i << " is " << fMin.at(i) << " cm/radian" << G4endl;
112  };
113  /// Set the maximum
114  void SetMaximum(const double value, const int i) {
115  fMax.at(i) = value;
116  G4cout << "Magnetic field grid max " << i << " is " << fMax.at(i) << " cm/radian" << G4endl;
117  };
118  /// Set the step
119  void SetStep(const double value, const int i) {
120  fStep.at(i) = value;
121  G4cout << "Magnetic field grid step " << i << " is " << fStep.at(i) << " cm/radian" << G4endl;
122  };
123  /// Set the wrap
124  void SetWrap(const int value, const int i) {
125  fWrap.at(i) = value;
126  G4cout << "Magnetic field grid wrap " << i << " is " << fWrap.at(i) << G4endl;
127  };
128 
129 
130  /// Read the field map
131  void ReadFieldMap(const G4String& filename);
132  void ReadFieldMapText(const G4String& filename);
133  void ReadFieldMapBinary(const G4String& filename);
134 
135  /// Test the field map
136  void TestFieldMap(const G4double point[4], const G4double exact[3]) const;
137 
138  private:
139 
141 
142  /// Field rotation and translation with respect to the z axis
143  // Defined as rotation/translation of the map in the standard coordinate
144  // system: rotation of +22.5 deg means that x in the map x is at +22.5 deg,
145  // likewise a translation of +5 cm means that the zero in the map is at +5 cm
146  // in the standard coordinate system.
148  double fTranslation;
149  G4ThreeVector fTranslationVector;
150 
151  /// Field map reference and actual currents
152  double fScaleFactor;
155 
156  /// Field map grid definitions
157  std::vector<double> fMin, fMax, fStep;
158  std::vector<size_t> fWrap;
159 };
160 
161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
162 #endif
QweakSimFieldMap< value_t, value_n > * fField
void SetTranslationVector(const G4ThreeVector translationvector)
Set the field translation vector.
void SetTranslation(const double translation)
Set the field translation along z.
QweakSimMagneticFieldMessenger * fMagneticFieldMessenger
Messenger.
double GetActualCurrent() const
Get the actual current.
void ReadFieldMapText(const G4String &filename)
std::vector< size_t > fWrap
A multi-dimensional grid of values with interpolation methods.
void SetWrap(const int value, const int i)
Set the wrap.
void SetReferenceCurrent(const double referencecurrent)
Set the reference current.
std::vector< double > fMax
void ReadFieldMap(const G4String &filename)
Read the field map.
static const unsigned int value_n
Number of field component in the map (x,y,z,r,phi)
void GetFieldValue(const G4double point[4], G4double *field) const
Get the field value.
double GetRotation() const
Get the field rotation around z.
void ReadFieldMapBinary(const G4String &filename)
double GetScaleFactor() const
Get the scale factor.
virtual ~QweakSimMagneticField()
Virtual destructor.
void SetScaleFactor(const double scalefactor)
Set the scale factor.
double GetReferenceCurrent() const
Get the reference current.
void SetStep(const double value, const int i)
Set the step.
double fRotation
Field rotation and translation with respect to the z axis.
std::vector< double > fMin
Field map grid definitions.
QweakSimMagneticField()
Default constructor.
void SetRotation(const double rotation)
Set the field rotation around z.
double fScaleFactor
Field map reference and actual currents.
G4ThreeVector GetTranslationVector() const
Get the field translation vector.
double GetTranslation() const
Get the field translation along z.
void TestFieldMap(const G4double point[4], const G4double exact[3]) const
Test the field map.
std::vector< double > fStep
float value_t
Field map storage data type.
void SetMaximum(const double value, const int i)
Set the maximum.
Scans input file for /MagnetField/xyz commands.
void PrintFieldValue(const G4double point[4]) const
Print the field value.
void SetMinimum(const double value, const int i)
Set the minimum.
void SetActualCurrent(const double actualcurrent)
Set the actual current.