source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/VSANS/V_SWB_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.2 KB
Line 
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 PlotGaussSpheresSWB(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_pgsSWB,ywave_pgsSWB
33        xwave_pgsSWB = alog( log(qmin) + x*((log(qmax)-log(qmin))/num) )
34        Make/O/D coef_pgsSWB = {0.01,60,0.2,1e-6,3e-6,0.001}
35        make/O/T parameters_pgsSWB = {"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_pgsSWB,coef_pgsSWB
37       
38        Variable/G root:g_pgsSWB
39        g_pgsSWB := GaussSpheresSWB(coef_pgsSWB,ywave_pgsSWB,xwave_pgsSWB)
40        Display ywave_pgsSWB vs xwave_pgsSWB
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("GaussSpheresSWB","coef_pgsSWB","parameters_pgsSWB","pgsSWB")
47End
48
49// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
50Proc PlotSmearedGaussSpheresSWB(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_pgsSWB = {0.01,60,0.2,1e-6,3e-6,0.001}                                     
63        make/o/t smear_parameters_pgsSWB = {"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_pgsSWB,smear_coef_pgsSWB                                 
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_pgsSWB,smeared_qvals                           
69        SetScale d,0,0,"1/cm",smeared_pgsSWB                                                   
70                                       
71        Variable/G gs_pgsSWB=0
72        gs_pgsSWB := fSmearedGaussSpheresSWB(smear_coef_pgsSWB,smeared_pgsSWB,smeared_qvals)    //this wrapper fills the STRUCT
73       
74        Display smeared_pgsSWB 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("SmearedGaussSpheresSWB","smear_coef_pgsSWB","smear_parameters_pgsSWB","pgsSWB")
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 GaussSpheresSWB(cw,yw,xw) : FitFunc
91        Wave cw,yw,xw
92       
93#if exists("GaussSpheresX")
94//      MultiThread yw = GaussSpheresX(cw,xw)
95        yw = V_fGaussSpheresSWB(cw,xw)
96
97#else
98//      yw = fGaussSpheresSWB(cw,xw)
99        yw = 1
100#endif
101        return(0)
102End
103
104Function V_fGaussSpheresSWB(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
123        loLim = 3.37/kSuperWhiteBeam_Mean
124        upLim = 20/kSuperWhiteBeam_Mean
125       
126        inten = V_IntegrGaussSphereSWB_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.     
130        inten *= kSuperWhiteBeam_Mean
131
132// normalize the integral       
133        inten /= kSuperWhiteBeam_Normalization          // "middle"  of peaks
134
135        inten -= w[5]
136// additional normalization???
137        inten /= 1.05           //
138       
139//      inten /= 2                      // need this factor to match low q of white beam??? -- and to get invariant to work...
140       
141        inten += w[5]
142        Return(inten)
143End
144
145
146// the trick here is that declaring the last qVal wave as a variable
147// since this is implicitly called N times in the wave assignment of the answer wave
148Function V_IntegrGaussSphereSWB_mid(cw,loLim,upLim,qVal)
149        Wave cw
150        Variable loLim,upLim
151        Variable qVal
152       
153        Variable/G root:qq = qval
154        Variable ans
155       
156//      ans = Integrate1D(V_intgrnd_top,lolim,uplim,2,0,cw)             //adaptive quadrature
157        ans = Integrate1D(V_integrand_pgsSWB,lolim,uplim,1,0,cw)                // Romberg integration
158       
159        return ans
160end
161
162Function V_integrand_pgsSWB(cw,dum)
163        Wave cw
164        Variable dum            // the dummy of the integration
165
166        Variable val
167        NVAR qq = root:qq               //the q-value of the integration, not part of cw, so pass global
168//      SVAR funcStr = root:gFunctionString
169//      FUNCREF SANSModel_proto func = $funcStr
170
171        val = V_SuperWhiteBeamDist_mid(dum*kSuperWhiteBeam_Mean)*GaussSpheresX(cw,qq/dum)
172       
173        return (val)
174End
175
176//wrapper to calculate the smeared model as an AAO-Struct
177// fills the struct and calls the ususal function with the STRUCT parameter
178//
179// used only for the dependency, not for fitting
180//
181Function fSmearedGaussSpheresSWB(coefW,yW,xW)
182        Wave coefW,yW,xW
183       
184        String str = getWavesDataFolder(yW,0)
185        String DF="root:"+str+":"
186       
187        WAVE resW = $(DF+str+"_res")
188       
189        STRUCT ResSmearAAOStruct fs
190        WAVE fs.coefW = coefW   
191        WAVE fs.yW = yW
192        WAVE fs.xW = xW
193        WAVE fs.resW = resW
194       
195        Variable err
196        err = SmearedGaussSpheresSWB(fs)
197       
198        return (0)
199End
200
201// this is all there is to the smeared calculation!
202Function SmearedGaussSpheresSWB(s) :FitFunc
203        Struct ResSmearAAOStruct &s
204
205//      the name of your unsmeared model (AAO) is the first argument
206        Smear_Model_20(GaussSpheresSWB,s.coefW,s.xW,s.yW,s.resW)
207
208        return(0)
209End
210
211
Note: See TracBrowser for help on using the repository browser.