def cut_hlt(wvz):
    presel = reduce_and(
        wvz["lep_pass_veto"].sum() >= 2,
        wvz["firstgoodvertex"] == 0,
        wvz["passesMETfiltersRun2"],
        np.logical_or(~wvz["isData"], wvz["pass_duplicate_mm_em_ee"]),
    )

    # Check if any of the combination of leptons pass the trigger thresholds
    # Ele 23 12
    # El23 Mu8
    # Mu23 El12
    # Mu 17 8
    # The thresholds are rounded up to 25, 15, or 10

    pt = wvz["lep_pt"][wvz["lep_pass_veto"]]
    pdg = np.abs(wvz["lep_id"][wvz["lep_pass_veto"]])

    ele_pt = pt[pdg == 11]
    mu_pt = pt[pdg == 13]
    triggered = reduce_or(
        reduce_and(wvz["HLT_DoubleEl"], (ele_pt > 25).sum(),
                   (ele_pt > 15).sum() > 1),
        reduce_and(wvz["HLT_MuEG"], (mu_pt > 25).sum(), (ele_pt > 15).sum()),
        reduce_and(wvz["HLT_MuEG"], (ele_pt > 25).sum(), (mu_pt > 10).sum()),
        reduce_and(wvz["HLT_DoubleMu"], (mu_pt > 20).sum(),
                   (mu_pt > 10).sum() > 1),
    )

    return np.logical_and(presel, triggered)
def cut_four_leptons_low_mll(wvz):
    mask = reduce_or(wvz["lep_is_z"], wvz["lep_is_nom"])

    res = mask.sum() == 4

    p4 = wvz["lep_p4"][mask][res]
    ch = np.sign(wvz["lep_id"][mask][res])

    mll_cut = 12.0

    combinations = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]

    def veto(i, j):
        return reduce_and(ch[:, i] == -ch[:, j],
                          (p4[:, i] + p4[:, j]).mass < mll_cut)

    res[res] = ~reduce_or(*[veto(i, j) for i, j in combinations])

    return res
def pass_nominal_lepton_mva_id(wvz):
    pdg = np.abs(wvz["lep_id"])
    pass_el = reduce_and(
        pdg == 11,
        wvz["lep_isMVAwp90IsoPOG"],
        np.abs(wvz["lep_sip3d"]) < 4.0,
        wvz["lep_relIso03EAwLep"] < 0.2,
        wvz["lep_isMVAwpLooseNoIsoPOG"],
    )
    pass_mu = reduce_and(pdg == 13, wvz["lep_isMediumPOG"],
                         np.abs(wvz["lep_relIso04DB"] < 0.15),
                         np.abs(wvz["lep_sip3d"]) < 4.0)
    return reduce_and(wvz["lep_pass_veto"], reduce_or(pass_el, pass_mu))
 def is_4_lepton_event(wvz):
     m = reduce_and(wvz["lep_pass_veto"].sum() == 4,
                    np.sign(wvz["lep_id"][wvz["lep_pass_veto"]]).sum() == 0)
     pdg = wvz["lep_id"][wvz["lep_pass_veto"]][m]
     m[m] = reduce_or(
         pdg[:, 0] + pdg[:, 1] == 0,
         pdg[:, 0] + pdg[:, 2] == 0,
         pdg[:, 0] + pdg[:, 3] == 0,
         pdg[:, 1] + pdg[:, 2] == 0,
         pdg[:, 1] + pdg[:, 3] == 0,
         pdg[:, 2] + pdg[:, 3] == 0,
     )
     return m
def is_4_lepton_event(wvz):
    return wvz["n_veto_leptons"] == 4
    pdg = jagged_lepton_variable(wvz, "pdgId")
    m = np.sign(pdg).sum() == 0
    # m = reduce_and(wvz["lep_pass_veto"].sum() == 4, np.sign(wvz["lep_id"][wvz["lep_pass_veto"]]).sum() == 0)
    # pdg = wvz["lep_id"][wvz["lep_pass_veto"]][m]
    return np.logical_and(
        m,
        reduce_or(
            pdg[:, 0] + pdg[:, 1] == 0,
            pdg[:, 0] + pdg[:, 2] == 0,
            pdg[:, 0] + pdg[:, 3] == 0,
            pdg[:, 1] + pdg[:, 2] == 0,
            pdg[:, 1] + pdg[:, 3] == 0,
            pdg[:, 2] + pdg[:, 3] == 0,
        ),
    )
def pass_nominal_lepton_id(wvz):
    pdg = np.abs(wvz["lep_id"])
    pass_el = reduce_and(pdg == 11, wvz["lep_isCutBasedIsoMediumPOG"])
    pass_mu = reduce_and(pdg == 13, wvz["lep_relIso04DB"] < 0.15)
    return reduce_and(wvz["lep_pass_veto"], reduce_or(pass_el, pass_mu))
def pass_vefrom_lepton_id(wvz):
    return reduce_or(pass_vefrom_electron_id(wvz), pass_vefrom_muon_id(wvz))