15 setlocale(LC_NUMERIC,
"en_US");
23 double cell1 = (max1 - min1)/(np_1 - 1);
24 double cell2 = (max2 - min2)/(np_2 - 1);
28 map->
B1_2D =
new double*[map->
np[0]];
29 for (
unsigned int i = 0; i < map->
np[0]; ++i)
30 map->
B1_2D[i] =
new double[map->
np[1]];
46 FILE *fp = fopen (map->
identifier.c_str(),
"r");
49 while(tmp !=
"</mfield>")
51 fscanf(fp,
"%s", ctmp);
57 for(
int i1 = 0; i1<np_1 ; i1++)
59 for(
int i2 = 0; i2<np_2 ; i2++)
61 fscanf(fp,
"%lg %lg %lg", &d1, &d2, &b);
69 cout <<
" Loading Map: coordinates (" << d1 <<
", " << d2 <<
") value: " << b << endl;
73 if( (min1 + i1*cell1 - d1)/d1 > 0.001)
75 cout <<
" !! Error: coordinate index wrong. Map first point should be " << min1 + i1*cell1
76 <<
" but it's " << d1 <<
" instead. Cell size: " << cell1 <<
" min: " << min1 <<
" max : " << max1 <<
" index: " << i1 << endl;
79 if( (min2 + i2*cell2 - d2)/d2 > 0.001)
81 cout <<
" !! Error: coordinate index wrong. Map second point should be " << min2 + i2*cell2
82 <<
" but it's " << d2 <<
" instead. Cell size: " << cell2 <<
" min: " << min2 <<
" max : " << max2 <<
" index: " << i2 << endl;
86 unsigned t1 = (unsigned) floor( ( d1 - min1 + cell1/2 ) / ( cell1 ) ) ;
87 unsigned t2 = (unsigned) floor( ( d2 - min2 + cell2/2 ) / ( cell2 ) ) ;
92 map->
B1_2D[t1][t2] = b;
96 map->
B1_2D[t2][t1] = b;
101 double progress = (double)i1/(
double)np_1;
102 int pos = progress*barWidth;
103 for (
int i = 0; i < barWidth; ++i)
105 if (i < pos) cout <<
"=";
106 else if (i == pos) cout <<
">";
109 cout <<
"] " << int(progress * 100.0) <<
" %\r";
123 if(symmetry ==
"dipole-x")
128 if(symmetry ==
"dipole-y")
133 if(symmetry ==
"dipole-z")
140 unsigned int IL = floor( ( LC - startMap[0] ) / cellSize[0] );
141 unsigned int IT = floor( ( TC - startMap[1] ) / cellSize[1] );
144 if( fabs( startMap[0] + IL*cellSize[0] - LC) > fabs( startMap[0] + (IL+1)*cellSize[0] - LC) ) IL++;
145 if( fabs( startMap[1] + IT*cellSize[1] - TC) > fabs( startMap[1] + (IT+1)*cellSize[1] - TC) ) IT++;
148 if(IL>=np[0] || IT>=np[1])
return;
151 if(interpolation ==
"none")
153 if(symmetry ==
"dipole-x") Bfield[0] = B1_2D[IL][IT];
154 if(symmetry ==
"dipole-y") Bfield[1] = B1_2D[IL][IT];
155 if(symmetry ==
"dipole-z") Bfield[2] = B1_2D[IL][IT];
163 cout <<
" > Track position in magnetic field: " 164 <<
"(" << (x[0] + mapOrigin[0])/cm <<
", " 165 << (x[1] + mapOrigin[1])/cm <<
", " 166 << (x[2] + mapOrigin[2])/cm <<
") cm, " << endl;
168 cout <<
"loc. pos. = (" << x[0]/cm <<
", " << x[1]/cm <<
", " << x[2]/cm <<
") cm, ";
169 cout <<
"IT=" << IT <<
" ";
170 cout <<
"IL=" << IL <<
", ";
171 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
void GetFieldValue_Dipole(const double x[3], double *Bfield, int FIRST_ONLY) const
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 loadFieldMap_Dipole(gMappedField *, double)
string identifier
Pointer to map in factory (for example, hostname / filename with path / date)