Commit in lcsim/src/org/lcsim/contrib/uiowa on MAIN
MIPReassignmentAlgorithm.java+232-2201.1 -> 1.2
fix the bug where no mip

lcsim/src/org/lcsim/contrib/uiowa
MIPReassignmentAlgorithm.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- MIPReassignmentAlgorithm.java	2 Jul 2008 00:07:42 -0000	1.1
+++ MIPReassignmentAlgorithm.java	7 Jul 2008 00:28:06 -0000	1.2
@@ -26,66 +26,127 @@
 import org.lcsim.geometry.subdetector.CylindricalCalorimeter;
 import org.lcsim.geometry.*;
 import org.lcsim.util.decision.*;
+import hep.aida.ITree;
+import hep.aida.IAnalysisFactory;
+import hep.aida.IHistogramFactory;
+import hep.aida.IHistogram1D;
+import hep.aida.ICloud1D;
+import hep.aida.ICloud2D;
 
-public class MIPReassignmentAlgorithm implements ReassignClustersAlgorithm {
+	public class MIPReassignmentAlgorithm implements ReassignClustersAlgorithm {
     protected double m_limit;
     protected LocalHelixExtrapolator m_findCluster;
     protected Map<Track, Set<Cluster>> m_newMapTrackToShowerComponents;
     protected List<Cluster> m_mips;
 	protected Set<CalorimeterHit> m_allhits;
-	static int exam = 0;
-	private boolean debug = false;
- 
-    public MIPReassignmentAlgorithm(double limit, LocalHelixExtrapolator findCluster, Map<Track, Set<Cluster>> newMapTrackToShowerComponents, List<Cluster> mips, Set<CalorimeterHit> allHits) {
-	m_limit = limit;
-	m_findCluster = findCluster;
-    m_newMapTrackToShowerComponents = newMapTrackToShowerComponents;
-    m_mips = mips;
-	m_allhits = allHits; 
+	protected int exam = 0;
+	protected boolean nomip = false;
+	protected boolean debug = true;
+	protected double m_distance = 0;
+    protected double m_angle = 0; 
+	protected double m_degree = 0;
+	protected double m_costheta = 0;
+
+	protected ICloud2D m_histo_radian_distance;
+	protected ICloud2D m_histo_degree_distance;
+	protected ICloud2D m_histo_costheta_distance;
+	protected double hcalR=1410.0; //HCAL inner radius for sid01
+	protected double hcalZ=1820.0; //HCAL inner Z for sid01
+
+    public MIPReassignmentAlgorithm(double limit, LocalHelixExtrapolator findCluster, Map<Track, Set<Cluster>> newMapTrackToShowerComponents, List<Cluster> mips, Set<CalorimeterHit> allHits, ICloud2D histo1, ICloud2D histo2, ICloud2D histo3 ) {
+		m_limit = limit;
+		m_findCluster = findCluster;
+		m_newMapTrackToShowerComponents = newMapTrackToShowerComponents;
+		m_mips = mips;
+		m_allhits = allHits; 
+		m_histo_radian_distance = histo1;
+		m_histo_degree_distance = histo2;
+		m_histo_costheta_distance = histo3;
     }
 
 	 
 	public Double computeFigureOfMerit(Track tr, Cluster clus) {
 
+		Hep3Vector tangent = new BasicHep3Vector(); //extrapolated direction
+		Hep3Vector tangentUnit = new BasicHep3Vector(); 
+		Hep3Vector clusterPosition = new BasicHep3Vector(); //cluster position
+		Hep3Vector displacement = new BasicHep3Vector(); //displacement between cluster and last point
+		Hep3Vector displacementUnit = new BasicHep3Vector();
+	
 		List<Hep3Vector> lastTwoPositions = computePointsOfShower(tr);
-
-        Hep3Vector last0pos =  lastTwoPositions.get(0);
-        Hep3Vector last1pos =  lastTwoPositions.get(1);
-		Hep3Vector tangent = VecOp.sub(last0pos, last1pos);
-        Hep3Vector tangentUnit = VecOp.unit(tangent);
-        Hep3Vector clusterPosition = new BasicHep3Vector(clus.getPosition());
-        Hep3Vector displacement = VecOp.sub(clusterPosition, last1pos);
-        Hep3Vector displacementUnit = VecOp.unit(displacement);
-        
-		double angle=Math.acos(VecOp.dot(tangentUnit, displacementUnit));
-        if (angle < m_limit) return new Double(angle);
-        
-		return null;
+       	Hep3Vector last0pos =  lastTwoPositions.get(0);
+       	Hep3Vector last1pos =  lastTwoPositions.get(1);
+		if(debug) System.out.println("Debug: last0pos= " + last0pos.magnitude() );	
+		if(debug) System.out.println("Debug: last1pos= " + last1pos.magnitude() );	
+		Hep3Vector interceptPoint = m_findCluster.performExtrapolation(tr);		
+	
+		if(lastTwoPositions == null){ //These is no mip close to track.
+    		if (interceptPoint != null) {
+	        	tangent = m_findCluster.getTangent(); //tangent obtained using extrapolated track.
+			    tangentUnit = VecOp.unit(tangent);
+				clusterPosition = new BasicHep3Vector(clus.getPosition());
+				displacement = VecOp.sub(clusterPosition, interceptPoint);
+				displacementUnit = VecOp.unit(displacement);
+			}
+		}else{ //There is a mip attached to track.
+ 	      	tangent = VecOp.sub(last0pos, last1pos); //tangent obtained using last two points.
+    	    tangentUnit = VecOp.unit(tangent);
+        	clusterPosition = new BasicHep3Vector(clus.getPosition());
+        	displacement = VecOp.sub(clusterPosition, last1pos);
+        	displacementUnit = VecOp.unit(displacement);
+			if(debug) {
+				System.out.println("Debug: From last two points");
+				System.out.println("Debug: Displacement from (r="+Math.sqrt(last1pos.x()*last1pos.x()+last1pos.y()*last1pos.y())+", z="+last1pos.z()+")");
+				System.out.println("to (r="+Math.sqrt(clusterPosition.x()*clusterPosition.x()+clusterPosition.y()*clusterPosition.y())+", z="+clusterPosition.z()+")");                                                                                                            
+			}
         }
+		
+		m_distance=displacement.magnitude()*VecOp.dot(tangentUnit, displacementUnit); //longitudinal distance 
+		m_angle=Math.acos(VecOp.dot(tangentUnit, displacementUnit));
+		m_degree=m_angle*180/3.14;
+		m_costheta = VecOp.dot(tangentUnit, displacementUnit);
+		m_histo_radian_distance.fill(m_angle,m_distance);
+		m_histo_degree_distance.fill(m_degree,m_distance);
+		m_histo_costheta_distance.fill(m_costheta,m_distance);
+	
+		if(debug){
+			System.out.println("Debug: Angle= " + m_angle);
+			System.out.println("Debug: Distance= " + m_distance);
+		}
+		
+		if (m_angle < m_limit) return new Double(m_angle); // return the angle if it is below cone angle.
+                                                                                                                              
+        return null;
+	}
 
 
-    protected List<Hep3Vector> computePointsOfShower(Track tr) {
+    //find last two points just before track started to shower.
+	protected List<Hep3Vector> computePointsOfShower(Track tr) {
         Set<Cluster> clusoftrk = m_newMapTrackToShowerComponents.get(tr);
 		Set<Cluster> mipsoftrk = new HashSet<Cluster>();
         for(Cluster cl : clusoftrk)
-       		 if(m_mips.contains(cl))
-				 mipsoftrk.add(cl);
-        
+			if(m_mips.contains(cl))
+				mipsoftrk.add(cl);
+        if(mipsoftrk.size() == 0) return null; //no any mip found
 
 		if(debug) System.out.println("Given track");
 		
 		Hep3Vector interceptPoint = m_findCluster.performExtrapolation(tr);
+		Hep3Vector tangent =  m_findCluster.getTangent();
+	    Hep3Vector tangentUnit = VecOp.unit(tangent);
+				
 		Hep3Vector first = new BasicHep3Vector();	
 		Hep3Vector trackThreeMomentum = new BasicHep3Vector(tr.getMomentum());
         double trackMomentum = trackThreeMomentum.magnitude();
 		
 		if(debug){
-		System.out.println("Debug: Size of Cluster of track= " + clusoftrk.size());
-		System.out.println("Debug: Size of Cluster of Mip of track= " + mipsoftrk.size());
-		System.out.println("Debug: trk momentum= " + trackMomentum);
-		if(interceptPoint != null) System.out.println("Debug: extra trk: pos= " + interceptPoint.magnitude() + " ("+ interceptPoint.x() + " " + interceptPoint.y() + " " + interceptPoint.z() + ")" );
+			System.out.println("Debug: Size of Cluster of track= " + clusoftrk.size());
+			System.out.println("Debug: Size of Cluster of Mip of track= " + mipsoftrk.size());
+			System.out.println("Debug: trk momentum= " + trackMomentum);
+			if(interceptPoint != null) System.out.println("Debug: extra trk: pos= " + interceptPoint.magnitude() + " ("+ interceptPoint.x() + " " + interceptPoint.y() + " " + interceptPoint.z() + ")" );
 		}
 
+		//find closest mip to track
 		SortedMap<Double, Cluster> mipsSortedByDistance = new TreeMap();
         for(Cluster cl : mipsoftrk){
 			CalorimeterHit firstHit =  cl.getCalorimeterHits().get(0);
@@ -96,216 +157,167 @@
         	double z = id.getPosition()[2];
         	first = new BasicHep3Vector(x, y, z);
 			Hep3Vector displacement = new BasicHep3Vector();
-				if (interceptPoint != null) {
-					displacement = VecOp.sub(first, interceptPoint);
-					double distance = displacement.magnitude();
-		    		mipsSortedByDistance.put(distance, cl);
-        		}
-		 }
-
-		SortedMap<Integer, CalorimeterHit> sortedMipBylayer = new TreeMap();
-        int t=0;
-		Iterator iter = mipsSortedByDistance.entrySet().iterator();
-        while(iter.hasNext() && t == 0){
-		t++;
-		Map.Entry entry = (Map.Entry) iter.next();
-        Double key = (Double)entry.getKey();
-        Cluster cl = (Cluster)entry.getValue();
-                for( int i = 0 ; i < cl.getCalorimeterHits().size() ; i++){
-					 CalorimeterHit hit=cl.getCalorimeterHits().get(i);
-					 IDDecoder idMIP = hit.getIDDecoder();
-                     idMIP.setID(hit.getCellID());
-                     int layerMIP = idMIP.getLayer();
-                     sortedMipBylayer.put(layerMIP, hit);
-				}
+			if (interceptPoint != null) {
+				displacement = VecOp.sub(first, interceptPoint);
+				double distance = displacement.magnitude();
+		    	mipsSortedByDistance.put(distance, cl);
+        	}
+		}
+		
+		//arrange by the length of the hit position
+		SortedMap<Double, CalorimeterHit> sortedMIPbyPos = new TreeMap();
+		Cluster cl = mipsSortedByDistance.get(mipsSortedByDistance.firstKey());
+        for( int i = 0 ; i < cl.getCalorimeterHits().size() ; i++){
+			CalorimeterHit hit=cl.getCalorimeterHits().get(i);
+		    IDDecoder idMIP = hit.getIDDecoder();
+            idMIP.setID(hit.getCellID());
+			double x = idMIP.getPosition()[0];
+			double y = idMIP.getPosition()[1];
+			double z = idMIP.getPosition()[2];
+   	        double pmag = Math.sqrt(x*x+y*y+z*z);
+            sortedMIPbyPos.put(pmag, hit);
 		}
-			
-
-			Hep3Vector last0pos = new BasicHep3Vector();
-        	Hep3Vector last1pos = new BasicHep3Vector();
-			Hep3Vector last2pos = new BasicHep3Vector();
-        	Hep3Vector last3pos = new BasicHep3Vector();
-			Hep3Vector last4pos = new BasicHep3Vector();
-
 
+		List<Hep3Vector> miphit = new ArrayList<Hep3Vector>();//vector list of each hit
+		
 		Set<Long> allHitIDs = new HashSet<Long>();	
 		for (CalorimeterHit hit : m_allhits)  allHitIDs.add(hit.getCellID());
 
-		if(debug) System.out.println("Debug: Starting mip");
-
 		int lastlayer = 0;
 		long[] lastlayer5x5x2 = new long[26];
 		String lastDet = new String();
-		int sizeofmip = sortedMipBylayer.size();
-		Iterator itermip = sortedMipBylayer.entrySet().iterator();
-		for(int i=0 ; i < sizeofmip ;i++){ 
-		Map.Entry entry = (Map.Entry) itermip.next();
-        Integer key = (Integer)entry.getKey();
-        CalorimeterHit hit = (CalorimeterHit)entry.getValue();
-			
-				Hep3Vector last= lastPosition(hit,i,allHitIDs);			
-
-				if(i == (sizeofmip-1)) {
-					IDDecoder lastid = hit.getIDDecoder();
-                	lastid.setID(hit.getCellID());
-                	lastlayer = lastid.getLayer();
-					last0pos = last;
-				    lastDet = hit.getSubdetector().getName();
-					lastlayer5x5x2 = lastid.getNeighbourIDs(1, 2, 2);
-					}	
-            	if(i == (sizeofmip-2)) last1pos = last;
-				if(i == (sizeofmip-3)) last2pos = last;
-				if(i == (sizeofmip-4)) last3pos = last;
-       }
-	   int s=sizeofmip;
-       if(debug) System.out.println("Debug: The end of the mip" );
-
-	
-			Hep3Vector lastv_mip = VecOp.sub(last0pos, last1pos);
-		    Hep3Vector lastv_mip_unit = VecOp.unit(lastv_mip);
-
-			int cl = 0 ;
-			for( int i = lastlayer+1 ; i < lastlayer+100 ; i++){
-			SortedMap<Double, CalorimeterHit> sortedHitbyAngle= new TreeMap();
-        		for (CalorimeterHit hit : m_allhits)  {
-
-				IDDecoder id = hit.getIDDecoder();
-	            id.setID(hit.getCellID());
-    	        double x = id.getPosition()[0];
-        	    double y = id.getPosition()[1];
-            	double z = id.getPosition()[2];
-
-				Set<Long> nearIDs = new HashSet<Long>();
-                    for (long lastnearID : lastlayer5x5x2 ) nearIDs.add(lastnearID);
-				boolean cond = ((id.getLayer() != 0) &&  (lastDet == hit.getSubdetector().getName()) && nearIDs.contains(hit.getCellID())) || ((id.getLayer() == 0) &&  (lastDet != hit.getSubdetector().getName()));
-
-					if(i <= 30) cl = i;
-					if(i > 30) cl = i-31;		
-
-					if(cl==id.getLayer() && cond){
-					Hep3Vector hitpos = new BasicHep3Vector();
-            		hitpos = new BasicHep3Vector(x,y,z);
-					Hep3Vector test = VecOp.sub(hitpos, last0pos);
-					double d = test.magnitude();
-					Hep3Vector test_unit = VecOp.unit(test);
-					double a = Math.acos(VecOp.dot(lastv_mip_unit, test_unit));
-					if ( a < 0.79) { // 45 degree = 0.79 radian
-						sortedHitbyAngle.put(a, hit);
-		            	IDDecoder idt = hit.getIDDecoder();
-		                idt.setID(hit.getCellID());
-					}
-					}
+		int sizeofmip = sortedMIPbyPos.size();
 
+		if(debug) System.out.println("Debug: Starting mip");
+		Iterator itermip = sortedMIPbyPos.entrySet().iterator();
+		for(int i=0 ; i < sizeofmip ;i++){ 
+			Map.Entry entry = (Map.Entry) itermip.next();
+			Double key = (Double)entry.getKey();
+			CalorimeterHit hit = (CalorimeterHit)entry.getValue();
+			IDDecoder id = hit.getIDDecoder();
+			id.setID(hit.getCellID());
+			if(i==0){
+				if(id.getLayer()>3){
+					System.out.println("No mip found near interceptpoint! It's secondary mip.");
+					return null;
 				}
-				 
-				Hep3Vector last = new BasicHep3Vector();
-				Iterator it = sortedHitbyAngle.entrySet().iterator();
-				int te = 0; 
-		        while(it.hasNext() && te == 0){
-				te++;
-        		Map.Entry e = (Map.Entry) it.next();
-        		Double k = (Double)e.getKey();
-        		CalorimeterHit hit = (CalorimeterHit)e.getValue();
-				last=lastPosition(hit,s,allHitIDs);
-				s++;
-
-                
-	
-				if(!(last3pos == null)) last4pos = last3pos;
-				if(!(last2pos == null)) last3pos = last2pos;
-				if(!(last1pos == null)) last2pos = last1pos;
-				if(!(last0pos == null)) last1pos = last0pos;
-				if(!(last == null))  last0pos = last;
-			
-				IDDecoder id = hit.getIDDecoder();
-                id.setID(hit.getCellID());
+			}
+			Hep3Vector pos = hitPosition(hit,allHitIDs);
+			miphit.add(pos);
+        }
+		if(debug) System.out.println("Debug: The end of the mip" );
+		
+		for( int i = 0 ; i < 100 ; i++){ // 100? until finding shower starting point
+			//To get the information from last hit
+			CalorimeterHit hit = sortedMIPbyPos.get(sortedMIPbyPos.lastKey());
+			IDDecoder id = hit.getIDDecoder();
+			id.setID(hit.getCellID());
+			double x = id.getPosition()[0];
+			double y = id.getPosition()[1];
+			double z = id.getPosition()[2];
+			double p = Math.sqrt(x*x+y*y+z*z);								
+			lastlayer = id.getLayer();
+			lastDet = hit.getSubdetector().getName();
+			lastlayer5x5x2 = id.getNeighbourIDs(1, 2, 2);
+		
+		    //Searh next hit in next layer and arrange in angular order
+			SortedMap<Double, CalorimeterHit> sortedHitbyPos= new TreeMap();
+        	for (CalorimeterHit hitall : m_allhits){
+				IDDecoder idall = hitall.getIDDecoder();
+	            idall.setID(hitall.getCellID());
+    	        double xall = idall.getPosition()[0];
+        	    double yall = idall.getPosition()[1];
+            	double zall = idall.getPosition()[2];
+				double hitmag = Math.sqrt(xall*xall+yall*yall+zall*zall);
+				Set<Long> nearIDs = new HashSet<Long>();
+                for (long lastnearID : lastlayer5x5x2 ) nearIDs.add(lastnearID);
 	
-				lastDet = hit.getSubdetector().getName();
-                lastlayer5x5x2 = id.getNeighbourIDs(1, 2, 2);
-
-				}
-
+				//use geometric information and layer number to find next hit
+				boolean cond = true;
+				if(lastlayer == 30) cond = hitmag > p && idall.getLayer() == 0; // next layer = 0 since HCAL starts and nearID does not work
+			    else cond = hitmag > p && nearIDs.contains(hitall.getCellID()); //examine in a given area.
+
+				if(cond){
+            			Hep3Vector hitpos = new BasicHep3Vector(xall,yall,zall);
+						Hep3Vector test = VecOp.sub(hitpos, miphit.get(miphit.size()-1));
+						Hep3Vector test_unit = VecOp.unit(test);
+						Hep3Vector lastmip = VecOp.sub(miphit.get(miphit.size()-1), miphit.get(miphit.size()-2));
+						Hep3Vector lastmip_unit = VecOp.unit(lastmip);
+						double a = Math.acos(VecOp.dot(lastmip_unit, test_unit));
+						sortedHitbyPos.put(a, hitall);
+				}		
 
+			}		
+			
+			if(sortedHitbyPos.size() == 0) continue; 
+			CalorimeterHit hitAdd = sortedHitbyPos.get(sortedHitbyPos.firstKey()); //add the hit with a smallest angle 
+			IDDecoder idAdd = hitAdd.getIDDecoder();
+	        idAdd.setID(hitAdd.getCellID());
+			double xAdd = idAdd.getPosition()[0];
+			double yAdd = idAdd.getPosition()[1];
+			double zAdd = idAdd.getPosition()[2];
+			double Addmag=Math.sqrt(xAdd*xAdd+yAdd*yAdd+zAdd*zAdd);
+			sortedMIPbyPos.put(Addmag,hitAdd);
+			
+			Hep3Vector tempPos = hitPosition(hitAdd,allHitIDs);
+			miphit.add(tempPos);
 
-				if (exam > 2) {
+			if (exam > 2) {
 				if(debug) System.out.println("Debug: showering is already started " + exam + " layers ago" );
-					break;
-				}
+				if(miphit.size() < 5) break; // if size of miphit is fewer than 5, not need to go back to three layers before 
+				else for(int k=0; k < 3 ; k++) miphit.remove(miphit.size()-1);
+				break;
 			}
-
-		if(debug){
-		 System.out.println("Debug: last4pos= " + last4pos.magnitude() + " (" +last4pos.x() + " " + last4pos.y() + " " + last4pos.z()+ ")" ); 
-		 System.out.println("Debug: last3pos= " + last3pos.magnitude() + " (" +last3pos.x() + " " + last3pos.y() + " " + last3pos.z()+ ")");
-         System.out.println("Debug: last2pos= " + last2pos.magnitude() + " (" + last2pos.x() + " " + last2pos.y() + " " + last2pos.z()+ ") ");
-		 System.out.println("Debug: last1pos= " + last1pos.magnitude() +  " (" + last1pos.x() + " " + last1pos.y() + " " + last1pos.z()+ ")");
-         System.out.println("Debug: last0pos= " + last0pos.magnitude() + " (" + last0pos.x() + " " + last0pos.y() + " " + last0pos.z()+ ")");
 		}
 
-	      List<Hep3Vector> lastTwoPositions = new ArrayList<Hep3Vector>(); 
-		 if(last4pos != null ){
-					lastTwoPositions.add(last3pos);
-                    lastTwoPositions.add(last4pos);
-		 }	
-		 else if(last3pos != null){
-                    lastTwoPositions.add(last2pos);
-                    lastTwoPositions.add(last3pos);
-         }
-	     else if(last2pos != null){
-                    lastTwoPositions.add(last1pos);
-                    lastTwoPositions.add(last2pos);
-         }
-         else {
-                    lastTwoPositions.add(last0pos);
-                    lastTwoPositions.add(last1pos);
-         }
-
-
-
-	  	  return lastTwoPositions;
-        }
-
-
-
-			protected Hep3Vector lastPosition(CalorimeterHit hit, int s, Set<Long> allHitIDs){
-            
-			    int count3x3=0;
-                int count5x5=0;
-				int count7x7=0;
-				int count9x9=0;
-                IDDecoder id = hit.getIDDecoder();
-                id.setID(hit.getCellID());
-				int lay = id.getLayer();
-                double x = id.getPosition()[0];
-                double y = id.getPosition()[1];
-                double z = id.getPosition()[2];
-                Hep3Vector v = new BasicHep3Vector(x,y,z);
-                int p = (int) (v.magnitude());
-                                                                                                                              
-                long[] neighbours3x3 = id.getNeighbourIDs(0, 1, 1);
-                long[] neighbours5x5 = id.getNeighbourIDs(0, 2, 2);
-				long[] neighbours7x7 = id.getNeighbourIDs(0, 3, 3);
-                long[] neighbours9x9 = id.getNeighbourIDs(0, 4, 4);
-				for (long neighbourID3x3 : neighbours3x3)
-                    if (allHitIDs.contains(neighbourID3x3)) count3x3++;
-                for (long neighbourID5x5 : neighbours5x5)
-                    if (allHitIDs.contains(neighbourID5x5)) count5x5++;
-				for (long neighbourID7x7 : neighbours7x7)
-                    if (allHitIDs.contains(neighbourID7x7)) count7x7++;
-				for (long neighbourID9x9 : neighbours9x9)
-                    if (allHitIDs.contains(neighbourID9x9)) count9x9++;
-				                
+		if(debug){
+			int k=0;
+			if(miphit.size() < 4) k = miphit.size();
+			else k = 4;
+			for(int i =0; i < k ;i++){
+			System.out.println("Debug: last " + i + " pos= " + miphit.get(miphit.size()-1-i).magnitude() + " (" +miphit.get(miphit.size()-1-i).x() + " " + miphit.get(miphit.size()-1-i).y() + " " + miphit.get(miphit.size()-1-i).z()+ ")" ); 
+			}
+		}		
 
+	    List<Hep3Vector> lastTwoPositions = new ArrayList<Hep3Vector>();
+		if(miphit.size() < 5){ //since there are only 4 hits
+		lastTwoPositions.add(miphit.get(1));
+		lastTwoPositions.add(miphit.get(0));
+		} else {		
+		lastTwoPositions.add(miphit.get(miphit.size()-1));
+        lastTwoPositions.add(miphit.get(miphit.size()-2));
+		}
+		
+	  	return lastTwoPositions;
+	}
 
+	//give the hit position vector and examine neighbour hits
+	protected Hep3Vector hitPosition(CalorimeterHit hit, Set<Long> allHitIDs){
+           
+		IDDecoder id = hit.getIDDecoder();
+		id.setID(hit.getCellID());
+		int lay = id.getLayer();
+		double x = id.getPosition()[0];
+		double y = id.getPosition()[1];
+		double z = id.getPosition()[2];
+		Hep3Vector v = new BasicHep3Vector(x,y,z);
+		int p = (int) (v.magnitude());
+
+		int count[] = new int[4];
+		for (int i =0 ; i < 4 ; i++){
+			long[] neighbours = id.getNeighbourIDs(0,i+1,i+1);
+			for(long neighbourID : neighbours)
+				if (allHitIDs.contains(neighbourID)) count[i]++;
+		}
 
-				if ( count9x9 >=2 ) exam++ ;
-				else exam = 0;
+		if ( count[3] >=2 ) exam++ ; // if number of neighbour hits in 9x9 is larger than 1, count 1 
+		else exam = 0; // if number of neighbour is none, set to zero and start again from 0 
 				
-				if(debug){
-                System.out.println("Debug: "+s+" hit: pos=" + p + " , " + count3x3 + " hits in 3x3, " + count5x5 + " hits in 5x5 " + count7x7 + " hits in 7x7 " + count9x9 + " hits in 9x9 " + lay + " layer of " + hit.getSubdetector().getName());
-                }
+		if(debug){
+			System.out.println(" hit: pos=" + p + " , " + count[0] + " hits in 3x3, " + count[1] + " hits in 5x5 " + count[2] + " hits in 7x7 " + count[3] + " hits in 9x9 " + lay + " layer of " + hit.getSubdetector().getName());
+		}
 	
-				return v;
-				}
-
+		return v;
+	}
 
 }
CVSspam 0.2.8