View Javadoc

1   package org.lcsim.geometry.field;
2   
3   import hep.physics.vec.BasicHep3Vector;
4   import hep.physics.vec.Hep3Vector;
5   import java.io.InputStream;
6   import java.util.Map;
7   import static junit.framework.Assert.assertEquals;
8   import org.lcsim.geometry.Detector;
9   import org.lcsim.geometry.FieldMap;
10  import org.lcsim.geometry.GeometryReader;
11  import org.lcsim.geometry.compact.Field;
12  
13  /**
14   *
15   * @author jeremym
16   */
17  public class FieldMap3DTest extends FieldTest
18  {
19      /** Creates a new instance of FieldMap3DTest */
20      public FieldMap3DTest(String name)
21      {
22          super(name);
23      }
24         
25      public void testRead() throws Exception
26      {
27          String[] files = {"/org/lcsim/geometry/field/FieldMap3DTest.xml", "/org/lcsim/geometry/field/FieldMap3DURLTest.xml"};
28          for(int f=0; f<files.length; ++f)
29          {
30              System.out.println("testing "+files[f]);
31          InputStream in = this.getClass().getResourceAsStream(files[f]); 
32          GeometryReader reader = new GeometryReader();
33          Detector det = reader.read(in);
34          FieldMap map = det.getFieldMap();
35  
36          double[] off = {2.117, 0.0, 45.72};
37          double[] fp = {-25.0, -8.9, -150.};
38          double[] B = new double[3];
39  
40          // field at first map position should be zero since we offset the field
41          testFieldAt(map, fp[0], fp[1], fp[2], 0, 0, 0);
42          // field at first map position with offset included should equal first field values
43          testFieldAt(map, fp[0] + off[0], fp[1] + off[1], fp[2] + off[2], 0, -1.9, 0);
44          // field at the origin
45          testFieldAt(map, 0.0 + off[0], -8.9 + off[1], 0.0 + off[2], 0., -500.6, 0.);
46          // this field map is invariant in y, test this...
47          testFieldAt(map, 0.0 + off[0], 0. + off[1], 0.0 + off[2], 0., -500.6, 0.);
48          testFieldAt(map, 0.0 + off[0], 8.9 + off[1], 0.0 + off[2], 0., -500.6, 0.);
49  
50          //TODO check interpolation more rigorously
51          //check all variations of accessor methods (why do we have SO many?!
52          double[] p = {fp[0] + off[0], fp[1] + off[1], fp[2] + off[2]};
53          Hep3Vector h3vP = new BasicHep3Vector(fp[0] + off[0], fp[1] + off[1], fp[2] + off[2]);
54  
55          map.getField(p, B);
56          Hep3Vector h3vB = map.getField(h3vP);
57          assertEquals(B[0], h3vB.x());
58          assertEquals(B[1], h3vB.y());
59          assertEquals(B[2], h3vB.z());
60  
61          double[] B2 = map.getField(p);
62          for (int i = 0; i < 3; ++i) {
63              assertEquals(B[i], B2[i]);
64          }
65  
66          // test specifics of Cartesian3DMagneticFieldMap
67          Map<String, Field> fields = det.getFields();
68          assertEquals(fields.size(), 1);
69          FieldMap3D cmap = (FieldMap3D) fields.get("FieldMap3DTest");
70          double[] offsets = cmap.globalOffset();
71          assertEquals(offsets[0], off[0]);
72          assertEquals(offsets[1], off[1]);
73          assertEquals(offsets[2], off[2]);             
74          }
75      }
76  }