1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion=6.0 |
---|
3 | |
---|
4 | // |
---|
5 | // The plotting macro sets up TWO dependencies |
---|
6 | // - one for the triplet calculation |
---|
7 | // - one for a matrix to display, a copy of the triplet |
---|
8 | // |
---|
9 | // For display, there are two copies of the matrix. One matrix is linear, and is a copy of the |
---|
10 | // triplet (which is ALWAYS linear). The other matrix is toggled log/lin for display |
---|
11 | // in the same way the 2D SANS data matrix is handled. |
---|
12 | // |
---|
13 | |
---|
14 | /// REQUIRES XOP for 2D FUNCTIONS |
---|
15 | |
---|
16 | // |
---|
17 | // the calculation is done as for the QxQy data set: |
---|
18 | // three waves XYZ, then converted to a matrix |
---|
19 | // |
---|
20 | Proc PlotPeakGauss2D(str) |
---|
21 | String str |
---|
22 | Prompt str,"Pick the data folder containing the 2D data",popup,getAList(4) |
---|
23 | |
---|
24 | SetDataFolder $("root:"+str) |
---|
25 | |
---|
26 | Make/O/D coef_pkGau2D = {100.0, 0.25,0.005, 1.0} |
---|
27 | make/o/t parameters_pkGau2D = {"Scale Factor, I0 ", "Peak position (A^-1)", "Std Dev (A^-1)","Incoherent Bgd (cm-1)"} |
---|
28 | Edit parameters_pkGau2D,coef_pkGau2D |
---|
29 | |
---|
30 | // generate the triplet representation |
---|
31 | Duplicate/O $(str+"_qx") xwave_pkGau2D |
---|
32 | Duplicate/O $(str+"_qy") ywave_pkGau2D,zwave_pkGau2D |
---|
33 | |
---|
34 | Variable/G g_pkGau2D=0 |
---|
35 | g_pkGau2D := PeakGauss2D(coef_pkGau2D,zwave_pkGau2D,xwave_pkGau2D,ywave_pkGau2D) //AAO 2D calculation |
---|
36 | |
---|
37 | Display ywave_pkGau2D vs xwave_pkGau2D |
---|
38 | modifygraph log=0 |
---|
39 | ModifyGraph mode=3,marker=16,zColor(ywave_pkGau2D)={zwave_pkGau2D,*,*,YellowHot,0} |
---|
40 | ModifyGraph standoff=0 |
---|
41 | ModifyGraph width={Aspect,1} |
---|
42 | ModifyGraph lowTrip=0.001 |
---|
43 | Label bottom "qx (A\\S-1\\M)" |
---|
44 | Label left "qy (A\\S-1\\M)" |
---|
45 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
46 | |
---|
47 | // generate the matrix representation |
---|
48 | ConvertQxQy2Mat(xwave_pkGau2D,ywave_pkGau2D,zwave_pkGau2D,"pkGau2D_mat") |
---|
49 | Duplicate/O $"pkGau2D_mat",$"pkGau2D_lin" //keep a linear-scaled version of the data |
---|
50 | // _mat is for display, _lin is the real calculation |
---|
51 | |
---|
52 | // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation |
---|
53 | Variable/G g_pkGau2Dmat=0 |
---|
54 | g_pkGau2Dmat := UpdateQxQy2Mat(xwave_pkGau2D,ywave_pkGau2D,zwave_pkGau2D,pkGau2D_lin,pkGau2D_mat) |
---|
55 | |
---|
56 | |
---|
57 | SetDataFolder root: |
---|
58 | AddModelToStrings("PeakGauss2D","coef_pkGau2D","parameters_pkGau2D","pkGau2D") |
---|
59 | End |
---|
60 | |
---|
61 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
62 | Proc PlotSmearedPeakGauss2D(str) |
---|
63 | String str |
---|
64 | Prompt str,"Pick the data folder containing the 2D data",popup,getAList(4) |
---|
65 | |
---|
66 | // if any of the resolution waves are missing => abort |
---|
67 | // if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
68 | // Abort |
---|
69 | // endif |
---|
70 | |
---|
71 | SetDataFolder $("root:"+str) |
---|
72 | |
---|
73 | // Setup parameter table for model function |
---|
74 | Make/O/D smear_coef_pkGau2D = {100.0, 0.25,0.005, 1.0} |
---|
75 | make/o/t smear_parameters_pkGau2D = {"Scale Factor, I0 ", "Peak position (A^-1)", "Std Dev (A^-1)","Incoherent Bgd (cm-1)"} |
---|
76 | Edit smear_parameters_pkGau2D,smear_coef_pkGau2D |
---|
77 | |
---|
78 | Duplicate/O $(str+"_qx") smeared_pkGau2D //1d place for the smeared model |
---|
79 | SetScale d,0,0,"1/cm",smeared_pkGau2D |
---|
80 | |
---|
81 | Variable/G gs_pkGau2D=0 |
---|
82 | gs_pkGau2D := fSmearedPeakGauss2D(smear_coef_pkGau2D,smeared_pkGau2D) //this wrapper fills the STRUCT |
---|
83 | |
---|
84 | Display $(str+"_qy") vs $(str+"_qx") |
---|
85 | modifygraph log=0 |
---|
86 | ModifyGraph mode=3,marker=16,zColor($(str+"_qy"))={smeared_pkGau2D,*,*,YellowHot,0} |
---|
87 | ModifyGraph standoff=0 |
---|
88 | ModifyGraph width={Aspect,1} |
---|
89 | ModifyGraph lowTrip=0.001 |
---|
90 | Label bottom "qx (A\\S-1\\M)" |
---|
91 | Label left "qy (A\\S-1\\M)" |
---|
92 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
93 | |
---|
94 | // generate the matrix representation |
---|
95 | Duplicate/O $(str+"_qx"), sm_qx |
---|
96 | Duplicate/O $(str+"_qy"), sm_qy // I can't use local variables in dependencies, so I need the name (that I can't get) |
---|
97 | |
---|
98 | ConvertQxQy2Mat(sm_qx,sm_qy,smeared_pkGau2D,"sm_pkGau2D_mat") |
---|
99 | Duplicate/O $"sm_pkGau2D_mat",$"sm_pkGau2D_lin" //keep a linear-scaled version of the data |
---|
100 | // _mat is for display, _lin is the real calculation |
---|
101 | |
---|
102 | // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation |
---|
103 | Variable/G gs_pkGau2Dmat=0 |
---|
104 | gs_pkGau2Dmat := UpdateQxQy2Mat(sm_qx,sm_qy,smeared_pkGau2D,sm_pkGau2D_lin,sm_pkGau2D_mat) |
---|
105 | |
---|
106 | SetDataFolder root: |
---|
107 | AddModelToStrings("SmearedPeakGauss2D","smear_coef_pkGau2D","smear_parameters_pkGau2D","pkGau2D") |
---|
108 | End |
---|
109 | |
---|
110 | |
---|
111 | //threaded version of the function |
---|
112 | ThreadSafe Function PeakGauss2D_T(cw,zw,xw,yw,p1,p2) |
---|
113 | WAVE cw,zw,xw,yw |
---|
114 | Variable p1,p2 |
---|
115 | |
---|
116 | #if exists("PeakGauss2DX") //to hide the function if XOP not installed |
---|
117 | |
---|
118 | zw[p1,p2]= PeakGauss2DX(cw,xw,yw) |
---|
119 | |
---|
120 | #else |
---|
121 | zw[p1,p2] = I_PeakGauss2D(cw,xw,yw) |
---|
122 | #endif |
---|
123 | |
---|
124 | return 0 |
---|
125 | End |
---|
126 | |
---|
127 | // |
---|
128 | // Fit function that is actually a wrapper to dispatch the calculation to N threads |
---|
129 | // |
---|
130 | // not used |
---|
131 | // |
---|
132 | Function PeakGauss2D(cw,zw,xw,yw) : FitFunc |
---|
133 | Wave cw,zw,xw,yw |
---|
134 | |
---|
135 | Variable npt=numpnts(yw) |
---|
136 | Variable i,nthreads= ThreadProcessorCount |
---|
137 | variable mt= ThreadGroupCreate(nthreads) |
---|
138 | |
---|
139 | // Variable t1=StopMSTimer(-2) |
---|
140 | |
---|
141 | for(i=0;i<nthreads;i+=1) |
---|
142 | // Print (i*npt/nthreads),((i+1)*npt/nthreads-1) |
---|
143 | ThreadStart mt,i,PeakGauss2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1)) |
---|
144 | endfor |
---|
145 | |
---|
146 | do |
---|
147 | variable tgs= ThreadGroupWait(mt,100) |
---|
148 | while( tgs != 0 ) |
---|
149 | |
---|
150 | variable dummy= ThreadGroupRelease(mt) |
---|
151 | |
---|
152 | // Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6 |
---|
153 | |
---|
154 | return(0) |
---|
155 | End |
---|
156 | |
---|
157 | |
---|
158 | //non-threaded version of the function |
---|
159 | Function PeakGauss2D_noThread(cw,zw,xw,yw) |
---|
160 | WAVE cw,zw, xw,yw |
---|
161 | |
---|
162 | #if exists("PeakGauss2DX") //to hide the function if XOP not installed |
---|
163 | |
---|
164 | zw= PeakGauss2DX(cw,xw,yw) |
---|
165 | #else |
---|
166 | zw = I_PeakGauss2D(cw,xw,yw) |
---|
167 | #endif |
---|
168 | |
---|
169 | return 0 |
---|
170 | End |
---|
171 | |
---|
172 | // I think I did this because when I do the quadrature loops I'm calling the AAO with 1-pt waves, so threading |
---|
173 | // would just be a slowdown |
---|
174 | Function SmearedPeakGauss2D(s) |
---|
175 | Struct ResSmear_2D_AAOStruct &s |
---|
176 | |
---|
177 | Smear_2DModel_20(PeakGauss2D_noThread,s) |
---|
178 | // Smear_2DModel_5(PeakGauss2D_noThread,s) |
---|
179 | return(0) |
---|
180 | end |
---|
181 | |
---|
182 | |
---|
183 | Function fSmearedPeakGauss2D(coefW,resultW) |
---|
184 | Wave coefW,resultW |
---|
185 | |
---|
186 | String str = getWavesDataFolder(resultW,0) |
---|
187 | String DF="root:"+str+":" |
---|
188 | |
---|
189 | WAVE qx = $(DF+str+"_qx") |
---|
190 | WAVE qy = $(DF+str+"_qy") |
---|
191 | WAVE qz = $(DF+str+"_qz") |
---|
192 | WAVE sigQx = $(DF+str+"_sigQx") |
---|
193 | WAVE sigQy = $(DF+str+"_sigQy") |
---|
194 | WAVE shad = $(DF+str+"_fs") |
---|
195 | |
---|
196 | STRUCT ResSmear_2D_AAOStruct s |
---|
197 | WAVE s.coefW = coefW |
---|
198 | WAVE s.zw = resultW |
---|
199 | WAVE s.qx = qx |
---|
200 | WAVE s.qy = qy |
---|
201 | WAVE s.qz = qz |
---|
202 | WAVE s.sigQx = sigQx |
---|
203 | WAVE s.sigQy = sigQy |
---|
204 | WAVE s.fs = shad |
---|
205 | |
---|
206 | Variable err |
---|
207 | err = SmearedPeakGauss2D(s) |
---|
208 | |
---|
209 | return (0) |
---|
210 | End |
---|
211 | |
---|
212 | ThreadSafe Function I_PeakGauss2D(w,x,y) |
---|
213 | Wave w |
---|
214 | Variable x,y |
---|
215 | |
---|
216 | Variable retVal,qval |
---|
217 | qval = sqrt(x^2+y^2) |
---|
218 | |
---|
219 | retval = Peak_Gauss_modelX(w,qval) |
---|
220 | // retval = fPeak_Gauss_model(w,qval) |
---|
221 | |
---|
222 | RETURN(retVal) |
---|
223 | END |
---|