Commit in lcsim/src/org/lcsim/fit/helicaltrack on MAIN
HelicalTrackFit.java+28-91.8 -> 1.9
HelicalTrackFitter.java+57-431.18 -> 1.19
+85-52
2 modified files
Provide additional methods for accessing helix fit information

lcsim/src/org/lcsim/fit/helicaltrack
HelicalTrackFit.java 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- HelicalTrackFit.java	6 Feb 2008 02:33:50 -0000	1.8
+++ HelicalTrackFit.java	4 Apr 2008 23:39:30 -0000	1.9
@@ -3,7 +3,7 @@
  *
  * Created on March 25, 2006, 6:11 PM
  *
- * $Id: HelicalTrackFit.java,v 1.8 2008/02/06 02:33:50 partridge Exp $
+ * $Id: HelicalTrackFit.java,v 1.9 2008/04/04 23:39:30 partridge Exp $
  */
 
 package org.lcsim.fit.helicaltrack;
@@ -13,10 +13,6 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.lcsim.fit.circle.CircleFit;
-import org.lcsim.fit.line.SlopeInterceptLineFit;
-import org.lcsim.fit.zsegment.ZSegmentFit;
-
 /**
  * Represents the result of a fit to a helical track.
  * @author Norman Graf
@@ -25,6 +21,7 @@
     // fit independently to a circle in x-y and a line in s-z
     // first is circle, second is line
     private double[] _chisq = new double[2];
+    private double _nhchisq;
     private int[] _ndf = new int[2];
     private double[] _parameters;
     private SymmetricMatrix _covmatrix;
@@ -40,6 +37,7 @@
         _parameters = pars;
         _covmatrix = cov;
         _chisq = chisq;
+        _nhchisq = 0.;
         _ndf = ndf;
         _smap = smap;
     }
@@ -76,8 +74,17 @@
         return _chisq;
     }
     
+    public void setnhchisq(double nhchisq) {
+        _nhchisq = nhchisq;
+        return;
+    }
+    
+    public double nhchisq() {
+        return _nhchisq;
+    }
+    
     public double chisqtot() {
-        return _chisq[0]+_chisq[1];
+        return _chisq[0]+_chisq[1]+_nhchisq;
     }
     
     public int[] ndf() {
@@ -89,21 +96,33 @@
     }
     
     public double cth() {
-        return _parameters[4] / Math.sqrt(1 + Math.pow(_parameters[4], 2));
+        return _parameters[4] / Math.sqrt(1 + Math.pow(slope(), 2));
     }
     
     public double sth() {
-        return 1. / Math.sqrt(1 + Math.pow(_parameters[4], 2));
+        return 1. / Math.sqrt(1 + Math.pow(slope(), 2));
     }
     
     public double pT(double bfield) {
-        return 0.0003 * bfield / Math.abs(_parameters[2]);
+        return 0.0003 * bfield * Math.abs(R());
     }
     
     public double p(double bfield) {
         return pT(bfield) / sth();
     }
     
+    public double R() {
+        return 1./_parameters[2];
+    }
+    
+    public double xc() {
+        return (R() - dca()) * Math.sin(phi0());
+    }
+    
+    public double yc() {
+        return -(R() - dca()) * Math.cos(phi0());
+    }
+    
     public String toString() {
         StringBuffer sb = new StringBuffer("HelicalTrackFit: \n");
         

lcsim/src/org/lcsim/fit/helicaltrack
HelicalTrackFitter.java 1.18 -> 1.19
diff -u -r1.18 -r1.19
--- HelicalTrackFitter.java	29 Feb 2008 18:49:05 -0000	1.18
+++ HelicalTrackFitter.java	4 Apr 2008 23:39:30 -0000	1.19
@@ -4,7 +4,7 @@
  *
  * Created on March 25, 2006, 6:11 PM
  *
- * $Id: HelicalTrackFitter.java,v 1.18 2008/02/29 18:49:05 partridge Exp $
+ * $Id: HelicalTrackFitter.java,v 1.19 2008/04/04 23:39:30 partridge Exp $
  */
 
 import hep.physics.matrix.SymmetricMatrix;
@@ -45,9 +45,13 @@
     private SlopeInterceptLineFitter _lfitter = new SlopeInterceptLineFitter();
     private ZSegmentFitter _zfitter = new ZSegmentFitter();
     private HelixUtils _hutil = new HelixUtils();
-    
+    private CircleFit _cfit;
+    private SlopeInterceptLineFit _lfit;
+    private ZSegmentFit _zfit;
     private HelicalTrackFit _fit;
     
+    public enum FitStatus {Success, CircleFitFailed, LineFitFailed, ZSegmentFitFailed};
+    
     /**
      * Creates a new instance of HelicalTrackFitter.
      */
@@ -65,7 +69,7 @@
      * @param np number of points
      * @return true for successful fit
      */
-    public boolean fit(double[] x, double[] y, double[] z, double[] drphi, double[] dz, int np) {
+    public FitStatus fit(double[] x, double[] y, double[] z, double[] drphi, double[] dz, int np) {
         List<HelicalTrackHit> hitcol = new ArrayList<HelicalTrackHit>();
         for(int i=0; i<np; i++) {
             if (dz[i] > 0.) {
@@ -80,12 +84,18 @@
         return fit(hitcol, msmap);
     }
     
-    public boolean fit(List<HelicalTrackHit> hitcol) {
+    public FitStatus fit(List<HelicalTrackHit> hitcol) {
         Map<HelicalTrackHit, MultipleScatter> msmap = new HashMap<HelicalTrackHit, MultipleScatter>();
         return fit(hitcol, msmap);
     }
     
-    public boolean fit(List<HelicalTrackHit> hitcol, Map<HelicalTrackHit, MultipleScatter> msmap) {
+    public FitStatus fit(List<HelicalTrackHit> hitcol, Map<HelicalTrackHit, MultipleScatter> msmap) {
+        
+        //  Initialize the various fitter outputs
+        _cfit = null;
+        _lfit = null;
+        _zfit = null;
+        _fit = null;
         
         //  Create lists for the various types of hits
         List<HelicalTrackHit> circle_hits = new ArrayList<HelicalTrackHit>();
@@ -120,19 +130,11 @@
         
         //  Setup for doing the circle fit
         int nc = circle_hits.size();
-        if (nc < 3) return false;
+        if (nc < 3) return FitStatus.CircleFitFailed;
         double[] x = new double[nc];
         double[] y = new double[nc];
         double[] wrphi = new double[nc];
         
-        //  Make sure that r is increaseing for the first two hits so that
-        //  the circle gives an outward trajectory
-//        if (circle_hits.get(0).r() > circle_hits.get(1).r()) {
-//            HelicalTrackHit temp = circle_hits.get(0);
-//            circle_hits.set(0, circle_hits.get(1));
-//            circle_hits.set(1, temp);
-//        }
-        
         //  Store the hit coordinates and weights in arrays for the circle fitter
         for(int i=0; i<nc; i++) {
             HelicalTrackHit hit = circle_hits.get(i);
@@ -146,25 +148,25 @@
         
         //  Call the circle fitter and check for success
         boolean success = _cfitter.fit(x, y, wrphi, nc);
-        if(!success) return false;
+        if(!success) return FitStatus.CircleFitFailed;
         
         //  If we are going around the circle in the wrong direction, fix it
-        CircleFit cfit = CircleFix(_cfitter.getfit(), circle_hits);
+        _cfit = CircleFix(_cfitter.getfit(), circle_hits);
         
-        chisq[0] = cfit.chisq();
+        chisq[0] = _cfit.chisq();
         ndof[0] = nc - 3;
-        par[0] = -cfit.dca();
-        par[1] = cfit.phi();
-        par[2] = cfit.curvature();
-        cov.setElement(0, 0, cfit.cov()[0]);
-        cov.setElement(0, 1, -cfit.cov()[1]);
-        cov.setElement(1, 1, cfit.cov()[2]);
-        cov.setElement(0, 2, -cfit.cov()[3]);
-        cov.setElement(1, 2, cfit.cov()[4]);
-        cov.setElement(2, 2, cfit.cov()[5]);
+        par[0] = -_cfit.dca();
+        par[1] = _cfit.phi();
+        par[2] = _cfit.curvature();
+        cov.setElement(0, 0, _cfit.cov()[0]);
+        cov.setElement(0, 1, -_cfit.cov()[1]);
+        cov.setElement(1, 1, _cfit.cov()[2]);
+        cov.setElement(0, 2, -_cfit.cov()[3]);
+        cov.setElement(1, 2, _cfit.cov()[4]);
+        cov.setElement(2, 2, _cfit.cov()[5]);
         
         //  Calculate the arc lengths from the DCA to each hit
-        Map<HelicalTrackHit, Double> smap = getPathLengths(cfit, hitcol);
+        Map<HelicalTrackHit, Double> smap = getPathLengths(_cfit, hitcol);
         
         //  Check if we have enough pixel hits to do a straight-line fit of s(z)
         int npix = pixel_hits.size();
@@ -187,19 +189,19 @@
             
             //  Call the line fitter and check for success
             success = _lfitter.fit(s, z, dz, npix);
-            if(!success) return false;
+            if(!success) return FitStatus.LineFitFailed;
             
             //  TODO:  see if the strip hits are consistent with the track hits
             
             //  Store the line fit output
-            SlopeInterceptLineFit lfit = _lfitter.getFit();
-            chisq[1] = lfit.chisquared();
+            _lfit = _lfitter.getFit();
+            chisq[1] = _lfit.chisquared();
             ndof[1] = npix - 2;
-            par[3] = lfit.intercept();
-            par[4] = lfit.slope();
-            cov.setElement(3, 3, Math.pow(lfit.interceptUncertainty(),2));
-            cov.setElement(3, 4, lfit.covariance());
-            cov.setElement(4, 4, Math.pow(lfit.slopeUncertainty(),2));
+            par[3] = _lfit.intercept();
+            par[4] = _lfit.slope();
+            cov.setElement(3, 3, Math.pow(_lfit.interceptUncertainty(),2));
+            cov.setElement(3, 4, _lfit.covariance());
+            cov.setElement(4, 4, Math.pow(_lfit.slopeUncertainty(),2));
             
         } else {
             
@@ -235,23 +237,23 @@
                 
                 //  Call the ZSegment fitter and check for success
                 success = _zfitter.fit(s, zmin, zmax);
-                if(!success) return false;
+                if(!success) return FitStatus.ZSegmentFitFailed;
                 
                 //  Store the ZSegment fit output
-                ZSegmentFit zfit = _zfitter.getFit();
+                _zfit = _zfitter.getFit();
                 chisq[1] = 0.;
                 ndof[1] = 0;
-                par[3] = zfit.getCentroid()[0];
-                par[4] = zfit.getCentroid()[1];
-                cov.setElement(3, 3, zfit.getCovariance().e(0, 0));
-                cov.setElement(3, 4, zfit.getCovariance().e(0,1));
-                cov.setElement(4, 4, zfit.getCovariance().e(1, 1));
+                par[3] = _zfit.getCentroid()[0];
+                par[4] = _zfit.getCentroid()[1];
+                cov.setElement(3, 3, _zfit.getCovariance().e(0, 0));
+                cov.setElement(3, 4, _zfit.getCovariance().e(0,1));
+                cov.setElement(4, 4, _zfit.getCovariance().e(1, 1));
             }
         }
         
         //  Create the HelicalTrackFit for this helix and exit
         _fit = new HelicalTrackFit(par, cov, chisq, ndof, smap);
-        return true;
+        return FitStatus.Success;
     }
     
     /**
@@ -262,6 +264,18 @@
         return _fit;
     }
     
+    public CircleFit getCircleFit() {
+        return _cfit;
+    }
+    
+    public SlopeInterceptLineFit getLineFit() {
+        return _lfit;
+    }
+    
+    public ZSegmentFit getZSegmentFit() {
+        return _zfit;
+    }
+    
     /**
      * Find the arc lengths for a list of hits
      */
CVSspam 0.2.8