lcsim/src/org/lcsim/fit/helicaltrack
diff -u -r1.11 -r1.12
--- HelixUtils.java 14 Nov 2010 00:33:25 -0000 1.11
+++ HelixUtils.java 1 Feb 2011 22:45:05 -0000 1.12
@@ -77,8 +77,34 @@
* @return path length from the DCA to the hit
*/
public static double PathLength(HelicalTrackFit helix, HelicalTrackHit hit) {
- // Return the path length from the DCA
- return PathCalc(helix.xc(), helix.yc(), helix.R(), helix.x0(), helix.y0(), hit.x(), hit.y());
+
+ // Calculate the shortest path length from the DCA to the hit x-y coordinates
+ double path0 = PathCalc(helix.xc(), helix.yc(), helix.R(), helix.x0(), helix.y0(), hit.x(), hit.y());
+ if (hit instanceof HelicalTrack2DHit) return path0;
+
+ // Find the closest 3D hit in the z coordinate (if there is one)
+ HelicalTrackHit close = null;
+ double zhit = hit.z();
+ for (HelicalTrackHit fithit : helix.PathMap().keySet()) {
+ if (!(fithit instanceof HelicalTrack2DHit)) {
+
+ if (close == null) {
+ // If this is the first 3D hit, mark it as being closest
+ close = fithit;
+ } else {
+ // Check if the fithit is closer in z
+ if (Math.abs(zhit - fithit.z()) < Math.abs(zhit - close.z())) close = fithit;
+ }
+ }
+ }
+
+ // If we didn't find another 3D hit, return the path from the DCA
+ if (close == null) return path0;
+
+ // Find the path length for the closest hit assuming it hasn't looped
+ double path = helix.PathMap().get(close) +
+ PathCalc(helix.xc(), helix.yc(), helix.R(), close.x(), close.y(), hit.x(), hit.y());
+ return path;
}
/**