Print

Print


Commit in lcsim on MAIN
src/org/lcsim/util/swim/Helix.java+10-91.15 -> 1.16
test/org/lcsim/util/swim/HelixTest.java+55-221.9 -> 1.10
+65-31
2 modified files
Fixed the bug that caused the helices to be displayed in the wrong direction.
Added a test that covers the sign of the curvature.
This bug was introduced by myself in an attempt to fix the negative sign bug as reported by Nick Sinev.
Unfortunately, that bug appears to be not completely fixed.
ONE TEST FAILS !!!
This still needs to be looked into.

lcsim/src/org/lcsim/util/swim
Helix.java 1.15 -> 1.16
diff -u -r1.15 -r1.16
--- Helix.java	26 Oct 2005 00:36:23 -0000	1.15
+++ Helix.java	28 Oct 2005 07:57:27 -0000	1.16
@@ -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.15 2005/10/26 00:36:23 jstrube Exp $
+ * @version $Id: Helix.java,v 1.16 2005/10/28 07:57:27 jstrube Exp $
  */
 public class Helix implements Trajectory
 {
@@ -31,14 +31,14 @@
     * @param origin A point on the helix
     * @param radius The <em>signed</em> radius of curvature of the helix.
     *               The conventions is such that for <em>positive</em> radii,
-    *               the direction is <em>counter-clockwise</em>.
+    *               the direction is <em>clockwise</em>.
     * @param phi The azimuthal angle of the helix <em>momentum</em> in x-y plane w/rt positive x-axis at the origin
     * @param lambda The dip angle w/rt positive part of the x-y plane
     */
    public Helix(Hep3Vector origin, double radius, double phi, double lambda)
    {
-      if (abs(lambda) > PI/2.)
-          throw new IllegalArgumentException("lambda = " + lambda + " is outside of -PI/2<lambda<PI/2");
+//      if (abs(lambda) > PI/2.)
+//          throw new IllegalArgumentException("lambda = " + lambda + " is outside of -PI/2<lambda<PI/2");
       this.origin = origin;
       this.radius = radius;
       this.phi = phi;
@@ -56,17 +56,18 @@
 
    /**
     * returns a point on the Helix at a distance alpha from the origin along
-    * the trajectory. alpha == 2*PI*radius is one rotation in the x-y plane
+    * the trajectory. alpha == 2*PI*radius/cos(lambda) is one rotation in the x-y plane
     */
    public Hep3Vector getPointAtDistance(double alpha)
    {
-      double darg = alpha*cosLambda/abs(radius) - phi;
+      double darg = alpha*cosLambda/radius - phi;
       double x = xCenter + radius*sin( darg );
       double y = yCenter + radius*cos( darg );
       double z = origin.z() + alpha*sinLambda;     
       return new BasicHep3Vector(x,y,z);
    }
 
+   
    public double getDistanceToZPlane(double z)
    {
       return (z - origin.z())/sinLambda;      
@@ -110,7 +111,7 @@
        
        // first, the point needs to be translated into the first period
        Hep3Vector xDiff = VecOp.sub(origin, point);
-       double zPos = xDiff.z();
+       double zPos = abs(xDiff.z());
        int addedQuarterPeriods = 0;
        // these are two mutually exclusive cases and two while loops
        // may not be the best way to express this 
@@ -186,8 +187,8 @@
    }
    
    private Hep3Vector origin;
-   private double xCenter;
-   private double yCenter;
+   double xCenter;
+   double yCenter;
    private double radius;
    private double sinLambda;
    private double cosLambda;

lcsim/test/org/lcsim/util/swim
HelixTest.java 1.9 -> 1.10
diff -u -r1.9 -r1.10
--- HelixTest.java	26 Oct 2005 00:36:24 -0000	1.9
+++ HelixTest.java	28 Oct 2005 07:57:27 -0000	1.10
@@ -12,7 +12,7 @@
 /**
  *
  * @author tonyj
- * @version $Id: HelixTest.java,v 1.9 2005/10/26 00:36:24 jstrube Exp $
+ * @version $Id: HelixTest.java,v 1.10 2005/10/28 07:57:27 jstrube Exp $
  */
 public class HelixTest extends TestCase
 {
@@ -84,26 +84,26 @@
       assertEquals(0,helix.getDistanceToInfiniteCylinder(0),1e-14);     
    }
    
-//   public void testHelix2()
-//   {
-//      Hep3Vector origin = new BasicHep3Vector(0,0,0);
-//      double radius = -1;
-//      double phi = Math.PI/2;
-//      double lambda = -Math.PI/4;
-//      Helix helix = new Helix(origin,radius,phi,lambda);
-//
-//      assertEquals(origin, helix.getPointAtDistance(0));
-//      double d = Math.PI*2*Math.sqrt(2);
-//      assertEquals(new BasicHep3Vector(0,0,-Math.PI*2), helix.getPointAtDistance(d));
-//      assertEquals(new BasicHep3Vector(-2,0,-Math.PI), helix.getPointAtDistance(d/2));
-//      
-//      assertEquals(d/2,helix.getDistanceToZPlane(-Math.PI));
-//      assertEquals(d,helix.getDistanceToZPlane(-Math.PI*2));
-//      assertTrue(Double.isNaN(helix.getDistanceToInfiniteCylinder(3)));
-//      assertEquals(d/2,helix.getDistanceToInfiniteCylinder(2),1e-14);
-//      assertEquals(1.4809609793861218,helix.getDistanceToInfiniteCylinder(1),1e-14);
-//      assertEquals(0,helix.getDistanceToInfiniteCylinder(0),1e-14);     
-//   }
+   public void testHelix2()
+   {
+      Hep3Vector origin = new BasicHep3Vector(0,0,0);
+      double radius = -1;
+      double phi = Math.PI/2;
+      double lambda = -Math.PI/4;
+      Helix helix = new Helix(origin,radius,phi,lambda);
+
+      assertEquals(origin, helix.getPointAtDistance(0));
+      double d = Math.PI*2*Math.sqrt(2);
+      assertEquals(new BasicHep3Vector(0,0,-Math.PI*2), helix.getPointAtDistance(d));
+      assertEquals(new BasicHep3Vector(-2,0,-Math.PI), helix.getPointAtDistance(d/2));
+      
+      assertEquals(d/2,helix.getDistanceToZPlane(-Math.PI));
+      assertEquals(d,helix.getDistanceToZPlane(-Math.PI*2));
+      assertTrue(Double.isNaN(helix.getDistanceToInfiniteCylinder(3)));
+      assertEquals(d/2,helix.getDistanceToInfiniteCylinder(2),1e-14);
+      assertEquals(1.4809609793861218,helix.getDistanceToInfiniteCylinder(1),1e-14);
+      assertEquals(0,helix.getDistanceToInfiniteCylinder(0),1e-14);     
+   }
 
    public void testHelix3() throws IOException
    {
@@ -283,16 +283,49 @@
        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); 
+           // momentum conservation
            assertEquals(tangentAtThisPiece_1.magnitude(), helix1.getTangentAtDistance((i+1)*.37).magnitude());
            assertEquals(tangentAtThisPiece_2.magnitude(), helix2.getTangentAtDistance(i*.37).magnitude());
+           // both positively and negatively charged tracks must be moving forward
            assertEquals(tangentAtThisPiece_1.z(), tangentAtThisPiece_2.z());
        }
    }
    
+   public void testCurvature() {
+       Hep3Vector origin = new BasicHep3Vector(3, 6, 9);
+       double radius = 1.5;
+       double phi = Math.PI/2;
+       double lambda = 0;
+       for (int iPhi=0; iPhi<50; ++iPhi) {
+           Helix helix1 = new Helix(origin, radius, iPhi*phi, lambda);
+           Helix helix2 = new Helix(origin, -radius, iPhi*phi, lambda);
+           Helix helix5 = new Helix(origin, radius, Math.PI-iPhi*phi, lambda);
+           Helix helix6 = new Helix(origin, -radius, Math.PI-iPhi*phi, lambda);
+           assertEquals(helix1.yCenter, helix6.yCenter, 1e-10);
+           assertEquals(helix1.xCenter, helix5.xCenter, 1e-10);
+           assertEquals(helix2.xCenter, helix6.xCenter, 1e-10);
+           assertEquals(helix2.yCenter, helix5.yCenter, 1e-10);
+       }
+       Helix helix1 = new Helix(origin, radius, phi, lambda);
+       Helix helix2 = new Helix(origin, -radius, phi, lambda);
+       
+       Hep3Vector h1 = helix1.getPointAtDistance(Math.PI/2*radius);
+       assertEquals(h1.x(), 4.5, 1e-14);
+       assertEquals(h1.y(), 7.5, 1e-14);
+       Hep3Vector h2 = helix2.getPointAtDistance(Math.PI/2*radius);
+       assertEquals(h2.x(), 1.5, 1e-14);
+       assertEquals(h2.y(), 7.5, 1e-14);
+       Hep3Vector h3 = helix1.getPointAtDistance(-Math.PI/2*radius);
+       assertEquals(h3.x(), 4.5, 1e-14);
+       assertEquals(h3.y(), 4.5, 1e-14);
+       Hep3Vector h4 = helix2.getPointAtDistance(-Math.PI/2*radius);
+       assertEquals(h4.x(), 1.5, 1e-14);
+       assertEquals(h4.y(), 4.5, 1e-14);
+   }
+   
    
    private void assertEquals(Hep3Vector v1, Hep3Vector v2)
    {
CVSspam 0.2.8