Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _evaluate(self, *args):
""" uncertainties = f(args) """
bin_vals = {argname: args[self._dim_args[argname]] for argname in self._dim_order}
eval_vals = {argname: args[self._eval_args[argname]] for argname in self._eval_vars}
# lookup the bins that we care about
dim1_name = self._dim_order[0]
dim1_indices = np.clip(np.searchsorted(self._bins[dim1_name],
bin_vals[dim1_name],
side='right') - 1,
0, self._bins[dim1_name].size - 2)
# get clamp values and clip the inputs
outs = np.ones(shape=(args[0].size, 2), dtype=np.float)
for i in np.unique(dim1_indices):
mask = np.where(dim1_indices == i)
vals = np.clip(eval_vals[self._eval_vars[0]][mask],
self._eval_knots[0], self._eval_knots[-1])
outs[:, 0][mask] += self._eval_ups[i](vals)
outs[:, 1][mask] -= self._eval_downs[i](vals)
return outs
def masked_bin_eval(dim1_indices, dimN_bins, dimN_vals):
dimN_indices = np.empty_like(dim1_indices)
for i in np.unique(dim1_indices):
idx = np.where(dim1_indices == i)
dimN_indices[idx] = np.clip(np.searchsorted(dimN_bins[i],
dimN_vals[idx],
side='right') - 1,
0, len(dimN_bins[i]) - 2)
return dimN_indices
def _evaluate(self, *args):
""" SFs = f(args) """
bin_vals = {argname: args[self._dim_args[argname]] for argname in self._dim_order}
eval_vals = {argname: args[self._eval_args[argname]] for argname in self._eval_vars}
# lookup the bins that we care about
dim1_name = self._dim_order[0]
dim1_indices = np.clip(np.searchsorted(self._bins[dim1_name],
bin_vals[dim1_name],
side='right') - 1,
0, self._bins[dim1_name].size - 2)
bin_indices = [dim1_indices]
for binname in self._dim_order[1:]:
bin_indices.append(masked_bin_eval(bin_indices[0], self._bins[binname],
bin_vals[binname]))
bin_tuple = tuple(bin_indices)
# get clamp values and clip the inputs
eval_values = []
for eval_name in self._eval_vars:
clamp_mins = self._eval_clamp_mins[eval_name][bin_tuple]
clamp_maxs = self._eval_clamp_maxs[eval_name][bin_tuple]
eval_values.append(np.clip(eval_vals[eval_name], clamp_mins, clamp_maxs))
def masked_bin_eval(dim1_indices, dimN_bins, dimN_vals):
dimN_indices = np.empty_like(dim1_indices)
for i in np.unique(dim1_indices):
idx = np.where(dim1_indices == i)
dimN_indices[idx] = np.clip(np.searchsorted(dimN_bins[i],
dimN_vals[idx],
side='right') - 1,
0, len(dimN_bins[i]) - 2)
return dimN_indices
def masked_bin_eval(dim1_indices, dimN_bins, dimN_vals):
dimN_indices = np.empty_like(dim1_indices)
for i in np.unique(dim1_indices):
idx = np.where(dim1_indices == i)
dimN_indices[idx] = np.clip(np.searchsorted(dimN_bins[i],
dimN_vals[idx],
side='right') - 1,
0, len(dimN_bins[i]) - 2)
return dimN_indices
def _apply_run_lumi_mask_kernel(masks, runs, lumis, mask_out):
for iev in numba.prange(len(runs)):
run = np.uint32(runs[iev])
lumi = np.uint32(lumis[iev])
if run in masks:
lumimask = masks[run]
ind = np.searchsorted(lumimask, lumi)
if np.mod(ind, 2) == 1:
mask_out[iev] = 1
def _evaluate(self, *args):
""" jec/jer = f(args) """
bin_vals = {argname: args[self._dim_args[argname]] for argname in self._dim_order}
eval_vals = {argname: args[self._eval_args[argname]] for argname in self._eval_vars}
# lookup the bins that we care about
dim1_name = self._dim_order[0]
dim1_indices = np.clip(np.searchsorted(self._bins[dim1_name],
bin_vals[dim1_name],
side='right') - 1,
0, self._bins[dim1_name].size - 2)
bin_indices = [dim1_indices]
for binname in self._dim_order[1:]:
bin_indices.append(masked_bin_eval(bin_indices[0],
self._bins[binname],
bin_vals[binname]))
bin_tuple = tuple(bin_indices)
# get clamp values and clip the inputs
eval_values = []
for eval_name in self._eval_vars:
clamp_mins = None
if self._eval_clamp_mins[eval_name].content.size == 1: