Esempio n. 1
0
 def fourvect_vis(self):
     vect = LorentzVector()
     try:
         vect.SetPtEtaPhiM(et2pt(self.vis_Et, self.vis_eta, self.vis_m),
                           self.eta, self.phi, self.m)
     except ValueError:
         log.warning("DOMAIN ERROR ON TRUTH 4-VECT: "
                     "Et: {0} eta: {1} m: {2}".format(
                         self.vis_Et, self.vis_eta, self.vis_m))
         vect.SetPtEtaPhiM(0, self.eta, self.phi, self.m)
     return vect
Esempio n. 2
0
def mass(tau1, tau2, METpx, METpy):
    """
    Calculate and return the collinear mass and momentum fractions
    of tau1 and tau2

    TODO: set visible mass of taus. 1.2 GeV for 3p and 0.8 GeV for 1p
    """
    recTau1 = LorentzVector()
    recTau2 = LorentzVector()

    # tau 4-vector; synchronize for MMC calculation
    if tau1.nTracks() < 3:
        recTau1.SetPtEtaPhiM(tau1.pt(), tau1.eta(), tau1.phi(), 800.)  # MeV
    else:
        recTau1.SetPtEtaPhiM(tau1.pt(), tau1.eta(), tau1.phi(), 1200.)  # MeV

    if tau2.nTracks() < 3:
        recTau2.SetPtEtaPhiM(tau2.pt(), tau2.eta(), tau2.phi(), 800.)  # MeV
    else:
        recTau2.SetPtEtaPhiM(tau2.pt(), tau2.eta(), tau2.phi(), 1200.)  # MeV

    K = ROOT.TMatrixD(2, 2)
    K[0][0] = recTau1.Px()
    K[0][1] = recTau2.Px()
    K[1][0] = recTau1.Py()
    K[1][1] = recTau2.Py()

    if K.Determinant() == 0:
        return -1., -1111., -1111.

    M = ROOT.TMatrixD(2, 1)
    M[0][0] = METpx
    M[1][0] = METpy

    Kinv = K.Invert()

    X = Kinv * M

    X1 = X(0, 0)
    X2 = X(1, 0)

    x1 = 1. / (1. + X1)
    x2 = 1. / (1. + X2)

    p1 = recTau1 * (1. / x1)
    p2 = recTau2 * (1. / x2)
    m_col = (p1 + p2).M()
    m_vis = (recTau1 + recTau2).M()

    return m_vis, m_col, x1, x2
Esempio n. 3
0
 def fourvect(self):
     vect = LorentzVector()
     vect.SetPtEtaPhiM(
             self.pt,
             self.eta,
             self.phi,
             self.m)
     #       self._particle.Mass() * GeV)
     return vect
Esempio n. 4
0
 def fourvect_clbased(self):
     vect = LorentzVector()
     tau_numTrack = self.numTrack
     tau_nPi0s = self.pi0_n
     if tau_nPi0s == 0:
         if self.track_n > 0:
             sumTrk = LorentzVector()
             for trk_ind in xrange(0, self.track_n):
                 curTrk = LorentzVector()
                 curTrk.SetPtEtaPhiM(self.track_atTJVA_pt[trk_ind],
                                     self.track_atTJVA_eta[trk_ind],
                                     self.track_atTJVA_phi[trk_ind], 139.8)
                 sumTrk += curTrk
             vect.SetPtEtaPhiM(sumTrk.Pt(), sumTrk.Eta(), sumTrk.Phi(),
                               sumTrk.M())
         else:
             vect.SetPtEtaPhiM(self.pt, self.eta, self.phi, self.m)
     elif tau_nPi0s == 1 or tau_nPi0s == 2:
         if self.pi0_vistau_pt == 0:
             vect.SetPtEtaPhiM(self.pt, self.eta, self.phi, self.m)
         else:
             vect.SetPtEtaPhiM(self.pi0_vistau_pt, self.pi0_vistau_eta,
                               self.pi0_vistau_phi, self.pi0_vistau_m)
     else:
         vect.SetPtEtaPhiM(self.pi0_vistau_pt, self.pi0_vistau_eta,
                           self.pi0_vistau_phi, self.pi0_vistau_m)
     return vect
def transformVars(df):
    '''
    modifies the variables to create the ones that mv2 uses, inserts default values when needed, saves new variables
    in the dataframe
    Args:
    -----
        df: pandas dataframe containing all the interesting variables as extracted from the .root file
    Returns:
    --------
        modified mv2-compliant dataframe
    '''
    from rootpy.vector import LorentzVector, Vector3
    import pandautils as pup

    # -- modify features and set default values
    df['abs(jet_eta)'] = abs(df['jet_eta'])

    # -- create new IPxD features
    for (pu, pb, pc) in zip(df['jet_ip2d_pu'], df['jet_ip2d_pb'],
                            df['jet_ip2d_pc']):
        pu[np.logical_or(pu >= 10, pu < -1)] = -1
        pb[np.logical_or(pu >= 10, pu < -1)] = -1
        pc[np.logical_or(pu >= 10, pu < -1)] = -1
    for (pu, pb, pc) in zip(df['jet_ip3d_pu'], df['jet_ip3d_pb'],
                            df['jet_ip3d_pc']):
        pu[pu >= 10] = -1
        pb[pu >= 10] = -1
        pc[pu >= 10] = -1
    df['jet_ip2'] = (df['jet_ip2d_pb'] / df['jet_ip2d_pu']).apply(
        lambda x: np.log(x)).apply(lambda x: _replaceInfNaN(x, -20))
    df['jet_ip2_c'] = (df['jet_ip2d_pb'] / df['jet_ip2d_pc']).apply(
        lambda x: np.log(x)).apply(lambda x: _replaceInfNaN(x, -20))
    df['jet_ip2_cu'] = (df['jet_ip2d_pc'] / df['jet_ip2d_pu']).apply(
        lambda x: np.log(x)).apply(lambda x: _replaceInfNaN(x, -20))
    df['jet_ip3'] = (df['jet_ip3d_pb'] / df['jet_ip3d_pu']).apply(
        lambda x: np.log(x)).apply(lambda x: _replaceInfNaN(x, -20))
    df['jet_ip3_c'] = (df['jet_ip3d_pb'] / df['jet_ip3d_pc']).apply(
        lambda x: np.log(x)).apply(lambda x: _replaceInfNaN(x, -20))
    df['jet_ip3_cu'] = (df['jet_ip3d_pc'] / df['jet_ip3d_pu']).apply(
        lambda x: np.log(x)).apply(lambda x: _replaceInfNaN(x, -20))

    # -- create new IPMP features
    for (pu, pb, pc) in zip(df['jet_ipmp_pu'], df['jet_ipmp_pb'],
                            df['jet_ipmp_pc']):
        pu[pu >= 10] = -1
        pb[pu >= 10] = -1
        pc[pu >= 10] = -1
    df['jet_ip'] = (df['jet_ipmp_pb'] / df['jet_ipmp_pu']).apply(
        lambda x: np.log(x)).apply(lambda x: _replaceInfNaN(x, -20))
    df['jet_ip_c'] = (df['jet_ipmp_pb'] / df['jet_ipmp_pc']).apply(
        lambda x: np.log(x)).apply(lambda x: _replaceInfNaN(x, -20))
    df['jet_ip_cu'] = (df['jet_ipmp_pc'] / df['jet_ipmp_pu']).apply(
        lambda x: np.log(x)).apply(lambda x: _replaceInfNaN(x, -20))

    # -- SV1 features
    dx = df['jet_sv1_vtx_x'] - df['PVx']
    dy = df['jet_sv1_vtx_y'] - df['PVy']
    dz = df['jet_sv1_vtx_z'] - df['PVz']

    v_jet = LorentzVector()
    pv2sv = Vector3()
    sv1_L3d = []
    sv1_Lxy = []
    dR = []

    for index, dxi in enumerate(dx):  # loop thru events
        sv1_L3d_ev = []
        sv1L_ev = []
        dR_ev = []
        for jet in xrange(len(dxi)):  # loop thru jets
            v_jet.SetPtEtaPhiM(df['jet_pt'][index][jet],
                               df['jet_eta'][index][jet],
                               df['jet_phi'][index][jet],
                               df['jet_m'][index][jet])
            if (dxi[jet].size != 0):
                sv1_L3d_ev.append(
                    np.sqrt(
                        pow(dx[index][jet], 2) + pow(dy[index][jet], 2) +
                        pow(dz[index][jet], 2))[0])
                sv1L_ev.append(math.hypot(dx[index][jet], dy[index][jet]))

                pv2sv.SetXYZ(dx[index][jet], dy[index][jet], dz[index][jet])
                jetAxis = Vector3(v_jet.Px(), v_jet.Py(), v_jet.Pz())
                dR_ev.append(pv2sv.DeltaR(jetAxis))
            else:
                dR_ev.append(-1)
                sv1L_ev.append(-100)
                sv1_L3d_ev.append(-100)

        sv1_Lxy.append(sv1L_ev)
        dR.append(dR_ev)
        sv1_L3d.append(sv1_L3d_ev)

    df['jet_sv1_dR'] = dR
    df['jet_sv1_Lxy'] = sv1_Lxy
    df['jet_sv1_L3d'] = sv1_L3d

    # -- add more default values for sv1 variables
    sv1_vtx_ok = pup.match_shape(
        np.asarray([len(el) for event in df['jet_sv1_vtx_x'] for el in event]),
        df['jet_pt'])

    for (ok4event, sv1_ntkv4event, sv1_n2t4event, sv1_mass4event,
         sv1_efrc4event,
         sv1_sig34event) in zip(sv1_vtx_ok, df['jet_sv1_ntrkv'],
                                df['jet_sv1_n2t'], df['jet_sv1_m'],
                                df['jet_sv1_efc'], df['jet_sv1_sig3d']):
        sv1_ntkv4event[np.asarray(ok4event) == 0] = -1
        sv1_n2t4event[np.asarray(ok4event) == 0] = -1
        sv1_mass4event[np.asarray(ok4event) == 0] = -1000
        sv1_efrc4event[np.asarray(ok4event) == 0] = -1
        sv1_sig34event[np.asarray(ok4event) == 0] = -100

    # -- JF features
    jf_dR = []
    for eventN, (etas, phis, masses) in enumerate(
            zip(df['jet_jf_deta'], df['jet_jf_dphi'],
                df['jet_jf_m'])):  # loop thru events
        jf_dR_ev = []
        for m in xrange(len(masses)):  # loop thru jets
            if (masses[m] > 0):
                jf_dR_ev.append(np.sqrt(etas[m] * etas[m] + phis[m] * phis[m]))
            else:
                jf_dR_ev.append(-10)
        jf_dR.append(jf_dR_ev)
    df['jet_jf_dR'] = jf_dR

    # -- add more default values for jf variables
    for (jf_mass, jf_n2tv, jf_ntrkv, jf_nvtx, jf_nvtx1t, jf_efrc,
         jf_sig3) in zip(df['jet_jf_m'], df['jet_jf_n2t'],
                         df['jet_jf_ntrkAtVx'], df['jet_jf_nvtx'],
                         df['jet_jf_nvtx1t'], df['jet_jf_efc'],
                         df['jet_jf_sig3d']):
        jf_n2tv[jf_mass <= 0] = -1
        jf_ntrkv[jf_mass <= 0] = -1
        jf_nvtx[jf_mass <= 0] = -1
        jf_nvtx1t[jf_mass <= 0] = -1
        jf_mass[jf_mass <= 0] = -1e3
        jf_efrc[jf_mass <= 0] = -1
        jf_sig3[jf_mass <= 0] = -100

    return df
Esempio n. 6
0
def create_dict(nom):
    current = 0

    events = []
    bestScores = []

    nEntries = nom.GetEntries()
    print(nEntries)
    for idx in range(nEntries):
        if idx % 10000 == 0:
            print(str(idx) + '/' + str(nEntries))

        nom.GetEntry(idx)

        higgCand = LorentzVector()

        lep4Vecs = []
        jet4Vecs = []

        btags = []

        met = LorentzVector()
        met.SetPtEtaPhiE(nom.MET_RefFinal_et, 0, nom.MET_RefFinal_phi,
                         nom.MET_RefFinal_et)

        #for i in range(2):
        lep_Pt_0 = nom.lep_Pt_0
        lep_Eta_0 = nom.lep_Eta_0
        lep_Phi_0 = nom.lep_Phi_0
        lep_E_0 = nom.lep_E_0

        lepVec_0 = LorentzVector()
        lepVec_0.SetPtEtaPhiE(lep_Pt_0, lep_Eta_0, lep_Phi_0, lep_E_0)
        lep4Vecs.append(lepVec_0)

        lep_Pt_1 = nom.lep_Pt_1
        lep_Eta_1 = nom.lep_Eta_1
        lep_Phi_1 = nom.lep_Phi_1
        lep_E_1 = nom.lep_E_1

        lepVec_1 = LorentzVector()
        lepVec_1.SetPtEtaPhiE(lep_Pt_1, lep_Eta_1, lep_Phi_1, lep_E_1)
        lep4Vecs.append(lepVec_1)

        for j in range(len(nom.m_pflow_jet_pt)):  #nom.selected_jets'][i]:
            jetVec = LorentzVector()
            jetVec.SetPtEtaPhiM(nom.m_pflow_jet_pt[j], nom.m_pflow_jet_eta[j],
                                nom.m_pflow_jet_phi[j], nom.m_pflow_jet_m[j])
            jet4Vecs.append(jetVec)

            btags.append(nom.m_pflow_jet_flavor_weight_MV2c10[j])

        combos = []
        combosTop = []

        for l in range(len(lep4Vecs)):
            for i in range(len(jet4Vecs) - 1):
                for j in range(i + 1, len(jet4Vecs)):
                    comb = [l, i, j]

                    t = topDict(jet4Vecs[i], jet4Vecs[j], lep4Vecs[0],
                                lep4Vecs[1], met, btags[i], btags[j],
                                nom.m_pflow_jet_jvt[i], nom.m_pflow_jet_jvt[j],
                                nom.m_pflow_jet_numTrk[i],
                                nom.m_pflow_jet_numTrk[j])

                    combosTop.append([t, comb])

        #loop over combinations, score them in the BDT, figure out the best result
        topDF = pd.DataFrame.from_dict([x[0] for x in combosTop])
        topMat = xgb.DMatrix(topDF, feature_names=list(topDF))

        topPred = topModel.predict(topMat)
        topBest = np.argmax(topPred)

        bestTopComb = combosTop[topBest][1]
        topMatches = bestTopComb[1:]

        for l in range(len(lep4Vecs)):
            for i in range(len(jet4Vecs) - 1):
                for j in range(i + 1, len(jet4Vecs)):
                    comb = [l, i, j]

                    if l == 0:
                        k = higgsDict(jet4Vecs[i], jet4Vecs[j], lep4Vecs[l],
                                      met, btags[i], btags[j], lep4Vecs[1],
                                      nom.m_pflow_jet_jvt[i],
                                      nom.m_pflow_jet_jvt[j],
                                      nom.m_pflow_jet_numTrk[i],
                                      nom.m_pflow_jet_numTrk[j])
                    else:
                        k = higgsDict(jet4Vecs[i], jet4Vecs[j], lep4Vecs[l],
                                      met, btags[i], btags[j], lep4Vecs[0],
                                      nom.m_pflow_jet_jvt[i],
                                      nom.m_pflow_jet_jvt[j],
                                      nom.m_pflow_jet_numTrk[i],
                                      nom.m_pflow_jet_numTrk[j])

                    combos.append([k, comb])

        ###Evaluate higgsTop BDT
        df = pd.DataFrame.from_dict([x[0] for x in combos])
        xgbMat = xgb.DMatrix(df, feature_names=list(df))

        pred = xgbModel.predict(xgbMat)
        best = np.argmax(pred)

        bestScores.append(pred[best])

        bestComb = combos[best][1]
        lepMatch = bestComb[0]
        jetMatches = bestComb[1:]

        k = {}
        #k['higgs_pt'] = nom.higgs_pt
        k['comboScore'] = pred[best]
        k['topScore'] = topPred[topBest]

        if lepMatch == 0:
            k['lep_Pt_H'] = nom.lep_Pt_0
            k['lep_Eta_H'] = nom.lep_Eta_0
            phi_0 = nom.lep_Phi_0
            k['lep_E_H'] = nom.lep_E_0

            k['lep_Pt_O'] = nom.lep_Pt_1
            k['lep_Eta_O'] = nom.lep_Eta_1
            k['lep_Phi_O'] = calc_phi(phi_0, nom.lep_Phi_1)
            k['lep_E_O'] = nom.lep_E_1

        elif lepMatch == 1:
            k['lep_Pt_H'] = nom.lep_Pt_1
            k['lep_Eta_H'] = nom.lep_Eta_1
            phi_0 = nom.lep_Phi_1
            k['lep_E_H'] = nom.lep_E_1

            k['lep_Pt_O'] = nom.lep_Pt_0
            k['lep_Eta_O'] = nom.lep_Eta_0
            k['lep_Phi_O'] = calc_phi(phi_0, nom.lep_Phi_0)
            k['lep_E_O'] = nom.lep_E_0

        n = 0
        for i in jetMatches:  #nom.nJets_OR_T):

            k['jet_Pt_h' + str(n)] = nom.m_pflow_jet_pt[i]
            k['jet_Eta_h' + str(n)] = nom.m_pflow_jet_eta[i]
            k['jet_E_h' + str(n)] = jet4Vecs[i].E()  #nom.m_pflow_jet_E[i]
            k['jet_Phi_h' + str(n)] = calc_phi(phi_0, nom.m_pflow_jet_phi[i])
            k['jet_MV2c10_h' +
              str(n)] = nom.m_pflow_jet_flavor_weight_MV2c10[i]

            n += 1

        btags = np.array(btags)

        btags[jetMatches[0]] = 0
        btags[jetMatches[1]] = 0
        bestBtags = np.argpartition(btags, -2)[-2:]

        n = 0
        for i in topMatches:  #bestBtags:#nom.nJets_OR_T):
            k['top_Pt_' + str(n)] = nom.m_pflow_jet_pt[i]
            k['top_Eta_' + str(n)] = nom.m_pflow_jet_eta[i]
            k['top_E_' + str(n)] = jet4Vecs[i].E()  #nom.m_pflow_jet_E[i]
            k['top_Phi_' + str(n)] = calc_phi(phi_0, nom.m_pflow_jet_phi[i])
            k['top_MV2c10_' + str(n)] = nom.m_pflow_jet_flavor_weight_MV2c10[i]

            n += 1

        k['MET'] = nom.MET_RefFinal_et
        k['MET_phi'] = calc_phi(phi_0, nom.MET_RefFinal_phi)

        events.append(k)

    return events
Esempio n. 7
0
 def fourvect(self):
     vect = LorentzVector()
     vect.SetPtEtaPhiM(self.pt * GeV, self.eta, self.phi, self.m)
     return vect
Esempio n. 8
0
 def getTruthVis4Vector(self):
     """Get the LorentzVector for the visible truth tau """
     vector = LorentzVector()
     vector.SetPtEtaPhiM(self.vis_Et, self.vis_eta, self.vis_phi,
                         self.vis_m)
     return vector
Esempio n. 9
0
def create_dict(nom):
    current = 0

    events1l = []
    events2l = []
    decayDicts = []
    bestScores = []

    nEntries = nom.GetEntries()
    for idx in range(nEntries):
        if idx % 10000 == 0:
            print(str(idx) + '/' + str(nEntries))
            #if current%100000==0:
            #break
        nom.GetEntry(idx)

        higgCand = LorentzVector()

        lep4Vecs = []
        jet4Vecs = []

        btags = []

        met = LorentzVector()
        met.SetPtEtaPhiE(nom.MET_RefFinal_et, 0, nom.MET_RefFinal_phi,
                         nom.MET_RefFinal_et)

        lepVec_0 = LorentzVector()
        lepVec_0.SetPtEtaPhiE(nom.lep_Pt_0, nom.lep_Eta_0, nom.lep_Phi_0,
                              nom.lep_E_0)
        lep4Vecs.append(lepVec_0)

        lepVec_1 = LorentzVector()
        lepVec_1.SetPtEtaPhiE(nom.lep_Pt_1, nom.lep_Eta_1, nom.lep_Phi_1,
                              nom.lep_E_1)
        lep4Vecs.append(lepVec_1)

        lepVec_2 = LorentzVector()
        lepVec_2.SetPtEtaPhiE(nom.lep_Pt_2, nom.lep_Eta_2, nom.lep_Phi_2,
                              nom.lep_E_2)
        lep4Vecs.append(lepVec_2)

        for j in range(len(nom.m_pflow_jet_pt)):  #nom.selected_jets'][i]:
            jetVec = LorentzVector()
            jetVec.SetPtEtaPhiM(nom.m_pflow_jet_pt[j], nom.m_pflow_jet_eta[j],
                                nom.m_pflow_jet_phi[j], nom.m_pflow_jet_m[j])
            jet4Vecs.append(jetVec)

            btags.append(nom.m_pflow_jet_flavor_weight_MV2c10[j])

        combosTop = []

        for l in range(len(lep4Vecs)):
            for i in range(len(jet4Vecs) - 1):
                for j in range(i + 1, len(jet4Vecs)):
                    comb = [l, i, j]

                    t = topDict(jet4Vecs[i], jet4Vecs[j], lep4Vecs[0],
                                lep4Vecs[1], lep4Vecs[2], met, btags[i],
                                btags[j], nom.m_pflow_jet_jvt[i],
                                nom.m_pflow_jet_jvt[j],
                                nom.m_pflow_jet_numTrk[i],
                                nom.m_pflow_jet_numTrk[j])

                    combosTop.append([t, comb])

        #loop over combinations, score them in the BDT, figure out the best result
        topDF = pd.DataFrame.from_dict([x[0] for x in combosTop])
        topMat = xgb.DMatrix(topDF, feature_names=list(topDF))

        topPred = topModel.predict(topMat)
        topBest = np.argmax(topPred)

        bestTopComb = combosTop[topBest][1]
        topMatches = bestTopComb[1:]

        combos1l = []

        for l in range(1, len(lep4Vecs)):
            for i in range(len(jet4Vecs) - 1):
                for j in range(i + 1, len(jet4Vecs)):
                    comb = [l, i, j]
                    if l == 1:
                        k = higgs1lDict(
                            jet4Vecs[i], jet4Vecs[j], lep4Vecs[l], met,
                            nom.m_pflow_jet_flavor_weight_MV2c10[i],
                            nom.m_pflow_jet_flavor_weight_MV2c10[j],
                            lep4Vecs[0], lep4Vecs[2], nom.m_pflow_jet_jvt[i],
                            nom.m_pflow_jet_jvt[j], nom.m_pflow_jet_numTrk[i],
                            nom.m_pflow_jet_numTrk[j])
                    else:
                        k = higgs1lDict(
                            jet4Vecs[i], jet4Vecs[j], lep4Vecs[l], met,
                            nom.m_pflow_jet_flavor_weight_MV2c10[i],
                            nom.m_pflow_jet_flavor_weight_MV2c10[j],
                            lep4Vecs[0], lep4Vecs[1], nom.m_pflow_jet_jvt[i],
                            nom.m_pflow_jet_jvt[j], nom.m_pflow_jet_numTrk[i],
                            nom.m_pflow_jet_numTrk[j])

                    combos1l.append([k, comb])

        combos2l = []

        possCombs = [[0, 1, 2], [0, 2, 1]]
        for comb in possCombs:
            k = higgs2lDict(lep4Vecs[comb[0]], lep4Vecs[comb[1]],
                            lep4Vecs[comb[2]], met)
            combos2l.append([k, [comb[0], comb[1]]])

        #Run 2l XGB, find best match
        df2l = pd.DataFrame.from_dict([x[0] for x in combos2l])
        xgbMat2l = xgb.DMatrix(df2l, feature_names=list(df2l))

        pred2l = higgs2lModel.predict(xgbMat2l)
        best2l = np.argmax(pred2l)

        bestComb2l = combos2l[best2l][1]
        lepMatch2l = bestComb2l[1]

        #Run 1l XGB, find best match
        df1l = pd.DataFrame.from_dict([x[0] for x in combos1l])
        xgbMat1l = xgb.DMatrix(df1l, feature_names=list(df1l))

        pred1l = higgs1lModel.predict(xgbMat1l)
        best1l = np.argmax(pred1l)

        bestComb1l = combos1l[best1l][1]
        lepMatch1l = bestComb1l[0]
        jetMatches1l = bestComb1l[1:]

        ### Add decay dict

        k = decayDict(lep4Vecs[0], lep4Vecs[1], lep4Vecs[2], met,
                      jet4Vecs[topMatches[0]], jet4Vecs[topMatches[1]])
        k['nJets'] = nom.nJets_OR_T
        k['nJets_MV2c10_70'] = nom.nJets_OR_T_MV2c10_70
        k['higgs2l_score'] = pred2l[best2l]
        k['higgs1l_score'] = pred1l[best1l]
        decayDicts.append(k)

        ### Add 2l pt prediction dict

        q = {}
        q['comboScore'] = pred2l[best2l]

        if lepMatch2l == 1:
            q['lep_Pt_0'] = nom.lep_Pt_0
            q['lep_Eta_0'] = nom.lep_Eta_0
            phi_0 = nom.lep_Phi_0
            q['lep_E_0'] = nom.lep_E_0

            q['lep_Pt_1'] = nom.lep_Pt_1
            q['lep_Eta_1'] = nom.lep_Eta_1
            q['lep_Phi_1'] = calc_phi(phi_0, nom.lep_Phi_1)
            q['lep_E_1'] = nom.lep_E_1

            q['lep_Pt_2'] = nom.lep_Pt_2
            q['lep_Eta_2'] = nom.lep_Eta_2
            q['lep_Phi_2'] = calc_phi(phi_0, nom.lep_Phi_2)
            q['lep_E_2'] = nom.lep_E_2

        elif lepMatch2l == 2:
            q['lep_Pt_0'] = nom.lep_Pt_0
            q['lep_Eta_0'] = nom.lep_Eta_0
            phi_0 = nom.lep_Phi_0
            q['lep_E_0'] = nom.lep_E_0

            q['lep_Pt_1'] = nom.lep_Pt_2
            q['lep_Eta_1'] = nom.lep_Eta_2
            q['lep_Phi_1'] = calc_phi(phi_0, nom.lep_Phi_2)
            q['lep_E_1'] = nom.lep_E_2

            q['lep_Pt_2'] = nom.lep_Pt_1
            q['lep_Eta_2'] = nom.lep_Eta_1
            q['lep_Phi_2'] = calc_phi(phi_0, nom.lep_Phi_1)
            q['lep_E_2'] = nom.lep_E_1

        n = 0
        for i in topMatches:
            q['top_Pt_' + str(n)] = nom.m_pflow_jet_pt[i]
            q['top_Eta_' + str(n)] = nom.m_pflow_jet_eta[i]
            q['top_E_' + str(n)] = jet4Vecs[i].E()  #nom.m_pflow_jet_E[i]
            q['top_Phi_' + str(n)] = calc_phi(phi_0, nom.m_pflow_jet_phi[i])
            q['top_MV2c10_' + str(n)] = nom.m_pflow_jet_flavor_weight_MV2c10[i]

            n += 1

        q['MET'] = nom.MET_RefFinal_et
        q['MET_phi'] = calc_phi(phi_0, nom.MET_RefFinal_phi)

        events2l.append(q)

        ### Add 1l Pt prediction dict

        y = {}
        #y['higgs_pt'] = nom.higgs_pt
        y['comboScore'] = pred1l[best1l]

        if lepMatch1l == 1:
            y['lep_Pt_H'] = nom.lep_Pt_1
            y['lep_Eta_H'] = nom.lep_Eta_1
            phi_0 = nom.lep_Phi_1
            y['lep_E_H'] = nom.lep_E_1

            y['lep_Pt_0'] = nom.lep_Pt_0
            y['lep_Eta_0'] = nom.lep_Eta_0
            y['lep_Phi_0'] = calc_phi(phi_0, nom.lep_Phi_0)
            y['lep_E_0'] = nom.lep_E_0

            y['lep_Pt_1'] = nom.lep_Pt_2
            y['lep_Eta_1'] = nom.lep_Eta_2
            y['lep_Phi_1'] = calc_phi(phi_0, nom.lep_Phi_2)
            y['lep_E_1'] = nom.lep_E_2

        elif lepMatch1l == 2:
            y['lep_Pt_H'] = nom.lep_Pt_2
            y['lep_Eta_H'] = nom.lep_Eta_2
            phi_0 = nom.lep_Phi_2
            y['lep_E_H'] = nom.lep_E_2

            y['lep_Pt_0'] = nom.lep_Pt_0
            y['lep_Eta_0'] = nom.lep_Eta_0
            y['lep_Phi_0'] = calc_phi(phi_0, nom.lep_Phi_0)
            y['lep_E_0'] = nom.lep_E_0

            y['lep_Pt_1'] = nom.lep_Pt_1
            y['lep_Eta_1'] = nom.lep_Eta_1
            y['lep_Phi_1'] = calc_phi(phi_0, nom.lep_Phi_1)
            y['lep_E_1'] = nom.lep_E_1

        n = 0
        for i in jetMatches1l:  #nom.nJets_OR_T):

            y['jet_Pt_h' + str(n)] = nom.m_pflow_jet_pt[i]
            y['jet_Eta_h' + str(n)] = nom.m_pflow_jet_eta[i]
            y['jet_E_h' + str(n)] = jet4Vecs[i].E()  #nom.m_pflow_jet_E[i]
            y['jet_Phi_h' + str(n)] = calc_phi(phi_0, nom.m_pflow_jet_phi[i])
            y['jet_MV2c10_h' +
              str(n)] = nom.m_pflow_jet_flavor_weight_MV2c10[i]

            n += 1

        n = 0
        for i in topMatches:  #bestBtags:#nom.nJets_OR_T):
            y['top_Pt_' + str(n)] = nom.m_pflow_jet_pt[i]
            y['top_Eta_' + str(n)] = nom.m_pflow_jet_eta[i]
            y['top_E_' + str(n)] = jet4Vecs[i].E()  #nom.m_pflow_jet_E[i]
            y['top_Phi_' + str(n)] = calc_phi(phi_0, nom.m_pflow_jet_phi[i])
            y['top_MV2c10_' + str(n)] = nom.m_pflow_jet_flavor_weight_MV2c10[i]

            n += 1

        y['MET'] = nom.MET_RefFinal_et
        y['MET_phi'] = calc_phi(phi_0, nom.MET_RefFinal_phi)

        events1l.append(y)

    return decayDicts, events1l, events2l