@@ -44,7 +44,6 @@ def camm_convolve(signal,response,mode='same'):
44
44
g = response [::- 1 ] # numpy convolve uses the definition of convolution of math textbooks, which does E --> -E
45
45
return convolve (signal ,g ,mode = mode )
46
46
47
-
48
47
def convolution (simulated , resolution , expdata , convolved , dak = None , norm2one = False ):
49
48
"""Convolve a simulated S(Q,E) with a resolution file
50
49
@@ -56,17 +55,30 @@ def convolution(simulated, resolution, expdata, convolved, dak=None, norm2one=Fa
56
55
Returns:
57
56
workspace for the convolution
58
57
"""
59
- from mantid .simpleapi import (LoadNexus , Rebin , ConvertToHistogram , NormaliseToUnity , SaveNexus , AddSampleLog )
58
+ from mantid .simpleapi import (LoadNexus , Rebin , ConvertToHistogram , NormaliseToUnity , SaveNexus , SaveAscii , AddSampleLog )
60
59
wss = LoadNexus (Filename = simulated ,OutputWorkspace = 'simulated' )
61
60
width = wss .readX (0 )[1 ]- wss .readX (0 )[0 ] # rebin resolution as simulated
62
61
wsr = LoadNexus (Filename = resolution ,OutputWorkspace = 'resolution' )
63
- wsr = Rebin (InputWorkspace = 'resolution' , Params = (wsr .readX (0 )[0 ], width , wsr .readX (0 )[- 1 ]), OutputWorkspace = 'resolution' )
62
+
63
+ #symmetrize the domain of the resolution function. Otherwise the
64
+ #convolution results in a function with its peak shifted from the origin
65
+ min = wsr .readX (0 )[0 ]
66
+ max = wsr .readX (0 )[- 1 ]
67
+ delta = min + max
68
+ if delta < 0 :
69
+ wsr = Rebin (wsr , Params = (- max ,width ,max ))
70
+ elif delta > 0 :
71
+ wsr = Rebin (wsr , Params = (min ,width ,- min ))
72
+ else :
73
+ wsr = Rebin (wsr , Params = (min ,width ,max ))
74
+
64
75
# convolve now, overwriting simulateds
65
76
for i in range (wss .getNumberHistograms ()):
66
77
v = wsr .readY (i )
67
78
w = wss .readY (i )
68
79
x = camm_convolve (w ,v ,mode = 'same' )
69
80
wss .setY (i ,x )
81
+
70
82
wse = LoadNexus (Filename = expdata ,OutputWorkspace = 'expdata' )
71
83
width = wse .readX (0 )[1 ]- wse .readX (0 )[0 ] # rebin simulated as expdata
72
84
Rebin (InputWorkspace = 'simulated' , Params = (wse .readX (0 )[0 ],width ,wse .readX (0 )[- 1 ]), OutputWorkspace = 'convolved' )
0 commit comments