40 #include "G4SystemOfUnits.hh"
50 G4cout << G4endl <<
"###### Calling QweakSimMagneticField::QweakSimMagneticField() " << G4endl << G4endl;
64 fMin.push_back(-250.0);
fMax.push_back(250.0);
fStep.push_back(2.0);
fWrap.push_back(0);
66 fMin.push_back(-0.5 * degree/radian);
fMax.push_back(360.5 * degree/radian);
fStep.push_back(1.0 * degree/radian);
fWrap.push_back(2);
69 G4double current = 8921.0;
74 G4cout << G4endl <<
"###### Leaving QweakSimMagneticField::QweakSimMagneticField " << G4endl << G4endl;
80 G4cout << G4endl <<
"###### Calling QweakSimMagneticField::~QweakSimMagneticField() " << G4endl << G4endl;
88 G4cout << G4endl <<
"###### Leaving QweakSimMagneticField::~QweakSimMagneticField() " << G4endl << G4endl;
94 G4cout << G4endl <<
"###### Calling QweakSimMagneticField::ReadFieldMap() " << G4endl << G4endl;
97 if (filename.find(
".dat") != std::string::npos) {
100 if (filename.find(
".bin") != std::string::npos) {
105 G4double point1[4] = {100.0 * cm, 0.0 * cm, 100.0 * cm, 0.0};
106 G4double exact1[3] = {-0.0499845 * kilogauss, 3.28516 * kilogauss, -0.0112704 * kilogauss};
108 G4double point2[4] = {0.0 * cm, 100.0 * cm, 100.0 * cm, 0.0};
109 G4double exact2[3] = {-3.28505 * kilogauss, -0.0030823 * kilogauss, 0.0014373 * kilogauss};
111 G4double point3[4] = {100.0 * cm, 100.0 * cm, 100.0 * cm, 0.0};
112 G4double exact3[3] = {-0.838069 * kilogauss, 0.836675 * kilogauss, 0.00004997 * kilogauss};
115 G4cout << G4endl <<
"###### Leaving QweakSimMagneticField::ReadFieldMap() " << G4endl << G4endl;
122 G4cout <<
"Calculating test field value at cartesian position "
123 <<
"(" << point[0]/cm <<
"," << point[1]/cm <<
"," << point[2]/cm <<
") cm "
125 G4double value[3] = {0.0, 0.0, 0.0};
129 G4double diff[3] = {0.0, 0.0, 0.0};
131 for (
size_t i = 0; i < 3; i++) {
132 diff[i] = value[i] - exact[i];
133 norm += diff[i] * diff[i];
138 G4cout <<
" Value = "
139 <<
"(" << value[0]/kilogauss <<
", " << value[1]/kilogauss <<
", " << value[2]/kilogauss <<
") kG."
141 G4cout <<
" Exact = "
142 <<
"(" << exact[0]/kilogauss <<
", " << exact[1]/kilogauss <<
", " << exact[2]/kilogauss <<
") kG."
145 <<
"(" << diff[0]/kilogauss <<
", " << diff[1]/kilogauss <<
", " << diff[2]/kilogauss <<
") kG."
149 if (norm > 0.1 * kilogauss) {
150 G4cerr <<
"Magnetic field is different from expected value by " << norm/kilogauss <<
" kG."
185 G4cout <<
"Reading field grid: ";
188 std::ifstream inputfile;
189 inputfile.open(filename);
190 while (inputfile.good()) {
192 if (
fField->GetCurrentEntries() % (
fField->GetMaximumEntries() / 10) == 0) {
193 int pct =
fField->GetCurrentEntries() / (
fField->GetMaximumEntries() / 100);
194 G4cout << pct <<
"%" << std::flush;
196 if (
fField->GetCurrentEntries() % (
fField->GetMaximumEntries() / 10) != 0
197 &&
fField->GetCurrentEntries() % (
fField->GetMaximumEntries() / 40) == 0) {
198 G4cout <<
"." << std::flush;
202 G4double r = 0.0, z = 0.0, phi = 0.0;
203 value_t b[3] = {0.0, 0.0, 0.0};
204 inputfile >> r >> z >> phi >> b[0] >> b[1] >> b[2];
219 if (phi < 0.0 * degree) phi += 360.0 * degree;
220 if (phi > 360.0 * degree) phi -= 360.0 * degree;
224 b[0] = b_rot[0]; b[1] = b_rot[1];
227 double coord[3] = { z/cm, r/cm, phi/radian };
249 G4cout <<
"Calculating test field value at cartesian position "
250 <<
"(" << point[0]/cm <<
"," << point[1]/cm <<
"," << point[2]/cm <<
") cm "
252 G4double value[3] = {0.0, 0.0, 0.0};
256 G4cout <<
" Value = "
257 <<
"(" << value[0]/kilogauss <<
", " << value[1]/kilogauss <<
", " << value[2]/kilogauss <<
") kG."
266 G4double y = point[1] - fTranslationVector[1];
267 G4double z = point[2] - fTranslationVector[2];
270 G4double r = sqrt(x*x + y*y);
271 G4double phi = atan2(y, x);
272 if (phi < 0.0) phi += 360.0 * degree;
280 G4double coord[3] = {z/cm, r/cm, phi/radian};
281 fField->GetValue(coord,field);
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.
void ReadFieldMapText(const G4String &filename)
std::vector< size_t > fWrap
A multi-dimensional grid of values with interpolation methods.
std::vector< double > fMax
void ReadFieldMap(const G4String &filename)
Read the field map.
void GetFieldValue(const G4double point[4], G4double *field) const
Get the field value.
void ReadFieldMapBinary(const G4String &filename)
virtual ~QweakSimMagneticField()
Virtual destructor.
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.
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.
Scans input file for /MagnetField/xyz commands.
void PrintFieldValue(const G4double point[4]) const
Print the field value.
G4ThreeVector fTranslationVector