Commit in hps-java/src/main/java/org/lcsim/hps/users/phansson on MAIN | |||
AlignmentUtils.java | +156 | -137 | 1.6 -> 1.7 |
Updated local derivatives.
diff -u -r1.6 -r1.7 --- AlignmentUtils.java 4 Sep 2012 03:01:12 -0000 1.6 +++ AlignmentUtils.java 28 Sep 2012 22:08:39 -0000 1.7 @@ -16,10 +16,15 @@
public class AlignmentUtils {
+ public AlignmentUtils() { + _debug = false; + }
public AlignmentUtils(boolean debug) { _debug = debug; }
-
+ public void setDebug(boolean debug) { + _debug = debug; + }
public BasicMatrix calculateLocalHelixDerivatives(HelicalTrackFit trk, HelicalTrackStrip strip, double smax, int _nlc) { // Calculate the derivative w.r.t. to the track parameters (in order/index):
@@ -46,47 +51,156 @@
BasicMatrix dfdq = new BasicMatrix(3,5); //3-dim,ntrackparams
- dfdq.setElement(0, 0, dx_dd0(xint,xr,d0,phi0,R)); - dfdq.setElement(0, 1, dx_dz0()); - dfdq.setElement(0, 2, dx_dslope()); - dfdq.setElement(0, 3, dx_dphi0(xint,xr,yr,d0,phi0,R)); - dfdq.setElement(0, 4, dx_dR(xint,xr,yr,d0,phi0,R,phi)); - - - dfdq.setElement(1, 0, dy_dd0(xint,xr,d0,phi0,R)); - dfdq.setElement(1, 1, dy_dz0()); - dfdq.setElement(1, 2, dy_dslope()); - dfdq.setElement(1, 3, dy_dphi0(xint,xr,d0,phi0,R)); - dfdq.setElement(1, 4, dy_dR(xint,xr,d0,phi0,R)); - - - dfdq.setElement(2, 0, dz_dd0(xint,xr,yr,d0,phi0,slope,R,phi)); - dfdq.setElement(2, 1, dz_dz0()); - dfdq.setElement(2, 2, dz_dslope(xint,xr,yr,d0,phi0,slope,R,phi)); - dfdq.setElement(2, 3, dz_ddphi(xint,xr,yr,d0,phi0,slope,R,phi)); - dfdq.setElement(2, 4, dz_dR(xint,xr,yr,d0,phi0,slope,R,phi));
+ dfdq.setElement(0, 0, this.dx_dd0(xint, d0, phi0, R, phi)); + dfdq.setElement(0, 1, this.dx_dz0(R, phi)); + dfdq.setElement(0, 2, this.dx_dslope(R, phi)); + dfdq.setElement(0, 3, this.dx_dphi0(xint, d0, phi0, R, phi)); + dfdq.setElement(0, 4, this.dx_dR(xint, xr, yr, d0, phi0, R, phi)); + + + dfdq.setElement(1, 0, this.dy_dd0(xint, d0, phi0, R, phi)); + dfdq.setElement(1, 1, this.dy_dz0(R, phi)); + dfdq.setElement(1, 2, this.dy_dslope(R, phi)); + dfdq.setElement(1, 3, this.dy_dphi0(xint, d0, phi0, R, phi)); + dfdq.setElement(1, 4, this.dy_dR(xint, d0, phi0, R, phi)); + + + dfdq.setElement(2, 0, this.dz_dd0(xint, d0, phi0, slope, R)); + dfdq.setElement(2, 1, this.dz_dz0()); + dfdq.setElement(2, 2, this.dz_dslope(phi0, R, phi)); + dfdq.setElement(2, 3, this.dz_ddphi0(s, d0, phi0, slope, R)); + dfdq.setElement(2, 4, this.dz_dR(xint, d0, phi0, slope, R, phi));
return dfdq; }
+ + + + + + + //----------------------------------- + // Local derivatives of f in the x-direction + + + public double dx_dd0(double x, double d0, double phi0, double R, double phi) { + return -Math.sin(phi0) - R * Math.cos(phi)*dphi_dd0(x,d0,phi0,R); + } + public double dx_dz0(double R, double phi) { + return -R*Math.cos(phi)*dphi_dz0(); + } + public double dx_dslope(double R, double phi) { + return R*Math.cos(phi)*dphi_dslope(); + } + public double dx_dphi0(double x, double d0, double phi0, double R, double phi) { + return (R-d0)*Math.cos(phi0) - R*Math.cos(phi)*dphi_dphi0(x,d0,phi0,R); + } + public double dx_dR(double x, double xr, double yr, double d0, double phi0, double R, double phi) { + return Math.sin(phi0) - R*Math.cos(phi)*dphi_dR(x,d0,phi0,R); + } + + //----------------------------------- + + //----------------------------------- + // Local derivatives of f in the y-direction + + public double dy_dd0(double x, double d0, double phi0, double R, double phi) { + return Math.cos(phi0) - R*Math.sin(phi)*dphi_dd0(x, d0, phi0, R); + } + public double dy_dz0(double R, double phi) { + return -R*Math.sin(phi)*this.dphi_dz0(); + } + public double dy_dslope(double R, double phi) { + return -R*Math.sin(phi)*this.dphi_dslope(); + } + + public double dy_dphi0(double x, double d0, double phi0, double R, double phi) { + return (R-d0)*Math.sin(phi0) - R*Math.sin(phi)*this.dphi_dphi0(x, d0, phi0, R); + } + public double dy_dR(double x, double d0, double phi0, double R, double phi) { + return -Math.cos(phi0) - R*Math.sin(phi)*this.dphi_dR(x, d0, phi0, R); + } + + + //----------------------------------- + // Local derivatives of f in the z-direction + + + public double dz_dd0(double x, double d0, double phi0, double slope, double R) { + return -R*slope*this.dphi_dd0(x, d0, phi0, R); + } + + public double dz_dz0() { + return 1.0; + } + + public double dz_dslope(double phi0, double R, double phi) { + return -R*(phi-phi0); + } + + public double dz_ddphi0(double x, double d0, double phi0, double slope, double R) { + return -R*slope*(this.dphi_dphi0(x, d0, phi0, R)-1); + } + + public double dz_dR(double x, double d0, double phi0, double slope, double R, double phi) { + return -slope*(phi-phi0+R*this.dphi_dR(x, d0, phi0, R)); + } + + + //----------------------------------- + // Derivatives of phi w.r.t. track parameters + + public double dphi_dd0(double x,double d0, double phi0, double R) { + double num = Math.sin(phi0); + double den = R*Math.sqrt(Math.pow(x+(d0-R)*Math.sin(phi0), 2)/Math.pow(R,2)); + return num/den; + } + + public double dphi_dz0() { + return 0; + } + public double dphi_dslope() { + return 0; + } + public double dphi_dphi0(double x,double d0, double phi0, double R) { + double num = (d0-R)*Math.sin(phi0); + double den = R*Math.sqrt(1-Math.pow(x+(d0-R)*Math.sin(phi0),2)/Math.pow(R, 2)); + return num/den; + } + + public double dphi_dR(double x,double d0, double phi0, double R) { + double num = -x-d0*Math.sin(phi0); + double den = Math.pow(R, 2)*Math.sqrt(1-Math.pow(x+(d0-R)*Math.sin(phi0),2)/Math.pow(R, 2)); + return num/den; + } + + + + + +
- public double dphi_dx(double xint,double xr, double yr, double d0, double phi0, double R, double phi) { - double arg1 = Math.sin(phi0) - (xint-x0(xr,d0,phi0))/R; - double arg2 = Math.cos(phi0) + (y(xint,xr,yr,d0,phi0,R,phi)-y0(yr,d0,phi0))/R; - return (-1/R)*arg2/(arg2*arg2+arg1*arg1);
+ public double dphi_dx(double xint, double d0, double phi0, double R, double phi) { + double num = -Math.pow(R, 2)*sign(R); + double den1 = Math.sqrt( Math.pow(R, 2) - Math.pow(xint+(d0-R)*Math.sin(phi0), 2) ); + double den2 = -Math.pow(xint+(d0-R)*Math.sin(phi0),2); + double den3 = sign(R)*sign(R)*(-Math.pow(R, 2)+Math.pow(xint, 2)+2*(d0-R)*xint*Math.sin(phi0)+Math.pow(d0-R,2)*Math.pow(Math.sin(phi0),2) ); + return num/(den1*(den2+den3));
}
- public double dphi_dy(double xint,double xr, double yr, double d0, double phi0, double R, double phi) { - if(_debug) 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,phi)-y0(yr,d0,phi0))/R; - if(_debug) System.out.println("dphi_dy: arg1=" + arg1 + " arg2="+arg2 + " R =" + R ); - if(_debug) System.out.println("dphi_dy ===> " + (-1/R)*arg1/(arg2*arg2+arg1*arg1)); - return (-1/R)*arg1/(arg2*arg2+arg1*arg1);
+ public double dphi_dy(double y, double d0, double phi0, double R, double phi) { + double c0 = Math.cos(phi0); + double num = Math.pow(R,2)*sign(R)*sign(R); + double den1 = Math.sqrt(Math.pow(R, 2)-Math.pow(y+(d0-R)*c0, 2)); + double den2 = -Math.pow(y+(d0-R)*c0,2); + double den3 = (-Math.pow(R,2) + Math.pow(y, 2) + 2*(d0-R)*y*c0 + Math.pow(d0-R, 2)*Math.pow(c0, 2))*sign(R)*sign(R); + return num/(den1*(den2+den3));
}
+
public double dphi_dz(double slope, double R) { return -1/(R*slope); }
@@ -103,36 +217,32 @@
return 1; }
- public double dy_dx(double xint, double xr, double yr ,double d0, double phi0, double R, double phi) { - return -1*sign(R)*R*phi*this.dphi_dx(xint, xr, yr, d0, phi0, R, phi); - //return -1*sign(R)*R*this.phi(xint, xr, yr, d0, phi0, R)*this.dphi_dx(xint, xr, yr, d0, phi0, R);
+ public double dy_dx(double xint, double d0, double phi0, double R, double phi) { + return -R*Math.sin(phi)*this.dphi_dx(xint, d0, phi0, R, phi);
}
-
public double dz_dx(double xint, double xr,double yr,double d0, double phi0, double slope, double R, double phi) {
- return -slope*R*this.dphi_dx(xint, xr, yr, d0, phi0, R, phi);
+ return -R*slope*this.dphi_dx(xint, d0, phi0, R, phi);
}
- public double dx_dy(double xint, double xr, double yr ,double d0, double phi0, double R, double phi) { - if(_debug) System.out.println("dx_dy: xint=" + xint + " phi0="+phi0+" R="+R ); - if(_debug) System.out.println("dx_dy: cos(phi)="+Math.cos(phi) + " dphi_dy="+this.dphi_dy(xint, xr, yr, d0, phi0, R, phi)); - if(_debug) System.out.println("dx_dy: ====> R*cos*dphi_dy = "+ sign(R)*R*Math.cos(phi)*this.dphi_dy(xint, xr, yr, d0, phi0, R, phi)); - return sign(R)*R*Math.cos(phi)*this.dphi_dy(xint, xr, yr, d0, phi0, R, phi);
+ public double dx_dy(double y, double d0, double phi0, double R, double phi) { + return R*Math.cos(phi)*this.dphi_dy(y, d0, phi0, R, phi);
} public double dy_dy() { return 1; }
- public double dz_dy(double xint, double xr ,double d0, double phi0, double slope, double R, double phi) { - return -R*slope*this.dphi_dy(xint, xr, xr, d0, phi0, R, phi);
+ public double dz_dy(double y,double d0, double phi0, double slope, double R, double phi) { + return -R*slope*this.dphi_dy(y, d0, phi0, R, phi);
}
+
- public double dx_dz(double xint, double xr, double yr ,double d0, double phi0, double slope, double R, double phi) {
+ public double dx_dz(double slope, double R, double phi) {
return sign(R)*R*Math.cos(phi)*this.dphi_dz(slope, R);
- }
+ }
- public double dy_dz(double xint, double xr, double yr ,double d0, double phi0, double slope, double R, double phi) {
+ public double dy_dz(double slope, double R, double phi) {
return -sign(R)*R*Math.sin(phi)*this.dphi_dz(slope, R); }
@@ -187,97 +297,6 @@
- - - //d0,z0,slope,phi0,R - - - //----------------------------------- - // Derivatives of x - - - public double dx_dd0(double x, double xr,double d0, double phi0, double R) { - return -Math.sin(phi0) + sign(R)*ddeltayc_dd0(x, xr, d0,phi0,R); - } - public double dx_dz0() { - return 0.0; - } - public double dx_dslope() { - return 0.0; - } - public double dx_dphi0(double x, double xr, double yr, double d0, double phi0, double R) { - return (-d0+R)*Math.cos(phi0) + sign(R)*ddeltayc_dphi0(x,xr,yr,d0,phi0,R); - - } - public double dx_dR(double x, double xr, double yr, double d0, double phi0, double R, double phi) { - return Math.sin(phi0) + deltayc(x,xr,yr,d0,phi0,R,phi)*dsign_dR(R) + sign(R)*ddeltayc_dR(x,xr,d0,phi0,R); - } - - //----------------------------------- - - //----------------------------------- - // Derivatives of y - public double dy_dd0(double x, double xr,double d0, double phi0, double R) { - //double num = sign(R)*Math.sin(phi0)*( x - xr + (d0-R)*Math.sin(phi0) ); - //double den = Math.sqrt( R*R - Math.pow(x-xr+(d0-R)*Math.sin(phi0),2) ); - //simplify using xc - double num = sign(R)*Math.sin(phi0)*( x - xc(xr,d0,phi0,R) ); - double den = Math.sqrt( R*R - Math.pow(x-xc(xr,d0,phi0,R),2) ); - return Math.cos(phi0) - num/den; - } - public double dy_dz0() { - return 0.0; - } - public double dy_dslope() { - return 0.0; - } - - public double dy_dphi0(double x, double xr,double d0, double phi0, double R) { - //simplify using xc - double num = Math.cos(phi0)*sign(R)*( x - xc(xr,d0,phi0,R) ); - double den = Math.sqrt( R*R - Math.pow( x - xc(xr,d0,phi0,R) ,2) ); - return (-d0+R)*( Math.sin(phi0) + num/den ); - } - public double dy_dR(double x, double xr,double d0, double phi0, double R) { - //Simplify with xc - double num = sign(R) * ( d0 + R + (-d0+R)*Math.cos(2*phi0) + 2*(x-xr)*Math.sin(phi0) ); - double den = 2*Math.sqrt( R*R - Math.pow( x - xc(xr,d0,phi0,R), 2) ); - double C = Math.sqrt( R*R + Math.pow( x - xc(xr,d0,phi0,R), 2) )*dsign_dR(R); - return -Math.cos(phi0) + num/den + C; - } - - - //----------------------------------- - // Derivatives of z - - - public double dz_dd0(double x, double xr, double yr, double d0, double phi0, double slope, double R, double phi) { - return -R*slope*dtmpdphi_dd0(x, xr, yr, d0, phi0, R, phi); - } - - public double dz_dz0() { - return 1.0; - } - - public double dz_dslope(double x, double xr, double yr, double d0, double phi0, double slope, double R, double phi) { - double dphi = get_dphi(x,xr,yr,d0,phi0,R,phi); - return -R*dphi; - } - - public double dz_ddphi(double x, double xr, double yr, double d0, double phi0, double slope, double R, double phi) { - return -R*slope*dtmpdphi_ddphi(x, xr, yr, d0, phi0, R, phi); - } - - public double dz_dR(double x, double xr, double yr, double d0, double phi0, double slope, double R, double phi) { - double dphi = get_dphi(x,xr,yr,d0,phi0,R,phi); - double derdphi_dR = dtmpdphi_dR(x,xr,yr,d0,phi0,R,phi); - return -slope*( dphi + R*derdphi_dR); - } - - - - -
//------------------------------------------- //Helper functions
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1