def fevaluate_qcdewk_weight(ev, evidx, nsig, source): central = ev.WeightQcdEwkNominal try: up = getattr(ev, 'WeightQcdEwk_{}Up'.format(source)) down = getattr(ev, 'WeightQcdEwk_{}Down'.format(source)) except AttributeError: up = 0. down = 0. return weight_numba(central, nsig, up, down)
def fevaluate_scale_variations(ev, evidx, nsig, source, name_): if source == name_: up = ev.LHEScaleWeight[:, positions[0]] down = ev.LHEScaleWeight[:, positions[1]] weight = weight_numba(1., nsig, up, down) else: weight = np.ones(ev.size, dtype=np.float32) ev.delete_branches(["LHEScaleWeight"]) return weight
def fevaluate_pu(ev, evidx, nsig, source, var_): mins = corrs["nTrueInt"].values.astype(np.float32) maxs = mins[:] + 1 maxs[-1] = np.inf indices = get_bin_indices([getattr(ev, var_)], [mins], [maxs], 1)[:, 0] ev_corrs = corrs.iloc[indices] nominal = ev_corrs["corr"].values up = (ev_corrs["corr_up"].values / nominal - 1.) * (source == "pileup") down = (ev_corrs["corr_down"].values / nominal - 1.) * (source == "pileup") return weight_numba(nominal, nsig, up, down)
def fevaluate_pdf_variations(ev, evidx, nsig, source): if source == "pdf": pdf_relstddev = rel_stddev( ev.LHEWeight_originalXWGTUP, ev.LHEPdfWeight.content, ev.LHEPdfWeight.starts, ev.LHEPdfWeight.stops, ) weight = weight_numba(1., nsig, pdf_relstddev, -pdf_relstddev) else: weight = np.ones(ev.size, dtype=np.float32) ev.delete_branches(["LHEWeight_originalXWGTUP", "LHEPdfWeight"]) return weight
def fevaluate_met_trigger(ev, evidx, nsig, source): nmuons = ev.MuonSelection(ev, 'pt').counts metnox = ev.METnoX_pt(ev) wmet = met_trigger_numba(cats, xcents, params[0], nmuons, metnox) if source == "metTrigStat": up = met_trigger_numba(cats, xcents, params[1], nmuons, metnox) / wmet - 1. down = met_trigger_numba(cats, xcents, params[2], nmuons, metnox) / wmet - 1. elif source == "metTrigSyst": up = met_trigger_numba(cats, xcents, params[3], nmuons, metnox) / wmet - 1. down = met_trigger_numba(cats, xcents, params[4], nmuons, metnox) / wmet - 1. else: up = np.zeros_like(wmet) down = np.zeros_like(wmet) return weight_numba(wmet, nsig, up, down)
def fevaluate_prefiring_weight(ev, evidx, nsig, source): jet_mask = funcs["Jet"](ev) jet_eta = ev.Jet_eta[jet_mask] jet_effs, jet_effs_stat = get_efficiencies( ev, "Jet", jet_mask, jetmap, ) jet_effs_err = np.sqrt(jet_effs_stat**2 + (syst * jet_effs)**2) photon_mask = funcs["Photon"](ev) photon_eta = ev.Photon_eta[photon_mask] photon_effs, photon_effs_stat = get_efficiencies( ev, "Photon", photon_mask, photmap, ) photon_effs_err = np.sqrt(photon_effs_stat**2 + (syst * photon_effs)**2) prob, probup, probdown = prob_nonprefiring_numba( photon_eta.content, ev.Photon_phi[photon_mask].content, photon_effs, photon_effs_err, photon_eta.starts, photon_eta.stops, jet_eta.content, ev.Jet_phi[jet_mask].content, jet_effs, jet_effs_err, jet_eta.starts, jet_eta.stops, ) return weight_numba( prob, nsig, (source == "prefiring") * probup / prob, (source == "prefiring") * probdown / prob, )
def fevaluate_object_weights(ev, evidx, nsig, source, name_): event_vars = [v(ev) for v in bins_vars] for v in event_vars: v.content[np.isnan(v.content)] = 0. indices = get_bin_indices( [event_vars[idx].content.astype(np.float32) for idx in range(len(event_vars))], [df["bin{}_low".format(idx)].values.astype(np.float32) for idx in range(len(event_vars))], [df["bin{}_upp".format(idx)].values.astype(np.float32) for idx in range(len(event_vars))], df["weight"].unique().shape[0], ).ravel() dfw = df.iloc[indices] sf, sfup, sfdown = weighted_mean_numba( event_vars[0].content, dfw["weight"].values, dfw["corr"].values, dfw["unc_up"].values, dfw["unc_down"].values, add_syst(ev).content, df["weight"].unique().shape[0], ) return awk.JaggedArray( event_vars[0].starts, event_vars[0].stops, weight_numba(sf, nsig, sfup, sfdown), )
def fevaluate_btagsf(ev, evidx, nsig, source, attrs_): jet_flavour = dict_apply(h2f, ev.Jet.hadronFlavour.content) # Create mask mask = np.ones((jet_flavour.shape[0], df.shape[0]), dtype=np.bool8) # Flavour mask event_attrs = [jet_flavour.astype(np.float32)] mins = [df["jetFlavor"].values.astype(np.float32)] maxs = [(df["jetFlavor"].values + 1).astype(np.float32)] for jet_attr, df_attr in attrs_: obj_attr = getattr(ev.Jet, jet_attr) if callable(obj_attr): obj_attr = obj_attr(ev) event_attrs.append(obj_attr.content.astype(np.float32)) mins.append(df[df_attr + "Min"].values.astype(np.float32)) maxs.append(df[df_attr + "Max"].values.astype(np.float32)) # Create indices from mask indices = get_bin_indices(event_attrs, mins, maxs, 3) idx_central = indices[:, 0] idx_down = indices[:, 1] idx_up = indices[:, 2] jpt = ev.Jet.ptShift(ev) sf = btag_formula(jpt.content, df.iloc[idx_central]) sf_up = btag_formula(jpt.content, df.iloc[idx_up]) sf_down = btag_formula(jpt.content, df.iloc[idx_down]) sf_up = (source == "btagSF") * (sf_up / sf - 1.) sf_down = (source == "btagSF") * (sf_down / sf - 1.) return awk.JaggedArray( jpt.starts, jpt.stops, weight_numba(sf, nsig, sf_up, sf_down), )