Commit in lcsim/src/org/lcsim/recon/cluster/mst on MAIN
MSTClusterDriver.java+133-281.2 -> 1.3
Expanded/rewrote a lot of the driver so that it can handle HitMaps

lcsim/src/org/lcsim/recon/cluster/mst
MSTClusterDriver.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- MSTClusterDriver.java	16 Feb 2006 21:45:02 -0000	1.2
+++ MSTClusterDriver.java	17 Feb 2006 00:48:04 -0000	1.3
@@ -10,23 +10,54 @@
 
 import org.lcsim.recon.cluster.util.*;
 import org.lcsim.util.decision.*;
+import org.lcsim.util.hitmap.HitMap;
 
 /**
   * A convenience class which wraps the MSTClusterBuilder in a Driver.
   *
-  * @version $Id: MSTClusterDriver.java,v 1.2 2006/02/16 21:45:02 mcharles Exp $
+  * @version $Id: MSTClusterDriver.java,v 1.3 2006/02/17 00:48:04 mcharles Exp $
   */
 public class MSTClusterDriver extends Driver {
 
-    private double threshold = 30.0;
-    private String calType = "EMCal";
-    private String clusterName = "MSTCluster "+calType;
-    private Metrics metrics = new GeometricalDistance();
-    private DecisionMakerSingle<Cluster> inputDecision = new ClusterNotEmptyDecisionMaker();
-    private DecisionMakerSingle<Cluster> seedDecision = new ClusterNotEmptyDecisionMaker();
-    private DecisionMakerPair<Cluster,Cluster> pairDecision = new ClusterNotEmptyDecisionMaker();
-    private DecisionMakerSingle<Cluster> outputDecision = new ClusterNotEmptyDecisionMaker();
-    private List<String> listToGet;
+    protected double threshold = 30.0;
+    protected String clusterName;
+    protected Metrics metrics = new GeometricalDistance();
+    protected DecisionMakerSingle<Cluster> inputDecision = new ClusterNotEmptyDecisionMaker();
+    protected DecisionMakerSingle<Cluster> seedDecision = new ClusterNotEmptyDecisionMaker();
+    protected DecisionMakerPair<Cluster,Cluster> pairDecision = new ClusterNotEmptyDecisionMaker();
+    protected DecisionMakerSingle<Cluster> outputDecision = new ClusterNotEmptyDecisionMaker();
+    protected List<String> m_inputListNames = new Vector<String>();
+    protected String m_outputHitMapName;
+    protected List<String> m_inputHitMapNames = new Vector<String>();
+
+    /**
+      * Constructor.
+      */
+    public MSTClusterDriver() {}
+
+    /**
+      * Convenience constructor.
+      *
+      * @param outputHitMap       Write any unused hits here
+      * @param outputClusterList  Write the list of clusters here
+      */
+    public MSTClusterDriver(String outputHitMap, String outputClusterList) {
+        m_outputHitMapName = outputHitMap;
+        clusterName = outputClusterList;
+    }
+
+    /**
+      * Convenience constructor.
+      *
+      * @param inputHitMap        Name of the HitMap to use
+      * @param outputHitMap       Write any unused hits here
+      * @param outputClusterList  Write the list of clusters here
+      */
+    public MSTClusterDriver(String inputHitMap, String outputHitMap, String outputClusterList) {
+        m_inputHitMapNames.add(inputHitMap);
+        m_outputHitMapName = outputHitMap;
+        clusterName = outputClusterList;
+    }
 
   /**
     * Constructor. Takes a string parameter which controls the behaviour.
@@ -37,22 +68,26 @@
     * For all three strings, additional lists may be specified with the 
     * addUserInputList() method.
     *
+    * This constructor is deprecated: the hit list names are hardwired
+    * to pre-DigiSim strings by default.
+    *
     * @param inString Calorimeter type (see above)
     */
-    public MSTClusterDriver(String inString){
-        calType = inString;
-        listToGet = new ArrayList<String>();
+    @Deprecated public MSTClusterDriver(String inString){
+        String calType = inString;
+	clusterName = "MSTCluster "+calType;
+        m_inputListNames = new ArrayList<String>();
         if ( calType == "EMCal" ) {
-            listToGet.add("EcalBarrHits");
-	    listToGet.add("EcalEndcapHits");
+            m_inputListNames.add("EcalBarrHits");
+	    m_inputListNames.add("EcalEndcapHits");
         } else if ( calType == "HCal" ) {
-	    listToGet.add("HcalBarrHits");
-            listToGet.add("HcalEndcapHits");
+	    m_inputListNames.add("HcalBarrHits");
+            m_inputListNames.add("HcalEndcapHits");
         } else if ( calType == "all" ) {
-            listToGet.add("EcalBarrHits");
-	    listToGet.add("EcalEndcapHits");
-	    listToGet.add("HcalBarrHits");
-            listToGet.add("HcalEndcapHits");
+            m_inputListNames.add("EcalBarrHits");
+	    m_inputListNames.add("EcalEndcapHits");
+	    m_inputListNames.add("HcalBarrHits");
+            m_inputListNames.add("HcalEndcapHits");
         } else if ( calType == "User" ) {
         } else {
             throw new AssertionError("Calorimeter type '"+calType+"' not recognized.");
@@ -63,10 +98,31 @@
     * Process one event.
     */
     public void process(EventHeader event){
+	// Set up the inputs:
+        List<HitMap> inputHitMaps = new Vector<HitMap>();
+        Collection<CalorimeterHit> inputHits = new Vector<CalorimeterHit>();
+        for (String inputHitMapName : m_inputHitMapNames) {
+            HitMap currentInputHitMap = (HitMap) (event.get(inputHitMapName));
+            inputHitMaps.add(currentInputHitMap);
+            inputHits.addAll(currentInputHitMap.values());
+        }
+
+	// This is the list of clusters/wrapped hits we'll use
         List<Cluster> inputList = new ArrayList<Cluster> ();
 
-        for (String s : listToGet) {
-          ObjectToClusterWrapper wrap = new BasicObjectToClusterWrapper();
+        // Wrap the input HitMap hits:
+        ObjectToClusterWrapper wrap = new BasicObjectToClusterWrapper();
+        List<Cluster> wrappedHits = null;
+        try {
+            wrappedHits = wrap.wrapListOfObjects(inputHits);
+        } catch (UnwrappableObjectException x) {
+            // We fed it an  object it didn't understand
+	    throw new AssertionError(x);
+	}
+	inputList.addAll(wrappedHits);
+	
+	// Add any other inputs (lists of hits, clusters, ...)
+        for (String s : m_inputListNames) {
           List l = event.get(Object.class, s);
           try {
             List<Cluster> wrappedList = wrap.wrapListOfObjects(l);
@@ -76,17 +132,45 @@
             throw new AssertionError(x);
           }
 	}
+
+	// Apply prefilter:
         ListFilter<Cluster> filter = new ListFilter<Cluster> (inputDecision);
 	List<Cluster> list = filter.filterList(inputList);
 
+	// Make the clusterer:
         MSTClusterBuilder clusterBuilder = new MSTClusterBuilder( list, event );
         clusterBuilder.registerMetrics(metrics);
         clusterBuilder.setThreshold(threshold);
         clusterBuilder.setSeedDecision(seedDecision);
         clusterBuilder.setPairDecision(pairDecision);
         clusterBuilder.setOutputDecision(outputDecision);
-        List<Cluster> outputList = clusterBuilder.doClustering();
-        event.put(clusterName, outputList );
+
+	// Cluster & write out cluster list:
+	List<Cluster> outputList = clusterBuilder.doClustering();
+	if (clusterName != null) {
+	    event.put(clusterName, outputList );
+	}
+
+	// Now, produce an updated HitMap
+	if (m_outputHitMapName != null) {
+	    HitMap outputHitMap = new HitMap();
+	    // Add all input hits
+	    for (Cluster inputClus : inputList) {
+		for (CalorimeterHit hit : inputClus.getCalorimeterHits()) {
+		    Long id = new Long(hit.getCellID());
+		    outputHitMap.put(id,hit);
+		}
+	    }
+	    // Remove all used hits:
+	    for (Cluster clus : outputList) {
+		for (CalorimeterHit hit : clus.getCalorimeterHits()) {
+		    Long cellID = new Long(hit.getCellID());
+		    outputHitMap.remove(cellID);
+		}
+	    }
+	    // Write out:
+	    event.put(m_outputHitMapName, outputHitMap);
+	}
     }
 
   /**
@@ -151,16 +235,37 @@
         outputDecision = decision;}
 
   /**
-    * Add a list of hits/clusters to be clustered.
+    * Add a list of objects to be clustered. Currently,
+    * CalorimeterHits and Clusters are accepted.
     *
     * @param tag Name of the list as stored in the EventHeader
     */
     public void addUserInputList(String tag){
-        listToGet.add(tag);
+        m_inputListNames.add(tag);
     }
 
   /**
     * Wipes ALL information on lists of hits/clusters to use.
     */
-    public void resetUserInputList(){listToGet.clear();}
+    public void resetUserInputList(){
+	clearInputLists();
+	clearInputHitMaps();
+    }
+
+    /**
+     * Add a HitMap of hits to cluster
+     */
+    public void addInputHitMap(String name) { m_inputHitMapNames.add(name); }
+
+    /**
+     * Set the name to write a HitMap of unused hits to.
+     * If not set, no HitMap will be written out.
+     */
+    public void setOutputHitMap(String name) { m_outputHitMapName = name; }
+
+
+    protected void clearInputLists() { m_inputListNames.clear(); }
+    protected void clearInputHitMaps() { m_inputHitMapNames.clear(); }
+
+ 
 }
CVSspam 0.2.8