Print

Print


Commit in lcsim/test on MAIN
HitPositionTest.java+58-191.10 -> 1.11
Updated HitPositionTest with some new files.  Also, added a bit more functionality.

lcsim/test
HitPositionTest.java 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- HitPositionTest.java	16 Jul 2005 09:05:37 -0000	1.10
+++ HitPositionTest.java	18 Jul 2005 18:00:56 -0000	1.11
@@ -1,6 +1,7 @@
 import java.io.File;
 import java.net.URL;
 import java.util.List;
+import java.util.ArrayList;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -18,33 +19,38 @@
  */
 public class HitPositionTest extends TestCase
 {
-    /* Collections to test. */
-    public static final String colls[] = {"EcalBarrHits", "EcalEndcapHits"};
+    private static final String[] detectors = {"sdfeb05","sdjan03","sdjan03","sidmay05","sidmay05_20mr","sidmay05_2mr","sidmay05_np","sidmay05_scinthcal"};
+    private static final String[] colls = {"EcalBarrHits", "EcalEndcapHits", "HcalBarrHits", "HcalEndcapHits"};
     private int recordCount = 0;
+    private static final int maxEvents = 50;
     
-    public HitPositionTest(String testName)
+    public void testHitPosition() throws Exception
+    {        
+        for ( String detectorName  : getDetectors() )
+        {
+            runTestFile(getBaseURL() + getFileChunk() + detectorName + ".slcio");
+        }
+    }
+    
+    /** Base URL for test files. */
+    private static final String getBaseURL()
     {
-        super(testName);
+        return "http://www.lcsim.org/test/lcio/";
     }
     
-    public static Test suite()
+    /** Chunk of pathname to detector tag. */
+    private static final String getFileChunk()
     {
-        return new TestSuite(HitPositionTest.class);
+        return "n/n_Theta90_1GeV_SLIC_v1r9p1_";
     }
     
-    public void testHitPosition() throws Exception
+    public void testMuScan() throws Exception
     {
-        /* Test ProjectiveCylinder and ProjectiveZPlane segmentations. */
-        //runTestFile("http://www.lcsim.org/datasamples/rho+_pi+gamma_Theta90_10GeV.slcio");
-        //runTestFile("http://www.lcsim.org/datasamples/SLIC_v1r9p1_sdjan03_muons_Theta4-176_1-10GeV.slcio");
-        
-        /* Test NonprojectiveCylinder and GridXYZ (in a cylindrical endcap) segmentations. */
-        //runTestFile("http://www.lcsim.org/datasamples/SLIC_v1r9p1_sidmay05_np_muons_Theta4-176_1-10GeV.slcio");
-        runTestFile("http://www.lcsim.org/test/lcio/muons_SLIC_v1r9p1_sidmay05.slcio");  
+        runTestFile("http://www.lcsim.org/test/lcio/muons_SLIC_v1r9p1_sidmay05.slcio");
         runTestFile("http://www.lcsim.org/test/lcio/muons_SLIC_v1r9p1_sidmay05_np.slcio");
     }
     
-    public void runTestFile(String s) throws Exception
+    private void runTestFile(String s) throws Exception
     {
         System.out.println("Running HitPositionTest on file: " + s);
         
@@ -56,10 +62,36 @@
         LCSimLoop loop = new LCSimLoop();
         loop.setLCIORecordSource(file);
         loop.add(new HitPositionDriver());
-        loop.loop(-1);
+        loop.loop(maxEvents);
         loop.dispose();
     }
     
+    /** Collections to test. */
+    private static final String[] getColls()
+    {
+        return colls;
+    }
+    
+    /** Detectors to test. */
+    private static final String[] getDetectors()
+    {
+        return detectors;
+    };
+    
+    public HitPositionTest(String testName)
+    {
+        super(testName);
+    }
+    
+    public static Test suite()
+    {
+        return new TestSuite(HitPositionTest.class);
+    }
+    
+    //protected void setUp() throws Exception
+    //{
+    //}
+    
     /** Tests whether position from hit matches the decoder's position from Id and segmentation calculations. */
     private class HitPositionDriver extends Driver
     {
@@ -73,6 +105,12 @@
                 
                 List<SimCalorimeterHit> hits = event.get(SimCalorimeterHit.class, s);
                 CalorimeterIDDecoder decoder = (CalorimeterIDDecoder) event.getMetaData(hits).getIDDecoder();
+               
+                if ( decoder == null )
+                {
+                    throw new RuntimeException("HitPositionTest - decoder is null");
+                }
+                
                 for (SimCalorimeterHit hit: hits)
                 {
                     long id = hit.getCellID();
@@ -86,9 +124,10 @@
 //                        System.out.println("dec: " + decoder.getX() + " " + decoder.getY() + " " + decoder.getZ() +
 //                                " " + decoder.getTheta() + " " + decoder.getPhi() + " " + decoder.getValue("phi") + " " + decoder.getValue("z") );
 //                    }
-                    assertEquals(decoder.getX(),pos[0], 0.001);
-                    assertEquals(decoder.getY(),pos[1], 0.001);
-                    assertEquals(decoder.getZ(),pos[2], 0.001);
+                    // FIXME: Could be added to IDDecoder as checkPosition() with tolerance.
+                    assertEquals(decoder.getX(), pos[0], 0.001);
+                    assertEquals(decoder.getY(), pos[1], 0.001);
+                    assertEquals(decoder.getZ(), pos[2], 0.001);
                 }
             }
         }
CVSspam 0.2.8