Print

Print


Commit in lcsim/src/org/lcsim/recon/cluster/mipfinder on MAIN
NonProjectiveMipFinder.java+89-31.1 -> 1.2
MJC: Work-around for broken geometry

lcsim/src/org/lcsim/recon/cluster/mipfinder
NonProjectiveMipFinder.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- NonProjectiveMipFinder.java	26 Mar 2008 19:45:57 -0000	1.1
+++ NonProjectiveMipFinder.java	17 Apr 2008 12:24:27 -0000	1.2
@@ -22,7 +22,7 @@
  * and curving MIPs better.
  *
  * @author Mat Charles <[log in to unmask]>
- * @version $Id: NonProjectiveMipFinder.java,v 1.1 2008/03/26 19:45:57 mcharles Exp $
+ * @version $Id: NonProjectiveMipFinder.java,v 1.2 2008/04/17 12:24:27 mcharles Exp $
  */
 
 public class NonProjectiveMipFinder extends Driver implements Clusterer
@@ -795,6 +795,8 @@
 
 
     protected void findIsolatedAndSemiIsolatedHits(Map<Long,CalorimeterHit>  hitsToProcess, Map<Long,CalorimeterHit> allHits, Map<Integer,List<CalorimeterHit>> isolatedHits, Map<Integer,List<CalorimeterHit>> semiIsolatedHits, Map<CalorimeterHit,CalorimeterHit> doubleHits) {
+	Set<Long> vetoHitIDs = new HashSet<Long>();
+	Set<CalorimeterHit> vetoHits = new HashSet<CalorimeterHit>();
 	for (Map.Entry<Long,CalorimeterHit> hitPair : hitsToProcess.entrySet()) {
 	    Long hitID = hitPair.getKey();
 	    CalorimeterHit hit = hitPair.getValue();
@@ -807,14 +809,78 @@
 		if (allHits.keySet().contains(neighbour)) {
 		    countFoundNeighbours++;
 		    lastNeighbourHit = allHits.get(neighbour);
+		    // Verify that this hit is a neighbour of its neighbour
+		    id.setID(neighbour);
+		    long[] neighboursOfNeighbour = id.getNeighbourIDs(0,1,1);
+		    if (neighboursOfNeighbour.length == 0) {
+			System.out.println("ERROR: Hit has no neighbours!");
+			Hep3Vector hit2pos = new BasicHep3Vector(lastNeighbourHit.getPosition());
+			long tryAgainID = id.findCellContainingXYZ(hit2pos.x(), hit2pos.y(), hit2pos.z());
+			boolean consistent = (tryAgainID == neighbour);
+			if (consistent) {
+			    System.out.println("id.findCellContainingXYZ maps "+neighbour+" -> "+tryAgainID+" -- OK.");
+			} else {
+			    System.out.println("id.findCellContainingXYZ maps "+neighbour+" at ("+hit2pos.x()+", "+hit2pos.y()+", "+hit2pos.z()+") -> "+tryAgainID+" -- ERROR");
+			}
+		    }
+		    boolean foundReverseMap = false;
+		    for (long neighbourOfNeighbour : neighboursOfNeighbour) {
+			if (neighbourOfNeighbour == hitID) {
+			    foundReverseMap = true;
+			    break;
+			}
+		    }
+		    if (!foundReverseMap) { 
+			id.setID(hitID);
+			double hit1_gridphi = 0.0;
+			double hit1_dphi = 0.0;
+			if (id instanceof org.lcsim.geometry.segmentation.NonprojectiveCylinder) {
+			    hit1_gridphi = ((org.lcsim.geometry.segmentation.NonprojectiveCylinder)(id)).getGridSizePhi();
+			    hit1_dphi = ((org.lcsim.geometry.segmentation.NonprojectiveCylinder)(id)).computeDeltaPhiForLayer();
+			}
+			double hit1_phi = id.getPhi();
+			id.setID(neighbour);
+			double hit2_gridphi = 0.0;
+			if (id instanceof org.lcsim.geometry.segmentation.NonprojectiveCylinder) {
+			    hit2_gridphi = ((org.lcsim.geometry.segmentation.NonprojectiveCylinder)(id)).getGridSizePhi();
+			}
+			double hit2_phi = id.getPhi();
+			Hep3Vector hit1pos = new BasicHep3Vector(hit.getPosition());
+			Hep3Vector hit2pos = new BasicHep3Vector(lastNeighbourHit.getPosition());
+			double r1 = Math.sqrt(hit1pos.x()*hit1pos.x() + hit1pos.y()*hit1pos.y());
+			double r2 = Math.sqrt(hit2pos.x()*hit2pos.x() + hit2pos.y()*hit2pos.y());
+			double costh1 = hit1pos.z() / hit1pos.magnitude();
+			double costh2 = hit2pos.z() / hit2pos.magnitude();
+			for (long neighbourOfNeighbour : neighboursOfNeighbour) {
+			    id.setID(neighbourOfNeighbour);
+			    double non_x = id.getX();
+			    double non_y = id.getY();
+			    double non_z = id.getZ();
+			    double non_r = Math.sqrt(non_x*non_x + non_y*non_y);
+			    System.out.println(" * Hit "+neighbour+" has neighbour "+neighbourOfNeighbour+" at ("+non_x+", "+non_y+", "+non_z+") -- r="+non_r);
+			}
+			System.out.println("Inconsistency in neighbours map: Hit (id="+hitID+") in layer "+getLayer(hit)+" has neighbour "+neighbour
+			    +", but hit "+neighbour+" in layer "+getLayer(lastNeighbourHit)+" does not have "+hitID+" as a neighbour."
+			    +" hit1 is at (r="+r1+", costh="+costh1+", x="+hit1pos.x()+", y="+hit1pos.y()+", z="+hit1pos.z()+");"
+			    +" hit2 is at (r="+r2+", costh="+costh2+", x="+hit2pos.x()+", y="+hit2pos.y()+", z="+hit2pos.z()+");"
+			    +" for ID of type "+id.getClass().getName()
+			    +" -- hit1 has "+neighbours.length+" neighbours and hit2 has "+neighboursOfNeighbour.length+" neighbours."
+			    +" -- hit1 has phi="+hit1_phi+" and gridphi="+hit1_gridphi+" and dphi="+hit1_dphi
+			    +" -- hit2 has phi="+hit2_phi+" and gridphi="+hit2_gridphi
+			    ); 
+			vetoHitIDs.add(hitID);
+			vetoHitIDs.add(neighbour);
+			vetoHits.add(hit);
+			vetoHits.add(lastNeighbourHit);
+		    }
 		}
 	    }
 	    int layer = getLayer(hit);
-	    if (countFoundNeighbours == 0) {
+	    if (countFoundNeighbours == 0 && !vetoHitIDs.contains(hitID)) {
 		List<CalorimeterHit> isolatedHitsInThisLayer = isolatedHits.get(layer);
 		if (isolatedHitsInThisLayer == null) { isolatedHitsInThisLayer = new Vector<CalorimeterHit>(); isolatedHits.put(layer, isolatedHitsInThisLayer); }
 		isolatedHitsInThisLayer.add(hit);
-	    } else if (countFoundNeighbours == 1) {
+	    } else if (countFoundNeighbours == 1 && !vetoHitIDs.contains(hitID) && !vetoHitIDs.contains(lastNeighbourHit)) {
 		List<CalorimeterHit> semiIsolatedHitsInThisLayer = semiIsolatedHits.get(layer);
 		if (semiIsolatedHitsInThisLayer == null) { semiIsolatedHitsInThisLayer = new Vector<CalorimeterHit>(); semiIsolatedHits.put(layer, semiIsolatedHitsInThisLayer); }
 		semiIsolatedHitsInThisLayer.add(hit);
@@ -824,6 +890,26 @@
 		}
 	    }
 	}
+
+	// Go back and remove anything vetoed
+	for (CalorimeterHit vetoHit : vetoHits) {
+	    for (List<CalorimeterHit> isolatedList : isolatedHits.values()) {
+		isolatedList.remove(vetoHit);
+	    }
+	    for (List<CalorimeterHit> semiIsolatedList : semiIsolatedHits.values()) {
+		semiIsolatedList.remove(vetoHit);
+	    }
+	    doubleHits.remove(vetoHit);
+	    List<CalorimeterHit> tagForRemoval = new Vector<CalorimeterHit>();
+	    for (CalorimeterHit testHit : doubleHits.keySet()) {
+		if (doubleHits.get(testHit) == vetoHit) {
+		    tagForRemoval.add(testHit);
+		}
+	    }
+	    for (CalorimeterHit removeHit : tagForRemoval) {
+		doubleHits.remove(removeHit);
+	    }
+	}
 	return;
     }
 
CVSspam 0.2.8