Skip to content

Commit ceebe9f

Browse files
committed
Refs #30 Symmetrize resolution domain prior to convolution
1 parent 503fc90 commit ceebe9f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

simulation/src/beamline/convolve.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def camm_convolve(signal,response,mode='same'):
4444
g=response[::-1] # numpy convolve uses the definition of convolution of math textbooks, which does E --> -E
4545
return convolve(signal,g,mode=mode)
4646

47-
4847
def convolution(simulated, resolution, expdata, convolved, dak=None, norm2one=False):
4948
"""Convolve a simulated S(Q,E) with a resolution file
5049
@@ -56,17 +55,30 @@ def convolution(simulated, resolution, expdata, convolved, dak=None, norm2one=Fa
5655
Returns:
5756
workspace for the convolution
5857
"""
59-
from mantid.simpleapi import (LoadNexus, Rebin, ConvertToHistogram, NormaliseToUnity, SaveNexus, AddSampleLog)
58+
from mantid.simpleapi import (LoadNexus, Rebin, ConvertToHistogram, NormaliseToUnity, SaveNexus, SaveAscii, AddSampleLog)
6059
wss=LoadNexus(Filename=simulated,OutputWorkspace='simulated')
6160
width=wss.readX(0)[1]-wss.readX(0)[0] # rebin resolution as simulated
6261
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+
6475
# convolve now, overwriting simulateds
6576
for i in range(wss.getNumberHistograms()):
6677
v=wsr.readY(i)
6778
w=wss.readY(i)
6879
x=camm_convolve(w,v,mode='same')
6980
wss.setY(i,x)
81+
7082
wse=LoadNexus(Filename=expdata,OutputWorkspace='expdata')
7183
width=wse.readX(0)[1]-wse.readX(0)[0] # rebin simulated as expdata
7284
Rebin(InputWorkspace='simulated', Params=(wse.readX(0)[0],width,wse.readX(0)[-1]), OutputWorkspace='convolved')

0 commit comments

Comments
 (0)