Print

Print


Commit in java/trunk/integration-tests/src/test on MAIN
java/org/hps/MockDataReconTest.java+175added 632
resources/org/hps/mockdatarecon/MockDataReconTest.lcsim+75added 632
+250
2 added files
Add skeleton test of Mock Data Recon.  Runs the current version of the recon over Mock Data and produces diagnostic plots.  Does not have test assertions yet.  (JM)

java/trunk/integration-tests/src/test/java/org/hps
MockDataReconTest.java added at 632
--- java/trunk/integration-tests/src/test/java/org/hps/MockDataReconTest.java	                        (rev 0)
+++ java/trunk/integration-tests/src/test/java/org/hps/MockDataReconTest.java	2014-05-23 22:54:05 UTC (rev 632)
@@ -0,0 +1,175 @@
+package org.hps;
+
+import hep.aida.IHistogram1D;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.hps.users.jeremym.MockDataChallengeDiagnosticDriver;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.ReconstructedParticle;
+import org.lcsim.event.Track;
+import org.lcsim.job.AidaSaveDriver;
+import org.lcsim.job.JobControlManager;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCSimLoop;
+
+/**
+ * This test runs the standard reconstruction on a small set of Mock Data events generated by the
+ * trigger simulation. It then generates a set of diagnostic plots which are checked against an
+ * answer key.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class MockDataReconTest extends TestCase {
+
+    static final String className = MockDataReconTest.class.getSimpleName();
+    static final File outputDir = new File("./target/test-output/" + className);
+    static final File outputFile = new File(outputDir.getPath() + File.separator + className);
+    static final File reconFile = new File(outputFile.getPath() + ".slcio");
+    static final File aidaFile = new File(outputFile.getPath() + ".aida");
+
+    static final String steeringResource = "/org/hps/mockdatarecon/MockDataReconTest.lcsim";
+
+    // TODO: Get some values for these and add test assertions!
+    /*
+    static final int expectedReconstructedParticles = 0;
+    static final int expectedClusters = 0;
+    static final int expectedTracks = 0;
+    static final int expectedCalorimeterHits = 0;
+    static final int expectedMCParticles = 0;
+    */
+
+    static final String clusterCollectionName = "EcalClusters";
+    static final String reconstructedParticleCollectionName = "FinalStateParticles";
+    static final String trackCollectionName = "MatchedTracks";
+
+    AIDA aida = AIDA.defaultInstance();
+
+    static final String mockDataUrl = "http://www.slac.stanford.edu/~meeg/hps2/meeg/mock_data/tritrig-beam-tri_1-10_readout.slcio";
+
+    public void setUp() {
+        // Delete files if they already exist.
+        if (reconFile.exists())
+            reconFile.delete();
+        if (aidaFile.exists())
+            aidaFile.delete();
+        
+        // Create output dir.
+        outputDir.mkdirs();
+        if (!outputDir.exists()) {
+            throw new RuntimeException("Failed to create test output dir.");
+        }
+    }
+    
+    public void testReconMockData() {
+
+        // Run the reconstruction over input events.
+        runRecon();
+
+        // Create the plots.
+        createPlots();
+
+        // Check the statistics of the plots.
+        checkPlots();
+    }
+
+    private void runRecon() {
+        File mockDataFile = null;
+        try {
+            FileCache cache = new FileCache();
+            mockDataFile = cache.getCachedFile(new URL(mockDataUrl));
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+        JobControlManager jobManager = new JobControlManager();
+        jobManager.addVariableDefinition("outputFile", outputFile.getPath());
+        jobManager.addInputFile(mockDataFile);
+        jobManager.setup(steeringResource);
+        jobManager.run();
+    }
+
+    private void createPlots() {
+        LCSimLoop loop = new LCSimLoop();
+        loop.add(new MockDataChallengeDiagnosticDriver());
+        loop.add(new CheckDriver());
+        AidaSaveDriver aidaSaveDriver = new AidaSaveDriver();       
+        loop.add(aidaSaveDriver);
+        aidaSaveDriver.setOutputFileName(aidaFile.getPath());
+        try {
+            loop.setLCIORecordSource(reconFile);
+            loop.loop(-1);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void checkPlots() {
+
+        /*
+        IHistogram1D reconParticleCountPlot = aida.histogram1D("/" + reconstructedParticleCollectionName + "/Item Count");
+        System.out.println("reconParticleCount sumBinHeights = " + reconParticleCountPlot.sumBinHeights());
+        System.out.println("reconParticleCount mean = " + reconParticleCountPlot.mean());
+        System.out.println("reconParticleCount itemCount = " + computeItemCount(reconParticleCountPlot));
+
+        IHistogram1D trackCountPlot = aida.histogram1D("/" + trackCollectionName + "/Item Count");
+        System.out.println("trackCount Plot sumBinHeights = " + trackCountPlot.sumBinHeights());
+        System.out.println("trackCount itemCount = " + computeItemCount(trackCountPlot));
+        //assertEquals("Wrong number of tracks counted.", expectedTracks, computeItemCount(trackCountPlot));         
+         */
+    }
+    
+    /**
+     * Compute an item count based on a histogram with bins of size 1.
+     * @param histogram
+     * @return
+     */
+    private int computeItemCount(IHistogram1D histogram) {
+        if (histogram.axis().binUpperEdge(0) - histogram.axis().binLowerEdge(0) != 1.0)
+            throw new IllegalArgumentException("The bins are the wrong size for this method.");
+        if (!histogram.title().equals("Item Count"))
+            throw new IllegalArgumentException("The histogram doesn't appear to contain item counts.");
+        int nbins = histogram.axis().bins();
+        double total = 0;
+        for (int i = 0; i < nbins; i++) {
+            total += histogram.binHeight(i) * histogram.axis().binLowerEdge(i);
+        }
+        if (total % 1 != 0)
+            throw new RuntimeException("Nonsensical number of items computed: " + total);
+        return (int)total;
+    }
+    
+    static class CheckDriver extends Driver {
+        
+        int ntracks;
+        int nparticles;
+        int nclusters;
+        int nevents;
+        
+        public void process(EventHeader event) {
+            ++nevents;
+            ntracks += event.get(Track.class, trackCollectionName).size(); 
+            nparticles += event.get(ReconstructedParticle.class, reconstructedParticleCollectionName).size();
+            nclusters += event.get(Cluster.class, clusterCollectionName).size();
+        }
+        
+        public void endOfData() {
+            System.out.println("CheckDriver got the following ...");
+            System.out.println("  nevents = " + nevents);
+            System.out.println("  ntracks = " + ntracks);
+            System.out.println("  nparticles = " + nparticles);
+            System.out.println("  nclusters = " + nclusters);
+            System.out.println("  <ntracks / nevents> = " + ((double)ntracks / (double)nevents));
+            System.out.println("  <nparticles / nevents> = " + ((double)nparticles / (double)nevents));
+            System.out.println("  <nclusters / nevents> = " + ((double)nclusters / (double)nevents));
+        }
+        
+    }
+}

java/trunk/integration-tests/src/test/resources/org/hps/mockdatarecon
MockDataReconTest.lcsim added at 632
--- java/trunk/integration-tests/src/test/resources/org/hps/mockdatarecon/MockDataReconTest.lcsim	                        (rev 0)
+++ java/trunk/integration-tests/src/test/resources/org/hps/mockdatarecon/MockDataReconTest.lcsim	2014-05-23 22:54:05 UTC (rev 632)
@@ -0,0 +1,75 @@
+<!-- 
+  Offline reconstruction for 2014 (electron run) data.
+  Based on original steering file written by Sho and copied here for access 
+  from integration-tests module.  
+-->
+<lcsim xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" 
+       xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/lcsim/1.0/lcsim.xsd">
+<!--              
+    <control>
+        <numberOfEvents>100</numberOfEvents>
+    </control>
+-->    
+    <execute>
+        <driver name="EventMarkerDriver"/>
+        <driver name="CalibrationDriver"/>
+        <driver name="RawTrackerHitSensorSetup"/>
+        <driver name="RawTrackerHitFitterDriver" />
+        <driver name="TrackerHitDriver"/>
+        <driver name="HelicalTrackHitDriver"/>
+        <driver name="TrackerReconDriver"/>
+        <driver name="EcalRawConverter" />
+        <driver name="EcalClusterer" />
+        <driver name="ReconParticle" />        
+        <driver name="GBLDriver"/> 
+        <driver name="LCIOWriter"/>
+        <driver name="CleanupDriver"/>        
+    </execute>    
+    <drivers>    
+        <driver name="CalibrationDriver" type="org.hps.conditions.deprecated.CalibrationDriver"/>
+        <driver name="EventMarkerDriver" type="org.lcsim.job.EventMarkerDriver">
+            <eventInterval>100</eventInterval>
+        </driver>        
+        <driver name="RawTrackerHitSensorSetup" type="org.lcsim.recon.tracking.digitization.sisim.config.RawTrackerHitSensorSetup"/>
+        <driver name="RawTrackerHitFitterDriver" type="org.hps.recon.tracking.RawTrackerHitFitterDriver">
+            <fitAlgorithm>Analytic</fitAlgorithm>
+            <useTimestamps>false</useTimestamps>
+            <correctT0Shift>false</correctT0Shift>
+            <useTruthTime>true</useTruthTime>
+            <subtractTOF>true</subtractTOF>
+        </driver>
+        <driver name="TrackerHitDriver" type="org.hps.recon.tracking.DataTrackerHitDriver" />     
+        <driver name="HelicalTrackHitDriver" type="org.hps.recon.tracking.HelicalTrackHitDriver">
+            <debug>false</debug>
+            <clusterTimeCut>16.0</clusterTimeCut>
+            <maxSeperation>20.0</maxSeperation>
+            <tolerance>1.0</tolerance>
+        </driver>
+        <driver name="TrackerReconDriver" type="org.hps.recon.tracking.TrackerReconDriver">
+            <strategyResource>HPS-Full.xml</strategyResource>
+            <debug>false</debug>
+        </driver>        
+        <driver name="GBLDriver" type="org.hps.recon.tracking.gbl.GBLOutputDriver">
+            <debug>0</debug>
+            <isMC>false</isMC>
+            <gblFileName></gblFileName>
+        </driver>
+        <driver name="EcalRawConverter" type="org.hps.recon.ecal.EcalRawConverterDriver">
+            <ecalCollectionName>EcalCalHits</ecalCollectionName>
+            <use2014Gain>true</use2014Gain>
+            <useTimestamps>false</useTimestamps>
+            <useTruthTime>true</useTruthTime>
+        </driver>
+        <driver name="EcalClusterer" type="org.hps.recon.ecal.EcalClusterICBasic">
+            <ecalName>Ecal</ecalName>
+            <ecalCollectionName>EcalCalHits</ecalCollectionName>
+            <timeCut>true</timeCut>
+        </driver>
+        <driver name="ReconParticle" type="org.hps.recon.particle.HpsReconParticleDriver">          
+        </driver>
+        <driver name="LCIOWriter" type="org.lcsim.util.loop.LCIODriver">
+            <outputFilePath>${outputFile}.slcio</outputFilePath>
+        </driver>
+        <driver name="CleanupDriver" type="org.lcsim.recon.tracking.digitization.sisim.config.ReadoutCleanupDriver"/>
+    </drivers>
+</lcsim>
SVNspam 0.1