Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple scattering correction to OSIRIS script #35927

Merged
merged 6 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 51 additions & 12 deletions Testing/SystemTests/tests/framework/ISIS_PowderOsirisTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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",
]
Expand All @@ -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",
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
534b1473c5f9827fec49e90563e7905c
Original file line number Diff line number Diff line change
@@ -1 +1 @@
73a30dc9bf46d636b47974003819f4cc
e4f663f1311e30a217701e9f03acb5d3
Original file line number Diff line number Diff line change
@@ -1 +1 @@
994ad405b8b6fe3763a0b4bc313420bc
409654effe6096a197d437a4cc7d3f92
42 changes: 41 additions & 1 deletion scripts/Diffraction/isis_powder/osiris.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)