Commit in lcsim/src/org/lcsim/contrib/uiowa on MAIN
ShowerPointFinder.java+36-751.1 -> 1.2
remove unnesessary part

lcsim/src/org/lcsim/contrib/uiowa
ShowerPointFinder.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- ShowerPointFinder.java	10 Jul 2008 20:34:52 -0000	1.1
+++ ShowerPointFinder.java	10 Jul 2008 22:18:43 -0000	1.2
@@ -74,13 +74,13 @@
 
 			if(debug) System.out.println("Given track");
 
+			//new cluster for finding shower point
 			BasicCluster mipclus = new BasicCluster();
 		
 			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();
 		
@@ -95,15 +95,9 @@
 			SortedMap<Double, Cluster> mipsSortedByDistance = new TreeMap();
         	for(Cluster cl : mipsoftrk){
 				CalorimeterHit firstHit =  cl.getCalorimeterHits().get(0);
-	        	IDDecoder id = firstHit.getIDDecoder();
-    	    	id.setID(firstHit.getCellID());
-        		double x = id.getPosition()[0];
-        		double y = id.getPosition()[1];
-        		double z = id.getPosition()[2];
-        		first = new BasicHep3Vector(x, y, z);
-				Hep3Vector displacement = new BasicHep3Vector();
+        		Hep3Vector first = hitPosition(firstHit);
 				if (interceptPoint != null) {
-					displacement = VecOp.sub(first, interceptPoint);
+					Hep3Vector displacement = VecOp.sub(first, interceptPoint);
 					double distance = displacement.magnitude();
 		    		mipsSortedByDistance.put(distance, cl);
         		}
@@ -114,63 +108,44 @@
 			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);
+				Hep3Vector v = hitPosition(hit);
+   	        	double pmag = v.magnitude();
             	sortedMIPbyPos.put(pmag, hit);
 			}
 
-			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());
 
-			long[] lastlayer5x5x2 = new long[26];
-			String lastDet = new String();
-			int sizeofmip = sortedMIPbyPos.size();
+			//String lastDet = new String();
 
 			if(debug) System.out.println("Debug: Starting mip");
 			Iterator itermip = sortedMIPbyPos.entrySet().iterator();
-			for(int i=0 ; i < sizeofmip ;i++){ 
+			for(int i=0 ; i < sortedMIPbyPos.size() ;i++){ 
 				Map.Entry entry = (Map.Entry) itermip.next();
 				Double key = (Double)entry.getKey();
 				CalorimeterHit hit = (CalorimeterHit)entry.getValue();
-				Hep3Vector pos = hitPosition(hit,allHitIDs);
-				miphit.add(pos);
+				examPosition(hit,allHitIDs);
 				mipclus.addHit(hit);
         	}
 			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
-				double p=0;
-				double r=0;
-				int lastlayer = 0;
-				double x=0;
-				double y=0;
-				double z=0;
-				Hep3Vector last0 = new BasicHep3Vector();
-				Hep3Vector last1 = new BasicHep3Vector();
-				
-				for(int s=0; s<2 ; s++){
-					CalorimeterHit hit = mipclus.getCalorimeterHits().get( mipclus.getCalorimeterHits().size()-1-s);
-					IDDecoder id = hit.getIDDecoder();
-					id.setID(hit.getCellID());
-					x = id.getPosition()[0];
-					y = id.getPosition()[1];
-					z = id.getPosition()[2];
-					if(s==0){
-						p = Math.sqrt(x*x+y*y+z*z);			
-						r = Math.sqrt(x*x+y*y);
-		        		lastlayer = id.getLayer();
-						lastDet = hit.getSubdetector().getName();
-						lastlayer5x5x2 = id.getNeighbourIDs(1, 2, 2);
-						last0 = new BasicHep3Vector(x,y,z);
-					} else {last1 = new BasicHep3Vector(x,y,z);}
-				}
+				CalorimeterHit hit = mipclus.getCalorimeterHits().get( mipclus.getCalorimeterHits().size()-1);
+				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);			
+			    double r = Math.sqrt(x*x+y*y);
+				double lastlayer = id.getLayer();
+				//lastDet = hit.getSubdetector().getName();
+				long[] lastlayer5x5x2 = id.getNeighbourIDs(1, 2, 2);
+				Hep3Vector last0 = hitPosition(hit);
+				CalorimeterHit hit1 = mipclus.getCalorimeterHits().get( mipclus.getCalorimeterHits().size()-2);
+				Hep3Vector last1 = hitPosition(hit1);
 
 				
 			    //Searh next hit in next layer and arrange in angular order
@@ -207,24 +182,15 @@
 	
 				}		
 			
-				if(sortedHitbyPos.size() == 0)	continue; 
+				if(sortedHitbyPos.size() == 0)	continue; // add next hit if eligible hit in next layer. 
 				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);
+				examPosition(hitAdd,allHitIDs);
 				mipclus.addHit(hitAdd);
 
 				if (exam > 2) {
 					if(debug) System.out.println("Debug: showering is already started " + exam + " layers ago" );
 					if(mipclus.getCalorimeterHits().size() < 5) break; // if hit size is fewer than 5, don't remove 
 					else for(int k=0; k < 3 ; k++) {
-						miphit.remove(miphit.size()-1);
 						CalorimeterHit toRemove = mipclus.getCalorimeterHits().get(mipclus.getCalorimeterHits().size()-1);
 						mipclus.removeHit(toRemove);
 					}
@@ -238,12 +204,7 @@
 				else k = 4;
 				for(int i =0; i < k ;i++){
 				CalorimeterHit hit = mipclus.getCalorimeterHits().get( mipclus.getCalorimeterHits().size()-1-i);
-				IDDecoder id = hit.getIDDecoder();
-				id.setID(hit.getCellID());
-				double x = id.getPosition()[0];
-				double y = id.getPosition()[1];
-				double z = id.getPosition()[2];
-				Hep3Vector v = new BasicHep3Vector(x,y,z);
+				Hep3Vector v = hitPosition(hit);
 				System.out.println("Debug: last "+i+" pos= "+v.magnitude()+" (" +v.x() + " " + v.y() + " " + v.z()+ ")" );
 				}
 			}		
@@ -259,32 +220,32 @@
 	}
 
 	//give the hit position vector and examine neighbour hits
-	protected Hep3Vector hitPosition(CalorimeterHit hit, Set<Long> allHitIDs){
-           
+	protected void examPosition(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);
+		Hep3Vector v = hitPosition(hit);
 		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 ( 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(" 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;
 	}
 
+	protected Hep3Vector hitPosition(CalorimeterHit hit){
+		IDDecoder id = hit.getIDDecoder();
+		id.setID(hit.getCellID());
+		double x = id.getPosition()[0];
+		double y = id.getPosition()[1];
+		double z = id.getPosition()[2];
+		Hep3Vector v = new BasicHep3Vector(x,y,z);
+		return v;
+	}
 }
CVSspam 0.2.8