Skip to content

Commit

Permalink
Updates Direct Reduction scripts as of December 2024
Browse files Browse the repository at this point in the history
* Fix MARI auto-ei disk phase edge case
* Fix MERLIN auto-ei due to replacement chopper sensor
* Set FixEi to False for MERLIN
* Fix auto-ei error with continuous scans
  • Loading branch information
mducle committed Dec 5, 2024
1 parent 8a83fa2 commit 5b9869c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion direct_inelastic/ISIS/DG_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#==================Local Contact Inputs==================
inst = 'INSTRUMENT_NAME'
cycle = 'CYCLE_ID' # cycle number
fixei = True # True for LET since no monitor 3
fixei = FIXEIVAL # True for LET since no monitor 3
powdermap = 'RINGS_MAP_XML' # rings mapping file - must be .xml format
file_wait = 30 # wait for data file to appear (seconds)
keepworkspaces = False # should be false for Horace scans
Expand Down Expand Up @@ -230,6 +230,7 @@ def load_sum(run_list, block_name=None):
# https://github.com/mantidproject/mantid/issues/36194
sumruns = False
ws_full, bval = load_sum(sample, cs_block)
ws = ws_full # So that auto-ei works (it assumes the workspace variable is "ws")
ws_monitors = CloneWorkspace('ws_full_monitors')
bval_range = max(bval) - min(bval)
bval_nbins = int(bval_range / cs_bin_size)
Expand Down
23 changes: 18 additions & 5 deletions direct_inelastic/ISIS/reduction_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,21 @@ def inrange(tf, l):
freq = mode(getLog('Fermi_Speed'))
except ValueError:
return []
phase1, phase2 = (mode(getLog(nam)) for nam in ['Phase_Thick_1', 'Phase_Thick_2'])
delay = getfracLog('Fermi_delay')
lmc = 10.04 # Moderator-Fermi distance
period = 1.e6 / freq
try:
phase1, phase2 = (mode(getLog(nam)) for nam in ['Phase_Thick_1', 'Phase_Thick_2'])
except RuntimeError:
# Pre-upgrade MARI - single slot disk
phase_disk = mode(getLog('Phase_Thick')) + 500 # Offset used in mari_utils.gcl
eis_disk = ((2286.26*7.05) / (phase_disk))**2
if mode(getLog('Freq_Thick')) > 0 or (run.hasProperty('nchannels') and run.getProperty('nchannels').value > 1000):
return [eis_disk]
else:
delay_calc = ((2286.26 * lmc) / np.sqrt(eis_disk))
eis = list({((2286.26*lmc) / (delay_calc + s*period))**2 for s in range(-10, 10)})
return [roundlog10(ei) for ei in np.sort(eis)[::-1] if ei > 10]
try:
ei_nominal = mode(getLog('Ei_nominal'))
except RuntimeError: # Old file
Expand All @@ -381,10 +392,10 @@ def inrange(tf, l):
disk_delta = delt_disk2 - delt_disk1
slots_delta = np.round(disk_delta / 202.11) / 10
assert slots_delta % 1.0 < 0.2, 'Bad slots calculation'
slots = {0:[0,1,2,4], 1:[0,1], 2:[0,2], 4:[0]}[abs(int(slots_delta))]
slots = {0:[0,1,2,4], 1:[0,1], 2:[0,2], 3:[0], 4:[0]}[abs(int(slots_delta))]
disk_ref = 6 - (np.round(delt_disk1 / 202.11) / 10)
assert disk_ref % 1.0 < 0.2, f'Bad disk calculation'
disk = {0:disk_ref, 1:disk_ref-1, 2:1 if disk_ref==2 else 0, 4:0}[abs(int(slots_delta))]
disk = {0:disk_ref, 1:disk_ref-1, 2:1 if disk_ref==2 else 0, 3:0, 4:0}[abs(int(slots_delta))]
reps = [d-disk for d in slots]
eis_disk = {((2286.26*lmc) / (delay_calc + s*2500.))**2 for s in reps}
period = period / 2. if 'G' in chopper_type.upper() else period
Expand Down Expand Up @@ -432,9 +443,11 @@ def inrange(tf, l):
ldc = 9.2176 # Mod-Disk distance
if not rrm_mode:
return [roundlog10(((2286.26*ldc) / disk_delay)**2)]
else: # Assume using Gd chopper (t_offset = 2000/freq-5, for 'S' it is 300/freq-8)
else: # Assume using Gd chopper (t_offset = 2000/freq-5, for 'S' it is 300/freq-8.1)
# The opto on the Fermi was replaced on 28/11/24 - need to use different constants
m, c = (2000, -5) if run.endTime().to_datetime64() < np.datetime64('2024-11-27') else (6483, -5.5)
period = 20000 * (25. / freq)
tof = (2286.26 * lmc) / np.sqrt(roundlog10(((2286.26 * lmc) / (delay - 2000/freq - 2))**2))
tof = (2286.26 * lmc) / np.sqrt(roundlog10(((2286.26 * lmc) / (delay - m/freq - c))**2))
tfmx = 7500 if np.abs(disk_delay - 12400) < 10 else 8500
return [roundlog10(((2286.26*lmc) / tf)**2) for tf in [(tof + s*period) for s in range(-10, 10)] if tf > 1500 and tf < tfmx]

Expand Down
1 change: 1 addition & 0 deletions direct_inelastic/LET/USER_Files_description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<replace var = "MASK_FILE_XML" by_var="LET_mask_222.xml"/>
<replace var = "CYCLE_ID" by_var="$cycleID$"/>
<replace var = "RINGS_MAP_XML" by_var="LET_rings_222.xml"/>
<replace var = "FIXEIVAL" by_var="True"/>
</file_to_copy>
<file_to_copy file_name="../ISIS/DG_monovan.py" copy_as="DG_monovan.py">
<replace var = "INSTRUMENT_NAME" by_var="LET"/>
Expand Down
1 change: 1 addition & 0 deletions direct_inelastic/MAPS/USER_Files_description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<replace var = "MASK_FILE_XML" by_var="4to1_211_msk.xml"/>
<replace var = "CYCLE_ID" by_var="$cycleID$"/>
<replace var = "RINGS_MAP_XML" by_var="MAPS_rings.map"/>
<replace var = "FIXEIVAL" by_var="True"/>
</file_to_copy>
<file_to_copy file_name="../ISIS/DG_monovan.py" copy_as="DG_monovan.py">
<replace var = "INSTRUMENT_NAME" by_var="MAPS"/>
Expand Down
1 change: 1 addition & 0 deletions direct_inelastic/MARI/DG_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def load_sum(run_list, block_name=None):
# https://github.com/mantidproject/mantid/issues/36194
sumruns = False
ws_full, bval = load_sum(sample, cs_block)
ws = ws_full # So that auto-ei works (it assumes the workspace variable is "ws")
ws_monitors = CloneWorkspace('ws_full_monitors')
bval_range = max(bval) - min(bval)
bval_nbins = int(bval_range / cs_bin_size)
Expand Down
1 change: 1 addition & 0 deletions direct_inelastic/MARI/USER_Files_description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<replace var = "MASK_FILE_XML" by_var="mari_mask$cycleID$.xml"/>
<replace var = "CYCLE_ID" by_var="$cycleID$"/>
<replace var = "RINGS_MAP_XML" by_var="mari_res2013.map"/>
<replace var = "FIXEIVAL" by_var="True"/>
</file_to_copy>
<file_to_copy file_name="../ISIS/DG_monovan.py" copy_as="DG_monovan.py">
<replace var = "INSTRUMENT_NAME" by_var="MARI"/>
Expand Down
1 change: 1 addition & 0 deletions direct_inelastic/MERLIN/USER_Files_description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<replace var = "MASK_FILE_XML" by_var="mask_242.xml"/>
<replace var = "CYCLE_ID" by_var="$cycleID$"/>
<replace var = "RINGS_MAP_XML" by_var="MERLIN_rings_242.xml"/>
<replace var = "FIXEIVAL" by_var="False"/>
</file_to_copy>
<file_to_copy file_name="../ISIS/DG_monovan.py" copy_as="DG_monovan.py">
<replace var = "INSTRUMENT_NAME" by_var="MERLIN"/>
Expand Down

0 comments on commit 5b9869c

Please sign in to comment.