Commit in lcsim/test/org/lcsim/detector/driver on MAIN
SimTrackerHitIdentifierReadoutDriverTest.java+48-931.6 -> 1.7


lcsim/test/org/lcsim/detector/driver
SimTrackerHitIdentifierReadoutDriverTest.java 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- SimTrackerHitIdentifierReadoutDriverTest.java	11 Sep 2007 00:21:01 -0000	1.6
+++ SimTrackerHitIdentifierReadoutDriverTest.java	8 Dec 2007 00:36:27 -0000	1.7
@@ -15,6 +15,7 @@
 import org.lcsim.detector.IDetectorElement;
 import org.lcsim.detector.IReadout;
 import org.lcsim.detector.identifier.Identifier;
+import org.lcsim.detector.driver.CollectionHandler;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.SimTrackerHit;
 import org.lcsim.geometry.compact.Subdetector;
@@ -23,23 +24,10 @@
 import org.lcsim.util.loop.LCSimLoop;
 
 /**
- * Reads 2 muon event generated in sid01_polyhedra, which uses
- * SiTrackerBarrel.  For DetectorElements where there is a 
- * Readout containing one hit, check that the hit from the event
- * and the DE's have matching cell id. 
+ * Test the {@link org.lcsim.detector.driver.SimTrackerHitIdentifierReadoutDriver} on the sid01 detector.
  */
-public class SimTrackerHitIdentifierReadoutDriverTest extends TestCase
+public class SimTrackerHitIdentifierReadoutDriverTest_sid01 extends TestCase
 {
-    public SimTrackerHitIdentifierReadoutDriverTest(String testName)
-    {
-        super(testName);
-    }
-
-    public static Test suite()
-    {
-        return new TestSuite(SimTrackerHitIdentifierReadoutDriverTest.class);
-    }
-
     public void setUp()
     {
         java.lang.Runtime.getRuntime().gc();
@@ -48,98 +36,65 @@
     public void testReadout() throws Exception
     {        
         URL url = 
-            new URL("http://www.lcsim.org/test/lcio/mu-_10GeV_SiTrackerBarrelTest00.slcio");
+            new URL("http://www.lcsim.org/test/lcio/muons10_Theta4-176_1-10GeV_SLIC_v2r2p1_sid01.slcio");
         FileCache cache = new FileCache();
         File file = cache.getCachedFile(url);        
 
         LCSimLoop loop = new LCSimLoop();
         loop.setLCIORecordSource(file);
-        loop.add( new SimTrackerHitPositionalReadoutDriver(new String[] {"SiTrackerBarrel_RO"} ) );
-        loop.add( new TestDriver() );
+
+        String[] colls = {"TkrBarrHits","TkrEndcapHits"};
+
+        loop.add( new SimTrackerHitIdentifierReadoutDriver(colls));
+        loop.add( new TestDriver(colls));
         loop.loop(1, null);
         loop.dispose();
     }     
-
+    
     class TestDriver
-    extends Driver
+    extends CollectionHandler
     {
-        protected void process(EventHeader header)
-        {      
-            List<SimTrackerHit> hitsFromRO = new ArrayList<SimTrackerHit>();
-            Subdetector tkr = header.getDetector().getSubdetector("SiTrackerBarrel");
-            //IIdentifierHelper helper = tkr.getDetectorElement().getIdentifierHelper();
-            for ( IDetectorElement layer : tkr.getDetectorElement().getChildren() )
-            {
-                for ( IDetectorElement module : layer.getChildren() )
-                {
-                    for ( IDetectorElement sensor : module.getChildren() )
-                    {
-                        IReadout ro = sensor.getReadout();
-                                
-                        for ( SimTrackerHit rohit : ro.getHits(SimTrackerHit.class) )
-                        {
-                        		hitsFromRO.add( rohit );
-                        }
-                    }
-                }
-            }
-                         
-            List<SimTrackerHit> eventHits = header.get(SimTrackerHit.class, "SiTrackerBarrel_RO");
-            
-            assertEquals( "Collection and detector readout have different number of hits!", eventHits.size(), hitsFromRO.size() );
-            
-            for ( SimTrackerHit hit : eventHits )
-            {                               
-                IDetectorElement de = hit.getDetectorElement();
-
-                // Check that DetectorElement and hit have same id.
-
-                //System.out.println("deId = " + helper.unpack( de.getIdentifier() ).toString() );
-                //System.out.println("hitId = " + helper.unpack( new Identifier( hit.getCellID() ) ).toString() );
-                //System.out.println();
-                
-                assertEquals( 
-                        "DetectorElement id and hit id are different!",
-                        de.getIdentifier(), 
-                        new Identifier( hit.getCellID() ) );
-                
-                // Get the Readoout.
-                IReadout ro = de.getReadout();
-                
-                // Get the hits from the Readout.
-                List<SimTrackerHit> hits = ro.getHits( SimTrackerHit.class );
-                
-                // Loop over the hits in the Readout.
-                for ( SimTrackerHit deHit : hits )
-                {		
-                    // Check that the cellIDs are the same for the event hit and the Readout hit.
-                    assertEquals( "CellIDs do not match!", hit.getCellID(), deHit.getCellID() );
-                    
-                    // Check that the SimTrackerHit is inside the DetectorElement it is assigned to.
-                    assertEquals( "SimTrackerHit not inside its DetectorElement!", de.getGeometry().inside( new BasicHep3Vector( hit.getPoint() ) ), Inside.INSIDE );
-                    
-                    // Check that the hit can be looked up by position in the Readout hits.
-                    SimTrackerHit lkpHit = findHitByPosition( hit, hits );
-                    assertTrue( "Didn't find hit by position on the Readout!", lkpHit != null );                                       
-                }
-            } 
-        }
-        
-        private SimTrackerHit findHitByPosition( SimTrackerHit findHit, List<SimTrackerHit> hits)
+    	TestDriver(String[] colls)
+    	{
+    		super(colls);
+    	}
+    	
+    	protected void process(EventHeader event)
+    	{
+    		List<List<SimTrackerHit>> collections = event.get(SimTrackerHit.class);
+    		for (List<SimTrackerHit> collection : collections)
+    		{
+    			if (canHandle(event.getMetaData(collection).getName()))
+    			{
+    				for (SimTrackerHit hit : collection)
+    				{
+    					//System.out.println("Checking SimTrackerHit at " + hit.getPoint()[0] + "," + hit.getPoint()[1] + " " + hit.getPoint()[2] + " with id: " + new Identifier(hit.getCellID()).toHexString());
+    					IDetectorElement deHit = hit.getDetectorElement();
+    					assertTrue("DetectorElement from the hit is null!",deHit!=null);
+    					assertEquals("IDs do not match",new Identifier(hit.getCellID()),deHit.getIdentifier());
+    					SimTrackerHit lkpHit = findHitByPosition(hit,deHit.getReadout().getHits(SimTrackerHit.class));
+    					assertTrue("Failed to find SimTrackerHit in Readout!",lkpHit != null);
+    					//System.out.println("OK!");
+    				}
+    			}
+    		}
+    	}
+    }
+    
+    private SimTrackerHit findHitByPosition( SimTrackerHit findHit, List<SimTrackerHit> hits)
+    {
+        double[] findHitPos = findHit.getPoint();
+        for ( SimTrackerHit hit : hits )
         {
-            double[] findHitPos = findHit.getPoint();
-            for ( SimTrackerHit hit : hits )
+            double[] hitPos = hit.getPoint();
+            if ( findHitPos[0] == hitPos[0] && 
+                    findHitPos[1] == hitPos[1] && 
+                    findHitPos[2] == hitPos[2] )
             {
-                double[] hitPos = hit.getPoint();
-                if ( findHitPos[0] == hitPos[0] && 
-                        findHitPos[1] == hitPos[1] && 
-                        findHitPos[2] == hitPos[2] )
-                {
-                    return hit;
-                }
+                return hit;
             }
-            return null;
         }
+        return null;
     }
 }
 
CVSspam 0.2.8