1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion=6.0 |
---|
3 | |
---|
4 | //////////////////////////////////////////////////// |
---|
5 | // |
---|
6 | // an empirical model containing power law scattering + a broad peak |
---|
7 | // |
---|
8 | // B. Hammouda OCT 2008 |
---|
9 | // |
---|
10 | // |
---|
11 | // updated for use with latest macros SRK Nov 2008 |
---|
12 | // |
---|
13 | //////////////////////////////////////////////////// |
---|
14 | |
---|
15 | // |
---|
16 | Proc PlotBroadPeak(num,qmin,qmax) |
---|
17 | Variable num=200, qmin=0.001, qmax=0.7 |
---|
18 | Prompt num "Enter number of data points for model: " |
---|
19 | Prompt qmin "Enter minimum q-value (^-1) for model: " |
---|
20 | Prompt qmax "Enter maximum q-value (^-1) for model: " |
---|
21 | // |
---|
22 | Make/O/D/n=(num) xwave_BroadPeak, ywave_BroadPeak |
---|
23 | xwave_BroadPeak = alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) |
---|
24 | Make/O/D coef_BroadPeak = {1e-5, 3, 10, 50.0, 0.1,2,0.1} |
---|
25 | make/o/t parameters_BroadPeak = {"Porod Scale", "Porod Exponent","Lorentzian Scale","Lor Screening Length [A]","Qzero [1/A]","Lorentzian Exponent","Bgd [1/cm]"} //CH#2 |
---|
26 | Edit parameters_BroadPeak, coef_BroadPeak |
---|
27 | |
---|
28 | Variable/G root:g_BroadPeak |
---|
29 | g_BroadPeak := BroadPeak(coef_BroadPeak, ywave_BroadPeak, xwave_BroadPeak) |
---|
30 | Display ywave_BroadPeak vs xwave_BroadPeak |
---|
31 | ModifyGraph marker=29, msize=2, mode=4 |
---|
32 | ModifyGraph log=1,grid=1,mirror=2 |
---|
33 | Label bottom "q (\\S-1\\M) " |
---|
34 | Label left "I(q) (cm\\S-1\\M)" |
---|
35 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
36 | |
---|
37 | AddModelToStrings("BroadPeak","coef_BroadPeak","BroadPeak") |
---|
38 | // |
---|
39 | End |
---|
40 | |
---|
41 | |
---|
42 | // |
---|
43 | //no input parameters are necessary, it MUST use the experimental q-values |
---|
44 | // from the experimental data read in from an AVE/QSIG data file |
---|
45 | //////////////////////////////////////////////////// |
---|
46 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
47 | Proc PlotSmearedBroadPeak(str) |
---|
48 | String str |
---|
49 | Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4) |
---|
50 | |
---|
51 | // if any of the resolution waves are missing => abort |
---|
52 | if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
53 | Abort |
---|
54 | endif |
---|
55 | |
---|
56 | SetDataFolder $("root:"+str) |
---|
57 | |
---|
58 | // Setup parameter table for model function |
---|
59 | Make/O/D smear_coef_BroadPeak = {1e-5, 3, 10, 50.0, 0.1,2,0.1} |
---|
60 | make/o/t smear_parameters_BroadPeak = {"Porod Scale", "Porod Exponent","Lorentzian Scale","Lor Screening Length [A]","Qzero [1/A]","Lorentzian Exponent","Bgd [1/cm]"} |
---|
61 | Edit smear_parameters_BroadPeak,smear_coef_BroadPeak //display parameters in a table |
---|
62 | |
---|
63 | // output smeared intensity wave, dimensions are identical to experimental QSIG values |
---|
64 | // make extra copy of experimental q-values for easy plotting |
---|
65 | Duplicate/O $(str+"_q") smeared_BroadPeak,smeared_qvals |
---|
66 | SetScale d,0,0,"1/cm",smeared_BroadPeak |
---|
67 | |
---|
68 | Variable/G gs_BroadPeak=0 |
---|
69 | gs_BroadPeak := fSmearedBroadPeak(smear_coef_BroadPeak,smeared_BroadPeak,smeared_qvals) //this wrapper fills the STRUCT |
---|
70 | |
---|
71 | Display smeared_BroadPeak vs smeared_qvals |
---|
72 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
73 | Label bottom "q (\\S-1\\M)" |
---|
74 | Label left "I(q) (cm\\S-1\\M)" |
---|
75 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
76 | |
---|
77 | SetDataFolder root: |
---|
78 | AddModelToStrings("SmearedBroadPeak","smear_coef_BroadPeak","BroadPeak") |
---|
79 | End |
---|
80 | |
---|
81 | |
---|
82 | // |
---|
83 | //AAO version, uses XOP if available |
---|
84 | // simply calls the original single point calculation with |
---|
85 | // a wave assignment (this will behave nicely if given point ranges) |
---|
86 | Function BroadPeak(cw,yw,xw) : FitFunc |
---|
87 | Wave cw,yw,xw |
---|
88 | |
---|
89 | #if exists("BroadPeakX") |
---|
90 | yw = BroadPeakX(cw,xw) |
---|
91 | #else |
---|
92 | yw = fBroadPeak(cw,xw) |
---|
93 | #endif |
---|
94 | return(0) |
---|
95 | End |
---|
96 | |
---|
97 | // |
---|
98 | // unsmeared model calculation |
---|
99 | // |
---|
100 | Function fBroadPeak(w,x) : FitFunc |
---|
101 | Wave w |
---|
102 | Variable x |
---|
103 | |
---|
104 | // variables are: |
---|
105 | //[0] Porod term scaling |
---|
106 | //[1] Porod exponent |
---|
107 | //[2] Lorentzian term scaling |
---|
108 | //[3] Lorentzian screening length [A] |
---|
109 | //[4] peak location [1/A] |
---|
110 | //[5] Lorentzian exponent |
---|
111 | //[6] background |
---|
112 | |
---|
113 | Variable aa,nn,cc,LL,Qzero,mm,bgd |
---|
114 | aa = w[0] |
---|
115 | nn = w[1] |
---|
116 | cc = w[2] |
---|
117 | LL=w[3] |
---|
118 | Qzero=w[4] |
---|
119 | mm=w[5] |
---|
120 | bgd=w[6] |
---|
121 | // local variables |
---|
122 | Variable inten, qval |
---|
123 | // x is the q-value for the calculation |
---|
124 | qval = x |
---|
125 | // do the calculation and return the function value |
---|
126 | |
---|
127 | inten = aa/(qval)^nn + cc/(1 + (abs(qval-Qzero)*LL)^mm) + bgd |
---|
128 | |
---|
129 | Return (inten) |
---|
130 | |
---|
131 | End |
---|
132 | |
---|
133 | //CH#4 |
---|
134 | /////////////////////////////////////////////////////////////// |
---|
135 | // smeared model calculation |
---|
136 | // |
---|
137 | // you don't need to do anything with this function, as long as |
---|
138 | // your BroadPeak works correctly, you get the resolution-smeared |
---|
139 | // version for free. |
---|
140 | // |
---|
141 | // this is all there is to the smeared model calculation! |
---|
142 | Function SmearedBroadPeak(s) : FitFunc |
---|
143 | Struct ResSmearAAOStruct &s |
---|
144 | |
---|
145 | // the name of your unsmeared model (AAO) is the first argument |
---|
146 | Smear_Model_20(BroadPeak,s.coefW,s.xW,s.yW,s.resW) |
---|
147 | |
---|
148 | return(0) |
---|
149 | End |
---|
150 | |
---|
151 | |
---|
152 | /////////////////////////////////////////////////////////////// |
---|
153 | |
---|
154 | |
---|
155 | // nothing to change here |
---|
156 | // |
---|
157 | //wrapper to calculate the smeared model as an AAO-Struct |
---|
158 | // fills the struct and calls the ususal function with the STRUCT parameter |
---|
159 | // |
---|
160 | // used only for the dependency, not for fitting |
---|
161 | // |
---|
162 | Function fSmearedBroadPeak(coefW,yW,xW) |
---|
163 | Wave coefW,yW,xW |
---|
164 | |
---|
165 | String str = getWavesDataFolder(yW,0) |
---|
166 | String DF="root:"+str+":" |
---|
167 | |
---|
168 | WAVE resW = $(DF+str+"_res") |
---|
169 | |
---|
170 | STRUCT ResSmearAAOStruct fs |
---|
171 | WAVE fs.coefW = coefW |
---|
172 | WAVE fs.yW = yW |
---|
173 | WAVE fs.xW = xW |
---|
174 | WAVE fs.resW = resW |
---|
175 | |
---|
176 | Variable err |
---|
177 | err = SmearedBroadPeak(fs) |
---|
178 | |
---|
179 | return (0) |
---|
180 | End |
---|