lcsim/src/org/lcsim/contrib/seedtracker
diff -N HelicalTrackFitter.java
--- HelicalTrackFitter.java 23 Oct 2006 19:42:37 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,180 +0,0 @@
-/*
- * HelicalTrackFitter.java
- *
- * Created on March 25, 2006, 6:11 PM
- *
- * $Id: HelicalTrackFitter.java,v 1.4 2006/10/23 19:42:37 tonyj Exp $
- */
-
-package org.lcsim.contrib.seedtracker;
-import hep.physics.matrix.SymmetricMatrix;
-import static java.lang.Math.atan2;
-import static java.lang.Math.abs;
-import static java.lang.Math.PI;
-import static java.lang.Math.cos;
-import static java.lang.Math.sin;
-import org.lcsim.fit.circle.CircleFit;
-import org.lcsim.fit.circle.CircleFitter;
-import org.lcsim.fit.helicaltrack.HelicalTrackFit;
-import org.lcsim.fit.line.SlopeInterceptLineFit;
-import org.lcsim.fit.line.SlopeInterceptLineFitter;
-/**
- * Fit a helix to a set of space points. First, a circle is fit to the x-y coordinates.
- * A straight-line fit is then performed on the s-z coordinates.
- *
- * The r-phi and z coordinate measurements are assumed to be uncorrelated. A block
- * diagonal covariance matrix is formed from the results of the circle and s-z fits,
- * ignoring any correlations between these fits.
- *
- * The resulting track parameters follow the "L3 Convention" adopted by org.lcsim.
- *
- * Modified August 2006 by Richard Partridge
- * @author Norman Graf
- */
-public class HelicalTrackFitter
-{
- private CircleFitter _cfitter = new CircleFitter();
- private SlopeInterceptLineFitter _lfitter = new SlopeInterceptLineFitter();
-
- private HelicalTrackFit _fit;
-
- private double[] _circleParameters = new double[3];
-
- /**
- * Creates a new instance of HelicalTrackFitter.
- */
- public HelicalTrackFitter()
- {
- }
-
- /**
- * Fit a helix to a set of space points. The space points should be ordered in
- * increasing track length. The code will properly handle loopers provided
- * that the change in direction between successive points is less than pi.
- * @param x Array of x coordinates
- * @param y Array of y coordinates
- * @param z Array of z coordinates
- * @param drphi Error in r-phi hit position
- * @param dz Error in z coordinate. A negative value indicates that this point is to
- * be excluded in the s-z fit.
- * @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)
- {
- // fit a circle in the x-y plane
- double[] wrphi = new double[np];
- for(int i=0; i<np; ++i)
- {
- wrphi[i] = 1/(drphi[i]*drphi[i]);
- }
- boolean success = _cfitter.fit(x, y, wrphi, np);
- if(!success) return false;
-
- CircleFit cfit = _cfitter.getfit();
- double radius = 1./cfit.curvature();
- double phi0 = cfit.phi();
- double dca = -cfit.dca();
- double xc = (radius-dca)*sin(phi0);
- double yc = -(radius-dca)*cos(phi0);
- _circleParameters[0] = xc;
- _circleParameters[1] = yc;
- _circleParameters[2] = radius;
- // fit a line in the s-z plane
- // assumes points are in increasing order
- double[] s = new double[np];
- double[] sfit = new double[np];
- double[] zfit = new double[np];
- double[] wz = new double[np];
- int nz = 0;
- for(int i=0; i<np; i++)
- {
- if (i==0) {
- s[0] = s(radius, xc, yc, x[0], y[0], 0., 0.);
- }
- else {
- s[i] = s(radius, xc, yc, x[i], y[i], x[i-1], y[i-1]) + s[i-1];
- }
- if (dz[i]>0) {
- sfit[nz] = s[i];
- zfit[nz] = z[i];
- wz[nz] = 1/(dz[i]*dz[i]);
- nz++;
- }
- }
-
- success = _lfitter.fit(sfit, zfit, wz, nz);
- if(!success) return false;
- SlopeInterceptLineFit lfit = _lfitter.getFit();
-
- double[] pars = new double[5];
- SymmetricMatrix cov = new SymmetricMatrix(5);
- double[] chisq = new double[2];
- int[] ndf = new int[2];
-
- chisq[0] = cfit.chisq();
- chisq[1] = lfit.chisquared();
-
- ndf[1] = lfit.ndf();
- ndf[0] = np - 3;
-
- // d0, xy impact parameter. Note: - sign due to opposite sign convention in CircleFitter
- pars[0] = -cfit.dca();
- // phi0
- pars[1] = cfit.phi();
- // omega signed curvature
- pars[2] = cfit.curvature();
- // z0
- pars[3] = lfit.intercept();
- // tan lambda
- pars[4] = lfit.slope();
-
- // fill in covariance matrix
- cov.setElement(0,0, cfit.cov()[0]);
- cov.setElement(0,1,-cfit.cov()[1]); // Need - sign due to sign convention in CircleFitter
- cov.setElement(1,1, cfit.cov()[2]);
- cov.setElement(0,2,-cfit.cov()[3]); // Need - sign due to sign convention in CircleFitter
- cov.setElement(1,2, cfit.cov()[4]);
- cov.setElement(2,2, cfit.cov()[5]);
- //cov[0][3] = 0.;
- //cov[1][3] = 0.;
- //cov[2][3] = 0.;
- cov.setElement(3,3, lfit.interceptUncertainty());
- //cov[0][4] = 0.;
- //cov[1][4] = 0.;
- //cov[2][4] = 0.;
- cov.setElement(3,4, lfit.covariance());
- cov.setElement(4,4, lfit.slopeUncertainty());
- _fit = new HelicalTrackFit(pars, cov, chisq, ndf);
- _fit.setCircleParameters(_circleParameters);
- return true;
- }
-
- /**
- * Get the results of the most recent fit.
- * @return HelicalTrackFit corresponding to most recent fit
- */
- public HelicalTrackFit getFit()
- {
- return _fit;
- }
-
- /**
- * Get the circle paramaters (xc, yc, R) from the most recent fit.
- * @return Circle parameters (xc, yc, R)
- */
- public double[] getCircleParameters()
- {
- return _circleParameters;
- }
-
- double s(double radius, double xcenter, double ycenter, double x1, double y1, double x2, double y2)
- {
- double phi1 = atan2( (y1-ycenter), (x1-xcenter) );
- double phi2 = atan2( (y2-ycenter), (x2-xcenter) );
- double dphi = abs(phi1-phi2);
- if(dphi>PI) dphi = 2.*PI-dphi;
- return abs(radius)*dphi;
- }
-
-}
\ No newline at end of file