Commit in lcsim/src/org/lcsim/recon/cluster/structural on MAIN
FragmentHandler.java+59-31.2 -> 1.3
MJC: Make fragment handler more flexible

lcsim/src/org/lcsim/recon/cluster/structural
FragmentHandler.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- FragmentHandler.java	12 Oct 2007 20:34:52 -0000	1.2
+++ FragmentHandler.java	12 Oct 2007 23:26:45 -0000	1.3
@@ -19,7 +19,7 @@
  *
  * @see FragmentIdentifier
  * @see FragmentMerger
- * @version $Id: FragmentHandler.java,v 1.2 2007/10/12 20:34:52 mcharles Exp $
+ * @version $Id: FragmentHandler.java,v 1.3 2007/10/12 23:26:45 mcharles Exp $
  */
 
 public class FragmentHandler extends Driver
@@ -73,6 +73,22 @@
 	    }
 	}
 
+	// Add in the lists of known fragment and nonfragment clusters:
+	for (String name : m_inputFragmentClusterListNames) {
+	    List<Cluster> clist = event.get(Cluster.class, name);
+	    fragments.addAll(clist);
+	}
+	for (String name : m_inputNonfragmentClusterListNames) {
+	    List<Cluster> clist = event.get(Cluster.class, name);
+	    nonFragments.addAll(clist);
+	}
+	for (String name : m_inputSeparateNonfragmentClusterListNames.keySet()) {
+	    List<Cluster> clist = event.get(Cluster.class, name);
+	    System.out.println("DEBUG: Added a list of "+clist.size()+" clusters, named "+name+", to be kept separate and written out as "+m_inputSeparateNonfragmentClusterListNames.get(name));
+	    nonFragments.addAll(clist);
+	}
+
+	// Check for pathological case
 	if ( ! m_allowAllFragments && nonFragments.size()==0 && fragments.size()>0 ) {
 	    // If non-fragments list is empty, promote largest non-fragment.
 	    Cluster largestCluster = null;
@@ -98,12 +114,40 @@
 	    }
 	}
 
+	// Special case: Some of the known non-fragments are to be kept separate.
+	for (String name : m_inputSeparateNonfragmentClusterListNames.keySet()) {
+	    List<Cluster> clist = event.get(Cluster.class, name);
+	    List<Cluster> outputList = new Vector<Cluster>();
+	    System.out.println("DEBUG: Checking clusters from input list "+name+" of size "+clist.size()+"...");
+	    for (Cluster originalClus : clist) {
+		List<Cluster> removalList = new Vector<Cluster>();
+		System.out.println("DEBUG: Checking original cluster of "+originalClus.getCalorimeterHits().size()+" hits against a list of "+nonFragments.size()+" non-fragment output clusters...");
+		for (Cluster modifiedClus : mergedClusters) {
+		    System.out.println("DEBUG:    Comparing to modified cluster with "+modifiedClus.getCalorimeterHits().size()+" hits that contains "+modifiedClus.getClusters().size()+"sub-clusters...");
+		    if (modifiedClus.getClusters().contains(originalClus)) {
+			removalList.add(modifiedClus);
+			outputList.add(modifiedClus);
+		    }
+		}
+		if (removalList.size() != 1) { throw new AssertionError("Internal consistency failure: cluster appears "+removalList.size()+" times (should be 1)"); }
+		for (Cluster clus : removalList) {
+		    boolean removedOK = mergedClusters.remove(clus);
+		    if (!removedOK) { throw new AssertionError("Internal consistency failure: failed to remove cluster"); }
+		}
+	    }
+	    event.put(m_inputSeparateNonfragmentClusterListNames.get(name), outputList);
+	}
+
 	// Output
 	event.put(m_outputClusterListName, mergedClusters);
 	event.put(m_outputHitMapName, leftoverHits);
     }
 
-    /** Add another named list of clusters. */
+    /** Add another named list of clusters that will always be treated as fragments. */
+    public void addInputFragmentClusterList(String name) { m_inputFragmentClusterListNames.add(name); }
+    /** Add another named list of clusters that will always be treated as nonfragments. */
+    public void addInputNonfragmentClusterList(String name) { m_inputNonfragmentClusterListNames.add(name); }
+    /** Add another named list of clusters. We'll decide whether they are fragments. */
     public void addInputClusterList(String name) {m_inputClusterListNames.add(name);}
     /** Add another named HitMap. */
     public void addInputHitMap(String name) {m_inputHitMapNames.add(name);}
@@ -116,9 +160,21 @@
     /** Specify the FragmentMerger to use. */
     public void setFragmentMerger(FragmentMerger merger) {m_fragmentMerger=merger;}
 
+    /**
+     * Add another named list of clusters that will always be 
+     * treated as nonfragments and will be kept separate.
+     * These clusters will NOT be written out in the main
+     * output cluster list. Instead, they are written out
+     * (with fragments bundled in) to a named list.
+     */
+    public void addInputSeparateNonfragmentClusterList(String inputName, String outputName) { m_inputSeparateNonfragmentClusterListNames.put(inputName, outputName); }
+
     List<String> m_inputClusterListNames = new Vector<String>();
     List<String> m_inputHitMapNames = new Vector<String>();
-    
+    List<String> m_inputFragmentClusterListNames = new Vector<String>();
+    List<String> m_inputNonfragmentClusterListNames = new Vector<String>();
+    Map<String,String> m_inputSeparateNonfragmentClusterListNames = new HashMap<String,String>();
+
     String m_outputClusterListName;
     String m_outputHitMapName;
     FragmentIdentifier m_fragmentID;
CVSspam 0.2.8