Commit in lcsim/src/org/lcsim/recon/tracking/seedtracker on MAIN
FastCheck.java+104added 1.1
ConfirmerExtender.java+78-571.3 -> 1.4
SeedTrackFinder.java+10-741.4 -> 1.5
+192-131
1 added + 2 modified, total 3 files
New checking for viable hits

lcsim/src/org/lcsim/recon/tracking/seedtracker
FastCheck.java added at 1.1
diff -N FastCheck.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ FastCheck.java	16 Jan 2009 17:22:51 -0000	1.1
@@ -0,0 +1,104 @@
+/*
+ * 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;
+import org.lcsim.fit.helicaltrack.HelicalTrack2DHit;
+import org.lcsim.fit.helicaltrack.HelicalTrackHit;
+
+/**
+ *
+ * @author richp
+ */
+public class FastCheck {
+
+    private HelicalTrackHit _hit1cache;
+    private double _RMin;
+    private double _dMax;
+    private double _z0Max;
+    private double _r1;
+    private double _phi1;
+    private double _dphi1mx;
+    private double _zmin1;
+    private double _zmax1;
+    private double _s1min;
+    private double _s1max;
+
+    public FastCheck(SeedStrategy strategy, double bfield) {
+        //  Calculate the minimum radius of curvature, maximum DCA and Maximum z0
+        _RMin = strategy.getMinPT() / (Constants.fieldConversion * bfield);
+        _dMax = strategy.getMaxDCA();
+        _z0Max = strategy.getMaxZ0();
+    }
+
+    public boolean CheckHitPair(HelicalTrackHit hit1, HelicalTrackHit hit2) {
+
+        //  If we have a cache miss for hit1, calculate the cached hit 1 variables
+        if (hit1 != _hit1cache) {
+            _r1 = hit1.r();
+            _phi1 = hit1.phi();
+            _dphi1mx = Math.asin((2 * _RMin * _dMax - _dMax * _dMax - _r1 * _r1) / (2 * _r1 * (_RMin - _dMax)));
+            double zlen1 = 0.;
+            if (hit1 instanceof HelicalTrack2DHit) {
+                zlen1 = ((HelicalTrack2DHit) hit1).zlen();
+            }
+            _zmin1 = hit1.z() - 0.5 * zlen1;
+            _zmax1 = _zmin1 + zlen1;
+            _s1min = _r1 - _dMax;
+            _s1max = 2.0 * _RMin * Math.asin((_r1 + _dMax) / (2.0 * _RMin));
+            _hit1cache = hit1;
+        }
+
+        //  Get the polar coordinates for hit 2
+        double r2 = hit2.r();
+        double phi2 = hit2.phi();
+
+        //  Get the maximum deviation in phi from a radial track given the cuts on radius of curvature and DCA
+        double dphi2mx = Math.asin((2 * _RMin * _dMax - _dMax * _dMax - r2 * r2) / (2 * r2 * (_RMin - _dMax)));
+
+        //  Calculate the difference in azimuthal angle between these two hits, which should always be positive
+        double dphi = Math.abs(phi2 - _phi1);
+        if (dphi > Math.PI) {
+            dphi = 2. * Math.PI - dphi;
+        }
+
+        //  Check that the difference in azimuthal angle is less than the difference in maximum phi deviations
+        boolean phiOK = dphi <= Math.abs(dphi2mx - _dphi1mx);
+        if (!phiOK) return false;
+
+        //  Get the z limits for the hit2
+        double zlen2 = 0.;
+        if (hit2 instanceof HelicalTrack2DHit) {
+            zlen2 = ((HelicalTrack2DHit) hit2).zlen();
+        }
+        double zmin2 = hit2.z() - 0.5 * zlen2;
+        double zmax2 = zmin2 + zlen2;
+
+        //  Check the z0 limits using the minimum path lengths
+        boolean zOK;
+        double s2min = r2 - _dMax;
+        zOK = checkz0(_s1min, _zmin1, _zmax1, s2min, zmin2, zmax2);
+
+        //  If we failed, also try checking with the maximum path lengths
+        if (!zOK) {
+            double s2max = 2.0 * _RMin * Math.asin((r2 + _dMax) / (2.0 * _RMin));
+            zOK = checkz0(_s1max, _zmin1, _zmax1, s2max, zmin2, zmax2);
+        }
+        return zOK;
+    }
+
+    private boolean checkz0(double s1, double zmin1, double zmax1, double s2, double zmin2, double zmax2) {
+        //  Check the minimum and maximum value for z0
+        double zlim1 = (zmin1 * s2 - zmax2 * s1) / (s2 - s1);
+        double zlim2 = (zmax1 * s2 - zmin2 * s1) / (s2 - s1);
+        boolean checkz0;
+        if (s2 > s1) {
+            checkz0 = (zlim1 <= _z0Max) && (zlim2 >= -_z0Max);
+        } else {
+            checkz0 = (zlim2 <= _z0Max) && (zlim1 >= -_z0Max);
+        }
+        return checkz0;
+    }
+}
\ No newline at end of file

lcsim/src/org/lcsim/recon/tracking/seedtracker
ConfirmerExtender.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- ConfirmerExtender.java	13 Jan 2009 06:12:44 -0000	1.3
+++ ConfirmerExtender.java	16 Jan 2009 17:22:51 -0000	1.4
@@ -2,7 +2,6 @@
  * To change this template, choose Tools | Templates
  * and open the template in the editor.
  */
-
 package org.lcsim.recon.tracking.seedtracker;
 
 import java.util.ArrayList;
@@ -17,18 +16,18 @@
  *
  * @author cozzy
  */
-
 public class ConfirmerExtender {
-    
-    public enum Task{
+
+    public enum Task {
+
         CONFIRM,
         EXTEND;
     }
-    
     private HitManager hmanager;
     private HelixFitter fitter;
     private List<SeedCandidate> result;
     private ISeedTrackerDiagnostics diag = null;
+
     /**
      * Constructs the Confirmer/Extender class..
      * @param workinglist The list to work on, either confirmed (extending) or seed (confirming)
@@ -38,126 +37,148 @@
      * @param hitmanager pass the hit manager
      * @param strategy pass the strategy
      */
-    public ConfirmerExtender(HitManager hitmanager, HelixFitter helixfitter){
-              
+    public ConfirmerExtender(HitManager hitmanager, HelixFitter helixfitter) {
+
         this.hmanager = hitmanager;
         this.fitter = helixfitter;
     }
-    
+
     /**
      * Retrieves the result of the confirmation or extension.
      * @return result The list of confirmed/extended seeds..
      */
-    public List<SeedCandidate> getResult(){
-        
+    public List<SeedCandidate> getResult() {
+
         return result;
     }
-    
+
     public void setDiagnostics(ISeedTrackerDiagnostics d) {
         diag = d;
-    }    
-    
-    public boolean Confirm(SeedCandidate seed, boolean optimize, SeedStrategy strategy){
-        return doTask(seed, Task.CONFIRM, optimize, strategy);
-    }
-    
-    public boolean Extend(SeedCandidate seed, boolean optimize, SeedStrategy strategy){
-        return doTask(seed, Task.EXTEND, optimize, strategy);
     }
-    
-    private boolean doTask(SeedCandidate seed, Task task, boolean optimize, SeedStrategy strategy){
+
+    public boolean Confirm(SeedCandidate seed, SeedStrategy strategy, double bfield) {
+        return doTask(seed, Task.CONFIRM, strategy, bfield);
+    }
+
+    public boolean Extend(SeedCandidate seed, SeedStrategy strategy, double bfield) {
+        return doTask(seed, Task.EXTEND, strategy, bfield);
+    }
+
+    private boolean doTask(SeedCandidate seed, Task task, SeedStrategy strategy, double bfield) {
+
+        //  Instantiate the fast hit checker
+        FastCheck checker = new FastCheck(strategy, bfield);
 
         //  Create a list to hold the confirmed / extended seeds
         this.result = new ArrayList<SeedCandidate>();
-        
+
         //  Get the list of layers to use
         List<SeedLayer> lyrs;
-        if (task == Task.EXTEND)
-            lyrs= strategy.getLayers(SeedLayer.SeedType.Extend);
-        else if (task == Task.CONFIRM)
-            lyrs = strategy.getLayers(SeedLayer.SeedType.Confirm);
-        else throw new RuntimeException("Unrecognized Task");
-        
+        if (task == Task.EXTEND) {
+            lyrs = strategy.getLayers(SeedLayer.SeedType.Extend);
+        } else {
+            if (task == Task.CONFIRM) {
+                lyrs = strategy.getLayers(SeedLayer.SeedType.Confirm);
+            } else {
+                throw new RuntimeException("Unrecognized Task");
+            }
+        }
+
         int n = 0;
-        
+
         //  Create a list of input seeds to be searched for a confirmation/extension hit
         List<SeedCandidate> seedlist = new ArrayList<SeedCandidate>();
         //  For the first confirm/extend layer, the input seed is the seed we are trying to check out
         seedlist.add(seed);
-        
+
         //  Loop over the confirmation/extension layers
         for (SeedLayer lyr : lyrs) {
 
             //  Get the hits on this confirmation/extension layer
             List<HelicalTrackHit> hitlist = hmanager.getTrackerHits(lyr);
             if (hitlist.size() == 0) continue;
-            
+
             //  Create a list for seeds that are confirmed/extended using the current layer
             List<SeedCandidate> newlist = new ArrayList<SeedCandidate>();
 
             //  Loop over the input seeds for this layer search
             for (SeedCandidate seedin : seedlist) {
 
-                //  Sort the hits
-                if(optimize) {
-                    SortHits comp = new SortHits(seedin.getHelix());
-                    Collections.sort(hitlist, comp);
-                }
-                
+                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);
-                
+                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) {
-                    
+
+                    //  Check that this hit is potentially viable
+                    if (!checker.CheckHitPair(checkhit, hit)) continue;
+
                     SeedCandidate test = new SeedCandidate(seedin);
                     test.addHit(hit);
-                    
+
                     //  See if we have a successful fit
                     boolean success = fitter.FitCandidate(test, strategy);
 
-                    if (!success ) {
+                    if (!success) {
 
-                        if(diag!=null) diag.fireConfirmerExtenderFitNoSuccess(task, seedin, hit, fitter, optimize);
-                        if (optimize){
-                            if (fitter.getFitStatus() != FitStatus.CircleFitFailed) {
-                                double circlechisq = fitter.getCircleFit().chisq();
-                                if (circlechisq > oldcirclechisq + strategy.getMaxChisq()) break;
+                        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;
                     }
                     if (success) {
-                        
+
                         //  Attach the fit to the test seed and add it to the list
                         test.setHelix(fitter.getHelix());
-                        if(diag!=null) diag.fireConfirmerExtenderFitSuccess(task, seedin, hit, fitter, chisqbest, optimize);
+                        if (diag != null) {
+                            diag.fireConfirmerExtenderFitSuccess(task, seedin, hit, fitter, chisqbest, true);
+                        }
                         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 n++;
+                    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;
-            if(diag!=null) diag.fireConfirmerExtenderLayerDone(task, n, seedlist);
+            if (diag != null) {
+                diag.fireConfirmerExtenderLayerDone(task, n, seedlist);
+            }
         }
-        
+
         //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) ) {
+            if ((task == Task.EXTEND && hits >= strategy.getMinHits()) ||
+                    (task == Task.CONFIRM && hits >= strategy.getMinConfirm() + 3)) {
                 result.add(candidate);
             }
         }

lcsim/src/org/lcsim/recon/tracking/seedtracker
SeedTrackFinder.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- SeedTrackFinder.java	13 Jan 2009 06:12:44 -0000	1.4
+++ SeedTrackFinder.java	16 Jan 2009 17:22:51 -0000	1.5
@@ -10,8 +10,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.lcsim.constants.Constants;
-import org.lcsim.fit.helicaltrack.HelicalTrack2DHit;
 import org.lcsim.fit.helicaltrack.HelicalTrackHit;
 import org.lcsim.recon.tracking.seedtracker.diagnostic.ISeedTrackerDiagnostics;
 
@@ -27,10 +25,6 @@
     private MergeSeedLists _merger;
     private List<SeedCandidate> _trackseeds;
     private ISeedTrackerDiagnostics _diag = null;
-    private double _RMin;
-    private double _dMax;
-    private double _z0Max;
-    private HelicalTrackHit _lasthit;
     
     /**
      * Creates a new instance of SeedTrackFinder
@@ -58,16 +52,14 @@
     }
     
     public boolean FindTracks(SeedStrategy strategy, double bfield) {
-        
+
+        //  Instantiate the fast hit checker
+        FastCheck checker = new FastCheck(strategy, bfield);
+
         //  Get the SeedLayers for this strategy
         List<SeedLayer> seedlayerlist = strategy.getLayers(SeedLayer.SeedType.Seed);
         if (seedlayerlist.size() != 3) return false;
-       
-        //  Cache the minimum radius of curvature and DCA for use by the HitCheck method
-        _RMin = strategy.getMinPT() / (Constants.fieldConversion * bfield);
-        _dMax = strategy.getMaxDCA();
-        _z0Max = strategy.getMaxZ0();
-        
+               
         //  Initialize counters
         int nfit = 0;
         int nseed = 0;
@@ -82,12 +74,12 @@
 
             //  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 (!HitCheck(2, hit1, hit2)) continue;
+                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 (!HitCheck(3, hit2, hit3)) continue;
-                    if (!HitCheck(4, hit1, hit3)) continue;
+                    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);
@@ -105,7 +97,7 @@
                     nfit++;
                     
                     //  See if we can confirm this seed candidate
-                    success = _confirmer.Confirm(seed, true, strategy);
+                    success = _confirmer.Confirm(seed, strategy, bfield);
                     if (!success) continue;
                     nconfirm++;
                     
@@ -114,7 +106,7 @@
                     for (SeedCandidate confirmedseed : confirmedlist) {
                         
                         //  See if we can extend this seed candidate
-                        success = _confirmer.Extend(confirmedseed, true, strategy);
+                        success = _confirmer.Extend(confirmedseed, strategy, bfield);
                         if (!success) continue;
                         nextend++;
                         
@@ -138,60 +130,4 @@
     public void clearTrackSeedList() {
         _trackseeds.clear();
     }
-    
-    private boolean HitCheck(int level, HelicalTrackHit hit1, HelicalTrackHit hit2) {
-        
-        //  Get the polar coordinates for the hits
-        double r1 = hit1.r();
-        double r2 = hit2.r();
-        double phi1 = hit1.phi();
-        double phi2 = hit2.phi();
-        
-        //  Get the maximum deviation in phi from a radial track given the cuts on radius of curvature and DCA
-        double dphi1mx = Math.asin((2*_RMin*_dMax - _dMax*_dMax - r1*r1)/(2*r1*(_RMin - _dMax)));
-        double dphi2mx = Math.asin((2*_RMin*_dMax - _dMax*_dMax - r2*r2)/(2*r2*(_RMin - _dMax)));
-        
-        //  Calculate the difference in azimuthal angle between these two hits, which should always be positive
-        double dphi = Math.abs(phi2 - phi1);
-        if (dphi > Math.PI) dphi = 2. * Math.PI - dphi;
-        if (dphi < 0.) System.out.println("HitCheck: negative dphi = "+dphi);
-
-        //  Check that the difference in azimuthal angle is less than the difference in maximum phi deviations
-        boolean phicut = dphi <= Math.abs(dphi2mx - dphi1mx);
-
-        //  Call the diagnostics if requested and return if we fail the cut
-        if(_diag!=null) _diag.fireFinderDPhiCut(level, dphi, phicut, hit2);
-        if (!phicut) return false;
-
-        //  Get the z limits for the hit1
-        double zlen1 = 0.;
-        if (hit1 instanceof HelicalTrack2DHit) zlen1 = ((HelicalTrack2DHit) hit1).zlen();
-        double zmin1 = hit1.z() - 0.5 * zlen1;
-        double zmax1 = zmin1 + zlen1;
-
-        //  Get the z limits for the hit2
-        double zlen2 = 0.;
-        if (hit2 instanceof HelicalTrack2DHit) zlen2 = ((HelicalTrack2DHit) hit2).zlen();
-        double zmin2 = hit2.z() - 0.5 * zlen2;
-        double zmax2 = zmin2 + zlen2;
-
-        //  Check the z0 limits using the minimum path lengths
-        double s1 = r1 - _dMax;
-        double s2 = r2 - _dMax;
-        if (checkz0(s1, zmin1, zmax1, s2, zmin2, zmax2)) return true;
-
-        //  If we failed, also try checking with the maximum path lengths
-        s1 = 2.0 * _RMin * Math.asin((r1 + _dMax) / (2.0 * _RMin));
-        s2 = 2.0 * _RMin * Math.asin((r2 + _dMax) / (2.0 * _RMin));
-        return checkz0(s1, zmin1, zmax1, s2, zmin2, zmax2);
-    }
-
-    private boolean checkz0(double s1, double zmin1, double zmax1, double s2, double zmin2, double zmax2) {
-        //  Check the minimum and maximum value for z0
-        double zlim1 = (zmin1*s2 - zmax2*s1) / (s2 - s1);
-        double zlim2 = (zmax1*s2 - zmin2*s1) / (s2 - s1);
-        boolean checkz0 = (zlim1 <= _z0Max) && (zlim2 >= -_z0Max);
-        if (s2 < s1) checkz0 = (zlim2 <= _z0Max) && (zlim1 >= -_z0Max);
-        return checkz0;
-    }
 }
\ No newline at end of file
CVSspam 0.2.8