27 map->
B1_3D =
new double**[map->
np[0]];
28 map->
B2_3D =
new double**[map->
np[0]];
29 map->
B3_3D =
new double**[map->
np[0]];
30 for (
unsigned i = 0; i < map->
np[0]; ++i)
32 map->
B1_3D[i] =
new double*[map->
np[1]];
33 map->
B2_3D[i] =
new double*[map->
np[1]];
34 map->
B3_3D[i] =
new double*[map->
np[1]];
35 for (
unsigned j = 0; j < map->
np[1]; ++j)
37 map->
B1_3D[i][j] =
new double[map->
np[2]];
38 map->
B2_3D[i][j] =
new double[map->
np[2]];
39 map->
B3_3D[i][j] =
new double[map->
np[2]];
50 double d1, d2, d3, b1, b2, b3;
58 FILE *fp = fopen (map->
identifier.c_str(),
"r");
61 while(tmp !=
"</mfield>")
63 fscanf(fp,
"%s", ctmp);
69 for(
int i1 = 0; i1<np_1 ; i1++)
71 for(
int i2 = 0; i2<np_2 ; i2++)
73 for(
int i3 = 0; i3<np_3 ; i3++)
75 fscanf(fp,
"%lg %lg %lg %lg %lg %lg", &d1, &d2, &d3, &b1, &b2, &b3);
85 if( (min1 + i1*cell1 - d1)/d1 > 0.001)
87 cout <<
" !! Error: coordinate index wrong. Map point should be " << min1 + i1*cell1
88 <<
" but it's " << d1 <<
" instead." << endl;
91 if( (min2 + i2*cell2 - d2)/d2 > 0.001)
93 cout <<
" !! Error: coordinate index wrong. Map point should be " << min2 + i2*cell2
94 <<
" but it's " << d2 <<
" instead." << endl;
98 if( (min3 + i3*cell3 - d3)/d3 > 0.001)
100 cout <<
" !! Error: coordinate index wrong. Map point should be " << min2 + i2*cell2
101 <<
" but it's " << d2 <<
" instead." << endl;
106 unsigned t1 = (unsigned) floor( ( d1 - min1 + cell1/2 ) / ( cell1 ) ) ;
107 unsigned t2 = (unsigned) floor( ( d2 - min2 + cell2/2 ) / ( cell2 ) ) ;
108 unsigned t3 = (unsigned) floor( ( d3 - min3 + cell3/2 ) / ( cell3 ) ) ;
115 map->
B1_3D[t1][t2][t3] = b1;
116 map->
B2_3D[t1][t2][t3] = b2;
117 map->
B3_3D[t1][t2][t3] = b3;
123 map->
B1_3D[t1][t3][t2] = b1;
124 map->
B2_3D[t1][t3][t2] = b2;
125 map->
B3_3D[t1][t3][t2] = b3;
131 map->
B1_3D[t3][t1][t2] = b1;
132 map->
B2_3D[t3][t1][t2] = b2;
133 map->
B3_3D[t3][t1][t2] = b3;
139 map->
B1_3D[t3][t2][t1] = b1;
140 map->
B2_3D[t3][t2][t1] = b2;
141 map->
B3_3D[t3][t2][t1] = b3;
147 map->
B1_3D[t2][t3][t1] = b1;
148 map->
B2_3D[t2][t3][t1] = b2;
149 map->
B3_3D[t2][t3][t1] = b3;
155 map->
B1_3D[t2][t1][t3] = b1;
156 map->
B2_3D[t2][t1][t3] = b2;
157 map->
B3_3D[t2][t1][t3] = b3;
164 double progress = (double)i1/(
double)np_1;
165 int pos = progress*barWidth;
166 for (
int i = 0; i < barWidth; ++i)
168 if (i < pos) cout <<
"=";
169 else if (i == pos) cout <<
">";
172 cout <<
"] " << int(progress * 100.0) <<
" %\r";
188 double mfield[3] = {0,0,0};
198 aC = atan2( x[1], x[0] )*rad;
199 if( aC < 0 ) aC += 360*deg;
201 tC = sqrt(x[0]*x[0] + x[1]*x[1]);
214 double dphi = aC - aLC;
217 double aaLC = fabs(aLC);
220 aI = floor( ( aaLC - startMap[0] ) / cellSize[0] );
221 tI = floor( ( tC - startMap[1] ) / cellSize[1] );
222 lI = floor( ( lC - startMap[2] ) / cellSize[2] );
225 if( fabs( startMap[0] + aI*cellSize[0] - aaLC) > fabs( startMap[0] + (aI + 1)*cellSize[0] - aaLC) ) aI++;
226 if( fabs( startMap[1] + tI*cellSize[1] - tC) > fabs( startMap[1] + (tI + 1)*cellSize[1] - tC) ) tI++;
227 if( fabs( startMap[2] + lI*cellSize[2] - lC) > fabs( startMap[2] + (lI + 1)*cellSize[2] - lC) ) lI++;
230 if(aI >= np[0] || tI >= np[1] || lI >= np[2])
return;
234 int sign = (aLC >= 0 ? 1 : -1);
238 if(interpolation ==
"none")
241 mfield[0] = B1_3D[aI][tI][lI];
242 mfield[1] = B2_3D[aI][tI][lI];
243 mfield[2] = B3_3D[aI][tI][lI];
247 Bfield[0] = sign*mfield[0] * cos(dphi/rad) - mfield[1] * sin(dphi/rad);
248 Bfield[1] = sign*mfield[0] * sin(dphi/rad) + mfield[1] * cos(dphi/rad);
249 Bfield[2] = sign*mfield[2];
254 cout <<
" > Track position in magnetic field: " 255 <<
"(" << (x[0] + mapOrigin[0])/cm <<
", " 256 << (x[1] + mapOrigin[1])/cm <<
", " 257 << (x[2] + mapOrigin[2])/cm <<
") cm, " << endl;
259 cout <<
" > Track position in magnetic field (phi, r, z): " 260 <<
"(" << aC/deg <<
" deg, " 262 << lC/cm <<
" cm) " << endl;
264 cout <<
" > Local coordinates (phi, segment, delta phi) " 265 <<
"(" << aaLC/deg <<
" deg, " 267 << dphi/deg <<
" deg) " << endl;
269 cout <<
" > Map Indexes (phi, r, z) " 272 << lI <<
") " << endl;
274 cout <<
" > Field Values (local) (Bx, By, Bz) " 275 <<
"(" << mfield[0]/tesla <<
", " 276 << mfield[1]/tesla <<
", " 277 << mfield[2]/tesla <<
") tesla " << endl;
279 cout <<
" > Field Values (absolute) (Bx, By, Bz) " 280 <<
"(" << Bfield[0]/tesla <<
", " 281 << Bfield[1]/tesla <<
", " 282 << Bfield[2]/tesla <<
") tesla " << 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.
void loadFieldMap_phiSegmented(gMappedField *, double)
gcoord getCoordinateWithSpeed(int speed)
return coordinate based on speed
void GetFieldValue_phiSegmented(const double x[3], double *Bfield, int FIRST_ONLY) const
string identifier
Pointer to map in factory (for example, hostname / filename with path / date)