Skip to content
Snippets Groups Projects
Commit 27388d75 authored by Gagik Vardanyan's avatar Gagik Vardanyan
Browse files

Re #24109 dead time and parallax corrections

parent c53e438f
No related branches found
No related tags found
No related merge requests found
......@@ -197,11 +197,22 @@ class SANSILLReduction(PythonAlgorithm):
duration = mtd[ws].getRun().getLogData('timer').value
if duration != 0.:
Scale(InputWorkspace=ws, Factor=1./duration, OutputWorkspace=ws)
self._dead_time_correction(ws)
else:
raise RuntimeError('Unable to normalise to time; duration found is 0 seconds.')
else:
raise RuntimeError('Normalise to timer requested, but timer information is not available.')
def _dead_time_correction(self, ws):
run = mtd[ws].getRun()
if run.hasParameter('tau'):
tau = run.getNumberParameter('tau')[0]
DeadTimeCorrection(InputWorkspace=ws, Tau=tau, OutputWorkspace=ws)
else:
self.log().information('No tau available in IPF, skipping dead time correction.')
def _process_beam(self, ws):
"""
Calculates the beam center's x,y coordinates, and the beam flux
......@@ -248,25 +259,13 @@ class SANSILLReduction(PythonAlgorithm):
def _check_processed_flag(ws, value):
return ws.getRun().getLogData('ProcessedAs').value == value
@staticmethod
def _parallax_correction(ws):
formula = ws.getInstrument().getStringParameter('parallax_old')[0]
l2 = ws.getRun().getLogData('L2').value
n_spectra = ws.getNumberHistograms()
p = np.empty(n_spectra)
for i in range(n_spectra):
d = ws.getDetector(i).getPos()
p[i] = np.arctan(d[0]/l2)
parallax_ws = ws.getName() + '_parallax'
parallax_ws = CreateWorkspace(NSpec=n_spectra, DataY=eval(formula), DataX=ws.extractX(), ParentWorkspace=ws, StoreInADS=False)
Divide(LHSWorkspace=ws, RHSWorkspace=parallax_ws, OutputWorkspace=ws.getName())
def PyExec(self): # noqa: C901
process = self.getPropertyValue('ProcessAs')
ws = '__' + self.getPropertyValue('OutputWorkspace')
LoadAndMerge(Filename=self.getPropertyValue('Run').replace(',','+'), LoaderName='LoadILLSANS', OutputWorkspace=ws)
self._normalise(ws)
ExtractMonitors(InputWorkspace=ws, DetectorWorkspace=ws)
instrument = mtd[ws].getInstrument().getName()
if process in ['Beam', 'Transmission', 'Container', 'Reference', 'Sample']:
absorber_ws = self.getProperty('AbsorberInputWorkspace').value
if absorber_ws:
......@@ -342,10 +341,13 @@ class SANSILLReduction(PythonAlgorithm):
thickness = self.getProperty('SampleThickness').value
NormaliseByThickness(InputWorkspace=ws, OutputWorkspace=ws, SampleThickness=thickness)
# parallax (gondola) effect
if mtd[ws].getInstrument().hasParameter('parallax_old'):
# for the moment it's only D22 that has this
if instrument in ['D22', 'D22lr', 'D33']:
self.log().information('Performing parallax correction')
self._parallax_correction(mtd[ws])
if instrument == 'D33':
components = ['back_detector', 'front_detector_top', 'front_detector_bottom', 'front_detector_left', 'front_detector_right']
else:
components = ['detector']
ParallaxCorrection(InputWorkspace=ws, OutputWorkspace=ws, ComponentNames=components)
if process == 'Reference':
sensitivity_out = self.getPropertyValue('SensitivityOutputWorkspace')
if sensitivity_out:
......@@ -386,7 +388,7 @@ class SANSILLReduction(PythonAlgorithm):
ReplaceSpecialValues(InputWorkspace=ws, OutputWorkspace=ws,
NaNValue=0., NaNError=0., InfinityValue=0., InfinityError=0.)
if process != 'Transmission':
if mtd[ws].getInstrument().getName() == 'D33':
if instrument == 'D33':
CalculateDynamicRange(Workspace=ws, ComponentNames=['back_detector', 'front_detector'])
else:
CalculateDynamicRange(Workspace=ws)
......
<?xml version="1.0" encoding="UTF-8"?>
<parameter-file instrument = "D11">
<!-- Tau coefficient for DeadTimeCorrection, to be applied for the entire detector -->
<component-link name="D11">
<parameter name="tau" type="number">
<value val="0.00000042" />
</parameter>
</component-link>
</component-link>
</parameter-file>
<?xml version="1.0" encoding="UTF-8"?>
<parameter-file instrument = "D11lr">
<!-- Tau coefficient for DeadTimeCorrection, to be applied for the entire detector -->
<component-link name="D11lr">
<parameter name="tau" type="number">
<value val="0.00000042" />
</parameter>
</component-link>
</component-link>
</parameter-file>
......@@ -2,19 +2,11 @@
<parameter-file instrument = "D22" valid-from="2017-10-01 23:59:59">
<!-- This should be removed when the new way of correction is in the workflow-->
<!-- Tau coefficient for DeadTimeCorrection, to be applied tube by tube -->
<component-link name="D22">
<!-- This is the formula to model the theta dependency of the
detector sensitivities because of varying path lengths in the
detector volume. This is evaluated with python eval.
Note that the np stands for the numpy, p must be the parallax:
p = arctan(x/l2) [in radians], where x is the coordinate of the
detector pixel, l2 is the sample to detector distance. -->
<parameter name="parallax_old" type="string">
<value val="1+0.14*np.exp(-4*np.log(2.)*((np.abs(p)-0.588)/0.414)**2)"/>
<parameter name="tau" type="number">
<value val="0.0000015" />
</parameter>
</component-link>
<!-- These parameters are used in ParallaxCorrection algorithm -->
......
<?xml version="1.0" encoding="UTF-8"?>
<parameter-file instrument = "D22lr" valid-from="2017-10-01 23:59:59">
<!-- This should be removed when the new way of correction is in the workflow-->
<!-- Tau coefficient for DeadTimeCorrection, to be applied tube by tube -->
<component-link name="D22lr">
<!-- This is the formula to model the theta dependency of the
detector sensitivities because of varying path lengths in the
detector volume. This is evaluated with python eval.
Note that the np stands for the numpy, p must be the parallax:
p = arctan(x/l2) [in radians], where x is the coordinate of the
detector pixel, l2 is the sample to detector distance. -->
<parameter name="parallax_old" type="string">
<value val="1+0.14*np.exp(-4*np.log(2.)*((np.abs(p)-0.588)/0.414)**2)"/>
<parameter name="tau" type="number">
<value val="0.0000015" />
</parameter>
</component-link>
<!-- These parameters are used in ParallaxCorrection algorithm -->
......
<?xml version="1.0" encoding="UTF-8"?>
<parameter-file instrument = "D33" valid-from = "20th May 2010">
<!-- Tau coefficient for DeadTimeCorrection, to be applied tube by tube -->
<component-link name="D33">
<parameter name="tau" type="number">
<value val="0.0000015" />
</parameter>
</component-link>
<!-- These parameters are used in ParallaxCorrection algorithm -->
<component-link name="back_detector">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment