source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/VSANS/V_WB_GaussSpheres.ipf @ 1222

Last change on this file since 1222 was 1222, checked in by srkline, 3 years ago

Updated help file for VSANS. Graphics were not PNG.

Removed HFIR SANS package since if requires XML XOP - no longer supported.

Improved quality of graphics export for Analysis reports.

Added more support for super_white_beam mode on VSANS

Corrected printf bug (Igor 8) when printing out % sign

Added utilities for patching wavelength and monochromator type on VSANS since the type is still not written out correctly by NICE, and super_white_beam is not yet defined in NICE

Adjusted panel dimensions for the temperature sensor display on VSANS (needed onWindows)

File size: 6.0 KB
RevLine 
[1098]1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5// turn the White Beam resolution smearing into a fitting function
6// so that the wavelength smeared function can then be smeared by
7// a gaussian resolution function that has geometry only.
8//
9// The geometry only resolution is generated by passing dl/l=0 to the resolution
10// calculation.
11//
12// This representation uses the "middle" of the distribution
13
14//
15//
16
17//#include "sphere_v40"
18// plots the form factor of  spheres with a Gaussian radius distribution
19//
20// also can plot the distribution itself, based on the current model parameters
21//
22// integration is currently done using 20-pt quadrature, but may benefit from
23//switching to an adaptive integration.
24//
25
26Proc PlotGaussSpheresWB(num,qmin,qmax)
27        Variable num=128,qmin=0.001,qmax=0.7
28        Prompt num "Enter number of data points for model: "
29        Prompt qmin "Enter minimum q-value (A^-1) for model: "
30        Prompt qmax "Enter maximum q-value (A^-1) for model: "
31       
32        Make/O/D/N=(num) xwave_pgsWB,ywave_pgsWB
33        xwave_pgsWB = alog( log(qmin) + x*((log(qmax)-log(qmin))/num) )
34        Make/O/D coef_pgsWB = {0.01,60,0.2,1e-6,3e-6,0.001}
35        make/O/T parameters_pgsWB = {"Volume Fraction (scale)","mean radius (A)","polydisp (sig/avg)","SLD sphere (A-2)","SLD solvent (A-2)","bkg (cm-1 sr-1)"}
36        Edit parameters_pgsWB,coef_pgsWB
37       
38        Variable/G root:g_pgsWB
39        g_pgsWB := GaussSpheresWB(coef_pgsWB,ywave_pgsWB,xwave_pgsWB)
40        Display ywave_pgsWB vs xwave_pgsWB
41        ModifyGraph log=1,marker=29,msize=2,mode=4
42        Label bottom "q (A\\S-1\\M)"
43        Label left "Intensity (cm\\S-1\\M)"
44        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
45       
46        AddModelToStrings("GaussSpheresWB","coef_pgsWB","parameters_pgsWB","pgsWB")
47End
48
49// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
50Proc PlotSmearedGaussSpheresWB(str)                                                             
51        String str
52        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
53       
54        // if any of the resolution waves are missing => abort
55        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
56                Abort
57        endif
58       
59        SetDataFolder $("root:"+str)
60       
61        // Setup parameter table for model function
62        Make/O/D smear_coef_pgsWB = {0.01,60,0.2,1e-6,3e-6,0.001}                                       
63        make/o/t smear_parameters_pgsWB = {"Volume Fraction (scale)","mean radius (A)","polydisp (sig/avg)","SLD sphere (A-2)","SLD solvent (A-2)","bkg (cm-1 sr-1)"}   
64        Edit smear_parameters_pgsWB,smear_coef_pgsWB                                   
65       
66        // output smeared intensity wave, dimensions are identical to experimental QSIG values
67        // make extra copy of experimental q-values for easy plotting
68        Duplicate/O $(str+"_q") smeared_pgsWB,smeared_qvals                             
69        SetScale d,0,0,"1/cm",smeared_pgsWB                                                     
70                                       
71        Variable/G gs_pgsWB=0
72        gs_pgsWB := fSmearedGaussSpheresWB(smear_coef_pgsWB,smeared_pgsWB,smeared_qvals)        //this wrapper fills the STRUCT
73       
74        Display smeared_pgsWB vs smeared_qvals                                                                 
75        ModifyGraph log=1,marker=29,msize=2,mode=4
76        Label bottom "q (A\\S-1\\M)"
77        Label left "Intensity (cm\\S-1\\M)"
78        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
79       
80        SetDataFolder root:
81        AddModelToStrings("SmearedGaussSpheresWB","smear_coef_pgsWB","smear_parameters_pgsWB","pgsWB")
82End
83       
84
85
86
87//AAO version, uses XOP if available
88// simply calls the original single point calculation with
89// a wave assignment (this will behave nicely if given point ranges)
90Function GaussSpheresWB(cw,yw,xw) : FitFunc
91        Wave cw,yw,xw
92       
93#if exists("GaussSpheresX")
94//      MultiThread yw = GaussSpheresX(cw,xw)
95        yw = V_fGaussSpheresWB(cw,xw)
96
97#else
98//      yw = fGaussSpheresWB(cw,xw)
99        yw = 1
100#endif
101        return(0)
102End
103
104Function V_fGaussSpheresWB(w,xx) : FitFunc
105        wave w
106        variable xx
107       
108        Variable scale,rad,pd,sig,rho,rhos,bkg,delrho,inten,loLim,upLim
109       
110        //the coefficient values
111//      scale=w[0]
112//      rad=w[1]
113//      pd=w[2]
114//      sig=pd*rad
115//      rho=w[3]
116//      rhos=w[4]
117//      delrho=rho-rhos
118//      bkg=w[5]
119       
120       
121        // define limits based on lo/mean, hi/mean of the wavelength distribution
122        // using the empirical definition, "middle" of the peaks
[1222]123        loLim = 3.37/kWhiteBeam_Mean
124        upLim = 8.37/kWhiteBeam_Mean
[1098]125       
126        inten = V_IntegrGaussSphereWB_mid(w,loLim,upLim,xx)
127
128// why do I need this? Is this because this is defined as the mean of the distribution
129//  and is needed to normalize the integral? verify this on paper.     
[1222]130        inten *= kWhiteBeam_Mean
[1098]131
132// normalize the integral       
[1222]133        inten /= kWhiteBeam_Normalization               // "middle"  of peaks
[1098]134
[1209]135        inten -= w[5]
[1098]136// additional normalization???
137        inten /= 1.05           //
138       
[1209]139        inten += w[5]
[1098]140        Return(inten)
141End
142
143
144// the trick here is that declaring the last qVal wave as a variable
145// since this is implicitly called N times in the wave assignment of the answer wave
146Function V_IntegrGaussSphereWB_mid(cw,loLim,upLim,qVal)
147        Wave cw
148        Variable loLim,upLim
149        Variable qVal
150       
151        Variable/G root:qq = qval
152        Variable ans
153       
154//      ans = Integrate1D(V_intgrnd_top,lolim,uplim,2,0,cw)             //adaptive quadrature
155        ans = Integrate1D(V_integrand_pgsWB,lolim,uplim,1,0,cw)         // Romberg integration
156       
157        return ans
158end
159
160Function V_integrand_pgsWB(cw,dum)
161        Wave cw
162        Variable dum            // the dummy of the integration
163
164        Variable val
165        NVAR qq = root:qq               //the q-value of the integration, not part of cw, so pass global
166//      SVAR funcStr = root:gFunctionString
167//      FUNCREF SANSModel_proto func = $funcStr
168
[1222]169        val = V_WhiteBeamDist_mid(dum*kWhiteBeam_Mean)*GaussSpheresX(cw,qq/dum)
[1098]170       
171        return (val)
172End
173
174//wrapper to calculate the smeared model as an AAO-Struct
175// fills the struct and calls the ususal function with the STRUCT parameter
176//
177// used only for the dependency, not for fitting
178//
179Function fSmearedGaussSpheresWB(coefW,yW,xW)
180        Wave coefW,yW,xW
181       
182        String str = getWavesDataFolder(yW,0)
183        String DF="root:"+str+":"
184       
185        WAVE resW = $(DF+str+"_res")
186       
187        STRUCT ResSmearAAOStruct fs
188        WAVE fs.coefW = coefW   
189        WAVE fs.yW = yW
190        WAVE fs.xW = xW
191        WAVE fs.resW = resW
192       
193        Variable err
194        err = SmearedGaussSpheresWB(fs)
195       
196        return (0)
197End
198
199// this is all there is to the smeared calculation!
200Function SmearedGaussSpheresWB(s) :FitFunc
201        Struct ResSmearAAOStruct &s
202
203//      the name of your unsmeared model (AAO) is the first argument
204        Smear_Model_20(GaussSpheresWB,s.coefW,s.xW,s.yW,s.resW)
205
206        return(0)
207End
208
209
Note: See TracBrowser for help on using the repository browser.