source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/VSANS/V_SWB_BroadPeak.ipf @ 1203

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

Corrected attenuator table for VSANS to include the range 4.52->19. Patching of the attenuation factor is disabled since the factor is always calculated rather than read from the file.

Added a few help links in preparation for the full help file integration

Added a "super" white beam distribution definition and a single model function for testing of this new mode. Still need the normalization and mean wavelength for the distribution + a way to identify it in the file metadata.

File size: 6.6 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5////////////////////////////////////////////////////
6//
7// an empirical model containing power law scattering + a broad peak
8//
9// B. Hammouda OCT 2008
10//
11//
12// updated for use with latest macros SRK Nov 2008
13//
14// Updated 2019 to Super White Beam Smearing
15//
16// TODO -- be sure that I'm using the correct normalization and
17//   the correct mean wavelength (used for limits + normalization)
18//
19//
20////////////////////////////////////////////////////
21
22//
23Proc PlotBroadPeakSWB(num,qmin,qmax)
24        Variable num=200, qmin=0.001, qmax=0.7
25        Prompt num "Enter number of data points for model: "
26        Prompt qmin "Enter minimum q-value (^-1) for model: "
27        Prompt qmax "Enter maximum q-value (^-1) for model: "
28//
29        Make/O/D/n=(num) xwave_BroadPeakSWB, ywave_BroadPeakSWB
30        xwave_BroadPeakSWB =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
31        Make/O/D coef_BroadPeakSWB = {1e-5, 3, 10, 50.0, 0.1,2,0.1}             
32        make/o/t parameters_BroadPeakSWB = {"Porod Scale", "Porod Exponent","Lorentzian Scale","Lor Screening Length [A]","Qzero [1/A]","Lorentzian Exponent","Bgd [1/cm]"}     //CH#2
33        Edit parameters_BroadPeakSWB, coef_BroadPeakSWB
34       
35        Variable/G root:g_BroadPeakSWB
36        g_BroadPeakSWB := BroadPeakSWB(coef_BroadPeakSWB, ywave_BroadPeakSWB, xwave_BroadPeakSWB)
37        Display ywave_BroadPeakSWB vs xwave_BroadPeakSWB
38        ModifyGraph marker=29, msize=2, mode=4
39        ModifyGraph log=1,grid=1,mirror=2
40        Label bottom "q (\\S-1\\M) "
41        Label left "I(q) (cm\\S-1\\M)"
42        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
43       
44        AddModelToStrings("BroadPeakSWB","coef_BroadPeakSWB","parameters_BroadPeakSWB","BroadPeakSWB")
45//
46End
47
48
49//
50//no input parameters are necessary, it MUST use the experimental q-values
51// from the experimental data read in from an AVE/QSIG data file
52////////////////////////////////////////////////////
53// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
54Proc PlotSmearedBroadPeakSWB(str)                                                               
55        String str
56        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
57       
58        // if any of the resolution waves are missing => abort
59        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
60                Abort
61        endif
62       
63        SetDataFolder $("root:"+str)
64       
65        // Setup parameter table for model function
66        Make/O/D smear_coef_BroadPeakSWB = {1e-5, 3, 10, 50.0, 0.1,2,0.1}               
67        make/o/t smear_parameters_BroadPeakSWB = {"Porod Scale", "Porod Exponent","Lorentzian Scale","Lor Screening Length [A]","Qzero [1/A]","Lorentzian Exponent","Bgd [1/cm]"}
68        Edit smear_parameters_BroadPeakSWB,smear_coef_BroadPeakSWB                                      //display parameters in a table
69       
70        // output smeared intensity wave, dimensions are identical to experimental QSIG values
71        // make extra copy of experimental q-values for easy plotting
72        Duplicate/O $(str+"_q") smeared_BroadPeakSWB,smeared_qvals
73        SetScale d,0,0,"1/cm",smeared_BroadPeakSWB
74                                       
75        Variable/G gs_BroadPeakSWB=0
76        gs_BroadPeakSWB := fSmearedBroadPeakSWB(smear_coef_BroadPeakSWB,smeared_BroadPeakSWB,smeared_qvals)     //this wrapper fills the STRUCT
77       
78        Display smeared_BroadPeakSWB vs smeared_qvals
79        ModifyGraph log=1,marker=29,msize=2,mode=4
80        Label bottom "q (\\S-1\\M)"
81        Label left "I(q) (cm\\S-1\\M)"
82        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
83       
84        SetDataFolder root:
85        AddModelToStrings("SmearedBroadPeakSWB","smear_coef_BroadPeakSWB","smear_parameters_BroadPeakSWB","BroadPeakSWB")
86End
87
88
89//
90//AAO version, uses XOP if available
91// simply calls the original single point calculation with
92// a wave assignment (this will behave nicely if given point ranges)
93Function BroadPeakSWB(cw,yw,xw) : FitFunc
94        Wave cw,yw,xw
95       
96#if exists("BroadPeakX")
97//      yw = BroadPeakX(cw,xw)
98        yw = V_fBroadPeakSWB(cw,xw)
99#else
100//      yw = fBroadPeakSWB(cw,xw)
101        yw = 1
102#endif
103        return(0)
104End
105
106//
107// unsmeared model calculation
108//
109Function V_fBroadPeakSWB(w,x) : FitFunc
110        Wave w
111        Variable x
112       
113        // variables are:                                                       
114        //[0] Porod term scaling
115        //[1] Porod exponent
116        //[2] Lorentzian term scaling
117        //[3] Lorentzian screening length [A]
118        //[4] peak location [1/A]
119        //[5] Lorentzian exponent
120        //[6] background
121       
122        Variable aa,nn,cc,LL,Qzero,mm,bgd,inten,lolim,uplim
123
124        // define limits based on lo/mean, hi/mean of the wavelength distribution
125        // using the empirical definition, "middle" of the peaks
126        loLim = 3.37/5.3
127        upLim = 20/5.3
128       
129        inten = V_IntegrBroadPeakSWB_mid(w,loLim,upLim,x)
130
131// why do I need this? Is this because this is defined as the mean of the distribution
132//  and is needed to normalize the integral? verify this on paper.     
133        inten *= 5.3
134
135// normalize the integral       
136        inten /= 30955          // "middle"  of peaks
137
138// additional normalization???
139        inten /= 1.05           //
140        Return (inten)
141       
142End
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_IntegrBroadPeakSWB_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_BroadPeakSWB,lolim,uplim,1,0,cw)          // Romberg integration
156       
157        return ans
158end
159
160Function V_integrand_BroadPeakSWB(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
169        val = V_SuperWhiteBeamDist_mid(dum*5.3)*BroadPeakX(cw,qq/dum)
170       
171        return (val)
172End
173
174//CH#4 
175///////////////////////////////////////////////////////////////
176// smeared model calculation
177//
178// you don't need to do anything with this function, as long as
179// your BroadPeak works correctly, you get the resolution-smeared
180// version for free.
181//
182// this is all there is to the smeared model calculation!
183Function SmearedBroadPeakSWB(s) : FitFunc
184        Struct ResSmearAAOStruct &s
185
186//      the name of your unsmeared model (AAO) is the first argument
187        Smear_Model_76(BroadPeakSWB,s.coefW,s.xW,s.yW,s.resW)
188
189        return(0)
190End
191
192
193///////////////////////////////////////////////////////////////
194
195
196// nothing to change here
197//
198//wrapper to calculate the smeared model as an AAO-Struct
199// fills the struct and calls the ususal function with the STRUCT parameter
200//
201// used only for the dependency, not for fitting
202//
203Function fSmearedBroadPeakSWB(coefW,yW,xW)
204        Wave coefW,yW,xW
205       
206        String str = getWavesDataFolder(yW,0)
207        String DF="root:"+str+":"
208       
209        WAVE resW = $(DF+str+"_res")
210       
211        STRUCT ResSmearAAOStruct fs
212        WAVE fs.coefW = coefW   
213        WAVE fs.yW = yW
214        WAVE fs.xW = xW
215        WAVE fs.resW = resW
216       
217        Variable err
218        err = SmearedBroadPeakSWB(fs)
219       
220        return (0)
221End
Note: See TracBrowser for help on using the repository browser.