Changeset 583
- Timestamp:
- Oct 27, 2009 2:07:14 PM (13 years ago)
- Location:
- sans/Dev/trunk/NCNR_User_Procedures
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Cylinder_v40.ipf
r570 r583 79 79 80 80 #if exists("CylinderFormX") 81 // yw = CylinderFormX(cw,xw) 81 82 MultiThread yw = CylinderFormX(cw,xw) 82 83 #else -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/MultScatter_MonteCarlo_2D.ipf
r572 r583 907 907 SetVariable cntVar,pos={185,73},size={90,15},proc=CountTimeSetVarProc,title="time(s)" 908 908 SetVariable cntVar,format="%d" 909 SetVariable cntVar,limits={1, 600,1},value= root:Packages:NIST:SAS:gCntTime909 SetVariable cntVar,limits={1,3600,1},value= root:Packages:NIST:SAS:gCntTime 910 910 Button MC_button2,pos={17,234},size={100,20},proc=SaveAsVAXButtonProc,title="Save 2D VAX" 911 911 CheckBox check0,pos={216,180},size={68,14},title="Raw counts",variable = root:Packages:NIST:SAS:gRawCounts … … 1037 1037 // will prompt for the sample label 1038 1038 // 1039 // currently hard-wired for SAS data folder 1040 // 1039 1041 Function SaveAsVAXButtonProc(ctrlName) : ButtonControl 1040 1042 String ctrlName 1041 1043 1042 Write_RawData_File("SAS","",0) 1044 String fullpath="",destStr="" 1045 Variable refnum 1046 1047 fullpath = Write_RawData_File("SAS","",0) 1048 1049 // write out the results into a text file 1050 destStr = "root:Packages:NIST:SAS:" 1051 SetDataFolder $destStr 1052 1053 WAVE results=results 1054 WAVE/T results_desc=results_desc 1055 1056 //check each wave 1057 If(!(WaveExists(results))) 1058 Abort "results DNExist WriteVAXData()" 1059 Endif 1060 If(!(WaveExists(results_desc))) 1061 Abort "results_desc DNExist WriteVAXData()" 1062 Endif 1063 1064 Open refNum as fullpath+".txt" 1065 wfprintf refNum, "%30s\t\t%g\r",results_desc,results 1066 FStatus refNum 1067 FSetPos refNum,V_logEOF 1068 Close refNum 1069 1070 /////////////////////////////// 1071 1072 // could also automatically do the average here, but probably not worth the the effort... 1073 1074 SetDataFolder root: 1075 1076 return(0) 1043 1077 End 1044 1078 … … 1306 1340 ValDisplay valdisp0_3,pos={326,121},size={220,13},title="Estimated transmission" 1307 1341 ValDisplay valdisp0_3,limits={0,0,0},barmisc={0,1000},value=root:Packages:NIST:SAS:g_1DEstTrans 1342 ValDisplay valdisp0_4,pos={326,145},size={220,13},title="Multiple Coherent Scattering" 1343 ValDisplay valdisp0_4,limits={0,0,0},barmisc={0,1000},value=root:Packages:NIST:SAS:g_MultScattFraction 1308 1344 // set the flags here -- do the simulation, but not 2D 1309 1345 … … 1425 1461 NVAR detCR = root:Packages:NIST:SAS:g_1DEstDetCR // estimated detector count rate 1426 1462 NVAR fractScat = root:Packages:NIST:SAS:g_1DFracScatt 1463 NVAR mScat = root:Packages:NIST:SAS:g_MultScattFraction 1427 1464 1428 1465 SIMProtocol[0] = junk … … 1431 1468 SIMProtocol[3] = "\tDetector countrate (1/s) = "+num2str(detCR) 1432 1469 SIMProtocol[4] = "\tFraction of beam scattered coherently = "+num2str(fractScat) 1433 SIMProtocol[5] = junk1470 SIMProtocol[5] = "\tFraction of multiple coherent scattering = "+num2str(mScat) 1434 1471 SIMProtocol[6] = "" 1435 1472 SIMProtocol[7] = "" … … 1565 1602 1566 1603 End 1604 1605 1606 /// called in SASCALC:ReCalculateInten() 1607 Function Simulate_1D(funcStr,aveint,qval,sigave,sigmaq,qbar,fsubs) 1608 String funcStr 1609 WAVE aveint,qval,sigave,sigmaq,qbar,fsubs 1610 1611 Variable r1,xCtr,yCtr,sdd,pixSize,wavelength 1612 String coefStr,abortStr,str 1613 1614 FUNCREF SANSModelAAO_MCproto func=$("fSmeared"+funcStr) //a wrapper for the structure version 1615 FUNCREF SANSModelAAO_MCproto funcUnsmeared=$(funcStr) //unsmeared 1616 coefStr = MC_getFunctionCoef(funcStr) 1617 1618 if(!MC_CheckFunctionAndCoef(funcStr,coefStr)) 1619 Abort "Function and coefficients do not match. You must plot the unsmeared function before simulation." 1620 endif 1621 1622 Wave inten=$"root:Simulation:Simulation_i" // this will exist and send the smeared calculation to the corect DF 1623 1624 // the resolution-smeared intensity is calculated, including the incoherent background 1625 func($coefStr,inten,qval) 1626 1627 NVAR imon = root:Packages:NIST:SAS:gImon 1628 NVAR ctTime = root:Packages:NIST:SAS:gCntTime 1629 NVAR thick = root:Packages:NIST:SAS:gThick 1630 NVAR trans = root:Packages:NIST:SAS:gSamTrans 1631 NVAR SimDetCts = root:Packages:NIST:SAS:g_1DTotCts //summed counts (simulated) 1632 NVAR estDetCR = root:Packages:NIST:SAS:g_1DEstDetCR // estimated detector count rate 1633 NVAR fracScat = root:Packages:NIST:SAS:g_1DFracScatt // fraction of beam captured on detector 1634 NVAR estTrans = root:Packages:NIST:SAS:g_1DEstTrans // estimated transmission of sample 1635 NVAR mScat = root:Packages:NIST:SAS:g_MultScattFraction 1636 1637 WAVE rw=root:Packages:NIST:SAS:realsRead 1638 WAVE nCells=root:Packages:NIST:SAS:nCells 1639 1640 pixSize = rw[10]/10 // convert pix size in mm to cm 1641 sdd = rw[18]*100 //convert header of [m] to [cm] 1642 wavelength = rw[26] // in 1/A 1643 1644 imon = beamIntensity()*ctTime 1645 1646 // calculate the scattering cross section simply to be able to estimate the transmission 1647 Variable sig_sas=0 1648 1649 // remember that the random deviate is the coherent portion ONLY - the incoherent background is 1650 // subtracted before the calculation. 1651 CalculateRandomDeviate(funcUnsmeared,$coefStr,wavelength,"root:Packages:NIST:SAS:ran_dev",sig_sas) 1652 1653 // if(sig_sas > 100) 1654 // sprintf abortStr,"sig_sas = %g. Please check that the model coefficients have a zero background, or the low q is well-behaved.",sig_sas 1655 // endif 1656 1657 // calculate the multiple scattering fraction for display (10/2009) 1658 Variable ii,nMax=10,tau 1659 mScat=0 1660 tau = thick*sig_sas 1661 // this sums the normalized scattering P', so the result is the fraction of multiply coherently scattered 1662 // neutrons out of those that were scattered 1663 for(ii=2;ii<nMax;ii+=1) 1664 mScat += tau^(ii)/factorial(ii) 1665 // print tau^(ii)/factorial(ii) 1666 endfor 1667 estTrans = exp(-1*thick*sig_sas) //thickness and sigma both in units of cm 1668 mscat *= (estTrans)/(1-estTrans) 1669 1670 if(mScat > 0.1) // /Z to supress error if this was a 1D calc with the 2D panel open 1671 ValDisplay/Z valdisp0_4 win=Sim_1D_Panel,labelBack=(65535,32768,32768) 1672 else 1673 ValDisplay/Z valdisp0_4 win=Sim_1D_Panel,labelBack=0 1674 endif 1675 1676 1677 Print "Sig_sas = ",sig_sas 1678 1679 Duplicate/O qval prob_i,countsInAnnulus 1680 1681 // not needed - nCells takes care of this when the error is correctly calculated 1682 // Duplicate/O qval circle_fraction,rval,nCells_expected 1683 // rval = sdd*tan(2*asin(qval*wavelength/4/pi)) //radial distance in cm 1684 // nCells_expected = 2*pi*rval/pixSize //does this need to be an integer? 1685 // circle_fraction = nCells / nCells_expected 1686 1687 1688 // prob_i = trans*thick*nCells*(pixSize/sdd)^2*inten //probability of a neutron in q-bin(i) that has nCells 1689 prob_i = trans*thick*(pixSize/sdd)^2*inten //probability of a neutron in q-bin(i) 1690 1691 Variable P_on = sum(prob_i,-inf,inf) 1692 Print "P_on = ",P_on 1693 1694 // fracScat = P_on 1695 fracScat = 1-estTrans 1696 1697 // aveint = (Imon)*prob_i / circle_fraction / nCells_expected 1698 aveint = (Imon)*prob_i 1699 1700 countsInAnnulus = aveint*nCells 1701 SimDetCts = sum(countsInAnnulus,-inf,inf) 1702 estDetCR = SimDetCts/ctTime 1703 1704 1705 NVAR doABS = root:Packages:NIST:SAS:g_1D_DoABS 1706 NVAR addNoise = root:Packages:NIST:SAS:g_1D_AddNoise 1707 1708 // this is where the number of cells comes in - the calculation of the error bars 1709 // sigma[i] = SUM(sigma[ij]^2) / nCells^2 1710 // and since in the simulation, SUM(sigma[ij]^2) = nCells*sigma[ij]^2 = nCells*Inten 1711 // then... 1712 sigave = sqrt(aveint/nCells) // corrected based on John's memo, from 8/9/99 1713 1714 // add in random error in aveint based on the sigave 1715 if(addNoise) 1716 aveint += gnoise(sigave) 1717 endif 1718 1719 // signature in the standard deviation, do this after the noise is added 1720 // start at 10 to be out of the beamstop (makes for nicer plotting) 1721 // end at 50 to leave the natural statistics at the end of the set (may have a total of 80+ points if no offset) 1722 sigave[10,50;10] = 10*sigave[p] 1723 1724 // convert to absolute scale 1725 if(doABS) 1726 Variable kappa = thick*(pixSize/sdd)^2*trans*iMon 1727 aveint /= kappa 1728 sigave /= kappa 1729 endif 1730 1731 1732 return(0) 1733 End 1734 1735 /// for testing only 1736 Function testProbability(sas,thick) 1737 Variable sas,thick 1738 1739 Variable tau,trans,p2p,p3p,p4p 1740 1741 tau = sas*thick 1742 trans = exp(-tau) 1743 1744 Print "tau = ",tau 1745 Print "trans = ",trans 1746 1747 p2p = tau^2/factorial(2)*trans/(1-trans) 1748 p3p = tau^3/factorial(3)*trans/(1-trans) 1749 p4p = tau^4/factorial(4)*trans/(1-trans) 1750 1751 Print "double scattering = ",p2p 1752 Print "triple scattering = ",p3p 1753 Print "quadruple scattering = ",p4p 1754 1755 Variable ii,nMax=10,mScat=0 1756 for(ii=2;ii<nMax;ii+=1) 1757 mScat += tau^(ii)/factorial(ii) 1758 // print tau^(ii)/factorial(ii) 1759 endfor 1760 mscat *= (Trans)/(1-Trans) 1761 1762 Print "Total fraction of multiple scattering = ",mScat 1763 1764 return(mScat) 1765 End -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/NCNR_DataReadWrite.ipf
r578 r583 1865 1865 // data file, as if it was a raw data file 1866 1866 // 1867 Function Write_RawData_File(type,fullpath,dialog)1867 Function/S Write_RawData_File(type,fullpath,dialog) 1868 1868 String type,fullpath 1869 1869 Variable dialog //=1 will present dialog for name 1870 1870 1871 Write_VAXRaw_Data(type,fullpath,dialog) 1872 1873 return(0) 1871 String filename = "" 1872 filename = Write_VAXRaw_Data(type,fullpath,dialog) 1873 1874 return(filename) 1874 1875 End 1875 1876 … … 1899 1900 // Print Secs2Date(DateTime,-2) // 1993-03-14 //this call is independent of System date/time!// 1900 1901 // 1901 // for now, 20 characters 01-JAN-2009 12:12:121902 1902 // 1903 1903 // simulation should call as ("SAS","",0) to bypass the dialog, and to fill the header … … 1905 1905 // 1906 1906 /// 1907 Function Write_VAXRaw_Data(type,fullpath,dialog) 1907 // changed to return the string w/ the filename as written for later use 1908 Function/S Write_VAXRaw_Data(type,fullpath,dialog) 1908 1909 String type,fullpath 1909 1910 Variable dialog //=1 will present dialog for name … … 2241 2242 Close refNum 2242 2243 2243 2244 // write out the results into a text file2245 // SetDataFolder $destStr2246 WAVE results=results2247 WAVE/T results_desc=results_desc2248 2249 //check each wave2250 If(!(WaveExists(results)))2251 Abort "results DNExist WriteVAXData()"2252 Endif2253 If(!(WaveExists(results_desc)))2254 Abort "results_desc DNExist WriteVAXData()"2255 Endif2256 2257 Save/T results_desc,results as fullpath+".itx"2258 2259 ///////////////////////////////2260 2261 2244 // all done 2262 2245 Killwaves/Z tmpFile,dataWRecMarkers … … 2264 2247 Print "Saved VAX binary data as: ",textW[0] 2265 2248 SetDatafolder root: 2266 return( 0)2249 return(fullpath) 2267 2250 End 2268 2251 … … 2442 2425 index += 1 2443 2426 2444 tw[0] = prefix+num2str(runNum)+".SA2_SIM_A"+num2str(runNum) 2427 //make a three character string of the run number 2428 String numStr="" 2429 if(runNum<10) 2430 numStr = "00"+num2str(runNum) 2431 else 2432 if(runNum<100) 2433 numStr = "0"+num2str(runNum) 2434 else 2435 numStr = num2str(runNum) 2436 Endif 2437 Endif 2438 //date()[0] is the first letter of the day of the week 2439 // OK for most cases, except for an overnight simulation! then the suffix won't sort right... 2440 // tw[0] = prefix+numstr+".SA2_SIM_"+(date()[0])+numStr 2441 2442 //fancier, JAN=A, FEB=B, etc... 2443 String timeStr= secs2date(datetime,-1) 2444 String monthStr=StringFromList(1, timeStr ,"/") 2445 2446 tw[0] = prefix+numstr+".SA2_SIM_"+(num2char(str2num(monthStr)+64))+numStr 2445 2447 2446 2448 labelStr = PadString(labelStr,60,0x20) //60 fortran-style spaces -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/SASCALC.ipf
r577 r583 133 133 Variable/G root:Packages:NIST:SAS:g_1D_DoABS = 1 134 134 Variable/G root:Packages:NIST:SAS:g_1D_AddNoise = 1 135 Variable/G root:Packages:NIST:SAS:g_MultScattFraction=0 135 136 136 137 //tick labels for SDD slider … … 926 927 927 928 if(exists(funcStr) != 0) 928 FUNCREF SANSModelAAO_MCproto func=$("fSmeared"+funcStr) //a wrapper for the structure version929 FUNCREF SANSModelAAO_MCproto funcUnsmeared=$(funcStr) //unsmeared930 coefStr = MC_getFunctionCoef(funcStr)931 929 932 if(!MC_CheckFunctionAndCoef(funcStr,coefStr)) 933 Abort "Function and coefficients do not match. You must plot the unsmeared function before simulation." 934 endif 935 936 Wave inten=$"root:Simulation:Simulation_i" // this will exist and send the smeared calculation to the corect DF 937 938 // the resolution-smeared intensity is calculated, including the incoherent background 939 func($coefStr,inten,qval) 940 941 NVAR imon = root:Packages:NIST:SAS:gImon 942 NVAR ctTime = root:Packages:NIST:SAS:gCntTime 943 NVAR thick = root:Packages:NIST:SAS:gThick 944 NVAR trans = root:Packages:NIST:SAS:gSamTrans 945 NVAR SimDetCts = root:Packages:NIST:SAS:g_1DTotCts //summed counts (simulated) 946 NVAR estDetCR = root:Packages:NIST:SAS:g_1DEstDetCR // estimated detector count rate 947 NVAR fracScat = root:Packages:NIST:SAS:g_1DFracScatt // fraction of beam captured on detector 948 NVAR estTrans = root:Packages:NIST:SAS:g_1DEstTrans // estimated transmission of sample 949 NVAR SimCountTime = root:Packages:NIST:SAS:gCntTime //counting time used for simulation 950 951 WAVE rw=root:Packages:NIST:SAS:realsRead 952 WAVE nCells=root:Packages:NIST:SAS:nCells 953 954 pixSize = rw[10]/10 // convert pix size in mm to cm 955 sdd = rw[18]*100 //convert header of [m] to [cm] 956 wavelength = rw[26] // in 1/A 957 958 imon = beamIntensity() 959 960 // calculate the scattering cross section simply to be able to estimate the transmission 961 Variable sig_sas=0 962 963 // remember that the random deviate is the coherent portion ONLY - the incoherent background is 964 // subtracted before the calculation. 965 CalculateRandomDeviate(funcUnsmeared,$coefStr,wavelength,"root:Packages:NIST:SAS:ran_dev",sig_sas) 966 967 // if(sig_sas > 100) 968 // sprintf abortStr,"sig_sas = %g. Please check that the model coefficients have a zero background, or the low q is well-behaved.",sig_sas 969 // endif 970 estTrans = exp(-1*thick*sig_sas) //thickness and sigma both in units of cm 971 Print "Sig_sas = ",sig_sas 972 973 Duplicate/O qval prob_i,countsInAnnulus 974 975 // not needed - nCells takes care of this when the error is correctly calculated 976 // Duplicate/O qval circle_fraction,rval,nCells_expected 977 // rval = sdd*tan(2*asin(qval*wavelength/4/pi)) //radial distance in cm 978 // nCells_expected = 2*pi*rval/pixSize //does this need to be an integer? 979 // circle_fraction = nCells / nCells_expected 980 981 982 // prob_i = trans*thick*nCells*(pixSize/sdd)^2*inten //probability of a neutron in q-bin(i) that has nCells 983 prob_i = trans*thick*(pixSize/sdd)^2*inten //probability of a neutron in q-bin(i) 984 985 Variable P_on = sum(prob_i,-inf,inf) 986 Print "P_on = ",P_on 987 988 // fracScat = P_on 989 fracScat = 1-estTrans 990 991 // aveint = (Imon*ctTime)*prob_i / circle_fraction / nCells_expected 992 aveint = (Imon*ctTime)*prob_i 993 994 countsInAnnulus = aveint*nCells 995 SimDetCts = sum(countsInAnnulus,-inf,inf) 996 estDetCR = SimDetCts/SimCountTime 997 998 999 NVAR doABS = root:Packages:NIST:SAS:g_1D_DoABS 1000 NVAR addNoise = root:Packages:NIST:SAS:g_1D_AddNoise 1001 1002 // this is where the number of cells comes in - the calculation of the error bars 1003 // sigma[i] = SUM(sigma[ij]^2) / nCells^2 1004 // and since in the simulation, SUM(sigma[ij]^2) = nCells*sigma[ij]^2 = nCells*Inten 1005 // then... 1006 sigave = sqrt(aveint/nCells) // corrected based on John's memo, from 8/9/99 1007 1008 // add in random error in aveint based on the sigave 1009 if(addNoise) 1010 aveint += gnoise(sigave) 1011 endif 1012 1013 // convert to absolute scale 1014 if(doABS) 1015 Variable kappa = thick*(pixSize/sdd)^2*trans*iMon*ctTime 1016 aveint /= kappa 1017 sigave /= kappa 1018 endif 930 Simulate_1D(funcStr,aveint,qval,sigave,sigmaq,qbar,fsubs) 1019 931 1020 932 else -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/USANS/U_CALC.ipf
r577 r583 134 134 Variable/G g_1DFracScatt= 0 // ?? 135 135 Variable/G g_1DEstTrans = 0 // ? can I calculate this? 136 Variable/G g_MultScattFraction = 0 137 136 138 137 139 // not on panel yet … … 311 313 312 314 GroupBox group0,pos={5,1},size={493,177},title="Instrument Setup" 313 GroupBox group1,pos={5,183},size={240,1 47},title="Sample Setup"314 GroupBox group2,pos={5,3 43},size={259,147},title="Results"315 GroupBox group1,pos={5,183},size={240,110},title="Sample Setup" 316 GroupBox group2,pos={5,310},size={240,170},title="Results" 315 317 316 318 PopupMenu popup0,pos={17,19},size={165,20},title="Sample Aperture Diam (in)" … … 455 457 456 458 // a box for the results 457 SetVariable totalTime,pos={left+20,3 70},size={150,15},title="Count time (h:m)",value= gTotTimeStr458 ValDisplay valdisp0_2,pos={left+20,395},size={220,13},title="Fraction of beam scattered"459 ValDisplay valdisp0_2,limits={0,0,0},barmisc={0,1000},value= root:Packages:NIST:USANS:Globals:U_Sim:g_1DFracScatt460 ValDisplay valdisp0_2,disable=1461 ValDisplay valdisp0_3,pos={left+20,420},size={220,13},title="Estimated transmission"462 ValDisplay valdisp0_3,limits={0,0,0},barmisc={0,1000},value=root:Packages:NIST:USANS:Globals:U_Sim:g_1DEstTrans463 ValDisplay valdisp0_3,disable=1464 Button button1,pos={left+20, 400},size={150,20},proc=U_SavePanelProc,title="Save PNG"465 Button button2,pos={left+20,4 30},size={150,20},proc=U_ConfigTextProc,title="Config Text"466 Button button3,pos={left+20,4 60},size={150,20},proc=U_SaveButtonProc,title="Save Simulated Data"459 SetVariable totalTime,pos={left+20,335},size={150,15},title="Count time (h:m)",value= gTotTimeStr 460 SetVariable totalTime,limits={-inf,inf,0},noedit=1 461 SetVariable valdisp0_2,pos={left+20,365},size={190,15},title="Multiple Coherent Scattering" 462 SetVariable valdisp0_2,limits={-inf,inf,0},noedit=1,value=g_MultScattFraction 463 // ValDisplay valdisp0_3,pos={left+20,420},size={220,13},title="Estimated transmission" 464 // ValDisplay valdisp0_3,limits={0,0,0},barmisc={0,1000},value=root:Packages:NIST:USANS:Globals:U_Sim:g_1DEstTrans 465 // ValDisplay valdisp0_3,disable=1 466 Button button1,pos={left+20,390},size={150,20},proc=U_SavePanelProc,title="Save PNG" 467 Button button2,pos={left+20,420},size={150,20},proc=U_ConfigTextProc,title="Config Text" 468 Button button3,pos={left+20,450},size={150,20},proc=U_SaveButtonProc,title="Save Simulated Data" 467 469 468 470 // help, done buttons … … 906 908 // sprintf abortStr,"sig_sas = %g. Please check that the model coefficients have a zero background, or the low q is well-behaved.",sig_sas 907 909 // endif 910 // calculate the multiple scattering fraction for display (10/2009) 911 NVAR mScat = root:Packages:NIST:USANS:Globals:U_Sim:g_MultScattFraction 912 Variable nMax=10,tau 913 mScat=0 914 tau = thick*sig_sas 915 // this sums the normalized scattering P', so the result is the fraction of multiply coherently scattered 916 // neutrons out of those that were scattered 917 for(ii=2;ii<nMax;ii+=1) 918 mScat += tau^(ii)/factorial(ii) 919 // print tau^(ii)/factorial(ii) 920 endfor 908 921 estTrans = exp(-1*thick*sig_sas) //thickness and sigma both in units of cm 922 mscat *= (estTrans)/(1-estTrans) 923 924 if(mScat > 0.1) 925 SetVariable valdisp0_2 win=UCALC,labelBack=(65535,32768,32768) 926 else 927 SetVariable valdisp0_2 win=UCALC,labelBack=0 928 endif 929 930 909 931 Print "Sig_sas = ",sig_sas 910 932
Note: See TracChangeset
for help on using the changeset viewer.