60 double fieldUnit= tesla;
61 G4cout <<
"\n-----------------------------------------------------------"
62 <<
"\n Magnetic field"
63 <<
"\n-----------------------------------------------------------"
64 <<
"\n ---> " "Reading the field grid from " << filename <<
" ... " << endl;
65 ifstream file( filename );
67 cout <<
"Field map input file error." << endl;
70 file.getline(buffer,256);
72 G4cout <<
" [ Number of values x,y,z: "
73 << nx <<
" " << ny <<
" " << nz <<
" ] "
81 for (ix=0; ix<nx; ix++)
83 xField[ix].resize(ny);
84 yField[ix].resize(ny);
85 zField[ix].resize(ny);
86 for (iy=0; iy<ny; iy++)
88 xField[ix][iy].resize(nz);
89 yField[ix][iy].resize(nz);
90 zField[ix][iy].resize(nz);
95 double xval,yval,zval,bx,by,bz;
97 minx = miny = minz = maxx = maxy = maxz = 0;
99 for (ix=0; ix<nx; ix++)
101 for (iy=0; iy<ny; iy++)
103 for (iz=0; iz<nz; iz++)
106 file >> xval >> yval >> zval >> bx >> by >> bz;
119 xField[ix][iy][iz] = bx * fieldUnit;
120 yField[ix][iy][iz] = by * fieldUnit;
121 zField[ix][iy][iz] = bz * fieldUnit;
127 G4cout <<
"\n ---> ... done reading " << endl;
136 MYSQL_RES* resLimits;
140 con = mysql_init(
NULL);
144 cout << mysql_error(con) << endl;
149 double fieldUnit= tesla;
151 G4cout <<
"\n-----------------------------------------------------------"
152 <<
"\n Magnetic field"
153 <<
"\n-----------------------------------------------------------\n";
155 G4cout <<
" [ Number of values x,y,z: "
156 << nx <<
" " << ny <<
" " << nz <<
" ] "
164 for (ix=0; ix<nx; ix++)
166 xField[ix].resize(ny);
167 yField[ix].resize(ny);
168 zField[ix].resize(ny);
169 for (iy=0; iy<ny; iy++)
171 xField[ix][iy].resize(nz);
172 yField[ix][iy].resize(nz);
173 zField[ix][iy].resize(nz);
177 float xval,yval,zval,bx,by,bz;
181 mysql_query(con,
"SELECT minX, minY, minZ, maxX, maxY, maxZ FROM Fmag_limits");
182 cout << mysql_error(con) << endl;
183 resLimits = mysql_store_result(con);
187 mysql_query(con,
"SELECT minX, minY, minZ, maxX, maxY, maxZ FROM Kmag_limits");
188 cout << mysql_error(con) << endl;
189 resLimits = mysql_store_result(con);
192 row = mysql_fetch_row(resLimits);
194 minx = atof(row[0]) * cm;
195 miny = atof(row[1]) * cm;
196 minz = atof(row[2]) * cm;
197 maxx = atof(row[3]) * cm;
198 maxy = atof(row[4]) * cm;
199 maxz = atof(row[5]) * cm;
201 mysql_free_result(resLimits);
205 mysql_query(con,
"SELECT x, y, z, B_x, B_y, B_z FROM Fmag");
206 cout << mysql_error(con) << endl;
207 resField = mysql_store_result(con);
211 mysql_query(con,
"SELECT x, y, z, B_x, B_y, B_z FROM Kmag");
212 cout << mysql_error(con) << endl;
213 resField = mysql_store_result(con);
218 while ((row = mysql_fetch_row(resField)))
227 xc = floor((xval*cm-minx)*(nx-1)/(maxx-minx)+0.5);
228 yc = floor((yval*cm-miny)*(ny-1)/(maxy-miny)+0.5);
229 zc = floor((zval*cm-minz)*(nz-1)/(maxz-minz)+0.5);
231 xField[xc][yc][zc] = bx*fieldUnit;
232 yField[xc][yc][zc] = by*fieldUnit;
233 zField[xc][yc][zc] = bz*fieldUnit;
236 mysql_free_result(resField);
238 G4cout <<
"\n ---> ... done reading " << endl;
243 G4cout <<
"\n ---> Min values x,y,z: "
244 << minx/cm <<
" " << miny/cm <<
" " << minz/cm <<
" cm "
245 <<
"\n ---> Max values x,y,z: "
246 << maxx/cm <<
" " << maxy/cm <<
" " << maxz/cm <<
" cm "
247 <<
"\n ---> The field will be offset by " << zOffset/cm <<
" cm " << endl;
253 G4cout <<
"\n ---> Dif values x,y,z (range): "
254 << dx/cm <<
" " << dy/cm <<
" " << dz/cm <<
" cm in z "
255 <<
"\n-----------------------------------------------------------" << endl;
268 z = point[2] + fZoffset;
271 if ( x>=minx && x<=maxx &&
272 y>=miny && y<=maxy &&
277 double xfraction = (x - minx) / dx;
278 double yfraction = (y - miny) / dy;
279 double zfraction = (z - minz) / dz;
283 double xdIndex, ydIndex, zdIndex;
287 double xlocal = ( std::modf(xfraction*(nx-1), &xdIndex));
288 double ylocal = ( std::modf(yfraction*(ny-1), &ydIndex));
289 double zlocal = ( std::modf(zfraction*(nz-1), &zdIndex));
293 int xindex =
static_cast<int>(xdIndex);
294 int yindex =
static_cast<int>(ydIndex);
295 int zindex =
static_cast<int>(zdIndex);
299 xField[xindex ][yindex ][zindex ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
300 xField[xindex ][yindex ][zindex+1] * (1-xlocal) * (1-ylocal) * zlocal +
301 xField[xindex ][yindex+1][zindex ] * (1-xlocal) * ylocal * (1-zlocal) +
302 xField[xindex ][yindex+1][zindex+1] * (1-xlocal) * ylocal * zlocal +
303 xField[xindex+1][yindex ][zindex ] * xlocal * (1-ylocal) * (1-zlocal) +
304 xField[xindex+1][yindex ][zindex+1] * xlocal * (1-ylocal) * zlocal +
305 xField[xindex+1][yindex+1][zindex ] * xlocal * ylocal * (1-zlocal) +
306 xField[xindex+1][yindex+1][zindex+1] * xlocal * ylocal * zlocal ;
308 yField[xindex ][yindex ][zindex ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
309 yField[xindex ][yindex ][zindex+1] * (1-xlocal) * (1-ylocal) * zlocal +
310 yField[xindex ][yindex+1][zindex ] * (1-xlocal) * ylocal * (1-zlocal) +
311 yField[xindex ][yindex+1][zindex+1] * (1-xlocal) * ylocal * zlocal +
312 yField[xindex+1][yindex ][zindex ] * xlocal * (1-ylocal) * (1-zlocal) +
313 yField[xindex+1][yindex ][zindex+1] * xlocal * (1-ylocal) * zlocal +
314 yField[xindex+1][yindex+1][zindex ] * xlocal * ylocal * (1-zlocal) +
315 yField[xindex+1][yindex+1][zindex+1] * xlocal * ylocal * zlocal ;
317 zField[xindex ][yindex ][zindex ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
318 zField[xindex ][yindex ][zindex+1] * (1-xlocal) * (1-ylocal) * zlocal +
319 zField[xindex ][yindex+1][zindex ] * (1-xlocal) * ylocal * (1-zlocal) +
320 zField[xindex ][yindex+1][zindex+1] * (1-xlocal) * ylocal * zlocal +
321 zField[xindex+1][yindex ][zindex ] * xlocal * (1-ylocal) * (1-zlocal) +
322 zField[xindex+1][yindex ][zindex+1] * xlocal * (1-ylocal) * zlocal +
323 zField[xindex+1][yindex+1][zindex ] * xlocal * ylocal * (1-zlocal) +
324 zField[xindex+1][yindex+1][zindex+1] * xlocal * ylocal * zlocal ;
TabulatedField3D(double, int, int, int, bool, Settings *)
void GetFieldValue(const double Point[3], double *Bfield) const