source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Models_2D/Sphere_2D_v40.ipf @ 509

Last change on this file since 509 was 509, checked in by srkline, 14 years ago

(1) fix in ProtocolAsPanel? that correctly calculates Kappa for data taken with the Cerca detectors. In the Kappa calculation, the data is manually scaled, bypassing the normal "ADD" step where the 4x detector data is correctly renormalized. Added a flag to divide by 4 if ILL detector type found.

(2) lots of bits to try to accomodate 2D resolution smearing. Changes to the QxQy? output to have everything needed: Qz, sigX, sigY, and shadowing. So presumably, all of the information is in the reduced data, where it should be.

  • added a 2D resolution calculation based on David Mildner's notes.
  • added 2D quadrature calculation for smearing, and new structure definitions

File size: 5.3 KB
Line 
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//
20Proc PlotSphere2D(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_sf2D = {1.,60,1e-6,6.3e-6,0.01}                                           
27        make/o/t parameters_sf2D = {"scale","Radius (A)","SLD sphere (A-2)","SLD solvent","bkgd (cm-1)"}               
28        Edit parameters_sf2D,coef_sf2D                         
29       
30        // generate the triplet representation
31        Duplicate/O $(str+"_qx") xwave_sf2D
32        Duplicate/O $(str+"_qy") ywave_sf2D,zwave_sf2D                 
33               
34        Variable/G g_sf2D=0
35        g_sf2D := Sphere2D(coef_sf2D,zwave_sf2D,xwave_sf2D,ywave_sf2D)  //AAO 2D calculation
36       
37        Display ywave_sf2D vs xwave_sf2D
38        modifygraph log=0
39        ModifyGraph mode=3,marker=16,zColor(ywave_sf2D)={zwave_sf2D,*,*,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_sf2D,ywave_sf2D,zwave_sf2D,"sf2D_mat")
49        Duplicate/O $"sf2D_mat",$"sf2D_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_sf2Dmat=0
54        g_sf2Dmat := UpdateQxQy2Mat(xwave_sf2D,ywave_sf2D,zwave_sf2D,sf2D_lin,sf2D_mat)
55       
56       
57        SetDataFolder root:
58        AddModelToStrings("Sphere2D","coef_sf2D","sf2D")
59End
60
61// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
62Proc PlotSmearedSphere2D(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_sf2D = {1.,60,1e-6,6.3e-6,0.01}                                     
75        make/o/t smear_parameters_sf2D = {"scale","Radius (A)","SLD sphere (A-2)","SLD solvent (A-2)","bkgd (cm-1)"}
76        Edit smear_parameters_sf2D,smear_coef_sf2D                                     
77       
78        Duplicate/O $(str+"_qx") smeared_sf2D   //1d place for the smeared model
79        SetScale d,0,0,"1/cm",smeared_sf2D                                     
80               
81        Variable/G gs_sf2D=0
82        gs_sf2D := fSmearedSphere2D(smear_coef_sf2D,smeared_sf2D)       //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_sf2D,*,*,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        SetDataFolder root:
95        AddModelToStrings("SmearedSphere2D","smear_coef_sf2D","sf2D")
96End
97
98
99//threaded version of the function
100ThreadSafe Function Sphere2D_T(cw,zw,xw,yw,p1,p2)
101        WAVE cw,zw,xw,yw
102        Variable p1,p2
103       
104#if exists("Sphere_2DX")                        //to hide the function if XOP not installed
105       
106        zw[p1,p2]= Sphere_2DX(cw,xw,yw)
107
108#endif
109
110        return 0
111End
112
113//
114//  Fit function that is actually a wrapper to dispatch the calculation to N threads
115//
116// nthreads is 1 or an even number, typically 2
117// it doesn't matter if npt is odd. In this case, fractional point numbers are passed
118// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points
119// and the points "2.5" and "3.5" evaluate correctly as 2 and 3
120//
121Function Sphere2D(cw,zw,xw,yw) : FitFunc
122        Wave cw,zw,xw,yw
123       
124        Variable npt=numpnts(yw)
125        Variable i,nthreads= ThreadProcessorCount
126        variable mt= ThreadGroupCreate(nthreads)
127
128//      Variable t1=StopMSTimer(-2)
129       
130        for(i=0;i<nthreads;i+=1)
131        //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1)
132                ThreadStart mt,i,Sphere2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1))
133        endfor
134
135        do
136                variable tgs= ThreadGroupWait(mt,100)
137        while( tgs != 0 )
138
139        variable dummy= ThreadGroupRelease(mt)
140       
141//      Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6
142       
143        return(0)
144End
145
146
147//threaded version of the function
148Function Sphere2D_noThread(cw,zw,xw,yw)
149        WAVE cw,zw, xw,yw
150       
151#if exists("Sphere_2DX")                        //to hide the function if XOP not installed
152       
153        zw= Sphere_2DX(cw,xw,yw)
154
155#endif
156
157        return 0
158End
159
160
161Function SmearedSphere2D(s)
162        Struct ResSmear_2D_AAOStruct &s
163       
164        Smear_2DModel_5(Sphere2D_noThread,s)
165        return(0)
166end
167
168
169Function fSmearedSphere2D(coefW,resultW)
170        Wave coefW,resultW
171       
172        String str = getWavesDataFolder(resultW,0)
173        String DF="root:"+str+":"
174       
175        WAVE qx = $(DF+str+"_qx")
176        WAVE qy = $(DF+str+"_qy")
177        WAVE qz = $(DF+str+"_qz")
178        WAVE sigQx = $(DF+str+"_sigQx")
179        WAVE sigQy = $(DF+str+"_sigQy")
180        WAVE shad = $(DF+str+"_fs")
181       
182        STRUCT ResSmear_2D_AAOStruct s
183        WAVE s.coefW = coefW   
184        WAVE s.zw = resultW     
185        WAVE s.qx = qx
186        WAVE s.qy = qy
187        WAVE s.qz = qz
188        WAVE s.sigQx = sigQx
189        WAVE s.sigQy = sigQy
190        WAVE s.fs = shad
191       
192        Variable err
193        err = SmearedSphere2D(s)
194       
195        return (0)
196End
Note: See TracBrowser for help on using the repository browser.