hps-java/src/main/java/org/lcsim/hps/users/phansson
diff -u -r1.4 -r1.5
--- AlignmentUtils.java 31 Aug 2012 02:49:46 -0000 1.4
+++ AlignmentUtils.java 3 Sep 2012 00:32:18 -0000 1.5
@@ -71,6 +71,28 @@
+ public double dphi_dx(double xint,double xr, double yr, double d0, double phi0, double R) {
+ double arg1 = Math.sin(phi0) - (xint-x0(xr,d0,phi0))/R;
+ double arg2 = Math.cos(phi0) + (y(xint,xr,yr,d0,phi0,R)-y0(yr,d0,phi0))/R;
+ return (-1/R)*arg2/(arg2*arg2+arg1*arg1);
+ }
+
+ public double dphi_dy(double xint,double xr, double yr, double d0, double phi0, double R) {
+ System.out.println("dphi_dy:");
+ double arg1 = Math.sin(phi0) - (xint-x0(xr,d0,phi0))/R;
+ double arg2 = Math.cos(phi0) + (y(xint,xr,yr,d0,phi0,R)-y0(yr,d0,phi0))/R;
+ System.out.println("dphi_dy: arg1=" + arg1 + " arg2="+arg2 + " R =" + R );
+ System.out.println("dphi_dy ===> " + (-1/R)*arg1/(arg2*arg2+arg1*arg1));
+ return (-1/R)*arg1/(arg2*arg2+arg1*arg1);
+ }
+ public double dphi_dz(double slope, double R) {
+ return -1/(R*slope);
+ }
+
+
+
+
+
//-----------------------------------
// Derivatives for translation
@@ -79,47 +101,36 @@
return 1;
}
- public double dy_dx(double xint, double xr, double yr ,double d0, double phi0, double R) {
- return -1*sign(R)*(xint-xc(xr,d0,phi0,R))/(y(xint,xr,yr,d0,phi0,R) - yc(yr,d0,phi0,R));
+ public double dy_dx(double xint, double xr, double yr ,double d0, double phi0, double R) {
+ return -1*sign(R)*R*this.phi(xint, xr, yr, d0, phi0, R)*this.dphi_dx(xint, xr, yr, d0, phi0, R);
}
public double dz_dx(double xint, double xr,double yr,double d0, double phi0, double slope, double R) {
- return -slope*(y(xint,xr,yr,d0,phi0,R) - yc(yr,d0,phi0,R))/R;
+ return -slope*R*this.dphi_dx(xint, xr, yr, d0, phi0, R);
}
public double dx_dy(double xint, double xr, double yr ,double d0, double phi0, double R) {
- double d = -sign(R)*(y(xint,xr,yr,d0,phi0,R) - yc(yr,d0,phi0,R))/(xint-xc(xr,d0,phi0,R));
- System.out.println("dx_dy: y=" + y(xint,xr,yr,d0,phi0,R) + ", yc=" + yc(yr,d0,phi0,R));
- System.out.println("dx_dy: xint=" + xint + ", xc=" + xc(xr,d0,phi0,R));
- System.out.println("dx_dy: sign(R)=" + sign(R));
- System.out.println(" ===> " + d);
- return d;
+ System.out.println("dx_dy: xint=" + xint + " phi0="+phi0+" R="+R );
+ System.out.println("dx_dy: cos(phi)="+Math.cos(this.phi(xint, xr, yr, d0, phi0, R)) + " dphi_dy="+this.dphi_dy(xint, xr, yr, d0, phi0, R));
+ System.out.println("dx_dy: ====> R*cos*dphi_dy = "+ sign(R)*R*Math.cos(this.phi(xint, xr, yr, d0, phi0, R))*this.dphi_dy(xint, xr, yr, d0, phi0, R));
+ return sign(R)*R*Math.cos(this.phi(xint, xr, yr, d0, phi0, R))*this.dphi_dy(xint, xr, yr, d0, phi0, R);
}
-
+
public double dy_dy() {
return 1;
}
public double dz_dy(double xint, double xr ,double d0, double phi0, double slope, double R) {
- return slope*(xint-xc(xr,d0,phi0,R))/R;
+ return -R*slope*this.dphi_dy(xint, xr, xr, d0, phi0, R);
}
public double dx_dz(double xint, double xr, double yr ,double d0, double phi0, double slope, double R) {
- double A = Math.atan2(x0(xr,d0,phi0)-xc(xr,d0,phi0,R),y0(yr,d0,phi0)-yc(yr,d0,phi0,R));
- double dphi = tmpdphi(xint,xr,yr,d0,phi0,R);
- return -1/(R*slope)*(y(xint,xr,yr,d0,phi0,R) - yc(yr,d0,phi0,R))*(1 + Math.pow(Math.tan(dphi+A),2));
+ return sign(R)*R*Math.cos(this.phi(xint, xr, yr, d0, phi0, R))*this.dphi_dz(slope, R);
}
- public double dy_dz(double xint, double xr, double yr ,double d0, double phi0, double slope, double R) {
- double A = phi1(xr,yr,d0,phi0,R);
- double dphi = tmpdphi(xint,xr,yr,d0,phi0,R);
- double d = 1/(R*slope)*(xint-xc(xr,d0,phi0,R))*(1 + 1/(Math.pow(Math.tan(dphi+A),2)));
- System.out.println("dy_dz: y0=" + y0(yr,d0,phi0) + ", yc=" + yc(yr,d0,phi0,R));
- System.out.println("dy_dz: x0=" + x0(xr,d0,phi0) + ", xc=" + xc(xr,d0,phi0,R));
- System.out.println("dy_dz: dphi="+dphi+", A="+A+", tan(dphi+A)="+Math.tan(dphi+A));
- System.out.print(" ===> " + d);
- return d;
+ public double dy_dz(double xint, double xr, double yr ,double d0, double phi0, double slope, double R) {
+ return -sign(R)*R*Math.sin(this.phi(xint, xr, yr, d0, phi0, R))*this.dphi_dz(slope, R);
}
public double dz_dz() {
@@ -284,9 +295,28 @@
//Generic point y on circle/helix
public double y(double x, double xr, double yr, double d0, double phi0, double R) {
+ //double phi_angle = phi(x, xr, yr, d0, phi0, R);
+ //double value = yc(yr,d0,phi0,R) + R*Math.cos(phi);
+ double value = yolddangerous(x, xr, yr, d0, phi0, R);
+ /*
+ double ydanger = yolddangerous(x, xr, yr, d0, phi0, R);
+ if(value!=ydanger) {
+ System.out.println("ERROR ydanger " + ydanger + " is different than good y " + value +" !!");
+ System.out.println("xint " + x + " d0 " + d0 + " phi0 " + phi0 + " R " + R);
+ System.out.println("R*Math.cos(phi0)=" + R*Math.cos(phi0) + " sign(R)*Math.sqrt( R*R - Math.pow(x - xc(xr,d0,phi0,R),2) )=" + sign(R)*Math.sqrt( R*R - Math.pow(x - xc(xr,d0,phi0,R),2) ) );
+ System.out.println("Math.pow(x - xc(xr,d0,phi0,R),2)=" + Math.pow(x - xc(xr,d0,phi0,R),2) + " ");
+ System.exit(1);
+ }
+
+ */
+ return value;
+ }
+
+ //Generic point y on circle/helix
+ public double yolddangerous(double x, double xr, double yr, double d0, double phi0, double R) {
return yc(yr,d0,phi0,R) + sign(R)*deltaxc(x,xr,d0,phi0,R);
}
-
+
//x-coordiante of center of circle/helix
double xc(double xr,double d0, double phi0, double R) {
return xr + (R-d0)*Math.sin(phi0);
@@ -383,6 +413,51 @@
return term1 + term2;
}
+
+ public double phi(double xint,double xr, double yr, double d0, double phi0, double R) {
+ double arg1 = Math.sin(phi0) - (xint-x0(xr,d0,phi0))/R;
+ double arg2 = Math.cos(phi0) + (y(xint,xr,yr,d0,phi0,R)-y0(yr,d0,phi0))/R;
+ double p = Math.atan2( arg1,arg2);
+
+// double arg1_2 = R*Math.sin(phi0) + (x0(xr,d0,phi0)-xint);
+// double arg2_2 = R*Math.cos(phi0) + (y(xint,xr,yr,d0,phi0,R)-y0(yr,d0,phi0));
+// double p_2 = Math.atan2( arg1,arg2);
+//
+// double arg1test = -sign(R )*Math.sin(phi0)+(x0(xr,d0,phi0)-xint)/R;
+// double arg2test = sign(R )*Math.cos(phi0)+(y(xint,xr,yr,d0,phi0,R)-y0(yr,d0,phi0))/R;
+// double phitest=Math.atan2(arg1test, arg2test);
+
+// if(p!=p_2) {
+// System.out.println("ERROR phi " + p + " != p_2" + p_2 + "!!");
+// System.out.printf("arg1 =%f arg2=%f\n",arg1,arg2);
+// System.out.printf("arg1_2=%f arg_2=%f\n",arg1_2,arg2_2);
+// System.exit(1);
+// }
+
+ /*
+ if(p!=phitest) {
+ System.out.println("ERROR phi " + p + " != phitest " + phitest + "!!");
+ System.out.printf("arg1 =%f arg2=%f\n",arg1,arg2);
+ System.out.printf("arg1test=%f arg2test=%f\n",arg1test,arg2test);
+ System.out.println("arg1: phi0=" + phi0 + " sin(phi0)=" + Math.sin(phi0) + " -(xint-x0(xr,d0,phi0))/R="+ - (xint-x0(xr,d0,phi0))/R);
+ System.out.println("arg2: phi0=" + phi0 + " os(phi0)=" + Math.cos(phi0) + " + (y(xint,xr,yr,d0,phi0,R)-y0(yr,d0,phi0))/R = " + (y(xint,xr,yr,d0,phi0,R)-y0(yr,d0,phi0))/R);
+ System.out.println("argtest1: -sign(R )*Math.sin(phi0) = " +-sign(R )*Math.sin(phi0)+ " + (x0(xr,d0,phi0)-xint)/R = " + (x0(xr,d0,phi0)-xint)/R );
+ System.out.println("argtest2: sign(R )*Math.cos(phi0) = " + sign(R )*Math.cos(phi0) + " + (y(xint,xr,yr,d0,phi0,R)-y0(yr,d0,phi0))/R = " + (y(xint,xr,yr,d0,phi0,R)-y0(yr,d0,phi0))/R);
+
+
+ System.out.println(" phi " + p + " != p_2" + p_2 + "!!");
+ System.out.printf("arg1 =%f arg2=%f\n",arg1,arg2);
+ System.out.printf("arg1_2=%f arg_2=%f\n",arg1_2,arg2_2);
+
+
+ System.exit(1);
+ }
+ */
+
+
+ return p;
+ }
+
// derivative of delta phi between point on helix (x,y) and point of closest approach (x0,y0)
public double dtmpdphi_dR(double x, double xr, double yr, double d0, double phi0, double R) {
// this calculation has been large "simplified" from the original by using x, x0, xc, y, y0, yc