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 DANSE 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 PlotCoreShellCylinder2D(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 | // Setup parameter table for model function |
---|
27 | make/O/T/N=15 parameters_CSCyl2D |
---|
28 | Make/O/D/N=15 coef_CSCyl2D |
---|
29 | |
---|
30 | coef_CSCyl2D[0] = 1.0 |
---|
31 | coef_CSCyl2D[1] = 20.0 |
---|
32 | coef_CSCyl2D[2] = 10.0 |
---|
33 | coef_CSCyl2D[3] = 200.0 |
---|
34 | coef_CSCyl2D[4] = 1.0e-6 |
---|
35 | coef_CSCyl2D[5] = 4.0e-6 |
---|
36 | coef_CSCyl2D[6] = 1.0e-6 |
---|
37 | coef_CSCyl2D[7] = 0.0 |
---|
38 | coef_CSCyl2D[8] = 1.57 |
---|
39 | coef_CSCyl2D[9] = 0.0 |
---|
40 | coef_CSCyl2D[10] = 0.0 |
---|
41 | coef_CSCyl2D[11] = 0.0 |
---|
42 | coef_CSCyl2D[12] = 0.0 |
---|
43 | coef_CSCyl2D[13] = 0.0 |
---|
44 | coef_CSCyl2D[14] = 10 |
---|
45 | |
---|
46 | parameters_CSCyl2D[0] = "Scale" |
---|
47 | parameters_CSCyl2D[1] = "Radius" |
---|
48 | parameters_CSCyl2D[2] = "Thickness" |
---|
49 | parameters_CSCyl2D[3] = "Length" |
---|
50 | parameters_CSCyl2D[4] = "Core SLD" |
---|
51 | parameters_CSCyl2D[5] = "Shell SLD" |
---|
52 | parameters_CSCyl2D[6] = "Solvent SLD" |
---|
53 | parameters_CSCyl2D[7] = "Background" |
---|
54 | parameters_CSCyl2D[8] = "Axis Theta" |
---|
55 | parameters_CSCyl2D[9] = "Axis Phi" |
---|
56 | parameters_CSCyl2D[10] = "Sigma of polydisp in Radius [Angstrom]" |
---|
57 | parameters_CSCyl2D[11] = "Sigma of polydisp in Thickness [Angstrom]" |
---|
58 | parameters_CSCyl2D[12] = "Sigma of polydisp in Theta [rad]" |
---|
59 | parameters_CSCyl2D[13] = "Sigma of polydisp in Phi [rad]" |
---|
60 | parameters_CSCyl2D[14] = "Num of polydisp points" |
---|
61 | |
---|
62 | Edit parameters_CSCyl2D,coef_CSCyl2D |
---|
63 | |
---|
64 | // generate the triplet representation |
---|
65 | Duplicate/O $(str+"_qx") xwave_CSCyl2D |
---|
66 | Duplicate/O $(str+"_qy") ywave_CSCyl2D,zwave_CSCyl2D |
---|
67 | |
---|
68 | Variable/G gs_CSCyl2D=0 |
---|
69 | gs_CSCyl2D := CoreShellCylinder2D(coef_CSCyl2D,zwave_CSCyl2D,xwave_CSCyl2D,ywave_CSCyl2D) //AAO 2D calculation |
---|
70 | |
---|
71 | Display ywave_CSCyl2D vs xwave_CSCyl2D |
---|
72 | modifygraph log=0 |
---|
73 | ModifyGraph mode=3,marker=16,zColor(ywave_CSCyl2D)={zwave_CSCyl2D,*,*,YellowHot,0} |
---|
74 | ModifyGraph standoff=0 |
---|
75 | ModifyGraph width={Aspect,1} |
---|
76 | ModifyGraph lowTrip=0.001 |
---|
77 | Label bottom "qx (A\\S-1\\M)" |
---|
78 | Label left "qy (A\\S-1\\M)" |
---|
79 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
80 | |
---|
81 | // generate the matrix representation |
---|
82 | ConvertQxQy2Mat(xwave_CSCyl2D,ywave_CSCyl2D,zwave_CSCyl2D,"CSCyl2D_mat") |
---|
83 | Duplicate/O $"CSCyl2D_mat",$"CSCyl2D_lin" //keep a linear-scaled version of the data |
---|
84 | // _mat is for display, _lin is the real calculation |
---|
85 | |
---|
86 | // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation |
---|
87 | Variable/G gs_CSCyl2Dmat=0 |
---|
88 | gs_CSCyl2Dmat := UpdateQxQy2Mat(xwave_CSCyl2D,ywave_CSCyl2D,zwave_CSCyl2D,CSCyl2D_lin,CSCyl2D_mat) |
---|
89 | |
---|
90 | |
---|
91 | SetDataFolder root: |
---|
92 | AddModelToStrings("CoreShellCylinder2D","coef_CSCyl2D","CSCyl2D") |
---|
93 | End |
---|
94 | |
---|
95 | //AAO version, uses XOP if available |
---|
96 | // simply calls the original single point calculation with |
---|
97 | // a wave assignment (this will behave nicely if given point ranges) |
---|
98 | // |
---|
99 | // NON-THREADED IMPLEMENTATION |
---|
100 | // |
---|
101 | //Function CoreShellCylinder2D(cw,zw,xw,yw) : FitFunc |
---|
102 | // Wave cw,zw,xw,yw |
---|
103 | // |
---|
104 | //#if exists("CoreShellCylinderModel_D") |
---|
105 | // zw = CoreShellCylinderModel_D(cw,xw,yw) |
---|
106 | //#else |
---|
107 | // Abort "You do not have the SANS Analysis XOP installed" |
---|
108 | //#endif |
---|
109 | // return(0) |
---|
110 | //End |
---|
111 | // |
---|
112 | |
---|
113 | //threaded version of the function |
---|
114 | ThreadSafe Function CoreShellCylinder2D_T(cw,zw,xw,yw,p1,p2) |
---|
115 | WAVE cw,zw,xw,yw |
---|
116 | Variable p1,p2 |
---|
117 | |
---|
118 | #if exists("CoreShellCylinderModel_D") //to hide the function if XOP not installed |
---|
119 | zw[p1,p2]= CoreShellCylinderModel_D(cw,xw,yw) |
---|
120 | #endif |
---|
121 | |
---|
122 | return 0 |
---|
123 | End |
---|
124 | |
---|
125 | // |
---|
126 | // Fit function that is actually a wrapper to dispatch the calculation to N threads |
---|
127 | // |
---|
128 | // nthreads is 1 or an even number, typically 2 |
---|
129 | // it doesn't matter if npt is odd. In this case, fractional point numbers are passed |
---|
130 | // and the wave indexing works just fine - I tested this with test waves of 7 and 8 points |
---|
131 | // and the points "2.5" and "3.5" evaluate correctly as 2 and 3 |
---|
132 | // |
---|
133 | Function CoreShellCylinder2D(cw,zw,xw,yw) : FitFunc |
---|
134 | Wave cw,zw,xw,yw |
---|
135 | |
---|
136 | Variable npt=numpnts(yw) |
---|
137 | Variable i,nthreads= ThreadProcessorCount |
---|
138 | variable mt= ThreadGroupCreate(nthreads) |
---|
139 | |
---|
140 | for(i=0;i<nthreads;i+=1) |
---|
141 | // Print (i*npt/nthreads),((i+1)*npt/nthreads-1) |
---|
142 | ThreadStart mt,i,CoreShellCylinder2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1)) |
---|
143 | endfor |
---|
144 | |
---|
145 | do |
---|
146 | variable tgs= ThreadGroupWait(mt,100) |
---|
147 | while( tgs != 0 ) |
---|
148 | |
---|
149 | variable dummy= ThreadGroupRelease(mt) |
---|
150 | |
---|
151 | return(0) |
---|
152 | End |
---|