lcsim/test/org/lcsim/contrib/JanStrube/tracking
diff -N HelixSwimmerTrackConsistencyTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ HelixSwimmerTrackConsistencyTest.java 18 Jul 2006 06:40:10 -0000 1.1
@@ -0,0 +1,116 @@
+/**
+ * @version $Id: HelixSwimmerTrackConsistencyTest.java,v 1.1 2006/07/18 06:40:10 jstrube Exp $
+ */
+package org.lcsim.contrib.JanStrube.tracking;
+
+import java.util.Random;
+
+import org.lcsim.contrib.JanStrube.tracking.HelixSwimmer;
+import org.lcsim.contrib.JanStrube.tracking.NewFastMCTrackFactory;
+import org.lcsim.contrib.JanStrube.tracking.Track;
+import org.lcsim.spacegeom.CartesianPoint;
+import org.lcsim.spacegeom.SpacePoint;
+
+import static java.lang.Math.atan2;
+import junit.framework.TestCase;
+
+/**
+ * @author jstrube
+ *
+ */
+public class HelixSwimmerTrackConsistencyTest extends TestCase {
+
+ private HelixSwimmer swimmerRaw;
+ private HelixSwimmer swimmerTrack;
+ private NewFastMCTrackFactory factory;
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ swimmerRaw = new HelixSwimmer(5.);
+ factory = new NewFastMCTrackFactory("sidaug05", 5., true);
+ swimmerTrack = new HelixSwimmer(5.);
+ }
+
+ public void testHelix_TrackFactoryConsistency1() {
+ SpacePoint momentum = new CartesianPoint(-2, 2, 4);
+ SpacePoint location = new CartesianPoint(1, 2, 3);
+ int charge = -1;
+ swimmerRaw.setTrack(momentum, location, charge);
+ // get a Track in a way that no swimming is necessary for the reference point
+ // turn off smearing
+ Track t = factory.getTrack(momentum, location, location, charge, new Random(), false);
+ swimmerTrack.setTrack(t);
+ // swim to pocas of several points and compare position and momentum at these points
+ double alpha = swimmerRaw.getTrackLengthToPoint(location);
+ double beta = swimmerTrack.getTrackLengthToPoint(location);
+ assertEquals(swimmerRaw.getPointAtDistance(alpha), swimmerTrack.getPointAtDistance(beta), 4e-4);
+ assertEquals(swimmerRaw.getMomentumAtDistance(alpha), swimmerTrack.getMomentumAtDistance(beta), 1e-5);
+
+ // use the momentum components as another random point to swim to
+ alpha = swimmerRaw.getTrackLengthToPoint(momentum);
+ beta = swimmerTrack.getTrackLengthToPoint(momentum);
+ // TODO there are obviously some floating point precision issues, probably related to the trigonometric functions.
+ // Investigation can be put off to a later date
+ assertEquals(swimmerRaw.getPointAtDistance(alpha), swimmerTrack.getPointAtDistance(beta), 4e-4);
+ assertEquals(swimmerRaw.getMomentumAtDistance(alpha), swimmerTrack.getMomentumAtDistance(beta), 4e-4);
+ }
+
+ public void testHelix_TrackFactoryConsistency2() {
+ SpacePoint momentum = new CartesianPoint(-2, 2, 4);
+ SpacePoint location = new CartesianPoint(1, 2, 3);
+ int charge = -1;
+ swimmerRaw.setTrack(momentum, location, charge);
+ SpacePoint referencePoint = new SpacePoint();
+ // reference Point is (0, 0, 0)
+ Track t = factory.getTrack(momentum, location, referencePoint, charge, new Random(), false);
+ swimmerTrack.setTrack(t);
+
+ double alpha = swimmerRaw.getTrackLengthToPoint(referencePoint);
+ double beta = swimmerTrack.getTrackLengthToPoint(referencePoint);
+ // The track is already at the reference point
+ assertEquals(beta, 0, 1e-10);
+ // The distance that has been swum is equal and opposite
+ assertEquals(alpha, -1 * swimmerTrack.getTrackLengthToPoint(location), 4e-4);
+ // It should be possible to calculate the angle
+ // phi = phi0 - omega*alpha*cosLambda
+ double phi = atan2(momentum.y(), momentum.x());
+ double phi_0 = t.getParameter(Track.ParameterName.phi0);
+ double omega = t.getParameter(Track.ParameterName.omega);
+ System.out.printf("phi: %f\nphi0: %f\nomega: %f\nalpha: %f\n", phi, phi_0, omega, alpha);
+// assertEquals(phi, phi_0 - omega*alpha);
+ // The Track and the helix should be the same, except for being offset by alpha.
+ System.out.println("Raw:\n" + (Helix)swimmerRaw.getTrajectory());
+ System.out.println("Track:\n" + (Helix)swimmerTrack.getTrajectory());
+
+ System.out.println(swimmerRaw.getPointAtDistance(alpha));
+ System.out.println(swimmerTrack.getPointAtDistance(-alpha));
+ System.out.printf("Pt: %f\n", t.getPt());
+ for (Track.ParameterName n : Track.ParameterName.values()) {
+ System.out.printf("%s: %f\n", n.name(), t.getParameter(n));
+ }
+ // The points at these two locations should be the same, too.
+// assertEquals(swimmerRaw.getPointAtDistance(alpha), swimmerTrack.getPointAtDistance(0), 1e-4);
+
+
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ void assertEquals(SpacePoint a, SpacePoint b, double precision) {
+ assertEquals(a.x(), b.x(), precision);
+ assertEquals(a.y(), b.y(), precision);
+ assertEquals(a.z(), b.z(), precision);
+ }
+
+ void assertEquals(SpacePoint a, SpacePoint b) {
+ assertEquals(a, b, 1e-10);
+ }
+
+}
lcsim/test/org/lcsim/contrib/JanStrube/tracking
diff -N NewTrackTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ NewTrackTest.java 18 Jul 2006 06:40:10 -0000 1.1
@@ -0,0 +1,126 @@
+/**
+ * @version $Id: NewTrackTest.java,v 1.1 2006/07/18 06:40:10 jstrube Exp $
+ */
+package org.lcsim.contrib.JanStrube.tracking;
+
+import java.util.Random;
+
+import org.lcsim.spacegeom.CartesianPoint;
+import org.lcsim.spacegeom.SpacePoint;
+
+import junit.framework.TestCase;
+
+/**
+ * @author jstrube
+ *
+ */
+public class NewTrackTest extends TestCase {
+
+ private NewFastMCTrackFactory factory;
+ private Track t;
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ factory = new NewFastMCTrackFactory("sidaug05", 5., true);
+ SpacePoint momentum = new CartesianPoint(1, 1, 1);
+ SpacePoint location = new CartesianPoint(1, 2, 3);
+ t = factory.getTrack(momentum, location, 1);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link org.lcsim.contrib.JanStrube.tracking.NewTrack#NewTrack(org.lcsim.spacegeom.SpacePoint, org.lcsim.contrib.JanStrube.tracking.EMap, Jama.Matrix, int)}.
+ */
+ public void testNewTrack() {
+
+ }
+
+ /**
+ * Test method for {@link org.lcsim.contrib.JanStrube.tracking.NewTrack#getPt()}.
+ * Testing equality of pt for different initializations of the track.
+ * Notable is that different values of the charge are tested.
+ */
+ public void testGetPt() {
+ SpacePoint location = new CartesianPoint(0, 0, 0);
+ SpacePoint momentum = new CartesianPoint(1, 1, 1);
+ SpacePoint referencePoint = new SpacePoint();
+ int charge = 1;
+ // don't smear tracks
+ t = factory.getTrack(momentum, location, referencePoint, charge, new Random(), false);
+ assertEquals(t.getPt(), momentum.rxy(), 1e-10);
+
+ location = new CartesianPoint(1, 2, 3);
+ momentum = new CartesianPoint(-1, -1, -1);
+ charge = 2;
+ // don't smear tracks
+ t = factory.getTrack(momentum, location, referencePoint, charge, new Random(), false);
+ assertEquals(t.getPt(), momentum.rxy(), 1e-10);
+
+ location = new CartesianPoint(-1, -2, -3);
+ momentum = new CartesianPoint(-1, -1, -1);
+ charge = -1;
+ // don't smear tracks
+ t = factory.getTrack(momentum, location, referencePoint, charge, new Random(), false);
+ assertEquals(t.getPt(), momentum.rxy(), 1e-10);
+
+ location = new CartesianPoint(1, 2, 3);
+ momentum = new CartesianPoint(-2, -1, 1);
+ charge = -2;
+ // don't smear tracks
+ t = factory.getTrack(momentum, location, referencePoint, charge, new Random(), false);
+ assertEquals(t.getPt(), momentum.rxy(), 1e-10);
+ }
+
+ /**
+ * Test method for {@link org.lcsim.contrib.JanStrube.tracking.NewTrack#getCharge()}.
+ */
+ public void testGetCharge() {
+ SpacePoint location = new CartesianPoint(0, 0, 0);
+ SpacePoint momentum = new CartesianPoint(1, 1, 1);
+ t = factory.getTrack(momentum, location, -2);
+ assertEquals(t.getCharge(), -2);
+ t = factory.getTrack(momentum, location, -1);
+ assertEquals(t.getCharge(), -1);
+ t = factory.getTrack(momentum, location, 1);
+ assertEquals(t.getCharge(), 1);
+ t = factory.getTrack(momentum, location, 2);
+ assertEquals(t.getCharge(), 2);
+ }
+
+ /**
+ * Test method for {@link org.lcsim.contrib.JanStrube.tracking.NewTrack#getReferencePoint()}.
+ */
+ public void testGetReferencePoint() {
+ SpacePoint location = new CartesianPoint(1, 2, 3);
+ SpacePoint momentum = new CartesianPoint(1, 1, 1);
+ SpacePoint referencePoint = new CartesianPoint(0, 0, 0);
+ t = factory.getTrack(momentum, location, referencePoint, -2);
+ assertEquals(t.getReferencePoint(), referencePoint);
+
+ referencePoint = new CartesianPoint(1, 2, 3);
+ t = factory.getTrack(momentum, location, referencePoint, -2);
+ assertEquals(t.getReferencePoint(), referencePoint);
+
+ referencePoint = new CartesianPoint(-2, -3, -4);
+ t = factory.getTrack(momentum, location,referencePoint, -2);
+ assertEquals(t.getReferencePoint(), referencePoint);
+
+ referencePoint = new CartesianPoint(1, 0, 7);
+ t = factory.getTrack(momentum, location, referencePoint, -2);
+ assertEquals(t.getReferencePoint(), referencePoint);
+ }
+
+ void assertEquals(SpacePoint a, SpacePoint b) {
+ assertEquals(a.x(), b.x(), 1e-10);
+ assertEquals(a.y(), b.y(), 1e-10);
+ assertEquals(a.z(), b.z(), 1e-10);
+ }
+}