Commit in lcsim/src/org/lcsim/recon/cluster/mipfinder on MAIN
NonProjectiveMipFinder.java+22-191.2 -> 1.3
MJC: Deal with a rare assertion failure in mip-finger

lcsim/src/org/lcsim/recon/cluster/mipfinder
NonProjectiveMipFinder.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- NonProjectiveMipFinder.java	17 Apr 2008 12:24:27 -0000	1.2
+++ NonProjectiveMipFinder.java	23 May 2008 00:28:55 -0000	1.3
@@ -22,7 +22,7 @@
  * and curving MIPs better.
  *
  * @author Mat Charles <[log in to unmask]>
- * @version $Id: NonProjectiveMipFinder.java,v 1.2 2008/04/17 12:24:27 mcharles Exp $
+ * @version $Id: NonProjectiveMipFinder.java,v 1.3 2008/05/23 00:28:55 mcharles Exp $
  */
 
 public class NonProjectiveMipFinder extends Driver implements Clusterer
@@ -716,6 +716,7 @@
     protected Stub mergeStubs(Collection<Stub> inputStubs) {
 	// Be careful if modifying this -- Stub is picky about the order in which hits are added.
 	Stub mergedStub = new Stub();
+	Set<Integer> vetoLayers = new HashSet<Integer>();
 	for (Stub stub : inputStubs) {
 	    for (int iLayer = stub.getInnerLayer(); iLayer <= stub.getOuterLayer(); iLayer++) {
 		Collection<CalorimeterHit> hitsInLayerInThisStub = stub.getHitsInLayer(iLayer);
@@ -743,36 +744,28 @@
 			    mergedStub.addNonEdgeHit(firstHit);
 			    mergedStub.addDoubleHit(firstHit,secondHit);
 			} else if (hitsInLayerInMergedStub.size()==1) {
-			    // Contains one... need to add the other as a double-hit
+			    // Stub already has one hit -- assuming it's one of
+			    // these two, we need to add the other as a double-hit
 			    if (hitsInLayerInMergedStub.contains(firstHit)) {
 				mergedStub.addDoubleHit(firstHit, secondHit);
 			    } else if (hitsInLayerInMergedStub.contains(secondHit)) {
 				mergedStub.addDoubleHit(secondHit, firstHit);
 			    } else {
-				throw new AssertionError("Book-keeping error");
+				// Ambiguity -- one hits in this layer already in the
+				// merged stub, separate from the two we want to add.
+				// We can't put three hits in there -- veto this layer.
+				vetoLayers.add(new Integer(iLayer));
 			    }
 			} else if (hitsInLayerInMergedStub.size()==2) {
 			    // Contains two... should both be in there already
 			    if (hitsInLayerInMergedStub.contains(firstHit) && hitsInLayerInMergedStub.contains(secondHit)) {
 				// It all checks out
 			    } else {
-				String printme = new String();
-				printme += "Book-keeping error: Trying to add a double-hit in layer "+iLayer+" with cell IDs ";
-				printme += firstHit.getCellID()+" and "+secondHit.getCellID()+"\n";
-				printme += "But merged stub already contains two hits with cell IDs ";
-				for (CalorimeterHit tmpHit : hitsInLayerInMergedStub) {
-				    printme += tmpHit.getCellID();
-				    printme += " ";
-				}
-				printme += "so I don't know what to do!";
-				Set<CalorimeterHit> tmpSet = new HashSet<CalorimeterHit>();
-				tmpSet.addAll(hitsInLayerInThisStub);
-				tmpSet.addAll(hitsInLayerInMergedStub);
-				printme += "\nDealing with "+tmpSet.size()+" unique hits.";
-				throw new AssertionError(printme);
+				// Ambiguity -- 3+ hits in this layer. Veto it.
+				vetoLayers.add(new Integer(iLayer));
 			    }
 			} else {
-			    throw new AssertionError("Book-keeping error");
+			    throw new AssertionError("Book-keeping error: "+hitsInLayerInMergedStub.size()+" hits in layer (must be 2 or fewer)");
 			}
 		    } else {
 			// One hit...
@@ -781,15 +774,22 @@
 			    mergedStub.addNonEdgeHit(firstHit);
 			} else if (hitsInLayerInMergedStub.contains(firstHit)) {
 			    // Already in there -- don't need to re-add
-			} else {
+			} else if (hitsInLayerInMergedStub.size()==1) {
 			    // Already have a different hit -- add this one as a double-hit
 			    CalorimeterHit existingHit = hitsInLayerInMergedStub.iterator().next();
 			    mergedStub.addDoubleHit(existingHit, firstHit);
+			} else {
+			    // Already have 2+ hits in there -- can't add mode.
+			    vetoLayers.add(new Integer(iLayer));
 			}
 		    }
 		}
 	    }
 	}
+	// Did we veto any layers?
+	for (Integer iLayer : vetoLayers) {
+	    mergedStub.removeAllHitsInLayer(iLayer);
+	}
 	return mergedStub;
     }
 
@@ -1368,6 +1368,9 @@
 	    // Found no problems => compatible
 	    return true;
 	}
+	public void removeAllHitsInLayer(int layer) {
+	    m_hits.remove(layer);
+	}
 	public void addNonEdgeHit(CalorimeterHit hit) { 
 	    int layer = getLayer(hit);
 	    if (m_hits.get(layer) != null) { throw new AssertionError("Error"); }
CVSspam 0.2.8