1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion = 6.0 |
---|
3 | |
---|
4 | //////////////////////////////////////////////// |
---|
5 | // this procedure calculates the form factor of a sphere |
---|
6 | // |
---|
7 | // 06 NOV 98 SRK |
---|
8 | // |
---|
9 | // modified June 2007 to calculate all-at-once |
---|
10 | // and to use a structure for resolution information |
---|
11 | // |
---|
12 | //////////////////////////////////////////////// |
---|
13 | |
---|
14 | Proc PlotSphereForm(num,qmin,qmax) |
---|
15 | Variable num=128,qmin=0.001,qmax=0.7 |
---|
16 | Prompt num "Enter number of data points for model: " |
---|
17 | Prompt qmin "Enter minimum q-value (^-1) for model: " |
---|
18 | Prompt qmax "Enter maximum q-value (^-1) for model: " |
---|
19 | |
---|
20 | Make/O/D/n=(num) xwave_sf,ywave_sf |
---|
21 | xwave_sf = alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) |
---|
22 | Make/O/D coef_sf = {1.,60,1e-6,0.01} |
---|
23 | make/o/t parameters_sf = {"scale","Radius (A)","contrast (-2)","bkgd (cm-1)"} |
---|
24 | Edit parameters_sf,coef_sf |
---|
25 | Variable/G root:g_sf=0 |
---|
26 | g_sf := SphereForm(coef_sf,ywave_sf,xwave_sf) // AAO calculation, "fake" dependency |
---|
27 | // ywave_sf := SphereForm(coef_sf,xwave_sf) //point calculation |
---|
28 | Display ywave_sf vs xwave_sf |
---|
29 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
30 | Label bottom "q (\\S-1\\M)" |
---|
31 | Label left "Intensity (cm\\S-1\\M)" |
---|
32 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
33 | End |
---|
34 | |
---|
35 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
36 | Proc PlotSmearedSphereForm(str) |
---|
37 | String str |
---|
38 | Prompt str,"Pick the data folder conatining the resolution you want",popup,getAList(4) |
---|
39 | |
---|
40 | // if any of the resolution waves are missing => abort |
---|
41 | if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
42 | Abort |
---|
43 | endif |
---|
44 | |
---|
45 | SetDataFolder $("root:"+str) |
---|
46 | |
---|
47 | // Setup parameter table for model function |
---|
48 | make/o/t smear_parameters_sf = {"scale","Radius (A)","contrast (-2)","bkgd (cm-1)"} |
---|
49 | Make/O/D smear_coef_sf = {1.,60,1e-6,0.0} |
---|
50 | Edit smear_parameters_sf,smear_coef_sf |
---|
51 | |
---|
52 | Duplicate/O $(str+"_q") smeared_sf,smeared_qvals |
---|
53 | SetScale d,0,0,"1/cm",smeared_sf |
---|
54 | |
---|
55 | Variable/G gs_sf=0 |
---|
56 | gs_sf := fSmearedSphereForm(smear_coef_sf,smeared_sf,smeared_qvals) //this wrapper fills the STRUCT |
---|
57 | Display smeared_sf vs smeared_qvals |
---|
58 | |
---|
59 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
60 | Label bottom "q (\\S-1\\M)" |
---|
61 | Label left "Intensity (cm\\S-1\\M)" |
---|
62 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
63 | |
---|
64 | SetDataFolder root: |
---|
65 | End |
---|
66 | |
---|
67 | //AAO version, uses XOP if available |
---|
68 | // simply calls the original single point calculation with |
---|
69 | // a wave assignment (this will behave nicely if given point ranges) |
---|
70 | Function SphereForm(cw,yw,xw) : FitFunc |
---|
71 | Wave cw,yw,xw |
---|
72 | |
---|
73 | #if exists("SphereFormX") |
---|
74 | yw = SphereFormX(cw,xw) |
---|
75 | #else |
---|
76 | yw = fSphereForm(cw,xw) |
---|
77 | #endif |
---|
78 | return(0) |
---|
79 | End |
---|
80 | |
---|
81 | /////////////////////////////////////////////////////////////// |
---|
82 | // unsmeared model calculation |
---|
83 | // this is a "regular" calculation at a single q-value |
---|
84 | /////////////////////////// |
---|
85 | Function fSphereForm(w,x) |
---|
86 | Wave w |
---|
87 | Variable x |
---|
88 | |
---|
89 | // variables are: |
---|
90 | //[0] scale |
---|
91 | //[1] radius () |
---|
92 | //[2] delrho (-2) |
---|
93 | //[3] background (cm-1) |
---|
94 | |
---|
95 | Variable scale,radius,delrho,bkg |
---|
96 | scale = w[0] |
---|
97 | radius = w[1] |
---|
98 | delrho = w[2] |
---|
99 | bkg = w[3] |
---|
100 | |
---|
101 | // calculates scale * f^2/Vol where f=Vol*3*delrho*((sin(qr)-qrcos(qr))/qr^3 |
---|
102 | // and is rescaled to give [=] cm^-1 |
---|
103 | |
---|
104 | Variable bes,f,vol,f2 |
---|
105 | // |
---|
106 | //handle q==0 separately |
---|
107 | If(x==0) |
---|
108 | f = 4/3*pi*radius^3*delrho*delrho*scale*1e8 + bkg |
---|
109 | return(f) |
---|
110 | Endif |
---|
111 | |
---|
112 | bes = 3*(sin(x*radius)-x*radius*cos(x*radius))/x^3/radius^3 |
---|
113 | vol = 4*pi/3*radius^3 |
---|
114 | f = vol*bes*delrho // [=] |
---|
115 | // normalize to single particle volume, convert to 1/cm |
---|
116 | f2 = f * f / vol * 1.0e8 // [=] 1/cm |
---|
117 | |
---|
118 | return (scale*f2+bkg) // Scale, then add in the background |
---|
119 | End |
---|
120 | |
---|
121 | |
---|
122 | //wrapper to calculate the smeared model as an AAO-Struct |
---|
123 | // fills the struct |
---|
124 | // calls the ususal function with the STRUCT parameter |
---|
125 | // |
---|
126 | // -- problem- this assumes USANS w/no matrix |
---|
127 | // -- needs experimental q-values to properly calculate the fitted curve?? is this true? |
---|
128 | // -- how to fill the struct if the type of data is unknown? |
---|
129 | // -- where do I find the matrix? |
---|
130 | // |
---|
131 | Function fSmearedSphereForm(coefW,yW,xW) |
---|
132 | Wave coefW,yW,xW |
---|
133 | |
---|
134 | String str = getWavesDataFolder(yW,0) |
---|
135 | String DF="root:"+str+":" |
---|
136 | |
---|
137 | WAVE resW = $(DF+str+"_res") |
---|
138 | |
---|
139 | STRUCT ResSmearAAOStruct fs |
---|
140 | WAVE fs.coefW = coefW //is this the proper way to populate? seems redundant... |
---|
141 | WAVE fs.yW = yW |
---|
142 | WAVE fs.xW = xW |
---|
143 | WAVE fs.resW = resW |
---|
144 | |
---|
145 | Variable err |
---|
146 | err = SmearedSphereForm(fs) |
---|
147 | |
---|
148 | return (0) |
---|
149 | End |
---|
150 | |
---|
151 | // smeared calculation, AAO and using a structure... |
---|
152 | // defined as as STRUCT, there can never be a dependency linked directly to this function |
---|
153 | // - so set a dependency to the wrapper |
---|
154 | // |
---|
155 | // like the unsmeared function, AAO is equivalent to a wave assignment to the point calculation |
---|
156 | // - but now the function passed is an AAO function |
---|
157 | // |
---|
158 | // Smear_Model_20() takes care of what calculation is done, depending on the resolution information |
---|
159 | // |
---|
160 | // |
---|
161 | Function SmearedSphereForm(s) : FitFunc |
---|
162 | Struct ResSmearAAOStruct &s |
---|
163 | |
---|
164 | ////the name of your unsmeared model is the first argument |
---|
165 | s.yW = Smear_Model_20(SphereForm,s.coefW,s.xW,s.resW) |
---|
166 | |
---|
167 | return(0) |
---|
168 | End |
---|
169 | |
---|
170 | |
---|
171 | // wrapper to do the desired fit |
---|
172 | // |
---|
173 | // str is the data folder for the desired data set |
---|
174 | // |
---|
175 | // -- this looks like something that can be made rather generic rather easily |
---|
176 | // |
---|
177 | Function SphereFitWrapper(str) |
---|
178 | String str |
---|
179 | |
---|
180 | SetDataFolder root: |
---|
181 | String DF="root:"+str+":" |
---|
182 | |
---|
183 | Struct ResSmearAAOStruct fs |
---|
184 | WAVE resW = $(DF+str+"_res") |
---|
185 | WAVE fs.resW = resW |
---|
186 | |
---|
187 | WAVE cw=$(DF+"smear_coef_sf") |
---|
188 | WAVE yw=$(DF+str+"_i") |
---|
189 | WAVE xw=$(DF+str+"_q") |
---|
190 | WAVE sw=$(DF+str+"_s") |
---|
191 | |
---|
192 | Duplicate/O yw $(DF+"FitYw") |
---|
193 | |
---|
194 | //can't use execute if /STRC is needed since structure instance is not a global! |
---|
195 | //don't use the auto-destination with no flag, it doesn't appear to work correctly |
---|
196 | //force it to use a wave of identical length, at least - no guarantee that the q-values |
---|
197 | // will be the same? be sure that the smearing iterpolates |
---|
198 | // |
---|
199 | // ?? how can I get the hold string in correctly?? - from a global? - no, as string function |
---|
200 | // |
---|
201 | FuncFit/H=getHoldStr() /NTHR=0 SmearedSphereForm cw, yw /X=xw /W=sw /I=1 /D=$(DF+"FitYw") /STRC=fs |
---|
202 | |
---|
203 | // FuncFit/H="0010"/NTHR=0 SmearedSphereForm cw, yw /X=xw /W=sw /I=1 /D=$(DF+"FitYw") /STRC=fs |
---|
204 | |
---|
205 | AppendToGraph $(DF+"FitYw") vs xw |
---|
206 | |
---|
207 | print "V_chisq = ",V_chisq |
---|
208 | print cw |
---|
209 | WAVE w_sigma |
---|
210 | print w_sigma |
---|
211 | |
---|
212 | return(0) |
---|
213 | End |
---|