source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/Peak_Lorentz_model.ipf @ 153

Last change on this file since 153 was 153, checked in by srkline, 15 years ago

Changed Plot* and PlotSmeared?* naming schemes to be all consistent prefixes for the actual function name, so that the macros can be constructed from the function name, or vice versa.

also some tweaks to the wrapper to make sure that plot and append really work

File size: 4.3 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
3
4////////////////////////////////////////////////////
5//      J. Barker, 2-10-99
6////////////////////////////////////
7Proc PlotPeak_Lorentz_Model(num,qmin,qmax)
8        Variable num=512, qmin=.001, qmax=.7
9        Prompt num "Enter number of data points for model: "
10        Prompt qmin "Enter minimum q-value (^1) for model: "
11         Prompt qmax "Enter maximum q-value (^1) for model: "
12//
13        Make/O/D/n=(num) xwave_Peak_Lorentz, ywave_Peak_Lorentz
14        xwave_Peak_Lorentz =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
15        Make/O/D coef_Peak_Lorentz = {100.0, 0.05,0.005, 1.0}
16        make/o/t parameters_Peak_Lorentz = {"Scale Factor, I0 ", "Peak position (^-1)", "Peak hwhm (^-1)","Incoherent Bgd (cm-1)"}
17        Edit parameters_Peak_Lorentz, coef_Peak_Lorentz
18        Variable/G root:g_Peak_Lorentz
19        g_Peak_Lorentz  := Peak_Lorentz_Model(coef_Peak_Lorentz, ywave_Peak_Lorentz,xwave_Peak_Lorentz)
20//      ywave_Peak_Lorentz  := Peak_Lorentz_Model(coef_Peak_Lorentz, xwave_Peak_Lorentz)
21        Display ywave_Peak_Lorentz vs xwave_Peak_Lorentz
22        ModifyGraph marker=29, msize=2, mode=4
23        ModifyGraph log(left)=1
24        Label bottom "q (\\S-1\\M) "
25        Label left "Peak - Lorentzian (cm\\S-1\\M)"
26        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
27//
28End
29
30////////////////////////////////////////////////////
31// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
32Proc PlotSmearedPeak_Lorentz_Model(str)                                                         
33        String str
34        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
35       
36        // if any of the resolution waves are missing => abort
37        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
38                Abort
39        endif
40       
41        SetDataFolder $("root:"+str)
42       
43        // Setup parameter table for model function
44        Make/O/D smear_coef_Peak_Lorentz = {100.0, 0.05,0.005, 1.0}
45        make/o/t smear_parameters_Peak_Lorentz = {"Scale Factor, I0 ", "Peak position (^-1)", "Peak hwhm (^-1)","Incoherent Bgd (cm-1)"}
46        Edit smear_parameters_Peak_Lorentz,smear_coef_Peak_Lorentz                                      //display parameters in a table
47       
48        // output smeared intensity wave, dimensions are identical to experimental QSIG values
49        // make extra copy of experimental q-values for easy plotting
50        Duplicate/O $(str+"_q") smeared_Peak_Lorentz,smeared_qvals                              //
51        SetScale d,0,0,"1/cm",smeared_Peak_Lorentz                                                      //                                     
52               
53        Variable/G gs_Peak_Lorentz=0
54        gs_Peak_Lorentz := fSmearedPeak_Lorentz_Model(smear_coef_Peak_Lorentz,smeared_Peak_Lorentz,smeared_qvals)       //this wrapper fills the STRUCT
55
56        Display smeared_Peak_Lorentz vs smeared_qvals                                                                   //
57        ModifyGraph log=1,marker=29,msize=2,mode=4
58        Label bottom "q (\\S-1\\M)"
59        Label left "Peak_Lorentz Model (cm\\S-1\\M)"
60        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) 
61       
62        SetDataFolder root:
63End
64
65
66//AAO version
67Function Peak_Lorentz_model(cw,yw,xw) : FitFunc
68        Wave cw,yw,xw
69
70#if exists("Peak_Lorentz_modelX")
71        yw = Peak_Lorentz_modelX(cw,xw)
72#else
73        yw = fPeak_Lorentz_model(cw,xw)
74#endif
75        return(0)
76End
77
78Function fPeak_Lorentz_model(w,x) : FitFunc
79        Wave w
80        Variable x
81//       Input (fitting) variables are:
82        //[0] scale factor
83        //[1] peak position
84        //[2] peak hwhm
85        //[3] incoherent background
86//      give them nice names
87        Variable I0, qpk, dq,bgd
88        I0 = w[0]
89        qpk = w[1]
90        dq = w[2]
91        bgd = w[3]
92       
93//      local variables
94        Variable inten, qval
95//      x is the q-value for the calculation
96        qval = x
97//      do the calculation and return the function value
98       
99        inten = I0/(1 + ((qval-qpk)/dq)^2) + bgd
100        Return (inten)
101End
102/////////////////////////////////////////////////////////////////////////////////
103
104// this is all there is to the smeared calculation!
105Function SmearedPeak_Lorentz_Model(s) :FitFunc
106        Struct ResSmearAAOStruct &s
107
108////the name of your unsmeared model is the first argument
109        Smear_Model_20(Peak_Lorentz_model,s.coefW,s.xW,s.yW,s.resW)
110
111        return(0)
112End
113
114//wrapper to calculate the smeared model as an AAO-Struct
115// fills the struct and calls the ususal function with the STRUCT parameter
116//
117// used only for the dependency, not for fitting
118//
119Function fSmearedPeak_Lorentz_Model(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   
129        WAVE fs.yW = yW
130        WAVE fs.xW = xW
131        WAVE fs.resW = resW
132       
133        Variable err
134        err = SmearedPeak_Lorentz_Model(fs)
135       
136        return (0)
137End
Note: See TracBrowser for help on using the repository browser.