source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/NewModels_2008/TwoLorentzian_v40.ipf @ 445

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

Adding a pile of new model functions. Some are from Boualem, some old code from Danilo, some from me.

As far as I can tell, these replicate the original references (not the empirical models).

Help file and XOPs have net been done yet.

File size: 5.4 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.0
3
4////////////////////////////////////////////////////
5//
6// an empirical model containing two "lorentzian" functions if the exponents are = 2
7// - you get similar behavior for m!=n!=2, just not truly "Lorentzian"
8//
9//
10// B. Hammouda OCT 2008
11//
12//
13// updated for use with latest macros SRK Nov 2008
14//
15////////////////////////////////////////////////////
16
17//
18Proc PlotTwoLorentzian(num,qmin,qmax)
19        Variable num=200, qmin=0.001, qmax=0.7
20        Prompt num "Enter number of data points for model: "
21        Prompt qmin "Enter minimum q-value (^-1) for model: "
22        Prompt qmax "Enter maximum q-value (^-1) for model: "
23//
24        Make/O/D/n=(num) xwave_TwoLorentzian, ywave_TwoLorentzian
25        xwave_TwoLorentzian =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
26        Make/O/D coef_TwoLorentzian = {10,100,3,1,10,2,0.1}             
27        make/o/t parameters_TwoLorentzian = {"Lorentzian #1 scale","Correlation length #1 [A]","Lorentzian #1 exponent","Lorentzian #2 scale","Correlation length #2 [A]","Lorentzian #2 exponent","Bkg [1/cm]"}
28        Edit parameters_TwoLorentzian, coef_TwoLorentzian
29       
30        Variable/G root:g_TwoLorentzian
31        g_TwoLorentzian := TwoLorentzian(coef_TwoLorentzian, ywave_TwoLorentzian, xwave_TwoLorentzian)
32        Display ywave_TwoLorentzian vs xwave_TwoLorentzian
33        ModifyGraph marker=29, msize=2, mode=4
34        ModifyGraph log=1,grid=1,mirror=2
35        Label bottom "q (\\S-1\\M) "
36        Label left "I(q) (cm\\S-1\\M)"
37        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
38       
39        AddModelToStrings("TwoLorentzian","coef_TwoLorentzian","TwoLorentzian")
40//
41End
42
43
44//
45//no input parameters are necessary, it MUST use the experimental q-values
46// from the experimental data read in from an AVE/QSIG data file
47////////////////////////////////////////////////////
48// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
49Proc PlotSmearedTwoLorentzian(str)                                                             
50        String str
51        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
52       
53        // if any of the resolution waves are missing => abort
54        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
55                Abort
56        endif
57       
58        SetDataFolder $("root:"+str)
59       
60        // Setup parameter table for model function
61        Make/O/D smear_coef_TwoLorentzian = {10,100,3,1,10,2,0.1}               
62        make/o/t smear_parameters_TwoLorentzian = {"Lorentzian #1 scale","Correlation length #1 [A]","Lorentzian #1 exponent","Lorentzian #2 scale","Correlation length #2 [A]","Lorentzian #2 exponent","Bkg [1/cm]"}
63        Edit smear_parameters_TwoLorentzian,smear_coef_TwoLorentzian                                    //display parameters in a table
64       
65        // output smeared intensity wave, dimensions are identical to experimental QSIG values
66        // make extra copy of experimental q-values for easy plotting
67        Duplicate/O $(str+"_q") smeared_TwoLorentzian,smeared_qvals
68        SetScale d,0,0,"1/cm",smeared_TwoLorentzian
69                                       
70        Variable/G gs_TwoLorentzian=0
71        gs_TwoLorentzian := fSmearedTwoLorentzian(smear_coef_TwoLorentzian,smeared_TwoLorentzian,smeared_qvals) //this wrapper fills the STRUCT
72       
73        Display smeared_TwoLorentzian vs smeared_qvals
74        ModifyGraph log=1,marker=29,msize=2,mode=4
75        Label bottom "q (\\S-1\\M)"
76        Label left "I(q) (cm\\S-1\\M)"
77        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
78       
79        SetDataFolder root:
80        AddModelToStrings("SmearedTwoLorentzian","smear_coef_TwoLorentzian","TwoLorentzian")
81End
82
83
84//
85//AAO version, uses XOP if available
86// simply calls the original single point calculation with
87// a wave assignment (this will behave nicely if given point ranges)
88Function TwoLorentzian(cw,yw,xw) : FitFunc
89        Wave cw,yw,xw
90       
91#if exists("TwoLorentzianX")
92        yw = TwoLorentzianX(cw,xw)
93#else
94        yw = fTwoLorentzian(cw,xw)
95#endif
96        return(0)
97End
98
99//
100// unsmeared model calculation
101//
102Function fTwoLorentzian(w,x) : FitFunc
103        Wave w
104        Variable x
105       
106        // variables are:                                                       
107        //[0] Lorentzian term scaling
108        //[1] Lorentzian screening length [A]
109        //[2] Lorentzian exponent
110        //[3] Lorentzian #2 term scaling
111        //[4] Lorentzian #2 screening length [A]
112        //[5] Lorentzian #2 exponent
113        //[6] background
114       
115        Variable aa,LL1,nn,cc,LL2,mm,bgd
116        aa = w[0]
117        LL1=w[1]
118        nn = w[2]
119        cc = w[3]
120        LL2=w[4]
121        mm=w[5]
122        bgd=w[6]
123//      local variables
124        Variable inten, qval
125//      x is the q-value for the calculation
126        qval = x
127//      do the calculation and return the function value
128       
129        inten = aa/(1+(qval*LL1)^nn) + cc/(1 + (qval*LL2)^mm) + bgd
130
131        Return (inten)
132       
133End
134
135
136///////////////////////////////////////////////////////////////
137// smeared model calculation
138//
139// you don't need to do anything with this function, as long as
140// your TwoLorentzian works correctly, you get the resolution-smeared
141// version for free.
142//
143// this is all there is to the smeared model calculation!
144Function SmearedTwoLorentzian(s) : FitFunc
145        Struct ResSmearAAOStruct &s
146
147//      the name of your unsmeared model (AAO) is the first argument
148        Smear_Model_20(TwoLorentzian,s.coefW,s.xW,s.yW,s.resW)
149
150        return(0)
151End
152
153
154///////////////////////////////////////////////////////////////
155
156
157// nothing to change here
158//
159//wrapper to calculate the smeared model as an AAO-Struct
160// fills the struct and calls the ususal function with the STRUCT parameter
161//
162// used only for the dependency, not for fitting
163//
164Function fSmearedTwoLorentzian(coefW,yW,xW)
165        Wave coefW,yW,xW
166       
167        String str = getWavesDataFolder(yW,0)
168        String DF="root:"+str+":"
169       
170        WAVE resW = $(DF+str+"_res")
171       
172        STRUCT ResSmearAAOStruct fs
173        WAVE fs.coefW = coefW   
174        WAVE fs.yW = yW
175        WAVE fs.xW = xW
176        WAVE fs.resW = resW
177       
178        Variable err
179        err = SmearedTwoLorentzian(fs)
180       
181        return (0)
182End
Note: See TracBrowser for help on using the repository browser.