Print

Print


Commit in lcsim on MAIN
src/org/lcsim/util/swim/Helix.java+1-111.3 -> 1.4
                       /HelixSwimmer.java+8-21.3 -> 1.4
                       /Line.java+14-31.1 -> 1.2
                       /Trajectory.java+13-21.1 -> 1.2
test/org/lcsim/util/swim/LineTest.java+99added 1.1
                        /HelixSwimTest.java+32-61.1 -> 1.2
+167-24
1 added + 5 modified, total 6 files
Latest swim stuff

lcsim/src/org/lcsim/util/swim
Helix.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- Helix.java	20 Aug 2005 21:11:04 -0000	1.3
+++ Helix.java	20 Aug 2005 23:25:07 -0000	1.4
@@ -19,7 +19,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.3 2005/08/20 21:11:04 jstrube Exp $
+ * @version $Id: Helix.java,v 1.4 2005/08/20 23:25:07 tonyj Exp $
  */
 public class Helix implements Trajectory
 {
@@ -55,21 +55,11 @@
       return new BasicHep3Vector(x,y,z);
    }
 
-   /** 
-    * Calculate the distance along the helix to reach a given Z plane.
-    * Note distance may be negative.
-    *
-    */
    public double getDistanceToZPlane(double z)
    {
       return (z - origin.z())/sinLambda;      
    }
    
-   /**
-    * Calculates the distance at which the helix first reaches radius R.
-    * Returns Double.NaN if the helix does not intercept the cylinder.
-    */
-   
    public double getDistanceToInfiniteCylinder(double r)
    {
       double darg  = r*r/(2.*radius*radiusOfCenter) - radiusOfCenter/(2.*radius) - radius/(2.*radiusOfCenter);

lcsim/src/org/lcsim/util/swim
HelixSwimmer.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- HelixSwimmer.java	20 Aug 2005 19:16:20 -0000	1.3
+++ HelixSwimmer.java	20 Aug 2005 23:25:07 -0000	1.4
@@ -12,7 +12,7 @@
  * A simple helix smimmer for use in org.lcsim. Uses standard lcsim units
  * Tesla, mm, GeV. This swimmer works for charged and neutral tracks.
  * @author tonyj
- * @version $Id: HelixSwimmer.java,v 1.3 2005/08/20 19:16:20 tonyj Exp $
+ * @version $Id: HelixSwimmer.java,v 1.4 2005/08/20 23:25:07 tonyj Exp $
  */
 public class HelixSwimmer
 {
@@ -51,7 +51,6 @@
       {
          trajectory = new Line(r0, phi, lambda);
       }
-      
    }
    public void setTrack(Track t)
    {
@@ -70,4 +69,11 @@
    {
       return trajectory.getPointAtDistance(alpha);
    }
+   public double getDistanceToCylinder(double r,double z)
+   {
+      double x1 = trajectory.getDistanceToInfiniteCylinder(r);
+      double x2 = trajectory.getDistanceToZPlane(z);
+      if (x2<0) x2 = trajectory.getDistanceToZPlane(-z);
+      return Double.isNaN(x1) ? x2 : Math.min(x1,x2);
+   }
 }
\ No newline at end of file

lcsim/src/org/lcsim/util/swim
Line.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- Line.java	20 Aug 2005 19:16:20 -0000	1.1
+++ Line.java	20 Aug 2005 23:25:07 -0000	1.2
@@ -6,7 +6,7 @@
 /**
  * A straight line
  * @author tonyj
- * @version $Id: Line.java,v 1.1 2005/08/20 19:16:20 tonyj Exp $
+ * @version $Id: Line.java,v 1.2 2005/08/20 23:25:07 tonyj Exp $
  */
 public class Line implements Trajectory
 {
@@ -29,8 +29,19 @@
    {
       double z = origin.z() + alpha*sinLambda;
       double dr = alpha*cosLambda;
-      double x = origin.x() + dr*sinPhi;
-      double y = origin.y() + dr*cosPhi;
+      double x = origin.x() + dr*cosPhi;
+      double y = origin.y() + dr*sinPhi;
       return new BasicHep3Vector(x,y,z);
    }
+
+   public double getDistanceToInfiniteCylinder(double r)
+   {
+      // Fixme: Implement properly
+      return Double.NaN;
+   }
+
+   public double getDistanceToZPlane(double z)
+   {
+      return (z-origin.z())/sinLambda;
+   }
 }

lcsim/src/org/lcsim/util/swim
Trajectory.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- Trajectory.java	20 Aug 2005 19:16:20 -0000	1.1
+++ Trajectory.java	20 Aug 2005 23:25:07 -0000	1.2
@@ -5,12 +5,23 @@
 /**
  * A particle trajectory (either a Helix or a Line)
  * @author tonyj
- * @version $Id: Trajectory.java,v 1.1 2005/08/20 19:16:20 tonyj Exp $
+ * @version $Id: Trajectory.java,v 1.2 2005/08/20 23:25:07 tonyj Exp $
  */
 public interface Trajectory
 {
    /**
-    * Gets a point after traveling distance alpha from the origin along the helix
+    * Gets a point after traveling distance alpha from the origin along the trajectory
     */
    Hep3Vector getPointAtDistance(double alpha);
+  /**
+    * Calculates the distance at which the trajectory first reaches radius R.
+    * Returns Double.NaN if the trajectory does not intercept the cylinder.
+    */
+   
+   public double getDistanceToInfiniteCylinder(double r);
+  /** 
+    * Calculate the distance along the trajectory to reach a given Z plane.
+    * Note distance may be negative.
+    */
+   public double getDistanceToZPlane(double z);
 }

lcsim/test/org/lcsim/util/swim
LineTest.java added at 1.1
diff -N LineTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ LineTest.java	20 Aug 2005 23:25:07 -0000	1.1
@@ -0,0 +1,99 @@
+package org.lcsim.util.swim;
+
+import hep.aida.ICloud2D;
+import junit.framework.*;
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import hep.physics.vec.VecOp;
+import java.io.IOException;
+import org.lcsim.util.aida.AIDA;
+
+/**
+ *
+ * @author tonyj
+ * @version $Id: LineTest.java,v 1.1 2005/08/20 23:25:07 tonyj Exp $
+ */
+public class LineTest extends TestCase
+{
+   
+   public LineTest(String testName)
+   {
+      super(testName);
+   }
+
+   public static Test suite()
+   {
+      return new TestSuite(LineTest.class);
+   }
+   
+   public void testLine()
+   {
+      Hep3Vector origin = new BasicHep3Vector(1,2,3);
+      double phi = 0;
+      double lambda = 0;
+      Line line = new Line(origin,phi,lambda);
+
+      assertEquals(origin, line.getPointAtDistance(0));
+      Hep3Vector point = line.getPointAtDistance(10);
+      assertEquals(point.x(), origin.x()+10, 1e-14);
+      assertEquals(point.y(), origin.y(), 1e-14);
+      assertEquals(point.z(), origin.z(), 1e-14);     
+      assertEquals(10,VecOp.sub(origin,point).magnitude(),1e-14);
+   }
+   public void testLine2()
+   {
+      Hep3Vector origin = new BasicHep3Vector(1,2,3);
+      double phi = Math.PI/2;
+      double lambda = Math.PI/4;
+      Line line = new Line(origin,phi,lambda);
+
+      assertEquals(origin, line.getPointAtDistance(0));
+      Hep3Vector point = line.getPointAtDistance(10);
+      assertEquals(10,VecOp.sub(origin,point).magnitude(),1e-14);
+   }
+   public void testIntercept()
+   {
+      Hep3Vector origin = new BasicHep3Vector(0,0,0);
+      double phi = Math.PI/4;
+      double lambda = Math.atan2(1,Math.sqrt(2));
+      Line line = new Line(origin,phi,lambda);
+      
+      assertEquals(0,line.getDistanceToZPlane(0),1e-14);
+      assertEquals(Math.sqrt(3),line.getDistanceToZPlane(1),1e-14);
+      //Fixme: Implement properly
+      //assertEquals(Math.sqrt(3),line.getDistanceToInfiniteCylinder(1));
+   }
+
+   public void testLine3() throws IOException
+   {
+      Hep3Vector origin = new BasicHep3Vector(0,0,0);
+      double phi = Math.PI/4;
+      double lambda = Math.atan2(1,Math.sqrt(2));
+      Line line = new Line(origin,phi,lambda);
+
+      double d = Math.sqrt(3);
+      
+      AIDA aida = AIDA.defaultInstance();
+      ICloud2D xy = aida.cloud2D("xy");
+      ICloud2D rz = aida.cloud2D("rz");
+      for (int i=0; i<100; i++)
+      {
+         double alpha = i*d/100;
+         Hep3Vector point  = line.getPointAtDistance(alpha);
+         xy.fill(point.x(),point.y());
+         double r = Math.sqrt(point.x()*point.x()+point.y()*point.y());
+         rz.fill(r,point.z());
+      }
+//      assertEquals(1,xy.meanX(),1e-14);
+//      assertEquals(0,xy.meanY(),1e-14);
+//      assertEquals(Math.sqrt(2)/2,xy.rmsX(),1e-14);
+//      assertEquals(Math.sqrt(2)/2,xy.rmsY(),1e-14);
+      aida.saveAs("line.aida");    
+   }   
+   private void assertEquals(Hep3Vector v1, Hep3Vector v2)
+   {
+      assertEquals(v1.x(),v2.x(), 1e-14);
+      assertEquals(v1.y(),v2.y(), 1e-14);
+      assertEquals(v1.z(),v2.z(), 1e-14);
+   }
+}

lcsim/test/org/lcsim/util/swim
HelixSwimTest.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- HelixSwimTest.java	15 Aug 2005 23:15:35 -0000	1.1
+++ HelixSwimTest.java	20 Aug 2005 23:25:07 -0000	1.2
@@ -1,7 +1,9 @@
 package org.lcsim.util.swim;
-
+import hep.aida.ICloud2D;
+import java.io.IOException;
 import junit.framework.*;
 import org.lcsim.spacegeom.SpacePoint;
+import org.lcsim.util.aida.AIDA;
 
 /**
  *
@@ -41,10 +43,34 @@
       SpacePoint point  = swim.getPointAtLength(alpha);
       assertEquals(SpacePoint.distance(origin,point),alpha, 1e-14);
       
-//      alpha = Math.sqrt(3);
-//      swim.setTrack(new double[]{1,1,1},origin.getCartesianArray(), 1);
-//      point  = swim.getPointAtLength(alpha);
-//      System.out.println(point);
+      alpha = Math.sqrt(3);
+      point  = swim.getPointAtLength(alpha);  
+      System.out.println(point);
+      
+      double radius = swim.getRc();
+      System.out.println("radius="+radius);
+      alpha = Math.PI * 2 * radius;
+      //swim.setTrack(new double[]{1,1,1},origin.getCartesianArray(), 1);
+      point  = swim.getPointAtLength(alpha);
+      System.out.println(point);   
    }
-
+   public void test3() throws IOException
+   {
+      AIDA aida = AIDA.defaultInstance();
+      HelixSwim swim = new HelixSwim(5);
+      SpacePoint origin = new SpacePoint();
+      swim.setTrack(new double[]{1,1,1},origin.getCartesianArray(), 1);
+      double radius = swim.getRc();
+      ICloud2D xy = aida.cloud2D("xy");
+      ICloud2D rz = aida.cloud2D("rz");
+      for (double alpha = 0 ; alpha < Math.PI * 2 * radius; alpha += 10)
+      {
+         SpacePoint point  = swim.getPointAtLength(alpha);
+         xy.fill(point.x(),point.y());
+         rz.fill(point.rxy(),point.z());
+      }
+      aida.saveAs("c:\\helix.aida");
+   }
+   
+   
 }
CVSspam 0.2.8