1 | #pragma TextEncoding = "MacRoman" |
---|
2 | #pragma rtGlobals=3 // Use modern global access method and strict wave access. |
---|
3 | |
---|
4 | |
---|
5 | ///////////////////////////////////////////////////// |
---|
6 | // |
---|
7 | // Plot's Greg Beaucage's Rg-power Law "model" of scattering |
---|
8 | // somewhat useful for identifying length scales, but short on |
---|
9 | // physical inerpretation of the real structure of the sample. |
---|
10 | // |
---|
11 | // up to 4 "levels" can be calculated |
---|
12 | // best to start with single level, and fit a small range of |
---|
13 | // the data, and add more levels as needed |
---|
14 | // |
---|
15 | // see the help file for the original references |
---|
16 | // |
---|
17 | Proc PlotOnelevelSWB(num,qmin,qmax) |
---|
18 | Variable num=256,qmin=0.001,qmax=0.7 |
---|
19 | Prompt num "Enter number of data points for model: " |
---|
20 | Prompt qmin "Enter minimum q-value (A^-1) for model: " |
---|
21 | Prompt qmax "Enter maximum q-value (A^-1) for model: " |
---|
22 | |
---|
23 | make/o/d/n=(num) xwave_b1SWB,ywave_b1SWB |
---|
24 | xwave_b1SWB = alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) |
---|
25 | make/o/d coef_b1SWB = {1,3,21,6e-4,2,0} |
---|
26 | make/o/t parameters_b1SWB = {"scale","G1 (cm-1 sr-1)","Rg1 (A)","B1 (cm-1 sr-1 A^-Pow)","Pow1","bkg (cm-1 sr-1)"} |
---|
27 | Edit parameters_b1SWB,coef_b1SWB |
---|
28 | |
---|
29 | Variable/G root:g_b1SWB |
---|
30 | g_b1SWB := OneLevelSWB(coef_b1SWB,ywave_b1SWB,xwave_b1SWB) |
---|
31 | Display ywave_b1SWB vs xwave_b1SWB |
---|
32 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
33 | Label bottom "q (A\\S-1\\M)" |
---|
34 | Label left "Intensity (cm\\S-1\\M)" |
---|
35 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
36 | |
---|
37 | AddModelToStrings("OneLevelSWB","coef_b1SWB","parameters_b1SWB","b1SWB") |
---|
38 | End |
---|
39 | |
---|
40 | Proc PlotTwoLevelSWB(num,qmin,qmax) |
---|
41 | Variable num=256,qmin=0.001,qmax=0.7 |
---|
42 | Prompt num "Enter number of data points for model: " |
---|
43 | Prompt qmin "Enter minimum q-value (A^-1) for model: " |
---|
44 | Prompt qmax "Enter maximum q-value (A^-1) for model: " |
---|
45 | |
---|
46 | make/o/d/n=(num) xwave_b2SWB,ywave_b2SWB |
---|
47 | xwave_b2SWB = alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) |
---|
48 | make/o/d coef_b2SWB = {1,400,200,5e-6,4,3,21,6e-4,2,0} |
---|
49 | make/o/t parameters_b2SWB = {"scale","G1 (cm-1 sr-1)","Rg1 (A)","B1 (cm-1 sr-1 A^-Pow)","Pow1","G2 (cm-1 sr-1)","Rg2 (A)","B2 (cm-1 sr-1 A^-Pow)","Pow2","bkg (cm-1 sr-1)"} |
---|
50 | Edit parameters_b2SWB,coef_b2SWB |
---|
51 | |
---|
52 | Variable/G root:g_b2SWB |
---|
53 | g_b2SWB := TwoLevelSWB(coef_b2SWB,ywave_b2SWB,xwave_b2SWB) |
---|
54 | Display ywave_b2SWB vs xwave_b2SWB |
---|
55 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
56 | Label bottom "q (A\\S-1\\M)" |
---|
57 | Label left "Intensity (cm\\S-1\\M)" |
---|
58 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
59 | |
---|
60 | AddModelToStrings("TwoLevelSWB","coef_b2SWB","parameters_b2SWB","b2SWB") |
---|
61 | End |
---|
62 | |
---|
63 | Proc PlotThreeLevelSWB(num,qmin,qmax) |
---|
64 | Variable num=256,qmin=0.001,qmax=0.7 |
---|
65 | Prompt num "Enter number of data points for model: " |
---|
66 | Prompt qmin "Enter minimum q-value (A^-1) for model: " |
---|
67 | Prompt qmax "Enter maximum q-value (A^-1) for model: " |
---|
68 | |
---|
69 | make/o/d/n=(num) xwave_b3SWB,ywave_b3SWB |
---|
70 | xwave_b3SWB = alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) |
---|
71 | make/o/d coef_b3SWB = {1,4000,600,2e-7,4,400,200,5e-6,4,3,21,6e-4,2,0} |
---|
72 | make/o/t parameters_b3SWB = {"scale","G1 (cm-1 sr-1)","Rg1 (A)","B1 (cm-1 sr-1 A^-Pow)","Pow1","G2 (cm-1 sr-1)","Rg2 (A)","B2 (cm-1 sr-1 A^-Pow)","Pow2","G3 (cm-1 sr-1)","Rg3 (A)","B3 (cm-1 sr-1 A^-Pow)","Pow3","bkg (cm-1)"} |
---|
73 | Edit parameters_b3SWB,coef_b3SWB |
---|
74 | |
---|
75 | Variable/G root:g_b3SWB |
---|
76 | g_b3SWB := ThreeLevelSWB(coef_b3SWB,ywave_b3SWB,xwave_b3SWB) |
---|
77 | Display ywave_b3SWB vs xwave_b3SWB |
---|
78 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
79 | Label bottom "q (A\\S-1\\M)" |
---|
80 | Label left "Intensity (cm\\S-1\\M)" |
---|
81 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
82 | |
---|
83 | AddModelToStrings("ThreeLevelSWB","coef_b3SWB","parameters_b3SWB","b3SWB") |
---|
84 | End |
---|
85 | |
---|
86 | Proc PlotFourLevelSWB(num,qmin,qmax) |
---|
87 | Variable num=256,qmin=0.001,qmax=0.7 |
---|
88 | Prompt num "Enter number of data points for model: " |
---|
89 | Prompt qmin "Enter minimum q-value (A^-1) for model: " |
---|
90 | Prompt qmax "Enter maximum q-value (A^-1) for model: " |
---|
91 | |
---|
92 | make/o/d/n=(num) xwave_b4SWB,ywave_b4SWB |
---|
93 | xwave_b4SWB = alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) |
---|
94 | make/o/d coef_b4SWB = {1,40000,2000,1e-8,4,4000,600,2e-7,4,400,200,5e-6,4,3,21,6e-4,2,0} |
---|
95 | make/o/t parameters_b4SWB = {"scale","G1 (cm-1 sr-1)","Rg1 (A)","B1 (cm-1 sr-1 A^-Pow)","Pow1","G2 (cm-1 sr-1)","Rg2 (A)","B2 (cm-1 sr-1 A^-Pow)","Pow2","G3 (cm-1 sr-1)","Rg3 (A)","B3 (cm-1 sr-1 A^-Pow)","Pow3","G4 (cm-1 sr-1)","Rg4 (A)","B4 (cm-1 sr-1 A^-Pow)","Pow4","bkg (cm-1)"} |
---|
96 | Edit parameters_b4SWB,coef_b4SWB |
---|
97 | |
---|
98 | Variable/G root:g_b4SWB |
---|
99 | g_b4SWB := FourLevelSWB(coef_b4SWB,ywave_b4SWB,xwave_b4SWB) |
---|
100 | Display ywave_b4SWB vs xwave_b4SWB |
---|
101 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
102 | Label bottom "q (A\\S-1\\M)" |
---|
103 | Label left "Intensity (cm\\S-1\\M)" |
---|
104 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
105 | |
---|
106 | AddModelToStrings("FourLevelSWB","coef_b4SWB","parameters_b4SWB","b4SWB") |
---|
107 | End |
---|
108 | |
---|
109 | /////////// macros for smeared model calculations |
---|
110 | |
---|
111 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
112 | Proc PlotSmearedOneLevelSWB(str) |
---|
113 | String str |
---|
114 | Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4) |
---|
115 | |
---|
116 | // if any of the resolution waves are missing => abort |
---|
117 | if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
118 | Abort |
---|
119 | endif |
---|
120 | |
---|
121 | SetDataFolder $("root:"+str) |
---|
122 | |
---|
123 | // Setup parameter table for model function |
---|
124 | Make/O/D smear_coef_b1SWB ={1,3,21,6e-4,2,0} |
---|
125 | make/o/t smear_parameters_b1SWB = {"scale","G1 (cm-1 sr-1)","Rg1 (A)","B1 (cm-1 sr-1 A^-Pow)","Pow1","bkg (cm-1 sr-1)"} |
---|
126 | Edit smear_parameters_b1SWB,smear_coef_b1SWB |
---|
127 | |
---|
128 | // output smeared intensity wave, dimensions are identical to experimental QSIG values |
---|
129 | // make extra copy of experimental q-values for easy plotting |
---|
130 | Duplicate/O $(str+"_q") smeared_b1SWB,smeared_qvals |
---|
131 | SetScale d,0,0,"1/cm",smeared_b1SWB |
---|
132 | |
---|
133 | Variable/G gs_b1SWB=0 |
---|
134 | gs_b1SWB := fSmearedOneLevelSWB(smear_coef_b1SWB,smeared_b1SWB,smeared_qvals) //this wrapper fills the STRUCT |
---|
135 | |
---|
136 | Display smeared_b1SWB vs smeared_qvals |
---|
137 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
138 | Label bottom "q (A\\S-1\\M)" |
---|
139 | Label left "Intensity (cm\\S-1\\M)" |
---|
140 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
141 | |
---|
142 | SetDataFolder root: |
---|
143 | AddModelToStrings("SmearedOneLevelSWB","smear_coef_b1SWB","smear_parameters_b1SWB","b1SWB") |
---|
144 | End |
---|
145 | |
---|
146 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
147 | Proc PlotSmearedTwoLevelSWB(str) |
---|
148 | String str |
---|
149 | Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4) |
---|
150 | |
---|
151 | // if any of the resolution waves are missing => abort |
---|
152 | if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
153 | Abort |
---|
154 | endif |
---|
155 | |
---|
156 | SetDataFolder $("root:"+str) |
---|
157 | |
---|
158 | // Setup parameter table for model function |
---|
159 | Make/O/D smear_coef_b2SWB = {1,400,200,5e-6,4,3,21,6e-4,2,0} |
---|
160 | make/o/t smear_parameters_b2SWB = {"scale","G1 (cm-1 sr-1)","Rg1 (A)","B1 (cm-1 sr-1 A^-Pow)","Pow1","G2 (cm-1 sr-1)","Rg2 (A)","B2 (cm-1 sr-1 A^-Pow)","Pow2","bkg (cm-1 sr-1)"} |
---|
161 | Edit smear_parameters_b2SWB,smear_coef_b2SWB |
---|
162 | |
---|
163 | // output smeared intensity wave, dimensions are identical to experimental QSIG values |
---|
164 | // make extra copy of experimental q-values for easy plotting |
---|
165 | Duplicate/O $(str+"_q") smeared_b2SWB,smeared_qvals |
---|
166 | SetScale d,0,0,"1/cm",smeared_b2SWB |
---|
167 | |
---|
168 | Variable/G gs_b2SWB=0 |
---|
169 | gs_b2SWB := fSmearedTwoLevelSWB(smear_coef_b2SWB,smeared_b2SWB,smeared_qvals) //this wrapper fills the STRUCT |
---|
170 | |
---|
171 | Display smeared_b2SWB vs smeared_qvals |
---|
172 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
173 | Label bottom "q (A\\S-1\\M)" |
---|
174 | Label left "Intensity (cm\\S-1\\M)" |
---|
175 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
176 | |
---|
177 | SetDataFolder root: |
---|
178 | AddModelToStrings("SmearedTwoLevelSWB","smear_coef_b2SWB","smear_parameters_b2SWB","b2SWB") |
---|
179 | End |
---|
180 | |
---|
181 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
182 | Proc PlotSmearedThreeLevelSWB(str) |
---|
183 | String str |
---|
184 | Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4) |
---|
185 | |
---|
186 | // if any of the resolution waves are missing => abort |
---|
187 | if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
188 | Abort |
---|
189 | endif |
---|
190 | |
---|
191 | SetDataFolder $("root:"+str) |
---|
192 | |
---|
193 | // Setup parameter table for model function |
---|
194 | Make/O/D smear_coef_b3SWB = {1,4000,600,2e-7,4,400,200,5e-6,4,3,21,6e-4,2,0} |
---|
195 | make/o/t smear_parameters_b3SWB = {"scale","G1 (cm-1 sr-1)","Rg1 (A)","B1 (cm-1 sr-1 A^-Pow)","Pow1","G2 (cm-1 sr-1)","Rg2 (A)","B2 (cm-1 sr-1 A^-Pow)","Pow2","G3 (cm-1 sr-1)","Rg3 (A)","B3 (cm-1 sr-1 A^-Pow)","Pow3","bkg (cm-1)"} |
---|
196 | Edit smear_parameters_b3SWB,smear_coef_b3SWB |
---|
197 | |
---|
198 | // output smeared intensity wave, dimensions are identical to experimental QSIG values |
---|
199 | // make extra copy of experimental q-values for easy plotting |
---|
200 | Duplicate/O $(str+"_q") smeared_b3SWB,smeared_qvals |
---|
201 | SetScale d,0,0,"1/cm",smeared_b3SWB |
---|
202 | |
---|
203 | Variable/G gs_b3SWB=0 |
---|
204 | gs_b3SWB := fSmearedThreeLevelSWB(smear_coef_b3SWB,smeared_b3SWB,smeared_qvals) //this wrapper fills the STRUCT |
---|
205 | |
---|
206 | Display smeared_b3SWB vs smeared_qvals |
---|
207 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
208 | Label bottom "q (A\\S-1\\M)" |
---|
209 | Label left "Intensity (cm\\S-1\\M)" |
---|
210 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
211 | |
---|
212 | SetDataFolder root: |
---|
213 | AddModelToStrings("SmearedThreeLevelSWB","smear_coef_b3SWB","smear_parameters_b3SWB","b3SWB") |
---|
214 | End |
---|
215 | |
---|
216 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
217 | Proc PlotSmearedFourLevelSWB(str) |
---|
218 | String str |
---|
219 | Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4) |
---|
220 | |
---|
221 | // if any of the resolution waves are missing => abort |
---|
222 | if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
223 | Abort |
---|
224 | endif |
---|
225 | |
---|
226 | SetDataFolder $("root:"+str) |
---|
227 | |
---|
228 | // Setup parameter table for model function |
---|
229 | Make/O/D smear_coef_b4SWB = {1,40000,2000,1e-8,4,4000,600,2e-7,4,400,200,5e-6,4,3,21,6e-4,2,0} |
---|
230 | Make/o/t smear_parameters_b4SWB = {"scale","G1 (cm-1 sr-1)","Rg1 (A)","B1 (cm-1 sr-1 A^-Pow)","Pow1","G2 (cm-1 sr-1)","Rg2 (A)","B2 (cm-1 sr-1 A^-Pow)","Pow2","G3 (cm-1 sr-1)","Rg3 (A)","B3 (cm-1 sr-1 A^-Pow)","Pow3","G4 (cm-1 sr-1)","Rg4 (A)","B4 (cm-1 sr-1 A^-Pow)","Pow4","bkg (cm-1)"} |
---|
231 | Edit smear_parameters_b4SWB,smear_coef_b4SWB |
---|
232 | |
---|
233 | // output smeared intensity wave, dimensions are identical to experimental QSIG values |
---|
234 | // make extra copy of experimental q-values for easy plotting |
---|
235 | Duplicate/O $(str+"_q") smeared_b4SWB,smeared_qvals |
---|
236 | SetScale d,0,0,"1/cm",smeared_b4SWB |
---|
237 | |
---|
238 | Variable/G gs_b4SWB=0 |
---|
239 | gs_b4SWB := fSmearedFourLevelSWB(smear_coef_b4SWB,smeared_b4SWB,smeared_qvals) //this wrapper fills the STRUCT |
---|
240 | |
---|
241 | Display smeared_b4SWB vs smeared_qvals |
---|
242 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
243 | Label bottom "q (A\\S-1\\M)" |
---|
244 | Label left "Intensity (cm\\S-1\\M)" |
---|
245 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
246 | |
---|
247 | SetDataFolder root: |
---|
248 | AddModelToStrings("SmearedFourLevelSWB","smear_coef_b4SWB","smear_parameters_b4SWB","b4SWB") |
---|
249 | End |
---|
250 | |
---|
251 | |
---|
252 | |
---|
253 | |
---|
254 | //AAO version, uses XOP if available |
---|
255 | // simply calls the original single point calculation with |
---|
256 | // a wave assignment (this will behave nicely if given point ranges) |
---|
257 | Function OneLevelSWB(cw,yw,xw) : FitFunc |
---|
258 | Wave cw,yw,xw |
---|
259 | |
---|
260 | #if exists("OneLevelX") |
---|
261 | // yw = OneLevelX(cw,xw) |
---|
262 | yw = V_fOneLevelSWB(cw,xw) |
---|
263 | #else |
---|
264 | // yw = fOneLevel(cw,xw) |
---|
265 | yw = 1 |
---|
266 | #endif |
---|
267 | return(0) |
---|
268 | End |
---|
269 | |
---|
270 | //////////Function definitions |
---|
271 | |
---|
272 | Function V_fOneLevelSWB(w,x) :FitFunc |
---|
273 | Wave w |
---|
274 | Variable x |
---|
275 | |
---|
276 | Variable inten,lolim,uplim |
---|
277 | |
---|
278 | // define limits based on lo/mean, hi/mean of the wavelength distribution |
---|
279 | // using the empirical definition, "middle" of the peaks |
---|
280 | loLim = 3.37/5.3 |
---|
281 | upLim = 20/5.3 |
---|
282 | |
---|
283 | inten = V_IntegrOneLevelSWB_mid(w,loLim,upLim,x) |
---|
284 | |
---|
285 | // why do I need this? Is this because this is defined as the mean of the distribution |
---|
286 | // and is needed to normalize the integral? verify this on paper. |
---|
287 | inten *= 5.3 |
---|
288 | |
---|
289 | // normalize the integral |
---|
290 | inten /= 30955 // "middle" of peaks |
---|
291 | |
---|
292 | // additional normalization??? |
---|
293 | inten /= 1.05 // |
---|
294 | Return (inten) |
---|
295 | |
---|
296 | End |
---|
297 | |
---|
298 | // the trick here is that declaring the last qVal wave as a variable |
---|
299 | // since this is implicitly called N times in the wave assignment of the answer wave |
---|
300 | Function V_IntegrOneLevelSWB_mid(cw,loLim,upLim,qVal) |
---|
301 | Wave cw |
---|
302 | Variable loLim,upLim |
---|
303 | Variable qVal |
---|
304 | |
---|
305 | Variable/G root:qq = qval |
---|
306 | Variable ans |
---|
307 | |
---|
308 | // ans = Integrate1D(V_intgrnd_top,lolim,uplim,2,0,cw) //adaptive quadrature |
---|
309 | ans = Integrate1D(V_integrand_OneLevelSWB,lolim,uplim,1,0,cw) // Romberg integration |
---|
310 | |
---|
311 | return ans |
---|
312 | end |
---|
313 | |
---|
314 | Function V_integrand_OneLevelSWB(cw,dum) |
---|
315 | Wave cw |
---|
316 | Variable dum // the dummy of the integration |
---|
317 | |
---|
318 | Variable val |
---|
319 | NVAR qq = root:qq //the q-value of the integration, not part of cw, so pass global |
---|
320 | // SVAR funcStr = root:gFunctionString |
---|
321 | // FUNCREF SANSModel_proto func = $funcStr |
---|
322 | |
---|
323 | val = V_SuperWhiteBeamDist_mid(dum*5.3)*OneLevelX(cw,qq/dum) |
---|
324 | |
---|
325 | return (val) |
---|
326 | End |
---|
327 | |
---|
328 | //AAO version, uses XOP if available |
---|
329 | // simply calls the original single point calculation with |
---|
330 | // a wave assignment (this will behave nicely if given point ranges) |
---|
331 | Function TwoLevelSWB(cw,yw,xw) : FitFunc |
---|
332 | Wave cw,yw,xw |
---|
333 | |
---|
334 | #if exists("TwoLevelX") |
---|
335 | // yw = TwoLevelX(cw,xw) |
---|
336 | yw = V_fTwoLevelSWB(cw,xw) |
---|
337 | #else |
---|
338 | // yw = fTwoLevel(cw,xw) |
---|
339 | yw = 1 |
---|
340 | #endif |
---|
341 | return(0) |
---|
342 | End |
---|
343 | |
---|
344 | Function V_fTwoLevelSWB(w,x) :FitFunc |
---|
345 | Wave w |
---|
346 | Variable x |
---|
347 | |
---|
348 | Variable inten,lolim,uplim |
---|
349 | |
---|
350 | // define limits based on lo/mean, hi/mean of the wavelength distribution |
---|
351 | // using the empirical definition, "middle" of the peaks |
---|
352 | loLim = 3.37/5.3 |
---|
353 | upLim = 20/5.3 |
---|
354 | |
---|
355 | inten = V_IntegrTwoLevelSWB_mid(w,loLim,upLim,x) |
---|
356 | |
---|
357 | // why do I need this? Is this because this is defined as the mean of the distribution |
---|
358 | // and is needed to normalize the integral? verify this on paper. |
---|
359 | inten *= 5.3 |
---|
360 | |
---|
361 | // normalize the integral |
---|
362 | inten /= 30955 // "middle" of peaks |
---|
363 | |
---|
364 | // additional normalization??? |
---|
365 | inten /= 1.05 // |
---|
366 | Return (inten) |
---|
367 | |
---|
368 | End |
---|
369 | |
---|
370 | // the trick here is that declaring the last qVal wave as a variable |
---|
371 | // since this is implicitly called N times in the wave assignment of the answer wave |
---|
372 | Function V_IntegrTwoLevelSWB_mid(cw,loLim,upLim,qVal) |
---|
373 | Wave cw |
---|
374 | Variable loLim,upLim |
---|
375 | Variable qVal |
---|
376 | |
---|
377 | Variable/G root:qq = qval |
---|
378 | Variable ans |
---|
379 | |
---|
380 | // ans = Integrate1D(V_intgrnd_top,lolim,uplim,2,0,cw) //adaptive quadrature |
---|
381 | ans = Integrate1D(V_integrand_TwoLevelSWB,lolim,uplim,1,0,cw) // Romberg integration |
---|
382 | |
---|
383 | return ans |
---|
384 | end |
---|
385 | |
---|
386 | Function V_integrand_TwoLevelSWB(cw,dum) |
---|
387 | Wave cw |
---|
388 | Variable dum // the dummy of the integration |
---|
389 | |
---|
390 | Variable val |
---|
391 | NVAR qq = root:qq //the q-value of the integration, not part of cw, so pass global |
---|
392 | // SVAR funcStr = root:gFunctionString |
---|
393 | // FUNCREF SANSModel_proto func = $funcStr |
---|
394 | |
---|
395 | val = V_SuperWhiteBeamDist_mid(dum*5.3)*TwoLevelX(cw,qq/dum) |
---|
396 | |
---|
397 | return (val) |
---|
398 | End |
---|
399 | |
---|
400 | //AAO version, uses XOP if available |
---|
401 | // simply calls the original single point calculation with |
---|
402 | // a wave assignment (this will behave nicely if given point ranges) |
---|
403 | Function ThreeLevelSWB(cw,yw,xw) : FitFunc |
---|
404 | Wave cw,yw,xw |
---|
405 | |
---|
406 | #if exists("ThreeLevelX") |
---|
407 | // yw = ThreeLevelX(cw,xw) |
---|
408 | yw = V_fThreeLevelSWB(cw,xw) |
---|
409 | #else |
---|
410 | // yw = fThreeLevel(cw,xw) |
---|
411 | yw = 1 |
---|
412 | #endif |
---|
413 | return(0) |
---|
414 | End |
---|
415 | |
---|
416 | Function V_fThreeLevelSWB(w,x) :FitFunc |
---|
417 | Wave w |
---|
418 | Variable x |
---|
419 | |
---|
420 | Variable inten,lolim,uplim |
---|
421 | |
---|
422 | // define limits based on lo/mean, hi/mean of the wavelength distribution |
---|
423 | // using the empirical definition, "middle" of the peaks |
---|
424 | loLim = 3.37/5.3 |
---|
425 | upLim = 20/5.3 |
---|
426 | |
---|
427 | inten = V_IntegrThreeLevelSWB_mid(w,loLim,upLim,x) |
---|
428 | |
---|
429 | // why do I need this? Is this because this is defined as the mean of the distribution |
---|
430 | // and is needed to normalize the integral? verify this on paper. |
---|
431 | inten *= 5.3 |
---|
432 | |
---|
433 | // normalize the integral |
---|
434 | inten /= 30955 // "middle" of peaks |
---|
435 | |
---|
436 | // additional normalization??? |
---|
437 | inten /= 1.05 // |
---|
438 | Return (inten) |
---|
439 | |
---|
440 | End |
---|
441 | |
---|
442 | // the trick here is that declaring the last qVal wave as a variable |
---|
443 | // since this is implicitly called N times in the wave assignment of the answer wave |
---|
444 | Function V_IntegrThreeLevelSWB_mid(cw,loLim,upLim,qVal) |
---|
445 | Wave cw |
---|
446 | Variable loLim,upLim |
---|
447 | Variable qVal |
---|
448 | |
---|
449 | Variable/G root:qq = qval |
---|
450 | Variable ans |
---|
451 | |
---|
452 | // ans = Integrate1D(V_intgrnd_top,lolim,uplim,2,0,cw) //adaptive quadrature |
---|
453 | ans = Integrate1D(V_integrand_ThreeLevelSWB,lolim,uplim,1,0,cw) // Romberg integration |
---|
454 | |
---|
455 | return ans |
---|
456 | end |
---|
457 | |
---|
458 | Function V_integrand_ThreeLevelSWB(cw,dum) |
---|
459 | Wave cw |
---|
460 | Variable dum // the dummy of the integration |
---|
461 | |
---|
462 | Variable val |
---|
463 | NVAR qq = root:qq //the q-value of the integration, not part of cw, so pass global |
---|
464 | // SVAR funcStr = root:gFunctionString |
---|
465 | // FUNCREF SANSModel_proto func = $funcStr |
---|
466 | |
---|
467 | val = V_SuperWhiteBeamDist_mid(dum*5.3)*ThreeLevelX(cw,qq/dum) |
---|
468 | |
---|
469 | return (val) |
---|
470 | End |
---|
471 | |
---|
472 | |
---|
473 | //AAO version, uses XOP if available |
---|
474 | // simply calls the original single point calculation with |
---|
475 | // a wave assignment (this will behave nicely if given point ranges) |
---|
476 | Function FourLevelSWB(cw,yw,xw) : FitFunc |
---|
477 | Wave cw,yw,xw |
---|
478 | |
---|
479 | #if exists("FourLevelX") |
---|
480 | // yw = FourLevelX(cw,xw) |
---|
481 | yw = V_fFourLevelSWB(cw,xw) |
---|
482 | #else |
---|
483 | // yw = fFourLevel(cw,xw) |
---|
484 | yw = 1 |
---|
485 | #endif |
---|
486 | return(0) |
---|
487 | End |
---|
488 | |
---|
489 | |
---|
490 | Function V_fFourLevelSWB(w,x) :FitFunc |
---|
491 | Wave w |
---|
492 | Variable x |
---|
493 | |
---|
494 | Variable inten,lolim,uplim |
---|
495 | |
---|
496 | // define limits based on lo/mean, hi/mean of the wavelength distribution |
---|
497 | // using the empirical definition, "middle" of the peaks |
---|
498 | loLim = 3.37/5.3 |
---|
499 | upLim = 20/5.3 |
---|
500 | |
---|
501 | inten = V_IntegrFourLevelSWB_mid(w,loLim,upLim,x) |
---|
502 | |
---|
503 | // why do I need this? Is this because this is defined as the mean of the distribution |
---|
504 | // and is needed to normalize the integral? verify this on paper. |
---|
505 | inten *= 5.3 |
---|
506 | |
---|
507 | // normalize the integral |
---|
508 | inten /= 30955 // "middle" of peaks |
---|
509 | |
---|
510 | // additional normalization??? |
---|
511 | inten /= 1.05 // |
---|
512 | Return (inten) |
---|
513 | |
---|
514 | End |
---|
515 | |
---|
516 | // the trick here is that declaring the last qVal wave as a variable |
---|
517 | // since this is implicitly called N times in the wave assignment of the answer wave |
---|
518 | Function V_IntegrFourLevelSWB_mid(cw,loLim,upLim,qVal) |
---|
519 | Wave cw |
---|
520 | Variable loLim,upLim |
---|
521 | Variable qVal |
---|
522 | |
---|
523 | Variable/G root:qq = qval |
---|
524 | Variable ans |
---|
525 | |
---|
526 | // ans = Integrate1D(V_intgrnd_top,lolim,uplim,2,0,cw) //adaptive quadrature |
---|
527 | ans = Integrate1D(V_integrand_FourLevelSWB,lolim,uplim,1,0,cw) // Romberg integration |
---|
528 | |
---|
529 | return ans |
---|
530 | end |
---|
531 | |
---|
532 | Function V_integrand_FourLevelSWB(cw,dum) |
---|
533 | Wave cw |
---|
534 | Variable dum // the dummy of the integration |
---|
535 | |
---|
536 | Variable val |
---|
537 | NVAR qq = root:qq //the q-value of the integration, not part of cw, so pass global |
---|
538 | // SVAR funcStr = root:gFunctionString |
---|
539 | // FUNCREF SANSModel_proto func = $funcStr |
---|
540 | |
---|
541 | val = V_SuperWhiteBeamDist_mid(dum*5.3)*FourLevelX(cw,qq/dum) |
---|
542 | |
---|
543 | return (val) |
---|
544 | End |
---|
545 | |
---|
546 | |
---|
547 | |
---|
548 | Function SmearedOneLevelSWB(s) :FitFunc |
---|
549 | Struct ResSmearAAOStruct &s |
---|
550 | |
---|
551 | // the name of your unsmeared model (AAO) is the first argument |
---|
552 | Smear_Model_20(OneLevelSWB,s.coefW,s.xW,s.yW,s.resW) |
---|
553 | |
---|
554 | return(0) |
---|
555 | End |
---|
556 | |
---|
557 | |
---|
558 | Function SmearedTwoLevelSWB(s) :FitFunc |
---|
559 | Struct ResSmearAAOStruct &s |
---|
560 | |
---|
561 | // the name of your unsmeared model (AAO) is the first argument |
---|
562 | Smear_Model_20(TwoLevelSWB,s.coefW,s.xW,s.yW,s.resW) |
---|
563 | |
---|
564 | return(0) |
---|
565 | End |
---|
566 | |
---|
567 | |
---|
568 | Function SmearedThreeLevelSWB(s) :FitFunc |
---|
569 | Struct ResSmearAAOStruct &s |
---|
570 | |
---|
571 | // the name of your unsmeared model (AAO) is the first argument |
---|
572 | Smear_Model_20(ThreeLevelSWB,s.coefW,s.xW,s.yW,s.resW) |
---|
573 | |
---|
574 | return(0) |
---|
575 | End |
---|
576 | |
---|
577 | Function SmearedFourLevelSWB(s) :FitFunc |
---|
578 | Struct ResSmearAAOStruct &s |
---|
579 | |
---|
580 | // the name of your unsmeared model (AAO) is the first argument |
---|
581 | Smear_Model_20(FourLevelSWB,s.coefW,s.xW,s.yW,s.resW) |
---|
582 | |
---|
583 | return(0) |
---|
584 | End |
---|
585 | |
---|
586 | //wrapper to calculate the smeared model as an AAO-Struct |
---|
587 | // fills the struct and calls the ususal function with the STRUCT parameter |
---|
588 | // |
---|
589 | // used only for the dependency, not for fitting |
---|
590 | // |
---|
591 | Function fSmearedOneLevelSWB(coefW,yW,xW) |
---|
592 | Wave coefW,yW,xW |
---|
593 | |
---|
594 | String str = getWavesDataFolder(yW,0) |
---|
595 | String DF="root:"+str+":" |
---|
596 | |
---|
597 | WAVE resW = $(DF+str+"_res") |
---|
598 | |
---|
599 | STRUCT ResSmearAAOStruct fs |
---|
600 | WAVE fs.coefW = coefW |
---|
601 | WAVE fs.yW = yW |
---|
602 | WAVE fs.xW = xW |
---|
603 | WAVE fs.resW = resW |
---|
604 | |
---|
605 | Variable err |
---|
606 | err = SmearedOneLevelSWB(fs) |
---|
607 | |
---|
608 | return (0) |
---|
609 | End |
---|
610 | |
---|
611 | //wrapper to calculate the smeared model as an AAO-Struct |
---|
612 | // fills the struct and calls the ususal function with the STRUCT parameter |
---|
613 | // |
---|
614 | // used only for the dependency, not for fitting |
---|
615 | // |
---|
616 | Function fSmearedTwoLevelSWB(coefW,yW,xW) |
---|
617 | Wave coefW,yW,xW |
---|
618 | |
---|
619 | String str = getWavesDataFolder(yW,0) |
---|
620 | String DF="root:"+str+":" |
---|
621 | |
---|
622 | WAVE resW = $(DF+str+"_res") |
---|
623 | |
---|
624 | STRUCT ResSmearAAOStruct fs |
---|
625 | WAVE fs.coefW = coefW |
---|
626 | WAVE fs.yW = yW |
---|
627 | WAVE fs.xW = xW |
---|
628 | WAVE fs.resW = resW |
---|
629 | |
---|
630 | Variable err |
---|
631 | err = SmearedTwoLevelSWB(fs) |
---|
632 | |
---|
633 | return (0) |
---|
634 | End |
---|
635 | |
---|
636 | //wrapper to calculate the smeared model as an AAO-Struct |
---|
637 | // fills the struct and calls the ususal function with the STRUCT parameter |
---|
638 | // |
---|
639 | // used only for the dependency, not for fitting |
---|
640 | // |
---|
641 | Function fSmearedThreeLevelSWB(coefW,yW,xW) |
---|
642 | Wave coefW,yW,xW |
---|
643 | |
---|
644 | String str = getWavesDataFolder(yW,0) |
---|
645 | String DF="root:"+str+":" |
---|
646 | |
---|
647 | WAVE resW = $(DF+str+"_res") |
---|
648 | |
---|
649 | STRUCT ResSmearAAOStruct fs |
---|
650 | WAVE fs.coefW = coefW |
---|
651 | WAVE fs.yW = yW |
---|
652 | WAVE fs.xW = xW |
---|
653 | WAVE fs.resW = resW |
---|
654 | |
---|
655 | Variable err |
---|
656 | err = SmearedThreeLevelSWB(fs) |
---|
657 | |
---|
658 | return (0) |
---|
659 | End |
---|
660 | |
---|
661 | //wrapper to calculate the smeared model as an AAO-Struct |
---|
662 | // fills the struct and calls the ususal function with the STRUCT parameter |
---|
663 | // |
---|
664 | // used only for the dependency, not for fitting |
---|
665 | // |
---|
666 | Function fSmearedFourLevelSWB(coefW,yW,xW) |
---|
667 | Wave coefW,yW,xW |
---|
668 | |
---|
669 | String str = getWavesDataFolder(yW,0) |
---|
670 | String DF="root:"+str+":" |
---|
671 | |
---|
672 | WAVE resW = $(DF+str+"_res") |
---|
673 | |
---|
674 | STRUCT ResSmearAAOStruct fs |
---|
675 | WAVE fs.coefW = coefW |
---|
676 | WAVE fs.yW = yW |
---|
677 | WAVE fs.xW = xW |
---|
678 | WAVE fs.resW = resW |
---|
679 | |
---|
680 | Variable err |
---|
681 | err = SmearedFourLevelSWB(fs) |
---|
682 | |
---|
683 | return (0) |
---|
684 | End |
---|
685 | |
---|