Commit in lcsim/src/org/lcsim/recon/cluster/mipfinder on MAIN
ShowerPointFinder.java+33-441.1 -> 1.2
fix bug in MapTrkToMIP

lcsim/src/org/lcsim/recon/cluster/mipfinder
ShowerPointFinder.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- ShowerPointFinder.java	13 Jul 2008 23:31:31 -0000	1.1
+++ ShowerPointFinder.java	15 Jul 2008 23:54:04 -0000	1.2
@@ -35,16 +35,6 @@
     protected int exam = 0; //to test neighbour
     protected boolean debug = false;
 
-    //sid01
-    protected double ecalRs=1270; //ECAL inner R
-    protected double ecalRe=1410; //ECAL outer R
-    protected double hcalRs=1410; //HCAL inner R
-    protected double hcalRe=2362; //HCAL outer R
-    protected double ecalZs=1680; //ECAL inner Z
-    protected double ecalZe=1820; //ECAL outer Z
-    protected double hcalZs=1820; //HCAL inner Z
-    protected double hcalZe=2772; //HCAL inner Z 
-
     public ShowerPointFinder(LocalHelixExtrapolator findCluster, Map<Track, Set<Cluster>> newMapTrackToShowerComponents, List<Cluster> mips, Set<CalorimeterHit> allHits) {
 		m_findCluster = findCluster;
 		m_newMapTrackToShowerComponents = newMapTrackToShowerComponents;
@@ -55,7 +45,6 @@
 	 
     public Map<Track, BasicCluster> findMips(List<Track> tracksSortedByMomentum) {
 	Map<Track, BasicCluster> MapTrkToMIP = new HashMap<Track, BasicCluster>();
-	BasicCluster mipclus = new BasicCluster();
 	for(Track tr : tracksSortedByMomentum){ 
 	    Set<Cluster> clusoftrk = m_newMapTrackToShowerComponents.get(tr);
 	    Set<Cluster> mipsoftrk = new HashSet<Cluster>();
@@ -64,7 +53,8 @@
 		    mipsoftrk.add(cl);
 		}
 	    }
-	
+
+            BasicCluster mipclus = new BasicCluster();     
 	    if(mipsoftrk.size() == 0) {//No any mip found
 		MapTrkToMIP.put(tr,mipclus);
 		continue; //go to next track
@@ -136,7 +126,7 @@
 		double p = Math.sqrt(x*x+y*y+z*z);			
 		double r = Math.sqrt(x*x+y*y);
 		double lastlayer = id.getLayer();
-
+		String lastsubdetName = hit.getSubdetector().getName();
 		// Check for neighbouring hits in a 5x5x(2n+1) grid
 		// where n is the number of iterations since we last saw a hit.
 		// For example, if we saw a hit in the previous layer/iteration
@@ -152,38 +142,38 @@
 		CalorimeterHit hit1 = mipclus.getCalorimeterHits().get( mipclus.getCalorimeterHits().size()-2);
 		Hep3Vector last1 = hitPosition(hit1);
 
-		//Searh next hit in next layer and arrange in angular order
+		//Searh cur hit in cur 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);
-		    Hep3Vector hitpos = new BasicHep3Vector(xall,yall,zall);
-		    int hitLayer = idall.getLayer();
-		    //use geometric information and layer number to find next hit
-		    boolean EcalToHcal= lastlayer == 30 && hitmag > p && idall.getLayer() == 0;
-		    boolean InSide = (hitmag > p || hitLayer > lastlayer) && nearIDs.contains(hitall.getCellID());
-		    boolean nearInnerEdgeBarrelEcal = (r < ecalRs && r > ecalRs-4);
-		    boolean nearOuterEdgeEndcapEcal = (Math.abs(z) < ecalZe && Math.abs(z) > ecalZs);
-		    boolean nearInnerEdgeBarrelHcal = (r < hcalRs && r > hcalRs-4);
-		    boolean nearOuterEdgeEndcapHcal = (Math.abs(z) < hcalZe && Math.abs(z) > hcalZs);		    
-		    boolean EndToBarrelEcal = nearInnerEdgeBarrelEcal && nearOuterEdgeEndcapEcal && (hitmag > p) && (idall.getLayer()==0);
-		    boolean EndToBarrelHcal = nearInnerEdgeBarrelHcal && nearOuterEdgeEndcapHcal && (hitmag > p) && (idall.getLayer()==0);
-
+		for (CalorimeterHit curhit : m_allhits){
+		    IDDecoder curid = curhit.getIDDecoder();
+		    curid.setID(curhit.getCellID());
+		    double curx = curid.getPosition()[0];
+		    double cury = curid.getPosition()[1];
+		    double curz = curid.getPosition()[2];
+		    double curp = Math.sqrt(curx*curx+cury*cury+curz*curz);
+		    double curr = Math.sqrt(curx*curx+cury*cury);  
+		    Hep3Vector curpos = new BasicHep3Vector(curx,cury,curz);
+		    double curlayer = curid.getLayer();
+		    String cursubdetName = curhit.getSubdetector().getName();
+		    //use geometric information and layer number to find cur hit
+		    boolean EcalToHcal= lastlayer == 30 && curp > p && curid.getLayer() == 0;
+		    boolean InSide = (curp > p || curlayer > lastlayer) && nearIDs.contains(curhit.getCellID());
+		    boolean EndToBarrelEcal = (curid.getLayer()==0 && cursubdetName == "EMBarrel") && lastsubdetName=="EMEndcap";
+                    boolean EndToBarrelHcal = (curid.getLayer()==0 && cursubdetName == "HADBarrel") && lastsubdetName=="HADEndcap";
 		    if(debug){
-			if(EndToBarrelEcal || EndToBarrelHcal ) System.out.println("This is a boundary condition");
+			if(EndToBarrelEcal || EndToBarrelHcal) System.out.println("This is a boundary condition");
 		    }				
 
-		    if(EcalToHcal || InSide || EndToBarrelEcal || EndToBarrelHcal){
-			Hep3Vector test = VecOp.sub(hitpos, last0);
-			Hep3Vector test_unit = VecOp.unit(test);
-			Hep3Vector lastmip = VecOp.sub(last0, last1);
-			Hep3Vector lastmip_unit = VecOp.unit(lastmip);
-			double a = Math.acos(VecOp.dot(lastmip_unit, test_unit));
-			sortedHitbyPos.put(a, hitall);
+		    if(EcalToHcal || InSide || EndToBarrelEcal || EndToBarrelHcal ){
+			Hep3Vector cur = VecOp.sub(curpos, last0);
+			Hep3Vector curUnit = VecOp.unit(cur);
+			Hep3Vector last = VecOp.sub(last0, last1);
+			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(?)
+			    sortedHitbyPos.put(a, curhit);
+			}
 		    }		
 
 		}		
@@ -225,8 +215,7 @@
 		}
 		System.out.println("MIP hit size= " + mipclus.getCalorimeterHits().size());
 	    }		
-
-	    MapTrkToMIP.put(tr,mipclus); 
+	    MapTrkToMIP.put(tr, mipclus);
 	} //track loop
 
 	return MapTrkToMIP;
@@ -245,7 +234,7 @@
 	    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 
+	if ( count[1] >=2 ) 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