Print

Print


Commit in lcsim/src/org/lcsim/recon/tracking/seedtracker on MAIN
SeedSectoring.java+44added 1.1
ConfirmerExtender.java+69-431.5 -> 1.6
FastCheck.java+27-161.2 -> 1.3
HitManager.java+20-2001.2 -> 1.3
Sector.java+122-231.1 -> 1.2
SectorManager.java+117-121.1 -> 1.2
SeedLayer.java+51.1 -> 1.2
SeedTrackFinder.java+76-541.5 -> 1.6
SeedTracker.java+1-21.4 -> 1.5
+481-350
1 added + 8 modified, total 9 files
Updated sectoring code

lcsim/src/org/lcsim/recon/tracking/seedtracker
SeedSectoring.java added at 1.1
diff -N SeedSectoring.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ SeedSectoring.java	20 Jan 2009 19:19:53 -0000	1.1
@@ -0,0 +1,44 @@
+package org.lcsim.recon.tracking.seedtracker;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author Richard Partridge
+ */
+public class SeedSectoring {
+
+    private List<List<Sector>> _seedsectors;
+
+    public SeedSectoring(HitManager hmanager, SeedStrategy strategy,
+            double bfield, List<SeedLayer> layers) {
+
+        _seedsectors = new ArrayList<List<Sector>>();
+
+        FastCheck checker = new FastCheck(strategy, bfield);
+
+        List<Sector> slist0 = hmanager.getSectors(layers.get(0));
+        List<Sector> slist1 = hmanager.getSectors(layers.get(1));
+        List<Sector> slist2 = hmanager.getSectors(layers.get(2));
+
+        for (Sector s0 : slist0) {
+            for (Sector s1 : slist1) {
+                if (!checker.CheckSectorPair(s0, s1)) continue;
+                for (Sector s2 : slist2) {
+                    if (!checker.CheckSectorPair(s0, s2)) continue;
+                    if (!checker.CheckSectorPair(s1, s2)) continue;
+                    List<Sector> slist = new ArrayList<Sector>();
+                    slist.add(s0);
+                    slist.add(s1);
+                    slist.add(s2);
+                    _seedsectors.add(slist);
+                }
+            }
+        }
+    }
+
+    public List<List<Sector>> SeedSectors() {
+        return _seedsectors;
+    }
+}
\ No newline at end of file

lcsim/src/org/lcsim/recon/tracking/seedtracker
ConfirmerExtender.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- ConfirmerExtender.java	18 Jan 2009 00:21:22 -0000	1.5
+++ ConfirmerExtender.java	20 Jan 2009 19:19:52 -0000	1.6
@@ -91,43 +91,63 @@
         //  For the first confirm/extend layer, the input seed is the seed we are trying to check out
         seedlist.add(seed);
 
+        //  Initialize the number of layers left to search
+        int nleft = lyrs.size();
+
+        //  Calculate the minimum number of hits to suceed
+        int minhits = strategy.getMinHits();
+        if (task == Task.CONFIRM) minhits = strategy.getMinConfirm() + 3;
+
         //  Loop over the confirmation/extension layers
         for (SeedLayer lyr : lyrs) {
+//            System.out.println("New Layer: "+lyr.LayerID());
 
             //  Create a list for seeds that are confirmed/extended using the current layer
             List<SeedCandidate> newlist = new ArrayList<SeedCandidate>();
 
-            //  Get the list of sectors with hits and loop over sectors
-            List<Sector> sectorlist = hmanager.getSectorList(lyr);
-            for (Sector sector : sectorlist) {
+            //  Get the list of sectors associated with this layer
+            List<Sector> sectorlist = hmanager.getSectors(lyr);
+
+            //  Loop over the input seeds for this layer search
+            for (SeedCandidate seedin : seedlist) {
+
+                //  Check if this seed is viable
+                if (seedin.getHits().size() + nleft < minhits) continue;
+
+                //  Retrieve the chisq for the last fit and initialize the best fit chisq for this layer
+                double oldchisq = seedin.getHelix().chisqtot();
+                double oldcirclechisq = seedin.getHelix().chisq()[0];
+                double chisqbest = 1.e6;
 
-                //  Loop over the input seeds for this layer search
-                for (SeedCandidate seedin : seedlist) {
+                //  Use the first seed hit for the fast check of additional hits
+                HelicalTrackHit checkhit = seedin.getHits().get(0);
+
+//                System.out.println("Trial seed with "+seedin.getHits().size()+" hits");
+
+                //  Loop over the sectors with hits
+                SectorLoop:
+                for (Sector sector : sectorlist) {
 
                     //  Check that this candidate is compatible with the sector
-                    if (!checker.CheckSector(hmanager, seedin, lyr, sector)) continue;
+                    if (!checker.CheckSector(seedin, sector)) continue;
+
+//                    System.out.println("Found a sector to check: "+
+//                            sector.Identifier()+" with "+sector.Hits().size()+" hits");
 
-                    //  Get the hits on this confirmation/extension layer
-                    List<HelicalTrackHit> hitlist = hmanager.getTrackerHits(lyr, sector);
+                    //  Get the hits for this confirmation/extension sector
+                    List<HelicalTrackHit> hitlist = sector.Hits();
 
                     SortHits comp = new SortHits(seedin.getHelix());
                     Collections.sort(hitlist, comp);
 
-                    //  Retrieve the chisq for the last fit and initialize the best fit chisq for this layer
-                    double oldchisq = seedin.getHelix().chisqtot();
-                    double oldcirclechisq = seedin.getHelix().chisq()[0];
-                    double chisqbest = 1.e6;
-
                     if (diag != null) {
                         diag.fireConfirmerExtenderWorkingSeedInfo(task, seedin, hitlist);
                     }
 
-                    //  Use the first seed hit for the fast check of additional hits
-                    HelicalTrackHit checkhit = seedin.getHits().get(0);
-
                     //  For each hit in this confirmation/extension layer, make a test seed including the new hit
                     for (HelicalTrackHit hit : hitlist) {
 
+//                        System.out.println("Checking a hit for viability");
                         //  Check that this hit is potentially viable
                         if (!checker.CheckHitPair(checkhit, hit)) continue;
 
@@ -137,19 +157,7 @@
                         //  See if we have a successful fit
                         boolean success = fitter.FitCandidate(test, strategy);
 
-                        if (!success) {
-
-                            if (diag != null) {
-                                diag.fireConfirmerExtenderFitNoSuccess(task, seedin, hit, fitter, true);
-                            }
-                            if (fitter.getFitStatus() != FitStatus.CircleFitFailed) {
-                                double circlechisq = fitter.getCircleFit().chisq();
-                                if (circlechisq > oldcirclechisq + strategy.getMaxChisq()) {
-                                    break;
-                                }
-                            }
-                            continue;
-                        }
+//                        System.out.println("Fit completed with status: "+success);
                         if (success) {
 
                             //  Attach the fit to the test seed and add it to the list
@@ -159,36 +167,54 @@
                             }
                             newlist.add(test);
                             chisqbest = Math.min(chisqbest, fitter.getHelix().chisqtot());
-                        }
-                    }
 
-                    //  If all fit tries for this layer are potentially bad hits, include the starting seed in the list
-                    if (chisqbest - oldchisq > strategy.getBadHitChisq()) {
-                        newlist.add(seedin);
-                        if (diag != null) {
-                            diag.fireConfirmerExtenderAllHitsPotentiallyBad(task, seedin, hitlist, chisqbest, oldchisq);
+                        } else {
+
+                            if (diag != null) {
+                                diag.fireConfirmerExtenderFitNoSuccess(task, seedin, hit, fitter, true);
+                            }
+//                            System.out.println("Fit Status: "+fitter.getFitStatus());
+                            if (fitter.getFitStatus() != FitStatus.CircleFitFailed) {
+                                double circlechisq = fitter.getCircleFit().chisq();
+
+//                                System.out.println("Delta chisq: "+(circlechisq-oldcirclechisq));
+
+                                if (circlechisq > oldcirclechisq + strategy.getMaxChisq()) {
+                                    continue SectorLoop;
+                                }
+                            }
                         }
-                    } else {
-                        n++;
                     }
                 }
-            }
 
+                //  If all fit tries for this layer are potentially bad hits, include the starting seed in the list
+                if (chisqbest - oldchisq > strategy.getBadHitChisq()) {
+//                    System.out.println("Keeping original fit with "+seedin.getHits().size()+" hits");
+                    newlist.add(seedin);
+//                    if (diag != null) {
+//                        diag.fireConfirmerExtenderAllHitsPotentiallyBad(task, seedin, hitlist, chisqbest, oldchisq);
+//                    }
+                } else {
+                    n++;
+                }
+            }
 
             //  Use the new list of seeds as the working listinput to the next layer search
             seedlist = newlist;
+//            System.out.println("New list with "+seedlist.size()+" seeds");
             if (diag != null) {
                 diag.fireConfirmerExtenderLayerDone(task, n, seedlist);
             }
+
+            //  One less layer left
+            nleft--;
         }
 
         //Check for seeds with sufficient numbers of confirmed/extended hits
         for (SeedCandidate candidate : seedlist) {
             int hits = candidate.getHits().size();
-            if ((task == Task.EXTEND && hits >= strategy.getMinHits()) ||
-                    (task == Task.CONFIRM && hits >= strategy.getMinConfirm() + 3)) {
-                result.add(candidate);
-            }
+//            System.out.println("Final candidate with "+hits+" hits");
+            if (hits >= minhits) result.add(candidate);
         }
         return result.size() > 0;
     }

lcsim/src/org/lcsim/recon/tracking/seedtracker
FastCheck.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- FastCheck.java	18 Jan 2009 00:21:22 -0000	1.2
+++ FastCheck.java	20 Jan 2009 19:19:52 -0000	1.3
@@ -1,7 +1,4 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
+
 package org.lcsim.recon.tracking.seedtracker;
 
 import org.lcsim.constants.Constants;
@@ -10,7 +7,7 @@
 
 /**
  *
- * @author richp
+ * @author Richard Partridge
  */
 public class FastCheck {
 
@@ -83,18 +80,15 @@
         return zOK;
     }
 
-    public boolean CheckSector(HitManager hmanager, SeedCandidate seed, SeedLayer layer, Sector sector) {
+    public boolean CheckSector(SeedCandidate seed, Sector sector) {
 
-        //  Get the identifier for this sector
-        String identifier = hmanager.MakeFullIdentifier(layer, sector);
-
-        //  Get limits on r, phi, and z for hits in this layer
-        double rmin = hmanager.getRMin(identifier);
-        double rmax = hmanager.getRMax(identifier);
-        double phimin = hmanager.getPhiMin(identifier);
-        double phimax = hmanager.getPhiMax(identifier);
-        double zmin = hmanager.getZMin(identifier);
-        double zmax = hmanager.getZMax(identifier);
+        //  Get limits on r, phi, and z for hits in this sector
+        double rmin = sector.rmin();
+        double rmax = sector.rmax();
+        double phimin = sector.phimin();
+        double phimax = sector.phimax();
+        double zmin = sector.zmin();
+        double zmax = sector.zmax();
 
         //  Calculate the maximum phi deviation from a straight-line track for this layer
         double dphimxsec1 = dphimx(rmax);
@@ -123,6 +117,23 @@
         return true;
     }
 
+    public boolean CheckSectorPair(Sector s1, Sector s2) {
+        if (CheckPair(s1, s2)) return true;
+        return CheckPair(s2, s1);
+    }
+
+    private boolean CheckPair(Sector s1, Sector s2) {
+        double dphimx1 = dphimx(s1.rmin());
+        double dphimx2 = dphimx(s2.rmax());
+        double dphi = phidif(dphimx1, dphimx2);
+        double mid1 = (s1.phimax() + s1.phimin()) / 2.0;
+        double wid1 = s1.phimax() - mid1;
+        double mid2 = (s2.phimax() + s2.phimin()) / 2.0;
+        double wid2 = s2.phimax() - mid2;
+        double dmid = phidif(mid1, mid2);
+        return dmid < dphi + wid1 + wid2;
+    }
+
     private double dphimx(double r) {
         return Math.asin((2 * _RMin * _dMax - _dMax * _dMax - r * r) / (2 * r * (_RMin - _dMax)));
     }

lcsim/src/org/lcsim/recon/tracking/seedtracker
HitManager.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- HitManager.java	18 Jan 2009 00:21:22 -0000	1.2
+++ HitManager.java	20 Jan 2009 19:19:52 -0000	1.3
@@ -7,13 +7,10 @@
 package org.lcsim.recon.tracking.seedtracker;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 
 import org.lcsim.event.EventHeader;
-import org.lcsim.fit.helicaltrack.HelicalTrack2DHit;
 import org.lcsim.fit.helicaltrack.HelicalTrackHit;
-import org.lcsim.geometry.subdetector.BarrelEndcapFlag;
 
 /**
  * Organize tracker hits into lists of hits sorted by detector name, layer number, and barrel-endcap flag
@@ -23,15 +20,6 @@
 public class HitManager {
 
     private SectorManager _smanager;
-    private HashMap<String, List<HelicalTrackHit>> _hitlist;
-    private HashMap<String, List<Sector>> _sectorlist;
-    private HashMap<String, Sector> _sector;
-    private HashMap<String, Double> _rmin;
-    private HashMap<String, Double> _rmax;
-    private HashMap<String, Double> _phimin;
-    private HashMap<String, Double> _phimax;
-    private HashMap<String, Double> _zmin;
-    private HashMap<String, Double> _zmax;
     private int _nphinom = 4;
     private double _detanom = 1.;
 
@@ -54,207 +42,39 @@
      */
     public void OrganizeHits(EventHeader event) {
 
-        //  Create the hash maps
-        _hitlist = new HashMap<String, List<HelicalTrackHit>>();
-        _sectorlist = new HashMap<String, List<Sector>>();
-        _sector = new HashMap<String, Sector>();
-        _rmin = new HashMap<String, Double>();
-        _rmax = new HashMap<String, Double>();
-        _phimin = new HashMap<String, Double>();
-        _phimax = new HashMap<String, Double>();
-        _zmin = new HashMap<String, Double>();
-        _zmax = new HashMap<String, Double>();
+        //  Initialize the sector manager
+        _smanager.Initialize();
 
-        //  Retrieve the HelicalTrackHits and loop over the hits
+        //  Retrieve the HelicalTrackHits
         List<HelicalTrackHit> hitcol = (List<HelicalTrackHit>) event.get("HelicalTrackHits");
-        for (HelicalTrackHit hit : hitcol) {
-
-            //  Create a sector for this hit
-            Sector sector = _smanager.FindSector(hit);
 
-            //  Construct identifier strings for the hit and hit+sector
-            String hitid = hit.getLayerIdentifier();
-            String fullid = hitid + sector.SectorID();
-
-            //  Create the sector list for this hit ID if it doesn't exist
-            if (!_sectorlist.containsKey(hitid))
-                _sectorlist.put(hitid, new ArrayList<Sector>());
-
-            //  Save the sector
-            if (!_sector.containsKey(fullid)) {
-                _sector.put(fullid, sector);
-                _sectorlist.get(hitid).add(sector);
-            }
-
-            //  Update the statistics for both the sector and full layer
-            Update(hitid, hit);
-            Update(fullid, hit);
+        //  Loop over the hits and let the SectorManager keep track of them
+        for (HelicalTrackHit hit : hitcol) {
+            //  Tell the sector manager about this hit
+            _smanager.AddHit(hit);
         }
     }
 
+    public List<Sector> getSectors(SeedLayer seedlayer) {
+        return _smanager.getSectors(seedlayer);
+    }
+
     /**
      * Return the list of tracker hits associated with a specified SeedLayer
      * @param seedlayer Seedlayer to look at
      * @return List of TrackerHits
      */
     public List<HelicalTrackHit> getTrackerHits(SeedLayer seedlayer) {
-        return getTrackerHits(MakeHitIdentifier(seedlayer));
-    }
-
-    public List<HelicalTrackHit> getTrackerHits(SeedLayer seedlayer, Sector sector) {
-        return getTrackerHits(MakeFullIdentifier(seedlayer, sector));
-    }
-
-    public List<HelicalTrackHit> getTrackerHits(String identifier) {
-        List<HelicalTrackHit> hitlist;
-        if (_hitlist.containsKey(identifier)) {
-            hitlist = _hitlist.get(identifier);
-        } else {
-            hitlist = new ArrayList<HelicalTrackHit>();
-        }
-        return hitlist;
-    }
-
-    public String MakeFullIdentifier(String hitid, Sector sector) {
-        return hitid+sector.SectorID();
-    }
-
-    public String MakeFullIdentifier(SeedLayer seedlayer, Sector sector) {
-        String hitid = MakeHitIdentifier(seedlayer);
-        return MakeFullIdentifier(hitid, sector);
-    }
-
-    public String MakeHitIdentifier(SeedLayer seedlayer) {
-        return MakeHitIdentifier(seedlayer.getDetName(), seedlayer.getLayer(),
-                seedlayer.getBarrelEndcapFlag());
-    }
-
-    public String MakeHitIdentifier(String detname, int layer, BarrelEndcapFlag beflag) {
-        return detname + layer + beflag;
-    }
-
-    public List<Sector> getSectorList(SeedLayer layer) {
-        String identifier = MakeHitIdentifier(layer);
-        List<Sector> sectorlist;
-        if (_sectorlist.containsKey(identifier)) {
-            sectorlist = _sectorlist.get(identifier);
-        } else {
-            sectorlist = new ArrayList<Sector>();
-        }
-        return sectorlist;
-    }
-
-    /**
-     * Return the smallest radius hit for a hit collection.  The hit collection
-     * can be for either a full SeedLayer or sector, depending on the
-     * identifier used.
-     * @param identifier Identifier for the hit collection
-     * @return Minimum hit radius
-     */
-    public double getRMin(String identifier) {
-        double rmin = 9999999.;
-        if (_rmin.containsKey(identifier)) {
-            rmin = Math.min(rmin, _rmin.get(identifier));
-        }
-        return rmin;
-    }
-
-    /**
-     * Return the largest radius hit for a hit collection.  The hit collection
-     * can be for either a full SeedLayer or sector, depending on the
-     * identifier used.
-     * @param identifier Identifier for the hit collection
-     * @return Maximum hit radius
-     */
-    public double getRMax(String identifier) {
-        double rmax = 0.;
-        if (_rmax.containsKey(identifier)) {
-            rmax = Math.max(rmax, _rmax.get(identifier));
-        }
-        return rmax;
-    }
-
-    public double getPhiMin(String identifier) {
-        double phimin = 2. * Math.PI;
-        if (_phimin.containsKey(identifier)) {
-            phimin = Math.min(phimin, _phimin.get(identifier));
-        }
-        return phimin;
-    }
-
-     public double getPhiMax(String identifier) {
-        double phimax = 0.;
-        if (_phimax.containsKey(identifier)) {
-            phimax = Math.max(phimax, _phimax.get(identifier));
-        }
-        return phimax;
-    }
-
-    /**
-     * Return the minimum z coordinate for a hit in a particular SeedLayer
-     * Return the minimum z coordinate for a hit collection.  The hit collection
-     * can be for either a full SeedLayer or sector, depending on the
-     * identifier used.
-     * @param identifier Identifier for the hit collection
-     * @return Minimum z coordinate
-     */
-    public double getZMin(String identifier) {
-        double zmin = 9999999.;
-        if (_zmin.containsKey(identifier)) {
-            zmin = Math.min(zmin, _zmin.get(identifier));
+        
+        //  Get the list of sectors for this SeedLayer
+        List<Sector> sectorlist = getSectors(seedlayer);
+
+        //  Make a list of all the hits in these sectors
+        List<HelicalTrackHit> hitlist = new ArrayList<HelicalTrackHit>();
+        for (Sector sector : sectorlist) {
+            hitlist.addAll(sector.Hits());
         }
-        return zmin;
-    }
-
-    /**
-     * Return the maximum z coordinate for a hit collection.  The hit collection
-     * can be for either a full SeedLayer or sector, depending on the
-     * identifier used.
-     * @param identifier  Identifier for the hit collection
-     * @return Maximum z coordinate
-     */
-    public double getZMax(String identifier) {
-        double zmax = -9999999.;
-        if (_zmax.containsKey(identifier)) {
-            zmax = Math.max(zmax, _zmax.get(identifier));
-        }
-        return zmax;
-    }
-
-    private void Update(String identifier, HelicalTrackHit hit) {
 
-        //  If we haven't encountered this identifier, initialize the hash maps
-        if (!_hitlist.containsKey(identifier)) {
-            _hitlist.put(identifier, new ArrayList<HelicalTrackHit>());
-            _rmin.put(identifier, 9999999.);
-            _rmax.put(identifier, 0.);
-            _phimin.put(identifier, 2. * Math.PI);
-            _phimax.put(identifier, 0.);
-            _zmin.put(identifier, 9999999.);
-            _zmax.put(identifier, -9999999.);
-        }
-
-        //  Add the hit to the appropriate list
-        _hitlist.get(identifier).add(hit);
-
-        //  Get r, phi, zmin, and zmax for this hit
-        double r = hit.r();
-        double phi = hit.phi();
-        double zmin = hit.z();
-        double zmax = zmin;
-        if (hit instanceof HelicalTrack2DHit) {
-            HelicalTrack2DHit hit2d = (HelicalTrack2DHit) hit;
-            zmin = hit2d.zmin();
-            zmax = hit2d.zmax();
-        }
-
-        //  Update the min/max values for this identifier
-        if (r < _rmin.get(identifier)) _rmin.put(identifier, r);
-        if (r > _rmax.get(identifier)) _rmax.put(identifier, r);
-        if (phi < _phimin.get(identifier)) _phimin.put(identifier, phi);
-        if (phi > _phimax.get(identifier)) _phimax.put(identifier, phi);
-        if (zmin < _zmin.get(identifier)) _zmin.put(identifier, zmin);
-        if (zmax > _zmax.get(identifier)) _zmax.put(identifier, zmax);
-        return;
+        return hitlist;
     }
 }
\ No newline at end of file

lcsim/src/org/lcsim/recon/tracking/seedtracker
Sector.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- Sector.java	18 Jan 2009 00:21:22 -0000	1.1
+++ Sector.java	20 Jan 2009 19:19:53 -0000	1.2
@@ -5,30 +5,129 @@
 
 package org.lcsim.recon.tracking.seedtracker;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.lcsim.fit.helicaltrack.HelicalTrack2DHit;
+import org.lcsim.fit.helicaltrack.HelicalTrackHit;
+
 /**
  *
- * @author partridge
+ * @author Richard Partridge
  */
 public class Sector {
+    private String _identifier;
+    private String _layerID;
+    private List<HelicalTrackHit> _hitlist;
     private int _phisector;
     private int _etasector;
+    private double _rmin;
+    private double _rmax;
     private double _phimin;
     private double _phimax;
-    private double _etamin;
-    private double _etamax;
+    private double _zmin;
+    private double _zmax;
+    private double _philo;
+    private double _phihi;
+    private double _etalo;
+    private double _etahi;
 
-    public Sector(int phisector, int etasector, double phimin, double phimax,
-            double etamin, double etamax) {
+    public Sector(String identifier, String layerID, int phisector, int etasector,
+            double philo, double phihi, double etalo, double etahi) {
 
-        //  Save the information defining this sector
+        //  Save the identifier, indices, and limits for this sector
+        _identifier = identifier;
+        _layerID = layerID;
         _phisector = phisector;
         _etasector = etasector;
-        _phimin = phimin;
-        _phimax = phimax;
-        _etamin = etamin;
-        _etamax = etamax;
+        _philo = philo;
+        _phihi = phihi;
+        _etalo = etalo;
+        _etahi = etahi;
+
+        //  Initialize the hit list
+        _hitlist = new ArrayList<HelicalTrackHit>();
+
+        //  Initialize the geographic region encompassed by hits in this sector
+        _rmin = 99999.;
+        _rmax = 0.;
+        _phimin = 2.0 * Math.PI;
+        _phimax = 0.0;
+        _zmin = 99999.;
+        _zmax = -99999.;
     }
-    
+
+    public void addHit(HelicalTrackHit hit) {
+
+        //  Check the layerID matches
+        if (!hit.getLayerIdentifier().equals(_layerID)) SectorError();
+
+        //  Check that phi is within limits
+        double phi = hit.phi();
+        if (phi < _philo || phi > _phihi) SectorError();
+
+        //  Check that eta is within limits
+        double eta = SectorManager.Eta(hit);
+        if (eta < _etalo || eta > _etahi) SectorError();
+
+        //  Add the hit to the list for this sector
+        _hitlist.add(hit);
+
+        //  Get the location of this hit
+        double r = hit.r();
+        double zmin = hit.z();
+        double zmax = zmin;
+        if (hit instanceof HelicalTrack2DHit) {
+            HelicalTrack2DHit hit2d = (HelicalTrack2DHit) hit;
+            zmin = hit2d.zmin();
+            zmax = hit2d.zmax();
+        }
+
+        //  Update the span in location for hits in this sector
+        _rmin = Math.min(_rmin, r);
+        _rmax = Math.max(_rmax, r);
+        _phimin = Math.min(_phimin, phi);
+        _phimax = Math.max(_phimax, phi);
+        _zmin = Math.min(_zmin, zmin);
+        _zmax = Math.min(_zmax, zmax);
+    }
+
+    public String Identifier() {
+        return _identifier;
+    }
+
+    public String LayerID() {
+        return _layerID;
+    }
+
+    public List<HelicalTrackHit> Hits() {
+        return _hitlist;
+    }
+
+    public double rmin() {
+        return _rmin;
+    }
+
+    public double rmax() {
+        return _rmax;
+    }
+
+    public double phimin() {
+        return _phimin;
+    }
+
+    public double phimax() {
+        return _phimax;
+    }
+
+    public double zmin() {
+        return _zmin;
+    }
+
+    public double zmax() {
+        return _zmax;
+    }
+
     public int phiSector() {
         return _phisector;
     }
@@ -37,23 +136,23 @@
         return _etasector;
     }
     
-    public double phimin() {
-        return _phimin;
+    public double philo() {
+        return _philo;
     }
     
-    public double phimax() {
-        return _phimax;
+    public double phihi() {
+        return _phihi;
     }
     
-    public double etamin() {
-        return _etamin;
+    public double etalo() {
+        return _etalo;
     }
     
-    public double etamax() {
-        return _etamax;
+    public double etahi() {
+        return _etahi;
     }
-    
-    public String SectorID() {
-        return "phi"+_phisector+"eta"+_etasector;
+
+    private void SectorError() {
+        throw new RuntimeException("Hit Sectoring error");
     }
-}
+}
\ No newline at end of file

lcsim/src/org/lcsim/recon/tracking/seedtracker
SectorManager.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- SectorManager.java	18 Jan 2009 00:21:22 -0000	1.1
+++ SectorManager.java	20 Jan 2009 19:19:53 -0000	1.2
@@ -1,7 +1,9 @@
-
 package org.lcsim.recon.tracking.seedtracker;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import org.lcsim.fit.helicaltrack.HelicalTrackHit;
 
 /**
@@ -11,32 +13,135 @@
 public class SectorManager {
 
     private List<Sector> _sectorlist;
+    private Map<String, Sector> _sectormap;
+    private Map<String, List<Sector>> _slistmap;
     private int _nphi;
     private double _dphi;
     private double _deta;
 
     public SectorManager(int nphi, double deta) {
-        _nphi = nphi;
-        if (_nphi == 0) throw new RuntimeException("Illegal Sectoring");
 
+        //  Check that we have valid inputs
+        if (nphi <= 0 || deta <= 0.) throw new RuntimeException("Illegal Sectoring");
+
+        //  Save the sector indexing info
+        _nphi = nphi;
         _dphi = 2. * Math.PI / _nphi;
         _deta = deta;
+
+        //  Create the list of sectors with hits
+        _sectorlist = new ArrayList<Sector>();
+
+        //  Create a map to locate a sector using it's ID
+        _sectormap = new HashMap<String, Sector>();
+
+        //  Create a map to locate the list of sectors for a given layer
+        _slistmap = new HashMap<String, List<Sector>>();
+    }
+
+    public void AddHit(HelicalTrackHit hit) {
+        
+        //  Get the sector identifier for this hit
+        String identifier = FindSectorIdentifier(hit);
+
+        //  Retrieve the sector - create a new sector if one doesn't already exist
+        Sector sector;
+        if (!_sectormap.containsKey(identifier)) {
+            sector = CreateSector(hit);
+            _sectorlist.add(sector);
+            _sectormap.put(identifier, sector);
+
+            //  See if we need to create a new list of Sensors for this detector layer
+            String lyrid = sector.LayerID();
+            if (!_slistmap.containsKey(lyrid)) {
+               List<Sector> slist = new ArrayList<Sector>();
+                _slistmap.put(lyrid, slist);
+            }
+
+            //  Update the list of sensors for this layer
+            _slistmap.get(lyrid).add(sector);
+
+        } else {
+            sector = _sectormap.get(identifier);
+        }
+        
+        //  Add the hit to the sector
+        sector.addHit(hit);
+    }
+
+    public List<Sector> getAllSectors() {
+        return _sectorlist;
+    }
+
+    public List<Sector> getSectors(SeedLayer layer) {
+        String layerID = layer.LayerID();
+        List<Sector> sectors;
+        if (_slistmap.containsKey(layerID)) {
+            sectors = _slistmap.get(layerID);
+        } else {
+            sectors = new ArrayList<Sector>();
+        }
+        return sectors;
+    }
+
+    public void Initialize() {
+        _sectorlist.clear();
+        _sectormap.clear();
     }
 
-    public Sector FindSector(HelicalTrackHit hit) {
+    private Sector CreateSector(HelicalTrackHit hit) {
+        String identifier = FindSectorIdentifier(hit);
+        String lyrid = hit.getLayerIdentifier();
+        int phibin = PhiBin(hit);
+        int etabin = EtaBin(hit);
+        double phimin = PhiMin(phibin);
+        double phimax = PhiMax(phibin);
+        double etamin = EtaMin(etabin);
+        double etamax = EtaMax(etabin);
+        return new Sector(identifier, lyrid, phibin, etabin, phimin, phimax, etamin, etamax);
+    }
+
+    private String FindSectorIdentifier(HelicalTrackHit hit) {
+        String layerID = hit.getLayerIdentifier();
+        int phibin = PhiBin(hit);
+        int etabin = EtaBin(hit);
+        return SectorID(layerID, phibin, etabin);
+    }
+
+    private String SectorID(String layerID, int phibin, int etabin) {
+        return layerID+"phi"+phibin+"eta"+etabin;
+    }
+
+    private int PhiBin(HelicalTrackHit hit) {
         double phi = hit.phi();
-        double eta = eta(hit);
         int phibin = (int) Math.floor(phi / _dphi);
+        return phibin;
+    }
+
+    private int EtaBin(HelicalTrackHit hit) {
+        double eta = Eta(hit);
         int etabin = (int) Math.floor(eta / _deta);
-        double phimin = phibin * _dphi;
-        double phimax = phimin + _dphi;
-        double etamin = etabin * _deta;
-        double etamax = etamin + _deta;
-        return new Sector(phibin, etabin, phimin, phimax, etamin, etamax);
+        return etabin;
+    }
+
+    private double PhiMin(int phibin) {
+        return phibin * _dphi;
+    }
+
+    private double PhiMax(int phibin) {
+        return (phibin + 1) * _dphi;
+    }
+
+    private double EtaMin(int etabin) {
+        return etabin * _deta;
+    }
+
+    private double EtaMax(int etabin) {
+        return (etabin + 1) * _deta;
     }
 
-    private double eta(HelicalTrackHit hit) {
+    public static double Eta(HelicalTrackHit hit) {
         double theta = Math.acos(hit.z() / hit.r());
         return -Math.log(Math.tan(theta/2.0));
     }
-}
+}
\ No newline at end of file

lcsim/src/org/lcsim/recon/tracking/seedtracker
SeedLayer.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- SeedLayer.java	27 Aug 2008 17:59:02 -0000	1.1
+++ SeedLayer.java	20 Jan 2009 19:19:53 -0000	1.2
@@ -7,6 +7,7 @@
 
 package org.lcsim.recon.tracking.seedtracker;
 
+import org.lcsim.fit.helicaltrack.HitIdentifier;
 import org.lcsim.geometry.subdetector.BarrelEndcapFlag;
 
 /**
@@ -82,6 +83,10 @@
     public SeedType getType() {
         return _type;
     }
+
+    public String LayerID() {
+        return HitIdentifier.Identifier(_detname, _layer, _beflag);
+    }
     
     @Override
     public boolean equals(Object other) {

lcsim/src/org/lcsim/recon/tracking/seedtracker
SeedTrackFinder.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- SeedTrackFinder.java	16 Jan 2009 17:22:51 -0000	1.5
+++ SeedTrackFinder.java	20 Jan 2009 19:19:53 -0000	1.6
@@ -4,7 +4,6 @@
  * Created on January 22, 2008, 9:39 AM
  *
  */
-
 package org.lcsim.recon.tracking.seedtracker;
 
 import java.util.ArrayList;
@@ -19,38 +18,39 @@
  * @version 1.0
  */
 public class SeedTrackFinder {
+
     private HitManager _hitmanager;
     private HelixFitter _helixfitter;
     private ConfirmerExtender _confirmer;
     private MergeSeedLists _merger;
     private List<SeedCandidate> _trackseeds;
     private ISeedTrackerDiagnostics _diag = null;
-    
+
     /**
      * Creates a new instance of SeedTrackFinder
      */
     public SeedTrackFinder(HitManager hitmanager, HelixFitter helixfitter) {
-        
+
         //  Save the pointers to the hit manager and helix fitter classes
         _hitmanager = hitmanager;
         _helixfitter = helixfitter;
-        
+
         //  Instantiate the Confirmer/Extender and Seed Candidate merging classes
         _confirmer = new ConfirmerExtender(_hitmanager, _helixfitter);
         _merger = new MergeSeedLists();
-        
+
         //  Create a list of track seeds that have been found
         _trackseeds = new ArrayList<SeedCandidate>();
     }
-    
+
     public void setDiagnostic(ISeedTrackerDiagnostics d) {
-        
+
         //  Setup the diagnostics for this class and the classes used by this class
         _diag = d;
         _confirmer.setDiagnostics(_diag);
         _merger.setDiagnostic(_diag);
     }
-    
+
     public boolean FindTracks(SeedStrategy strategy, double bfield) {
 
         //  Instantiate the fast hit checker
@@ -59,7 +59,12 @@
         //  Get the SeedLayers for this strategy
         List<SeedLayer> seedlayerlist = strategy.getLayers(SeedLayer.SeedType.Seed);
         if (seedlayerlist.size() != 3) return false;
-               
+
+        //  Find the valid sector combinations
+        SeedSectoring ss = new SeedSectoring(_hitmanager, strategy, bfield, seedlayerlist);
+        List<List<Sector>> sslist = ss.SeedSectors();
+//        System.out.println("Number of SeedSectors: "+sslist.size());
+
         //  Initialize counters
         int nfit = 0;
         int nseed = 0;
@@ -68,65 +73,82 @@
         int maxseeds = _hitmanager.getTrackerHits(seedlayerlist.get(0)).size() *
                 _hitmanager.getTrackerHits(seedlayerlist.get(1)).size() *
                 _hitmanager.getTrackerHits(seedlayerlist.get(2)).size();
+        int npairs = 0;
+        int ngdpairs = 0;
+        int ntrip = 0;
+        int nconseeds = 0;
+        int nextseeds = 0;
 
         //  Loop over the first seed layer
-        for (HelicalTrackHit hit1 : _hitmanager.getTrackerHits(seedlayerlist.get(0))) {
+        for (List<Sector> slist : sslist) {
+            for (HelicalTrackHit hit1 : slist.get(0).Hits()) {
+
+                //  Loop over the second seed layer and check that we have a hit pair consistent with our strategy
+                for (HelicalTrackHit hit2 : slist.get(1).Hits()) {
+                    npairs++;
+                    if (!checker.CheckHitPair(hit1, hit2)) continue;
+                    ngdpairs++;
+
+                    //  Loop over the third seed layer and check that we have a hit triplet consistent with our strategy
+                    for (HelicalTrackHit hit3 : slist.get(2).Hits()) {
+                        ntrip++;
+                        if (!checker.CheckHitPair(hit1, hit3)) continue;
+                        if (!checker.CheckHitPair(hit2, hit3)) continue;
+
+                        //  Create a seed candidate from this 3-hit seed
+                        SeedCandidate seed = new SeedCandidate(strategy);
+                        seed.addHit(hit1);
+                        seed.addHit(hit2);
+                        seed.addHit(hit3);
+                        nseed++;
+
+                        //  See if we can fit a helix to this seed candidate
+                        boolean success = _helixfitter.FitCandidate(seed, strategy);
+                        if (!success) continue;
+
+                        //  Save the helix fit
+                        seed.setHelix(_helixfitter.getHelix());
+                        nfit++;
 
-            //  Loop over the second seed layer and check that we have a hit pair consistent with our strategy
-            for (HelicalTrackHit hit2 : _hitmanager.getTrackerHits(seedlayerlist.get(1))) {
-                if (!checker.CheckHitPair(hit1, hit2)) continue;
-                
-                //  Loop over the third seed layer and check that we have a hit triplet consistent with our strategy
-                for (HelicalTrackHit hit3 : _hitmanager.getTrackerHits(seedlayerlist.get(2))) {
-                    if (!checker.CheckHitPair(hit3, hit2)) continue;
-                    if (!checker.CheckHitPair(hit3, hit1)) continue;
-                    
-                    //  Create a seed candidate from this 3-hit seed
-                    SeedCandidate seed = new SeedCandidate(strategy);
-                    seed.addHit(hit1);
-                    seed.addHit(hit2);
-                    seed.addHit(hit3);
-                    nseed++;
-
-                    //  See if we can fit a helix to this seed candidate
-                    boolean success = _helixfitter.FitCandidate(seed, strategy);
-                    if (!success) continue;
-                    
-                    //  Save the helix fit
-                    seed.setHelix(_helixfitter.getHelix());
-                    nfit++;
-                    
-                    //  See if we can confirm this seed candidate
-                    success = _confirmer.Confirm(seed, strategy, bfield);
-                    if (!success) continue;
-                    nconfirm++;
-                    
-                    //  Try to extend each confirmed seed candidates to make a track candidate
-                    List<SeedCandidate> confirmedlist = _confirmer.getResult();
-                    for (SeedCandidate confirmedseed : confirmedlist) {
-                        
-                        //  See if we can extend this seed candidate
-                        success = _confirmer.Extend(confirmedseed, strategy, bfield);
+                        //  See if we can confirm this seed candidate
+                        success = _confirmer.Confirm(seed, strategy, bfield);
                         if (!success) continue;
-                        nextend++;
-                        
-                        //  Found a track candidate - merge it into the list of track candidates
-                        List<SeedCandidate> extendedlist = _confirmer.getResult();
-                        _merger.Merge(_trackseeds, extendedlist, strategy);
+                        nconfirm++;
+
+                        //  Try to extend each confirmed seed candidates to make a track candidate
+                        List<SeedCandidate> confirmedlist = _confirmer.getResult();
+                        nconseeds += confirmedlist.size();
+                        for (SeedCandidate confirmedseed : confirmedlist) {
+
+                            //  See if we can extend this seed candidate
+                            success = _confirmer.Extend(confirmedseed, strategy, bfield);
+                            if (!success) continue;
+                            nextend++;
+
+                            //  Found a track candidate - merge it into the list of track candidates
+                            List<SeedCandidate> extendedlist = _confirmer.getResult();
+                            nextseeds += extendedlist.size();
+                            _merger.Merge(_trackseeds, extendedlist, strategy);
+                        }
+//                        System.out.println("npair: " + npairs + " Good Pairs: " + ngdpairs +
+//                                " ntrip: " + ntrip + " nseed: " + nseed);
+//                        System.out.println("confirmed: " + nconfirm + " con seeds: " + nconseeds +
+//                                " extended: " + nextend + " ext seeds: " + nextseeds);
                     }
                 }
             }
         }
-        
+
         //  Done with track finding for this strategy
-        if(_diag!=null) _diag.fireFinderDone(maxseeds, nseed, nfit, nconfirm, _trackseeds);
+        if (_diag != null)
+            _diag.fireFinderDone(maxseeds, nseed, nfit, nconfirm, _trackseeds);
         return _trackseeds.size() > 0;
     }
-    
+
     public List<SeedCandidate> getTrackSeeds() {
         return _trackseeds;
     }
-    
+
     public void clearTrackSeedList() {
         _trackseeds.clear();
     }

lcsim/src/org/lcsim/recon/tracking/seedtracker
SeedTracker.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- SeedTracker.java	18 Jan 2009 00:21:22 -0000	1.4
+++ SeedTracker.java	20 Jan 2009 19:19:53 -0000	1.5
@@ -69,7 +69,6 @@
     @Override
     protected void process(EventHeader event) {
 
-        System.out.println("Started SeedTracker");
         //  Pass the event to the diagnostics package
         if(_diag!=null) _diag.setEvent(event);
         
@@ -84,7 +83,7 @@
             
             //  Set the strategy for the diagnostics
             if(_diag!=null) _diag.fireStrategyChanged(strategy);
-            
+
             //  Perform track finding under this strategy
             _finder.FindTracks(strategy, _bfield);
         }
CVSspam 0.2.8