View Javadoc

1   package org.lcsim.geometry.field;
2   
3   import hep.physics.vec.BasicHep3Vector;
4   import hep.physics.vec.Hep3Vector;
5   
6   import java.util.ArrayList;
7   import java.util.List;
8   
9   import junit.framework.Test;
10  import junit.framework.TestCase;
11  import junit.framework.TestSuite;
12  
13  import org.lcsim.geometry.Detector;
14  import org.lcsim.util.test.OneTimeDetectorSetup;
15  
16  /**
17   * Test that checks BoxDipole returns the correct B values for a test detector.  It 
18   * also checks that several BoxDipoles overlay their values correctly.
19   * 
20   * @author Jeremy McCormick <jeremym@slac.stanford.edu>
21   * @version $Id: BoxDipoleTest.java,v 1.1 2011/06/24 22:17:13 jeremy Exp $
22   */
23  public class BoxDipoleTest extends TestCase
24  {
25      Detector det;
26      
27      // Test resource containing two BoxDipole fields.
28      static final String detLoc = "/org/lcsim/geometry/field/BoxDipoleTest.xml";
29      
30      public static Test suite()
31      {
32          TestSuite ts = new TestSuite();
33          ts.addTestSuite(BoxDipoleTest.class);
34          return new OneTimeDetectorSetup(ts, detLoc);
35      }
36  
37      protected void setUp() throws Exception
38      {
39          if (det == null)
40              det = OneTimeDetectorSetup.getDetector();
41      }
42      
43      public void testDipole()
44      {
45          // Points to test.
46          List<Hep3Vector> testPoints = new ArrayList<Hep3Vector>();
47          testPoints.add(new BasicHep3Vector(0,0,0));
48          testPoints.add(new BasicHep3Vector(251,0,0));
49          
50          // Answer key.
51          List<Hep3Vector> answerKey = new ArrayList<Hep3Vector>();
52          answerKey.add(new BasicHep3Vector(2., 1., 0.5));
53          answerKey.add(new BasicHep3Vector(2.1, 1.2, 0.8));
54          
55          // Loop over test points.
56          for (int i=0, n=testPoints.size(); i<n; i++)
57          {
58              // Get the point to check.
59              Hep3Vector point = testPoints.get(i);
60              
61              // Get the B-field values at this point.
62              Hep3Vector bfield = det.getFieldMap().getField(point);
63             
64              // Check that B-field value matches key.
65              assertEquals(bfield, answerKey.get(i));
66          }
67      }
68  }