lcsim/src/org/lcsim/fit/helicaltrack
diff -u -r1.5 -r1.6
--- HelicalTrackCross.java 30 Jul 2008 00:11:50 -0000 1.5
+++ HelicalTrackCross.java 28 Aug 2008 01:20:58 -0000 1.6
@@ -7,17 +7,13 @@
package org.lcsim.fit.helicaltrack;
-import hep.physics.matrix.BasicMatrix;
-import hep.physics.matrix.Matrix;
-import hep.physics.matrix.MatrixOp;
-import hep.physics.matrix.MutableMatrix;
import hep.physics.matrix.SymmetricMatrix;
+import hep.physics.vec.BasicHep3Vector;
import hep.physics.vec.Hep3Vector;
import hep.physics.vec.VecOp;
import java.util.ArrayList;
import java.util.List;
-import org.lcsim.event.MCParticle;
/**
* Encapsulate cross (stereo) hit information needed by HelicalTrackFitter.
@@ -27,7 +23,7 @@
* is calculated assuming the track originates from the origin. A corrected
* hit position and covariance matrix, which accounts for the track direction
* and uncertainties in the track direction, can be calculated as well.
- *
+ *
* Note that the nominal position will have large uncertainties associated
* with not knowing the track direction.
* @author Richard Partridge
@@ -51,7 +47,7 @@
// Save the strips
_strip1 = strip1;
_strip2 = strip2;
-
+
// Check if the sensors are parallel to each other
if (VecOp.cross(_strip1.w(),_strip2.w()).magnitude() > _eps) {
throw new RuntimeException("Trying to construct a stereo hit from non-parallel sensor planes!");
@@ -91,10 +87,18 @@
* @param hcov covariance matrix for helix parameters
*/
public void setTrackDirection(TrackDirection trkdir, SymmetricMatrix hcov) {
- super.setCorrectedPosition(HitUtils.PositionOnHelix(trkdir, _strip1, _strip2));
- super.setCorrectedCovMatrix(HitUtils.CovarianceOnHelix(trkdir, hcov, _strip1, _strip2));
- super.setChisq(ChisqPenalty(trkdir, hcov));
-
+ Hep3Vector poscor = HitUtils.PositionOnHelix(trkdir, _strip1, _strip2);
+ SymmetricMatrix covcor = HitUtils.CovarianceOnHelix(trkdir, hcov, _strip1, _strip2);
+ Hep3Vector pos = new BasicHep3Vector(super.getPosition());
+ SymmetricMatrix cov = new SymmetricMatrix(3, super.getCovMatrix(), true);
+ if (drphicalc(poscor, covcor) < drphicalc(pos, cov) && drcalc(poscor, covcor) < drcalc(pos, cov)) {
+ super.setCorrectedPosition(poscor);
+ super.setCorrectedCovMatrix(covcor);
+ super.setChisq(ChisqPenalty(trkdir, hcov));
+ } else {
+ resetTrackDirection();
+ }
+ return;
}
/**
lcsim/src/org/lcsim/fit/helicaltrack
diff -u -r1.12 -r1.13
--- HelicalTrackHit.java 21 Jul 2008 20:08:19 -0000 1.12
+++ HelicalTrackHit.java 28 Aug 2008 01:20:58 -0000 1.13
@@ -51,7 +51,7 @@
private double _drphi;
private double _dr;
private double _chisq;
- protected static final double _eps = 1e-6;
+ protected static final double _eps = 1e-6;
public HelicalTrackHit(Hep3Vector pos, SymmetricMatrix cov, double dEdx, double time, int type,
List rawhits, String detname, int layer, BarrelEndcapFlag beflag) {
_pos = pos;
@@ -66,88 +66,10 @@
_layer = layer;
_beflag = beflag;
_mcplist = new ArrayList<MCParticle>();
+ _chisq = 0.;
setPolarVariables();
}
-// public HelicalTrackHit() {
-// this(null, null, null);
-// }
-
- /**
- * Create a HelicalTrackHit from a TrackerHit.
- * @param hit Corresponding TrackerHit
- */
-// public HelicalTrackHit(TrackerHit hit) {
- // Construct a hit using the position and covariance matrix from the specified TrackerHit
-// this(hit, new BasicHep3Vector(hit.getPosition()), new SymmetricMatrix(3, hit.getCovMatrix(), true));
-// }
-
- /**
- * Create a HelicalTrackHit from scratch without reference to an existing
- * TrackerHit.
- * @param x x coordinate of the hit
- * @param y y coordinate of the hit
- * @param z z coordinate of the hit
- * @param drphi uncertainty in the r*phi direction
- * @param dz uncertainty in the z direction
- */
-// public HelicalTrackHit(double x, double y, double z, double drphi, double dz) {
- // Construct a hit with an empty covariance matrix
-// this(null, new BasicHep3Vector(x, y, z), new SymmetricMatrix(3));
- // Set the covariance matrix elements to their proper values
-// double phi = Math.atan2(y, x);
-// double sphi = Math.sin(phi);
-// double cphi = Math.cos(phi);
-// _cov.setElement(0, 0, sphi*sphi * drphi*drphi);
-// _cov.setElement(0, 1, -sphi * cphi * drphi*drphi);
-// _cov.setElement(1, 1, cphi*cphi * drphi*drphi);
-// _cov.setElement(2, 2, dz*dz);
-// }
-
- /**
- * Create a HelicalTrackHit from a TrackerHit overriding the hit position and
- * covariance matrix in the TrackerHit.
- * @param hit TrackerHit associated with this HelicalTrackHit
- * @param pos Hit position
- * @param cov Covariance matrix for the hit
- */
-// public HelicalTrackHit(TrackerHit hit, Hep3Vector pos, SymmetricMatrix cov) {
-// _trackerhit = hit;
-// _pos = pos;
-// _poscor = pos;
-// _cov = cov;
-// _covcor = cov;
-// if (hit != null) {
-// _dEdx = hit.getdEdx();
-// _time = hit.getTime();
-// _type = hit.getType();
-// _rawhits = hit.getRawHits();
-// } else {
-// _dEdx = 0.;
-// _time = 0.;
-// _type = 0;
-// _rawhits = null;
-// }
- // Default to an empty layer identifier;
-// _detname = "";
- // Default to layer 0
-// _layer = 0;
- // Default to a barrel hit
-// _beflag = BarrelEndcapFlag.BARREL;
- // Default to an empty list of MCParticles
-// _mcplist = new ArrayList<MCParticle>();
- // Cache the polar coordinates (r, phi) and polar uncertainties (drphi, dr)
-// setPolarVariables();
-// }
-
- /**
- * Return the TrackerHit that corresponds to this HelicalTrackHit
- * @return Associated TrackerHit
- */
-// public TrackerHit getTrackerHit() {
-// return _trackerhit;
-// }
-
/**
* Return the corrected x coordinate of the HelicalTrackHit
* @return x coordinate
@@ -347,16 +269,6 @@
}
/**
- * Set the nominal position for the hit.
- * @param pos hit position
- */
- protected void setPosition(Hep3Vector pos) {
- _pos = pos;
- if (_poscor == null) setCorrectedPosition(pos);
- return;
- }
-
- /**
* Set the corrected hit position.
* @param poscor corrected hit position
*/
@@ -367,16 +279,6 @@
}
/**
- * Set the nominal covariance matrix.
- * @param cov covariance matrix
- */
- protected void setCovMatrix(SymmetricMatrix cov) {
- _cov = cov;
- if (_covcor == null) setCorrectedCovMatrix(cov);
- return;
- }
-
- /**
* Set the corrected covariance matrix.
* @param covcor corrected covariance matrix
*/
@@ -386,40 +288,6 @@
return;
}
-// protected void setdEdx(double dEdx) {
-// _dEdx = dEdx;
-// return;
-// }
-
-// protected void setTime(double time) {
-// _time = time;
-// return;
-// }
-
-// protected void setType(int type) {
-// _type = type;
-// return;
-// }
-
-// protected void setRawHits(List rawhits) {
-// _rawhits = rawhits;
-// return;
-// }
-
-// protected void setDetector(String detname) {
-// _detname = detname;
-// return;
-// }
-
-// protected void setLayer(int layer) {
-// _layer = layer;
-// return;
-// }
-
-// protected void setBarrelEndcapFlag(BarrelEndcapFlag beflag) {
-// _beflag = beflag;
-// }
-
/**
* Set the chi^2 penalty for the hit (used by cross hits when one or both of
* the unmeasured coordinates is beyond its allowed range).
@@ -430,32 +298,41 @@
return;
}
+ protected double drphicalc(Hep3Vector pos, SymmetricMatrix cov) {
+ double x = pos.x();
+ double y = pos.y();
+ double r2 = x*x + y*y;
+ return Math.sqrt((y*y * cov.e(0,0) + x*x * cov.e(1,1) - 2. * x * y * cov.e(0,1)) / r2);
+ }
+
+ protected double drcalc(Hep3Vector pos, SymmetricMatrix cov) {
+ double x = pos.x();
+ double y = pos.y();
+ double r2 = x*x + y*y;
+ return Math.sqrt((x*x * cov.e(0,0) + y*y * cov.e(1,1) + 2. * x * y * cov.e(0,1)) / r2);
+ }
+
/**
* Calculate the polar coordinates _r, _phi from the cartesian
* coordinates _x, _y and cache them in this object since we
* expect them to be used repeatedly by the track finding code.
*/
private void setPolarVariables() {
- if (_poscor != null) {
- double x = _poscor.x();
- double y = _poscor.y();
- _r = Math.sqrt(x*x + y*y);
- _phi = Math.atan2(y, x);
- if (_phi < 0.) _phi += 2. * Math.PI;
- if (_covcor != null) {
- _drphi = Math.sqrt(y*y * _covcor.e(0,0) + x*x * _covcor.e(1,1)
- - 2. * x * y * _covcor.e(0,1)) / _r;
- _dr = Math.sqrt(x*x * _covcor.e(0,0) + y*y * _covcor.e(1,1)
- + 2. * x * y * _covcor.e(0,1)) / _r;
-
- //do ! > because that'll handle the NaN case
- if (! (_dr>_eps))
- _dr = _eps;
-
- if (! (_drphi>_eps))
- _drphi = _eps;
- }
- }
+ double x = _poscor.x();
+ double y = _poscor.y();
+ _r = Math.sqrt(x*x + y*y);
+ _phi = Math.atan2(y, x);
+ if (_phi < 0.) _phi += 2. * Math.PI;
+ _drphi = drphicalc(_poscor, _covcor);
+ _dr = drcalc(_poscor, _covcor);
+
+ //do ! > because that'll handle the NaN case
+ if (! (_dr>_eps))
+ _dr = _eps;
+
+ if (! (_drphi>_eps))
+ _drphi = _eps;
+
return;
}
}
\ No newline at end of file
lcsim/src/org/lcsim/fit/helicaltrack
diff -u -r1.5 -r1.6
--- HitUtils.java 19 Aug 2008 22:00:28 -0000 1.5
+++ HitUtils.java 28 Aug 2008 01:20:58 -0000 1.6
@@ -48,7 +48,7 @@
double dz = zres(hit, msmap, helix);
double zmin = hit.z() - tolerance * dz;
double zmax = hit.z() + tolerance * dz;
-
+
// Make a new strip hit using the pixel's corrected position and covariance matrix
HelicalTrack2DHit striphit = new HelicalTrack2DHit(hit.getCorrectedPosition(),
hit.getCorrectedCovMatrix(), hit.getdEdx(), hit.getTime(), hit.getRawHits(),
@@ -244,6 +244,7 @@
// Add the contributions from measurement errors: cov += (v2 * v2^T * du1^2 + v1 * v1^T * du2^2) / sin(alpha)^2
MatrixAdd(Vec2Matrix(VecOp.mult(strip1.du()/salpha, strip2.v())), cov);
MatrixAdd(Vec2Matrix(VecOp.mult(strip2.du()/salpha, strip1.v())), cov);
+
// Convert to a symmetric matrix
return new SymmetricMatrix(cov);
}