source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/VSANS/V_SWB_BroadPeak.ipf @ 1222

Last change on this file since 1222 was 1222, checked in by srkline, 3 years ago

Updated help file for VSANS. Graphics were not PNG.

Removed HFIR SANS package since if requires XML XOP - no longer supported.

Improved quality of graphics export for Analysis reports.

Added more support for super_white_beam mode on VSANS

Corrected printf bug (Igor 8) when printing out % sign

Added utilities for patching wavelength and monochromator type on VSANS since the type is still not written out correctly by NICE, and super_white_beam is not yet defined in NICE

Adjusted panel dimensions for the temperature sensor display on VSANS (needed onWindows)

File size: 6.8 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5////////////////////////////////////////////////////
6//
7// an empirical model containing power law scattering + a broad peak
8//
9// B. Hammouda OCT 2008
10//
11//
12// updated for use with latest macros SRK Nov 2008
13//
14// Updated 2019 to Super White Beam Smearing
15//
16// TODO -- be sure that I'm using the correct normalization and
17//   the correct mean wavelength (used for limits + normalization)
18//
19//
20////////////////////////////////////////////////////
21
22//
23Proc PlotBroadPeakSWB(num,qmin,qmax)
24        Variable num=200, qmin=0.001, qmax=0.7
25        Prompt num "Enter number of data points for model: "
26        Prompt qmin "Enter minimum q-value (^-1) for model: "
27        Prompt qmax "Enter maximum q-value (^-1) for model: "
28//
29        Make/O/D/n=(num) xwave_BroadPeakSWB, ywave_BroadPeakSWB
30        xwave_BroadPeakSWB =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
31        Make/O/D coef_BroadPeakSWB = {1e-5, 3, 10, 50.0, 0.1,2,0.1}             
32        make/o/t parameters_BroadPeakSWB = {"Porod Scale", "Porod Exponent","Lorentzian Scale","Lor Screening Length [A]","Qzero [1/A]","Lorentzian Exponent","Bgd [1/cm]"}     //CH#2
33        Edit parameters_BroadPeakSWB, coef_BroadPeakSWB
34       
35        Variable/G root:g_BroadPeakSWB
36        g_BroadPeakSWB := BroadPeakSWB(coef_BroadPeakSWB, ywave_BroadPeakSWB, xwave_BroadPeakSWB)
37        Display ywave_BroadPeakSWB vs xwave_BroadPeakSWB
38        ModifyGraph marker=29, msize=2, mode=4
39        ModifyGraph log=1,grid=1,mirror=2
40        Label bottom "q (\\S-1\\M) "
41        Label left "I(q) (cm\\S-1\\M)"
42        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
43       
44        AddModelToStrings("BroadPeakSWB","coef_BroadPeakSWB","parameters_BroadPeakSWB","BroadPeakSWB")
45//
46End
47
48
49//
50//no input parameters are necessary, it MUST use the experimental q-values
51// from the experimental data read in from an AVE/QSIG data file
52////////////////////////////////////////////////////
53// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
54Proc PlotSmearedBroadPeakSWB(str)                                                               
55        String str
56        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
57       
58        // if any of the resolution waves are missing => abort
59        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
60                Abort
61        endif
62       
63        SetDataFolder $("root:"+str)
64       
65        // Setup parameter table for model function
66        Make/O/D smear_coef_BroadPeakSWB = {1e-5, 3, 10, 50.0, 0.1,2,0.1}               
67        make/o/t smear_parameters_BroadPeakSWB = {"Porod Scale", "Porod Exponent","Lorentzian Scale","Lor Screening Length [A]","Qzero [1/A]","Lorentzian Exponent","Bgd [1/cm]"}
68        Edit smear_parameters_BroadPeakSWB,smear_coef_BroadPeakSWB                                      //display parameters in a table
69       
70        // output smeared intensity wave, dimensions are identical to experimental QSIG values
71        // make extra copy of experimental q-values for easy plotting
72        Duplicate/O $(str+"_q") smeared_BroadPeakSWB,smeared_qvals
73        SetScale d,0,0,"1/cm",smeared_BroadPeakSWB
74                                       
75        Variable/G gs_BroadPeakSWB=0
76        gs_BroadPeakSWB := fSmearedBroadPeakSWB(smear_coef_BroadPeakSWB,smeared_BroadPeakSWB,smeared_qvals)     //this wrapper fills the STRUCT
77       
78        Display smeared_BroadPeakSWB vs smeared_qvals
79        ModifyGraph log=1,marker=29,msize=2,mode=4
80        Label bottom "q (\\S-1\\M)"
81        Label left "I(q) (cm\\S-1\\M)"
82        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
83       
84        SetDataFolder root:
85        AddModelToStrings("SmearedBroadPeakSWB","smear_coef_BroadPeakSWB","smear_parameters_BroadPeakSWB","BroadPeakSWB")
86End
87
88
89//
90//AAO version, uses XOP if available
91// simply calls the original single point calculation with
92// a wave assignment (this will behave nicely if given point ranges)
93Function BroadPeakSWB(cw,yw,xw) : FitFunc
94        Wave cw,yw,xw
95       
96#if exists("BroadPeakX")
97//      yw = BroadPeakX(cw,xw)
98        yw = V_fBroadPeakSWB(cw,xw)
99#else
100//      yw = fBroadPeakSWB(cw,xw)
101        yw = 1
102#endif
103        return(0)
104End
105
106//
107// unsmeared model calculation
108//
109Function V_fBroadPeakSWB(w,x) : FitFunc
110        Wave w
111        Variable x
112       
113        // variables are:                                                       
114        //[0] Porod term scaling
115        //[1] Porod exponent
116        //[2] Lorentzian term scaling
117        //[3] Lorentzian screening length [A]
118        //[4] peak location [1/A]
119        //[5] Lorentzian exponent
120        //[6] background
121       
122        Variable aa,nn,cc,LL,Qzero,mm,bgd,inten,lolim,uplim
123
124        // define limits based on lo/mean, hi/mean of the wavelength distribution
125        // using the empirical definition, "middle" of the peaks
126        loLim = 3.37/kSuperWhiteBeam_Mean
127        upLim = 20/kSuperWhiteBeam_Mean
128       
129        inten = V_IntegrBroadPeakSWB_mid(w,loLim,upLim,x)
130
131
132       
133// why do I need this? Is this because this is defined as the mean of the distribution
134//  and is needed to normalize the integral? verify this on paper.     
135        inten *= kSuperWhiteBeam_Mean
136
137// normalize the integral       
138        inten /= kSuperWhiteBeam_Normalization          // "middle"  of peaks
139
140        inten -= w[6]
141
142// additional normalization???
143        inten /= 1.05           //
144       
145//      inten /= 2                      // need this factor to match low q of white beam???
146
147        inten += w[6]
148       
149        Return (inten)
150       
151End
152
153// the trick here is that declaring the last qVal wave as a variable
154// since this is implicitly called N times in the wave assignment of the answer wave
155Function V_IntegrBroadPeakSWB_mid(cw,loLim,upLim,qVal)
156        Wave cw
157        Variable loLim,upLim
158        Variable qVal
159       
160        Variable/G root:qq = qval
161        Variable ans
162       
163//      ans = Integrate1D(V_intgrnd_top,lolim,uplim,2,0,cw)             //adaptive quadrature
164        ans = Integrate1D(V_integrand_BroadPeakSWB,lolim,uplim,1,0,cw)          // Romberg integration
165       
166        return ans
167end
168
169Function V_integrand_BroadPeakSWB(cw,dum)
170        Wave cw
171        Variable dum            // the dummy of the integration
172
173        Variable val
174        NVAR qq = root:qq               //the q-value of the integration, not part of cw, so pass global
175//      SVAR funcStr = root:gFunctionString
176//      FUNCREF SANSModel_proto func = $funcStr
177
178        val = V_SuperWhiteBeamDist_mid(dum*kSuperWhiteBeam_Mean)*BroadPeakX(cw,qq/dum)
179       
180        return (val)
181End
182
183//CH#4 
184///////////////////////////////////////////////////////////////
185// smeared model calculation
186//
187// you don't need to do anything with this function, as long as
188// your BroadPeak works correctly, you get the resolution-smeared
189// version for free.
190//
191// this is all there is to the smeared model calculation!
192Function SmearedBroadPeakSWB(s) : FitFunc
193        Struct ResSmearAAOStruct &s
194
195//      the name of your unsmeared model (AAO) is the first argument
196        Smear_Model_76(BroadPeakSWB,s.coefW,s.xW,s.yW,s.resW)
197
198        return(0)
199End
200
201
202///////////////////////////////////////////////////////////////
203
204
205// nothing to change here
206//
207//wrapper to calculate the smeared model as an AAO-Struct
208// fills the struct and calls the ususal function with the STRUCT parameter
209//
210// used only for the dependency, not for fitting
211//
212Function fSmearedBroadPeakSWB(coefW,yW,xW)
213        Wave coefW,yW,xW
214       
215        String str = getWavesDataFolder(yW,0)
216        String DF="root:"+str+":"
217       
218        WAVE resW = $(DF+str+"_res")
219       
220        STRUCT ResSmearAAOStruct fs
221        WAVE fs.coefW = coefW   
222        WAVE fs.yW = yW
223        WAVE fs.xW = xW
224        WAVE fs.resW = resW
225       
226        Variable err
227        err = SmearedBroadPeakSWB(fs)
228       
229        return (0)
230End
Note: See TracBrowser for help on using the repository browser.