Print

Print


Commit in lcsim/test/org/lcsim/recon/tracking/seedtracker on MAIN
TrackReconTest.java+106added 1.1
add simple track recon test with assertions

lcsim/test/org/lcsim/recon/tracking/seedtracker
TrackReconTest.java added at 1.1
diff -N TrackReconTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TrackReconTest.java	1 Apr 2011 20:30:17 -0000	1.1
@@ -0,0 +1,106 @@
+package org.lcsim.recon.tracking.seedtracker;
+
+import java.io.File;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.GenericObject;
+import org.lcsim.event.Track;
+import org.lcsim.recon.tracking.seedtracker.trackingdrivers.sidloi3.MainTrackingDriver;
+import org.lcsim.util.Driver;
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCIODriver;
+import org.lcsim.util.loop.LCSimLoop;
+import org.lcsim.util.test.TestUtil.TestOutputFile;
+
+/**
+ * Tests whether seedtracker works on sidloi3 muon events.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: TrackReconTest.java,v 1.1 2011/04/01 20:30:17 jeremy Exp $
+ */
+public class TrackReconTest extends TestCase
+{
+    static final String testURLBase = "http://www.lcsim.org/test/lcio";
+    static final String testFileName = "mu_10GeV_Theta90_SLIC-v2r9p4_geant4-v9r3p2_QGSP_BERT_sidloi3.slcio";    
+    
+    public void testTrackRecon() throws Exception
+    {
+        File lcioInputFile = null;
+
+        URL testURL = new URL(testURLBase + "/" + testFileName);
+        FileCache cache = new FileCache();
+        lcioInputFile = cache.getCachedFile(testURL);
+        
+        // Write out file with Track recon.
+        LCSimLoop loop = new LCSimLoop();
+        loop.add(new MainTrackingDriver());
+        loop.add(new SeedTrackerTrackStateDriver());        
+        File outputFile = new TestOutputFile(testFileName + "_lcsimTracking.slcio");         
+        loop.add(new LCIODriver(outputFile));
+        loop.setLCIORecordSource(lcioInputFile);
+        loop.loop(10, null);
+        loop.dispose();
+        
+        // Read LCIO back and test it.
+        LCSimLoop readLoop = new LCSimLoop();
+        readLoop.add(new TrackReconTestDriver());
+        readLoop.setLCIORecordSource(outputFile);
+        readLoop.loop(10, null);
+        readLoop.dispose();
+    }   
+    
+    /**
+     * This Driver tests the following on an LCSim Event:
+     * 
+     * <ul>
+     * <li>Tracks were found.
+     * <li>One Track was found per event (single muon events).
+     * <li>Tracks have some hits.
+     * <li>Each Track has at least 9 hits.
+     * <li>The TrackState collections are not empty.
+     * <li>The size of the TrackState collections is the same as Tracks.
+     * </ul>
+     * 
+     * @author Jeremy McCormick <[log in to unmask]>
+     * @version $Id: TrackReconTest.java,v 1.1 2011/04/01 20:30:17 jeremy Exp $    
+     */
+    static class TrackReconTestDriver extends Driver
+    {
+        public void process(EventHeader event)
+        {            
+            List<Track> tracks = event.get(Track.class, "Tracks");
+            
+            // Test that Tracks were found.
+            assertTrue(
+                    "Seedtracker failed to find tracks in event: " + event.getEventNumber(),
+                    tracks.size() != 0);
+            
+            // Test that a single track was found.
+            assertEquals(
+                    "Too many tracks were found in this event: " + event.getEventNumber(), 
+                    tracks.size(), 
+                    1);
+            
+            // Test that the Track has hits and that the number of reasonable.  (min of 9)
+            for (Track track : tracks)
+            {
+                int nhits = track.getTrackerHits().size();
+                assertTrue("Track does not have any hits.", nhits != 0);
+                assertTrue("Track does not have at least 9 hits.", nhits >= 9);                
+            }
+
+            // Test that TrackState collections are the right size.
+            String states[] = {"StateAtStart", "StateAtECal", "StateAtEnd"};            
+            for (String state : states)
+            {                
+                List<GenericObject> stateColl = event.get(GenericObject.class, state);
+                assertTrue("State collection is empty: " + state, stateColl.size() != 0);
+                assertTrue("State collection size is wrong: " + state, stateColl.size() == tracks.size());
+            }
+        }        
+    }
+}
CVSspam 0.2.8