Print

Print


Commit in lcsim/src/org/lcsim/fit/helicaltrack on MAIN
HitUtils.java+13-61.1 -> 1.2
Eliminate divide by zero bug for stereo hits when the track candidate is perpendicular to the sensor normal

lcsim/src/org/lcsim/fit/helicaltrack
HitUtils.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- HitUtils.java	2 Jul 2008 23:54:24 -0000	1.1
+++ HitUtils.java	29 Jul 2008 23:43:51 -0000	1.2
@@ -134,7 +134,7 @@
         
         //  Assume the particle is coming from the origin, so x2 = gamma * x1
         //  gamma = Origin2 . w_hat / Origin1 . w_hat
-        double gamma = VecOp.dot(strip2.origin(), strip2.w()) / VecOp.dot(strip1.origin(), strip1.w());
+        double gamma = VecOp.dot(strip2.origin(), strip2.w()) / NonZeroDotProduct(strip1.origin(), strip1.w());
         
         //  Calculate the seperation between the sensor planes
         double separation = VecOp.dot(strip1.w(), VecOp.sub(strip2.origin(), strip1.origin()));
@@ -164,7 +164,7 @@
     public static SymmetricMatrix CovarianceFromOrigin(HelicalTrackStrip strip1, HelicalTrackStrip strip2) {
         //  Assume the particle is coming from the origin, so x2 = gamma * x1
         //  gamma = Origin2 . w_hat / Origin1 . w_hat
-        double gamma = VecOp.dot(strip2.origin(), strip2.w()) / VecOp.dot(strip1.origin(), strip1.w());
+        double gamma = VecOp.dot(strip2.origin(), strip2.w()) / NonZeroDotProduct(strip1.origin(), strip1.w());
         //  Calculate the seperation between the sensor planes
         double separation = SensorSeperation(strip1, strip2);
         //  Calculate v1hat . u2hat, which is equivalent to sin(alpha) where alpha is the stereo angle
@@ -194,7 +194,7 @@
         Hep3Vector dir = trkdir.Direction();
         double salpha = v1Dotu2(strip1, strip2);
         //  Gamma is the distance the particle travels between the two sensors:  gamma = separation / (what . dir)
-        double gamma = SensorSeperation(strip1, strip2) / VecOp.dot(strip1.w(), dir);
+        double gamma = SensorSeperation(strip1, strip2) / NonZeroDotProduct(strip1.w(), dir);
         Hep3Vector p1 = StripCenter(strip1);
         Hep3Vector p2 = StripCenter(strip2);
         //  dp = p2 - (p1 + gamma * dir)
@@ -225,7 +225,7 @@
         //  Calculate phat x v2
         Hep3Vector pcrossv2 = VecOp.cross(dir, strip2.v());
         //  Calculate phat . w
-        double pdotw = VecOp.dot(dir, strip1.w());
+        double pdotw = NonZeroDotProduct(dir, strip1.w());
         //  salpha is the sin of the stereo angle
         double salpha = v1Dotu2(strip1, strip2);
         //  Calculate the scale factor:  _separation / 2 * sin(alpha) * (phat . w)^2
@@ -251,7 +251,7 @@
         //  Get the track direction unit vector
         Hep3Vector dir = trkdir.Direction();
         //  Gamma is the distance the particle travels between the two sensors:  gamma = separation / (what . dir)
-        double gamma = SensorSeperation(strip1, strip2) / VecOp.dot(strip1.w(), dir);
+        double gamma = SensorSeperation(strip1, strip2) / NonZeroDotProduct(strip1.w(), dir);
         double salpha = v1Dotu2(strip1, strip2);
         Hep3Vector p1 = StripCenter(strip1);
         Hep3Vector p2 = StripCenter(strip2);
@@ -275,7 +275,7 @@
         //  Calculate u1 . u2
         double u1dotu2 = VecOp.dot(strip1.u(), strip2.u());
         //  Calculate phat . w
-        double pdotw = VecOp.dot(dir, strip1.w());
+        double pdotw = NonZeroDotProduct(dir, strip1.w());
         //  Calculate phat x v2
         Hep3Vector pcrossv2 = VecOp.cross(dir, strip2.v());
         double salpha = v1Dotu2(strip1, strip2);
@@ -307,6 +307,13 @@
         return VecOp.dot(strip1.v(), strip2.u());
     }
     
+    private static double NonZeroDotProduct(Hep3Vector v1, Hep3Vector v2) {
+        double cth = VecOp.dot(v1, v2);
+        if (Math.abs(cth) < _eps) cth = Math.copySign(_eps, cth);
+        if (cth == 0.) cth = _eps;
+        return cth;
+    }
+    
     /**
      * Form the outer matrix product vec1 * vec2^T from the vectors
      * vec1 and vec2.
CVSspam 0.2.8