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 event weights in weighted reflectivity calculation #52

Merged
merged 1 commit into from
Dec 5, 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
16 changes: 9 additions & 7 deletions reduction/lr_reduction/event_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ def specular_weighted(self, q_summing=True, bck_in_q=False):
"""
# Event weights for normalization
db_charge = self._ws_db.getRun().getProtonCharge()
wl_events = self._get_events(self._ws_db, self.norm_peak, self.norm_low_res)
wl_dist, wl_bins = np.histogram(wl_events, bins=60)
wl_events, wl_weights = self._get_events(self._ws_db, self.norm_peak, self.norm_low_res)
wl_dist, wl_bins = np.histogram(wl_events, bins=100, weights=wl_weights)
_bin_width = wl_bins[1:] - wl_bins[:-1]
wl_dist = wl_dist/db_charge/_bin_width
wl_middle = [(wl_bins[i+1]+wl_bins[i])/2.0 for i in range(len(wl_bins)-1)]
Expand Down Expand Up @@ -671,6 +671,7 @@ def _get_events(self, ws, peak, low_res):
Return an array of wavelengths for a given workspace.
"""
wl_events = np.asarray([])
wl_weights = np.asarray([])

for i in range(low_res[0], int(low_res[1]+1)):
for j in range(peak[0], int(peak[1]+1)):
Expand All @@ -685,8 +686,9 @@ def _get_events(self, ws, peak, low_res):
tofs = self.emission_time_correction(ws, tofs)
wl_list = tofs / self.constant
wl_events = np.concatenate((wl_events, wl_list))

return wl_events
weights = evt_list.getWeights()
wl_weights = np.concatenate((wl_weights, weights))
return wl_events, wl_weights

def off_specular(self, x_axis=None, x_min=-0.015, x_max=0.015, x_npts=50,
z_min=None, z_max=None, z_npts=-120, bck_in_q=None):
Expand Down Expand Up @@ -714,8 +716,8 @@ def off_specular(self, x_axis=None, x_min=-0.015, x_max=0.015, x_npts=50,
else:
qx_bins = np.logspace(np.log10(x_min), np.log10(x_max), num=np.abs(x_npts))

wl_events = self._get_events(self._ws_db, self.norm_peak, self.norm_low_res)
wl_dist, wl_bins = np.histogram(wl_events, bins=60)
wl_events, wl_weights = self._get_events(self._ws_db, self.norm_peak, self.norm_low_res)
wl_dist, wl_bins = np.histogram(wl_events, bins=100, weights=wl_weights)
wl_middle = [(wl_bins[i+1]+wl_bins[i])/2.0 for i in range(len(wl_bins)-1)]

_refl, _d_refl = self._off_specular(self._ws_sc, wl_dist, wl_middle, qx_bins, qz_bins,
Expand Down Expand Up @@ -767,7 +769,7 @@ def _off_specular(self, ws, wl_dist, wl_bins, x_bins, z_bins, peak_position, the
# Sign will depend on reflect up or down
ths_value = ws.getRun()['ths'].value[-1]
delta_theta_f *= np.sign(ths_value)
theta_f = theta + delta_theta_f
theta_f = theta - delta_theta_f

qz = k * (np.sin(theta_f) + np.sin(theta))
qz = np.fabs(qz)
Expand Down
2 changes: 1 addition & 1 deletion reduction/lr_reduction/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def reduce(ws, template_file, output_dir, average_overlap=False,
# Call the reduction using the template
qz_mid, refl, d_refl, meta_data = template.process_from_template_ws(ws, template_data,
q_summing=q_summing,
tof_weighted=False,
tof_weighted=bck_in_q,
clean=q_summing,
bck_in_q=bck_in_q,
info=True)
Expand Down
Loading