source:sans/Dev/trunk/NCNR_User_Procedures/Analysis/Alpha/Tinker/FFT_Fit_3Cyl_KR.ipf@1249

Last change on this file since 1249 was 940, checked in by srkline, 9 years ago

Updated the reduction Read/Write? and corresponding factility stubs to accomodate detector dead time written to the VAX header. It is currently not written to the header, but may be with NICE (hopefully).

With the move of NG3 SANS to CGB(upper), the NG3 designation in the account name [NGxSANSxx] has been replaced with CGB. Folders on charlotte and radio button on SASCALC are labeled "NGB30" to be more obvious which instrument it is.

FFT routines have minor typos cleaned up.

File size: 6.7 KB
Line
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.1
3
4////////////////////////////////////////////////
5//
6// This is a proof of principle to convert a structure built of spheres
7// into a fitting function
8//
9////////////////////////////////////////////////
10
11Proc PlotThreeCylKR(num,qmin,qmax)
12        Variable num=100,qmin=0.004,qmax=0.4
13        Prompt num "Enter number of data points for model: "
14        Prompt qmin "Enter minimum q-value (A^-1) for model: "
15        Prompt qmax "Enter maximum q-value (A^-1) for model: "
16
17
18        // make the needed waves, three rows for this case
20
21        make/o/D/n=(num) xwave_c3KR,ywave_c3KR
22        xwave_c3KR =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
23        make/o/D coef_c3KR = {0.01,40,32,26,34,26,34,1e-6,2e-6,0.01}
24        make/o/t parameters_c3KR = {"scale","radius 1 (A)","length 1 (A)","radius 2 (A)","length 2 (A)","radius 3 (A)","length 3 (A)","SLD cylinder (A^-2)","SLD solvent (A^-2)","incoh. bkg (cm^-1)"}
25        Edit parameters_c3KR,coef_c3KR
26        Variable/G root:g_c3KR
27        g_c3KR := ThreeCylKR(coef_c3KR,ywave_c3KR,xwave_c3KR)
28
29        Display ywave_c3KR vs xwave_c3KR
30        ModifyGraph log=1,marker=29,msize=2,mode=4
31        Label bottom "q (A\\S-1\\M)"
32        Label left "Intensity (cm\\S-1\\M)"
33        AutoPositionWindow/M=1/R=\$(WinName(0,1)) \$WinName(0,2)
34
36End
37
38/////////////////////////////////////////////////////////////
39//// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
40Proc PlotSmearedThreeCylKR(str)
41        String str
42        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
43
44        // if any of the resolution waves are missing => abort
45        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
46                Abort
47        endif
48
49        // make the needed waves, three rows for this case
51
52        SetDataFolder \$("root:"+str)
53
54        // Setup parameter table for model function
55        make/o/D smear_coef_c3KR = {0.01,40,32,26,34,26,34,1e-6,2e-6,0.01}
56        make/o/t smear_parameters_c3KR = {"scale","radius 1 (A)","length 1 (A)","radius 2 (A)","length 2 (A)","radius 3 (A)","length 3 (A)","SLD cylinder (A^-2)","SLD solvent (A^-2)","incoh. bkg (cm^-1)"}
57        Edit smear_parameters_c3KR,smear_coef_c3KR
58
59        // output smeared intensity wave, dimensions are identical to experimental QSIG values
60        // make extra copy of experimental q-values for easy plotting
61        Duplicate/O \$(str+"_q") smeared_c3KR,smeared_qvals
62        SetScale d,0,0,"1/cm",smeared_c3KR
63
64        Variable/G gs_c3KR=0
65        gs_c3KR := fSmearedThreeCylKR(smear_coef_c3KR,smeared_c3KR,smeared_qvals)       //this wrapper fills the STRUCT
66
67        Display smeared_c3KR vs smeared_qvals
68        ModifyGraph log=1,marker=29,msize=2,mode=4
69        Label bottom "q (A\\S-1\\M)"
70        Label left "Intensity (cm\\S-1\\M)"
71        AutoPositionWindow/M=1/R=\$(WinName(0,1)) \$WinName(0,2)
72
73        SetDataFolder root:
75End
76
77// The calculation is inherently AAO, so it's all done here, not passed to another FitFunc
78//
79// not quite sure how to handle the SLDs yet, since I'm treating them as 1 or 2 digit integers
80//
81Function ThreeCylKR(cw,yw,xw) : FitFunc
82        Wave cw,yw,xw
83
84//      Variable t1=StopMSTimer(-2)
85
86//The input variables are (and output)
87        //[0] scale
89        //[2] total cylinder LENGTH (A)
90        //[3] sld cylinder (A^-2)
91        //[4] sld solvent
92        //[5] background (cm^-1)
93        Variable scale,delrho,bkg,sldCyl,sldSolv,ctr,fill
94        Variable r0,r1,r2,l0,l1,l2
95        scale = cw[0]
96        r0 = cw[1]
97        l0 = cw[2]
98        r1 = cw[3]
99        l1 = cw[4]
100        r2 = cw[5]
101        l2 = cw[6]
102        sldCyl = cw[7]
103        sldSolv = cw[8]
104        bkg = cw[9]
105
106
107// make sure all of the globals are set correctly
108        NVAR FFT_T = root:FFT_T
109        NVAR FFT_N = root:FFT_N
110        NVAR FFT_SolventSLD = root:FFT_SolventSLD
111        NVAR FFT_delRho = root:FFT_delRho               //the SLD multiplier, should have been initialized to 1e-7
112
113        FFT_SolventSLD = trunc(sldSolv/FFT_delRho)              //spits back an integer, maybe not correct
114
115// generate the matrix and erase it
116//      FFT_MakeMatrixButtonProc("")
117//      FFTEraseMatrixButtonProc("")
118//      Wave m=root:mat
119
120// fill the matrix with solvent
121//      FFTFillSolventMatrixProc("")
122
123        // waves to pass to parsing routine
124        WAVE xCtr_KR=root:xCtr_KR
125        WAVE yCtr_KR=root:yCtr_KR
126        WAVE zCtr_KR=root:zCtr_KR
128        WAVE len_KR=root:len_KR
129        WAVE sph_KR=root:sph_KR
130        WAVE rotx_KR=root:rotx_KR
131        WAVE roty_KR=root:roty_KR
132        WAVE SLD_KR=root:SLD_KR
133
134
135
136// with the input parameters, build the structure
137// the first cylinder is at 0,0,0
138// the second cylinder is on "top" (Z)
139// the third cylinder is on the "bottom" (-Z)
140        xCtr_KR[0] = 0
141        yCtr_KR[0] = 0
142        zCtr_KR[0] = 0
144        len_KR[0] = l0
145
146        xCtr_KR[1] = 0
147        yCtr_KR[1] = 0
148        zCtr_KR[1] = l0/2 + l1/2
150        len_KR[1] = l1
151
152        xCtr_KR[2] = 0
153        yCtr_KR[2] = 0
154        zCtr_KR[2] = -(l0/2 + l2/2)
156        len_KR[2] = l2
157
158        //no rotation here, only one SLD
159        sph_KR = FFT_T          //use the global
160        rotx_KR = 0
161        roty_KR = 0
162        SLD_KR = trunc(sldCyl*1e6)
163
164
165
166// this parses the information and generates xoutW, youtW, zoutW, sldW in the root folder
168
169
170        // these are really just for display, or if the FFT of mat is wanted later.
171        WAVE xoutW=root:xoutW
172        WAVE youtW=root:youtW
173        WAVE zoutW=root:zoutW
174        WAVE sldW=root:sldW
175
176        XYZV_FillMat(xoutW,youtW,ZoutW,sldW,1)                  //last 1 will erase the matrix
177        MakeTriplet(xoutW,youtW,zoutW)
178
179
180
181// do the calculation (use the binned if only one SLD, or bin+SLD if the model requires this)
182        fDoCalc(xw,yw,FFT_T,12,0)               //the binned calculation
183//      fDoCalc(xw,yw,FFT_T,13,0)               //the binned + multiple SLD calculation
184
185// reset the volume fraction to get the proper scaling
186// the calculation is normalized to the volume fraction of spheres filling the matrix
187        Variable frac
188        Wave m=root:mat
189
190        frac = VolumeFraction_Occ(m)
191
192        yw /= frac
193        yw *= scale
194        yw += bkg
195
196//      Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6
197
198        return(0)
199End
200
201
202//
203//// this is all there is to the smeared calculation!
204Function SmearedThreeCylKR(s) :FitFunc
205        Struct ResSmearAAOStruct &s
206
207////the name of your unsmeared model is the first argument
208        Smear_Model_20(ThreeCylKR,s.coefW,s.xW,s.yW,s.resW)
209
210        return(0)
211End
212//
213//
214////wrapper to calculate the smeared model as an AAO-Struct
215//// fills the struct and calls the ususal function with the STRUCT parameter
216////
217//// used only for the dependency, not for fitting
218////
219Function fSmearedThreeCylKR(coefW,yW,xW)
220        Wave coefW,yW,xW
221
222        String str = getWavesDataFolder(yW,0)
223        String DF="root:"+str+":"
224
225        WAVE resW = \$(DF+str+"_res")
226
227        STRUCT ResSmearAAOStruct fs
228        WAVE fs.coefW = coefW
229        WAVE fs.yW = yW
230        WAVE fs.xW = xW
231        WAVE fs.resW = resW
232
233        Variable err
234        err = SmearedThreeCylKR(fs)
235
236        return (0)
237End
Note: See TracBrowser for help on using the repository browser.