Commit in hps-java/src/test/java/org/lcsim/hps/recon/tracking on MAIN
MainTrackingDriver.java+43added 1.1
TestRunTrackReconTest.java+204added 1.1
+247
2 added files
First version of new HPS track reco package tests.
Runs 1k events and compares track and hit info with reference.
All files are downloaded from URL at runtime.
Should work for any geometry and test file for HPS given the appropriate reference file and tracking strategy setting in MainTrackingDriver (add set methods for this).
New reference file can easily be created with switch.

hps-java/src/test/java/org/lcsim/hps/recon/tracking
MainTrackingDriver.java added at 1.1
diff -N MainTrackingDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MainTrackingDriver.java	28 Nov 2012 06:42:05 -0000	1.1
@@ -0,0 +1,43 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.lcsim.hps.recon.tracking;
+
+import org.lcsim.hps.monitoring.HPSCalibrationDriver;
+import org.lcsim.hps.users.mgraham.DataTrackerHitDriver;
+import org.lcsim.recon.tracking.digitization.sisim.config.RawTrackerHitSensorSetup;
+import org.lcsim.util.Driver;
+
+/**
+ *
+ * Sets up the standard track reco drivers
+ * 
+ * @author phansson
+ */
+
+public class MainTrackingDriver extends Driver {
+        
+    public MainTrackingDriver() {
+
+        //Setup the sensors and calibrations
+        HPSCalibrationDriver calibDriver = new HPSCalibrationDriver();
+        calibDriver.setRunNumber(1351); //not sure what should be done here!? -> FIX THIS!
+        add(calibDriver);
+        add(new RawTrackerHitSensorSetup());
+        HPSRawTrackerHitFitterDriver hitfitter = new HPSRawTrackerHitFitterDriver();
+        hitfitter.setFitAlgorithm("Analytic");
+        hitfitter.setCorrectT0Shift(true);
+        add(hitfitter);
+        add(new DataTrackerHitDriver());
+        HelicalTrackHitDriver hth_driver = new HelicalTrackHitDriver();
+        hth_driver.setLayerGeometryType("Common"); //"Common" or "Split"
+        hth_driver.setMaxSeperation(20.0);
+        hth_driver.setTolerance(1.0);
+        add(hth_driver);
+        TrackerReconDriver track_recon_driver = new TrackerReconDriver();
+        track_recon_driver.setStrategyResource("/org/lcsim/hps/recon/tracking/strategies/HPS-TestRun-v2-357.xml");
+        add(track_recon_driver);
+    }
+
+}

hps-java/src/test/java/org/lcsim/hps/recon/tracking
TestRunTrackReconTest.java added at 1.1
diff -N TestRunTrackReconTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TestRunTrackReconTest.java	28 Nov 2012 06:42:05 -0000	1.1
@@ -0,0 +1,204 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.lcsim.hps.recon.tracking;
+
+import hep.aida.IAnalysisFactory;
+import hep.aida.IHistogram1D;
+import hep.aida.ITree;
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import junit.framework.TestCase;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.Track;
+import org.lcsim.event.TrackerHit;
+import org.lcsim.hps.util.CompareHistograms;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+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;
+
+/**
+ *
+ * @author phansson
+ */
+public class TestRunTrackReconTest extends TestCase {
+    
+    static final String testURLBase = "http://www.slac.stanford.edu/~phansson/files/temp";
+    static final String testFileName = "egs_5.5gev_0.016x0_500mb_90na_filt_recon_01_HPSTestRun-v3.slcio";
+    static final String testURLBaseCmp = "http://www.slac.stanford.edu/~phansson/files/temp";
+    static final String testFileNameCmp = "egs_5.5gev_0.016x0_500mb_90na_filt_recon_01_HPSTestRun-v3_hpsTestRunTrackingTest.aida";
+    static final String trackCollection = "MatchedTracks";
+    static final boolean saveForReference = false;
+    static final boolean cmpHistograms = true;
+    private final int nEvents = 1000;
+    
+    public void testTrackRecon() throws Exception {
+        
+        File lcioInputFile = null;
+        
+        URL testURL = new URL(testURLBase + "/" + testFileName);
+        FileCache cache = new FileCache();
+        lcioInputFile  = cache.getCachedFile(testURL);
+                
+        //Process and write out the file
+        LCSimLoop loop = new LCSimLoop();
+        loop.setLCIORecordSource(lcioInputFile);
+        loop.add(new MainTrackingDriver());
+        File outputFile = new TestOutputFile(testFileName.replaceAll(".slcio", "") + "_hpsTestRunTrackingTest.slcio");
+        loop.add(new LCIODriver(outputFile));
+        loop.loop(nEvents, null);
+        loop.dispose();
+        
+        //Read LCIO back and test!
+        LCSimLoop readLoop = new LCSimLoop();
+        readLoop.add(new TrackReconTestDriver());
+        readLoop.setLCIORecordSource(outputFile);
+        readLoop.loop(nEvents, null);
+        readLoop.dispose();
+    }
+    
+    
+    /*
+     * static nested class that runs the drivers for standard HPS track recon
+     */
+    
+    
+    
+    static class TrackReconTestDriver extends Driver {
+
+        private AIDA aida = AIDA.defaultInstance();
+        private IAnalysisFactory af = aida.analysisFactory();
+        private final IHistogram1D hntracks = aida.histogram1D("hntracks",10,0,10);
+        private final IHistogram1D hnstereohits = aida.histogram1D("hnstereohits",20,0,20);
+        private final IHistogram1D hhitpositionx = aida.histogram1D("hhitpositionx",50,0,800);
+        private final IHistogram1D hhitpositiony = aida.histogram1D("hhitpositiony",50,-100,100);
+        private final IHistogram1D hhitpositionz = aida.histogram1D("hhitpositionz",50,-100,100);
+        private final List<String> histograms = Arrays.asList("hntracks","hnstereohits","hhitpositionx","hhitpositiony","hhitpositionz");
+        static final double alpha = 0.32; // Type-I error rate           
+        private int ntracks = 0;
+        private int nevents = 0;
+        
+        //Test thresholds
+        private final double ftracks_thr = 0.1;
+        
+        
+        @Override
+        protected void process(EventHeader event) {
+            super.process(event);
+            List<Track> tracks = event.get(Track.class, trackCollection);
+            //System.out.printf("%s: found %d tracks\n",this.getName(),tracks.size());
+            hntracks.fill(tracks.size());
+            ntracks += tracks.size();
+            for(Track track : tracks) {
+                List<TrackerHit> hitsOnTrack = track.getTrackerHits();
+                hnstereohits.fill(hitsOnTrack.size());
+                for(TrackerHit hit : hitsOnTrack) {
+                    double pos[] = hit.getPosition();
+                    this.hhitpositionx.fill(pos[0]);
+                    this.hhitpositiony.fill(pos[1]);
+                    this.hhitpositionz.fill(pos[2]);
+                }
+            }
+            
+            ++nevents;
+        }
+
+        @Override
+        protected void endOfData() {
+            super.endOfData();
+            
+            if(saveForReference) {
+                File outputFile = new TestOutputFile(testFileName.replaceAll(".slcio", "") + "_hpsTestRunTrackingTest.aida");
+                try {
+                    aida.saveAs(outputFile);
+                } catch (IOException ex) {
+                    Logger.getLogger(TestRunTrackReconTest.class.getName()).log(Level.SEVERE, null, ex);
+                }
+            }
+            
+            /*
+             * Basic tests
+             */
+            assertTrue("Failed to find any tracks",ntracks>0);
+            double ftracks = ((double)ntracks)/(double)nevents;
+            assertTrue("Failed to reconstruct more than " + this.ftracks_thr + " of tracks/event ("+ftracks+")",ftracks>this.ftracks_thr);
+            assertTrue("Failed to find any stereo hits",this.hnstereohits.mean()>0.);
+            
+            
+            
+//            IPlotter plotter = af.createPlotterFactory().create();
+//            plotter.createRegions(1, 3, 0);
+//            plotter.setTitle("Nr of tracks");
+//            plotter.style().statisticsBoxStyle().setVisible(false);
+//            plotter.region(0).plot(hntracks);
+//            plotter.show();
+            
+            if(cmpHistograms) {
+
+                File aidaCmpInputFile = null;
+
+                URL cmpURL;
+                try {
+                    cmpURL = new URL(testURLBaseCmp + "/" + testFileNameCmp);
+                    FileCache cache = null;
+                    try {
+                        cache = new FileCache();
+                    } catch (IOException ex) {
+                        Logger.getLogger(TestRunTrackReconTest.class.getName()).log(Level.SEVERE, null, ex);
+                    }
+                    try {
+                        aidaCmpInputFile  = cache.getCachedFile(cmpURL);
+                    } catch (IOException ex) {
+                        Logger.getLogger(TestRunTrackReconTest.class.getName()).log(Level.SEVERE, null, ex);
+                    }
+                    ITree tree_cmp = null;
+                    try {
+                        tree_cmp = af.createTreeFactory().create(aidaCmpInputFile.getAbsolutePath());
+                    } catch (IllegalArgumentException ex) {
+                        Logger.getLogger(TestRunTrackReconTest.class.getName()).log(Level.SEVERE, null, ex);
+                    } catch (IOException ex) {
+                        Logger.getLogger(TestRunTrackReconTest.class.getName()).log(Level.SEVERE, null, ex);
+                    }
+                    if(tree_cmp==null) {
+                        throw new RuntimeException("cannot create the ITree for the comparison file located at" + aidaCmpInputFile.getAbsolutePath());
+                    }
+                    for(String histname : histograms) {
+                    
+                        IHistogram1D h_ref = (IHistogram1D)tree_cmp.find(histname);
+                        IHistogram1D h_test = aida.histogram1D(histname);
+                        boolean nullHypoIsRejected = CompareHistograms.instance().getTTest(alpha, h_test.mean(), h_ref.mean(), h_test.rms()*h_test.rms(), h_ref.rms()*h_ref.rms(), h_test.allEntries(), h_ref.allEntries());
+                        double p_value = CompareHistograms.instance().getTTestPValue(h_test.mean(), h_ref.mean(), h_test.rms()*h_test.rms(), h_ref.rms()*h_ref.rms(), h_test.allEntries(), h_ref.allEntries());
+                        boolean entriesInconsistent = CompareHistograms.instance().getTTest(alpha, h_test.entries(), h_ref.entries(), h_test.entries(), h_ref.entries(), h_test.entries(), h_ref.entries());
+                        double p_value_entries = CompareHistograms.instance().getTTestPValue(h_test.entries(), h_ref.entries(), h_test.entries(), h_ref.entries(), h_test.entries(), h_ref.entries());                      
+                        System.out.printf("%s: %s %s T-Test (%.1f%s C.L.) with p-value=%.3f\n",TestRunTrackReconTest.class.getName(),histname,(nullHypoIsRejected?"FAILED":"PASSED"),(1-alpha)*100,"%",p_value);
+                        System.out.printf("%s: %s entries are %s (N=%d Ref=%d for T-Test w/ %.1f%s C.L.)\n",TestRunTrackReconTest.class.getName(),histname,(entriesInconsistent?"INCONSISTENT":"CONSISTENT"),h_test.entries(),h_ref.entries(),(1-alpha)*100,"%");                      
+                        assertTrue("Failed T-Test ("+ (1-alpha)*100 + "% C.L. p-value=" + p_value + ") comparing histogram " + histname,!nullHypoIsRejected);
+                        assertTrue("Failed T-Test ("+ (1-alpha)*100 + "% C.L. p-value=" + p_value_entries + ") on number of entries comparing histogram " + histname,!entriesInconsistent);
+                        
+                    }
+
+
+                } catch (MalformedURLException ex) {
+                    Logger.getLogger(TestRunTrackReconTest.class.getName()).log(Level.SEVERE, null, ex);
+                }
+            }
+                    
+        }
+
+        
+        
+        
+    }
+    
+    
+}
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1