示例#1
0
 def _evaluate(self, *args):
     indices = []
     for arg in args:
         if type(arg) == awkward.JaggedArray:
             raise Exception('JaggedArray in inputs')
     if self._dimension == 1:
         indices.append(np.clip(np.searchsorted(self._axes, args[0], side='right') - 1, 0, self._values.shape[0] - 1))
     else:
         for dim in range(self._dimension):
             indices.append(np.clip(np.searchsorted(self._axes[dim], args[dim], side='right') - 1, 0, self._values.shape[dim] - 1))
     return self._values[tuple(indices)]
示例#2
0
    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))

        #get parameter values
        parm_values = self._parms[bin_tuple]
        
        return parm_values
示例#3
0
    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 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
示例#6
0
    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:
                clamp_mins = self._eval_clamp_mins[eval_name].content[0]
            else:
                idxs = flatten_idxs(bin_tuple, self._eval_clamp_mins[eval_name])
                clamp_mins = self._eval_clamp_mins[eval_name].content[idxs]
                if isinstance(clamp_mins, awkward.JaggedArray):
                    if clamp_mins.content.size == 1:
                        clamp_mins = clamp_mins.content[0]
                    else:
                        clamp_mins = clamp_mins.flatten()
            clamp_maxs = None
            if self._eval_clamp_maxs[eval_name].content.size == 1:
                clamp_maxs = self._eval_clamp_maxs[eval_name].content[0]
            else:
                idxs = flatten_idxs(bin_tuple, self._eval_clamp_maxs[eval_name])
                clamp_maxs = self._eval_clamp_maxs[eval_name].content[idxs]
                if isinstance(clamp_maxs, awkward.JaggedArray):
                    if clamp_maxs.content.size == 1:
                        clamp_maxs = clamp_maxs.content[0]
                    else:
                        clamp_maxs = clamp_maxs.flatten()
            eval_values.append(np.clip(eval_vals[eval_name], clamp_mins, clamp_maxs))

        # get parameter values
        parm_values = []
        if len(self._parms) > 0:
            idxs = flatten_idxs(bin_tuple, self._parms[0])
            parm_values = [parm.content[idxs] for parm in self._parms]

        return self._formula(*tuple(parm_values + eval_values))
示例#7
0
 def index(self, identifier):
     if (isinstance(identifier, np.ndarray)
             and len(identifier.shape) == 1) or isinstance(
                 identifier, numbers.Number):
         if self._uniform:
             idx = np.clip(
                 np.floor((identifier - self._lo) * self._bins /
                          (self._hi - self._lo)) + 1, 0, self._bins + 1)
             if isinstance(idx, np.ndarray):
                 idx[np.isnan(idx)] = self.size - 1
                 idx = idx.astype(int)
             elif np.isnan(idx):
                 idx = self.size - 1
             else:
                 idx = int(idx)
             return idx
         else:
             return np.searchsorted(self._bins, identifier, side='right')
     elif isinstance(identifier, Interval):
         if identifier.nan():
             return self.size - 1
         return self.index(identifier._lo)
     raise TypeError(
         "Request bin indices with a identifier or 1-D array only")
示例#8
0
 def __call__(self, runs, lumis):
     mask = np.zeros(dtype='bool', shape=runs.shape)
     for run in np.unique(runs):
         if run in self._masks:
             mask |= (np.searchsorted(self._masks[run], lumis)%2==1) & (runs==run)
     return mask