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
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 VJetsQQ_kFactor2017(sampleName, lookup, genVPt): kfactor = genVPt.ones_like() if 'ZJetsToQQ_' in sampleName: kfactor._content = lookup['ZJetsNLO'](np.clip(genVPt.content, 250., 1200.)) elif 'WJetsToQQ_' in sampleName: kfactor._content = lookup['WJetsNLO'](np.clip(genVPt.content, 250., 1200.)) return kfactor
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)]
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))
def calculateNLOKFactorAndSysts(sampleName, lookup, genVPt): central = genVPt.ones_like() pdf_up, pdf_down = genVPt.ones_like(), genVPt.ones_like() ren_up, ren_down = genVPt.ones_like(), genVPt.ones_like() fac_up, fac_down = genVPt.ones_like(), genVPt.ones_like() clipped = np.clip(genVPt.content, 100., 700.) if ('ZJets' in sampleName or 'DYJets' in sampleName or 'ZPrime' in sampleName or 'VectorDiJet' in sampleName): central._content = lookup["ZJets_012j_NLO/nominal"](clipped) pdf_raw = lookup["ZJets_012j_NLO/PDF"](clipped) pdf_up._content = pdf_up._content + pdf_raw pdf_down._content = pdf_down._content - pdf_raw ren_up._content = lookup["ZJets_012j_NLO/ren_up"](clipped) ren_down._content = lookup["ZJets_012j_NLO/ren_down"](clipped) fac_up._content = lookup["ZJets_012j_NLO/fact_up"](clipped) fac_down._content = lookup["ZJets_012j_NLO/fact_down"](clipped) if 'WJets' in sampleName: central._content = lookup["WJets_012j_NLO/nominal"](clipped) pdf_raw = lookup["WJets_012j_NLO/PDF"](clipped) pdf_up._content = pdf_up._content + pdf_raw pdf_down._content = pdf_down._content - pdf_raw ren_up._content = lookup["WJets_012j_NLO/ren_up"](clipped) ren_down._content = lookup["WJets_012j_NLO/ren_down"](clipped) fac_up._content = lookup["WJets_012j_NLO/fact_up"](clipped) fac_down._content = lookup["WJets_012j_NLO/fact_down"](clipped) return (central, { 'PDF': (pdf_up, pdf_down), 'ren': (ren_up, ren_down), 'fact': (fac_up, fac_down) })
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 corrGEN(pt): #self.corrGEN = ROOT.TF1("corrGEN", "[0]+[1]*pow(x*[2],-[3])", 200, 3500) #self.corrGEN.SetParameter(0, 1.00626) #self.corrGEN.SetParameter(1, -1.06161) #self.corrGEN.SetParameter(2, 0.0799900) #self.corrGEN.SetParameter(3, 1.20454) x = np.clip(pt,200,3500) return 1.00626 - 1.06161*pow(x*0.0799900,-1.20454)
def VtrigSF(evaluator, ak8msd, ak8pt): msd = ak8msd pt = ak8pt if isinstance(ak8msd, awkward.JaggedArray): assert (ak8msd.offsets == ak8pt.offsets).all() msd = ak8msd.flatten() pt = ak8pt.flatten() else: assert ak8msd.size == ak8pt.size msd = np.clip(msd, 0, 300) pt = np.clip(pt, 200, 1000) eff = evaluator['data_obs_muCR4_eff'](msd, pt) lo = evaluator['data_obs_muCR4_eff_down'](msd, pt) hi = evaluator['data_obs_muCR4_eff_up'](msd, pt) if isinstance(ak8msd, awkward.JaggedArray): eff = awkward.JaggedArray.fromoffsets(ak8pt.offsets, eff) lo = awkward.JaggedArray.fromoffsets(ak8pt.offsets, lo) hi = awkward.JaggedArray.fromoffsets(ak8pt.offsets, hi) return eff, hi, lo
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")
def _ireduce(self, the_slice): if isinstance(the_slice, numbers.Number): the_slice = slice(the_slice, the_slice) elif isinstance(the_slice, Interval): if the_slice.nan(): return slice(-1, None) lo = the_slice._lo if the_slice._lo > -np.inf else None hi = the_slice._hi if the_slice._hi < np.inf else None the_slice = slice(lo, hi) if isinstance(the_slice, slice): blo, bhi = None, None if the_slice.start is not None: if the_slice.start < self._lo: raise ValueError( "Reducing along axis %r: requested start %r exceeds bin boundaries (use open slicing, e.g. x[:stop])" % (self, the_slice.start)) if self._uniform: blo_real = (the_slice.start - self._lo) * self._bins / ( self._hi - self._lo) + 1 blo = np.clip( np.round(blo_real).astype(int), 0, self._bins + 1) if abs(blo - blo_real) > 1.e-14: warnings.warn( "Reducing along axis %r: requested start %r between bin boundaries, no interpolation is performed" % (self, the_slice.start), RuntimeWarning) else: if the_slice.start not in self._bins: warnings.warn( "Reducing along axis %r: requested start %r between bin boundaries, no interpolation is performed" % (self, the_slice.start), RuntimeWarning) blo = self.index(the_slice.start) if the_slice.stop is not None: if the_slice.stop > self._hi: raise ValueError( "Reducing along axis %r: requested stop %r exceeds bin boundaries (use open slicing, e.g. x[start:])" % (self, the_slice.stop)) if self._uniform: bhi_real = (the_slice.stop - self._lo) * self._bins / ( self._hi - self._lo) + 1 bhi = np.clip( np.round(bhi_real).astype(int), 0, self._bins + 1) if abs(bhi - bhi_real) > 1.e-14: warnings.warn( "Reducing along axis %r: requested stop %r between bin boundaries, no interpolation is performed" % (self, the_slice.stop), RuntimeWarning) else: if the_slice.stop not in self._bins: warnings.warn( "Reducing along axis %r: requested stop %r between bin boundaries, no interpolation is performed" % (self, the_slice.stop), RuntimeWarning) bhi = self.index(the_slice.stop) # Assume null ranges (start==stop) mean we want the bin containing the value if blo is not None and blo == bhi: bhi += 1 if the_slice.step is not None: raise NotImplementedError( "Step slicing can be interpreted as a rebin factor") return slice(blo, bhi, the_slice.step) elif isinstance(the_slice, list) and all( isinstance(v, Interval) for v in the_slice): raise NotImplementedError("Slice histogram from list of intervals") raise IndexError("Cannot understand slice %r on axis %r" % (the_slice, self))
def corrRECO_for(pt): x = np.clip(pt,200,3500) return 1.27212 + x*(-0.000571640+x*(8.37289e-07+x*(-5.20433e-10+x*(1.45375e-13+ x*(-1.50389e-17)))))
def corrRECO_cen(pt): x = np.clip(pt,200,3500) return 1.09302 + x*(-0.000150068+x*(3.44866e-07+x*(-2.68100e-10+x*(8.67440e-14+ x*(-1.00114e-17)))))