1 | # load some data |
---|
2 | Load(r'MUSR00015189.nxs',OutputWorkspace='musr') |
---|
3 | # use first workspace in the group |
---|
4 | inputWS = 'musr_1' |
---|
5 | # rebin to remove negative values causing problems |
---|
6 | musr_1 = Rebin('musr_1','0.5,0.1,30') |
---|
7 | # |
---|
8 | musr_2 = Rebin('musr_2','0.5,0.1,30') |
---|
9 | musr_2 *= 2 |
---|
10 | musr_3 = Rebin('musr_2','0.5,0.1,30') |
---|
11 | musr_3 *= 1.5 |
---|
12 | workspaces = ['musr_1','musr_2','musr_3'] |
---|
13 | # we will fit 3 spectra simultaneously: one from each workspace |
---|
14 | nHist = 3 |
---|
15 | outNm = 'output' |
---|
16 | # template for function to fit each spectrum |
---|
17 | # the $ sign means that the attribute is to be passed to the parent composite function along with this function's index |
---|
18 | f1 = """( |
---|
19 | composite=CompositeFunction,$domains=i; |
---|
20 | name=LinearBackground,A0=0,A1=0,ties=(A1=0); |
---|
21 | name=UserFunction,Formula=Intensity*exp(-(x/Tau)^Beta),Intensity=1000.0,Tau=2,Beta=1 |
---|
22 | ); |
---|
23 | """ |
---|
24 | # top-level function is MultiDomainFunction |
---|
25 | # ensure that numerical derivatives are used |
---|
26 | func= 'composite=MultiDomainFunction,NumDeriv=1;' |
---|
27 | # to tie all Betas together |
---|
28 | ties='ties=(' |
---|
29 | # collect properties to specify additional spectra |
---|
30 | kwargs = {} |
---|
31 | for i in range(0,nHist): |
---|
32 | # for each spectrum add its function |
---|
33 | func+=f1 |
---|
34 | if i > 0: |
---|
35 | # tie f1.f1.Beta = f2.f1.Beta = f0.f1.Beta |
---|
36 | ties += 'f' + str(i) + '.f1.Beta=f0.f1.Beta' |
---|
37 | if i < nHist-1: |
---|
38 | ties += ',' |
---|
39 | # workspace name and spectrum index for the last two spectra |
---|
40 | kwargs['InputWorkspace_' + str(i)] = workspaces[i] |
---|
41 | kwargs['WorkspaceIndex_' + str(i)] = i |
---|
42 | |
---|
43 | ties+=')' |
---|
44 | # ties applied at MultiDomainFunction's level |
---|
45 | func += ties |
---|
46 | logger.notice(func) |
---|
47 | logger.notice(str(kwargs)) |
---|
48 | # do the fit |
---|
49 | Fit(Function=func,InputWorkspace=workspaces[0],WorkspaceIndex=0,Output=outNm,Minimizer='Levenberg-MarquardtMD,Debug=1',**kwargs) |
---|