View Javadoc

1   package org.lcsim.detector.converter.compact;
2   
3   import hep.physics.vec.BasicHep3Vector;
4   import hep.physics.vec.Hep3Vector;
5   
6   import java.io.InputStream;
7   
8   import junit.framework.TestCase;
9   import junit.framework.TestSuite;
10  
11  import org.lcsim.detector.IDetectorElement;
12  import org.lcsim.detector.IDetectorElementContainer;
13  import org.lcsim.detector.IPhysicalVolumeNavigator;
14  import org.lcsim.detector.IPhysicalVolumePath;
15  import org.lcsim.detector.identifier.IExpandedIdentifier;
16  import org.lcsim.detector.identifier.IIdentifier;
17  import org.lcsim.geometry.Detector;
18  import org.lcsim.geometry.GeometryReader;
19  import org.lcsim.geometry.Subdetector;
20  
21  /**
22   * 
23   * Perform tests on the detailed geometry of an
24   * 
25   * @see org.lcsim.geometry.subdetector.DiskTracker
26   * 
27   * @author Jeremy McCormick <jeremym@slac.stanford.edu>
28   * 
29   */
30  public class DiskTrackerTest extends TestCase
31  {
32      private Detector detector;
33  
34      public DiskTrackerTest(String name)
35      {
36          super(name);
37      }
38  
39      public static junit.framework.Test suite()
40      {
41          return new TestSuite(DiskTrackerTest.class);
42      }
43  
44      private static final String resource = "/org/lcsim/detector/converter/compact/DiskTrackerTest.xml";
45  
46      public void setUp()
47      {
48          InputStream in = this.getClass().getResourceAsStream(resource);
49  
50          GeometryReader reader = new GeometryReader();
51  
52          try
53          {
54              detector = reader.read(in);
55          }
56          catch (Throwable x)
57          {
58              throw new RuntimeException(x);
59          }
60      }
61  
62      public void testLayers()
63      {
64          Subdetector compact = detector.getSubdetector("DiskTracker");
65          IDetectorElement subdet = compact.getDetectorElement();
66          for (IDetectorElement endcap : subdet.getChildren())
67          {
68              // System.out.println("endcap: " + endcap.getName());
69              IDetectorElementContainer layers = endcap.getChildren();
70              // System.out.println("layers: " + layers.size());
71              assertEquals("Expected number of layers is wrong.", layers.size(), 1);
72              for (IDetectorElement layer : endcap.getChildren())
73              {
74                  int sensorNumber = 0;
75                  for (IDetectorElement sensor : layer.getChildren())
76                  {
77                      // System.out.println("sensor: " + sensor.getName());
78                      IIdentifier id = sensor.getIdentifier();
79                      IExpandedIdentifier expId = sensor.getIdentifierHelper().unpack(id);
80                      // System.out.println(expId.toString());
81                      assertEquals(sensor.getIdentifierHelper().getValue(sensor.getIdentifier(), "system"), compact
82                              .getIDDecoder().getSystemNumber());
83                      int barrel = sensor.getIdentifierHelper().getValue(sensor.getIdentifier(), "barrel");
84                      assertTrue(barrel == 1 || barrel == 2);
85                      assertTrue(sensor.getIdentifierHelper().getValue(sensor.getIdentifier(), "layer") == 0);
86                      assertTrue(sensor.getIdentifierHelper().getValue(sensor.getIdentifier(), "slice") == sensorNumber);
87                      ++sensorNumber;
88                  }
89              }
90          }
91      }
92  
93      /**
94       * Scan the geometry with some points along the z axis. Check that the points are within the correct geometric
95       * volumes and DetectorElements.
96       */
97      public void testZPointScan()
98      {
99          IPhysicalVolumeNavigator navigator = detector.getNavigator();
100 
101         double[] zpoints = new double[]{12.1,11.1,10.1,0.,-10.1,-11.1,-12.1};
102 
103         String[] pathAnswerKey =
104                 new String[]{
105                     "/tracking_region",
106                     "/tracking_region/DiskTracker_layer0_pos/DiskTracker_layer0_slice1",
107                     "/tracking_region/DiskTracker_layer0_pos/DiskTracker_layer0_slice0",
108                     "/tracking_region",
109                     "/tracking_region/DiskTracker_layer0_neg/DiskTracker_layer0_slice0",
110                     "/tracking_region/DiskTracker_layer0_neg/DiskTracker_layer0_slice1",
111                     "/tracking_region"
112                 };  
113                 
114         String[] deAnswerKey =
115                 new String[]{
116                     "DiskTrackerTest",
117                     "DiskTracker_layer0_slice1_pos",
118                     "DiskTracker_layer0_slice0_pos",
119                     "DiskTrackerTest",
120                     "DiskTracker_layer0_slice0_neg",
121                     "DiskTracker_layer0_slice1_neg",
122                     "DiskTrackerTest"
123                 };
124 
125         for (int i = 0; i < zpoints.length; i++ )
126         {
127             Hep3Vector zpoint = new BasicHep3Vector(0, 0, zpoints[i]);
128 
129             IPhysicalVolumePath path = navigator.getPath(zpoint);
130 
131             //System.out.println(path);
132             //System.out.println("path: " + path);
133             //System.out.println("pathAnswer: " + pathAnswerKey[i]);
134 
135             assertEquals("Wrong path <" + path.toString() + "> at z = " + zpoints[i] + ".  Expected <"
136                     + pathAnswerKey[i] + ">.", path.toString(), pathAnswerKey[i]);
137 
138             IDetectorElement srch = detector.getDetectorElement().findDetectorElement(zpoint);
139 
140             //System.out.println(srch.getName());
141             //System.out.println("deAnswer: " + deAnswerKey[i]);            
142 
143             assertTrue("Wrong DE <" + srch.getName() + "> at z = " + zpoints[i] + ".  Expected <" + deAnswerKey[i]+ ">.", srch.getName().equals(deAnswerKey[i]));
144             
145             //System.out.println("--");            
146         }
147     }
148 }