16 setlocale(LC_NUMERIC,
"en_US");
27 map->
B1_2D =
new double*[map->
np[0]];
28 map->
B2_2D =
new double*[map->
np[0]];
29 for (
unsigned int i = 0; i < map->
np[0]; ++i)
31 map->
B1_2D[i] =
new double[map->
np[1]];
32 map->
B2_2D[i] =
new double[map->
np[1]];
40 double d1, d2, b1, b2;
48 FILE *fp = fopen (map->
identifier.c_str(),
"r");
51 while(tmp !=
"</mfield>")
53 fscanf(fp,
"%s", ctmp);
58 for(
int i1 = 0; i1<np_1 ; i1++)
60 for(
int i2 = 0; i2<np_2 ; i2++)
62 fscanf(fp,
"%lg %lg %lg %lg", &d1, &d2, &b1, &b2);
70 cout <<
" Loading Map: coordinates (" << d1 <<
", " << d2 <<
") values: (" << b1 <<
", " << b2 <<
")." << endl;
73 if( (min1 + i1*cell1 - d1)/d1 > 0.001)
75 cout <<
" !! Error: first coordinate index wrong. Map point should be " << min1 + i1*cell1
76 <<
" but it's " << d1 <<
" instead." << endl;
77 cout <<
" min1: " << min1 <<
" cell1: " << cell1 <<
" unit1: " << unit1 <<
" i1: " << i1 << endl;
80 if( (min2 + i2*cell2 - d2)/d2 > 0.001)
82 cout <<
" !! Error: second coordinate index wrong. Map point should be " << min2 + i2*cell2
83 <<
" but it's " << d2 <<
" instead." << endl;
84 cout <<
" min2: " << min2 <<
" cell2: " << cell2 <<
" unit2: " << unit2 <<
" i2: " << i2 << endl;
88 unsigned t1 = (unsigned) floor( ( d1 - min1 + cell1/2 ) / ( cell1 ) ) ;
89 unsigned t2 = (unsigned) floor( ( d2 - min2 + cell2/2 ) / ( cell2 ) ) ;
95 map->
B1_2D[t1][t2] = b1;
96 map->
B2_2D[t1][t2] = b2;
101 map->
B1_2D[t2][t1] = b1;
102 map->
B2_2D[t2][t1] = b2;
107 double progress = (double)i1/(
double)np_1;
108 int pos = progress*barWidth;
109 for (
int i = 0; i < barWidth; ++i)
111 if (i < pos) cout <<
"=";
112 else if (i == pos) cout <<
">";
115 cout <<
"] " << int(progress * 100.0) <<
" %\r";
131 if(symmetry ==
"cylindrical-z")
134 TC = sqrt(x[0]*x[0] + x[1]*x[1]);
135 phi = G4ThreeVector(x[0], x[1], x[2]).phi();
138 else if(symmetry ==
"cylindrical-x")
141 TC = sqrt(x[1]*x[1] + x[2]*x[2]);
142 phi = G4ThreeVector(x[2], x[0], x[1]).phi();
145 else if(symmetry ==
"cylindrical-y")
148 TC = sqrt(x[0]*x[0] + x[2]*x[2]);
149 phi = G4ThreeVector(x[1], x[2], x[0]).phi();
153 unsigned int IT = floor( ( TC - startMap[0] ) / cellSize[0] );
154 unsigned int IL = floor( ( LC - startMap[1] ) / cellSize[1] );
156 if (TC < startMap[0] || LC < startMap[1])
return;
159 if(interpolation ==
"none")
162 if( fabs( startMap[0] + IT*cellSize[0] - TC) > fabs( startMap[0] + (IT+1)*cellSize[0] - TC) ) IT++;
163 if( fabs( startMap[1] + IL*cellSize[1] - LC) > fabs( startMap[1] + (IL+1)*cellSize[1] - LC) ) IL++;
166 if(IT>=np[0] || IL>=np[1])
return;
168 if(symmetry ==
"cylindrical-z")
170 Bfield[0] = B1_2D[IT][IL] * cos(phi);
171 Bfield[1] = B1_2D[IT][IL] * sin(phi);
172 Bfield[2] = B2_2D[IT][IL];
174 else if(symmetry ==
"cylindrical-x")
176 Bfield[0] = B2_2D[IT][IL];
177 Bfield[1] = B1_2D[IT][IL] * cos(phi);
178 Bfield[2] = B1_2D[IT][IL] * sin(phi);
180 else if(symmetry ==
"cylindrical-y")
182 Bfield[1] = B2_2D[IT][IL];
183 Bfield[0] = B1_2D[IT][IL] * sin(phi);
184 Bfield[2] = B1_2D[IT][IL] * cos(phi);
187 else if (interpolation ==
"linear")
190 if (IT+1 >= np[0] || IL+1 >= np[1])
return;
193 double xtr = (TC - (startMap[0] + IT*cellSize[0])) / cellSize[0];
194 double xlr = (LC - (startMap[1] + IL*cellSize[1])) / cellSize[1];
196 double b10 = B1_2D[IT][IL] * (1.0 - xtr) + B1_2D[IT+1][IL] * xtr;
197 double b11 = B1_2D[IT][IL+1] * (1.0 - xtr) + B1_2D[IT+1][IL+1] * xtr;
198 double b1 = b10 * (1.0 - xlr) + b11 * xlr;
199 double b20 = B2_2D[IT][IL] * (1.0 - xtr) + B2_2D[IT+1][IL] * xtr;
200 double b21 = B2_2D[IT][IL+1] * (1.0 - xtr) + B2_2D[IT+1][IL+1] * xtr;
201 double b2 = b20 * (1.0 - xlr) + b21 * xlr;
203 if(symmetry ==
"cylindrical-z")
205 Bfield[0] = b1 * cos(phi);
206 Bfield[1] = b1 * sin(phi);
209 else if(symmetry ==
"cylindrical-x")
212 Bfield[1] = b1 * cos(phi);
213 Bfield[2] = b1 * sin(phi);
215 else if(symmetry ==
"cylindrical-y")
218 Bfield[0] = b1 * sin(phi);
219 Bfield[2] = b1 * cos(phi);
222 else cout <<
"unkown field interpolation method, field is not on!!!" << endl;
229 cout <<
" > Track position in magnetic field: " 230 <<
"(" << (x[0] + mapOrigin[0])/cm <<
", " 231 << (x[1] + mapOrigin[1])/cm <<
", " 232 << (x[2] + mapOrigin[2])/cm <<
") cm, " << endl;
233 cout <<
" Cylindrical: ";
234 cout <<
"loc. pos. = (" << x[0]/cm <<
", " << x[1]/cm <<
", " << x[2]/cm <<
") cm, ";
235 cout <<
"tr=" << TC/cm <<
"cm, long=" << LC/cm <<
"cm, phi=" << phi/deg <<
", ";
236 cout <<
"IT=" << IT <<
" ";
237 cout <<
"IL=" << IL <<
", ";
238 cout <<
"B = (" << Bfield[0]/gauss <<
", " << Bfield[1]/gauss <<
", " << Bfield[2]/gauss <<
") gauss " << endl;
string unit
field unit in the map
double scaleFactor
copy of the gfield scaleFactor
double get_number(string v, int warn_no_unit)
Returns number with dimension from string, i.e. 100*cm.
gcoord getCoordinateWithSpeed(int speed)
return coordinate based on speed
void GetFieldValue_Cylindrical(const double x[3], double *Bfield, int FIRST_ONLY) const
void loadFieldMap_Cylindrical(gMappedField *, double)
string identifier
Pointer to map in factory (for example, hostname / filename with path / date)