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  February 2015

HPS-SVN February 2015

Subject:

r2042 - /java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClusterDriver.java

From:

[log in to unmask]

Reply-To:

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

Date:

Wed, 4 Feb 2015 22:03:35 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (150 lines)

Author: [log in to unmask]
Date: Wed Feb  4 14:03:29 2015
New Revision: 2042

Log:
Copy hit list so that modifications by Clusterer does not effect master list.  Add optional validation of output clusters.  Setup logger for specific Driver class.  HPSJAVA-412

Modified:
    java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClusterDriver.java

Modified: java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClusterDriver.java
 =============================================================================
--- java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClusterDriver.java	(original)
+++ java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClusterDriver.java	Wed Feb  4 14:03:29 2015
@@ -1,5 +1,6 @@
 package org.hps.recon.ecal.cluster;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.logging.Logger;
 
@@ -31,9 +32,9 @@
  */
 public class ClusterDriver extends Driver {
     
-    protected static Logger logger = LogUtil.create(ClusterDriver.class, new BasicFormatter(ClusterDriver.class.getSimpleName()));
-    
-    protected String ecalName = "Ecal";    
+    Logger logger;
+    
+    protected String ecalName = "Ecal";
     protected HPSEcal3 ecal;
     protected NeighborMap neighborMap;
     protected String outputClusterCollectionName = "EcalClusters";
@@ -49,11 +50,13 @@
     protected boolean calculateProperties = false;
     protected boolean applyCorrections = false;
     protected boolean sortHits = false;
+    protected boolean validateClusters = false;
     
     /**
      * No argument constructor.
      */
     public ClusterDriver() {
+        logger = LogUtil.create(getClass().getSimpleName(), new BasicFormatter(getClass().getSimpleName()));
     }
     
     /**
@@ -177,6 +180,14 @@
      */
     public void setCuts(double[] cuts) {
         this.cuts = cuts;
+    }
+    
+    /**
+     * Set whether to validate the output.
+     * @param validateClusters True to validate output.
+     */
+    public void setValidateClusters(boolean validateClusters) {
+        this.validateClusters = validateClusters;
     }
     
     /**
@@ -222,7 +233,10 @@
         if (event.hasCollection(CalorimeterHit.class, inputHitCollectionName)) {       
             List<CalorimeterHit> hits = event.get(CalorimeterHit.class, inputHitCollectionName);
             logger.fine("input hit collection " + inputHitCollectionName + " has " + hits.size() + " hits");
-            List<Cluster> clusters = clusterer.createClusters(event, hits);
+            
+            // Cluster the hits, copying the list from the event in case the clustering algorithm modifies it.
+            List<Cluster> clusters = clusterer.createClusters(event, new ArrayList<CalorimeterHit>(hits));
+            
             if (clusters == null) {
                 throw new RuntimeException("The clusterer returned a null list from its createClusters method.");
             }
@@ -258,6 +272,11 @@
                     logger.finer("Collection is set to transient and will not be persisted.");
                     event.getMetaData(clusters).setTransient(true);
                 }
+                
+                if (validateClusters) {
+                    // Perform basic validation checks.
+                    this.validateClusters(event);
+                }
             }
         } else {
             this.getLogger().severe("The input hit collection " + this.inputHitCollectionName + " is missing from the event.");
@@ -277,7 +296,7 @@
     }
     
     /**
-     * Get a Clusterer using type inference for the concrete type.
+     * Get a {@link Clusterer} using type inference for the concrete type.
      * @return The Clusterer object.
      */
     @SuppressWarnings("unchecked")
@@ -285,4 +304,51 @@
         // Return the Clusterer and cast it to the type provided by the caller.
         return (ClustererType) clusterer;
     }
-}
+
+    /**
+     * Perform basic validation of the cluster output collection, including checking
+     * that the cluster collection was created, clusters are not null, 
+     * none of the clustered hits are null, and each hit exists in the input 
+     * hit collection.
+     * @param event The LCSim event.
+     */
+    void validateClusters(EventHeader event) {
+        if (!event.hasCollection(Cluster.class, outputClusterCollectionName)) {
+            throw new RuntimeException("Cluster collection " + outputClusterCollectionName + " is missing.");
+        }
+        List<Cluster> clusters = event.get(Cluster.class, outputClusterCollectionName);
+        List<CalorimeterHit> inputHitCollection = event.get(CalorimeterHit.class, inputHitCollectionName);
+        for (int clusterIndex = 0; clusterIndex < clusters.size(); clusterIndex++) {
+            logger.finest("checking cluster " + clusterIndex);
+            Cluster cluster = clusters.get(clusterIndex);
+            if (clusters.get(clusterIndex) == null) {
+                throw new RuntimeException("The Cluster at index " + clusterIndex + " is null.");
+            }
+            List<CalorimeterHit> clusterHits = cluster.getCalorimeterHits();
+            logger.finest("cluster has " + clusterHits.size() + " hits");
+            for (int hitIndex = 0; hitIndex < clusterHits.size(); hitIndex++) {
+                logger.finest("checking cluster hit " + hitIndex);                              
+                CalorimeterHit clusterHit = clusterHits.get(hitIndex);
+                if (clusterHit == null) {
+                    throw new RuntimeException("The CalorimeterHit at index " + hitIndex + " in the cluster is null.");
+                }
+                if (!inputHitCollection.contains(clusterHit)) {
+                    logger.severe("The CalorimeterHit at index " + hitIndex + " with ID " + clusterHit.getIdentifier().toHexString() + " is missing from the input hit collection.");
+                    printHitIDs(inputHitCollection);
+                    throw new RuntimeException("The CalorimeterHit at index " + hitIndex + " in the cluster is missing from the input hit collection.");
+                }
+            }
+        }
+    }
+    
+    void printHitIDs(List<CalorimeterHit> hits) {        
+        StringBuffer buffer = new StringBuffer();
+        buffer.append("hit IDs");
+        buffer.append('\n');
+        for (CalorimeterHit hit : hits) {            
+            buffer.append(hit.getIdentifier().toHexString());
+            buffer.append('\n');
+        }
+        logger.finest(buffer.toString());        
+    }
+}

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