source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/NewModels_2008/GaussLorentzGel_v40.ipf @ 515

Last change on this file since 515 was 515, checked in by srkline, 13 years ago

A bunch of random changes:
-SASCALC - added the 2.5 cm aperture NG3/7g/polarizer back in, but made the 5 cm the default
-Some fiddling with 2D functionality to enable 2D resolution smearing. Still a work in progress
-Added two new model functions, and added them to the list.
-Changes to the wrapper for the new release to generate kw=val strings as needed for each function
and its coefficients and parameters. This behavior has been changed in the new release, so this
fix should keep old analysis experiments compatible with the new version.

File size: 4.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2////////////////////////////////////////////////////
3//
4// model to calculate the scattering from a gel
5//
6// Reference:G. Evmenenko, E. Theunissedn, K. Mortensen, H. Reynaers
7//                                      Polymer 42 (2001) 2907-2913. (equation 5)
8//
9//              see also: Hecht, Horkay, Geissler, PHYSICAL REVIEW E, VOLUME 64, 041402 (eqn 1)
10//
11// Steve Kline 14 JUL 2004 (for Robert Knott)
12// updated 6/2008
13//
14////////////////////////////////////////////////////
15
16//this macro sets up all the necessary parameters and waves that are
17//needed to calculate the model function.
18//
19Proc PlotGaussLorentzGel(num,qmin,qmax)
20        Variable num=256, qmin=.001, qmax=.7
21        Prompt num "Enter number of data points for model: "
22        Prompt qmin "Enter minimum q-value (A^1) for model: "
23        Prompt qmax "Enter maximum q-value (A^1) for model: "
24//
25        Make/O/D/n=(num) xwave_GL_Gel, ywave_GL_Gel
26        xwave_GL_Gel =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
27        Make/O/D coef_GL_Gel = {100,100,50,20,0}
28        make/o/t parameters_GL_Gel = {"Gauss Scale Factor, IG(0) ", "Static correlation Z (A)","Lorentzian Scale Factor IL(0)","Dynamic correlation z (A)","Incoherent Bgd (cm-1)"}
29        Edit parameters_GL_Gel, coef_GL_Gel
30        ModifyTable width(parameters_GL_Gel)=160
31       
32        Variable/G root:g_GL_Gel
33        g_GL_gel  := GaussLorentzGel(coef_GL_Gel, ywave_GL_Gel, xwave_GL_Gel)
34        Display ywave_GL_Gel vs xwave_GL_Gel
35        ModifyGraph log=1,marker=29, msize=2, mode=4
36        Label bottom "q (A\\S-1\\M) "
37        Label left "I(q) (cm\\S-1\\M)"
38        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
39       
40        AddModelToStrings("GaussLorentzGel","coef_GL_Gel","parameters_GL_Gel","GL_Gel")
41//
42End
43
44
45// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
46Proc PlotSmearedGaussLorentzGel(str)                                                           
47        String str
48        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
49       
50        // if any of the resolution waves are missing => abort
51        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
52                Abort
53        endif
54       
55        SetDataFolder $("root:"+str)
56       
57        // Setup parameter table for model function
58        Make/O/D smear_coef_GL_Gel = {100,100,50,20,0}
59        make/o/t smear_parameters_GL_Gel = {"Gauss Scale Factor, IG(0) ", "Static correlation Z (A)","Lorentzian Scale Factor IL(0)","Dynamic correlation z (A)","Incoherent Bgd (cm-1)"}       
60        Edit smear_parameters_GL_Gel,smear_coef_GL_Gel                                  //display parameters in a table
61        ModifyTable width(smear_parameters_GL_Gel)=160                         
62       
63        Duplicate/O $(str+"_q") smeared_GL_Gel,smeared_qvals
64        SetScale d,0,0,"1/cm",smeared_GL_Gel                                   
65               
66        Variable/G gs_GL_Gel=0
67        gs_GL_Gel := fSmearedGaussLorentzGel(smear_coef_GL_Gel,smeared_GL_Gel,smeared_qvals)    //this wrapper fills the STRUCT
68        Display smeared_GL_Gel vs smeared_qvals                                                         
69       
70        ModifyGraph log=1,marker=29,msize=2,mode=4
71        Label bottom "q (\\S-1\\M)"
72        Label left "Intensity (cm\\S-1\\M)"
73        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
74       
75        SetDataFolder root:
76        AddModelToStrings("SmearedGaussLorentzGel","smear_coef_GL_Gel","smear_parameters_GL_Gel","GL_Gel")
77End
78
79//AAO version, uses XOP if available
80// simply calls the original single point calculation with
81// a wave assignment (this will behave nicely if given point ranges)
82Function GaussLorentzGel(cw,yw,xw) : FitFunc
83        Wave cw,yw,xw
84       
85#if exists("GaussLorentzGelX")
86        yw = GaussLorentzGelX(cw,xw)
87#else
88        yw = fGaussLorentzGel(cw,xw)
89#endif
90        return(0)
91End
92
93//
94Function fGaussLorentzGel(w,x) : FitFunc
95        Wave w
96        Variable x
97//       Input (fitting) variables are:
98        //[0] Gaussian scale factor
99        //[1] Gaussian (static) screening length
100        //[2] Lorentzian (fluctuation) scale factor
101        //[3] Lorentzian screening length
102        //[4] incoherent background
103//      give them nice names
104        Variable Ig0,gg,Il0,ll,bgd
105        Ig0 = w[0]
106        gg = w[1]
107        Il0 = w[2]
108        ll = w[3]
109        bgd = w[4]
110       
111//      local variables
112        Variable inten
113
114        inten = Ig0*exp(-x*x*gg*gg/2) + Il0/(1 + (x*ll)^2) + bgd
115        Return (inten)
116End
117
118//
119Function fSmearedGaussLorentzGel(coefW,yW,xW)
120        Wave coefW,yW,xW
121       
122        String str = getWavesDataFolder(yW,0)
123        String DF="root:"+str+":"
124       
125        WAVE resW = $(DF+str+"_res")
126       
127        STRUCT ResSmearAAOStruct fs
128        WAVE fs.coefW = coefW           //is this the proper way to populate? seems redundant...
129        WAVE fs.yW = yW
130        WAVE fs.xW = xW
131        WAVE fs.resW = resW
132       
133        Variable err
134        err = SmearedGaussLorentzGel(fs)
135       
136        return (0)
137End
138
139// smeared calculation, AAO and using a structure...
140// defined as as STRUCT, there can never be a dependency linked directly to this function
141// - so set a dependency to the wrapper
142//
143// like the unsmeared function, AAO is equivalent to a wave assignment to the point calculation
144// - but now the function passed is an AAO function
145//
146// Smear_Model_20() takes care of what calculation is done, depending on the resolution information
147//
148//
149Function SmearedGaussLorentzGel(s) : FitFunc
150        Struct ResSmearAAOStruct &s
151
152////the name of your unsmeared model is the first argument
153        Smear_Model_20(GaussLorentzGel,s.coefW,s.xW,s.yW,s.resW)
154
155        return(0)
156End
Note: See TracBrowser for help on using the repository browser.