diff --git a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DirectILLReduction.py b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DirectILLReduction.py index 55bd25376e74a55ba6657e29e632f7ec7f3fd964..235ca49bc041283aa3df735c1a7dd67a849adfd4 100644 --- a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DirectILLReduction.py +++ b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DirectILLReduction.py @@ -6,8 +6,9 @@ import DirectILL_common as common from mantid.api import (AlgorithmFactory, DataProcessorAlgorithm, InstrumentValidator, MatrixWorkspaceProperty, Progress, PropertyMode, WorkspaceProperty, WorkspaceUnitValidator) from mantid.kernel import (CompositeValidator, Direction, FloatArrayProperty, StringListValidator) -from mantid.simpleapi import (BinWidthAtX, CloneWorkspace, ConvertSpectrumAxis, ConvertUnits, CorrectKiKf, DetectorEfficiencyCorUser, - Divide, GroupDetectors, MaskDetectors, Rebin, Scale, SofQWNormalisedPolygon, Transpose) +from mantid.simpleapi import (BinWidthAtX, CloneWorkspace, ConvertSpectrumAxis, ConvertToDistribution, ConvertUnits, CorrectKiKf, + DetectorEfficiencyCorUser, Divide, GroupDetectors, MaskDetectors, Rebin, Scale, SofQWNormalisedPolygon, + Transpose) import math import numpy import roundinghelper @@ -225,6 +226,9 @@ class DirectILLReduction(DataProcessorAlgorithm): mainWS = self._rebinInW(mainWS, wsNames, wsCleanup, report, subalgLogging) + # Divide the energy transfer workspace by bin widths. + mainWS = self._convertToDistribution(mainWS, wsNames, wsCleanup, subalgLogging) + # Detector efficiency correction. progress.report('Correcting detector efficiency') mainWS = self._correctByDetectorEfficiency(mainWS, wsNames, @@ -340,6 +344,17 @@ class DirectILLReduction(DataProcessorAlgorithm): wsCleanup.cleanup(mainWS) return maskedWS + def _convertToDistribution(self, mainWS, wsNames, wsCleanup, subalgLogging): + """Convert the workspace into a distribution.""" + distributionWSName = wsNames.withSuffix('as_distribution') + distributionWS = CloneWorkspace(InputWorkspace=mainWS, + OutputWorkspace=distributionWSName, + EnableLogging=subalgLogging) + wsCleanup.cleanup(mainWS) + ConvertToDistribution(Workspace=distributionWS, + EnableLogging=subalgLogging) + return distributionWS + def _convertTOFToDeltaE(self, mainWS, wsNames, wsCleanup, subalgLogging): """Convert the X axis units from time-of-flight to energy transfer.""" energyConvertedWSName = wsNames.withSuffix('energy_converted') diff --git a/Framework/PythonInterface/test/python/plugins/algorithms/WorkflowAlgorithms/DirectILLReductionTest.py b/Framework/PythonInterface/test/python/plugins/algorithms/WorkflowAlgorithms/DirectILLReductionTest.py index 98aedfce8148d40eed5cab7e4a0b3f68a3f0a4ab..b334ad1437bbefc68c31b17ab6b6fbd4b870e36f 100644 --- a/Framework/PythonInterface/test/python/plugins/algorithms/WorkflowAlgorithms/DirectILLReductionTest.py +++ b/Framework/PythonInterface/test/python/plugins/algorithms/WorkflowAlgorithms/DirectILLReductionTest.py @@ -78,6 +78,22 @@ class DirectILLReductionTest(unittest.TestCase): groupIds = groupedWS.getDetector(0).getDetectorIDs() self.assertEqual(collections.Counter(detectorIds), collections.Counter(groupIds)) + def testOutputIsDistribution(self): + outWSName = 'outWS' + algProperties = { + 'InputWorkspace': self._TEST_WS_NAME, + 'OutputWorkspace': outWSName, + 'OutputSofThetaEnergyWorkspace': 'SofThetaE', + 'rethrow': True + } + run_algorithm('DirectILLReduction', **algProperties) + self.assertTrue(mtd.doesExist(outWSName)) + ws = mtd[outWSName] + self.assertTrue(ws.isDistribution()) + self.assertTrue(mtd.doesExist('SofThetaE')) + ws = mtd['SofThetaE'] + self.assertTrue(ws.isDistribution()) + def _checkAlgorithmsInHistory(self, ws, *args): """Return true if algorithm names listed in *args are found in the workspace's history. diff --git a/docs/source/diagrams/DirectILLReduction-v1_wkflw.dot b/docs/source/diagrams/DirectILLReduction-v1_wkflw.dot index 6a91ffb61d548a16f3c732297b58f17718a10d7e..f0b26f2e3987a8db84e06e71ef151a3d49ac3b65 100644 --- a/docs/source/diagrams/DirectILLReduction-v1_wkflw.dot +++ b/docs/source/diagrams/DirectILLReduction-v1_wkflw.dot @@ -23,6 +23,7 @@ digraph DirectILLReduction { $algorithm_style AbsoluteUnits [label="Scale to absolute units"] ApplyDiagnostics [label="Mask spectra"] + ConvertToDistribution [label="ConvertToDistribution"] ConvertToEnergy [label="Convert TOF to energy transfer"] CorrectKiKf [label="CorrectKiKf"] DetectorEfficiency [label="DetectorEfficiencyCorUser"] @@ -49,7 +50,8 @@ digraph DirectILLReduction { ConvertToEnergy -> CorrectKiKf CorrectKiKf -> Rebin wRebinParams -> Rebin - Rebin -> DetectorEfficiency + Rebin -> ConvertToDistribution + ConvertToDistribution -> DetectorEfficiency DetectorEfficiency -> GroupDetectors GroupDetectors -> outputOptionalWS GroupDetectors -> SofQW diff --git a/docs/source/release/v3.13.0/direct_inelastic.rst b/docs/source/release/v3.13.0/direct_inelastic.rst index 0f58f2e7d58ad279585b97c313a140b9a8319717..91c137c8a0778a8e763669435171e69452e9d301 100644 --- a/docs/source/release/v3.13.0/direct_inelastic.rst +++ b/docs/source/release/v3.13.0/direct_inelastic.rst @@ -20,6 +20,8 @@ New features Improvements ############ +- :ref:`DirectILLReduction <algm-DirectILLReduction>` now converts all its output workspaces to distributions, i.e. divides the histograms by the bin width. + Bug fixes #########