Print

Print


Commit in lcsim/test/org/lcsim/detector/driver on MAIN
SiTrackerBarrelReadLcioTest.java+41added 1.1
SimTrackerHitPositionalReadoutDriverTest.java+127added 1.1
+168
2 added files


lcsim/test/org/lcsim/detector/driver
SiTrackerBarrelReadLcioTest.java added at 1.1
diff -N SiTrackerBarrelReadLcioTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ SiTrackerBarrelReadLcioTest.java	1 May 2007 23:40:35 -0000	1.1
@@ -0,0 +1,41 @@
+package org.lcsim.detector.driver;
+
+import java.io.File;
+import java.net.URL;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCSimLoop;
+import org.lcsim.detector.tracker.SimTrackerHitPositionalReadoutDriver;
+
+public class SiTrackerBarrelReadLcioTest
+extends TestCase
+{
+    public SiTrackerBarrelReadLcioTest(String testName)
+    {
+       super(testName);
+    }
+    
+    public static Test suite()
+    {
+       return new TestSuite(SiTrackerBarrelReadLcioTest.class);
+    }
+    
+    public void testReadLcio() throws Exception
+    {        
+        URL url = 
+            new URL("http://www.lcsim.org/test/lcio/mu-_10GeV_10_SLIC_v2r1p7_geant4-v8r2p0_SiTrackerBarrelTest00.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.loop(2);
+        loop.dispose();
+    }
+}
\ No newline at end of file

lcsim/test/org/lcsim/detector/driver
SimTrackerHitPositionalReadoutDriverTest.java added at 1.1
diff -N SimTrackerHitPositionalReadoutDriverTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ SimTrackerHitPositionalReadoutDriverTest.java	1 May 2007 23:40:35 -0000	1.1
@@ -0,0 +1,127 @@
+package org.lcsim.detector.driver;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import hep.physics.vec.BasicHep3Vector;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.SimTrackerHit;
+import org.lcsim.util.Driver;
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCSimLoop;
+import org.lcsim.detector.IDetectorElement;
+import org.lcsim.detector.IReadout;
+import org.lcsim.detector.ReadoutCleanupDriver;
+import org.lcsim.geometry.compact.Subdetector;
+
+/**
+ * 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. 
+ */
+public class SimTrackerHitPositionalReadoutDriverTest extends TestCase
+{
+    public SimTrackerHitPositionalReadoutDriverTest(String testName)
+    {
+        super(testName);
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite(SimTrackerHitPositionalReadoutDriverTest.class);
+    }
+
+    public void setUp()
+    {
+        java.lang.Runtime.getRuntime().gc();
+    }
+
+    public void testReadout() throws Exception
+    {        
+        URL url = 
+            new URL("http://www.lcsim.org/test/lcio/mu-_10GeV_10_SLIC_v2r1p7_geant4-v8r2p0_SiTrackerBarrelTest00.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() );
+        loop.loop(2);
+        loop.dispose();
+    }     
+
+    class TestDriver
+    extends Driver
+    {
+        protected void process(EventHeader header)
+        {      
+            List<SimTrackerHit> hitsFromRO = new ArrayList<SimTrackerHit>();
+            Subdetector tkr = header.getDetector().getSubdetector("SiTrackerBarrel");
+            for ( IDetectorElement layer : tkr.getDetectorElement().getChildren() )
+            {
+                for ( IDetectorElement module : layer.getChildren() )
+                {
+                    for ( IDetectorElement sensor : module.getChildren() )
+                    {
+                        IReadout<SimTrackerHit> ro = sensor.getReadout();
+                        List<SimTrackerHit> hits = ro.getHits();                        
+                        hitsFromRO.addAll( hits );
+                    }
+                }
+            }
+            
+            /*
+            System.out.println("hitsFromRO.size = " + hitsFromRO.size() );
+            for ( SimTrackerHit roHit : hitsFromRO )
+            {
+                System.out.println("got hit from RO - " + roHit.getCellID());
+            }*/
+            
+            List<SimTrackerHit> eventHits = header.get(SimTrackerHit.class, "SiTrackerBarrel_RO");
+            
+            assertTrue( "Event and RO hits do not have same size!", eventHits.size() == hitsFromRO.size() );
+            
+            for ( SimTrackerHit hit : eventHits )
+            {                               
+                IDetectorElement de = hit.getDetectorElement();
+                //System.out.println("detectorElement="+de.getName());
+                IReadout<SimTrackerHit> ro = de.getReadout();
+                List<SimTrackerHit> hits = ro.getHits();
+                for ( SimTrackerHit deHit : hits )
+                {		
+                    assertEquals( "CellIDs do not match!", hit.getCellID(), deHit.getCellID() );
+                    assertTrue( "SimTrackerHit not inside its DetectorElement!", de.getGeometry().isInside( new BasicHep3Vector( hit.getPoint() ) ) );
+                    
+                    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)
+        {
+            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] )
+                {
+                    return hit;
+                }
+            }
+            return null;
+        }
+    }
+}
+
CVSspam 0.2.8