Changeset 794 for sans/Dev/trunk
- Timestamp:
- Apr 4, 2011 11:12:38 AM (12 years ago)
- Location:
- sans/Dev/trunk/NCNR_User_Procedures
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Models_2D/CoreShellCyl2D_v40.ipf
r771 r794 276 276 Make/O/D/N=15 CSCyl2D_tmp 277 277 CSCyl2D_tmp[0,13] = cw 278 CSCyl2D_tmp[14] = 25278 CSCyl2D_tmp[14] = 5 // hard-wire the number of integration points, small number since smearing is used 279 279 CSCyl2D_tmp[7] = 0 //send a zero background to the calculation, add it in later 280 280 … … 383 383 384 384 Variable spl,spp,apl,app,bpl,bpp,phi_pt,qpl_pt 385 Variable qperp_pt,phi_prime,q_prime 385 386 386 387 //loop over q-values … … 401 402 apl = -numStdDev*spl + qval //parallel = q integration limits 402 403 bpl = numStdDev*spl + qval 403 app = -numStdDev*spp + phi //perpendicular = phi integration limits404 bpp = numStdDev*spp + phi404 app = -numStdDev*spp + 0 //q_perp = 0 405 bpp = numStdDev*spp + 0 405 406 406 407 //make sure the limits are reasonable. … … 413 414 sumOut = 0 414 415 for(jj=0;jj<nord;jj+=1) // call phi the "outer' 415 phi_pt = (xi[jj]*(bpp-app)+app+bpp)/2416 qperp_pt = (xi[jj]*(bpp-app)+app+bpp)/2 //this is now q_perp 416 417 417 418 sumIn=0 … … 420 421 qpl_pt = (xi[kk]*(bpl-apl)+apl+bpl)/2 421 422 422 FindQxQy(qpl_pt,phi_pt,qx_pt,qy_pt) //find the corresponding QxQy to the Q,phi 423 // find QxQy given Qpl and Qperp on the grid 424 // 425 q_prime = sqrt(qpl_pt^2+qperp_pt^2) 426 phi_prime = phi + qperp_pt/qpl_pt 427 FindQxQy(q_prime,phi_prime,qx_pt,qy_pt) 428 423 429 yPtw[kk] = qy_pt //phi is the same in this loop, but qy is not 424 430 xPtW[kk] = qx_pt //qx is different here too, as we're varying Qpl 425 431 426 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + ( phi_pt-phi)^2/spp/spp ) )432 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + (qperp_pt)^2/spp/spp ) ) 427 433 res_tot[kk] /= normFactor 428 434 // res_tot[kk] *= fs -
sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Models_2D/Cylinder_2D_v40.ipf
r788 r794 221 221 /// now using the MultiThread keyword. as of Igor 6.20, the manual threading 222 222 // as above gives a wave read error (index out of range). Same code works fine in Igor 6.12 223 //ThreadSafe Function Cylinder2D(cw,zw,xw,yw) : FitFunc 223 224 Function Cylinder2D(cw,zw,xw,yw) : FitFunc 224 225 Wave cw,zw,xw,yw … … 252 253 // Smear_2DModel_PP(Cylinder2D_noThread,s,10) 253 254 255 // this is generic, but I need to declare the Cylinder2D threadsafe 256 // and this calculation is significantly slower than the manually threaded calculation 257 // if the function is fast to calculate. Once the function has polydispersity on 2 or more parameters 258 // then this AAO calculation and the manual threading are both painfully slow, and more similar in execution time 259 // 260 // see the function for timing details 261 // 262 // Smear_2DModel_PP_AAO(Cylinder2D,s,10) 254 263 255 264 //// the last param is nord … … 385 394 386 395 // 387 // - worker function for threads of Sphere2D396 // - worker function for threads of Cylinder2D 388 397 // 389 398 ThreadSafe Function SmearedCylinder2D_T(coef,qxw,qyw,qzw,sxw,syw,fsw,zw,wt,xi,pt1,pt2,nord) … … 409 418 410 419 Variable spl,spp,apl,app,bpl,bpp,phi_pt,qpl_pt 420 Variable qperp_pt,phi_prime,q_prime 411 421 412 422 //loop over q-values … … 427 437 apl = -numStdDev*spl + qval //parallel = q integration limits 428 438 bpl = numStdDev*spl + qval 429 app = -numStdDev*spp + phi //perpendicular = phi integration limits430 bpp = numStdDev*spp + phi439 app = -numStdDev*spp + 0 //q_perp = 0 440 bpp = numStdDev*spp + 0 431 441 432 442 //make sure the limits are reasonable. … … 439 449 sumOut = 0 440 450 for(jj=0;jj<nord;jj+=1) // call phi the "outer' 441 phi_pt = (xi[jj]*(bpp-app)+app+bpp)/2451 qperp_pt = (xi[jj]*(bpp-app)+app+bpp)/2 //this is now q_perp 442 452 443 453 sumIn=0 … … 446 456 qpl_pt = (xi[kk]*(bpl-apl)+apl+bpl)/2 447 457 448 FindQxQy(qpl_pt,phi_pt,qx_pt,qy_pt) //find the corresponding QxQy to the Q,phi 458 // find QxQy given Qpl and Qperp on the grid 459 // 460 q_prime = sqrt(qpl_pt^2+qperp_pt^2) 461 phi_prime = phi + qperp_pt/qpl_pt 462 FindQxQy(q_prime,phi_prime,qx_pt,qy_pt) 463 449 464 yPtw[kk] = qy_pt //phi is the same in this loop, but qy is not 450 465 xPtW[kk] = qx_pt //qx is different here too, as we're varying Qpl 451 466 452 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + ( phi_pt-phi)^2/spp/spp ) )467 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + (qperp_pt)^2/spp/spp ) ) 453 468 res_tot[kk] /= normFactor 454 469 // res_tot[kk] *= fs -
sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Models_2D/Ellipsoid2D_v40.ipf
r771 r794 270 270 Make/O/D/N=13 Ellip2D_tmp 271 271 Ellip2D_tmp[0,11] = cw 272 Ellip2D_tmp[12] = 25272 Ellip2D_tmp[12] = 5 //use a small number of integration points since smearing is used 273 273 Ellip2D_tmp[5] = 0 //pass in a zero background and add it in later 274 274 … … 377 377 378 378 Variable spl,spp,apl,app,bpl,bpp,phi_pt,qpl_pt 379 Variable qperp_pt,phi_prime,q_prime 379 380 380 381 //loop over q-values … … 395 396 apl = -numStdDev*spl + qval //parallel = q integration limits 396 397 bpl = numStdDev*spl + qval 397 app = -numStdDev*spp + phi //perpendicular = phi integration limits398 bpp = numStdDev*spp + phi398 app = -numStdDev*spp + 0 //q_perp = 0 399 bpp = numStdDev*spp + 0 399 400 400 401 //make sure the limits are reasonable. … … 407 408 sumOut = 0 408 409 for(jj=0;jj<nord;jj+=1) // call phi the "outer' 409 phi_pt = (xi[jj]*(bpp-app)+app+bpp)/2410 qperp_pt = (xi[jj]*(bpp-app)+app+bpp)/2 //this is now q_perp 410 411 411 412 sumIn=0 … … 414 415 qpl_pt = (xi[kk]*(bpl-apl)+apl+bpl)/2 415 416 416 FindQxQy(qpl_pt,phi_pt,qx_pt,qy_pt) //find the corresponding QxQy to the Q,phi 417 // find QxQy given Qpl and Qperp on the grid 418 // 419 q_prime = sqrt(qpl_pt^2+qperp_pt^2) 420 phi_prime = phi + qperp_pt/qpl_pt 421 FindQxQy(q_prime,phi_prime,qx_pt,qy_pt) 422 417 423 yPtw[kk] = qy_pt //phi is the same in this loop, but qy is not 418 424 xPtW[kk] = qx_pt //qx is different here too, as we're varying Qpl 419 425 420 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + ( phi_pt-phi)^2/spp/spp ) )426 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + (qperp_pt)^2/spp/spp ) ) 421 427 res_tot[kk] /= normFactor 422 428 // res_tot[kk] *= fs -
sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Models_2D/EllipticalCylinder2D_v40.ipf
r771 r794 273 273 Make/O/D/N=15 EllCyl2D_tmp 274 274 EllCyl2D_tmp[0,13] = cw 275 EllCyl2D_tmp[14] = 25275 EllCyl2D_tmp[14] = 5 // small number of integration points since smearing is used 276 276 EllCyl2D_tmp[6] = 0 //pass in a zero background and add it in later 277 277 … … 380 380 381 381 Variable spl,spp,apl,app,bpl,bpp,phi_pt,qpl_pt 382 Variable qperp_pt,phi_prime,q_prime 382 383 383 384 //loop over q-values … … 398 399 apl = -numStdDev*spl + qval //parallel = q integration limits 399 400 bpl = numStdDev*spl + qval 400 app = -numStdDev*spp + phi //perpendicular = phi integration limits401 bpp = numStdDev*spp + phi401 app = -numStdDev*spp + 0 //q_perp = 0 402 bpp = numStdDev*spp + 0 402 403 403 404 //make sure the limits are reasonable. … … 410 411 sumOut = 0 411 412 for(jj=0;jj<nord;jj+=1) // call phi the "outer' 412 phi_pt = (xi[jj]*(bpp-app)+app+bpp)/2413 qperp_pt = (xi[jj]*(bpp-app)+app+bpp)/2 //this is now q_perp 413 414 414 415 sumIn=0 … … 417 418 qpl_pt = (xi[kk]*(bpl-apl)+apl+bpl)/2 418 419 419 FindQxQy(qpl_pt,phi_pt,qx_pt,qy_pt) //find the corresponding QxQy to the Q,phi 420 // find QxQy given Qpl and Qperp on the grid 421 // 422 q_prime = sqrt(qpl_pt^2+qperp_pt^2) 423 phi_prime = phi + qperp_pt/qpl_pt 424 FindQxQy(q_prime,phi_prime,qx_pt,qy_pt) 425 420 426 yPtw[kk] = qy_pt //phi is the same in this loop, but qy is not 421 427 xPtW[kk] = qx_pt //qx is different here too, as we're varying Qpl 422 428 423 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + ( phi_pt-phi)^2/spp/spp ) )429 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + (qperp_pt)^2/spp/spp ) ) 424 430 res_tot[kk] /= normFactor 425 431 // res_tot[kk] *= fs -
sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Models_2D/PeakGauss2D_v40.ipf
r775 r794 328 328 329 329 Variable spl,spp,apl,app,bpl,bpp,phi_pt,qpl_pt 330 Variable qperp_pt,phi_prime,q_prime 330 331 331 332 //loop over q-values … … 346 347 apl = -numStdDev*spl + qval //parallel = q integration limits 347 348 bpl = numStdDev*spl + qval 348 app = -numStdDev*spp + phi //perpendicular = phi integration limits349 bpp = numStdDev*spp + phi349 app = -numStdDev*spp + 0 //q_perp = 0 350 bpp = numStdDev*spp + 0 350 351 351 352 //make sure the limits are reasonable. … … 358 359 sumOut = 0 359 360 for(jj=0;jj<nord;jj+=1) // call phi the "outer' 360 phi_pt = (xi[jj]*(bpp-app)+app+bpp)/2361 qperp_pt = (xi[jj]*(bpp-app)+app+bpp)/2 //this is now q_perp 361 362 362 363 sumIn=0 … … 365 366 qpl_pt = (xi[kk]*(bpl-apl)+apl+bpl)/2 366 367 367 FindQxQy(qpl_pt,phi_pt,qx_pt,qy_pt) //find the corresponding QxQy to the Q,phi 368 // find QxQy given Qpl and Qperp on the grid 369 // 370 q_prime = sqrt(qpl_pt^2+qperp_pt^2) 371 phi_prime = phi + qperp_pt/qpl_pt 372 FindQxQy(q_prime,phi_prime,qx_pt,qy_pt) 373 368 374 yPtw[kk] = qy_pt //phi is the same in this loop, but qy is not 369 375 xPtW[kk] = qx_pt //qx is different here too, as we're varying Qpl 370 376 371 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + ( phi_pt-phi)^2/spp/spp ) )377 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + (qperp_pt)^2/spp/spp ) ) 372 378 res_tot[kk] /= normFactor 373 379 // res_tot[kk] *= fs -
sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Models_2D/Sphere_2D_v40.ipf
r771 r794 347 347 348 348 Variable spl,spp,apl,app,bpl,bpp,phi_pt,qpl_pt 349 Variable qperp_pt,phi_prime,q_prime 349 350 350 351 //loop over q-values … … 358 359 spp = syw[ii] 359 360 fs = fsw[ii] 361 360 362 361 363 normFactor = 2*pi*spl*spp … … 365 367 apl = -numStdDev*spl + qval //parallel = q integration limits 366 368 bpl = numStdDev*spl + qval 367 app = -numStdDev*spp + phi //perpendicular = phi integration limits 368 bpp = numStdDev*spp + phi 369 /// app = -numStdDev*spp + phi //perpendicular = phi integration limits (WRONG) 370 /// bpp = numStdDev*spp + phi 371 app = -numStdDev*spp + 0 //q_perp = 0 372 bpp = numStdDev*spp + 0 369 373 370 374 //make sure the limits are reasonable. … … 377 381 sumOut = 0 378 382 for(jj=0;jj<nord;jj+=1) // call phi the "outer' 379 phi_pt = (xi[jj]*(bpp-app)+app+bpp)/2 380 383 /// phi_pt = (xi[jj]*(bpp-app)+app+bpp)/2 384 qperp_pt = (xi[jj]*(bpp-app)+app+bpp)/2 //this is now q_perp 385 381 386 sumIn=0 382 387 for(kk=0;kk<nord;kk+=1) //at phi, integrate over Qpl … … 384 389 qpl_pt = (xi[kk]*(bpl-apl)+apl+bpl)/2 385 390 386 FindQxQy(qpl_pt,phi_pt,qx_pt,qy_pt) //find the corresponding QxQy to the Q,phi 391 /// FindQxQy(qpl_pt,phi_pt,qx_pt,qy_pt) //find the corresponding QxQy to the Q,phi 392 393 // find QxQy given Qpl and Qperp on the grid 394 // 395 q_prime = sqrt(qpl_pt^2+qperp_pt^2) 396 phi_prime = phi + qperp_pt/q_prime 397 FindQxQy(q_prime,phi_prime,qx_pt,qy_pt) 398 387 399 yPtw[kk] = qy_pt //phi is the same in this loop, but qy is not 388 400 xPtW[kk] = qx_pt //qx is different here too, as we're varying Qpl 389 390 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + (phi_pt-phi)^2/spp/spp ) ) 401 402 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + (qperp_pt)^2/spp/spp ) ) 403 /// res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + (phi_pt-phi)^2/spp/spp ) ) 391 404 res_tot[kk] /= normFactor 392 405 // res_tot[kk] *= fs -
sans/Dev/trunk/NCNR_User_Procedures/Common/GaussUtils_v40.ipf
r708 r794 742 742 // "backwards" wrapped to reduce redundant code 743 743 // there are only 4 choices of N (5,10,20,76) for smearing 744 // 745 // 746 // 4 MAR 2011 747 // Note: In John's paper, he integrated the Gaussian to +/- 3 sigma and then renormalized 748 // to an integral of 1. This "truncated" gaussian was a somewhat better approximation 749 // to the triangular resolution function. Here, I integrate to +/- 3 sigma and 750 // do not renormalize the integral to 1. Hence the smeared calculation is 0.27% low. 751 // This is easily seen by smearing a constant value. 752 // 753 // Using 5 quadrature points is not recommended, as it doesn't normalize properly using .9973 754 // -- instead, it normalizes to 1.0084, 755 // 744 756 Function Smear_Model_N(fcn,w,x,resW,wi,zi,nord) 745 757 FUNCREF SANSModelAAO_proto fcn … … 755 767 // local variables 756 768 Variable ii,va,vb 757 Variable answer,i_shad,i_qbar,i_sigq 769 Variable answer,i_shad,i_qbar,i_sigq,normalize=1 758 770 759 771 // current x point is the q-value for evaluation … … 788 800 //integration from va to vb 789 801 802 // for +/- 3 sigma ONLY 803 if(nord == 5) 804 normalize = 1.0057 //empirical correction, N=5 shouldn't be any different 805 else 806 normalize = 0.9973 807 endif 808 790 809 va = -3*i_sigq + i_qbar 791 810 if (va<0) 792 811 va=0 //to avoid numerical error when va<0 (-ve q-value) 793 //Print "truncated Gaussian at nominal q = ",x812 Print "truncated Gaussian at nominal q = ",x 794 813 endif 795 814 vb = 3*i_sigq + i_qbar 815 796 816 797 817 // Using 20 Gauss points … … 815 835 // all scaling, background addition... etc. is done in the model calculation 816 836 837 // renormalize to 1 838 answer /= normalize 817 839 else 818 840 //smear with the USANS routine … … 884 906 endif 885 907 886 answer = Smear_Model_N(fcn,w,x,resW,weightW,abscissW,nord) 908 // answer = Smear_Model_N(fcn,w,x,resW,weightW,abscissW,nord) 909 Smear_Model_N_AAO(fcn,w,x,resW,weightW,abscissW,nord,answer) 910 887 911 Return (0) 888 912 endif … … 932 956 endif 933 957 934 answer = Smear_Model_N(fcn,w,x,resW,weightW,abscissW,nord) 958 // answer = Smear_Model_N(fcn,w,x,resW,weightW,abscissW,nord) 959 Smear_Model_N_AAO(fcn,w,x,resW,weightW,abscissW,nord,answer) 960 935 961 Return (0) 936 962 endif … … 986 1012 endif 987 1013 988 answer = Smear_Model_N(fcn,w,x,resW,weightW,abscissW,nord) 1014 // answer = Smear_Model_N(fcn,w,x,resW,weightW,abscissW,nord) 1015 Smear_Model_N_AAO(fcn,w,x,resW,weightW,abscissW,nord,answer) 1016 989 1017 Return (0) 990 1018 endif … … 1032 1060 endif 1033 1061 1034 answer = Smear_Model_N(fcn,w,x,resW,weightW,abscissW,nord) 1062 // answer = Smear_Model_N(fcn,w,x,resW,weightW,abscissW,nord) 1063 Smear_Model_N_AAO(fcn,w,x,resW,weightW,abscissW,nord,answer) 1064 1035 1065 Return (0) 1036 1066 endif … … 1565 1595 return(0) 1566 1596 end 1567 1597 1598 1599 // 7 MAR 2011 SRK 1600 // 1601 // calculate the resolution smearing AAO 1602 // 1603 // - many of the form factor calculations are threaded, so they benefit 1604 // from being passed large numbers of q-values at once, rather than suffering the 1605 // overhead penalty of setting up threads. 1606 // 1607 // In general, single integral functions benefit from this, multiple integrals not so much. 1608 // As an example, a fit using SmearedCylinderForm took 4.3s passing nord (=20) q-values 1609 // at a time, but only 1.1s by passing all (Nq*nord) q-values at once. For Cyl_polyRad, 1610 // the difference was not so large, 16.2s vs. 11.9s. This is due to CylPolyRad being a 1611 // double integral and slow enough of a calculation that passing even 20 points at once 1612 // provides some speedup. 1613 // 1614 // 1615 // 1616 // "backwards" wrapped to reduce redundant code 1617 // there are only 4 choices of N (5,10,20,76) for smearing 1618 // 1619 // 1620 // 4 MAR 2011 SRK 1621 // Note: In John's paper, he integrated the Gaussian to +/- 3 sigma and then renormalized 1622 // to an integral of 1. This "truncated" gaussian was a somewhat better approximation 1623 // to the triangular resolution function. Here, I integrate to +/- 3 sigma and 1624 // do not renormalize the integral to 1. Hence the smeared calculation is 0.27% low. 1625 // This is easily seen by smearing a constant value. 1626 // 1627 // Using 5 quadrature points is not recommended, as it doesn't normalize properly using .9973 1628 // -- instead, it normalizes to 1.0084. 1629 // 1630 Function Smear_Model_N_AAO(fcn,w,x,resW,wi,zi,nord,sm_ans) 1631 FUNCREF SANSModelAAO_proto fcn 1632 Wave w //coefficients of function fcn(w,x) 1633 WAVE x //x-value (q) for the calculation THIS IS PASSED IN AS A WAVE 1634 Wave resW // Nx4 or NxN matrix of resolution 1635 Wave wi //weight wave 1636 Wave zi //abscissa wave 1637 Variable nord //order of integration 1638 Wave sm_ans // wave returned with the smeared model 1639 1640 NVAR dQv = root:Packages:NIST:USANS_dQv 1641 1642 // local variables 1643 Variable ii,jj 1644 Variable normalize=1 1645 Variable nTot,num,block_sum 1646 1647 1648 // current x point is the q-value for evaluation 1649 // 1650 // * for the input x, the resolution function waves are interpolated to get the correct values for 1651 // sigq, qbar and shad - since the model x-spacing may not be the same as 1652 // the experimental QSIG data. This is always the case when curve fitting, since fit_wave is 1653 // Igor-defined as 200 points and has its own (linear) q-(x)-scaling which will be quite different 1654 // from experimental data. 1655 // **note** if the (x) passed in is the experimental q-values, these values are 1656 // returned from the interpolation (as expected) 1657 1658 Make/O/D/N=(DimSize(resW, 0)) sigQ,qbar,shad,qvals,va,vb 1659 sigq = resW[p][0] //std dev of resolution fn 1660 qbar = resW[p][1] //mean q-value 1661 shad = resW[p][2] //beamstop shadow factor 1662 qvals = resW[p][3] //q-values where R(q) is known 1663 1664 //SKIP the interpolation, points passed in ARE (MUST) be the experimental q-values 1665 1666 1667 // if USANS data, handle separately 1668 // -- but this would only ever be used if the calculation was forced to use trapezoid integration 1669 if ( ! isSANSResolution(sigq[0]) ) 1670 //smear with the USANS routine 1671 // Make global string and local variables 1672 // now data folder aware, necessary for GlobalFit = FULL path to wave 1673 String/G gTrap_coefStr = GetWavesDataFolder(w, 2 ) 1674 Variable maxiter=20, tol=1e-4,uva,uvb 1675 1676 num=numpnts(x) 1677 // set up limits for the integration 1678 uva=0 1679 uvb=abs(dQv) 1680 1681 //loop over the q-values 1682 for(jj=0;jj<num;jj+=1) 1683 Variable/G gEvalQval = x[jj] 1684 1685 // call qtrap to do actual work 1686 sm_ans[jj] = qtrap_USANS(fcn,uva,uvb,tol,maxiter) 1687 sm_ans[jj] /= (uvb - uva) 1688 endfor 1689 1690 return(0) 1691 endif 1692 1693 1694 // now the idea is to calculate a long vector of all of the zi's (Nq * nord) 1695 // and pass these AAO to the AAO function, to make the most use of the threading 1696 // passing repeated short lengths of q to the function can actually be slower 1697 // due to the overhead. 1698 1699 num = numpnts(x) 1700 nTot = nord*num 1701 1702 Make/O/D/N=(nTot) Resoln,yyy,xGauss,wts 1703 1704 //loop over q 1705 for(jj=0;jj<num;jj+=1) 1706 1707 //for each q, set up the integration range 1708 // end points of integration limits are technically 0-inf, but wisely choose interesting region of q where R() is nonzero 1709 // +/- 3 sigq catches 99.73% of distrubution 1710 // change limits (and spacing of zi) at each evaluation based on R() 1711 //integration from va to vb 1712 1713 va[jj] = -3*sigq[jj] + qbar[jj] 1714 if (va[jj]<0) 1715 va[jj]=0 //to avoid numerical error when va<0 (-ve q-value) 1716 // Print "truncated Gaussian at nominal q = ",x 1717 endif 1718 vb[jj] = 3*sigq[jj] + qbar[jj] 1719 1720 // loop over the Gauss points 1721 for(ii=0;ii<nord;ii+=1) 1722 // calculate Gauss points on integration interval (q-value for evaluation) 1723 xGauss[nord*jj+ii] = ( zi[ii]*(vb[jj]-va[jj]) + vb[jj] + va[jj] )/2.0 1724 // calculate resolution function at input q-value (use the interpolated values and zi) 1725 Resoln[nord*jj+ii] = shad[jj]/sqrt(2*pi*sigq[jj]*sigq[jj]) 1726 Resoln[nord*jj+ii] *= exp((-1*(xGauss[nord*jj+ii] - qbar[jj])^2)/(2*sigq[jj]*sigq[jj])) 1727 // Resoln[nord*jj+ii] *= exp((-1*(xGauss[nord*jj+ii] - qvals[jj])^2)/(2*sigq[jj]*sigq[jj])) //WRONG, but just for testing 1728 // carry a copy of the weights 1729 wts[nord*jj+ii] = wi[ii] 1730 endfor // end of loop over quadrature points 1731 1732 endfor //loop over q 1733 1734 //calculate AAO 1735 yyy = 0 1736 fcn(w,yyy,xGauss) //yyy is the return value as a wave 1737 1738 //multiply by weights 1739 yyy *= wts*Resoln //multiply function by resolution and weights 1740 1741 //sum up blockwise to get the final answer 1742 for(jj=0;jj<num;jj+=1) 1743 block_sum = 0 1744 for(ii=0;ii<nord;ii+=1) 1745 block_sum += yyy[nord*jj+ii] 1746 endfor 1747 sm_ans[jj] = (vb[jj]-va[jj])/2.0*block_sum 1748 endfor 1749 1750 1751 // then normalize for +/- 3 sigma ONLY 1752 if(nord == 5) 1753 normalize = 1.0057 //empirical correction, N=5 shouldn't be any different 1754 else 1755 normalize = 0.9973 1756 endif 1757 1758 sm_ans /= normalize 1759 1760 return(0) 1761 1762 End 1763 -
sans/Dev/trunk/NCNR_User_Procedures/Common/Packages/PlotManager/PlotUtils2D_v40.ipf
r771 r794 17 17 // 2D model calculations (model_lin) 2D data files as well. 18 18 19 // Call the procedure BinQxQy_to_1D() to re-bin the QxQy data into I(q). good for testing to check the 2D error propagation 20 // 21 // 22 19 23 20 24 // … … 25 29 Proc LoadQxQy() 26 30 31 SetDataFolder root: 32 27 33 LoadWave/G/D/W/A 28 34 String fileName = S_fileName … … 1018 1024 // be made too, if needed. 1019 1025 // 1020 // X- need error on I(q) 1021 // -- need to set "proper" number of data points (delta and qMax?)1026 // X- need error on I(q) - now calculated both ways, from 2D error propagation, and from deviation from the mean 1027 // X- need to set "proper" number of data points (delta and qMax?) 1022 1028 // X- need to remove points at high Q end 1023 1029 // … … 1027 1033 // the results are in iBin_qxqy, qBin_qxqy, and eBin_qxqy, in the folder passed 1028 1034 // 1035 1036 Proc BinQxQy_to_1D(folderStr) 1037 String folderStr 1038 Prompt folderStr,"Pick the data folder containing 2D data",popup,getAList(4) 1039 1040 fDoBinning_QxQy2D(folderStr) 1041 End 1042 1043 1044 1029 1045 //Function fDoBinning_QxQy2D(inten,qx,qy,qz) 1046 // Wave inten,qx,qy,qz 1047 1030 1048 Function fDoBinning_QxQy2D(folderStr) 1031 1049 String folderStr 1032 1050 1033 // Wave inten,qx,qy,qz1034 1051 1035 1052 SetDataFolder $("root:"+folderStr) 1036 1053 1037 WAVE inten = $(folderStr + "_i") 1054 WAVE inten = $("smeared_sf2D") 1055 1056 // WAVE inten = $(folderStr + "_i") 1057 WAVE iErr = $(folderStr + "_iErr") 1038 1058 WAVE qx = $(folderStr + "_qx") 1039 1059 WAVE qy = $(folderStr + "_qy") … … 1048 1068 1049 1069 yDim = XDim 1050 Make/O/D/N=(nq) iBin_qxqy,qBin_qxqy,nBin_qxqy,iBin2_qxqy,eBin_qxqy 1070 Make/O/D/N=(nq) iBin_qxqy,qBin_qxqy,nBin_qxqy,iBin2_qxqy,eBin_qxqy,eBin2D_qxqy 1051 1071 delQ = abs(sqrt(qx[2]^2+qy[2]^2+qz[2]^2) - sqrt(qx[1]^2+qy[1]^2+qz[1]^2)) //use bins of 1 pixel width 1052 1072 qBin_qxqy[] = p* delQ … … 1056 1076 iBin2_qxqy = 0 1057 1077 eBin_qxqy = 0 1078 eBin2D_qxqy = 0 1058 1079 nBin_qxqy = 0 //number of intensities added to each bin 1059 1080 … … 1065 1086 iBin_qxqy[binIndex] += val 1066 1087 iBin2_qxqy[binIndex] += val*val 1088 eBin2D_qxqy[binIndex] += iErr[ii]*iErr[ii] 1067 1089 nBin_qxqy[binIndex] += 1 1068 1090 endif … … 1075 1097 iBin_qxqy[ii] = 0 1076 1098 eBin_qxqy[ii] = 1 1099 eBin2D_qxqy[ii] = NaN 1077 1100 else 1078 1101 if(nBin_qxqy[ii] <= 1) … … 1080 1103 iBin_qxqy[ii] /= nBin_qxqy[ii] 1081 1104 eBin_qxqy[ii] = 1 1105 eBin2D_qxqy[ii] /= (nBin_qxqy[ii])^2 1082 1106 else 1083 1107 //assume that the intensity in each pixel in annuli is normally … … 1092 1116 eBin_qxqy[ii] = sqrt(var/(nBin_qxqy[ii] - 1)) 1093 1117 endif 1118 // and calculate as it is propagated pixel-by-pixel 1119 eBin2D_qxqy[ii] /= (nBin_qxqy[ii])^2 1094 1120 endif 1095 1121 endif 1096 1122 endfor 1123 1124 eBin2D_qxqy = sqrt(eBin2D_qxqy) // as equation (3) of John's memo 1097 1125 1098 1126 // find the last non-zero point, working backwards … … 1103 1131 1104 1132 // print val, nBin_qxqy[val] 1105 DeletePoints val, nq-val, iBin_qxqy,qBin_qxqy,nBin_qxqy,iBin2_qxqy,eBin_qxqy 1133 DeletePoints val, nq-val, iBin_qxqy,qBin_qxqy,nBin_qxqy,iBin2_qxqy,eBin_qxqy,eBin2D_qxqy 1106 1134 1107 1135 SetDataFolder root: -
sans/Dev/trunk/NCNR_User_Procedures/Common/Smear_2D.ipf
r708 r794 95 95 96 96 Variable spl,spp,apl,app,bpl,bpp,phi_pt,qpl_pt 97 Variable qperp_pt,phi_prime,q_prime 98 97 99 Variable t1=StopMSTimer(-2) 98 100 … … 118 120 apl = -numStdDev*spl + qval //parallel = q integration limits 119 121 bpl = numStdDev*spl + qval 120 app = -numStdDev*spp + phi //perpendicular = phi integration limits 121 bpp = numStdDev*spp + phi 122 /// app = -numStdDev*spp + phi //perpendicular = phi integration limits (WRONG) 123 /// bpp = numStdDev*spp + phi 124 app = -numStdDev*spp + 0 //q_perp = 0 125 bpp = numStdDev*spp + 0 122 126 123 127 //make sure the limits are reasonable. … … 130 134 sumOut = 0 131 135 for(jj=0;jj<nord;jj+=1) // call phi the "outer' 132 phi_pt = (xi[jj]*(bpp-app)+app+bpp)/2 136 /// phi_pt = (xi[jj]*(bpp-app)+app+bpp)/2 137 qperp_pt = (xi[jj]*(bpp-app)+app+bpp)/2 //this is now q_perp 133 138 134 139 sumIn=0 … … 137 142 qpl_pt = (xi[kk]*(bpl-apl)+apl+bpl)/2 138 143 139 FindQxQy(qpl_pt,phi_pt,qx_pt,qy_pt) //find the corresponding QxQy to the Q,phi 144 /// FindQxQy(qpl_pt,phi_pt,qx_pt,qy_pt) //find the corresponding QxQy to the Q,phi 145 146 // find QxQy given Qpl and Qperp on the grid 147 // 148 q_prime = sqrt(qpl_pt^2+qperp_pt^2) 149 phi_prime = phi + qperp_pt/qpl_pt 150 FindQxQy(q_prime,phi_prime,qx_pt,qy_pt) 151 140 152 yPtw[kk] = qy_pt //phi is the same in this loop, but qy is not 141 153 xPtW[kk] = qx_pt //qx is different here too, as we're varying Qpl 142 143 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + (phi_pt-phi)^2/spp/spp ) ) 154 155 res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + (qperp_pt)^2/spp/spp ) ) 156 /// res_tot[kk] = exp(-0.5*( (qpl_pt-qval)^2/spl/spl + (phi_pt-phi)^2/spp/spp ) ) 144 157 res_tot[kk] /= normFactor 145 158 // res_tot[kk] *= fs … … 164 177 return(0) 165 178 end 179 180 181 // this is generic, but I need to declare the Cylinder2D function threadsafe 182 // and this calculation is significantly slower than the manually threaded calculation 183 // if the function is fast to calculate. Once the function has polydispersity on 2 or more parameters 184 // then this AAO calculation and the manual threading are both painfully slow, and more similar in execution time 185 // 186 // For 128x128 data, and 10x10 smearing, using 25 points for each polydispersity (using DANSE code) 187 // Successively making more things polydisperse gives the following timing (in seconds): 188 // 189 // monodisp sigR sigTheta sigPhi 190 // manual THR 1.1 3.9 74 1844 191 // this AAO 8.6 11.4 104 1930 192 // 193 // and using 5 points for each polydispersity: (I see no visual difference) 194 // manual THR 1.1 1.6 3.9 16.1 195 // 196 // so clearly -- use 5 points for the polydispersities, unless there's a good reason not to - and 197 // certainly for a survey, it's the way to go. 198 // 199 Function Smear_2DModel_PP_AAO(fcn,s,nord) 200 FUNCREF SANS_2D_ModelAAO_proto fcn 201 Struct ResSmear_2D_AAOStruct &s 202 Variable nord 203 204 String weightStr,zStr 205 206 Variable ii,jj,kk,num 207 Variable qx,qy,qz,qval,fs 208 Variable qy_pt,qx_pt,res_x,res_y,answer,sumIn,sumOut 209 210 Variable a,b,c,normFactor,phi,theta,maxSig,numStdDev=3 211 212 switch(nord) 213 case 5: 214 weightStr="gauss5wt" 215 zStr="gauss5z" 216 if (WaveExists($weightStr) == 0) 217 Make/O/D/N=(nord) $weightStr,$zStr 218 Make5GaussPoints($weightStr,$zStr) 219 endif 220 break 221 case 10: 222 weightStr="gauss10wt" 223 zStr="gauss10z" 224 if (WaveExists($weightStr) == 0) 225 Make/O/D/N=(nord) $weightStr,$zStr 226 Make10GaussPoints($weightStr,$zStr) 227 endif 228 break 229 case 20: 230 weightStr="gauss20wt" 231 zStr="gauss20z" 232 if (WaveExists($weightStr) == 0) 233 Make/O/D/N=(nord) $weightStr,$zStr 234 Make20GaussPoints($weightStr,$zStr) 235 endif 236 break 237 default: 238 Abort "Smear_2DModel_PP called with invalid nord value" 239 endswitch 240 241 Wave/Z wt = $weightStr 242 Wave/Z xi = $zStr 243 244 /// keep these waves local 245 // Make/O/D/N=1 yPtW 246 Make/O/D/N=(nord*nord) fcnRet,xptW,res_tot,yptW,wts 247 Make/O/D/N=(nord) phi_pt,qpl_pt,qperp_pt 248 249 // now just loop over the points as specified 250 num=numpnts(s.xw[0]) 251 252 answer=0 253 254 Variable spl,spp,apl,app,bpl,bpp 255 Variable phi_prime,q_prime 256 257 Variable t1=StopMSTimer(-2) 258 259 //loop over q-values 260 for(ii=0;ii<num;ii+=1) 261 262 // if(mod(ii, 1000 ) == 0) 263 // Print "ii= ",ii 264 // endif 265 266 qx = s.xw[0][ii] 267 qy = s.xw[1][ii] 268 qz = s.qz[ii] 269 qval = sqrt(qx^2+qy^2+qz^2) 270 spl = s.sQpl[ii] 271 spp = s.sQpp[ii] 272 fs = s.fs[ii] 273 274 normFactor = 2*pi*spl*spp 275 276 phi = -1*FindTheta(qx,qy) //Findtheta is an exact duplicate of FindPhi() * -1 277 278 apl = -numStdDev*spl + qval //parallel = q integration limits 279 bpl = numStdDev*spl + qval 280 /// app = -numStdDev*spp + phi //perpendicular = phi integration limits (WRONG) 281 /// bpp = numStdDev*spp + phi 282 app = -numStdDev*spp + 0 //q_perp = 0 283 bpp = numStdDev*spp + 0 284 285 //make sure the limits are reasonable. 286 if(apl < 0) 287 apl = 0 288 endif 289 // do I need to specially handle limits when phi ~ 0? 290 291 292 // sumOut = 0 293 for(jj=0;jj<nord;jj+=1) // call phi the "outer' 294 // phi_pt[jj] = (xi[jj]*(bpp-app)+app+bpp)/2 295 qperp_pt[jj] = (xi[jj]*(bpp-app)+app+bpp)/2 //this is now q_perp 296 297 // sumIn=0 298 for(kk=0;kk<nord;kk+=1) //at phi, integrate over Qpl 299 300 qpl_pt[kk] = (xi[kk]*(bpl-apl)+apl+bpl)/2 301 302 /// FindQxQy(qpl_pt[kk],phi_pt[jj],qx_pt,qy_pt) //find the corresponding QxQy to the Q,phi 303 304 // find QxQy given Qpl and Qperp on the grid 305 // 306 q_prime = sqrt(qpl_pt[kk]^2+qperp_pt[jj]^2) 307 phi_prime = phi + qperp_pt[jj]/qpl_pt[kk] 308 FindQxQy(q_prime,phi_prime,qx_pt,qy_pt) 309 310 yPtw[nord*jj+kk] = qy_pt //phi is the same in this loop, but qy is not 311 xPtW[nord*jj+kk] = qx_pt //qx is different here too, as we're varying Qpl 312 313 res_tot[nord*jj+kk] = exp(-0.5*( (qpl_pt[kk]-qval)^2/spl/spl + (qperp_pt[jj])^2/spp/spp ) ) 314 // res_tot[nord*jj+kk] = exp(-0.5*( (qpl_pt[kk]-qval)^2/spl/spl + (phi_pt[jj]-phi)^2/spp/spp ) ) 315 res_tot[nord*jj+kk] /= normFactor 316 // res_tot[kk] *= fs 317 318 //weighting 319 wts[nord*jj+kk] = wt[jj]*wt[kk] 320 endfor 321 322 endfor 323 324 fcn(s.coefW,fcnRet,xptw,yptw) //calculate nord*nord pts at a time 325 326 fcnRet *= wts*res_tot 327 // 328 answer = (bpl-apl)/2.0*sum(fcnRet) // get the sum, normalize to parallel direction 329 answer *= (bpp-app)/2.0 // and normalize to perpendicular direction 330 331 s.zw[ii] = answer 332 endfor 333 334 Variable elap = (StopMSTimer(-2) - t1)/1e6 335 Print "elapsed time = ",elap 336 337 return(0) 338 end 339 166 340 167 341 -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/Correct.ipf
r665 r794 103 103 //copy SAM information to COR, wiping out the old contents of the COR folder first 104 104 //do this even if no correction is dispatched (if incorrect mode) 105 // the Copy converts "SAM" to linear scale, so "COR" is then linear too 105 106 err = CopyWorkContents("SAM","COR") 106 107 if(err==1) … … 234 235 // data exists, checked by dispatch routine 235 236 // 237 // this is the most common use 238 // March 2011 added error propagation 239 // added explicit reference to use linear_data, instead of trusting that data 240 // was freshly loaded. added final copy of cor result to cor:data and cor:linear_data 241 // 236 242 Function CorrectMode_1() 237 243 238 244 //create the necessary wave references 239 WAVE sam_data=$"root:Packages:NIST:SAM: data"245 WAVE sam_data=$"root:Packages:NIST:SAM:linear_data" 240 246 WAVE sam_reals=$"root:Packages:NIST:SAM:realsread" 241 247 WAVE sam_ints=$"root:Packages:NIST:SAM:integersread" 242 248 WAVE/T sam_text=$"root:Packages:NIST:SAM:textread" 243 WAVE bgd_data=$"root:Packages:NIST:BGD: data"249 WAVE bgd_data=$"root:Packages:NIST:BGD:linear_data" 244 250 WAVE bgd_reals=$"root:Packages:NIST:BGD:realsread" 245 251 WAVE bgd_ints=$"root:Packages:NIST:BGD:integersread" 246 252 WAVE/T bgd_text=$"root:Packages:NIST:BGD:textread" 247 WAVE emp_data=$"root:Packages:NIST:EMP: data"253 WAVE emp_data=$"root:Packages:NIST:EMP:linear_data" 248 254 WAVE emp_reals=$"root:Packages:NIST:EMP:realsread" 249 255 WAVE emp_ints=$"root:Packages:NIST:EMP:integersread" 250 256 WAVE/T emp_text=$"root:Packages:NIST:EMP:textread" 251 WAVE cor_data=$"root:Packages:NIST:COR: data"257 WAVE cor_data=$"root:Packages:NIST:COR:linear_data" 252 258 WAVE/T cor_text=$"root:Packages:NIST:COR:textread" 259 260 // needed to propagate error 261 WAVE cor_data_display=$"root:Packages:NIST:COR:data" //just for the final copy 262 WAVE sam_err =$"root:Packages:NIST:SAM:linear_data_error" 263 WAVE bgd_err =$"root:Packages:NIST:BGD:linear_data_error" 264 WAVE emp_err =$"root:Packages:NIST:EMP:linear_data_error" 265 WAVE cor_err =$"root:Packages:NIST:COR:linear_data_error" 266 267 Variable sam_trans_err,emp_trans_err 268 sam_trans_err = sam_reals[41] 269 emp_trans_err = emp_reals[41] 270 253 271 254 272 //get sam and bgd attenuation factors … … 257 275 Variable tmonsam,fsam,fbgd,xshift,yshift,rsam,csam,rbgd,cbgd,tmonbgd 258 276 Variable wcen=0.001,tsam,temp,remp,cemp,tmonemp,femp 277 Variable sam_atten_err,emp_atten_err,bgd_atten_err 259 278 fileStr = sam_text[3] 260 279 lambda = sam_reals[26] 261 280 attenNo = sam_reals[3] 262 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )281 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,sam_atten_err) 263 282 fileStr = bgd_text[3] 264 283 lambda = bgd_reals[26] 265 284 attenNo = bgd_reals[3] 266 bgd_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )285 bgd_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,bgd_atten_err) 267 286 fileStr = emp_text[3] 268 287 lambda = emp_reals[26] 269 288 attenNo = emp_reals[3] 270 emp_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )289 emp_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,emp_atten_err) 271 290 272 291 //get relative monitor counts (should all be 10^8, since normalized in add step) … … 320 339 cor1 -= (tsam/temp)*(femp*emp_temp/emp_attenFactor - fbgd*bgd_temp/bgd_attenFactor) 321 340 cor1 *= noadd_bgd*noadd_emp //zero out the array mismatch values 341 342 // do the error propagation piecewise 343 Duplicate/O sam_err, tmp_a, tmp_b, tmp_c, tmp_d,c_val,d_val 344 tmp_a = (sam_err/sam_attenFactor)^2 + (sam_atten_err*sam_data/sam_attenFactor^2)^2 //sig a ^2 345 346 tmp_b = (bgd_err/bgd_attenFactor)^2*(tsam/temp - 1)^2 + (bgd_atten_err*bgd_data/bgd_attenFactor^2)^2*(1-tsam/temp)^2 //sig b ^2 347 348 tmp_c = (sam_trans_err/temp)^2*(emp_data/emp_attenFactor-bgd_data/bgd_attenFactor)^2 349 tmp_c += (tsam/temp^2)^2*emp_trans_err^2*(emp_data/emp_attenFactor-bgd_data/bgd_attenFactor)^2 350 351 tmp_d = (tsam/(temp*emp_attenFactor))^2*(emp_err)^2 + (tsam*emp_data/(temp*emp_attenFactor^2))^2*(emp_atten_err)^2 352 353 cor_err = sqrt(tmp_a + tmp_b + tmp_c + tmp_d) 322 354 323 355 //we're done, get out w/no error 324 //set the COR data to the result356 //set the COR data and linear_data to the result 325 357 cor_data = cor1 358 cor_data_display = cor1 359 326 360 //update COR header 327 361 cor_text[1] = date() + " " + time() //date + time stamp 328 362 329 363 KillWaves/Z cor1,bgd_temp,noadd_bgd,emp_temp,noadd_emp 364 Killwaves/Z tmp_a,tmp_b,tmp_c,tmp_d,c_val,d_val 330 365 SetDataFolder root: 331 366 Return(0) … … 338 373 339 374 //create the necessary wave references 340 WAVE sam_data=$"root:Packages:NIST:SAM: data"375 WAVE sam_data=$"root:Packages:NIST:SAM:linear_data" 341 376 WAVE sam_reals=$"root:Packages:NIST:SAM:realsread" 342 377 WAVE sam_ints=$"root:Packages:NIST:SAM:integersread" 343 378 WAVE/T sam_text=$"root:Packages:NIST:SAM:textread" 344 WAVE bgd_data=$"root:Packages:NIST:BGD: data"379 WAVE bgd_data=$"root:Packages:NIST:BGD:linear_data" 345 380 WAVE bgd_reals=$"root:Packages:NIST:BGD:realsread" 346 381 WAVE bgd_ints=$"root:Packages:NIST:BGD:integersread" 347 382 WAVE/T bgd_text=$"root:Packages:NIST:BGD:textread" 348 WAVE cor_data=$"root:Packages:NIST:COR: data"383 WAVE cor_data=$"root:Packages:NIST:COR:linear_data" 349 384 WAVE/T cor_text=$"root:Packages:NIST:COR:textread" 385 386 // needed to propagate error 387 WAVE cor_data_display=$"root:Packages:NIST:COR:data" //just for the final copy 388 WAVE sam_err =$"root:Packages:NIST:SAM:linear_data_error" 389 WAVE bgd_err =$"root:Packages:NIST:BGD:linear_data_error" 390 WAVE cor_err =$"root:Packages:NIST:COR:linear_data_error" 391 392 Variable sam_trans_err 393 sam_trans_err = sam_reals[41] 394 350 395 351 396 //get sam and bgd attenuation factors … … 354 399 Variable tmonsam,fsam,fbgd,xshift,yshift,rsam,csam,rbgd,cbgd,tmonbgd 355 400 Variable wcen=0.001 401 Variable sam_atten_err,bgd_atten_err 356 402 fileStr = sam_text[3] 357 403 lambda = sam_reals[26] 358 404 attenNo = sam_reals[3] 359 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )405 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,sam_atten_err) 360 406 fileStr = bgd_text[3] 361 407 lambda = bgd_reals[26] 362 408 attenNo = bgd_reals[3] 363 bgd_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )409 bgd_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,bgd_atten_err) 364 410 365 411 //Print "atten = ",sam_attenFactor,bgd_attenFactor … … 398 444 cor1 *= noadd_bgd //zeros out regions where arrays do not overlap, one otherwise 399 445 446 // do the error propagation piecewise 447 Duplicate/O sam_err, tmp_a, tmp_b 448 tmp_a = (sam_err/sam_attenFactor)^2 + (sam_atten_err*sam_data/sam_attenFactor^2)^2 //sig a ^2 449 450 tmp_b = (bgd_err/bgd_attenFactor)^2 + (bgd_atten_err*bgd_data/bgd_attenFactor^2)^2 //sig b ^2 451 452 cor_err = sqrt(tmp_a + tmp_b) 453 454 400 455 //we're done, get out w/no error 401 456 //set the COR_data to the result 402 457 cor_data = cor1 458 cor_data_display = cor1 459 403 460 //update COR header 404 461 cor_text[1] = date() + " " + time() //date + time stamp 405 462 406 463 KillWaves/Z cor1,bgd_temp,noadd_bgd 464 Killwaves/Z tmp_a,tmp_b 465 407 466 SetDataFolder root: 408 467 Return(0) … … 414 473 Function CorrectMode_3() 415 474 //create the necessary wave references 416 WAVE sam_data=$"root:Packages:NIST:SAM: data"475 WAVE sam_data=$"root:Packages:NIST:SAM:linear_data" 417 476 WAVE sam_reals=$"root:Packages:NIST:SAM:realsread" 418 477 WAVE sam_ints=$"root:Packages:NIST:SAM:integersread" 419 478 WAVE/T sam_text=$"root:Packages:NIST:SAM:textread" 420 WAVE emp_data=$"root:Packages:NIST:EMP: data"479 WAVE emp_data=$"root:Packages:NIST:EMP:linear_data" 421 480 WAVE emp_reals=$"root:Packages:NIST:EMP:realsread" 422 481 WAVE emp_ints=$"root:Packages:NIST:EMP:integersread" 423 482 WAVE/T emp_text=$"root:Packages:NIST:EMP:textread" 424 WAVE cor_data=$"root:Packages:NIST:COR: data"483 WAVE cor_data=$"root:Packages:NIST:COR:linear_data" 425 484 WAVE/T cor_text=$"root:Packages:NIST:COR:textread" 485 486 // needed to propagate error 487 WAVE cor_data_display=$"root:Packages:NIST:COR:data" //just for the final copy 488 WAVE sam_err =$"root:Packages:NIST:SAM:linear_data_error" 489 WAVE emp_err =$"root:Packages:NIST:EMP:linear_data_error" 490 WAVE cor_err =$"root:Packages:NIST:COR:linear_data_error" 491 492 Variable sam_trans_err,emp_trans_err 493 sam_trans_err = sam_reals[41] 494 emp_trans_err = emp_reals[41] 426 495 427 496 //get sam and bgd attenuation factors … … 430 499 Variable tmonsam,fsam,femp,xshift,yshift,rsam,csam,remp,cemp,tmonemp 431 500 Variable wcen=0.001,tsam,temp 501 Variable sam_atten_err,emp_atten_err 432 502 fileStr = sam_text[3] 433 503 lambda = sam_reals[26] 434 504 attenNo = sam_reals[3] 435 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )505 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,sam_atten_err) 436 506 fileStr = emp_text[3] 437 507 lambda = emp_reals[26] 438 508 attenNo = emp_reals[3] 439 emp_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )509 emp_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,emp_atten_err) 440 510 441 511 //get relative monitor counts (should all be 10^8, since normalized in add step) … … 478 548 cor1 *= noadd_emp //zeros out regions where arrays do not overlap, one otherwise 479 549 550 // do the error propagation piecewise 551 Duplicate/O sam_err, tmp_a, tmp_c ,c_val 552 tmp_a = (sam_err/sam_attenFactor)^2 + (sam_atten_err*sam_data/sam_attenFactor^2)^2 //sig a ^2 553 554 tmp_c = (sam_trans_err*emp_data/(temp*emp_attenFactor))^2 + (emp_err*tsam/(temp*emp_attenFactor))^2 555 tmp_c += (tsam*emp_data*emp_trans_err/(temp*temp*emp_attenFactor))^2 + (tsam*emp_data*emp_atten_err/(temp*emp_attenFactor^2))^2//total of 6 terms 556 557 cor_err = sqrt(tmp_a + tmp_c) 558 480 559 //we're done, get out w/no error 481 560 //set the COR data to the result 482 561 cor_data = cor1 562 cor_data_display = cor1 563 483 564 //update COR header 484 565 cor_text[1] = date() + " " + time() //date + time stamp 485 566 486 567 KillWaves/Z cor1,emp_temp,noadd_emp 568 Killwaves/Z tmp_a,tmp_c,c_val 569 487 570 SetDataFolder root: 488 571 Return(0) … … 496 579 Function CorrectMode_4() 497 580 //create the necessary wave references 498 WAVE sam_data=$"root:Packages:NIST:SAM: data"581 WAVE sam_data=$"root:Packages:NIST:SAM:linear_data" 499 582 WAVE sam_reals=$"root:Packages:NIST:SAM:realsread" 500 583 WAVE sam_ints=$"root:Packages:NIST:SAM:integersread" 501 584 WAVE/T sam_text=$"root:Packages:NIST:SAM:textread" 502 585 503 WAVE cor_data=$"root:Packages:NIST:COR: data"586 WAVE cor_data=$"root:Packages:NIST:COR:linear_data" 504 587 WAVE/T cor_text=$"root:Packages:NIST:COR:textread" 505 588 589 // needed to propagate error 590 WAVE cor_data_display=$"root:Packages:NIST:COR:data" //just for the final copy 591 WAVE sam_err =$"root:Packages:NIST:SAM:linear_data_error" 592 WAVE cor_err =$"root:Packages:NIST:COR:linear_data_error" 593 506 594 //get sam and bgd attenuation factors 507 595 String fileStr="" 508 Variable lambda,attenNo,sam_AttenFactor 596 Variable lambda,attenNo,sam_AttenFactor,sam_atten_err 509 597 fileStr = sam_text[3] 510 598 lambda = sam_reals[26] 511 599 attenNo = sam_reals[3] 512 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )600 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,sam_atten_err) 513 601 514 602 NVAR pixelsX = root:myGlobals:gNPixelsX … … 518 606 cor1 = sam_data/sam_AttenFactor //simply rescale the data 519 607 608 // do the error propagation piecewise 609 Duplicate/O sam_err, tmp_a 610 tmp_a = (sam_err/sam_attenFactor)^2 + (sam_atten_err*sam_data/sam_attenFactor^2)^2 //sig a ^2 611 612 cor_err = sqrt(tmp_a) 613 614 520 615 //we're done, get out w/no error 521 616 //set the COR data to the result 522 617 cor_data = cor1 618 cor_data_display = cor1 619 523 620 //update COR header 524 621 cor_text[1] = date() + " " + time() //date + time stamp 525 622 526 623 KillWaves/Z cor1 624 Killwaves/Z tmp_a 625 527 626 SetDataFolder root: 528 627 Return(0) … … 531 630 Function CorrectMode_11() 532 631 //create the necessary wave references 533 WAVE sam_data=$"root:Packages:NIST:SAM: data"632 WAVE sam_data=$"root:Packages:NIST:SAM:linear_data" 534 633 WAVE sam_reals=$"root:Packages:NIST:SAM:realsread" 535 634 WAVE sam_ints=$"root:Packages:NIST:SAM:integersread" 536 635 WAVE/T sam_text=$"root:Packages:NIST:SAM:textread" 537 WAVE bgd_data=$"root:Packages:NIST:BGD: data"636 WAVE bgd_data=$"root:Packages:NIST:BGD:linear_data" 538 637 WAVE bgd_reals=$"root:Packages:NIST:BGD:realsread" 539 638 WAVE bgd_ints=$"root:Packages:NIST:BGD:integersread" 540 639 WAVE/T bgd_text=$"root:Packages:NIST:BGD:textread" 541 WAVE emp_data=$"root:Packages:NIST:EMP: data"640 WAVE emp_data=$"root:Packages:NIST:EMP:linear_data" 542 641 WAVE emp_reals=$"root:Packages:NIST:EMP:realsread" 543 642 WAVE emp_ints=$"root:Packages:NIST:EMP:integersread" 544 643 WAVE/T emp_text=$"root:Packages:NIST:EMP:textread" 545 WAVE drk_data=$"root:Packages:NIST:DRK: data"644 WAVE drk_data=$"root:Packages:NIST:DRK:linear_data" 546 645 WAVE drk_reals=$"root:Packages:NIST:DRK:realsread" 547 646 WAVE drk_ints=$"root:Packages:NIST:DRK:integersread" 548 647 WAVE/T drk_text=$"root:Packages:NIST:DRK:textread" 549 WAVE cor_data=$"root:Packages:NIST:COR: data"648 WAVE cor_data=$"root:Packages:NIST:COR:linear_data" 550 649 WAVE/T cor_text=$"root:Packages:NIST:COR:textread" 650 651 // needed to propagate error 652 WAVE cor_data_display=$"root:Packages:NIST:COR:data" //just for the final copy 653 WAVE sam_err =$"root:Packages:NIST:SAM:linear_data_error" 654 WAVE bgd_err =$"root:Packages:NIST:BGD:linear_data_error" 655 WAVE emp_err =$"root:Packages:NIST:EMP:linear_data_error" 656 WAVE drk_err =$"root:Packages:NIST:DRK:linear_data_error" 657 WAVE cor_err =$"root:Packages:NIST:COR:linear_data_error" 658 659 Variable sam_trans_err,emp_trans_err 660 sam_trans_err = sam_reals[41] 661 emp_trans_err = emp_reals[41] 551 662 552 663 //get sam and bgd attenuation factors … … 555 666 Variable tmonsam,fsam,fbgd,xshift,yshift,rsam,csam,rbgd,cbgd,tmonbgd 556 667 Variable wcen=0.001,tsam,temp,remp,cemp,tmonemp,femp,time_sam,time_drk,savmon_sam 668 Variable sam_atten_err,bgd_atten_err,emp_atten_err 557 669 fileStr = sam_text[3] 558 670 lambda = sam_reals[26] 559 671 attenNo = sam_reals[3] 560 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )672 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,sam_atten_err) 561 673 fileStr = bgd_text[3] 562 674 lambda = bgd_reals[26] 563 675 attenNo = bgd_reals[3] 564 bgd_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )676 bgd_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,bgd_atten_err) 565 677 fileStr = emp_text[3] 566 678 lambda = emp_reals[26] 567 679 attenNo = emp_reals[3] 568 emp_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )680 emp_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,emp_atten_err) 569 681 570 682 //get relative monitor counts (should all be 10^8, since normalized in add step) … … 587 699 NVAR pixelsY = root:myGlobals:gNPixelsY 588 700 //rescale drk to sam cnt time and then multiply by the same monitor scaling as SAM 589 Make/D/O/N=(pixelsX,pixelsY) drk_temp 701 Make/D/O/N=(pixelsX,pixelsY) drk_temp, drk_tmp_err 590 702 drk_temp = drk_data*(time_sam/time_drk)*(tmonsam/savmon_sam) 703 drk_tmp_err *= drk_err*(time_sam/time_drk)*(tmonsam/savmon_sam) //temporarily rescale the error of DRK 591 704 592 705 if(temp==0) … … 628 741 cor1 *= noadd_bgd*noadd_emp //zero out the array mismatch values 629 742 743 // do the error propagation piecewise 744 Duplicate/O sam_err, tmp_a, tmp_b, tmp_c, tmp_d,c_val,d_val 745 tmp_a = (sam_err/sam_attenFactor)^2 + (sam_atten_err*sam_data/sam_attenFactor^2)^2 //sig a ^2 746 747 tmp_b = (bgd_err/bgd_attenFactor)^2*(tsam/temp - 1)^2 + (bgd_atten_err*bgd_data/bgd_attenFactor^2)^2*(1-tsam/temp)^2 //sig b ^2 748 749 tmp_c = (sam_trans_err/temp)^2*(emp_data/emp_attenFactor-bgd_data/bgd_attenFactor)^2 750 tmp_c += (tsam/temp^2)^2*emp_trans_err^2*(emp_data/emp_attenFactor-bgd_data/bgd_attenFactor)^2 751 752 tmp_d = (tsam/(temp*emp_attenFactor))^2*(emp_err)^2 + (tsam*emp_data/(temp*emp_attenFactor^2))^2*(emp_atten_err)^2 753 754 cor_err = sqrt(tmp_a + tmp_b + tmp_c + tmp_d + drk_tmp_err^2) 755 630 756 //we're done, get out w/no error 631 757 //set the COR data to the result 632 758 cor_data = cor1 759 cor_data_display = cor1 760 633 761 //update COR header 634 762 cor_text[1] = date() + " " + time() //date + time stamp 635 763 636 764 KillWaves/Z cor1,bgd_temp,noadd_bgd,emp_temp,noadd_emp,drk_temp 765 Killwaves/Z tmp_a,tmp_b,tmp_c,tmp_d,c_val,d_val,drk_tmp_err 766 637 767 SetDataFolder root: 638 768 Return(0) … … 643 773 Function CorrectMode_12() 644 774 //create the necessary wave references 645 WAVE sam_data=$"root:Packages:NIST:SAM: data"775 WAVE sam_data=$"root:Packages:NIST:SAM:linear_data" 646 776 WAVE sam_reals=$"root:Packages:NIST:SAM:realsread" 647 777 WAVE sam_ints=$"root:Packages:NIST:SAM:integersread" 648 778 WAVE/T sam_text=$"root:Packages:NIST:SAM:textread" 649 WAVE bgd_data=$"root:Packages:NIST:BGD: data"779 WAVE bgd_data=$"root:Packages:NIST:BGD:linear_data" 650 780 WAVE bgd_reals=$"root:Packages:NIST:BGD:realsread" 651 781 WAVE bgd_ints=$"root:Packages:NIST:BGD:integersread" 652 782 WAVE/T bgd_text=$"root:Packages:NIST:BGD:textread" 653 WAVE drk_data=$"root:Packages:NIST:DRK: data"783 WAVE drk_data=$"root:Packages:NIST:DRK:linear_data" 654 784 WAVE drk_reals=$"root:Packages:NIST:DRK:realsread" 655 785 WAVE drk_ints=$"root:Packages:NIST:DRK:integersread" 656 786 WAVE/T drk_text=$"root:Packages:NIST:DRK:textread" 657 WAVE cor_data=$"root:Packages:NIST:COR: data"787 WAVE cor_data=$"root:Packages:NIST:COR:linear_data" 658 788 WAVE/T cor_text=$"root:Packages:NIST:COR:textread" 789 790 // needed to propagate error 791 WAVE cor_data_display=$"root:Packages:NIST:COR:data" //just for the final copy 792 WAVE sam_err =$"root:Packages:NIST:SAM:linear_data_error" 793 WAVE bgd_err =$"root:Packages:NIST:BGD:linear_data_error" 794 WAVE drk_err =$"root:Packages:NIST:DRK:linear_data_error" 795 WAVE cor_err =$"root:Packages:NIST:COR:linear_data_error" 796 797 Variable sam_trans_err 798 sam_trans_err = sam_reals[41] 799 659 800 660 801 //get sam and bgd attenuation factors … … 663 804 Variable tmonsam,fsam,fbgd,xshift,yshift,rsam,csam,rbgd,cbgd,tmonbgd 664 805 Variable wcen=0.001,time_drk,time_sam,savmon_sam,tsam 806 Variable sam_atten_err,bgd_atten_err 665 807 fileStr = sam_text[3] 666 808 lambda = sam_reals[26] 667 809 attenNo = sam_reals[3] 668 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )810 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,sam_atten_err) 669 811 fileStr = bgd_text[3] 670 812 lambda = bgd_reals[26] 671 813 attenNo = bgd_reals[3] 672 bgd_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )814 bgd_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,bgd_atten_err) 673 815 674 816 //get relative monitor counts (should all be 10^8, since normalized in add step) … … 687 829 NVAR pixelsY = root:myGlobals:gNPixelsY 688 830 //rescale drk to sam cnt time and then multiply by the same monitor scaling as SAM 689 Make/D/O/N=(pixelsX,pixelsY) drk_temp 831 Make/D/O/N=(pixelsX,pixelsY) drk_temp,drk_tmp_err 690 832 drk_temp = drk_data*(time_sam/time_drk)*(tmonsam/savmon_sam) 691 833 drk_tmp_err *= drk_err*(time_sam/time_drk)*(tmonsam/savmon_sam) //temporarily rescale the error of DRK 834 692 835 // set up beamcenter shift, relative to SAM 693 836 xshift = cbgd-csam … … 712 855 cor1 *= noadd_bgd //zeros out regions where arrays do not overlap, one otherwise 713 856 857 // do the error propagation piecewise 858 Duplicate/O sam_err, tmp_a, tmp_b 859 tmp_a = (sam_err/sam_attenFactor)^2 + (sam_atten_err*sam_data/sam_attenFactor^2)^2 //sig a ^2 860 861 tmp_b = (bgd_err/bgd_attenFactor)^2 + (bgd_atten_err*bgd_data/bgd_attenFactor^2)^2 //sig b ^2 862 863 cor_err = sqrt(tmp_a + tmp_b + drk_tmp_err^2) 864 714 865 //we're done, get out w/no error 715 866 //set the COR_data to the result 716 867 cor_data = cor1 868 cor_data_display = cor1 869 717 870 //update COR header 718 871 cor_text[1] = date() + " " + time() //date + time stamp 719 872 720 // KillWaves/Z cor1,bgd_temp,noadd_bgd,drk_temp 873 KillWaves/Z cor1,bgd_temp,noadd_bgd,drk_temp 874 Killwaves/Z tmp_a,tmp_b,drk_tmp_err 875 721 876 SetDataFolder root: 722 877 Return(0) … … 729 884 Function CorrectMode_13() 730 885 //create the necessary wave references 731 WAVE sam_data=$"root:Packages:NIST:SAM: data"886 WAVE sam_data=$"root:Packages:NIST:SAM:linear_data" 732 887 WAVE sam_reals=$"root:Packages:NIST:SAM:realsread" 733 888 WAVE sam_ints=$"root:Packages:NIST:SAM:integersread" 734 889 WAVE/T sam_text=$"root:Packages:NIST:SAM:textread" 735 WAVE emp_data=$"root:Packages:NIST:EMP: data"890 WAVE emp_data=$"root:Packages:NIST:EMP:linear_data" 736 891 WAVE emp_reals=$"root:Packages:NIST:EMP:realsread" 737 892 WAVE emp_ints=$"root:Packages:NIST:EMP:integersread" 738 893 WAVE/T emp_text=$"root:Packages:NIST:EMP:textread" 739 WAVE drk_data=$"root: DRK:data"740 WAVE drk_reals=$"root: DRK:realsread"741 WAVE drk_ints=$"root: DRK:integersread"742 WAVE/T drk_text=$"root: DRK:textread"743 WAVE cor_data=$"root:Packages:NIST:COR: data"894 WAVE drk_data=$"root:Packages:NIST:DRK:linear_data" 895 WAVE drk_reals=$"root:Packages:NIST:DRK:realsread" 896 WAVE drk_ints=$"root:Packages:NIST:DRK:integersread" 897 WAVE/T drk_text=$"root:Packages:NIST:DRK:textread" 898 WAVE cor_data=$"root:Packages:NIST:COR:linear_data" 744 899 WAVE/T cor_text=$"root:Packages:NIST:COR:textread" 900 901 // needed to propagate error 902 WAVE cor_data_display=$"root:Packages:NIST:COR:data" //just for the final copy 903 WAVE sam_err =$"root:Packages:NIST:SAM:linear_data_error" 904 WAVE emp_err =$"root:Packages:NIST:EMP:linear_data_error" 905 WAVE drk_err =$"root:Packages:NIST:DRK:linear_data_error" 906 WAVE cor_err =$"root:Packages:NIST:COR:linear_data_error" 907 908 Variable sam_trans_err,emp_trans_err 909 sam_trans_err = sam_reals[41] 910 emp_trans_err = emp_reals[41] 745 911 746 912 //get sam and bgd attenuation factors (DRK irrelevant) … … 749 915 Variable tmonsam,fsam,femp,xshift,yshift,rsam,csam,remp,cemp,tmonemp 750 916 Variable wcen=0.001,tsam,temp,savmon_sam,time_sam,time_drk 917 Variable sam_atten_err,emp_atten_err 751 918 fileStr = sam_text[3] 752 919 lambda = sam_reals[26] 753 920 attenNo = sam_reals[3] 754 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )921 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,sam_atten_err) 755 922 fileStr = emp_text[3] 756 923 lambda = emp_reals[26] 757 924 attenNo = emp_reals[3] 758 emp_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )925 emp_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,emp_atten_err) 759 926 760 927 //get relative monitor counts (should all be 10^8, since normalized in add step) … … 774 941 NVAR pixelsY = root:myGlobals:gNPixelsY 775 942 //rescale drk to sam cnt time and then multiply by the same monitor scaling as SAM 776 Make/D/O/N=(pixelsX,pixelsY) drk_temp 943 Make/D/O/N=(pixelsX,pixelsY) drk_temp,drk_tmp_err 777 944 drk_temp = drk_data*(time_sam/time_drk)*(tmonsam/savmon_sam) 945 drk_tmp_err *= drk_err*(time_sam/time_drk)*(tmonsam/savmon_sam) //temporarily rescale the error of DRK 946 778 947 779 948 if(temp==0) … … 805 974 cor1 *= noadd_emp //zeros out regions where arrays do not overlap, one otherwise 806 975 976 // do the error propagation piecewise 977 Duplicate/O sam_err, tmp_a, tmp_c, c_val 978 tmp_a = (sam_err/sam_attenFactor)^2 + (sam_atten_err*sam_data/sam_attenFactor^2)^2 //sig a ^2 979 980 tmp_c = (sam_trans_err*emp_data/(temp*emp_attenFactor))^2 + (emp_err*tsam/(temp*emp_attenFactor))^2 981 tmp_c += (tsam*emp_data*emp_trans_err/(temp*temp*emp_attenFactor))^2 + (tsam*emp_data*emp_atten_err/(temp*emp_attenFactor^2))^2//total of 6 terms 982 983 cor_err = sqrt(tmp_a + tmp_c + drk_tmp_err^2) 984 807 985 //we're done, get out w/no error 808 986 //set the COR data to the result 809 987 cor_data = cor1 988 cor_data_display = cor1 989 810 990 //update COR header 811 991 cor_text[1] = date() + " " + time() //date + time stamp 812 992 813 993 KillWaves/Z cor1,emp_temp,noadd_emp,drk_temp 994 Killwaves/Z tmp_a,tmp_c,c_val,drk_tmp_err 995 814 996 SetDataFolder root: 815 997 Return(0) … … 820 1002 Function CorrectMode_14() 821 1003 //create the necessary wave references 822 WAVE sam_data=$"root:Packages:NIST:SAM: data"1004 WAVE sam_data=$"root:Packages:NIST:SAM:linear_data" 823 1005 WAVE sam_reals=$"root:Packages:NIST:SAM:realsread" 824 1006 WAVE sam_ints=$"root:Packages:NIST:SAM:integersread" 825 1007 WAVE/T sam_text=$"root:Packages:NIST:SAM:textread" 826 827 WAVE drk_data=$"root:DRK:data" 828 WAVE drk_reals=$"root:DRK:realsread" 829 WAVE drk_ints=$"root:DRK:integersread" 830 WAVE/T drk_text=$"root:DRK:textread" 831 WAVE cor_data=$"root:Packages:NIST:COR:data" 1008 WAVE drk_data=$"root:Packages:NIST:DRK:linear_data" 1009 WAVE drk_reals=$"root:Packages:NIST:DRK:realsread" 1010 WAVE drk_ints=$"root:Packages:NIST:DRK:integersread" 1011 WAVE/T drk_text=$"root:Packages:NIST:DRK:textread" 1012 WAVE cor_data=$"root:Packages:NIST:COR:linear_data" 832 1013 WAVE/T cor_text=$"root:Packages:NIST:COR:textread" 1014 1015 // needed to propagate error 1016 WAVE cor_data_display=$"root:Packages:NIST:COR:data" //just for the final copy 1017 WAVE sam_err =$"root:Packages:NIST:SAM:linear_data_error" 1018 WAVE drk_err =$"root:Packages:NIST:DRK:linear_data_error" 1019 WAVE cor_err =$"root:Packages:NIST:COR:linear_data_error" 1020 1021 Variable sam_trans_err 1022 sam_trans_err = sam_reals[41] 1023 833 1024 834 1025 //get sam and bgd attenuation factors … … 837 1028 Variable tmonsam,fsam,fbgd,xshift,yshift,rsam,csam,rbgd,cbgd,tmonbgd 838 1029 Variable wcen=0.001,time_drk,time_sam,savmon_sam,tsam 1030 Variable sam_atten_err 839 1031 fileStr = sam_text[3] 840 1032 lambda = sam_reals[26] 841 1033 attenNo = sam_reals[3] 842 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo )1034 sam_AttenFactor = AttenuationFactor(fileStr,lambda,AttenNo,sam_atten_err) 843 1035 844 1036 //get relative monitor counts (should all be 10^8, since normalized in add step) … … 855 1047 NVAR pixelsY = root:myGlobals:gNPixelsY 856 1048 //rescale drk to sam cnt time and then multiply by the same monitor scaling as SAM 857 Make/D/O/N=(pixelsX,pixelsY) drk_temp 1049 Make/D/O/N=(pixelsX,pixelsY) drk_temp,drk_tmp_err 858 1050 drk_temp = drk_data*(time_sam/time_drk)*(tmonsam/savmon_sam) 859 1051 drk_tmp_err *= drk_err*(time_sam/time_drk)*(tmonsam/savmon_sam) //temporarily rescale the error of DRK 1052 860 1053 Make/D/O/N=(pixelsX,pixelsY) cor1 //temp arrays 861 1054 //always ignore the DRK center shift … … 868 1061 cor1 = fsam*sam_data/sam_AttenFactor - drk_temp/sam_attenFactor 869 1062 1063 // do the error propagation piecewise 1064 Duplicate/O sam_err, tmp_a 1065 tmp_a = (sam_err/sam_attenFactor)^2 + (sam_atten_err*sam_data/sam_attenFactor^2)^2 //sig a ^2 1066 1067 cor_err = sqrt(tmp_a + drk_tmp_err^2) 1068 870 1069 //we're done, get out w/no error 871 1070 //set the COR_data to the result 872 1071 cor_data = cor1 1072 cor_data_display = cor1 1073 873 1074 //update COR header 874 1075 cor_text[1] = date() + " " + time() //date + time stamp 875 1076 876 // KillWaves/Z cor1,bgd_temp,noadd_bgd,drk_temp 1077 KillWaves/Z cor1,bgd_temp,noadd_bgd,drk_temp 1078 Killwaves/Z tmp_a,tmp_b,tmp_c,tmp_d,c_val,d_val,drk_tmp_err 1079 877 1080 SetDataFolder root: 878 1081 Return(0) … … 1138 1341 Variable SamAttenFactor,lambda,attenNo,err=0 1139 1342 String samfileStr="" 1343 Variable sam_atten_err 1140 1344 samfileStr = sam_text[3] 1141 1345 lambda = sam_reals[26] 1142 1346 attenNo = sam_reals[3] 1143 SamAttenFactor = AttenuationFactor(samFileStr,lambda,AttenNo )1347 SamAttenFactor = AttenuationFactor(samFileStr,lambda,AttenNo,sam_atten_err) 1144 1348 //if sample trans is zero, do only SAM-BGD subtraction (notify the user) 1145 1349 Variable sam_trans = sam_reals[4] -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/Marquee.ipf
r788 r794 26 26 // accepts arbitrary detector coordinates. calling function is responsible for 27 27 // keeping selection in bounds 28 Function SumCountsInBox(x1,x2,y1,y2, type)29 Variable x1,x2,y1,y2 28 Function SumCountsInBox(x1,x2,y1,y2,ct_err,type) 29 Variable x1,x2,y1,y2,&ct_err 30 30 String type 31 31 32 Variable counts = 0,ii,jj 32 Variable counts = 0,ii,jj,err2_sum 33 33 34 34 String dest = "root:Packages:NIST:"+type … … 41 41 wave w=$(dest + ":data") 42 42 endif 43 43 wave data_err = $(dest + ":linear_data_error") 44 45 err2_sum = 0 // running total of the squared error 44 46 ii=x1 45 47 jj=y1 … … 47 49 do 48 50 counts += w[ii][jj] 51 err2_sum += data_err[ii][jj]*data_err[ii][jj] 49 52 jj+=1 50 53 while(jj<=y2) … … 52 55 ii+=1 53 56 while(ii<=x2) 57 58 err2_sum = sqrt(err2_sum) 59 ct_err = err2_sum 60 61 // Print "error = ",err2_sum 62 // Print "error/counts = ",err2_sum/counts 63 54 64 55 65 Return (counts) … … 113 123 //to the same monitor counts and corrected for detector deadtime 114 124 String type = "SAM" 115 Variable counts 116 counts = SumCountsInBox(x1,x2,y1,y2,type) 117 Print " marquee counts =",counts 125 Variable counts,ct_err 126 counts = SumCountsInBox(x1,x2,y1,y2,ct_err,type) 127 // Print "marquee counts =",counts 128 // Print "relative error = ",ct_err/counts 129 118 130 //Set the global gTransCts 119 131 Variable/G root:myGlobals:Patch:gTransCts = counts … … 148 160 WriteBoxCountsToHeader(filename,counts) 149 161 162 WriteBoxCountsErrorToHeader(filename,ct_err) 163 164 return(0) 150 165 End 151 166 … … 315 330 //parse the list of file numbers 316 331 String fileList="",item="",pathStr="",fullPath="" 317 Variable ii,num,err,cts 332 Variable ii,num,err,cts,ct_err 318 333 319 334 PathInfo catPathName … … 330 345 //sum over the box 331 346 //print the results 332 Make/O/N=(num) FileID,BoxCounts 347 Make/O/N=(num) FileID,BoxCounts,BoxCount_err 333 348 Print "Results are stored in root:FileID and root:BoxCounts waves" 334 349 for(ii=0;ii<num;ii+=1) … … 344 359 String/G root:myGlobals:gDataDisplayType=type 345 360 fRawWindowHook() 346 cts=SumCountsInBox(x1,x2,y1,y2, type)361 cts=SumCountsInBox(x1,x2,y1,y2,ct_err,type) 347 362 BoxCounts[ii]=cts 363 BoxCount_err[ii]=ct_err 348 364 Print item+" counts = ",cts 349 365 endfor 350 366 351 DoBoxGraph(FileID,BoxCounts )367 DoBoxGraph(FileID,BoxCounts,BoxCount_err) 352 368 353 369 return(0) 354 370 End 355 371 356 Function DoBoxGraph(FileID,BoxCounts )357 Wave FileID,BoxCounts 372 Function DoBoxGraph(FileID,BoxCounts,BoxCount_err) 373 Wave FileID,BoxCounts,BoxCount_err 358 374 359 375 Sort FileID BoxCounts,FileID //sort the waves, in case the run numbers were entered out of numerical order … … 364 380 ModifyGraph grid=2 365 381 ModifyGraph mirror=2 382 ErrorBars/T=0 BoxCounts Y,wave=(BoxCount_err,BoxCount_err) 366 383 Label left "Counts (per 10^8 monitor counts)" 367 384 Label bottom "Run Number" … … 561 578 Print "There is no Marquee" 562 579 else 563 Variable count,x1,x2,y1,y2 580 Variable count,x1,x2,y1,y2,ct_err 564 581 x1 = V_left 565 582 x2 = V_right … … 574 591 KeepSelectionInBounds(x1,x2,y1,y2) 575 592 SVAR cur_folder=root:myGlobals:gDataDisplayType 576 count = SumCountsInBox(x1,x2,y1,y2,cur_folder) 577 Print "counts = "+ num2str(count) 593 count = SumCountsInBox(x1,x2,y1,y2,ct_err,cur_folder) 594 Print "counts = ",count 595 Print "err/counts = ",ct_err/count 578 596 endif 579 597 End -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/NCNR_DataReadWrite.ipf
r776 r794 369 369 370 370 Duplicate/O data linear_data // at this point, the data is still the raw data, and is linear_data 371 372 // proper error for counting statistics, good for low count values too 373 // rather than just sqrt(n) 374 // see N. Gehrels, Astrophys. J., 303 (1986) 336-346, equation (7) 375 // for S = 1 in eq (7), this corresponds to one sigma error bars 376 Duplicate/O linear_data linear_data_error 377 linear_data_error = 1 + sqrt(linear_data + 0.75) 371 378 // 372 379 … … 759 766 760 767 //read in the data 761 768 GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" 762 769 763 770 curPath = "root:Packages:NIST:"+cur_folder … … 904 911 Redimension/N=(pixelsX,pixelsY) data //,linear_data 905 912 913 Duplicate/O data linear_data_error 914 linear_data_error = 1 + sqrt(data + 0.75) 915 916 //just in case there are odd inputs to this, like negative intensities 917 WaveStats/Q linear_data_error 918 linear_data_error = numtype(linear_data_error[p]) == 0 ? linear_data_error[p] : V_avg 919 linear_data_error = linear_data_error[p] != 0 ? linear_data_error[p] : V_avg 920 906 921 //linear_data = data 907 922 … … 1082 1097 End 1083 1098 1099 //sample transmission error (one sigma) is a real value at byte 396 1100 Function WriteTransmissionErrorToHeader(fname,transErr) 1101 String fname 1102 Variable transErr 1103 1104 WriteVAXReal(fname,transErr,396) //transmission start byte is 396 1105 return(0) 1106 End 1107 1108 1084 1109 //whole transmission is a real value at byte 392 1085 1110 Function WriteWholeTransToHeader(fname,trans) … … 1097 1122 1098 1123 WriteVAXReal(fname,counts,494) // start byte is 494 1124 return(0) 1125 End 1126 1127 //box sum counts error is is a real value at byte 400 1128 Function WriteBoxCountsErrorToHeader(fname,rel_err) 1129 String fname 1130 Variable rel_err 1131 1132 WriteVAXReal(fname,rel_err,400) // start byte is 400 1099 1133 return(0) 1100 1134 End … … 1493 1527 end 1494 1528 1529 //transmission error (one sigma) is at byte 396 1530 Function getSampleTransError(fname) 1531 String fname 1532 1533 return(getRealValueFromHeader(fname,396)) 1534 end 1535 1495 1536 //box counts are stored at byte 494 1496 1537 Function getBoxCounts(fname) … … 1499 1540 return(getRealValueFromHeader(fname,494)) 1500 1541 end 1542 1543 //box counts error are stored at byte 400 1544 Function getBoxCountsError(fname) 1545 String fname 1546 1547 return(getRealValueFromHeader(fname,400)) 1548 end 1549 1501 1550 1502 1551 //whole detector trasmission is at byte 392 -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/NCNR_Utils.ipf
r788 r794 151 151 SigmaQ = QBar*sqrt(v_r/rmd^2 +v_lambda) 152 152 153 154 // more readable method for calculating the variance in Q 155 // EXCEPT - this is calculated for Qo, NOT qBar 156 // (otherwise, they are nearly equivalent, except for close to the beam stop) 157 // Variable kap,a_val,a_val_l2,m_h 158 // g = 981.0 //gravity acceleration [cm/s^2] 159 // m_h = 252.8 // m/h [=] s/cm^2 160 // 161 // kap = 2*pi/lambda 162 // a_val = L2*(L1+L2)*g/2*(m_h)^2 163 // a_val_L2 = a_val/L2*1e-16 //convert 1/cm^2 to 1/A^2 164 // 165 // sigmaQ = 0 166 // sigmaQ = 3*(S1/L1)^2 167 // 168 // if(usingLenses != 0) 169 // sigmaQ += 2*(S2/lp)^2*(lambdaWidth)^2 //2nd term w/ lenses 170 // else 171 // sigmaQ += 2*(S2/lp)^2 //2nd term w/ no lenses 172 // endif 173 // 174 // sigmaQ += (del_r/L2)^2 175 // sigmaQ += 2*(r0/L2)^2*(lambdaWidth)^2 176 // sigmaQ += 4*(a_val_l2)^2*lambda^4*(lambdaWidth)^2 177 // 178 // sigmaQ *= kap^2/12 179 // sigmaQ = sqrt(sigmaQ) 180 181 153 182 results = "success" 154 183 Return results … … 179 208 // phi is the azimuthal angle, CCW from +x axis 180 209 // r_dist is the real-space distance from ctr of detector to QxQy pixel location 210 // 211 // MAR 2011 - removed the del_r terms, they don't apply since no bining is done to the 2D data 181 212 // 182 213 Function/S get2DResolution(inQ,phi,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,usingLenses,r_dist,SigmaQX,SigmaQY,fSubS) … … 255 286 // endif 256 287 257 Variable kap,a_val,a_val_L2 288 Variable kap,a_val,a_val_L2,proj_DDet 258 289 259 290 kap = 2*pi/lambda … … 270 301 // 271 302 // a_val = 0 303 // a_val_l2 = 0 272 304 273 305 // the detector pixel is square, so correct for phi 274 DDet = DDet*cos(phi) + DDet*sin(phi)306 proj_DDet = DDet*cos(phi) + DDet*sin(phi) 275 307 276 308 // this is really sigma_Q_parallel 277 SigmaQX = kap*kap/12* (3*(S1/L1)^2 + 3*(S2/LP)^2 + ( DDet/L2)^2 + (del_r/L2)^2 + (sin(phi))^2*8*(a_val_L2)^2*lambda^4*lambdaWidth^2)309 SigmaQX = kap*kap/12* (3*(S1/L1)^2 + 3*(S2/LP)^2 + (proj_DDet/L2)^2 + (sin(phi))^2*8*(a_val_L2)^2*lambda^4*lambdaWidth^2) 278 310 SigmaQX += inQ*inQ*v_lambda 279 311 280 312 //this is really sigma_Q_perpendicular 281 SigmaQY = 3*(S1/L1)^2 + 3*(S2/LP)^2 + (DDet/L2)^2 + (del_r/L2)^2 + (cos(phi))^2*8*(a_val_L2)^2*lambda^4*lambdaWidth^2 313 proj_DDet = DDet*sin(phi) + DDet*cos(phi) //not necessary, since DDet is the same in both X and Y directions 314 315 SigmaQY = 3*(S1/L1)^2 + 3*(S2/LP)^2 + (proj_DDet/L2)^2 + (cos(phi))^2*8*(a_val_L2)^2*lambda^4*lambdaWidth^2 282 316 SigmaQY *= kap*kap/12 283 317 … … 1194 1228 Make/O/N=(num) root:myGlobals:Attenuators:ng3att10 1195 1229 1230 // and a wave for the errors at each attenuation factor 1231 Make/O/N=(num) root:myGlobals:Attenuators:ng3att0_err 1232 Make/O/N=(num) root:myGlobals:Attenuators:ng3att1_err 1233 Make/O/N=(num) root:myGlobals:Attenuators:ng3att2_err 1234 Make/O/N=(num) root:myGlobals:Attenuators:ng3att3_err 1235 Make/O/N=(num) root:myGlobals:Attenuators:ng3att4_err 1236 Make/O/N=(num) root:myGlobals:Attenuators:ng3att5_err 1237 Make/O/N=(num) root:myGlobals:Attenuators:ng3att6_err 1238 Make/O/N=(num) root:myGlobals:Attenuators:ng3att7_err 1239 Make/O/N=(num) root:myGlobals:Attenuators:ng3att8_err 1240 Make/O/N=(num) root:myGlobals:Attenuators:ng3att9_err 1241 Make/O/N=(num) root:myGlobals:Attenuators:ng3att10_err 1242 1243 1196 1244 //each wave has 10 elements, the transmission of att# at the wavelengths 1197 1245 //lambda = 4,5,6,7,8,10,12,14,17,20 (4 A and 20 A are extrapolated values) … … 1210 1258 root:myGlobals:Attenuators:ng3att9 = {6.27682e-05,3.69e-05,1.908e-05,1.196e-05,8.738e-06,6.996e-06,6.2901e-07,2.60221e-07,7.49748e-08,2.08029e-08} 1211 1259 root:myGlobals:Attenuators:ng3att10 = {1.40323e-05,8.51e-06,5.161e-06,4.4e-06,4.273e-06,1.88799e-07,5.87021e-08,2.08169e-08,4.8744e-09,1.08687e-09} 1260 1261 // percent errors as measured, May 2007 values 1262 // zero error for zero attenuators, appropriate average values put in for unknown values 1263 root:myGlobals:Attenuators:ng3att0_err = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } 1264 root:myGlobals:Attenuators:ng3att1_err = {0.15,0.142,0.154,0.183,0.221,0.328,0.136,0.13,0.163,0.15} 1265 root:myGlobals:Attenuators:ng3att2_err = {0.25,0.257,0.285,0.223,0.271,0.405,0.212,0.223,0.227,0.25} 1266 root:myGlobals:Attenuators:ng3att3_err = {0.3,0.295,0.329,0.263,0.323,0.495,0.307,0.28,0.277,0.3} 1267 root:myGlobals:Attenuators:ng3att4_err = {0.35,0.331,0.374,0.303,0.379,0.598,0.367,0.322,0.33,0.35} 1268 root:myGlobals:Attenuators:ng3att5_err = {0.4,0.365,0.418,0.355,0.454,0.745,0.411,0.367,0.485,0.4} 1269 root:myGlobals:Attenuators:ng3att6_err = {0.45,0.406,0.473,0.385,0.498,0.838,0.454,0.49,0.5,0.5} 1270 root:myGlobals:Attenuators:ng3att7_err = {0.6,0.554,0.692,0.425,0.562,0.991,0.715,0.8,0.8,0.8} 1271 root:myGlobals:Attenuators:ng3att8_err = {0.7,0.705,0.927,0.503,0.691,1.27,1,1,1,1} 1272 root:myGlobals:Attenuators:ng3att9_err = {1,0.862,1.172,0.799,1.104,1.891,1.5,1.5,1.5,1.5} 1273 root:myGlobals:Attenuators:ng3att10_err = {1.5,1.054,1.435,1.354,1.742,2,2,2,2,2} 1274 1212 1275 1213 1276 //old tables, pre-June 2007 … … 1246 1309 Make/O/N=(num) root:myGlobals:Attenuators:ng7att10 1247 1310 1311 // and a wave for the errors at each attenuation factor 1312 Make/O/N=(num) root:myGlobals:Attenuators:ng7att0_err 1313 Make/O/N=(num) root:myGlobals:Attenuators:ng7att1_err 1314 Make/O/N=(num) root:myGlobals:Attenuators:ng7att2_err 1315 Make/O/N=(num) root:myGlobals:Attenuators:ng7att3_err 1316 Make/O/N=(num) root:myGlobals:Attenuators:ng7att4_err 1317 Make/O/N=(num) root:myGlobals:Attenuators:ng7att5_err 1318 Make/O/N=(num) root:myGlobals:Attenuators:ng7att6_err 1319 Make/O/N=(num) root:myGlobals:Attenuators:ng7att7_err 1320 Make/O/N=(num) root:myGlobals:Attenuators:ng7att8_err 1321 Make/O/N=(num) root:myGlobals:Attenuators:ng7att9_err 1322 Make/O/N=(num) root:myGlobals:Attenuators:ng7att10_err 1323 1248 1324 //NG7 wave has 10 elements, the transmission of att# at the wavelengths 1249 1325 //lambda =4, 5,6,7,8,10,12,14,17,20 … … 1265 1341 root:myGlobals:Attenuators:ng7att10 = {2.1607e-05,7.521e-06,2.91221e-06,1.45252e-06,7.93451e-07,1.92309e-07,5.99279e-08,2.87928e-08,2.19862e-08,1.7559e-08} 1266 1342 1343 // percent errors as measured, May 2007 values 1344 // zero error for zero attenuators, appropriate average values put in for unknown values 1345 root:myGlobals:Attenuators:ng7att0_err = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } 1346 root:myGlobals:Attenuators:ng7att1_err = {0.2,0.169,0.1932,0.253,0.298,0.4871,0.238,0.245,0.332,0.3} 1347 root:myGlobals:Attenuators:ng7att2_err = {0.3,0.305,0.3551,0.306,0.37,0.6113,0.368,0.413,0.45,0.4} 1348 root:myGlobals:Attenuators:ng7att3_err = {0.4,0.355,0.4158,0.36,0.4461,0.7643,0.532,0.514,0.535,0.5} 1349 root:myGlobals:Attenuators:ng7att4_err = {0.45,0.402,0.4767,0.415,0.5292,0.9304,0.635,0.588,0.623,0.6} 1350 root:myGlobals:Attenuators:ng7att5_err = {0.5,0.447,0.5376,0.487,0.6391,1.169,0.708,0.665,0.851,0.8} 1351 root:myGlobals:Attenuators:ng7att6_err = {0.6,0.501,0.6136,0.528,0.8796,1.708,0.782,0.874,1,1} 1352 root:myGlobals:Attenuators:ng7att7_err = {0.8,0.697,0.9149,0.583,1.173,2.427,1.242,2,2,2} 1353 root:myGlobals:Attenuators:ng7att8_err = {1,0.898,1.24,0.696,1.577,3.412,3,3,3,3} 1354 root:myGlobals:Attenuators:ng7att9_err = {1.5,1.113,1.599,1.154,2.324,4.721,5,5,5,5} 1355 root:myGlobals:Attenuators:ng7att10_err = {1.5,1.493,5,5,5,5,5,5,5,5} 1356 1357 1267 1358 // Pre-June 2007 calibration values - do not use these anymore 1268 1359 //// root:myGlobals:Attenuators:ng7att0 = {1, 1, 1, 1, 1, 1, 1, 1 ,1} … … 1285 1376 // 1286 1377 // Mar 2010 - abs() added to attStr to account for ICE reporting -0.0001 as an attenuator position, which truncates to "-0" 1287 Function LookupAttenNG3(lambda,attenNo )1288 Variable lambda, attenNo 1378 Function LookupAttenNG3(lambda,attenNo,atten_err) 1379 Variable lambda, attenNo, &atten_err 1289 1380 1290 1381 Variable trans 1291 1382 String attStr="root:myGlobals:Attenuators:ng3att"+num2str(trunc(abs(attenNo))) 1383 String attErrWStr="root:myGlobals:Attenuators:ng3att"+num2str(trunc(abs(attenNo)))+"_err" 1292 1384 String lamStr = "root:myGlobals:Attenuators:ng3lambda" 1293 1385 … … 1300 1392 Endif 1301 1393 1302 if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) )1394 if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) || !(WaveExists($attErrWStr))) 1303 1395 Execute "MakeNG3AttenTable()" 1304 1396 Endif … … 1311 1403 //the attenuator must always be an integer 1312 1404 Wave att = $attStr 1405 Wave attErrW = $attErrWStr 1313 1406 Wave lam = $lamstr 1314 1407 trans = interp(lambda,lam,att) 1315 1408 atten_err = interp(lambda,lam,attErrW) 1409 1410 // the error in the tables is % error. return the standard deviation instead 1411 atten_err = trans*atten_err/100 1412 1316 1413 // Print "trans = ",trans 1414 // Print "trans err = ",atten_err 1317 1415 1318 1416 return trans … … 1329 1427 // 1330 1428 // Mar 2010 - abs() added to attStr to account for ICE reporting -0.0001 as an attenuator position, which truncates to "-0" 1331 Function LookupAttenNG7(lambda,attenNo )1332 Variable lambda, attenNo 1429 Function LookupAttenNG7(lambda,attenNo,atten_err) 1430 Variable lambda, attenNo, &atten_err 1333 1431 1334 1432 Variable trans 1335 1433 String attStr="root:myGlobals:Attenuators:ng7att"+num2str(trunc(abs(attenNo))) 1434 String attErrWStr="root:myGlobals:Attenuators:ng7att"+num2str(trunc(abs(attenNo)))+"_err" 1336 1435 String lamStr = "root:myGlobals:Attenuators:ng7lambda" 1337 1436 … … 1344 1443 Endif 1345 1444 1346 if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) )1445 if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) || !(WaveExists($attErrWStr))) 1347 1446 Execute "MakeNG7AttenTable()" 1348 1447 Endif … … 1355 1454 //the attenuator must always be an integer 1356 1455 Wave att = $attStr 1456 Wave attErrW = $attErrWStr 1357 1457 Wave lam = $lamstr 1358 1458 trans = interp(lambda,lam,att) 1359 1360 //Print "trans = ",trans 1459 atten_err = interp(lambda,lam,attErrW) 1460 1461 // the error in the tables is % error. return the standard deviation instead 1462 atten_err = trans*atten_err/100 1463 1464 // Print "trans = ",trans 1465 // Print "trans err = ",atten_err 1361 1466 1362 1467 return trans … … 1379 1484 // called by Correct.ipf, ProtocolAsPanel.ipf, Transmission.ipf 1380 1485 // 1381 Function AttenuationFactor(fileStr,lam,attenNo) 1486 // 1487 // as of March 2011, returns the error (one standard deviation) in the attenuation factor as the last parameter, by reference 1488 Function AttenuationFactor(fileStr,lam,attenNo,atten_err) 1382 1489 String fileStr 1383 Variable lam,attenNo 1490 Variable lam,attenNo, &atten_err 1384 1491 1385 1492 Variable attenFactor=1,loc … … 1388 1495 strswitch(instr) 1389 1496 case "NG3": 1390 attenFactor = LookupAttenNG3(lam,attenNo )1497 attenFactor = LookupAttenNG3(lam,attenNo,atten_err) 1391 1498 break 1392 1499 case "NG5": 1393 1500 //using NG7 lookup Table 1394 attenFactor = LookupAttenNG7(lam,attenNo )1501 attenFactor = LookupAttenNG7(lam,attenNo,atten_err) 1395 1502 break 1396 1503 case "NG7": 1397 attenFactor = LookupAttenNG7(lam,attenNo )1504 attenFactor = LookupAttenNG7(lam,attenNo,atten_err) 1398 1505 break 1399 1506 default: -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/ProDiv.ipf
r665 r794 38 38 39 39 WAVE data=$("root:Packages:NIST:"+type+":data") 40 WAVE data_lin=$("root:Packages:NIST:"+type+":linear_data") 41 WAVE data_err=$("root:Packages:NIST:"+type+":linear_data_error") 42 40 43 Variable totCts=sum(data,Inf,-Inf) //sum all of the data 41 44 NVAR pixelX = root:myGlobals:gNPixelsX … … 46 49 data *= pixelX*pixelY 47 50 51 data_lin /= totCts 52 data_lin *= pixelX*pixelY 53 54 data_err /= totCts 55 data_err *= pixelX*pixelY 56 48 57 return(0) 49 58 End … … 132 141 WAVE ctrData=$("root:Packages:NIST:"+ctrtype+":data") 133 142 WAVE offData=$("root:Packages:NIST:"+offtype+":data") 143 144 WAVE ctrData_lin=$("root:Packages:NIST:"+ctrtype+":linear_data") 145 WAVE offData_lin=$("root:Packages:NIST:"+offtype+":linear_data") 146 147 WAVE ctrData_err=$("root:Packages:NIST:"+ctrtype+":linear_data_error") 148 WAVE offData_err=$("root:Packages:NIST:"+offtype+":linear_data_error") 149 134 150 Variable ii,jj 135 151 … … 137 153 for(jj=y1;jj<=y2;jj+=1) 138 154 ctrData[ii][jj] = offData[ii][jj] 155 ctrData_lin[ii][jj] = offData_lin[ii][jj] 156 ctrData_err[ii][jj] = offData_err[ii][jj] 139 157 endfor 140 158 endfor -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/ProtocolAsPanel.ipf
r764 r794 242 242 numItems = ItemsInList(list,";") 243 243 checked = 1 244 if(numitems == 4 )244 if(numitems == 4 || numitems == 5) //allow for protocols with no SDEV list item 245 245 //correct number of parameters, assume ok 246 246 String/G root:myGlobals:Protocols:gAbsStr = list … … 1740 1740 Endif 1741 1741 1742 Variable c2,c3,c4,c5 1742 Variable c2,c3,c4,c5,kappa_err 1743 1743 //do absolute scaling if desired 1744 1744 if(cmpstr("none",prot[4])!=0) … … 1752 1752 c4 = NumberByKey("IZERO", junkAbsStr, "=", ";") 1753 1753 c5 = NumberByKey("XSECT", junkAbsStr, "=", ";") 1754 kappa_err = NumberByKey("SDEV", junkAbsStr, "=", ";") 1754 1755 else 1755 1756 //get the parames from the list … … 1758 1759 c4 = NumberByKey("IZERO", prot[4], "=", ";") 1759 1760 c5 = NumberByKey("XSECT", prot[4], "=", ";") 1761 kappa_err = NumberByKey("SDEV", prot[4], "=", ";") 1760 1762 Endif 1761 1763 //get the sample trans and thickness from the activeType folder … … 1765 1767 Variable c1 = dest[5] //sample thickness 1766 1768 1767 err = Absolute_Scale(activeType,c0,c1,c2,c3,c4,c5 )1769 err = Absolute_Scale(activeType,c0,c1,c2,c3,c4,c5,kappa_err) 1768 1770 if(err) 1769 1771 SetDataFolder root: … … 1990 1992 //values are passed back as a global string variable (keyword=value) 1991 1993 // 1992 Proc AskForAbsoluteParams(c2,c3,c4,c5 )1993 Variable c2=0.95,c3=0.1,c4=1,c5=32.0 1994 Proc AskForAbsoluteParams(c2,c3,c4,c5,err) 1995 Variable c2=0.95,c3=0.1,c4=1,c5=32.0,err=0 1994 1996 Prompt c2, "Standard Transmission" 1995 1997 Prompt c3, "Standard Thickness (cm)" 1996 1998 Prompt c4, "I(0) from standard fit (normalized to 1E8 monitor cts)" 1997 1999 Prompt c5, "Standard Cross-Section (cm-1)" 2000 Prompt err, "error in I(q=0) (one std dev)" 1998 2001 1999 2002 String/G root:myGlobals:Protocols:gAbsStr="" … … 2003 2006 root:myGlobals:Protocols:gAbsStr += ";" + "IZERO="+num2str(c4) 2004 2007 root:myGlobals:Protocols:gAbsStr += ";" + "XSECT="+num2str(c5) 2008 root:myGlobals:Protocols:gAbsStr += ";" + "SDEV="+num2str(err) 2005 2009 2006 2010 End … … 2059 2063 Variable lambda = rw[26] 2060 2064 Variable attenNo = rw[3] 2061 attenTrans = AttenuationFactor(acctStr,lambda,attenNo) 2065 Variable atten_err 2066 attenTrans = AttenuationFactor(acctStr,lambda,attenNo,atten_err) 2062 2067 //Print "attenTrans = ",attenTrans 2063 2068 2064 2069 //get the XY box, if needed 2065 Variable x1,x2,y1,y2 2070 Variable x1,x2,y1,y2,ct_err 2066 2071 String filename=tw[0],tempStr 2067 2072 PathInfo/S catPathName … … 2092 2097 2093 2098 //need the detector sensitivity file - make a guess, allow to override 2094 String junkStr="" 2099 String junkStr="",errStr="" 2095 2100 if(! waveexists($"root:Packages:NIST:DIV:data")) 2096 2101 junkStr = PromptForPath("Select the detector sensitivity file") … … 2124 2129 // detCnt = sum($"root:Packages:NIST:raw:data", -inf, inf ) 2125 2130 // Print "box is now ",x1,x2,y1,y2 2126 detCnt = SumCountsInBox(x1,x2,y1,y2, "RAW")2131 detCnt = SumCountsInBox(x1,x2,y1,y2,ct_err,"RAW") 2127 2132 if(cmpstr(tw[9],"ILL ")==0) 2128 2133 detCnt /= 4 // for cerca detector, header is right, sum(data) is 4x too large this is usually corrected in the Add step … … 2131 2136 // 2132 2137 kappa = detCnt/countTime/attenTrans*1.0e8/(monCnt/countTime)*(pixel/sdd)^2 2138 2139 Variable kappa_err 2140 kappa_err = (ct_err/detCnt)^2 + (atten_err/attenTrans)^2 2141 kappa_err = sqrt(kappa_err) * kappa 2142 2133 2143 junkStr = num2str(kappa) 2144 errStr = num2Str(kappa_err) 2134 2145 // set the parameters in the global string 2135 Execute "AskForAbsoluteParams(1,1,"+junkStr+",1)" //no missing parameters, no dialog 2146 // Print "AskForAbsoluteParams(1,1,"+junkStr+",1,"+errStr+")" 2147 Execute "AskForAbsoluteParams(1,1,"+junkStr+",1,"+errStr+")" //no missing parameters, no dialog 2136 2148 2137 2149 //should wipe out the data in the RAW folder, since it's not really RAW now … … 2140 2152 // - obsucre bug if "ask" in ABS section of protocol clears RAW folder, then Q-axes can't be set from RAW:RealsRead 2141 2153 //ClearDataFolder("RAW") 2142 Print "Kappa was successfully calculated as = ",kappa2154 Printf "Kappa was successfully calculated as = %g +/- %g (%g %)\r",kappa,kappa_err,(kappa_err/kappa)*100 2143 2155 Endif 2144 2156 -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/Transmission.ipf
r670 r794 80 80 Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Lambda" 81 81 Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Transmission" 82 Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Trans_Error" 83 82 84 Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Whole" 83 85 If(V_Flag==0) … … 177 179 Wave S_Lambda = $"root:myGlobals:TransHeaderInfo:S_Lambda" 178 180 Wave S_Transmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" 179 180 Edit/K=1/W=(50,50,520,270) S_TRANS_Filenames, S_Filenames, S_Labels, S_SDD, S_Lambda, S_Transmission as "ScatteringFiles" 181 Wave S_GTrans_err = $"root:myGlobals:TransHeaderInfo:S_Trans_Error" 182 183 184 Edit/K=1/W=(50,50,520,270) S_TRANS_Filenames, S_Filenames, S_Labels, S_SDD, S_Lambda, S_Transmission, S_GTrans_err as "ScatteringFiles" 181 185 String name="ScatterFileTable" 182 186 DoWindow/C $name … … 207 211 Wave S_GLambda = $"root:myGlobals:TransHeaderInfo:S_Lambda" 208 212 Wave S_GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" 213 Wave S_GTrans_err = $"root:myGlobals:TransHeaderInfo:S_Trans_Error" 209 214 Wave S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole" 210 215 211 216 Sort T_GSuffix, T_GEMP_Filenames, T_GSuffix, T_GSuffices, T_GFilenames, T_GLabels, T_GSDD, T_GLambda, T_GTransmission, T_Whole 212 Sort S_GSuffix, S_GTRANS_Filenames, S_GSuffix, S_GSuffices, S_GFilenames, S_GLabels, S_GSDD, S_GLambda, S_GTransmission, S_Whole 217 Sort S_GSuffix, S_GTRANS_Filenames, S_GSuffix, S_GSuffices, S_GFilenames, S_GLabels, S_GSDD, S_GLambda, S_GTransmission, S_Whole, S_GTrans_err 213 218 214 219 End … … 236 241 Wave S_GLambda = $"root:myGlobals:TransHeaderInfo:S_Lambda" 237 242 Wave S_GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" 243 Wave S_GTrans_err = $"root:myGlobals:TransHeaderInfo:S_Trans_Error" 238 244 Wave S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole" 239 245 240 246 Sort T_GLabels, T_GEMP_Filenames, T_GSuffix, T_GSuffices, T_GFilenames, T_GLabels, T_GSDD, T_GLambda, T_GTransmission, T_Whole 241 Sort S_GLabels, S_GTRANS_Filenames, S_GSuffix, S_GSuffices, S_GFilenames, S_GLabels, S_GSDD, S_GLambda, S_GTransmission, S_Whole 247 Sort S_GLabels, S_GTRANS_Filenames, S_GSuffix, S_GSuffices, S_GFilenames, S_GLabels, S_GSDD, S_GLambda, S_GTransmission, S_Whole, S_GTrans_err 242 248 243 249 End … … 279 285 Wave GLambda = $"root:myGlobals:TransHeaderInfo:S_Lambda" 280 286 Wave GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" 287 Wave S_GTrans_err = $"root:myGlobals:TransHeaderInfo:S_Trans_Error" 281 288 Wave GWhole = $"root:myGlobals:TransHeaderInfo:S_Whole" 289 290 //Transmission error 291 InsertPoints lastPoint,1,S_GTrans_err 292 S_GTrans_err[lastPoint] = getSampleTransError(fname) 293 282 294 Endif 283 295 … … 306 318 InsertPoints lastPoint,1,GTransmission 307 319 GTransmission[lastPoint]=getSampleTrans(fname) 320 321 308 322 309 323 //Whole detector Transmission … … 477 491 Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Lambda" 478 492 Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Transmission" 493 Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Trans_Error" 479 494 Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Whole" 480 495 End … … 605 620 Wave/T S_GSuffix = $"root:myGlobals:TransHeaderInfo:S_Suffix" 606 621 Wave S_GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" 622 Wave S_GTrans_err = $"root:myGlobals:TransHeaderInfo:S_Trans_Error" 607 623 Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames" 608 624 Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" … … 643 659 WriteWholeTransToHeader(filename,1) //WholeTrans start byte is 392 644 660 661 WriteTransmissionErrorToHeader(filename,0) //reset transmission error to zero 662 WriteBoxCountsErrorToHeader(filename,0) 663 645 664 //then update the table that is displayed 646 665 T_EMP_Filenames[ii] = "" … … 663 682 //write a trans==1 to the file header of the raw data (open/close done in function) 664 683 WriteTransmissionToHeader(filename,1) //sample trans 684 WriteTransmissionErrorToHeader(filename,0) //reset transmission error to zero 685 WriteBoxCountsErrorToHeader(filename,0) 665 686 666 687 //then update the table that is displayed 667 688 S_TRANS_Filenames[ii] = "" 668 689 S_GTransmission[ii] = 1 690 S_GTrans_err[ii] = 0 669 691 670 692 ii+=1 … … 710 732 Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" 711 733 Wave S_GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" 712 734 Wave S_GTrans_err = $"root:myGlobals:TransHeaderInfo:S_Trans_Error" 735 713 736 Variable num_s_files, num_t_files, ii, jj 714 Variable refnum, transCts, emptyCts,attenRatio,lambda,trans 715 Variable x1,x2,y1,y2,err,attenEmp,attenSam 737 Variable refnum, transCts, emptyCts,attenRatio,lambda,trans,sam_atten_err,emp_atten_err 738 Variable x1,x2,y1,y2,err,attenEmp,attenSam,empty_ct_err,sam_ct_err,samAttenFactor,empAttenFactor,trans_err 716 739 String suffix = "",pathName,textStr,abortStr,emptyFile,transFile,samFileStr 717 740 String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" … … 742 765 //read the real count value 743 766 emptyCts = getBoxCounts(emptyFile) 767 // get the error in count value 768 empty_ct_err = getBoxCountsError(emptyFile) 769 744 770 // read the attenuator number of the empty beam file 745 771 attenEmp = getAttenNumber(emptyFile) … … 757 783 err = Raw_to_work("SAM") 758 784 //sum region in SAM 759 transCts = SumCountsInBox(x1,x2,y1,y2, "SAM")785 transCts = SumCountsInBox(x1,x2,y1,y2,sam_ct_err,"SAM") 760 786 // get the attenuator, lambda, and sample string (to get the instrument) 761 787 WAVE/T samText = $"root:Packages:NIST:SAM:textRead" … … 764 790 lambda = samReals[26] 765 791 attenSam = samReals[3] 792 766 793 //calculate the ratio of attenuation factors - assumes that same instrument used for each, AND same lambda 767 AttenRatio = AttenuationFactor(samFileStr,lambda,attenEmp)/AttenuationFactor(samFileStr,lambda,attenSam) 794 samAttenFactor = AttenuationFactor(samFileStr,lambda,attenSam,sam_atten_err) 795 empAttenFactor = AttenuationFactor(samFileStr,lambda,attenEmp,emp_atten_err) 796 AttenRatio = empAttenFactor/samAttenFactor 768 797 //calculate trans based on empty beam value and rescale by attenuation ratio 769 798 trans= transCts/emptyCts * AttenRatio 770 799 800 // squared, relative error 801 if(AttenRatio == 1) 802 trans_err = (sam_ct_err/transCts)^2 + (empty_ct_err/emptyCts)^2 //same atten, att_err drops out 803 else 804 trans_err = (sam_ct_err/transCts)^2 + (empty_ct_err/emptyCts)^2 + (sam_atten_err/samAttenFactor)^2 + (emp_atten_err/empAttenFactor)^2 805 endif 806 trans_err = sqrt(trans_err) 807 trans_err *= trans // now, one std deviation 808 771 809 //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity 772 810 If(attenRatio==1) 773 Printf "%s\t\tTrans Counts = %g\tTrans = %g \r",S_GFilenames[ii], transCts,trans811 Printf "%s\t\tTrans Counts = %g\tTrans = %g +/- %g\r",S_GFilenames[ii], transCts,trans,trans_err 774 812 else 775 Printf "%s\t\tTrans Counts = %g\tTrans = %g \tAttenuatorRatio = %g\r",S_GFilenames[ii], transCts,trans,attenRatio813 Printf "%s\t\tTrans Counts = %g\tTrans = %g +/- %g\tAttenuatorRatio = %g\r",S_GFilenames[ii], transCts,trans,trans_err,attenRatio 776 814 endif 777 815 //write the trans to the file header of the raw data (open/close done in function) 778 816 WriteTransmissionToHeader(filename,trans) 779 817 818 WriteTransmissionErrorToHeader(filename,trans_err) 819 ///// 780 820 //then update the global that is displayed 781 821 S_GTransmission[ii] = trans 822 S_GTrans_err[ii] = trans_err 823 782 824 783 825 else // There is no empty assigned … … 821 863 822 864 Variable num_t_files, ii, jj 823 Variable refnum, transCts, emptyCts,attenRatio,lambda,trans 824 Variable x1,x2,y1,y2,err,attenEmp,attenSam 865 Variable refnum, transCts, emptyCts,attenRatio,lambda,trans,samAttenFactor,empAttenFactor,trans_err 866 Variable x1,x2,y1,y2,err,attenEmp,attenSam,empty_ct_err,sam_ct_err,emp_atten_err,sam_atten_err 825 867 String suffix = "",pathName,textStr,abortStr,emptyFile,transFile,samFileStr 826 868 String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" … … 851 893 //read the real count value 852 894 emptyCts = getBoxCounts(emptyFile) 895 // get the count error 896 empty_ct_err = getBoxCountsError(emptyFile) 897 853 898 // read the attenuator number of the empty beam file 854 899 attenEmp = getAttenNumber(emptyFile) 900 855 901 // 856 902 if( ((x1-x2)==0) || ((y1-y2)==0) ) //zero width marquee in either direction … … 866 912 err = Raw_to_work("SAM") 867 913 //sum region in SAM 868 transCts = SumCountsInBox(x1,x2,y1,y2, "SAM")914 transCts = SumCountsInBox(x1,x2,y1,y2,sam_ct_err,"SAM") 869 915 // get the attenuator, lambda, and sample string (to get the instrument) 870 916 WAVE/T samText = $"root:Packages:NIST:SAM:textRead" … … 873 919 lambda = samReals[26] 874 920 attenSam = samReals[3] 921 875 922 //calculate the ratio of attenuation factors - assumes that same instrument used for each, AND same lambda 876 AttenRatio = AttenuationFactor(samFileStr,lambda,attenEmp)/AttenuationFactor(samFileStr,lambda,attenSam) 923 samAttenFactor = AttenuationFactor(samFileStr,lambda,attenSam,sam_atten_err) 924 empAttenFactor = AttenuationFactor(samFileStr,lambda,attenEmp,emp_atten_err) 925 AttenRatio = empAttenFactor/samAttenFactor 877 926 //calculate trans based on empty beam value and rescale by attenuation ratio 878 927 trans= transCts/emptyCts * AttenRatio 928 929 // squared, relative error 930 if(AttenRatio == 1) 931 trans_err = (sam_ct_err/transCts)^2 + (empty_ct_err/emptyCts)^2 //same atten, att_err drops out 932 else 933 trans_err = (sam_ct_err/transCts)^2 + (empty_ct_err/emptyCts)^2 + (sam_atten_err/samAttenFactor)^2 + (emp_atten_err/empAttenFactor)^2 934 endif 935 trans_err = sqrt(trans_err) 936 trans_err *= trans // now, one std deviation 879 937 880 938 //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity 881 939 If(attenRatio==1) 882 940 //Printf "%s\t\tTrans Counts = %g\t Actual Trans = %g\r",T_GFilenames[ii], transCts,trans 883 Printf "%s\t\tBox Counts = %g\t Trans = %g \r",T_GFilenames[ii], transCts,trans941 Printf "%s\t\tBox Counts = %g\t Trans = %g +/- %g\r",T_GFilenames[ii], transCts,trans,trans_err 884 942 else 885 943 //Printf "%s\t\tTrans Counts = %g\t Trans = %g\tAttenuatorRatio = %g\r",T_GFilenames[ii], transCts,trans,attenRatio 886 Printf "%s\t\tBox Counts = %g\t Trans = %g \t AttenuatorRatio = %g\r",T_GFilenames[ii], transCts,trans,attenRatio944 Printf "%s\t\tBox Counts = %g\t Trans = %g +/- %g\t AttenuatorRatio = %g\r",T_GFilenames[ii], transCts,trans,trans_err,attenRatio 887 945 endif 888 946 //write the trans to the file header of the raw data (open/close done in function) 889 947 WriteTransmissionToHeader(filename,trans) //transmission start byte is 158 890 948 949 WriteTransmissionErrorToHeader(filename,trans_err) 950 891 951 //then update the global that is displayed 892 952 T_GTransmission[ii] = trans … … 936 996 Variable num_t_files, ii, jj 937 997 Variable refnum, transCts, emptyCts,attenRatio,lambda,trans 938 Variable x1,x2,y1,y2,err,attenEmp,attenSam 998 Variable x1,x2,y1,y2,err,attenEmp,attenSam,empty_ct_err,sam_ct_err,emp_atten_err,sam_atten_err 939 999 String suffix = "",pathName,textStr,abortStr,emptyFile,transFile,samFileStr 940 1000 String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" … … 965 1025 //read the real count value 966 1026 emptyCts = getBoxCounts(emptyFile) 1027 // get the box count error 1028 empty_ct_err = getBoxCountsError(emptyFile) 1029 967 1030 // read the attenuator number of the empty beam file 968 1031 attenEmp = getAttenNumber(emptyFile) 1032 969 1033 // 970 1034 if( ((x1-x2)==0) || ((y1-y2)==0) ) //zero width marquee in either direction … … 980 1044 err = Raw_to_work("SAM") 981 1045 //sum region in SAM 982 transCts = SumCountsInBox(0,pixelsX-1,0,pixelsY-1, "SAM")1046 transCts = SumCountsInBox(0,pixelsX-1,0,pixelsY-1,sam_ct_err,"SAM") 983 1047 // get the attenuator, lambda, and sample string (to get the instrument) 984 1048 WAVE/T samText = $"root:Packages:NIST:SAM:textRead" … … 987 1051 lambda = samReals[26] 988 1052 attenSam = samReals[3] 1053 989 1054 //calculate the ratio of attenuation factors - assumes that same instrument used for each, AND same lambda 990 AttenRatio = AttenuationFactor(samFileStr,lambda,attenEmp )/AttenuationFactor(samFileStr,lambda,attenSam)1055 AttenRatio = AttenuationFactor(samFileStr,lambda,attenEmp,emp_atten_err)/AttenuationFactor(samFileStr,lambda,attenSam,sam_atten_err) 991 1056 //calculate trans based on empty beam value and rescale by attenuation ratio 992 1057 trans= transCts/emptyCts * AttenRatio -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/WorkFileUtils.ipf
r788 r794 20 20 //*************************** 21 21 22 // 23 // 24 // MARCH 2011 - changed the references that manipulate the data to explcitly work on the linear_data wave 25 // at the end of routines that maniplulate linear_data, it is copied back to "data" which is displayed 26 // 27 // 22 28 23 29 //testing procedure, not called anymore … … 63 69 64 70 // if the desired workfile doesn't exist, let the user know, and just make a new one 65 destPath = "root:Packages:NIST:"+newType + ":data" 66 if(WaveExists($destpath) == 0) 71 if(WaveExists($("root:Packages:NIST:"+newType + ":data")) == 0) 67 72 Print "There is no old work file to add to - a new one will be created" 68 73 //call Raw_to_work(), then return from this function … … 76 81 //now make references to data in newType folder 77 82 DestPath="root:Packages:NIST:"+newType 78 WAVE data=$(destPath +":data") // these wave references point to the EXISTING work data 83 WAVE data=$(destPath +":linear_data") // these wave references point to the EXISTING work data 84 WAVE data_copy=$(destPath +":data") // these wave references point to the EXISTING work data 85 WAVE dest_data_err=$(destPath +":linear_data_error") // these wave references point to the EXISTING work data 79 86 WAVE/T textread=$(destPath + ":textread") 80 87 WAVE integersread=$(destPath + ":integersread") … … 110 117 //then unscale the data array 111 118 data *= uscale 119 dest_data_err *= uscale 112 120 113 121 //DetCorr() has not been applied to the data in RAW , do it now in a local reference to the raw data 114 WAVE raw_data = $"root:Packages:NIST:RAW:data" 122 WAVE raw_data = $"root:Packages:NIST:RAW:linear_data" 123 WAVE raw_data_err = $"root:Packages:NIST:RAW:linear_data_error" 115 124 WAVE raw_reals = $"root:Packages:NIST:RAW:realsread" 116 125 WAVE/T raw_text = $"root:Packages:NIST:RAW:textread" … … 128 137 endif 129 138 130 DetCorr(raw_data,raw_ reals,doEfficiency,doTrans) //applies correction to raw_data, and overwrites it139 DetCorr(raw_data,raw_data_err,raw_reals,doEfficiency,doTrans) //applies correction to raw_data, and overwrites it 131 140 132 141 //if RAW data is ILL type detector, correct raw_data for same counts being written to 4 pixels 133 142 if(cmpstr(raw_text[9], "ILL ") == 0 ) //text field in header is 6 characters "ILL---" 134 143 raw_data /= 4 144 raw_data_err /= 4 135 145 endif 136 146 … … 155 165 dscale = 1/(1-deadTime*cntrate) 156 166 // multiply data[ii][] by the dead time 157 data[][ii] *= dscale 167 raw_data[][ii] *= dscale 168 raw_data_err[][ii] *= dscale 158 169 endfor 170 #else 171 // dead time correction on all other RAW data, including NCNR 172 raw_data *= dscale 173 raw_data_err *= dscale 159 174 #endif 160 175 … … 162 177 total_mon += raw_reals[0] 163 178 #if (exists("ILL_D22")==6) 164 total_det += sum( data,-inf,inf) //add the newly scaled detector array179 total_det += sum(raw_data,-inf,inf) //add the newly scaled detector array 165 180 #else 166 181 total_det += dscale*raw_reals[2] … … 184 199 185 200 If((xshift == 0) && (yshift == 0)) //no shift, just add them 186 data += dscale*raw_data //do the deadtime correction on RAW here 201 data += raw_data //deadtime correction has already been done to the raw data 202 dest_data_err = sqrt(dest_data_err^2 + raw_data_err^2) // error of the sum 187 203 else 188 204 //shift the beamcenter, then add … … 202 218 else 203 219 //add the raw_data + shifted sum (and do the deadtime correction on both) 204 data[ii][jj] += dscale*(raw_data[ii][jj]+sh_sum) //do the deadtime correction on RAW here 220 data[ii][jj] += (raw_data[ii][jj]+sh_sum) //do the deadtime correction on RAW here 221 dest_data_err[ii][jj] = sqrt(dest_data_err[ii][jj]^2 + raw_data_err[ii][jj]^2) // error of the sum 205 222 Endif 206 223 jj+=1 … … 213 230 scale = defmon/total_mon 214 231 data *= scale 232 dest_data_err *= scale 233 234 // keep "data" and linear_data in sync in the destination folder 235 data_copy = data 215 236 216 237 //all is done, except for the bookkeeping of updating the header info in the work folder … … 277 298 DestPath = "root:Packages:NIST:"+newType 278 299 Duplicate/O $"root:Packages:NIST:RAW:data",$(destPath + ":data") 300 Duplicate/O $"root:Packages:NIST:RAW:linear_data_error",$(destPath + ":linear_data_error") 301 Duplicate/O $"root:Packages:NIST:RAW:linear_data",$(destPath + ":linear_data") 279 302 // Duplicate/O $"root:Packages:NIST:RAW:vlegend",$(destPath + ":vlegend") 280 303 Duplicate/O $"root:Packages:NIST:RAW:textread",$(destPath + ":textread") … … 282 305 Duplicate/O $"root:Packages:NIST:RAW:realsread",$(destPath + ":realsread") 283 306 Variable/G $(destPath + ":gIsLogscale")=0 //overwite flag in newType folder, data converted (above) to linear scale 284 285 WAVE data=$(destPath + ":data") // these wave references point to the data in work 286 WAVE/T textread=$(destPath + ":textread") //that are to be directly operated on 307 308 WAVE data=$(destPath + ":linear_data") // these wave references point to the data in work 309 WAVE data_copy=$(destPath + ":data") // these wave references point to the data in work 310 WAVE data_err=$(destPath + ":linear_data_error") 311 WAVE/T textread=$(destPath + ":textread") //that are to be directly operated on 287 312 WAVE integersread=$(destPath + ":integersread") 288 313 WAVE realsread=$(destPath + ":realsread") … … 298 323 endif 299 324 300 DetCorr(data, realsread,doEfficiency,doTrans) //the parameters are waves, and will be changed by the function301 325 DetCorr(data,data_err,realsread,doEfficiency,doTrans) //the parameters are waves, and will be changed by the function 326 302 327 //if ILL type detector, correct for same counts being written to 4 pixels 303 328 if(cmpstr(textread[9], "ILL ") == 0 ) //text field in header is 6 characters "ILL---" 304 329 data /= 4 330 data_err /= 4 //rescale error 305 331 endif 306 332 … … 326 352 // multiply data[ii][] by the dead time 327 353 data[][ii] *= dscale 354 data_err[][ii] *= dscale 328 355 endfor 329 356 #endif 330 357 358 // NO xcenter,ycenter shifting is done - this is the first (and only) file in the work folder 359 360 //only ONE data file- no addition of multiple runs in this function, so data is 361 //just simply corrected for deadtime. 362 #if (exists("ILL_D22")==0) //ILL correction done tube-by-tube above 363 data *= dscale //deadtime correction for everyone else, including NCNR 364 data_err *= dscale 365 #endif 331 366 332 367 //update totals to put in the work header (at the end of the function) … … 341 376 total_numruns +=1 342 377 343 // NO xcenter,ycenter shifting is done - this is the first (and only) file in the work folder 344 345 //only ONE data file- no addition of multiple runs in this function, so data is 346 //just simply corrected for deadtime. 347 #ifndef ILL_D22 //correction done tube-by-tube above 348 data *= dscale //deadtime correction 349 #endif 350 378 351 379 //scale the data to the default montor counts 352 380 scale = defmon/total_mon 353 381 data *= scale 382 data_err *= scale //assumes total monitor count is so large there is essentially no error 383 384 // to keep "data" and linear_data in sync 385 data_copy = data 354 386 355 387 //all is done, except for the bookkeeping, updating the header information in the work folder … … 383 415 Raw_to_work(type) 384 416 //data is now in "type" folder 385 WAVE data=$("root:Packages:NIST:"+type+":data") 417 WAVE data=$("root:Packages:NIST:"+type+":linear_data") 418 WAVE data_copy=$("root:Packages:NIST:"+type+":data") 419 WAVE data_err=$("root:Packages:NIST:"+type+":linear_data_error") 386 420 WAVE new_reals=$("root:Packages:NIST:"+type+":realsread") 387 421 … … 393 427 394 428 data /= scale //unscale the data 429 data_err /= scale 430 431 // to keep "data" and linear_data in sync 432 data_copy = data 395 433 396 434 return(0) … … 409 447 Add_Raw_to_work(type) 410 448 //data is now in "type" folder 411 WAVE data=$("root:Packages:NIST:"+type+":data") 449 WAVE data=$("root:Packages:NIST:"+type+":linear_data") 450 WAVE data_copy=$("root:Packages:NIST:"+type+":data") 451 WAVE data_err=$("root:Packages:NIST:"+type+":linear_data_error") 412 452 WAVE new_reals=$("root:Packages:NIST:"+type+":realsread") 413 453 … … 419 459 420 460 data /= scale //unscale the data 461 data_err /= scale 462 463 // to keep "data" and linear_data in sync 464 data_copy = data 421 465 422 466 return(0) … … 427 471 //works on the actual data array, assumes that is is already on LINEAR scale 428 472 // 429 Function DetCorr(data, realsread,doEfficiency,doTrans)430 Wave data, realsread473 Function DetCorr(data,data_err,realsread,doEfficiency,doTrans) 474 Wave data,data_err,realsread 431 475 Variable doEfficiency,doTrans 432 476 … … 434 478 Variable ii,jj,dtdist,dtdis2 435 479 Variable xi,xd,yd,rad,ratio,domega,xy 436 Variable lambda,trans 480 Variable lambda,trans,trans_err,lat_err,tmp_err,lat_corr 437 481 438 482 // Print "...doing jacobian and non-linear corrections" … … 457 501 lambda = realsRead[26] 458 502 trans = RealsRead[4] 503 trans_err = RealsRead[41] //new, March 2011 459 504 460 505 xx0 = dc_fx(x0,sx,sx3,xcenter) … … 492 537 data[ii][jj] *= xy*ratio 493 538 solidAngle[ii][jj] = xy*ratio //testing only 494 539 data_err[ii][jj] *= xy*ratio //error propagation assumes that SA and Jacobian are exact, so simply scale error 540 495 541 496 542 // correction factor for detector efficiency JBG memo det_eff_cor2.doc 3/20/07 … … 501 547 #if (exists("ILL_D22")==6) 502 548 data[ii][jj] /= DetEffCorrILL(lambda,dtdist,xd) //tube-by-tube corrections 503 solidAngle[ii][jj] = DetEffCorrILL(lambda,dtdist,xd) 549 data_err[ii][jj] /= DetEffCorrILL(lambda,dtdist,xd) //assumes correction is exact 550 // solidAngle[ii][jj] = DetEffCorrILL(lambda,dtdist,xd) 504 551 #else 505 552 data[ii][jj] /= DetEffCorr(lambda,dtdist,xd,yd) 553 data_err[ii][jj] /= DetEffCorr(lambda,dtdist,xd,yd) 506 554 // solidAngle[ii][jj] /= DetEffCorr(lambda,dtdist,xd,yd) //testing only 507 555 #endif … … 522 570 trans = 1 523 571 endif 524 525 data[ii][jj] /= LargeAngleTransmissionCorr(trans,dtdist,xd,yd) //moved from 1D avg SRK 11/2007 572 573 // pass in the transmission error, and the error in the correction is returned as the last parameter 574 lat_corr = LargeAngleTransmissionCorr(trans,dtdist,xd,yd,trans_err,lat_err) //moved from 1D avg SRK 11/2007 575 data[ii][jj] /= lat_corr //divide by the correction factor 576 // 577 // 578 // 579 // relative errors add in quadrature 580 tmp_err = (data_err[ii][jj]/lat_corr)^2 + (lat_err/lat_corr)^2*data[ii][jj]*data[ii][jj]/lat_corr^2 581 tmp_err = sqrt(tmp_err) 582 583 data_err[ii][jj] = tmp_err 584 585 solidAngle[ii][jj] = lat_err 586 587 526 588 //solidAngle[ii][jj] = LargeAngleTransmissionCorr(trans,dtdist,xd,yd) //testing only 527 589 endif … … 599 661 600 662 // DIVIDE the intensity by this correction to get the right answer 601 Function LargeAngleTransmissionCorr(trans,dtdist,xd,yd )602 Variable trans,dtdist,xd,yd 663 Function LargeAngleTransmissionCorr(trans,dtdist,xd,yd,trans_err,err) 664 Variable trans,dtdist,xd,yd,trans_err,&err 603 665 604 666 //angle dependent transmission correction … … 618 680 //optical thickness 619 681 uval = -ln(trans) //use natural logarithm 620 621 // theta = 2*asin(lambda*qval/(4*pi))622 623 682 cos_th = cos(theta) 624 683 arg = (1-cos_th)/cos_th 625 if((uval<0.01) || (cos_th>0.99)) //OR 684 685 // a Taylor series around uval*arg=0 only needs about 4 terms for very good accuracy 686 // correction= 1 - 0.5*uval*arg + (uval*arg)^2/6 - (uval*arg)^3/24 + (uval*arg)^4/120 687 // OR 688 if((uval<0.01) || (cos_th>0.99)) 626 689 //small arg, approx correction 627 690 correction= 1-0.5*uval*arg … … 631 694 endif 632 695 696 Variable tmp 697 698 if(trans == 1) 699 err = 0 //no correction, no error 700 else 701 //sigT, calculated from the Taylor expansion 702 tmp = (1/trans)*(arg/2-arg^2/3*uval+arg^3/8*uval^2-arg^4/30*uval^3) 703 tmp *= tmp 704 tmp *= trans_err^2 705 tmp = sqrt(tmp) //sigT 706 707 err = tmp 708 endif 709 710 // Printf "trans error = %g\r",trans_err 711 // Printf "correction = %g +/- %g\r", correction, err 712 633 713 //end of transmission/pathlength correction 634 714 … … 806 886 // if the desired workfile doesn't exist, let the user know, and abort 807 887 String destPath="" 808 destPath = "root:Packages:NIST:"+Type + ":data" 809 if(WaveExists($ destpath) == 0)888 889 if(WaveExists($("root:Packages:NIST:"+Type + ":data")) == 0) 810 890 Print "There is no work file in "+type+"--Aborting" 811 891 Return(1) //error condition … … 813 893 //check for DIV 814 894 // if the DIV workfile doesn't exist, let the user know,and abort 815 destPath = "root:Packages:NIST:DIV:data" 816 if(WaveExists($ destpath) == 0)895 896 if(WaveExists($"root:Packages:NIST:DIV:data") == 0) 817 897 Print "There is no work file in DIV --Aborting" 818 898 Return(1) //error condition … … 836 916 destPath = "root:Packages:NIST:" + type 837 917 Duplicate/O $(destPath + ":data"),$"root:Packages:NIST:CAL:data" 918 Duplicate/O $(destPath + ":linear_data"),$"root:Packages:NIST:CAL:linear_data" 919 Duplicate/O $(destPath + ":linear_data_error"),$"root:Packages:NIST:CAL:linear_data_error" 838 920 // Duplicate/O $(destPath + ":vlegend"),$"root:Packages:NIST:CAL:vlegend" 839 921 Duplicate/O $(destPath + ":textread"),$"root:Packages:NIST:CAL:textread" … … 846 928 destPath = "root:Packages:NIST:CAL" 847 929 //make appropriate wave references 848 Wave data=$(destPath + ":data") // these wave references point to the data in CAL 930 Wave data=$(destPath + ":linear_data") // these wave references point to the data in CAL 931 // Wave data_err=$(destPath + ":linear_data_err") // these wave references point to the data in CAL 932 Wave data_copy=$(destPath + ":data") // these wave references point to the data in CAL 849 933 Wave/t textread=$(destPath + ":textread") //that are to be directly operated on 850 934 Wave integersread=$(destPath + ":integersread") … … 857 941 //do the division, changing data in CAL 858 942 data /= div_data 943 944 // data_err /= div_data 945 946 // keep "data" in sync with linear_data 947 data_copy = data 859 948 860 949 //update CAL header … … 904 993 //w_ is the "work" file 905 994 //both are work files and should already be normalized to 10^8 monitor counts 906 Function Absolute_Scale(type,w_trans,w_thick,s_trans,s_thick,s_izero,s_cross )995 Function Absolute_Scale(type,w_trans,w_thick,s_trans,s_thick,s_izero,s_cross,kappa_err) 907 996 String type 908 Variable w_trans,w_thick,s_trans,s_thick,s_izero,s_cross 997 Variable w_trans,w_thick,s_trans,s_thick,s_izero,s_cross,kappa_err 909 998 910 999 //convert the "type" data to absolute scale using the given standard information … … 914 1003 String destPath 915 1004 //check for "type" 916 destPath = "root:Packages:NIST:"+Type + ":data" 917 if(WaveExists($destpath) == 0) 1005 if(WaveExists($("root:Packages:NIST:"+Type + ":data")) == 0) 918 1006 Print "There is no work file in "+type+"--Aborting" 919 1007 Return(1) //error condition … … 934 1022 //copy from current dir (type) to ABS, defined by destPath 935 1023 Duplicate/O $(oldType + ":data"),$"root:Packages:NIST:ABS:data" 1024 Duplicate/O $(oldType + ":linear_data"),$"root:Packages:NIST:ABS:linear_data" 1025 Duplicate/O $(oldType + ":linear_data_error"),$"root:Packages:NIST:ABS:linear_data_error" 936 1026 // Duplicate/O $(oldType + ":vlegend"),$"root:Packages:NIST:ABS:vlegend" 937 1027 Duplicate/O $(oldType + ":textread"),$"root:Packages:NIST:ABS:textread" … … 945 1035 //now switch to ABS folder 946 1036 //make appropriate wave references 947 WAVE data=$"root:Packages:NIST:ABS:data" // these wave references point to the "type" data in ABS 1037 WAVE data=$"root:Packages:NIST:ABS:linear_data" // these wave references point to the "type" data in ABS 1038 WAVE data_err=$"root:Packages:NIST:ABS:linear_data_error" // these wave references point to the "type" data in ABS 1039 WAVE data_copy=$"root:Packages:NIST:ABS:data" // just for display 948 1040 WAVE/T textread=$"root:Packages:NIST:ABS:textread" //that are to be directly operated on 949 1041 WAVE integersread=$"root:Packages:NIST:ABS:integersread" … … 962 1054 963 1055 //calculate scale factor 1056 Variable scale,trans_err 964 1057 s1 = defmon/realsread[0] //[0] is monitor count (s1 should be 1) 965 1058 s2 = s_thick/w_thick … … 967 1060 s4 = s_cross/s_izero 968 1061 1062 // kappa comes in as s_izero, so be sure to use 1/kappa_err 1063 969 1064 data *= s1*s2*s3*s4 1065 1066 scale = s1*s2*s3*s4 1067 trans_err = realsRead[41] 1068 1069 // print scale 1070 // print data[0][0] 1071 1072 data_err = sqrt(scale^2*data_err^2 + scale^2*data^2*(kappa_err^2/s_izero^2 +trans_err^2/w_trans^2)) 1073 1074 // print data_err[0][0] 1075 1076 // keep "data" in sync with linear_data 1077 data_copy = data 970 1078 971 1079 //********* 15APR02 … … 996 1104 // if the desired workfile doesn't exist, let the user know, and abort 997 1105 String destPath="" 998 destPath = "root:Packages:NIST:"+oldType + ":data" 999 if(WaveExists($destpath) == 0) 1106 if(WaveExists($("root:Packages:NIST:"+oldType + ":data")) == 0) 1000 1107 Print "There is no work file in "+oldtype+"--Aborting" 1001 1108 Return(1) //error condition … … 1010 1117 destPath = "root:Packages:NIST:" + oldtype 1011 1118 Duplicate/O $(destPath + ":data"),$("root:Packages:NIST:"+newtype+":data") 1119 Duplicate/O $(destPath + ":linear_data"),$("root:Packages:NIST:"+newtype+":linear_data") 1120 Duplicate/O $(destPath + ":linear_data_error"),$("root:Packages:NIST:"+newtype+":linear_data_error") 1012 1121 Duplicate/O $(destPath + ":textread"),$("root:Packages:NIST:"+newtype+":textread") 1013 1122 Duplicate/O $(destPath + ":integersread"),$("root:Packages:NIST:"+newtype+":integersread") … … 1015 1124 // 1016 1125 // be sure to get rid of the linear_data if it exists in the destination folder 1017 KillWaves/Z $("root:Packages:NIST:"+newtype+":linear_data") 1126 // KillWaves/Z $("root:Packages:NIST:"+newtype+":linear_data") 1127 1018 1128 //need to save a copy of filelist string too (from the current type folder) 1019 1129 SVAR oldFileList = $(destPath + ":fileList") … … 1108 1218 1109 1219 WAVE/Z data1=$("root:Packages:NIST:"+workMathStr+"File_1:data") 1220 WAVE/Z err1=$("root:Packages:NIST:"+workMathStr+"File_1:linear_data_error") 1221 1222 // set # 2 1110 1223 If(cmpstr(str2,"UNIT MATRIX")==0) 1111 1224 Make/O/N=(pixelsX,pixelsY) root:Packages:NIST:WorkMath:data //don't put in File_2 folder 1112 1225 Wave/Z data2 = root:Packages:NIST:WorkMath:data //it's not real data! 1113 1226 data2=1 1227 Duplicate/O data2 err2 1228 err2 = 0 1114 1229 else 1115 1230 //Load set #2 1116 1231 Load_NamedASC_File(pathStr+str2,workMathStr+"File_2") 1117 1232 WAVE/Z data2=$("root:Packages:NIST:"+workMathStr+"File_2:data") 1233 WAVE/Z err2=$("root:Packages:NIST:"+workMathStr+"File_2:linear_data_error") 1118 1234 Endif 1119 1235 … … 1128 1244 CopyWorkContents(workMathStr+"File_1",workMathStr+dest) 1129 1245 WAVE/Z destData=$("root:Packages:NIST:"+workMathStr+dest+":data") 1246 WAVE/Z destErr=$("root:Packages:NIST:"+workMathStr+dest+":linear_data_error") 1130 1247 1131 1248 //dispatch … … 1133 1250 case "*": //multiplication 1134 1251 destData = const1*data1 * const2*data2 1252 destErr = const1^2*const2^2*(err1^2*data2^2 + err2^2*data1^2) 1253 destErr = sqrt(destErr) 1135 1254 break 1136 1255 case "_": //subtraction 1137 1256 destData = const1*data1 - const2*data2 1257 destErr = const1^2*err1^2 + const2^2*err2^2 1258 destErr = sqrt(destErr) 1138 1259 break 1139 1260 case "/": //division 1140 1261 destData = (const1*data1) / (const2*data2) 1262 destErr = const1^2/const2^2*(err1^2/data2^2 + err2^2*data1^2/data2^4) 1263 destErr = sqrt(destErr) 1141 1264 break 1142 1265 case "+": //addition 1143 1266 destData = const1*data1 + const2*data2 1267 destErr = const1^2*err1^2 + const2^2*err2^2 1268 destErr = sqrt(destErr) 1144 1269 break 1145 1270 endswitch -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/WriteQIS.ipf
r762 r794 419 419 //labelWave[19] = "ASCII data created " +date()+" "+time() 420 420 PathInfo catPathName 421 String sfPath = S_Path+ StringFromList(0,samfiles,";")421 String sfPath = S_Path+RemoveAllSpaces(StringFromList(0,samfiles,";")) //make sure there are no leading spaces in the file name 422 422 print sfPath 423 423 labelWave[19] = "RAW SAM FILE "+StringFromList(0, samfiles , ";")+ " TIMESTAMP: "+getFileCreationDate(sfPath) … … 675 675 676 676 Wave data=$(destStr+typeStr) 677 Wave data_err=$(destStr+":linear_data_error") 677 678 WAVE intw=$(destStr + ":integersRead") 678 679 WAVE rw=$(destStr + ":realsRead") … … 691 692 If(!(WaveExists(data))) 692 693 Abort "data DNExist QxQy_Export()" 694 Endif 695 If(!(WaveExists(data_err))) 696 Abort "linear data error DNExist QxQy_Export()" 693 697 Endif 694 698 If(!(WaveExists(intw))) … … 813 817 //********************* 814 818 815 // generate my own error wave for I(qx,qy) 816 Duplicate/O z_val sw 817 sw = sqrt(z_val) //assumes Poisson statistics for each cell (counter) 818 // sw = 0.05*sw // uniform 5% error? tends to favor the low intensity too strongly 819 // get rid of the "bad" errorsby replacing the NaN, Inf, and zero with V_avg 820 // THIS IS EXTREMEMLY IMPORTANT - if this is not done, there are some "bad" values in the 821 // error wave (things that are not numbers) - and this wrecks the smeared model fitting. 822 // It appears to have no effect on the unsmeared model. 823 WaveStats/Q sw 824 sw = numtype(sw[p]) == 0 ? sw[p] : V_avg 825 sw = sw[p] != 0 ? sw[p] : V_avg 826 819 // // generate my own error wave for I(qx,qy) 820 // Duplicate/O z_val sw 821 // sw = sqrt(z_val) //assumes Poisson statistics for each cell (counter) 822 // // sw = 0.05*sw // uniform 5% error? tends to favor the low intensity too strongly 823 // // get rid of the "bad" errorsby replacing the NaN, Inf, and zero with V_avg 824 // // THIS IS EXTREMEMLY IMPORTANT - if this is not done, there are some "bad" values in the 825 // // error wave (things that are not numbers) - and this wrecks the smeared model fitting. 826 // // It appears to have no effect on the unsmeared model. 827 // WaveStats/Q sw 828 // sw = numtype(sw[p]) == 0 ? sw[p] : V_avg 829 // sw = sw[p] != 0 ? sw[p] : V_avg 830 831 // now use the properly propagated 2D error 832 Duplicate/O data_err sw 833 Redimension/N=(pixelsX*pixelsY) sw 834 835 827 836 828 837 //not demo-compatible, but approx 8x faster!!
Note: See TracChangeset
for help on using the changeset viewer.