hps-java/src/main/java/org/lcsim/hps/recon/tracking
diff -u -r1.22 -r1.23
--- TrackUtils.java 25 Aug 2013 21:41:44 -0000 1.22
+++ TrackUtils.java 12 Sep 2013 17:57:54 -0000 1.23
@@ -6,10 +6,12 @@
import hep.physics.vec.Hep3Matrix;
import hep.physics.vec.Hep3Vector;
import hep.physics.vec.VecOp;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
import org.lcsim.detector.ITransform3D;
import org.lcsim.detector.solids.Box;
import org.lcsim.detector.solids.Point3D;
@@ -28,7 +30,7 @@
/**
*
* @author Omar Moreno <[log in to unmask]>
- * @version $Id: TrackUtils.java,v 1.22 2013/08/25 21:41:44 phansson Exp $
+ * @version $Id: TrackUtils.java,v 1.23 2013/09/12 17:57:54 phansson Exp $
* TODO: Switch to JLab coordinates
*/
@@ -287,8 +289,71 @@
}
+ /**
+ * @param helix input helix object
+ * @param origin of the plane to intercept
+ * @param normal of the plane to intercept
+ * @param eps criteria on the distance to the plane before stopping iteration
+ * @return position in space at the intercept of the plane
+ */
+ public static Hep3Vector getHelixPlanePositionIter(HelicalTrackFit helix, Hep3Vector origin, Hep3Vector normal, double eps) {
+ boolean debug = false;
+ if(debug) {
+ System.out.printf("--- getHelixPlanePositionIter ---\n");
+ System.out.printf("Target origin [%.10f %.10f %.10f] normal [%.10f %.10f %.10f]\n",origin.x(),origin.y(),origin.z(),normal.x(),normal.y(),normal.z());
+ System.out.printf("%.10f %.10f %.10f %.10f %.10f\n",helix.dca(),helix.z0(),helix.phi0(),helix.slope(),helix.R());
+ }
+ double x = origin.x();
+ double d = 9999.9;
+ double dx = 0.0;
+ int nIter = 0;
+ Hep3Vector pos = null;
+ while( Math.abs(d) > eps && nIter < 50) {
+ // Calculate position on helix at x
+ pos = getHelixPosAtX(helix, x + dx);
+ // Check if we are on the plane
+ d = VecOp.dot(VecOp.sub(pos, origin), normal);
+ dx += -1.0 * d / 2.0;
+ if(debug) System.out.printf("%d d %.10f pos [%.10f %.10f %.10f] dx %.10f\n", nIter, d, pos.x(),pos.y(),pos.z(), dx);
+ nIter += 1;
+ }
+ return pos;
+ }
/*
+ * Calculates the point on the helix at a given point along the x-axis
+ * The normal of the plane is in the same x-y plane as the circle.
+ *
+ * @param helix
+ * @param x point along x-axis
+ * @return point on helix at x-coordinate
+ *
+ */
+ private static Hep3Vector getHelixPosAtX(HelicalTrackFit helix, double x) {
+ //double C = (double)Math.round(helix.curvature()*1000000)/1000000;
+ //double R = 1.0/C;
+ double R = helix.R();
+ double dca = helix.dca();
+ double z0 = helix.z0();
+ double phi0 = helix.phi0();
+ double slope = helix.slope();
+ //System.out.printf("%.10f %.10f %.10f %.10f %.10f\n",dca,z0,phi0,slope,R);
+
+ double xc = (R - dca) * Math.sin(phi0);
+ double sinPhi = (xc - x)/R;
+ double phi_at_x = Math.asin(sinPhi);
+ double dphi_at_x = phi_at_x - phi0;
+ if (dphi_at_x > Math.PI) dphi_at_x -= 2.0 * Math.PI;
+ if (dphi_at_x < -Math.PI) dphi_at_x += 2.0 * Math.PI;
+ double s_at_x = -1.0 * dphi_at_x * R;
+ double y = dca * Math.cos(phi0) - R * Math.cos(phi0) + R * Math.cos(phi_at_x);
+ double z = z0 + s_at_x * slope;
+ BasicHep3Vector pos = new BasicHep3Vector(x,y,z);
+ //System.out.printf("pos %s xc %f phi_at_x %f dphi_at_x %f s_at_x %f\n", pos.toString(),xc,phi_at_x,dphi_at_x,s_at_x);
+ return pos;
+ }
+
+ /*
* Calculates the point on the helix in the x-y plane at the intercept with plane
* The normal of the plane is in the same x-y plane as the circle.
*