Print

Print


Commit in lcsim/src/org/lcsim/recon/cluster/mipfinder on MAIN
ShowerPointFinder.java+33-741.2 -> 1.3
MJC: Port mipfinder changes to stable

lcsim/src/org/lcsim/recon/cluster/mipfinder
ShowerPointFinder.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- ShowerPointFinder.java	15 Jul 2008 23:54:04 -0000	1.2
+++ ShowerPointFinder.java	19 Aug 2008 14:57:36 -0000	1.3
@@ -28,91 +28,41 @@
 import org.lcsim.util.decision.*;
 
     public class ShowerPointFinder{
-    protected LocalHelixExtrapolator m_findCluster;
-    protected Map<Track, Set<Cluster>> m_newMapTrackToShowerComponents;
-    protected List<Cluster> m_mips;
+    protected LocalHelixExtrapolator m_extrap;
+    protected Map<Track,Cluster> m_tracksMatchedToClusters;
     protected Set<CalorimeterHit> m_allhits;
     protected int exam = 0; //to test neighbour
     protected boolean debug = false;
 
-    public ShowerPointFinder(LocalHelixExtrapolator findCluster, Map<Track, Set<Cluster>> newMapTrackToShowerComponents, List<Cluster> mips, Set<CalorimeterHit> allHits) {
-		m_findCluster = findCluster;
-		m_newMapTrackToShowerComponents = newMapTrackToShowerComponents;
-		m_mips = mips;
+    public ShowerPointFinder(LocalHelixExtrapolator extrap, Set<CalorimeterHit> allHits, Map<Track,Cluster> tracksMatchedToClusters ) {
+		m_extrap = extrap;
 		m_allhits = allHits; 
+		m_tracksMatchedToClusters = tracksMatchedToClusters;
     }
-
 	 
-    public Map<Track, BasicCluster> findMips(List<Track> tracksSortedByMomentum) {
+    public Map<Track, BasicCluster> findMips() {
+        
 	Map<Track, BasicCluster> MapTrkToMIP = new HashMap<Track, BasicCluster>();
-	for(Track tr : tracksSortedByMomentum){ 
-	    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);
-		}
-	    }
+	for(Track tr : m_tracksMatchedToClusters.keySet()){ 
+            BasicCluster mipclus = new BasicCluster();  //for new mip cluster   
+	    Hep3Vector interceptPoint = m_extrap.performExtrapolation(tr); //for debuging
+	    Cluster seed = m_tracksMatchedToClusters.get(tr);
 
-            BasicCluster mipclus = new BasicCluster();     
-	    if(mipsoftrk.size() == 0) {//No any mip found
-		MapTrkToMIP.put(tr,mipclus);
-		continue; //go to next track
-	    }
-	    
-	    //new cluster for finding shower point
-	    Hep3Vector interceptPoint = m_findCluster.performExtrapolation(tr); //not need except debuging
-	    //Hep3Vector tangent =  m_findCluster.getTangent();
-	    //Hep3Vector tangentUnit = VecOp.unit(tangent);
-				
 	    if(debug){
 	    	Hep3Vector v = new BasicHep3Vector(tr.getMomentum());
 		System.out.println("Given track");
-		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= " + v.magnitude());
 		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);
-		Hep3Vector first = hitPosition(firstHit);
-		double distance = first.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);
-		Hep3Vector v = hitPosition(hit);
-		double pmag = v.magnitude();
-            	sortedMIPbyPos.put(pmag, hit);
-	    }
+	    //It might be needed to use intecept point instead of using first hit of seed
+	    //so that we can find the exact first hit corresponding to track
+         
+	    // first hit of seed 
+	    mipclus.addHit(seed.getCalorimeterHits().get(0));
+	    //test for neighbour
+            examPosition(seed.getCalorimeterHits().get(0));
 
-	    //test if the mip is enough closet to track otherwise take it as no mip.
-	    CalorimeterHit firstmip = sortedMIPbyPos.get(sortedMIPbyPos.firstKey());
-	    IDDecoder firstmipid = firstmip.getIDDecoder();
-	    firstmipid.setID(firstmip.getCellID());
-	    if(firstmipid.getLayer() > 3) { // if the mip is not in first 3 layers, put 0 in mipclus
-		MapTrkToMIP.put(tr,mipclus);
-		continue; //go to next track
-	    }
-	
-	    if(debug) System.out.println("Debug: Starting mip");
-	    Iterator itermip = sortedMIPbyPos.entrySet().iterator();
-	    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();
-		examPosition(hit);
-		mipclus.addHit(hit);
-	    }
-	    if(debug) System.out.println("Debug: The end of the mip" );
-	
 	    int lastIterationWithFoundHit = -1;
 	    int maxSkippedLayers = 3;
 	    for( int iIteration = 0 ; iIteration < 70 ; iIteration++){ // 70? until finding shower starting point
@@ -139,8 +89,11 @@
 		for (long lastnearID : nearbyHitArray ) { nearIDs.add(lastnearID); }
 
 		Hep3Vector last0 = hitPosition(hit);
-		CalorimeterHit hit1 = mipclus.getCalorimeterHits().get( mipclus.getCalorimeterHits().size()-2);
-		Hep3Vector last1 = hitPosition(hit1);
+		Hep3Vector last1 = new BasicHep3Vector();
+		if( mipclus.getCalorimeterHits().size() > 1){
+		    CalorimeterHit hit1 = mipclus.getCalorimeterHits().get( mipclus.getCalorimeterHits().size()-2);
+	            last1 = hitPosition(hit1);
+		}
 
 		//Searh cur hit in cur layer and arrange in angular order
 		SortedMap<Double, CalorimeterHit> sortedHitbyPos= new TreeMap();
@@ -168,10 +121,13 @@
 			Hep3Vector cur = VecOp.sub(curpos, last0);
 			Hep3Vector curUnit = VecOp.unit(cur);
 			Hep3Vector last = VecOp.sub(last0, last1);
+		        //Since there is only one hit we have at the first, we use a extrapolrated tangent vector 	
+			if(  mipclus.getCalorimeterHits().size() > 1) { last = VecOp.sub(last0, last1);}
+			else { last = m_extrap.getTangent();}
 			Hep3Vector lastUnit = VecOp.unit(last);
 			double a = Math.acos(VecOp.dot(lastUnit, curUnit));
 			double d = VecOp.sub(cur,last).magnitude();
-			if(a < 1.57 && d < 100){ //next hit in the range of angle 90 degree and less than 100mm(?)
+			if(a < 1.05 && d < 100){ //next hit in the range of angle 90 degree and less than 100mm(?)
 			    sortedHitbyPos.put(a, curhit);
 			}
 		    }		
@@ -195,8 +151,11 @@
 
 		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++) {
+                    double numRemove = 0;
+		    if(mipclus.getCalorimeterHits().size() < 4) {
+                        numRemove = mipclus.getCalorimeterHits().size() - 1 ; 
+                    } else numRemove = 3;
+		    for(int k=0; k < numRemove ; k++) {
 			CalorimeterHit toRemove = mipclus.getCalorimeterHits().get(mipclus.getCalorimeterHits().size()-1);
 			mipclus.removeHit(toRemove);
 		    }
@@ -234,7 +193,7 @@
 	    for(long neighbourID : neighbours)
 		if (allHitIDs.contains(neighbourID)) count[i]++;
 	}
-	if ( count[1] >=2 ) exam++ ; // if number of neighbour hits in 5x5 is larger than 1, count 1 
+	if ( count[2] >=1 ) exam++ ; // if number of neighbour hits in 5x5 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){
CVSspam 0.2.8