Commit in lcsim/src/org/lcsim/recon/cluster/mipfinder on MAIN
MIPClusterBuilder.java+25-201.2 -> 1.3
TrackClusterDriver.java+55-401.7 -> 1.8
+80-60
2 modified files
MJC: Refactor mip finder a bit

lcsim/src/org/lcsim/recon/cluster/mipfinder
MIPClusterBuilder.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- MIPClusterBuilder.java	16 Jan 2006 21:04:40 -0000	1.2
+++ MIPClusterBuilder.java	5 Jun 2008 17:00:02 -0000	1.3
@@ -117,21 +117,11 @@
 		flash.remove(hit); 
 		
 		extend(cluster,hit,flash); 
-		//if ( cluster.isGoodMIP() ) {
 		if (isGoodMIP(cluster)) {
-//
-// See if MIP forks. Criterion is two SingeHits in the same Layer
-//
-		    boolean lFork = false; 
-		    Set<Integer> layers = iSingleHitsInLayer.keySet();
-		    for (Integer currentTestLayer : layers) {
-			Integer hitsInLayer = iSingleHitsInLayer.get(currentTestLayer);
-			if (hitsInLayer.intValue() >= 2) {
-			    lFork = true; 
-			}
-		    }
-
+		    // See if MIP forks.
+		    boolean lFork = checkForFork();
 		    cluster.doesFork(lFork); 
+		    // Add cluster to output
 		    vCluster.add(cluster); 
 		}
 	    }
@@ -156,7 +146,7 @@
 	return vCluster; 
     }
 
-    private void extend(MIPCluster c, 
+    protected void extend(MIPCluster c, 
 			CalorimeterHit h, 
 			HitCollection hc ) 
     {
@@ -194,7 +184,7 @@
 	
     }
 
-    private boolean validate(CalorimeterHit h){
+    protected boolean validate(CalorimeterHit h){
 	boolean lValidate = false; 
 
 	for (AbstractHitType aType : hitTypes) {
@@ -235,8 +225,8 @@
     private Hashtable<Integer, Vector<CalorimeterHit> > hitTable = new Hashtable<Integer, Vector<CalorimeterHit> > ();
     private List<AbstractHitType> hitTypes;
 
-    private Flash flash; 
-    private Collection<CalorimeterHit> nucleii = new Vector<CalorimeterHit>(); 
+    protected Flash flash; 
+    protected Collection<CalorimeterHit> nucleii = new Vector<CalorimeterHit>(); 
     private boolean lUserNucleii = false; 
 
     public void provideNucleii(Collection<CalorimeterHit> v){
@@ -348,10 +338,10 @@
 	return ((int) direction ); 
     }
 
-    private int nSeedLayers = 4; 
+    protected int nSeedLayers = 4; 
     private int firstLayer = 0; 
-    private int direction = 1; 
-    private Map<Integer, Integer> iSingleHitsInLayer; 
+    protected int direction = 1; 
+    protected Map<Integer, Integer> iSingleHitsInLayer; 
 
     private Vector<Cluster> vMIP = new Vector<Cluster>();  
     private int depth = 0; 
@@ -361,4 +351,19 @@
     public void setDebugMode(boolean b){
 	lDebug = b; 
     }
+
+//
+// See if MIP forks. Criterion is two SingeHits in the same Layer
+//
+    protected boolean checkForFork() {
+	boolean lFork = false;
+	Set<Integer> layers = iSingleHitsInLayer.keySet();
+	for (Integer currentTestLayer : layers) {
+	    Integer hitsInLayer = iSingleHitsInLayer.get(currentTestLayer);
+	    if (hitsInLayer.intValue() >= 2) {
+		lFork = true; 
+	    }
+	}
+	return lFork;
+    }
 }

lcsim/src/org/lcsim/recon/cluster/mipfinder
TrackClusterDriver.java 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- TrackClusterDriver.java	9 May 2008 23:44:41 -0000	1.7
+++ TrackClusterDriver.java	5 Jun 2008 17:00:02 -0000	1.8
@@ -22,7 +22,7 @@
  * An alternative driver. This is designed to find any track
  * segment, not just MIPs.
  *
- * @version $Id: TrackClusterDriver.java,v 1.7 2008/05/09 23:44:41 mcharles Exp $
+ * @version $Id: TrackClusterDriver.java,v 1.8 2008/06/05 17:00:02 mcharles Exp $
  */
 
 public class TrackClusterDriver extends Driver implements Clusterer
@@ -91,50 +91,14 @@
    public List<Cluster> createClusters(List<CalorimeterHit> hits)
     {
 	// Look for track segments. Any isolated hit could be a seed...
-        List<AbstractHitType> hitTypes = new Vector<AbstractHitType>();
-        SingleHit singleHit = new SingleHit();
-        DoubleHit doubleHit = new DoubleHit();
-        singleHit.useInSeeds(true);
-        doubleHit.useInSeeds(false);
-        hitTypes.add(singleHit);
-        hitTypes.add(doubleHit);
+        List<AbstractHitType> hitTypes = defineHitTypes();
 
 	// We need to figure out how many layers there are in the calorimeter.
 	// This number should be the same for all hits.
-	int nLayers = 0; // We'll set this to the right number shortly
-	boolean firstCheck = true;
-	for (CalorimeterHit hit : hits) {
-	    // Look up the number of layers for this hit's subdetector
-	    org.lcsim.geometry.Subdetector subdet = hit.getSubdetector();
-	    org.lcsim.geometry.layer.Layering layering = subdet.getLayering();
-	    int currentNumLayers = layering.getNumberOfLayers();
-	    if (firstCheck) {
-		// First hit => set nLayers and move on
-		nLayers = currentNumLayers;
-		firstCheck = false;
-	    } else {
-		// Not first hit => check that # layers matches
-		if (nLayers != currentNumLayers) { 
-		    throw new AssertionError("Layering mismatch: "+nLayers+" vs "+currentNumLayers+". Maybe you mixed ECAL and HCAL?");
-		}
-	    }
-	}
+	int nLayers = countLayersInCalorimeter(hits);
 
 	// OK. Next, separate the hits out according to their layer:
-	Map<Integer, List<CalorimeterHit>> hitsPerLayer = new HashMap<Integer, List<CalorimeterHit>>();
-	for (CalorimeterHit hit : hits) {
-	    // Look up the layer of this hit:
-	    IDDecoder id = hit.getIDDecoder();
-	    id.setID(hit.getCellID());
-	    Integer layer = new Integer(id.getLayer());
-	    // Add it to the list for that layer:
-	    List<CalorimeterHit> layerList = hitsPerLayer.get(layer);
-	    if (layerList == null) {
-		layerList = new Vector<CalorimeterHit>();
-		hitsPerLayer.put(layer, layerList);
-	    }
-	    layerList.add(hit);
-	}
+	Map<Integer, List<CalorimeterHit>> hitsPerLayer = sortHitsByLayer(hits);
 	
 	// Now run the cluster builder. We have to do this in a
 	// hackish way, unfortunately.
@@ -215,4 +179,55 @@
     String m_outputHitMapName;
     boolean m_debug = false;
     DecisionMakerSingle<Cluster> m_userFilter = null;
+
+    protected int countLayersInCalorimeter(List<CalorimeterHit> hits) {
+	int nLayers = 0; // We'll set this to the right number shortly
+	boolean firstCheck = true;
+	for (CalorimeterHit hit : hits) {
+	    // Look up the number of layers for this hit's subdetector
+	    org.lcsim.geometry.Subdetector subdet = hit.getSubdetector();
+	    org.lcsim.geometry.layer.Layering layering = subdet.getLayering();
+	    int currentNumLayers = layering.getNumberOfLayers();
+	    if (firstCheck) {
+		// First hit => set nLayers and move on
+		nLayers = currentNumLayers;
+		firstCheck = false;
+	    } else {
+		// Not first hit => check that # layers matches
+		if (nLayers != currentNumLayers) { 
+		    throw new AssertionError("Layering mismatch: "+nLayers+" vs "+currentNumLayers+". Maybe you mixed ECAL and HCAL?");
+		}
+	    }
+	}
+	return nLayers;
+    }
+
+    protected Map<Integer, List<CalorimeterHit>> sortHitsByLayer(List<CalorimeterHit> hits) {
+	Map<Integer, List<CalorimeterHit>> hitsPerLayer = new HashMap<Integer, List<CalorimeterHit>>();
+	for (CalorimeterHit hit : hits) {
+	    // Look up the layer of this hit:
+	    IDDecoder id = hit.getIDDecoder();
+	    id.setID(hit.getCellID());
+	    Integer layer = new Integer(id.getLayer());
+	    // Add it to the list for that layer:
+	    List<CalorimeterHit> layerList = hitsPerLayer.get(layer);
+	    if (layerList == null) {
+		layerList = new Vector<CalorimeterHit>();
+		hitsPerLayer.put(layer, layerList);
+	    }
+	    layerList.add(hit);
+	}
+	return hitsPerLayer;
+    }
+
+    protected List<AbstractHitType> defineHitTypes() {
+	List<AbstractHitType> hitTypes = new Vector<AbstractHitType>();
+        SingleHit singleHit = new SingleHit();
+        DoubleHit doubleHit = new DoubleHit();
+        singleHit.useInSeeds(true);
+        doubleHit.useInSeeds(false);
+        hitTypes.add(singleHit);
+        hitTypes.add(doubleHit);
+	return hitTypes;
+    }
 }
CVSspam 0.2.8