trf/src/main/java/org/lcsim/recon/tracking/magfield
diff -u -r1.1 -r1.2
--- Cartesian3DMagneticFieldMap.java 25 Sep 2012 22:53:41 -0000 1.1
+++ Cartesian3DMagneticFieldMap.java 26 Sep 2012 17:19:25 -0000 1.2
@@ -18,9 +18,6 @@
{
// Storage space for the table
-// ArrayList< ArrayList< ArrayList< Double>>> _xField = new ArrayList< ArrayList< ArrayList< Double>>>();
-// ArrayList< ArrayList< ArrayList< Double>>> _yField = new ArrayList< ArrayList< ArrayList< Double>>>();
-// ArrayList< ArrayList< ArrayList< Double>>> _zField = new ArrayList< ArrayList< ArrayList< Double>>>();
double[][][] _xField;
double[][][] _yField;
double[][][] _zField;
@@ -34,7 +31,6 @@
double _xOffset;
double _yOffset;
double _zOffset;
-// boolean _invertX, _invertY, _invertZ;
public Cartesian3DMagneticFieldMap(InputStream is, double xOffset, double yOffset, double zOffset)
{
@@ -43,11 +39,9 @@
_zOffset = zOffset;
System.out.println("\n-----------------------------------------------------------"
- + "\n Magnetic field"
+ + "\n Reading Magnetic Field map"
+ "\n-----------------------------------------------------------");
-// System.out.println("\n ---> Reading the field grid from " + filename + " ... ");
-
try {
BufferedReader myInput = new BufferedReader(new InputStreamReader(new BufferedInputStream(is)));
@@ -61,14 +55,13 @@
_nx = Integer.parseInt(st.nextToken());
_ny = Integer.parseInt(st.nextToken());
_nz = Integer.parseInt(st.nextToken());
-
-// // Set up storage space for table
- _xField = new double[_nx+1][_ny+1][_nz+1];
- _yField = new double[_nx+1][_ny+1][_nz+1];
- _zField = new double[_nx+1][_ny+1][_nz+1];
-//
- //char[] buff = new char[256];
+
+ // Set up storage space for table
+ _xField = new double[_nx + 1][_ny + 1][_nz + 1];
+ _yField = new double[_nx + 1][_ny + 1][_nz + 1];
+ _zField = new double[_nx + 1][_ny + 1][_nz + 1];
+
// Ignore other header information
// The first line whose second character is '0' is considered to
// be the last line of the header.
@@ -81,7 +74,6 @@
// format is:
// x y z Bx By Bz
//
- // Read in the data
int ix, iy, iz;
double xval = 0.;
double yval = 0.;
@@ -91,8 +83,6 @@
for (iy = 0; iy < _ny; iy++) {
for (iz = 0; iz < _nz; iz++) {
thisLine = myInput.readLine();
-// System.out.println(thisLine);
- // read in the table dimensions of the file
st = new StringTokenizer(thisLine, " ");
xval = Double.parseDouble(st.nextToken());
yval = Double.parseDouble(st.nextToken());
@@ -100,7 +90,6 @@
bx = Double.parseDouble(st.nextToken());
by = Double.parseDouble(st.nextToken());
bz = Double.parseDouble(st.nextToken());
- //file >> xval >> yval >> zval >> bx >> by >> bz;
if (ix == 0 && iy == 0 && iz == 0) {
_minx = xval;
_miny = yval;
@@ -118,8 +107,6 @@
_maxz = zval;
System.out.println("\n ---> ... done reading ");
-
- // System.out.println(" Read values of field from file " + filename );
System.out.println(" ---> assumed the order: x, y, z, Bx, By, Bz "
+ "\n ---> Min values x,y,z: "
+ _minx + " " + _miny + " " + _minz + " cm "
@@ -138,7 +125,7 @@
} catch (Exception e) {
e.printStackTrace();
}
-
+
}
@Override
@@ -159,12 +146,6 @@
double yfraction = (y - _miny) / _dy;
double zfraction = (z - _minz) / _dz;
-// if (_invertX) { xfraction = 1 - xfraction;}
-// if (_invertY) { yfraction = 1 - yfraction;}
-// if (_invertZ) { zfraction = 1 - zfraction;}
-
- // Need addresses of these to pass to modf below.
- // modf uses its second argument as an OUTPUT argument.
double xdindex, ydindex, zdindex;
// Position of the point within the cuboid defined by the
@@ -182,12 +163,7 @@
double xlocal = xmodf[1];
double ylocal = ymodf[1];
double zlocal = zmodf[1];
-
-
-
-//
-
- // Full 3-dimensional version
+ // bilinear interpolation
Bfield[0] =
_xField[xindex][yindex][zindex] * (1 - xlocal) * (1 - ylocal) * (1 - zlocal)
+ _xField[xindex][yindex][zindex + 1] * (1 - xlocal) * (1 - ylocal) * zlocal
@@ -221,7 +197,7 @@
Bfield[1] = 0.0;
Bfield[2] = 0.0;
}
-
+
return new CartesianPointVector(p, Bfield[0], Bfield[1], Bfield[2]);
}