lcsim/src/org/lcsim/fit/helicaltrack
diff -u -r1.6 -r1.7
--- HelicalTrackFitter.java 1 Aug 2007 20:13:53 -0000 1.6
+++ HelicalTrackFitter.java 11 Aug 2007 01:28:35 -0000 1.7
@@ -4,7 +4,7 @@
*
* Created on March 25, 2006, 6:11 PM
*
- * $Id: HelicalTrackFitter.java,v 1.6 2007/08/01 20:13:53 lstevens Exp $
+ * $Id: HelicalTrackFitter.java,v 1.7 2007/08/11 01:28:35 partridge Exp $
*/
import hep.physics.matrix.SymmetricMatrix;
@@ -18,28 +18,27 @@
import org.lcsim.fit.helicaltrack.HelicalTrackFit;
import org.lcsim.fit.line.SlopeInterceptLineFit;
import org.lcsim.fit.line.SlopeInterceptLineFitter;
-import java.util.ArrayList;
-import org.lcsim.event.TrackerHit;
+import java.util.ArrayList;
+import org.lcsim.event.TrackerHit;
import org.lcsim.event.base.BaseTrackerHit;
import java.util.Collections;
import java.util.*;
/**
* 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 July 2007 by Lori Stevens
* Modified August 2006 by Richard Partridge
* @author Norman Graf
*/
-public class HelicalTrackFitter
-{
+public class HelicalTrackFitter {
private CircleFitter _cfitter = new CircleFitter();
private SlopeInterceptLineFitter _lfitter = new SlopeInterceptLineFitter();
@@ -51,34 +50,32 @@
/**
* Creates a new instance of HelicalTrackFitter.
*/
- public HelicalTrackFitter()
- {
- }
+ public HelicalTrackFitter() {
+ }
/**
- * Reorder list of TrackerHits from closest to furthest from origin in z.
+ * Reorder list of TrackerHits from closest to furthest from origin in z.
* Calculate weights for circle and line fits.
* @param hits list of TrackerHits
* @return True for successful fit
- */
- public boolean fit(List<TrackerHit> hits)
- {
- int np = hits.size();
- double[] wrphi = new double[np];
- double[] wz = new double[np];
-
- order(hits);
-
- for(int i=0; i<np; ++i){
- //(1/(dxdx + dydy))
- wrphi[i] = 1/(hits.get(i).getCovMatrix()[0]+hits.get(i).getCovMatrix()[2]);
- //(1/dzdz)
- wz[i] = 1/hits.get(i).getCovMatrix()[5];
- }
- return fitting(hits, wrphi, wz);
- }
+ */
+ public boolean fit(List<TrackerHit> hits) {
+ int np = hits.size();
+ double[] wrphi = new double[np];
+ double[] wz = new double[np];
+
+ order(hits);
+
+ for(int i=0; i<np; ++i){
+ //(1/(dxdx + dydy))
+ wrphi[i] = 1/(hits.get(i).getCovMatrix()[0]+hits.get(i).getCovMatrix()[2]);
+ //(1/dzdz)
+ wz[i] = Math.sqrt(hits.get(i).getCovMatrix()[5]);
+ }
+ return fitting(hits, wrphi, wz);
+ }
/**
* Convert hits in Cartesian coordinates to BaseTrackerHits for helix fitting.
- * Order hits from closest to furthest from origin in z. Calculate weights
+ * Order hits from closest to furthest from origin in z. Calculate weights
* for circle and line fits.
* @param x array of x coordinates
* @param y array of y coordinates
@@ -88,10 +85,8 @@
* @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)
- {
- for(int i=0; i<np; i++)
- {
+ public boolean fit(double[] x, double[] y, double[] z, double[] drphi, double[] dz, int np) {
+ for(int i=0; i<np; i++) {
BaseTrackerHit bth = new BaseTrackerHit();
double[] pos = {x[i], y[i], z[i]};
bth.setPosition(pos);
@@ -101,17 +96,16 @@
hit.add(bth);
}
order(hit);
-
+
double[] wrphi = new double[np];
double[] wz = new double[np];
- for(int i=0; i<np; ++i)
- {
- wrphi[i] = 1/(drphi[i]*drphi[i]);
+ for(int i=0; i<np; ++i) {
+ wrphi[i] = 1/(drphi[i]*drphi[i]);
wz[i] = 1/(dz[i]*dz[i]);
}
return fitting(hit, wrphi, wz);
- }
+ }
/**
* Fit a helix to set of TrackerHits.
* @param hits list of TrackerHits
@@ -119,21 +113,19 @@
* @param wz array of weights for line fitter
* @return true for successful fit
*/
- public boolean fitting(List<TrackerHit> hits, double[] wrphi, double[] wz)
- {
+ public boolean fitting(List<TrackerHit> hits, double[] wrphi, double[] wz) {
int np = hits.size();
double[] x = new double[np];
double[] y = new double[np];
double[] z = new double[np];
- for(int i=0; i<np; i++)
- {
+ for(int i=0; i<np; i++) {
x[i] = hits.get(i).getPosition()[0];
y[i] = hits.get(i).getPosition()[1];
z[i] = hits.get(i).getPosition()[2];
}
- boolean success = _cfitter.fit(x, y, wrphi, np);
+ boolean success = _cfitter.fit(x, y, wrphi, np);
if(!success) return false;
CircleFit cfit = _cfitter.getfit();
@@ -153,28 +145,25 @@
double[] zfit = new double[np];
double[] wrphibh = new double[np];
int nz = 0;
- for(int i=0; i<np; i++)
- {
+ for(int i=0; i<np; i++) {
if (i==0) {
s[0] = s(radius, xc, yc, x[0], y[0], 0., 0.);
- }
- else {
+ } else {
s[i] = s(radius, xc, yc, x[i], y[i], x[i-1], y[i-1]) + s[i-1];
}
- //type 0 = 3D vertex hit, can only do line fit for vertex hits
- if (hits.get(i).getType()==0)
- {
- sfit[nz] = s[i];
- zfit[nz] = z[i];
- nz++;
- }
- }
+ //type 0 = 3D vertex hit, can only do line fit for vertex hits
+ if (hits.get(i).getType()==0) {
+ sfit[nz] = s[i];
+ zfit[nz] = z[i];
+ nz++;
+ }
+ }
success = _lfitter.fit(sfit, zfit, wz, nz);
if(!success) return false;
SlopeInterceptLineFit lfit = _lfitter.getFit();
- double[] pars = new double[5];
+ double[] pars = new double[5];
SymmetricMatrix cov = new SymmetricMatrix(5);
double[] chisq = new double[2];
@@ -182,7 +171,7 @@
chisq[0] = cfit.chisq();
chisq[1] = lfit.chisquared();
-
+
ndf[1] = lfit.ndf();
ndf[0] = np - 3;
@@ -196,7 +185,7 @@
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
@@ -217,24 +206,21 @@
_fit.setCircleParameters(_circleParameters);
return true;
}
- /**
+ /**
* Get the results of the most recent fit.
* @return HelicalTrackFit corresponding to most recent fit
*/
- public HelicalTrackFit getFit()
- {
+ 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()
- {
+ public double[] getCircleParameters() {
return _circleParameters;
- }
- double s(double radius, double xcenter, double ycenter, double x1, double y1, double x2, double y2)
- {
+ }
+ 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);
@@ -245,8 +231,7 @@
* Reorder TrackerHits from closest to furthest from origin in z.
* @param hits list of TrackerHits
*/
- public void order(List<TrackerHit> hits)
- {
+ public void order(List<TrackerHit> hits) {
Comparator<TrackerHit> z = new Comp();
Collections.sort(hits, z);
double[] hit1 = hits.get(0).getPosition();
@@ -254,20 +239,19 @@
double dist1 = Math.sqrt(hit1[0]*hit1[0]+hit1[1]*hit1[1]+hit1[2]*hit1[2]);
double dist2 = Math.sqrt(hit2[0]*hit2[0]+hit2[1]*hit2[1]+hit2[2]*hit2[2]);
if(dist1 > dist2){
- Collections.reverse(hits);
+ Collections.reverse(hits);
}
- }
+ }
}
class Comp implements Comparator<TrackerHit>
{
- public int compare(TrackerHit hit1, TrackerHit hit2)
- {
+ public int compare(TrackerHit hit1, TrackerHit hit2) {
double z1 = hit1.getPosition()[2];
double z2 = hit2.getPosition()[2];
if (z1 < z2)
return -1;
- else if (z1 > z2)
+ else if (z1 > z2)
return 1;
else
return 0;