diff --git a/Testing/SystemTests/tests/framework/ISIS_PowderOsirisTest.py b/Testing/SystemTests/tests/framework/ISIS_PowderOsirisTest.py index 96fa1b678405..227cd4f36b46 100644 --- a/Testing/SystemTests/tests/framework/ISIS_PowderOsirisTest.py +++ b/Testing/SystemTests/tests/framework/ISIS_PowderOsirisTest.py @@ -54,6 +54,9 @@ def run_diffraction_focusing( sample_details=None, paalman_pings_events_per_point=None, simple_events_per_point=None, + neutron_paths_multiple=None, + neutron_paths_single=None, + multiple_scattering=False, ): sample_runs = sample_runs # Choose full drange set in the cycle 1_1 @@ -78,6 +81,9 @@ def run_diffraction_focusing( empty_can_subtraction_method=empty_can_subtraction_method, paalman_pings_events_per_point=paalman_pings_events_per_point, simple_events_per_point=simple_events_per_point, + neutron_paths_multiple=neutron_paths_multiple, + neutron_paths_single=neutron_paths_single, + multiple_scattering=multiple_scattering, ) focussed_rel_path = os.path.join("1_1", user_name, output_file) @@ -103,6 +109,14 @@ def setup_inst_object(user_name, with_container=False): return inst_obj +def setup_sample_details(): + sample_details = SampleDetails(radius=1.1, height=8, center=[0, 0, 0], shape="cylinder") + sample_details.set_material(chemical_formula="Cr2-Ga-N", number_density=0.02) + sample_details.set_container(chemical_formula="Al", mass_density=2.71, radius=1.2) + + return sample_details + + def _try_delete(path): try: # Use this instead of os.remove as we could be passed a non-empty dir @@ -194,18 +208,14 @@ def skipTests(self): class OSIRISDiffractionFocusingWithSimpleAbsorptionCorrection(_OSIRISDiffractionFocusingTest): refrence_ws_name = "OSI120032_d_spacing_simple_corrected.nxs" required_run_files = [ - "OSI82717.nxs", - "OSI82718.nxs", # empty can + "OSI82717.nxs", # empty can "OSIRIS00119963.nxs", - "OSIRIS00119964.nxs", # van - "OSIRIS00120032.nxs", + "OSIRIS00120032.nxs", # van ] def runTest(self): super().runPreTest() - sample_details = SampleDetails(radius=1.1, height=8, center=[0, 0, 0], shape="cylinder") - sample_details.set_material(chemical_formula="Cr2-Ga-N", number_density=10.0) - sample_details.set_container(chemical_formula="Al", number_density=2.7, radius=1.2) + sample_details = setup_sample_details() self.results = run_diffraction_focusing( "120032", @@ -224,9 +234,7 @@ def skipTests(self): class OSIRISDiffractionFocusingWithPaalmanPingsAbsorptionCorrection(_OSIRISDiffractionFocusingTest): refrence_ws_name = "OSI120032_d_spacing_paalman_corrected.nxs" required_run_files = [ - "OSI82717.nxs", "OSI82718.nxs", # empty can - "OSIRIS00119963.nxs", "OSIRIS00119964.nxs", # van "OSIRIS00120032.nxs", ] @@ -235,9 +243,7 @@ def runTest(self): self.tolerance = 1e-8 self.tolerance_is_rel_err = True super().runPreTest() - sample_details = SampleDetails(radius=1.1, height=8, center=[0, 0, 0], shape="cylinder") - sample_details.set_material(chemical_formula="Cr2-Ga-N", number_density=10.0) - sample_details.set_container(chemical_formula="Al", number_density=2.7, radius=1.2) + sample_details = setup_sample_details() self.results = run_diffraction_focusing( "120032", @@ -251,3 +257,36 @@ def runTest(self): def skipTests(self): return False + + +class OSIRISDiffractionFocusingWithMultipleScattering(_OSIRISDiffractionFocusingTest): + refrence_ws_name = "OSI120032_d_multiple_scattering_corrected.nxs" + required_run_files = [ + "OSI82717.nxs", + "OSI82718.nxs", # empty can + "OSIRIS00119963.nxs", + "OSIRIS00119964.nxs", # van + "OSIRIS00120032.nxs", + ] + + def runTest(self): + super().runPreTest() + sample_details = setup_sample_details() + + self.results = run_diffraction_focusing( + "120032", + "Test_Multiple_Scattering", + "OSI120032_d_spacing.nxs", + absorb_corrections=True, + empty_can_subtraction_method="Simple", + sample_details=sample_details, + multiple_scattering=True, + simple_events_per_point=100, + neutron_paths_single=5, + neutron_paths_multiple=5, + ) + + mantid.SaveNexus(InputWorkspace=self.results, Filename=r"C:\Users\joy22959\Documents\test\multiscatt") + + def skipTests(self): + return False diff --git a/Testing/SystemTests/tests/framework/reference/OSI120032_d_multiple_scattering_corrected.nxs.md5 b/Testing/SystemTests/tests/framework/reference/OSI120032_d_multiple_scattering_corrected.nxs.md5 new file mode 100644 index 000000000000..d6bff7540156 --- /dev/null +++ b/Testing/SystemTests/tests/framework/reference/OSI120032_d_multiple_scattering_corrected.nxs.md5 @@ -0,0 +1 @@ +534b1473c5f9827fec49e90563e7905c \ No newline at end of file diff --git a/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_paalman_corrected.nxs.md5 b/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_paalman_corrected.nxs.md5 index 72d6a21cc591..20e122f43a36 100644 --- a/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_paalman_corrected.nxs.md5 +++ b/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_paalman_corrected.nxs.md5 @@ -1 +1 @@ -73a30dc9bf46d636b47974003819f4cc \ No newline at end of file +e4f663f1311e30a217701e9f03acb5d3 \ No newline at end of file diff --git a/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_simple_corrected.nxs.md5 b/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_simple_corrected.nxs.md5 index ae39c85bdafe..f6abebcb66c9 100644 --- a/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_simple_corrected.nxs.md5 +++ b/Testing/SystemTests/tests/framework/reference/OSI120032_d_spacing_simple_corrected.nxs.md5 @@ -1 +1 @@ -994ad405b8b6fe3763a0b4bc313420bc \ No newline at end of file +409654effe6096a197d437a4cc7d3f92 \ No newline at end of file diff --git a/scripts/Diffraction/isis_powder/osiris.py b/scripts/Diffraction/isis_powder/osiris.py index 495d6309af2c..1994f5258a5a 100644 --- a/scripts/Diffraction/isis_powder/osiris.py +++ b/scripts/Diffraction/isis_powder/osiris.py @@ -189,6 +189,9 @@ def _apply_absorb_corrections(self, run_details, ws_to_correct): else: events_per_point = 1000 + if self._sample_details is None: + raise TypeError("To apply absorption correction you need to supply `sample_details` using `set_sample_details` method") + container_geometry = self._sample_details.generate_container_geometry() container_material = self._sample_details.generate_container_material() if container_geometry and container_material: @@ -221,6 +224,9 @@ def _apply_absorb_corrections(self, run_details, ws_to_correct): ws_to_correct = ws_to_correct / corrections + if self._inst_settings.multiple_scattering: + ws_to_correct = self._apply_discus_multiple_scattering(ws_to_correct) + if previous_units != ws_units.wavelength: ws_to_correct = mantid.ConvertUnits( InputWorkspace=ws_to_correct, @@ -244,13 +250,47 @@ def _apply_paalmanpings_absorb_and_subtract_empty(self, workspace, summed_empty, :return: The corrected workspace. """ mantid.SetInstrumentParameter(Workspace=workspace, ParameterName="deltaE-mode", Value="Elastic") - return absorb_corrections.apply_paalmanpings_absorb_and_subtract_empty( + paalman_corrected = absorb_corrections.apply_paalmanpings_absorb_and_subtract_empty( workspace=workspace, summed_empty=summed_empty, sample_details=sample_details, paalman_pings_events_per_point=paalman_pings_events_per_point, ) + if self._inst_settings.multiple_scattering: + return self._apply_discus_multiple_scattering(paalman_corrected) + + return paalman_corrected + + def _apply_discus_multiple_scattering(self, ws_to_correct): + if self._inst_settings.neutron_paths_single: + neutron_paths_single = int(self._inst_settings.neutron_paths_single) + else: + neutron_paths_single = 100 + + if self._inst_settings.neutron_paths_multiple: + neutron_paths_multiple = int(self._inst_settings.neutron_paths_multiple) + else: + neutron_paths_multiple = 100 + + X = [1.0] + Y = [1.0] + Sofq_isotropic = mantid.CreateWorkspace(DataX=X, DataY=Y, UnitX="MomentumTransfer") + + ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, OutputWorkspace=ws_to_correct, Target="Momentum") + + mantid.DiscusMultipleScatteringCorrection( + InputWorkspace=ws_to_correct, + StructureFactorWorkspace=Sofq_isotropic, + NeutronPathsSingle=neutron_paths_single, + NeutronPathsMultiple=neutron_paths_multiple, + OutputWorkspace="MSResults", + ) + + ratio = mantid.mtd["MSResults_Ratio_Single_To_All"] + + return ws_to_correct * ratio + def apply_drange_cropping(self, run_number_string, focused_ws): """ Applies dspacing range cropping to a focused workspace. diff --git a/scripts/Diffraction/isis_powder/osiris_routines/osiris_param_mapping.py b/scripts/Diffraction/isis_powder/osiris_routines/osiris_param_mapping.py index b0e37c592cf6..f05d792b56f4 100644 --- a/scripts/Diffraction/isis_powder/osiris_routines/osiris_param_mapping.py +++ b/scripts/Diffraction/isis_powder/osiris_routines/osiris_param_mapping.py @@ -36,5 +36,8 @@ ), ParamMapEntry(ext_name="paalman_pings_events_per_point", int_name="paalman_pings_events_per_point", optional=True), ParamMapEntry(ext_name="simple_events_per_point", int_name="simple_events_per_point", optional=True), + ParamMapEntry(ext_name="multiple_scattering", int_name="multiple_scattering", optional=True), + ParamMapEntry(ext_name="neutron_paths_single", int_name="neutron_paths_single", optional=True), + ParamMapEntry(ext_name="neutron_paths_multiple", int_name="neutron_paths_multiple", optional=True), ] attr_mapping.extend(PARAM_MAPPING)