Commit in projects/lcsim/trunk/trf on MAIN
pom.xml+53087 -> 3088
src/main/java/org/lcsim/recon/tracking/magfield/Cartesian3DMagneticFieldMap.java+41-93087 -> 3088
                                               /SplineFit1DMagneticFieldMap.java+109added 3088
src/main/resources/org/lcsim/recon/tracking/magfield/HPS_b18d36_By_0_0_z.dat+301added 3088
src/test/java/org/lcsim/recon/tracking/magfield/Cartesian3DMagneticFieldMapTest.java+75-553087 -> 3088
                                               /SplineFit1DMagneticFieldMapTest.java+70added 3088
+601-64
3 added + 3 modified, total 6 files
adding support for spline fit of one component of the magnetic field as a function of one Cartesian coordinate.

projects/lcsim/trunk/trf
pom.xml 3087 -> 3088
--- projects/lcsim/trunk/trf/pom.xml	2014-04-04 21:51:04 UTC (rev 3087)
+++ projects/lcsim/trunk/trf/pom.xml	2014-04-08 20:24:39 UTC (rev 3088)
@@ -21,6 +21,11 @@
     
     <dependencies>
         <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-math</artifactId>
+            <version>2.2</version>
+        </dependency>
+        <dependency>
             <groupId>org.lcsim</groupId>
             <artifactId>lcsim-math</artifactId>
         </dependency>

projects/lcsim/trunk/trf/src/main/java/org/lcsim/recon/tracking/magfield
Cartesian3DMagneticFieldMap.java 3087 -> 3088
--- projects/lcsim/trunk/trf/src/main/java/org/lcsim/recon/tracking/magfield/Cartesian3DMagneticFieldMap.java	2014-04-04 21:51:04 UTC (rev 3087)
+++ projects/lcsim/trunk/trf/src/main/java/org/lcsim/recon/tracking/magfield/Cartesian3DMagneticFieldMap.java	2014-04-08 20:24:39 UTC (rev 3088)
@@ -17,19 +17,20 @@
 public class Cartesian3DMagneticFieldMap extends AbstractMagneticField
 {
     // Storage space for the table
-    double[][][] _xField;
-    double[][][] _yField;
-    double[][][] _zField;
+
+    private double[][][] _xField;
+    private double[][][] _yField;
+    private double[][][] _zField;
     // The dimensions of the table
-    int _nx, _ny, _nz;
+    private int _nx, _ny, _nz;
     // The physical limits of the defined region
-    double _minx, _maxx, _miny, _maxy, _minz, _maxz;
+    private double _minx, _maxx, _miny, _maxy, _minz, _maxz;
     // The physical extent of the defined region
-    double _dx, _dy, _dz;
+    private double _dx, _dy, _dz;
     // Offsets if field map is not in global coordinates
-    double _xOffset;
-    double _yOffset;
-    double _zOffset;
+    private double _xOffset;
+    private double _yOffset;
+    private double _zOffset;
 
     public Cartesian3DMagneticFieldMap(InputStream is, double xOffset, double yOffset, double zOffset)
     {
@@ -206,6 +207,37 @@
         throw new UnsupportedOperationException("Not supported yet.");
     }
 
+    public double minX()
+    {
+        return _minx + _xOffset;
+    }
+
+    public double minY()
+    {
+        return _miny + _yOffset;
+    }
+
+    public double minZ()
+    {
+        return _minz + _zOffset;
+    }
+    
+   public double maxX()
+    {
+        return _maxx + _xOffset;
+    }
+
+    public double maxY()
+    {
+        return _maxy + _yOffset;
+    }
+
+    public double maxZ()
+    {
+        return _maxz + _zOffset;
+    }    
+    
+
     private double[] modf(double fullDouble)
     {
         int intVal = (int) fullDouble;

projects/lcsim/trunk/trf/src/main/java/org/lcsim/recon/tracking/magfield
SplineFit1DMagneticFieldMap.java added at 3088
--- projects/lcsim/trunk/trf/src/main/java/org/lcsim/recon/tracking/magfield/SplineFit1DMagneticFieldMap.java	                        (rev 0)
+++ projects/lcsim/trunk/trf/src/main/java/org/lcsim/recon/tracking/magfield/SplineFit1DMagneticFieldMap.java	2014-04-08 20:24:39 UTC (rev 3088)
@@ -0,0 +1,109 @@
+package org.lcsim.recon.tracking.magfield;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.commons.math.ArgumentOutsideDomainException;
+import org.apache.commons.math.analysis.interpolation.SplineInterpolator;
+import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
+import org.lcsim.recon.tracking.spacegeom.CartesianPointVector;
+import org.lcsim.recon.tracking.spacegeom.SpacePoint;
+import org.lcsim.recon.tracking.spacegeom.SpacePointTensor;
+import org.lcsim.recon.tracking.spacegeom.SpacePointVector;
+
+/**
+ *
+ * @author Norman A Graf
+ *
+ * @version $Id:
+ */
+public class SplineFit1DMagneticFieldMap extends AbstractMagneticField
+{
+
+    private SplineInterpolator _interpolator = new SplineInterpolator();
+    private PolynomialSplineFunction _spline;
+
+    private COORDINATE _coord;
+    private BVAL _bval;
+
+    public enum COORDINATE
+    {
+
+        X(0, "x"), Y(1, "y"), Z(2, "z");
+        private int _numVal;
+        private String _stringVal;
+
+        COORDINATE(int numVal, String stringVal)
+        {
+            this._numVal = numVal;
+            this._stringVal = stringVal;
+        }
+
+        public int numVal()
+        {
+            return _numVal;
+        }
+
+        public String stringVal()
+        {
+            return _stringVal;
+        }
+    }
+
+    public enum BVAL
+    {
+
+        BX(0, "Bx"), BY(1, "By"), BZ(2, "Bz");
+        private int _numVal;
+        private String _stringVal;
+
+        BVAL(int numVal, String stringVal)
+        {
+            this._numVal = numVal;
+            this._stringVal = stringVal;
+        }
+
+        public int numVal()
+        {
+            return _numVal;
+        }
+
+        public String stringVal()
+        {
+            return _stringVal;
+        }
+
+    }
+
+    public SplineFit1DMagneticFieldMap(COORDINATE coord, double[] pos, BVAL bval, double[] val)
+    {
+        _coord = coord;
+        _bval = bval;
+        _spline = _interpolator.interpolate(pos, val);
+    }
+
+    @Override
+    public SpacePointVector field(SpacePoint p)
+    {
+        double[] b = {0., 0., 0.};
+        double v = p.getCartesianArray()[_coord.numVal()];
+        int index = _bval.numVal();
+        try {
+            b[index] = _spline.value(v);
+        } catch (ArgumentOutsideDomainException ex) {
+            ex.printStackTrace();
+        }
+        return new CartesianPointVector(p, b[0], b[1], b[2]);
+    }
+
+    @Override
+    public SpacePointVector field(SpacePoint p, SpacePointTensor g)
+    {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    public String toString()
+    {
+        return "1D magnetic field returning " + _bval.stringVal() + " as a function of " + _coord.stringVal();
+    }
+
+}

projects/lcsim/trunk/trf/src/main/resources/org/lcsim/recon/tracking/magfield
HPS_b18d36_By_0_0_z.dat added at 3088
--- projects/lcsim/trunk/trf/src/main/resources/org/lcsim/recon/tracking/magfield/HPS_b18d36_By_0_0_z.dat	                        (rev 0)
+++ projects/lcsim/trunk/trf/src/main/resources/org/lcsim/recon/tracking/magfield/HPS_b18d36_By_0_0_z.dat	2014-04-08 20:24:39 UTC (rev 3088)
@@ -0,0 +1,301 @@
+0 -0.5006
+0.5 -0.5006
+1 -0.5006
+1.5 -0.5006
+2 -0.5006
+2.5 -0.5006
+3 -0.5006
+3.5 -0.5006
+4 -0.5006
+4.5 -0.5006
+5 -0.5006
+5.5 -0.5006
+6 -0.5006
+6.5 -0.5006
+7 -0.5006
+7.5 -0.5006
+8 -0.5006
+8.5 -0.5006
+9 -0.5006
+9.5 -0.5006
+10 -0.5006
+10.5 -0.5006
+11 -0.5006
+11.5 -0.5006
+12 -0.5006
+12.5 -0.5006
+13 -0.5006
+13.5 -0.5006
+14 -0.5006
+14.5 -0.5006
+15 -0.5006
+15.5 -0.5005
+16 -0.5005
+16.5 -0.5005
+17 -0.5005
+17.5 -0.5005
+18 -0.5005
+18.5 -0.5005
+19 -0.5005
+19.5 -0.5005
+20 -0.5005
+20.5 -0.5005
+21 -0.5005
+21.5 -0.5005
+22 -0.5004
+22.5 -0.5004
+23 -0.5004
+23.5 -0.5004
+24 -0.5004
+24.5 -0.5003
+25 -0.5003
+25.5 -0.5002
+26 -0.5002
+26.5 -0.5001
+27 -0.5001
+27.5 -0.5
+28 -0.4999
+28.5 -0.4998
+29 -0.4997
+29.5 -0.4995
+30 -0.4994
+30.5 -0.4992
+31 -0.4989
+31.5 -0.4987
+32 -0.4984
+32.5 -0.4981
+33 -0.4978
+33.5 -0.4973
+34 -0.4967
+34.5 -0.4961
+35 -0.4953
+35.5 -0.4945
+36 -0.4935
+36.5 -0.4925
+37 -0.4914
+37.5 -0.49
+38 -0.4883
+38.5 -0.4863
+39 -0.484
+39.5 -0.4814
+40 -0.4786
+40.5 -0.4754
+41 -0.4719
+41.5 -0.4679
+42 -0.4634
+42.5 -0.4584
+43 -0.4528
+43.5 -0.4467
+44 -0.44
+44.5 -0.4329
+45 -0.4252
+45.5 -0.417
+46 -0.4082
+46.5 -0.3991
+47 -0.3896
+47.5 -0.3798
+48 -0.3696
+48.5 -0.3593
+49 -0.3489
+49.5 -0.3385
+50 -0.3279
+50.5 -0.3175
+51 -0.3071
+51.5 -0.297
+52 -0.2869
+52.5 -0.2771
+53 -0.2675
+53.5 -0.2582
+54 -0.2492
+54.5 -0.2404
+55 -0.2319
+55.5 -0.2237
+56 -0.2158
+56.5 -0.2082
+57 -0.2008
+57.5 -0.1937
+58 -0.1869
+58.5 -0.1803
+59 -0.174
+59.5 -0.1679
+60 -0.162
+60.5 -0.1564
+61 -0.151
+61.5 -0.1458
+62 -0.1408
+62.5 -0.1359
+63 -0.1313
+63.5 -0.1268
+64 -0.1225
+64.5 -0.1184
+65 -0.1144
+65.5 -0.1106
+66 -0.1069
+66.5 -0.1033
+67 -0.0999
+67.5 -0.0966
+68 -0.0934
+68.5 -0.0904
+69 -0.0874
+69.5 -0.0846
+70 -0.0818
+70.5 -0.0792
+71 -0.0766
+71.5 -0.0742
+72 -0.0718
+72.5 -0.0695
+73 -0.0673
+73.5 -0.0652
+74 -0.0632
+74.5 -0.0612
+75 -0.0593
+75.5 -0.0575
+76 -0.0557
+76.5 -0.054
+77 -0.0523
+77.5 -0.0507
+78 -0.0492
+78.5 -0.0477
+79 -0.0463
+79.5 -0.0449
+80 -0.0435
+80.5 -0.0422
+81 -0.041
+81.5 -0.0398
+82 -0.0386
+82.5 -0.0375
+83 -0.0364
+83.5 -0.0353
+84 -0.0343
+84.5 -0.0333
+85 -0.0324
+85.5 -0.0315
+86 -0.0306
+86.5 -0.0297
+87 -0.0289
+87.5 -0.0282
+88 -0.0275
+88.5 -0.0268
+89 -0.0261
+89.5 -0.0254
+90 -0.0247
+90.5 -0.0241
+91 -0.0234
+91.5 -0.0228
+92 -0.0222
+92.5 -0.0216
+93 -0.021
+93.5 -0.0204
+94 -0.0198
+94.5 -0.0193
+95 -0.0188
+95.5 -0.0183
+96 -0.0178
+96.5 -0.0173
+97 -0.0168
+97.5 -0.0163
+98 -0.0159
+98.5 -0.0154
+99 -0.015
+99.5 -0.0146
+100 -0.0142
+100.5 -0.0139
+101 -0.0135
+101.5 -0.0131
+102 -0.0128
+102.5 -0.0125
+103 -0.0122
+103.5 -0.0119
+104 -0.0116
+104.5 -0.0113
+105 -0.0111
+105.5 -0.0109
+106 -0.0106
+106.5 -0.0104
+107 -0.0102
+107.5 -0.01
+108 -0.0099
+108.5 -0.0097
+109 -0.0095
+109.5 -0.0093
+110 -0.0091
+110.5 -0.0089
+111 -0.0087
+111.5 -0.0085
+112 -0.0083
+112.5 -0.0081
+113 -0.0079
+113.5 -0.0078
+114 -0.0076
+114.5 -0.0074
+115 -0.0073
+115.5 -0.0071
+116 -0.0069
+116.5 -0.0068
+117 -0.0066
+117.5 -0.0065
+118 -0.0064
+118.5 -0.0062
+119 -0.0061
+119.5 -0.006
+120 -0.0058
+120.5 -0.0057
+121 -0.0056
+121.5 -0.0055
+122 -0.0054
+122.5 -0.0052
+123 -0.0051
+123.5 -0.005
+124 -0.0049
+124.5 -0.0048
+125 -0.0047
+125.5 -0.0047
+126 -0.0046
+126.5 -0.0045
+127 -0.0044
+127.5 -0.0043
+128 -0.0043
+128.5 -0.0042
+129 -0.0041
+129.5 -0.0041
+130 -0.004
+130.5 -0.0039
+131 -0.0038
+131.5 -0.0038
+132 -0.0037
+132.5 -0.0037
+133 -0.0036
+133.5 -0.0035
+134 -0.0035
+134.5 -0.0034
+135 -0.0033
+135.5 -0.0033
+136 -0.0032
+136.5 -0.0032
+137 -0.0031
+137.5 -0.0031
+138 -0.003
+138.5 -0.003
+139 -0.0029
+139.5 -0.0029
+140 -0.0028
+140.5 -0.0028
+141 -0.0027
+141.5 -0.0027
+142 -0.0026
+142.5 -0.0026
+143 -0.0025
+143.5 -0.0025
+144 -0.0025
+144.5 -0.0024
+145 -0.0024
+145.5 -0.0023
+146 -0.0023
+146.5 -0.0023
+147 -0.0022
+147.5 -0.0022
+148 -0.0022
+148.5 -0.0021
+149 -0.0021
+149.5 -0.0021
+150 -0.0021

projects/lcsim/trunk/trf/src/test/java/org/lcsim/recon/tracking/magfield
Cartesian3DMagneticFieldMapTest.java 3087 -> 3088
--- projects/lcsim/trunk/trf/src/test/java/org/lcsim/recon/tracking/magfield/Cartesian3DMagneticFieldMapTest.java	2014-04-04 21:51:04 UTC (rev 3087)
+++ projects/lcsim/trunk/trf/src/test/java/org/lcsim/recon/tracking/magfield/Cartesian3DMagneticFieldMapTest.java	2014-04-08 20:24:39 UTC (rev 3088)
@@ -1,55 +1,75 @@
-package org.lcsim.recon.tracking.magfield;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.StringTokenizer;
-import junit.framework.TestCase;
-import org.lcsim.recon.tracking.spacegeom.CartesianPoint;
-import org.lcsim.recon.tracking.spacegeom.SpacePoint;
-import org.lcsim.recon.tracking.spacegeom.SpacePointVector;
-import static java.lang.Math.abs;
-
-/**
- *
- * @author Norman A Graf
- * 
- *  @version $Id:
- */
-public class Cartesian3DMagneticFieldMapTest extends TestCase
-{
-
-    public void testCartesian3DMagneticFieldMap() throws Exception
-    {
-        InputStream is = this.getClass().getResourceAsStream("ThreeDFieldMap.dat");
-        Cartesian3DMagneticFieldMap map = new Cartesian3DMagneticFieldMap(is, 0., 0., 0.);
-
-        is.close();
-        // now read in field map again, and check that we get the correct values at the
-        // measured points
-        // does not test the interpolation per se but is a check.
-        BufferedReader myInput = new BufferedReader(new InputStreamReader(new BufferedInputStream(this.getClass().getResourceAsStream("ThreeDFieldMap.dat"))));
-        String thisLine;
-        //skip the first nine lines of metadata
-        for (int i = 0; i < 9; ++i) {
-            thisLine = myInput.readLine();
-        }
-        // loop over the field points
-
-        for (int i = 0; i < 360; ++i) {
-            thisLine = myInput.readLine();
-            StringTokenizer st = new StringTokenizer(thisLine, " ");
-            double x = Double.parseDouble(st.nextToken());
-            double y = Double.parseDouble(st.nextToken());
-            double z = Double.parseDouble(st.nextToken());
-            double bx = Double.parseDouble(st.nextToken());
-            double by = Double.parseDouble(st.nextToken());
-            double bz = Double.parseDouble(st.nextToken());
-            SpacePointVector spv = map.field(new CartesianPoint(x, y, z));
-            assertEquals(bx, spv.v_x(), abs(.001 * bx));
-            assertEquals(by, spv.v_y(), abs(.001 * by));
-            assertEquals(bz, spv.v_z(), abs(.001 * bz));
-        }
-    }
-}
+package org.lcsim.recon.tracking.magfield;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.StringTokenizer;
+import junit.framework.TestCase;
+import org.lcsim.recon.tracking.spacegeom.CartesianPoint;
+import org.lcsim.recon.tracking.spacegeom.SpacePoint;
+import org.lcsim.recon.tracking.spacegeom.SpacePointVector;
+import static java.lang.Math.abs;
+
+/**
+ *
+ * @author Norman A Graf
+ *
+ * @version $Id:
+ */
+public class Cartesian3DMagneticFieldMapTest extends TestCase
+{
+
+    private boolean debug = false;
+
+    public void testCartesian3DMagneticFieldMap() throws Exception
+    {
+        InputStream is = this.getClass().getResourceAsStream("ThreeDFieldMap.dat");
+        double xOff = 0.0;
+        double yOff = 0.0;
+        double zOff = 0.0;
+        Cartesian3DMagneticFieldMap map = new Cartesian3DMagneticFieldMap(is, xOff, yOff, zOff);
+
+        is.close();
+        // now read in field map again, and check that we get the correct values at the
+        // measured points
+        // does not test the interpolation per se but is a check.
+        BufferedReader myInput = new BufferedReader(new InputStreamReader(new BufferedInputStream(this.getClass().getResourceAsStream("ThreeDFieldMap.dat"))));
+        String thisLine;
+        int nx = 0;
+        int ny = 0;
+        int nz = 0;
+        //skip the first nine lines of metadata
+        for (int i = 0; i < 9; ++i) {
+            thisLine = myInput.readLine();
+            if (i == 1) // parse for number of grid point in x, y,x
+            {
+                StringTokenizer st = new StringTokenizer(thisLine, " ");
+                nx = Integer.parseInt(st.nextToken());
+                ny = Integer.parseInt(st.nextToken());
+                nz = Integer.parseInt(st.nextToken());
+            }
+        }
+        assertEquals(nx, 6);
+        assertEquals(ny, 6);
+        assertEquals(nz, 10);
+
+        int nlines = nx * ny * nz;
+        // loop over the field points
+
+        for (int i = 0; i < nlines; ++i) {
+            thisLine = myInput.readLine();
+            StringTokenizer st = new StringTokenizer(thisLine, " ");
+            double x = Double.parseDouble(st.nextToken());
+            double y = Double.parseDouble(st.nextToken());
+            double z = Double.parseDouble(st.nextToken());
+            double bx = Double.parseDouble(st.nextToken());
+            double by = Double.parseDouble(st.nextToken());
+            double bz = Double.parseDouble(st.nextToken());
+            SpacePointVector spv = map.field(new CartesianPoint(x+xOff, y+yOff, z+zOff));
+            assertEquals(bx, spv.v_x(), abs(.001 * bx));
+            assertEquals(by, spv.v_y(), abs(.001 * by));
+            assertEquals(bz, spv.v_z(), abs(.001 * bz));
+        }
+    }
+}

projects/lcsim/trunk/trf/src/test/java/org/lcsim/recon/tracking/magfield
SplineFit1DMagneticFieldMapTest.java added at 3088
--- projects/lcsim/trunk/trf/src/test/java/org/lcsim/recon/tracking/magfield/SplineFit1DMagneticFieldMapTest.java	                        (rev 0)
+++ projects/lcsim/trunk/trf/src/test/java/org/lcsim/recon/tracking/magfield/SplineFit1DMagneticFieldMapTest.java	2014-04-08 20:24:39 UTC (rev 3088)
@@ -0,0 +1,70 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.lcsim.recon.tracking.magfield;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+import junit.framework.TestCase;
+import org.lcsim.recon.tracking.spacegeom.CartesianPoint;
+import org.lcsim.recon.tracking.spacegeom.SpacePoint;
+import org.lcsim.recon.tracking.spacegeom.SpacePointVector;
+
+/**
+ *
+ * @author ngraf
+ */
+public class SplineFit1DMagneticFieldMapTest extends TestCase
+{
+    private boolean debug = false;
+    /**
+     * Test of field method, of class SplineFit1DMagneticFieldMap.
+     */
+    public void testSplineFit1DMagneticFieldMap()
+    {
+        List<Double> pos = new ArrayList<Double>();
+        List<Double> bval = new ArrayList<Double>();
+        
+        InputStream is = this.getClass().getResourceAsStream("HPS_b18d36_By_0_0_z.dat");
+        try {
+            BufferedReader myInput = new BufferedReader(new InputStreamReader(new BufferedInputStream(is)));
+
+            String thisLine;
+            
+            while ((thisLine = myInput.readLine()) != null) {  
+             //System.out.println(thisLine);
+             StringTokenizer st = new StringTokenizer(thisLine, " ");
+             pos.add(Double.parseDouble(st.nextToken()));
+             bval.add(Double.parseDouble(st.nextToken()));
+             }
+             myInput.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        int size = pos.size();
+        double[] z = new double[size];
+        double[] By = new double[size];
+        for(int i=0; i<size; ++i)
+        {
+            z[i] = pos.get(i);
+            By[i] = bval.get(i);
+        }
+        SplineFit1DMagneticFieldMap map = new SplineFit1DMagneticFieldMap(SplineFit1DMagneticFieldMap.COORDINATE.Z, z, SplineFit1DMagneticFieldMap.BVAL.BY, By);
+        if(debug) System.out.println(map);
+        for(int i=0; i<size; ++i)
+        {
+            SpacePoint p = new CartesianPoint(0., 0., z[i]);
+            SpacePointVector result = map.field(p);
+            if(debug) System.out.println("File z: "+z[i]+" By: "+By[i]+ " map By: "+result.v_y());
+            assertEquals(By[i], result.v_y());
+        }      
+    }
+}
\ No newline at end of file
SVNspam 0.1


Use REPLY-ALL to reply to list

To unsubscribe from the LCDET-SVN list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCDET-SVN&A=1