 Timestamp:
 May 18, 2009 5:15:08 PM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/NCNR_Utils.ipf
r412 r509 152 152 Return results 153 153 End 154 155 // 156 // 157 // this should end up in NCNR_Utils once it's fully functional 158 // 159 // lots of unnecessary junk... 160 // 161 //********************** 162 // 2D resolution function calculation  in terms of X and Y 163 // 164 // based on notes from David Mildner, 2008 165 // 166 //  21 MAR 07 uses projected BS diameter on the detector 167 //  APR 07 still need to add resolution with lenses. currently there is no flag in the 168 // raw data header to indicate the presence of lenses. 169 // 170 //  Aug 07  added input to switch calculation based on lenses (==1 if in) 171 // 172 // passed values are read from RealsRead 173 // except DDet and apOff, which are set from globals before passing 174 // 175 // phi is the azimuthal angle, CCW from +x axis 176 // r_dist is the realspace distance from ctr of detector to QxQy pixel location 177 // 178 Function/S get2DResolution(inQ,phi,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,usingLenses,r_dist,SigmaQX,SigmaQY,fSubS) 179 Variable inQ, phi,lambda, lambdaWidth, DDet, apOff, S1, S2, L1, L2, BS, del_r,usingLenses,r_dist 180 Variable &SigmaQX,&SigmaQY,&fSubS //these are the output quantities at the input Q value 181 182 //lots of calculation variables 183 Variable a2, lp, v_lambda, v_b, v_d, vz, yg, v_g 184 Variable r0, delta, inc_gamma, fr, fv, rmd, v_r1, rm, v_r 185 186 //Constants 187 Variable vz_1 = 3.956e5 //velocity [cm/s] of 1 A neutron 188 Variable g = 981.0 //gravity acceleration [cm/s^2] 189 Variable h_m = 3995 // h/m [=] A*m/s 190 191 String results 192 results ="Failure" 193 194 S1 *= 0.5*0.1 //convert to radius and [cm] 195 S2 *= 0.5*0.1 196 197 L1 *= 100.0 // [cm] 198 L1 = apOff //correct the distance 199 200 L2 *= 100.0 201 L2 += apOff 202 del_r *= 0.1 //width of annulus, convert mm to [cm] 203 204 BS *= 0.5*0.1 //nominal BS diameter passed in, convert to radius and [cm] 205 // 21 MAR 07 SRK  use the projected BS diameter, based on a point sample aperture 206 Variable LB 207 LB = 20.1 + 1.61*BS //distance in cm from beamstop to anode plane (empirical) 208 BS = bs + bs*lb/(l2lb) //adjusted diameter of shadow from parallax 209 210 //Start resolution calculation 211 a2 = S1*L2/L1 + S2*(L1+L2)/L1 212 lp = 1.0/( 1.0/L1 + 1.0/L2) 213 214 v_lambda = lambdaWidth^2/6.0 215 216 // if(usingLenses==1) //SRK 2007 217 if(usingLenses != 0) //SRK 2008 allows for the possibility of different numbers of lenses in header 218 v_b = 0.25*(S1*L2/L1)^2 +0.25*(2/3)*(lambdaWidth/lambda)^2*(S2*L2/lp)^2 //correction to 2nd term 219 else 220 v_b = 0.25*(S1*L2/L1)^2 +0.25*(S2*L2/lp)^2 //original form 221 endif 222 223 v_d = (DDet/2.3548)^2 + del_r^2/12.0 224 vz = vz_1 / lambda 225 yg = 0.5*g*L2*(L1+L2)/vz^2 226 v_g = 2.0*(2.0*yg^2*v_lambda) //factor of 2 correction, B. Hammouda, 2007 227 228 r0 = L2*tan(2.0*asin(lambda*inQ/(4.0*Pi) )) 229 delta = 0.5*(BS  r0)^2/v_d 230 231 if (r0 < BS) 232 inc_gamma=exp(gammln(1.5))*(1gammp(1.5,delta)) 233 else 234 inc_gamma=exp(gammln(1.5))*(1+gammp(1.5,delta)) 235 endif 236 237 fSubS = 0.5*(1.0+erf( (r0BS)/sqrt(2.0*v_d) ) ) 238 if (fSubS <= 0.0) 239 fSubS = 1.e10 240 endif 241 // fr = 1.0 + sqrt(v_d)*exp(1.0*delta) /(r0*fSubS*sqrt(2.0*Pi)) 242 // fv = inc_gamma/(fSubS*sqrt(Pi))  r0^2*(fr1.0)^2/v_d 243 // 244 // rmd = fr*r0 245 // v_r1 = v_b + fv*v_d +v_g 246 // 247 // rm = rmd + 0.5*v_r1/rmd 248 // v_r = v_r1  0.5*(v_r1/rmd)^2 249 // if (v_r < 0.0) 250 // v_r = 0.0 251 // endif 252 253 Variable kap,a_val 254 255 kap = 2*pi/lambda 256 a_val = (L1+L2)*g/2/(h_m)^2 257 258 SigmaQX = 3*(S1/L1)^2 + 3*(S2/LP)^2 + 2*(DDet/L2)^2 + 2*(r_dist/L2)^2*(lambdaWidth)^2*(cos(phi))^2 259 260 SigmaQY = 3*(S1/L1)^2 + 3*(S2/LP)^2 + 2*(DDet/L2)^2 + 2*(r_dist/L2)^2*(lambdaWidth)^2*(sin(phi))^2 + 8*(a_val/L2)^2*lambda^4*lambdaWidth^2 261 262 SigmaQX = sqrt(kap*kap/12*SigmaQX) 263 SigmaQy = sqrt(kap*kap/12*SigmaQY) 264 265 results = "success" 266 Return results 267 End 268 269 154 270 155 271
Note: See TracChangeset
for help on using the changeset viewer.