Skip to content

Commit

Permalink
Modified messages display and change the way the tof is calcualted. T…
Browse files Browse the repository at this point in the history
…his refs #4303
  • Loading branch information
JeanBilheux committed Mar 8, 2012
1 parent fad5cf8 commit 0d739ab
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
27 changes: 23 additions & 4 deletions Code/Mantid/Framework/PythonAPI/PythonAlgorithms/RefLReduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def PyExec(self):
NormFlag = self.getProperty("NormFlag")

normalization_run = self.getProperty("NormalizationRunNumber")


print '** Working with data runs: ' + str(run_numbers)
data_peak = self.getProperty("SignalPeakPixelRange")
data_back = self.getProperty("SignalBackgroundPixelRange")

Expand Down Expand Up @@ -98,7 +99,6 @@ def PyExec(self):
subtract_norm_bck = self.getProperty("SubtractNormBackground")

#name of the sfCalculator txt file
# sfCalculatorPath = "/home/j35/Desktop/"
slitsValuePrecision = 0.1 #precision of slits = 10%

# Pick a good workspace n ame
Expand Down Expand Up @@ -158,16 +158,20 @@ def PyExec(self):
to_units='rad')

# Rebin data (x-axis is in TOF)
print '-> Rebin'
ws_histo_data = "_"+ws_name+"_histo"
Rebin(InputWorkspace=ws_event_data, OutputWorkspace=ws_histo_data,
Rebin(InputWorkspace=ws_event_data,
OutputWorkspace=ws_histo_data,
Params=[TOFrange[0],
TOFsteps,
TOFrange[1]])

# Keep only range of TOF of interest
print '-> Crop TOF range'
CropWorkspace(ws_histo_data,ws_histo_data,XMin=TOFrange[0], XMax=TOFrange[1])

# Normalized by Current (proton charge)
print '-> Normalize by proton charge'
NormaliseByCurrent(InputWorkspace=ws_histo_data, OutputWorkspace=ws_histo_data)

# Calculation of the central pixel (using weighted average)
Expand All @@ -186,6 +190,7 @@ def PyExec(self):
start_pixel = start_pixel + 1
_den += pixelXtof_roi[i]
data_cpix = _num / _den
print '-> Central pixel is {0:.1f}'.format(data_cpix)

# Retrieve geometry of instrument
# Sample-to-detector distance
Expand Down Expand Up @@ -214,6 +219,7 @@ def PyExec(self):
# background range (along the y-axis) and of only the pixel
# of interest along the x-axis (to avoid the frame effect)
ws_integrated_data = "_IntegratedDataWks"
print '-> keep only range of pixel of interest'
wks_utility.createIntegratedWorkspace(mtd[ws_histo_data],
ws_integrated_data,
fromXpixel=Xrange[0],
Expand All @@ -227,6 +233,7 @@ def PyExec(self):
ws_transposed = '_TransposedID'
if subtract_data_bck:

print '-> substract background'
ConvertToHistogram(InputWorkspace=ws_integrated_data,
OutputWorkspace=ws_integrated_data)

Expand Down Expand Up @@ -288,6 +295,7 @@ def PyExec(self):

if (NormFlag):

print '-> normalization file is ' + str(normalization_run)
# Find full path to event NeXus data file
f = FileFinder.findRuns("REF_L%d" %normalization_run)
if len(f)>0 and os.path.isfile(f[0]):
Expand All @@ -307,6 +315,7 @@ def PyExec(self):
OutputWorkspace=ws_norm_event_data)

# Rebin data
print '-> rebin normalization'
Rebin(InputWorkspace=ws_norm_event_data,
OutputWorkspace=ws_norm_histo_data,
Params=[TOFrange[0],
Expand All @@ -319,6 +328,7 @@ def PyExec(self):
XMin=TOFrange[0], XMax=TOFrange[1])

# Normalized by Current (proton charge)
print '-> normalized by current direct beam'
NormaliseByCurrent(InputWorkspace=ws_norm_histo_data,
OutputWorkspace=ws_norm_histo_data)

Expand All @@ -337,6 +347,8 @@ def PyExec(self):

ws_data_bck = "_NormBckWks"
if subtract_norm_bck:

print '-> substract background to direct beam'
Transpose(InputWorkspace=ws_integrated_data,
OutputWorkspace=ws_transposed)

Expand Down Expand Up @@ -406,11 +418,13 @@ def PyExec(self):
OutputWorkspace=ws_norm_rebinned)


#Normalization
#Normalization
print '-> Sum spectra'
SumSpectra(InputWorkspace=ws_norm_rebinned,
OutputWorkspace=ws_norm_rebinned)

#### divide data by normalize histo workspace
print '-> Divide data by direct beam'
Divide(LHSWorkspace=ws_data,
RHSWorkspace=ws_norm_rebinned,
OutputWorkspace=ws_data)
Expand All @@ -424,6 +438,7 @@ def PyExec(self):
theta += AngleOffset_rad

# this is where we need to apply the scaling factor
print '-> Apply SF'
ws_data_scaled = wks_utility.applySF(ws_data,
slitsValuePrecision)

Expand All @@ -442,6 +457,7 @@ def PyExec(self):
q_max = max(_q_axis)

ws_data_Q = ws_data + '_Q'
print '-> convert to Q'
wks_utility.convertWorkspaceToQ(ws_data_scaled,
ws_data_Q,
fromYpixel=data_peak[0],
Expand Down Expand Up @@ -492,5 +508,8 @@ def PyExec(self):
UnitX="MomentumTransfer")

self.setProperty("OutputWorkspace", mtd[output_ws])

#space
print

mtd.registerPyAlgorithm(RefLReduction())
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,6 @@ def _convertToRvsQ(_tof_axis,

return q_array




def convertToRvsQ(dMD= -1, theta= -1, tof=None):
"""
This function converts the pixel/TOF array to the R(Q) array
Expand Down Expand Up @@ -606,10 +603,10 @@ def convertToRvsQWithCorrection(mt, dMD= -1, theta= -1, tof=None, yrange=None, c

for t in range(sz_tof - 1):
tof1 = tof[t]
# tof2 = tof[t+1]
# tofm = (tof1+tof2)/2.
# _Q = _const * math.sin(_theta) / (tofm*1e-6)
_Q = _const * math.sin(_theta) / (tof1 * 1e-6)
tof2 = tof[t+1]
tofm = (tof1+tof2)/2.
_Q = _const * math.sin(_theta) / (tofm*1e-6)
# _Q = _const * math.sin(_theta) / (tof1 * 1e-6)
q_array[y, t] = _Q * 1e-10

return q_array
Expand Down Expand Up @@ -751,7 +748,6 @@ def ref_beamdiv_correct(cpix, mt, det_secondary,
int_poly_y,
len(int_poly_x) - 2)


center_of_mass = calc_center_of_mass(int_poly_x,
int_poly_y,
area)
Expand Down Expand Up @@ -798,13 +794,12 @@ def applySF(InputWorkspace,
file created by the sfCalculator procedure
"""

print 'Apply SF'
#retrieve the lambdaRequested and check if we can find the sfCalculator
#file corresponding to that lambda
_lr = getLambdaValue(mtd[InputWorkspace])
_lr_value = _lr[0]
_lr_value = float("{0:.2f}".format(_lr_value))
print '-> Lambda Requested: {0:2f}'.format(_lr_value)
print '--> Lambda Requested: {0:2f}'.format(_lr_value)
delta_range = 0.05
# print '-> using delta range: {0:2f}'.format(delta_range)
list_of_delta = _lr_value + 0.01 * (numpy.arange(11) - 5)
Expand All @@ -817,13 +812,11 @@ def applySF(InputWorkspace,
_sfCalculatorFileFullPath = FileFinder.getFullPath(_sfCalculatorFile)
if (os.path.isfile(_sfCalculatorFileFullPath)):
sfCalculatorFile = _sfCalculatorFileFullPath
print '-> File ' + _sfCalculatorFile + ' ... FOUND and will be used'
print '--> File ' + _sfCalculatorFile + ' ... FOUND and will be used'
break
# else:
# print '--> File ' + _sfCalculatorFile + ' ... NOT FOUND'



if (sfCalculatorFile is not None):

#parse file and put info into array
Expand All @@ -844,9 +837,6 @@ def applySF(InputWorkspace,
s1h_value = s1h[0]
s2h_value = s2h[0]

# print 's1h_value={0:f}'.format(s1h_value)
# print 's2h_value={0:f}'.format(s2h_value)

#locate the row with s1h and s2h having the right value
s1h_precision = slitsValuePrecision * s1h_value
s1h_value_low = s1h_value - s1h_precision
Expand All @@ -857,13 +847,9 @@ def applySF(InputWorkspace,
s2h_value_high = s2h_value + s2h_precision

for i in range(nbr_row):
_s1h_table_value = sfFactorTable[i][0]
_s2h_table_value = sfFactorTable[i][1]

### just for testing REMOVE_ME
#_s1h_table_value = s1h_value_low
#_s2h_table_value = s2h_value_low
#### end of just testing REMOVE_ME

_s1h_table_value = float(sfFactorTable[i][0])
_s2h_table_value = float(sfFactorTable[i][1])

if (_s1h_table_value >= s1h_value_low and
_s1h_table_value <= s1h_value_high and
Expand Down Expand Up @@ -912,6 +898,11 @@ def _applySFtoArray(workspace, a, b, a_error, b_error):
Nspec=1,
UnitX="TOF")

mt_before = mtd[workspace]

Divide(workspace, 'sfWorkspace', workspace)

mt_after = mtd[workspace]

return workspace

0 comments on commit 0d739ab

Please sign in to comment.