Commit in lcsim on MAIN
src/org/lcsim/util/swim/Helix.java+14-111.14 -> 1.15
test/org/lcsim/util/swim/HelixTest.java+20-11.8 -> 1.9
+34-12
2 modified files
Added fix for getMomentum. (Which was package visible and therefore irrelevant)
Renamed getMomentum to getTangentAtDistance and made it public (So it can't really break anythong, because it wasn't visible in the first place)

Added tests to HelixTest to cover signed-radius-bug.

lcsim/src/org/lcsim/util/swim
Helix.java 1.14 -> 1.15
diff -u -r1.14 -r1.15
--- Helix.java	19 Oct 2005 10:32:53 -0000	1.14
+++ Helix.java	26 Oct 2005 00:36:23 -0000	1.15
@@ -20,7 +20,7 @@
  * All quantities in this class are dimensionless. It has no dependencies
  * except for Hep3Vector (which could easily be removed).
  * @author tonyj
- * @version $Id: Helix.java,v 1.14 2005/10/19 10:32:53 jstrube Exp $
+ * @version $Id: Helix.java,v 1.15 2005/10/26 00:36:23 jstrube Exp $
  */
 public class Helix implements Trajectory
 {
@@ -99,9 +99,10 @@
     */
    public double getDistanceToPoint(Hep3Vector point) {
        double tanLambda = sinLambda/cosLambda;
-       double px = abs(radius)*cosPhi;
-       double py = abs(radius)*sinPhi;
-       double pz = abs(radius)*tanLambda;
+       double r = abs(radius);
+       double px = r*cosPhi;
+       double py = r*sinPhi;
+       double pz = r*tanLambda;
        double rho = -cosLambda/radius;       
        double pMag = sqrt(px*px + py*py + pz*pz);
        Hep3Vector p0 = new BasicHep3Vector(px, py, pz);       
@@ -142,9 +143,10 @@
     */
    public double getSignedClosestDifferenceToPoint(Hep3Vector point) {
        double tanLambda = sinLambda/cosLambda;
-       double px = abs(radius)*cosPhi;
-       double py = abs(radius)*sinPhi;
-       double pz = abs(radius)*tanLambda;
+       double r = abs(radius);
+       double px = r*cosPhi;
+       double py = r*sinPhi;
+       double pz = r*tanLambda;
        double rho = -cosLambda/radius;
        Hep3Vector pCrossB = new BasicHep3Vector(py, -px, 0);
        Hep3Vector xDiff = VecOp.sub(origin, point);
@@ -170,10 +172,11 @@
 
    // Returns the "momentum" at the length s from the starting point.
    // This uses the definition in http://www.phys.ufl.edu/~avery/fitting/transport.pdf
-   Hep3Vector getMomentumAtDistance(double s) {
-	   double p0x = radius*cosPhi;
-	   double p0y = radius*sinPhi;
-	   double p0z = radius*sinLambda/cosLambda;
+   public Hep3Vector getTangentAtDistance(double s) {
+       double r = abs(radius);
+	   double p0x = r*cosPhi;
+	   double p0y = r*sinPhi;
+	   double p0z = r*sinLambda/cosLambda;
 	   double rho = -cosLambda/radius;
 	   
 	   double px = p0x*cos(rho*s) - p0y*sin(rho*s);

lcsim/test/org/lcsim/util/swim
HelixTest.java 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- HelixTest.java	19 Oct 2005 10:34:38 -0000	1.8
+++ HelixTest.java	26 Oct 2005 00:36:24 -0000	1.9
@@ -12,7 +12,7 @@
 /**
  *
  * @author tonyj
- * @version $Id: HelixTest.java,v 1.8 2005/10/19 10:34:38 jstrube Exp $
+ * @version $Id: HelixTest.java,v 1.9 2005/10/26 00:36:24 jstrube Exp $
  */
 public class HelixTest extends TestCase
 {
@@ -275,6 +275,25 @@
        }
    }
 
+   public void testGetTangentAtDistance() {
+       Hep3Vector origin = new BasicHep3Vector(3, 6, 9);
+       double radius = -1.7;
+       double phi = Math.PI/4;
+       double lambda = Math.PI/4;
+       Helix helix1 = new Helix(origin, radius, phi, lambda);
+       Helix helix2 = new Helix(origin, -radius, phi, lambda);
+       
+       // momentum conservation
+       for (int i=0; i<25; ++i) {
+           Hep3Vector tangentAtThisPiece_1 = helix1.getTangentAtDistance(i*.37); 
+           Hep3Vector tangentAtThisPiece_2 = helix2.getTangentAtDistance(i*.37); 
+           assertEquals(tangentAtThisPiece_1.magnitude(), helix1.getTangentAtDistance((i+1)*.37).magnitude());
+           assertEquals(tangentAtThisPiece_2.magnitude(), helix2.getTangentAtDistance(i*.37).magnitude());
+           assertEquals(tangentAtThisPiece_1.z(), tangentAtThisPiece_2.z());
+       }
+   }
+   
+   
    private void assertEquals(Hep3Vector v1, Hep3Vector v2)
    {
       assertEquals(v1.x(),v2.x(), 1e-14);
CVSspam 0.2.8