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

Fix TOF range #127

Merged
merged 6 commits into from
Jul 25, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 33 additions & 29 deletions RefRed/calculations/lr_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
PLANCK_CONSTANT = 6.626e-34 # m^2 kg s^-1
H_OVER_M_NEUTRON = PLANCK_CONSTANT / NEUTRON_MASS

# any run before, tmin and tmax will be used a different algorithm
RUN_NUMBER_0_BETTER_CHOPPER_COVERAGE = 137261
NEW_GEOMETRY_DATE = '2014-10-01'


Expand All @@ -34,16 +32,13 @@ class LRData(object):
tof_range_manual = None
tof_range_auto = None
tof_range_auto_flag = True
tof_range_auto_with_margin = []

low_res = [0, 255]
low_res_flag = True
use_it_flag = True
full_file_name = ['']
filename = ''
ipts = 'N/A'

is_better_chopper_coverage = True
total_counts = 0

def __init__(
Expand Down Expand Up @@ -82,9 +77,6 @@ def __init__(
self.ipts = mt_run.getProperty('experiment_identifier').value
self.run_number = mt_run.getProperty('run_number').value

if float(self.run_number) < RUN_NUMBER_0_BETTER_CHOPPER_COVERAGE:
self.is_better_chopper_coverage = False

self.lambda_requested = float(mt_run.getProperty('LambdaRequest').value[0])
self.lambda_requested_units = mt_run.getProperty('LambdaRequest').units
self.thi = mt_run.getProperty('thi').value[0]
Expand Down Expand Up @@ -131,39 +123,51 @@ def __init__(
self.theta = self.calculate_theta()
self.frequency = float(mt_run.getProperty('Speed1').value[0])

tof_coeff_narrow = 1.7 * 60 / self.frequency
tof_coeff_large = 2.5 * 60 / self.frequency
tof_coeff = 0.5 * 60 / self.frequency
# Determine the range to select in TOF according to how the DAS computed the
# chopper settings
use_emission_delay = False
if "BL4B:Chop:Skf2:ChopperModerator" in mt_run:
moderator_calc = mt_run.getProperty("BL4B:Chop:Skf2:ChopperModerator").value[0]
t_mult = mt_run.getProperty("BL4B:Chop:Skf2:ChopperMultiplier").value[0]
t_off = mt_run.getProperty("BL4B:Chop:Skf2:ChopperOffset").value[0]
use_emission_delay = moderator_calc == 1

wl_half_width = 1.7 * 60 / self.frequency
wl_delta_full_range = 0.8 * 60 / self.frequency

# Calculate the TOF range to select
if use_emission_delay:
# We cut 5% on each side compared to the case without correction to avoid the shoulders
tmin = (self.dMD * (self.lambda_requested - wl_half_width * 0.95) / H_OVER_M_NEUTRON * 1e-4 + t_off) / (
1 - t_mult / 1000
)
tmax = (self.dMD * (self.lambda_requested + wl_half_width * 0.95) / H_OVER_M_NEUTRON * 1e-4 + t_off) / (
1 - t_mult / 1000
)
else:
tmin = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested - wl_half_width) * 1e-4
tmax = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + wl_half_width) * 1e-4

if lconfig is not None:
autotmin = float(lconfig.tof_range[0])
autotmax = float(lconfig.tof_range[1])
else:
if self.is_better_chopper_coverage:
autotmin = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested - tof_coeff_narrow) * 1e-4
autotmax = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + tof_coeff_narrow) * 1e-4
else:
autotmin = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + tof_coeff - tof_coeff_narrow) * 1e-4
autotmax = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + tof_coeff + tof_coeff_narrow) * 1e-4

# automatically calculate the TOF range for display
if self.is_better_chopper_coverage:
tmin = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested - tof_coeff_large) * 1e-4
tmax = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + tof_coeff_large) * 1e-4
else:
tmin = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + tof_coeff - tof_coeff_large) * 1e-4
tmax = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + tof_coeff + tof_coeff_large) * 1e-4

if tmin < 0:
tmin = 0
autotmin = tmin
autotmax = tmax

self.tof_range_auto = [autotmin, autotmax] # microS
self.tof_range_auto_with_margin = [tmin, tmax] # microS

# manual tof range (if user wants to use a manual time range)
self.tof_range = [autotmin, autotmax] # for the first time, initialize tof_range like auto (microS)
self.tof_range_manual = [autotmin, autotmax]

# Widen the range to show the entire TOF range in the plots
delta_t = self.dMD / H_OVER_M_NEUTRON * wl_delta_full_range * 1e-4
tmin -= delta_t
if tmin < 0:
tmin = 0
tmax += delta_t

self.binning = [tmin, self.read_options['bins'], tmax]
self.calculate_lambda_range()
self.incident_angle = 2.0 * self.calculate_theta(with_offset=False) # 2.theta
Expand Down
26 changes: 23 additions & 3 deletions RefRed/sf_calculator/lr_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,29 @@ def __init__(self, workspace, read_options):
self.theta = self.calculate_theta()
self.frequency = float(mt_run.getProperty('Speed1').value[0])

tof_coeff_large = 1.7 * 60 / self.frequency
tmax = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + tof_coeff_large) * 1e-4
tmin = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested - tof_coeff_large) * 1e-4
# Determine the range to select in TOF according to how the DAS computed the
# chopper settings
use_emission_delay = False
if "BL4B:Chop:Skf2:ChopperModerator" in mt_run:
moderator_calc = mt_run.getProperty("BL4B:Chop:Skf2:ChopperModerator").value[0]
t_mult = mt_run.getProperty("BL4B:Chop:Skf2:ChopperMultiplier").value[0]
t_off = mt_run.getProperty("BL4B:Chop:Skf2:ChopperOffset").value[0]
use_emission_delay = moderator_calc == 1

wl_half_width = 1.7 * 60 / self.frequency

# Calculate the TOF range to select
if use_emission_delay:
# We cut 5% on each side compared to the case without correction to avoid the shoulders
tmin = (self.dMD * (self.lambda_requested - wl_half_width * 0.95) / H_OVER_M_NEUTRON * 1e-4 + t_off) / (
1 - t_mult / 1000
)
tmax = (self.dMD * (self.lambda_requested + wl_half_width * 0.95) / H_OVER_M_NEUTRON * 1e-4 + t_off) / (
1 - t_mult / 1000
)
else:
tmax = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + wl_half_width) * 1e-4
tmin = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested - wl_half_width) * 1e-4

if self.read_options['is_auto_tof_finder'] or self.tof_range is None:
autotmin = tmin
Expand Down
Loading