lcsim/src/org/lcsim/fit/helicaltrack
diff -N HelicalTrackFitter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ HelicalTrackFitter.java 28 Mar 2006 07:19:50 -0000 1.1
@@ -0,0 +1,92 @@
+/*
+ * HelicalTrackFitter.java
+ *
+ * Created on March 25, 2006, 6:11 PM
+ *
+ * $Id: HelicalTrackFitter.java,v 1.1 2006/03/28 07:19:50 ngraf Exp $
+ */
+
+package org.lcsim.fit.helicaltrack;
+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.line.SlopeInterceptLineFitter;
+/**
+ *
+ * @author Norman Graf
+ */
+public class HelicalTrackFitter
+{
+ private CircleFitter _cfitter = new CircleFitter();
+ private SlopeInterceptLineFitter _lfitter = new SlopeInterceptLineFitter();
+
+ /** Creates a new instance of HelicalTrackFitter */
+ public HelicalTrackFitter()
+ {
+ }
+
+ 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);
+ // fit a line in the s-z plane
+ // assumes points are in increasing order
+ double[] s = new double[np];
+ double[] wz = new double[np];
+ for(int i=0; i<np; ++i)
+ {
+ s[i] = s(radius, xc, yc, x[i], y[i], 0., 0.);
+ wz[i] = 1/(dz[i]*dz[i]);
+ }
+
+ success = _lfitter.fit(s, z, dz, np);
+ if(!success) return false;
+
+ // TODO convert fit results to track parameters and covariance matrix.
+ // now have the fits, need to assemble the track parameters...
+
+ // see org.lcsim.event.Track.Parameters
+ // The track parameters for LCD are defined as follows
+ // <table>
+ // <tr><th>Index</th><th>Meaning</th></tr>
+ // <tr><td> 0 </td><td> d0 = XY impact parameter </td><tr>
+ // <tr><td> 1 </td><td> phi0 </td><tr> </td><tr>
+ // <tr><td> 2 </td><td> omega = 1/curv.radius (negative for negative tracks) </td><tr>
+ // <tr><td> 3 </td><td> z0 = z of track origin (z impact parameter) </td><tr>
+ // <tr><td> 4 </td><td> s = tan lambda </td><tr>
+ // </table>
+
+ // tanlambda = line fit slope
+ // z0 = line fit intercept
+ //TODO should shift s-z line fit to centroid of x-y fit and introduce covariance terms to be correct.
+
+ return true;
+ }
+
+ 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
lcsim/src/org/lcsim/fit/helicaltrack
diff -N HelicalTrackFit.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ HelicalTrackFit.java 28 Mar 2006 07:19:50 -0000 1.1
@@ -0,0 +1,33 @@
+/*
+ * HelicalTrackFit.java
+ *
+ * Created on March 25, 2006, 6:11 PM
+ *
+ * $Id: HelicalTrackFit.java,v 1.1 2006/03/28 07:19:50 ngraf Exp $
+ */
+
+package org.lcsim.fit.helicaltrack;
+
+/**
+ * Represents the result of a fit to a helical track.
+ * @author Norman Graf
+ */
+public class HelicalTrackFit
+{
+ // 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 int[] _ndf = new int[2];
+ private double[] _parameters;
+ private double[][] _covmatrix;
+
+ /** Creates a new instance of HelicalTrackFit */
+ public HelicalTrackFit(double[] pars, double[][] cov, double[] chisq, int[] ndf)
+ {
+ _parameters = pars;
+ _covmatrix = cov;
+ _chisq = chisq;
+ _ndf = ndf;
+ }
+
+}