LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  December 2014

HPS-SVN December 2014

Subject:

r1797 - /java/trunk/ecal-recon/src/test/java/org/hps/recon/ecal/cluster/ClustererTest.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Sat, 20 Dec 2014 00:23:35 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (199 lines)

Author: [log in to unmask]
Date: Fri Dec 19 16:23:30 2014
New Revision: 1797

Log:
Add test that will run clustering recon on mock data using a number of the standard algorithms.

Added:
    java/trunk/ecal-recon/src/test/java/org/hps/recon/ecal/cluster/ClustererTest.java

Added: java/trunk/ecal-recon/src/test/java/org/hps/recon/ecal/cluster/ClustererTest.java
 =============================================================================
--- java/trunk/ecal-recon/src/test/java/org/hps/recon/ecal/cluster/ClustererTest.java	(added)
+++ java/trunk/ecal-recon/src/test/java/org/hps/recon/ecal/cluster/ClustererTest.java	Fri Dec 19 16:23:30 2014
@@ -0,0 +1,183 @@
+package org.hps.recon.ecal.cluster;
+
+import hep.aida.IHistogram1D;
+import hep.aida.IHistogram2D;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.logging.Level;
+
+import junit.framework.TestCase;
+
+import org.hps.conditions.database.DatabaseConditionsManager;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.EventHeader;
+import org.lcsim.job.EventMarkerDriver;
+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;
+
+/**
+ * This test does basic sanity checks on the output from the Clusterer algorithms,
+ * and it creates an AIDA file with useful plots.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class ClustererTest extends TestCase {
+    
+    static final String fileLocation = "http://www.lcsim.org/test/hps-java/MockDataReconTest.slcio";
+    File inputFile;
+    File testOutputDir;
+    static int nEvents = 50; 
+    
+    public void setUp() {
+        // Cache the input file.
+        try {
+            inputFile = new FileCache().getCachedFile(new URL(fileLocation));
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        
+        // Create test output dir.
+        testOutputDir = new TestOutputFile(getClass().getSimpleName());
+        testOutputDir.mkdir();        
+    }
+   
+    public void testClasInnerCalClusterer() {
+        // This is just replicating the default cuts.
+        runClustererTest("ClasInnerCalClusterer", new double[] { 0.0075, 0.1, 0.3, 0.0, 20.0, 0. }, true);;
+    }
+    
+    public void testSimplClasInnerCalClusterer() {
+        runClustererTest("SimpleClasInnerCalClusterer", new double[] { 0.0, 0.0, 9999.0, 0. }, true);
+    }
+    
+    public void testNearestNeighborClusterer() {
+        runClustererTest("NearestNeighborClusterer", new double[] { 0.0, 2.0 }, true);
+    }
+    
+    public void testLegacyClusterer() {
+        runClustererTest("LegacyClusterer", new double[] { 0.0, 0.0 }, true);
+    }
+    
+    /**
+     * Run the standard test for a Clusterer.
+     * @param clustererName The name of the Clusterer.
+     * @param cuts The cut values.
+     * @param writeLcioFile Whether or not to write an LCIO output file.
+     */
+    private void runClustererTest(String clustererName, double[] cuts, boolean writeLcioFile) {
+        
+        // Initialize conditions system.
+        new DatabaseConditionsManager();
+        
+        // Config loop.
+        LCSimLoop loop = new LCSimLoop();       
+        try {
+            loop.setLCIORecordSource(inputFile);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        
+        loop.add(new EventMarkerDriver());
+        
+        // Configure the ClusterDriver and add it to the loop.
+        String clusterCollectionName = clustererName + "Clusters";
+        ClusterDriver clusterDriver = new ClusterDriver();
+        clusterDriver.setClustererName(clustererName);
+        clusterDriver.setCuts(cuts);
+        clusterDriver.getLogger().setLevel(Level.ALL);
+        clusterDriver.setInputHitCollectionName("EcalHits");       
+        clusterDriver.setOutputClusterCollectionName(clusterCollectionName);
+        clusterDriver.setRaiseErrorNoHitCollection(true);
+        clusterDriver.getLogger().setLevel(Level.INFO);
+        loop.add(clusterDriver);                         
+        
+        loop.add(new ClusterCheckDriver(clusterCollectionName));
+        
+        if (writeLcioFile) {
+            loop.add(new LCIODriver(testOutputDir.getPath() + File.separator + clustererName));
+        }
+        
+        // Run the job.
+        try {
+            loop.loop(nEvents);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        loop.dispose();
+    }
+    
+    /**
+     * This Driver will check some of the basic Cluster values (currently just size and energy).
+     * It also produces some QA plots for each Clusterer in its own output AIDA dir within the plot tree.
+     */
+    static class ClusterCheckDriver extends Driver {                
+        
+        AIDA aida = AIDA.defaultInstance();
+        IHistogram1D energyH1D;
+        IHistogram1D uncorrectedEnergyH1D;
+        IHistogram1D countH1D;
+        IHistogram1D sizeH1D;    
+        IHistogram1D highestHitEnergyH1D;
+        IHistogram1D hitEnergyH1D;
+        IHistogram2D rawVsCorrectedH2D;
+        IHistogram1D positionXH1D;
+        IHistogram1D positionYH1D;
+        String clusterCollectionName;
+        String clustererName;        
+        
+        ClusterCheckDriver(String clusterCollectionName) {
+            this.clusterCollectionName = clusterCollectionName;
+        }        
+        
+        public void startOfData() {
+            energyH1D = aida.histogram1D(clusterCollectionName + "/Cluster Energy", 300, 0.0, 3.0);
+            uncorrectedEnergyH1D = aida.histogram1D(clusterCollectionName + "/Uncorrected Cluster Energy", 200, 0.0, 2.0);
+            countH1D = aida.histogram1D(clusterCollectionName + "/Cluster Count", 10, -0.5, 9.5);
+            sizeH1D = aida.histogram1D(clusterCollectionName + "/Cluster Size", 30, 0.5, 30.5);
+            highestHitEnergyH1D = aida.histogram1D(clusterCollectionName + "/Highest Hit Energy", 300, 0.0, 1.5);
+            hitEnergyH1D = aida.histogram1D(clusterCollectionName + "/Hit Energy", 300, 0.0, 1.5);
+            rawVsCorrectedH2D = aida.histogram2D(clusterCollectionName + "/Raw vs Corrected Energy", 100, 0.0, 2.0, 100, 0.0, 2.0);
+            positionXH1D = aida.histogram1D(clusterCollectionName + "/Position X", 300, 0., 1500.0);
+            positionYH1D = aida.histogram1D(clusterCollectionName + "/Position Y", 500, 0., 1000.0);
+        }
+        
+        public void process(EventHeader event) {
+            List<Cluster> clusters = event.get(Cluster.class, this.clusterCollectionName);
+            for (Cluster cluster : clusters) {
+                assertTrue("The cluster energy is invalid.", cluster.getEnergy() > 0.);
+                assertTrue("The cluster has no hits.", !cluster.getCalorimeterHits().isEmpty());                
+                energyH1D.fill(cluster.getEnergy());
+                double rawEnergy = ClusterUtilities.computeRawEnergy(cluster);
+                uncorrectedEnergyH1D.fill(rawEnergy);
+                sizeH1D.fill(cluster.getCalorimeterHits().size());
+                rawVsCorrectedH2D.fill(rawEnergy, cluster.getEnergy());
+                for (CalorimeterHit hit : cluster.getCalorimeterHits()) {
+                    hitEnergyH1D.fill(hit.getCorrectedEnergy());
+                }                
+                highestHitEnergyH1D.fill(ClusterUtilities.getHighestEnergyHit(cluster).getCorrectedEnergy());
+                positionXH1D.fill(Math.abs(cluster.getPosition()[0]));
+                positionYH1D.fill(Math.abs(cluster.getPosition()[1]));
+            }            
+            countH1D.fill(clusters.size());
+        }              
+    }
+    
+    /**
+     * This method writes the AIDA file to disk from all the tests.
+     */
+    public void tearDown() {
+        try {
+            AIDA.defaultInstance().saveAs(testOutputDir.getPath() + File.separator + this.getClass().getSimpleName() + ".aida");
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }  
+}

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use