Print

Print


Commit in lcsim/src/org/lcsim/recon/cluster/mipfinder on MAIN
ShowerPointFinder.java+273-1931.10 -> 1.11
Restructure to fix jumping over ecal hits

lcsim/src/org/lcsim/recon/cluster/mipfinder
ShowerPointFinder.java 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- ShowerPointFinder.java	8 Mar 2010 19:35:53 -0000	1.10
+++ ShowerPointFinder.java	30 Jun 2010 16:59:36 -0000	1.11
@@ -1,6 +1,6 @@
 package org.lcsim.recon.cluster.mipfinder;
 
-import java.util.*; 
+import java.util.*;
 import org.lcsim.event.*;
 import hep.physics.vec.*;
 
@@ -10,219 +10,299 @@
 import org.lcsim.recon.util.CalorimeterInformation;
 import org.lcsim.geometry.Calorimeter.CalorimeterType;
 
-    public class ShowerPointFinder{
+public class ShowerPointFinder
+{
+
     protected HelixExtrapolator m_extrap;
-    protected Map<Track,Cluster> m_tracksMatchedToClusters;
+    protected Map<Track, Cluster> m_tracksMatchedToClusters;
     protected Set<CalorimeterHit> m_allhits;
     protected int exam = 0; //to test neighbour hits
     protected boolean debug = false;
     protected boolean init;
     protected CalorimeterInformation ci;
+    Set<Long> allHitIDs;
 
-    public ShowerPointFinder(HelixExtrapolator extrap, Set<CalorimeterHit> allHits, Map<Track,Cluster> tracksMatchedToClusters ) {
-		m_extrap = extrap;
-		m_allhits = allHits; 
-		m_tracksMatchedToClusters = tracksMatchedToClusters;
-                init = false;
+    public ShowerPointFinder(HelixExtrapolator extrap, Set<CalorimeterHit> allHits, Map<Track, Cluster> tracksMatchedToClusters)
+    {
+        m_extrap = extrap;
+        m_allhits = allHits;
+        m_tracksMatchedToClusters = tracksMatchedToClusters;
+        init = false;
+        allHitIDs = new HashSet<Long>();
+        for (CalorimeterHit allhit : m_allhits)
+        {
+            allHitIDs.add(allhit.getCellID());
+        }
     }
-	 
-    public Map<Track, BasicCluster> findMips() {
 
-        if(!init)
+    public Map<Track, BasicCluster> findMips()
+    {
+        if (!init)
         {
             ci = CalorimeterInformation.instance();
             init = true;
         }
-	Map<Track, BasicCluster> MapTrkToMIP = new HashMap<Track, BasicCluster>();
-	for(Track tr : m_tracksMatchedToClusters.keySet()){ 
+        Map<Track, BasicCluster> MapTrkToMIP = new HashMap<Track, BasicCluster>();
+        for (Track tr : m_tracksMatchedToClusters.keySet())
+        {
             BasicCluster mipclus = new BasicCluster();  //for new mip cluster   
-	    HelixExtrapolationResult result = m_extrap.performExtrapolation(tr);
-	    Hep3Vector interceptPoint = null; // for debugging
-	    if (result != null) {
-		interceptPoint = result.getInterceptPoint();
-	    }
-	    Cluster seed = m_tracksMatchedToClusters.get(tr);
-
-	    if(debug){
-	    	Hep3Vector v = new BasicHep3Vector(tr.getMomentum());
-		System.out.println("Given track");
-		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() + ")" );
-	    }
-
-	    //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 hits
-            examPosition(seed.getCalorimeterHits().get(0));
-
-	    int lastIterationWithFoundHit = -1;
-	    int maxSkippedLayers = 3;
-	    for( int iIteration = 0 ; iIteration < 70 ; iIteration++){ // 70~layers ECAL+HCAL until finding shower starting point
-		// Get the information from last hit
-		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.getVLayer();
-		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
-		// it'll be a 5x5x3 grid.
-		Set<Long> nearIDs = new HashSet<Long>();
-		int countIterationsSinceLastHit = (iIteration - lastIterationWithFoundHit);
-		if (countIterationsSinceLastHit <= 0) { throw new AssertionError("Book-keeping error"); }
-		if (countIterationsSinceLastHit > maxSkippedLayers+1) { throw new AssertionError("Book-keeping error"); }
-		long[] nearbyHitArray = id.getNeighbourIDs(countIterationsSinceLastHit, 2, 2);
-		for (long lastnearID : nearbyHitArray ) { nearIDs.add(lastnearID); }
-
-		Hep3Vector last0 = hitPosition(hit);
-		Hep3Vector last1 = new BasicHep3Vector();
-		if( mipclus.getCalorimeterHits().size() > 1){
-		    CalorimeterHit hit1 = mipclus.getCalorimeterHits().get( mipclus.getCalorimeterHits().size()-2);
-	            last1 = hitPosition(hit1);
-		}
-
-		//Search current hit in current layer and arrange in angular order
-		SortedMap<Double, CalorimeterHit> sortedHitbyPosInside   = new TreeMap();
-		SortedMap<Double, CalorimeterHit> sortedHitbyPosCrossing = new TreeMap();
-		SortedMap<Double, CalorimeterHit> sortedHitbyPos= new TreeMap();
-		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.getVLayer();
-		    String cursubdetName = curhit.getSubdetector().getName();
-                    //use geometric information and layer number to find cur hit
-                    // Inside Sub detector -> 0)
-                    // ECal Barrel -> 1) HCal Barrel or 2) HCal Endcap
-                    // ECal Endcap -> 3) HCal Endcap or 4) Ecal Barrel
-                    // HCal Endcap -> 5) HCal Barrel
-		    boolean InSide = (curlayer > lastlayer) && cursubdetName.contains(lastsubdetName) && nearIDs.contains(curhit.getCellID()); // 0)
-                    boolean EcalToHcalBarrel= (curid.getVLayer()==0 && cursubdetName.contains(ci.getName(CalorimeterType.HAD_BARREL))) && lastsubdetName.contains(ci.getName(CalorimeterType.EM_BARREL)); // 1) ECal Barrel -> HCal Barrel
-                    boolean BarrelEcalToEndHcal = (curid.getVLayer()==0 && cursubdetName.contains(ci.getName(CalorimeterType.HAD_ENDCAP))) && lastsubdetName.contains(ci.getName(CalorimeterType.EM_BARREL)); //2) ECal Barrel -> HCal Endcap (There is no way to HCal Barrel directly from ECal Endcap
-                    boolean EcalToHcalEndcap= (curid.getVLayer()==0 && cursubdetName.contains(ci.getName(CalorimeterType.HAD_ENDCAP))) && lastsubdetName.contains(ci.getName(CalorimeterType.EM_ENDCAP)); // 3) ECal Endcap -> HCal Endcap
-		    boolean EndToBarrelEcal = (curid.getVLayer()==0 && cursubdetName.contains(ci.getName(CalorimeterType.EM_BARREL))) && lastsubdetName.contains(ci.getName(CalorimeterType.EM_ENDCAP)); // 4) ECal Endcap -> ECal Barrel
-                    boolean EndToBarrelHcal = (curid.getVLayer()==0 && cursubdetName.contains(ci.getName(CalorimeterType.HAD_BARREL))) && lastsubdetName.contains(ci.getName(CalorimeterType.HAD_ENDCAP)); // 5) HCal Endcap -> HCal Barrel
-
-		    if(InSide || EcalToHcalBarrel || BarrelEcalToEndHcal || EcalToHcalEndcap || EndToBarrelEcal || EndToBarrelHcal){
-			Hep3Vector cur = VecOp.sub(curpos, last0);
-			Hep3Vector curUnit = VecOp.unit(cur);
-			Hep3Vector last = null;
-			if (mipclus.getCalorimeterHits().size() > 1) { 
-			    last = VecOp.sub(last0, last1);
-			} else {
-			    //Since there is only one hit we have at first, we use a extrapolated tangent vector 	
-			    if (result != null) {
-				last = result.getTangent();
-			    }
-			    if (last == null) {
-				// No extrapolation info and only one hit -- fall back to using
-				// a straight line from the origin.
-				last = VecOp.sub(last0, new BasicHep3Vector(0,0,0));
-			    }
-			}
-			Hep3Vector lastUnit = VecOp.unit(last);
-			double a = Math.acos(VecOp.dot(lastUnit, curUnit));
-			double d = VecOp.sub(cur,last).magnitude();
-			if(a < 1.05 && d < 100){ //next hit in the range of angle 60 degree and less than 100mm
-                           if (InSide){
-				sortedHitbyPosInside.put(a, curhit);
-			    }else{
-				sortedHitbyPosCrossing.put(a, curhit);
-			    }
-			}
-		    }		
-
-		}		
-		if (sortedHitbyPosInside.size() ==0 ) 
-		    sortedHitbyPos = sortedHitbyPosCrossing;
-		else
-		    sortedHitbyPos = sortedHitbyPosInside;
-		
-		if(sortedHitbyPos.size() == 0) {
-		    // No hit found in this layer.
-		    if (countIterationsSinceLastHit <= maxSkippedLayers) {
-			continue; // go to next layer 
-		    } else {
-			break; // stop -- ran out of hits and haven't seen any for several iterations
-		    }
-		} else {
-		    // Found one or more hits
-		    lastIterationWithFoundHit = iIteration;
-		}
-		CalorimeterHit hitAdd = sortedHitbyPos.get(sortedHitbyPos.firstKey()); //add the hit with a smallest angle 
-		examPosition(hitAdd);
-		mipclus.addHit(hitAdd);
-
-		if (exam > 2) {
-		    if(debug) System.out.println("Debug: showering has already started " + exam + " layers ago" );
-                    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);
-		    }
-		    break;
-		}
-	    } //layer loop after mip
-
-	    if(debug){
-		int k=0;
-		if(mipclus.getCalorimeterHits().size() < 4) k = mipclus.getCalorimeterHits().size();
-		else k = 4;
-		for(int i =0; i < k ;i++){
-		    CalorimeterHit hit = mipclus.getCalorimeterHits().get( mipclus.getCalorimeterHits().size()-1-i);
-		    Hep3Vector v = hitPosition(hit);
-		    System.out.println("Debug: last "+i+" pos= "+v.magnitude()+" (" +v.x() + " " + v.y() + " " + v.z()+ ")" );
-		}
-		System.out.println("MIP hit size= " + mipclus.getCalorimeterHits().size());
-	    }		
-	    MapTrkToMIP.put(tr, mipclus);
-	} //track loop
+            HelixExtrapolationResult result = m_extrap.performExtrapolation(tr);
+            Cluster seed = m_tracksMatchedToClusters.get(tr);
+
+            // first hit of seed 
+            mipclus.addHit(seed.getCalorimeterHits().get(0));
+            CalorimeterType lcalt = null;
+            boolean foundip = false;
+            boolean biggap = false;
+            // Start with the calorimeter of the seed. Follow as far as possible, then
+            // Look for transition to another calorimeter. Could possibly travel through
+            // all 4 calorimeters.
+            for (int ical = 0; ical < 4; ical++)
+            {
+                if(foundip)break;
+                //test the seed for neighbour hits
+                examPosition(mipclus.getCalorimeterHits().get(mipclus.getCalorimeterHits().size() - 1));
+
+                int lastIterationWithFoundHit = -1;
+                int maxSkippedLayers = 3;
+                CalorimeterType calt = ((Calorimeter) mipclus.getCalorimeterHits().get(mipclus.getCalorimeterHits().size() - 1).getSubdetector()).getCalorimeterType();
+                // If we finished a calorimeter and found no transition to another, 
+                // we're done.
+                if (calt == lcalt)break;
+                lcalt = calt;
+                double cellsize = 3.5;
+                if((calt == CalorimeterType.HAD_BARREL)||(calt == CalorimeterType.HAD_ENDCAP))cellsize = 10.;
+                // First find all passing hits in initial subdetector
+                for (int iIteration = 0; iIteration < ci.getNLayers(calt); iIteration++)
+                {
+                    // Get the information from last hit
+                    CalorimeterHit hit = mipclus.getCalorimeterHits().get(mipclus.getCalorimeterHits().size() - 1);
+                    IDDecoder id = hit.getIDDecoder();
+                    id.setID(hit.getCellID());
+                    double lastlayer = id.getVLayer();
+                    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
+                    // it'll be a 5x5x3 grid.
+                    Set<Long> nearIDs = new HashSet<Long>();
+                    int countIterationsSinceLastHit = (iIteration - lastIterationWithFoundHit);
+                    if (countIterationsSinceLastHit <= 0)throw new AssertionError("Book-keeping error");
+                    if (countIterationsSinceLastHit > maxSkippedLayers + 1)throw new AssertionError("Book-keeping error");
+                    long[] nearbyHitArray = id.getNeighbourIDs(countIterationsSinceLastHit, 2, 2);
+                    for (long lastnearID : nearbyHitArray)
+                    {
+                        nearIDs.add(lastnearID);
+                    }
+
+                    Hep3Vector last0 = hitPosition(hit);
+                    Hep3Vector last1 = null;
+                    if (mipclus.getCalorimeterHits().size() > maxSkippedLayers)
+                    {
+                        CalorimeterHit hit1 = mipclus.getCalorimeterHits().get(mipclus.getCalorimeterHits().size() - maxSkippedLayers - 1);
+                        last1 = hitPosition(hit1);
+                    }
+
+                    // Initialize Map sorted by angle.
+                    SortedMap<Double, CalorimeterHit> sortedHitbyPosInside = new TreeMap();
+                    SortedMap<Double, CalorimeterHit> sortedHitbyPos = new TreeMap();
+                    // Loop over all the hits. Should probably divide hits into subdetectors, since 
+                    // we're only looking at 1 at a time here.
+                    for (CalorimeterHit curhit : m_allhits)
+                    {
+                        // Skip hits not in the subdetector of interest.
+                        if (!curhit.getSubdetector().getName().contains(lastsubdetName))continue;
+                        IDDecoder curid = curhit.getIDDecoder();
+                        curid.setID(curhit.getCellID());
+                        Hep3Vector curpos = new BasicHep3Vector(curid.getPosition());
+                        double curlayer = curid.getVLayer();
+                        // Only consder hits with increasing radius that are neighbors
+                        if ((curlayer > lastlayer) && (nearIDs.contains(curhit.getCellID())))
+                        {
+                            Hep3Vector cur = VecOp.sub(curpos, last0);
+                            Hep3Vector curUnit = VecOp.unit(cur);
+                            Hep3Vector last = null;
+                            if (last1 != null)
+                            {
+                                last = VecOp.sub(last0, last1);
+                            }
+                            else
+                            {
+                                //Since there is only one hit we have at first, we use a extrapolated tangent vector 	
+                                if (result != null)
+                                {
+                                    last = result.getTangent();
+                                }
+                                if (last == null)
+                                {
+                                    // No extrapolation info and only one hit -- fall back to using
+                                    // a straight line from the origin.
+                                    last = VecOp.sub(last0, new BasicHep3Vector(0, 0, 0));
+                                }
+                            }
+                            Hep3Vector lastUnit = VecOp.unit(last);
+                            double ct = VecOp.dot(lastUnit, curUnit);
+                            double st = Math.sqrt(1. - ct*ct);
+                            double d = cur.magnitude()*st;
+                            if (ct > 0.5 && d < 3.*cellsize)
+                            {
+                                sortedHitbyPosInside.put(1. - ct, curhit);
+                            }
+                        }
+
+                    }
+                    sortedHitbyPos = sortedHitbyPosInside;
+
+                    if (sortedHitbyPos.size() == 0)
+                    {
+                        // No hit found in this layer.
+                        if (countIterationsSinceLastHit <= maxSkippedLayers)
+                        {
+                            continue; // go to next layer 
+                        }
+                        else
+                        {
+                            biggap = true;
+                            break;
+                        } // stop -- ran out of hits and haven't seen any for several iterations
+                    }
+                    else
+                    {
+                        // Found one or more hits
+                        lastIterationWithFoundHit = iIteration;
+                    }
+                    CalorimeterHit hitAdd = sortedHitbyPos.get(sortedHitbyPos.firstKey()); //add the hit with a smallest angle 
+                    examPosition(hitAdd);
+                    mipclus.addHit(hitAdd);
+
+                    if (exam > 2)
+                    {
+                        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);
+                        }
+                        foundip = true;
+                        break;
+                    }
+                } //layer loop after mip
+                //Went as far as we could in 1 calorimeter, now check for crossovers
+                if(foundip)break;
+                CalorimeterHit hit = mipclus.getCalorimeterHits().get(mipclus.getCalorimeterHits().size() - 1);
+                String lastsubdetName = hit.getSubdetector().getName();
+                Hep3Vector last0 = hitPosition(hit);
+                Hep3Vector last1 = null;
+                if (mipclus.getCalorimeterHits().size() > maxSkippedLayers)
+                {
+                    CalorimeterHit hit1 = mipclus.getCalorimeterHits().get(mipclus.getCalorimeterHits().size() - maxSkippedLayers - 1);
+                    last1 = hitPosition(hit1);
+                }
+                SortedMap<Double, CalorimeterHit> sortedHitbyPosCrossing = new TreeMap();
+                for (CalorimeterHit curhit : m_allhits)
+                {
+                    if (curhit.getSubdetector().getName().contains(lastsubdetName))
+                    {
+                        continue;
+                    }
+                    IDDecoder curid = curhit.getIDDecoder();
+                    curid.setID(curhit.getCellID());
+                    Hep3Vector curpos = new BasicHep3Vector(curid.getPosition());
+                    String cursubdetName = curhit.getSubdetector().getName();
+                    boolean EcalToHcalBarrel = (curid.getVLayer() == 0 && cursubdetName.contains(ci.getName(CalorimeterType.HAD_BARREL))) && lastsubdetName.contains(ci.getName(CalorimeterType.EM_BARREL)); // 1) ECal Barrel -> HCal Barrel
+                    boolean BarrelEcalToEndHcal = (curid.getVLayer() == 0 && cursubdetName.contains(ci.getName(CalorimeterType.HAD_ENDCAP))) && lastsubdetName.contains(ci.getName(CalorimeterType.EM_BARREL)); //2) ECal Barrel -> HCal Endcap (There is no way to HCal Barrel directly from ECal Endcap
+                    boolean EcalToHcalEndcap = (curid.getVLayer() == 0 && cursubdetName.contains(ci.getName(CalorimeterType.HAD_ENDCAP))) && lastsubdetName.contains(ci.getName(CalorimeterType.EM_ENDCAP)); // 3) ECal Endcap -> HCal Endcap
+                    boolean EndToBarrelEcal = (curid.getVLayer() == 0 && cursubdetName.contains(ci.getName(CalorimeterType.EM_BARREL))) && lastsubdetName.contains(ci.getName(CalorimeterType.EM_ENDCAP)); // 4) ECal Endcap -> ECal Barrel
+                    boolean EndToBarrelHcal = (curid.getVLayer() == 0 && cursubdetName.contains(ci.getName(CalorimeterType.HAD_BARREL))) && lastsubdetName.contains(ci.getName(CalorimeterType.HAD_ENDCAP)); // 5) HCal Endcap -> HCal Barrel
+
+                    if (EcalToHcalBarrel || BarrelEcalToEndHcal || EcalToHcalEndcap || EndToBarrelEcal || EndToBarrelHcal)
+                    {
+                        if( (biggap)&& (EcalToHcalBarrel||EcalToHcalEndcap))continue;
+                        calt = ((Calorimeter) curhit.getSubdetector()).getCalorimeterType();
+                        cellsize = 3.5;
+                        if((calt == CalorimeterType.HAD_BARREL)||(calt == CalorimeterType.HAD_ENDCAP))cellsize = 10.;
+                        Hep3Vector cur = VecOp.sub(curpos, last0);
+                        Hep3Vector curUnit = VecOp.unit(cur);
+                        Hep3Vector last = null;
+                        if (last1 != null)
+                        {
+                            last = VecOp.sub(last0, last1);
+                        } else
+                        {
+                            //Since there is only one hit we have at first, we use a extrapolated tangent vector
+                            if (result != null)
+                            {
+                                last = result.getTangent();
+                            }
+                            if (last == null)
+                            {
+                                // No extrapolation info and only one hit -- fall back to using
+                                // a straight line from the origin.
+                                last = VecOp.sub(last0, new BasicHep3Vector(0, 0, 0));
+                            }
+                        }
+                        Hep3Vector lastUnit = VecOp.unit(last);
+                        double ct = VecOp.dot(lastUnit, curUnit);
+                        double st = Math.sqrt(1. - ct*ct);
+                        double d = cur.magnitude()*st;
+                        if (ct > 0.5 && d < 3.*cellsize && cur.magnitude() < 100.)
+                        {
+                            sortedHitbyPosCrossing.put(1. - ct, curhit);
+                        }
+                    }
+                }
+                if (sortedHitbyPosCrossing.size() > 0)
+                {
+                    CalorimeterHit hitAdd = sortedHitbyPosCrossing.get(sortedHitbyPosCrossing.firstKey()); //add the hit with a smallest angle
+                    examPosition(hitAdd);
+                    mipclus.addHit(hitAdd);
+                }
+            }
+
+            MapTrkToMIP.put(tr, mipclus);
+        } //track loop
 
-	return MapTrkToMIP;
+        return MapTrkToMIP;
     }
 
     //examine neighbour hits
-    protected void examPosition(CalorimeterHit hit){
-	Set<Long> allHitIDs = new HashSet<Long>();
-	for (CalorimeterHit allhit : m_allhits)  allHitIDs.add(allhit.getCellID());
-
-	IDDecoder id = hit.getIDDecoder();
-	id.setID(hit.getCellID());
-	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[2] >=1 ) exam++ ; // if number of neighbour hits in 5x5 is larger than 1, count 1 
-	else exam = 0; // if number of neighbour hits is 0, set to zero and start again from 0 
-
-	if(debug){
-	    Hep3Vector v = hitPosition(hit);
-	    int p = (int) (v.magnitude());
-	    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 " + id.getLayer() + " layer of " + hit.getSubdetector().getName());
-	}
+    protected void examPosition(CalorimeterHit hit)
+    {
+
+        IDDecoder id = hit.getIDDecoder();
+        id.setID(hit.getCellID());
+        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[2] >= 1)
+        {
+            exam++; // if number of neighbour hits in 5x5 is larger than 1, count 1 
+        } else
+        {
+            exam = 0; // if number of neighbour hits is 0, set to zero and start again from 0 
+        }
     }
 
     //give the vector of hit
-    protected Hep3Vector hitPosition(CalorimeterHit hit){
+    protected Hep3Vector hitPosition(CalorimeterHit hit)
+    {
         return new BasicHep3Vector(hit.getPosition());
     }
 }
CVSspam 0.2.8