#include "DLorentzDeflections.h" #include #include // Locate a position in array xx given x static 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. static 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[imin],4,r,&tanr,&dy); polint(&lorentz_x[imin],&ytemp2[imin],4,r,&tanz,&dy); return NOERROR; } // Obtain deflection of avalanche along wire due to Lorentz force double DLorentzDeflections::GetLorentzCorrection(double x,double y,double z, double alpha,double dx) const { double tanz=0.,tanr=0.; GetLorentzCorrectionParameters(x,y,z,tanz,tanr); // Deflection along wire double phi=atan2(y,x); return (-tanz*dx*sin(alpha)*cos(phi)+tanr*dx*cos(alpha)); }