#include "DLorentzDeflections.h" #include #include // Locate a position in array xx given x void locate(const double *xx,int n,double x,int *j){ int ju,jm,jl; int ascnd; jl=-1; ju=n; ascnd=(xx[n-1]>=xx[0]); while(ju-jl>1){ jm=(ju+jl)>>1; if (x>=xx[jm]==ascnd) jl=jm; else ju=jm; } if (x==xx[0]) *j=0; else if (x==xx[n-1]) *j=n-2; else *j=jl; } // Polynomial interpolation on a grid. // Adapted from Numerical Recipes in C (2nd Edition), pp. 121-122. void polint(const double *xa, const double *ya,int n,double x, double *y, double *dy){ int i,m,ns=0; double den,dif,dift,ho,hp,w; double *c=(double *)calloc(n,sizeof(double)); double *d=(double *)calloc(n,sizeof(double)); dif=fabs(x-xa[0]); for (i=0;i0){ imin=((ind+3)>LORENTZ_X_POINTS)?(LORENTZ_X_POINTS-4):(ind-1); } else imin=0; polint(&lorentz_x[imin],ytemp,4,r,&tanr,&dy); polint(&lorentz_x[imin],ytemp2,4,r,&tanz,&dy); // Deflection along wire return (-tanz*dx*sin(alpha)*cos(phi)+tanr*dx*cos(alpha)); }