Example #1
0
def calculate_variables(df):
    '''
    calculate additional variables needed
    '''

    df[name+"_dPhiGen_0"]  = common.get_dPhi(df[name+"_AddB1_Phi"].values, df["AdditionalGenBJet_Phi[0]"].values)
    df[name+"_dPhiGen_1"]  = common.get_dPhi(df[name+"_AddB2_Phi"].values, df["AdditionalGenBJet_Phi[1]"].values)
    df[name+"_dEtaGen_0"]  = abs(df[name+"_AddB1_Eta"].values - df["AdditionalGenBJet_Eta[0]"].values)
    df[name+"_dEtaGen_1"]  = abs(df[name+"_AddB2_Eta"].values - df["AdditionalGenBJet_Eta[1]"].values)
    df[name+"_dRGen_0"] = np.sqrt(df[name+"_dPhiGen_0"].values**2 + df[name+"_dEtaGen_0"].values**2)
    df[name+"_dRGen_1"] = np.sqrt(df[name+"_dPhiGen_1"].values**2 + df[name+"_dEtaGen_1"].values**2)

    
    df[name+"_bb_dPhi"] = common.get_dPhi(df[name+"_AddB1_Phi"].values, df[name+"_AddB2_Phi"])
    df[name+"_bb_dEta"] = abs(df[name+"_AddB1_Eta"].values - df[name+"_AddB2_Eta"])
    df[name+"_bb_dPt"] = abs(df[name+"_AddB1_Pt"].values - df[name+"_AddB2_Pt"])
    df[name+"_bb_dR"]   = np.sqrt(df[name+"_bb_dPhi"].values**2 + df[name+"_bb_dEta"].values**2)
    df[name+"_bb_dKin"] = np.sqrt( (df[name+"_bb_dPhi"].values/(2.*np.pi))**2 + \
                                   (df[name+"_bb_dEta"].values/5.)**2 + \
                                   (df[name+"_bb_dPt"].values/1000.)**2 )

    vectors = common.Vectors(df, name, ["AddB1", "AddB2"])
    vectors.add(["AddB1", "AddB2"], out = "bb")

    df[name+"_bb_Pt"]  = vectors.get("bb", "Pt")
    df[name+"_bb_Eta"] = vectors.get("bb", "Eta")
    df[name+"_bb_M"]   = vectors.get("bb", "M")
    df[name+"_bb_E"]   = vectors.get("bb", "E")
    
    df[name+"_bb_openingAngle"] = vectors.getOpeningAngle("AddB1", "AddB2")

    vectors.initIndexedVector(df, "TightLepton", 0)
    vectors.addNeutrino(df, "Evt_MET_Pt", "Evt_MET_Phi", "TightLepton_0")
    #vectors.add(["TightLepton", "nu"], out = "lepW")

    vectors.add(["TightLepton_0", "nu", "AddB1"], out = "lepTop1")
    vectors.add(["TightLepton_0", "nu", "AddB2"], out = "lepTop2")

    #df[name+"_lepW_Pt"] = vectors.get("lepW", "Pt")
    #df[name+"_lepW_M"]  = vectors.get("lepW", "M")

    df[name+"_lepTop1_Pt"]  = vectors.get("lepTop1", "Pt")
    df[name+"_lepTop1_Eta"] = vectors.get("lepTop1", "Eta")
    df[name+"_lepTop1_M"]   = vectors.get("lepTop1", "M")
    df[name+"_lepTop1_E"]   = vectors.get("lepTop1", "E")

    df[name+"_lepTop2_Pt"]  = vectors.get("lepTop2", "Pt")
    df[name+"_lepTop2_Eta"] = vectors.get("lepTop2", "Eta")
    df[name+"_lepTop2_M"]   = vectors.get("lepTop2", "M")
    df[name+"_lepTop2_E"]   = vectors.get("lepTop2", "E")

    return df
Example #2
0
def calculate_variables(df):
    '''
    calculate additional variables needed
    '''

    # get vectors to build top quarks
    vectors = common.Vectors(df, name, ["HadTopB", "LepTopB"])

    # leptonic top quark
    vectors.initIndexedVector(df, "TightLepton", 0)
    vectors.add(["TightLepton_0", "LepTopB"], out="LepTop")

    # get ttbar b system
    vectors.add(["HadTopB", "LepTopB"], out="bb")

    # write ttbar variables to dataframe
    df[name + "_lepBhadB_M"] = vectors.get("bb", "M")

    df[name + "_lepBhadB_openingAngle"] = vectors.getOpeningAngle(
        "HadTopB", "LepTopB")

    # get dR values of jets
    df[name + "_dRGen_LepTopB"] = common.get_dR(
        eta1=df[name + "_LepTopB_Eta"].values,
        phi1=df[name + "_LepTopB_Phi"].values,
        eta2=df["GenTopLep_B_Eta[0]"].values,
        phi2=df["GenTopLep_B_Phi[0]"].values)

    df[name + "_dRGen_HadTopB"] = common.get_dR(
        eta1=df[name + "_HadTopB_Eta"].values,
        phi1=df[name + "_HadTopB_Phi"].values,
        eta2=df["GenTopHad_B_Eta[0]"].values,
        phi2=df["GenTopHad_B_Phi[0]"].values)

    # b kinematic differences
    df[name + "_lepBhadB_dPhi"] = common.get_dPhi(
        df[name + "_LepTopB_Phi"].values, df[name + "_HadTopB_Phi"].values)

    df[name + "_lepBhadB_dEta"] = common.get_dPhi(
        df[name + "_LepTopB_Eta"].values, df[name + "_HadTopB_Eta"].values)

    df[name+"_lepBhadB_dR"] = np.sqrt(
        df[name+"_lepBhadB_dEta"].values**2 + \
        df[name+"_lepBhadB_dPhi"].values**2)

    return df
def calculate_variables(df):
    '''
    calculate additional variables needed for DNN input
    '''

    # angular differences
    df[name + "_H_dPhi"] = common.get_dPhi(df[name + "_B1_Phi"].values,
                                           df[name + "_B2_Phi"].values)
    df[name + "_H_dEta"] = abs(df[name + "_B1_Eta"].values -
                               df[name + "_B2_Eta"].values)
    df[name + "_H_dPt"] = abs(df[name + "_B1_Pt"].values -
                              df[name + "_B2_Pt"].values)
    df[name + "_H_dR"] = np.sqrt(df[name + "_H_dEta"].values**2 +
                                 df[name + "_H_dPhi"].values**2)
    df[name+"_H_dKin"] = np.sqrt((df[name+"_H_dEta"].values/5.)**2 + \
                                (df[name+"_H_dPhi"].values/(2.*np.pi))**2 + \
                                (df[name+"_H_dPt"].values/1000.))

    # reconstruct Higgs boson
    vectors = common.Vectors(df, name, ["B1", "B2"])
    vectors.add(["B1", "B2"], out="H")

    df[name + "_H_Pt"] = vectors.get("H", "Pt")
    df[name + "_H_Eta"] = vectors.get("H", "Eta")
    df[name + "_H_M"] = vectors.get("H", "M")
    df[name + "_H_E"] = vectors.get("H", "E")

    # log values
    for obj in ["B1", "B2", "H"]:
        df[name + "_" + obj + "_logPt"] = np.log(df[name + "_" + obj +
                                                    "_Pt"].values)
        df[name + "_" + obj + "_logM"] = np.log(df[name + "_" + obj +
                                                   "_M"].values)
        df[name + "_" + obj + "_logE"] = np.log(df[name + "_" + obj +
                                                   "_E"].values)

    # 3D opening angle
    df[name + "_H_openingAngle"] = vectors.getOpeningAngle("B1", "B2")

    # boost
    vectors.boost(["B1", "B2", "H"], frame="H")

    # add boosted variables
    for obj in ["B1", "B2", "H"]:
        df[name + "_" + obj + "_Pt_boosted"] = vectors.get(obj,
                                                           "Pt",
                                                           boostFrame="H")
        df[name + "_" + obj + "_M_boosted"] = vectors.get(obj,
                                                          "M",
                                                          boostFrame="H")
        df[name + "_" + obj + "_E_boosted"] = vectors.get(obj,
                                                          "E",
                                                          boostFrame="H")
        df[name + "_" + obj + "_Eta_boosted"] = vectors.get(obj,
                                                            "Eta",
                                                            boostFrame="H")
        df[name + "_" + obj + "_Phi_boosted"] = vectors.get(obj,
                                                            "Phi",
                                                            boostFrame="H")

        df[name + "_" + obj + "_logPt_boosted"] = np.log(df[name + "_" + obj +
                                                            "_Pt_boosted"])

    # boosted angular differences
    df[name + "_dPhi_boosted"] = common.get_dPhi(
        df[name + "_B1_Phi_boosted"].values,
        df[name + "_B2_Phi_boosted"].values)
    df[name + "_dEta_boosted"] = abs(df[name + "_B1_Eta_boosted"].values -
                                     df[name + "_B2_Eta_boosted"].values)
    df[name + "_dR_boosted"] = np.sqrt(df[name + "_dEta_boosted"].values**2 +
                                       df[name + "_dPhi_boosted"].values**2)

    df[name + "_dRGen_Higgs_genB1_recoB1"] = common.get_dR(
        eta1=df["GenHiggs_B1_Eta"].values,
        phi1=df["GenHiggs_B1_Phi"].values,
        eta2=df[name + "_B1_Eta"].values,
        phi2=df[name + "_B1_Phi"].values)

    df[name + "_dRGen_Higgs_genB2_recoB2"] = common.get_dR(
        eta1=df["GenHiggs_B2_Eta"].values,
        phi1=df["GenHiggs_B2_Phi"].values,
        eta2=df[name + "_B2_Eta"].values,
        phi2=df[name + "_B2_Phi"].values)

    df[name + "_dRGen_Higgs_genB1_recoB2"] = common.get_dR(
        eta1=df["GenHiggs_B1_Eta"].values,
        phi1=df["GenHiggs_B1_Phi"].values,
        eta2=df[name + "_B2_Eta"].values,
        phi2=df[name + "_B2_Phi"].values)

    df[name + "_dRGen_Higgs_genB2_recoB1"] = common.get_dR(
        eta1=df["GenHiggs_B2_Eta"].values,
        phi1=df["GenHiggs_B2_Phi"].values,
        eta2=df[name + "_B1_Eta"].values,
        phi2=df[name + "_B1_Phi"].values)
    return df
Example #4
0
def calculate_variables(df):
    '''
    calculate additional variables needed
    '''

    # get vectors to build top quarks
    vectors = common.Vectors(df, name,
                             ["HadTopB", "HadTopQ1", "HadTopQ2", "LepTopB"])

    # hadronic top quark
    vectors.add(["HadTopQ1", "HadTopQ2"], out="HadW")
    vectors.add(["HadTopB", "HadTopQ1", "HadTopQ2"], out="HadTop")

    # leptonic top quark
    vectors.initIndexedVector(df, "TightLepton", 0)
    vectors.addNeutrino(df, "Evt_MET_Pt", "Evt_MET_Phi", "TightLepton_0")
    vectors.add(["TightLepton_0", "nu", "LepTopB"], out="LepTop")

    # get ttbar system
    vectors.add(["HadTop", "LepTop"], out="ttbar")

    # write ttbar variables to dataframe
    df[name + "_ttbar_Pt"] = vectors.get("ttbar", "Pt")
    df[name + "_ttbar_Eta"] = vectors.get("ttbar", "Eta")
    df[name + "_ttbar_M"] = vectors.get("ttbar", "M")
    df[name + "_ttbar_E"] = vectors.get("ttbar", "E")

    df[name + "_ttbar_openingAngle"] = vectors.getOpeningAngle(
        "HadTop", "LepTop")

    # write top variables to dataframe
    df[name + "_LepTop_Pt"] = vectors.get("LepTop", "Pt")
    df[name + "_LepTop_Eta"] = vectors.get("LepTop", "Eta")
    df[name + "_LepTop_M"] = vectors.get("LepTop", "M")
    df[name + "_LepTop_E"] = vectors.get("LepTop", "E")
    df[name + "_LepTop_Phi"] = vectors.get("LepTop", "Phi")

    df[name + "_HadTop_Pt"] = vectors.get("HadTop", "Pt")
    df[name + "_HadTop_Eta"] = vectors.get("HadTop", "Eta")
    df[name + "_HadTop_M"] = vectors.get("HadTop", "M")
    df[name + "_HadTop_E"] = vectors.get("HadTop", "E")
    df[name + "_HadTop_Phi"] = vectors.get("HadTop", "Phi")

    # mass corrections
    df["GenTopHad_massCorrection"] = df["GenTopHad_M[0]"].values / (
        df[name + "_HadTop_M"].values + 1e-10)
    df["GenTopLep_massCorrection"] = df["GenTopLep_M[0]"].values / (
        df[name + "_LepTop_M"].values + 1e-10)

    # get dR values of gen and reco top quarks
    df[name + "_dRGen_HadTop"] = common.get_dR(
        eta1=df[name + "_HadTop_Eta"].values,
        phi1=df[name + "_HadTop_Phi"].values,
        eta2=df["GenTopHad_Eta[0]"].values,
        phi2=df["GenTopHad_Phi[0]"].values)

    df[name + "_dRGen_LepTop"] = common.get_dR(
        eta1=df[name + "_LepTop_Eta"].values,
        phi1=df[name + "_LepTop_Phi"].values,
        eta2=df["GenTopLep_Eta[0]"].values,
        phi2=df["GenTopLep_Phi[0]"].values)

    # get dR values of jets
    df[name + "_dRGen_LepTopB"] = common.get_dR(
        eta1=df[name + "_LepTopB_Eta"].values,
        phi1=df[name + "_LepTopB_Phi"].values,
        eta2=df["GenTopLep_B_Eta[0]"].values,
        phi2=df["GenTopLep_B_Phi[0]"].values)

    df[name + "_dRGen_HadTopB"] = common.get_dR(
        eta1=df[name + "_HadTopB_Eta"].values,
        phi1=df[name + "_HadTopB_Phi"].values,
        eta2=df["GenTopHad_B_Eta[0]"].values,
        phi2=df["GenTopHad_B_Phi[0]"].values)

    df[name + "_dRGen_HadTopQ1"] = common.get_dR(
        eta1=df[name + "_HadTopQ1_Eta"].values,
        phi1=df[name + "_HadTopQ1_Phi"].values,
        eta2=df["GenTopHad_Q1_Eta[0]"].values,
        phi2=df["GenTopHad_Q1_Phi[0]"].values)

    df[name + "_dRGen_HadTopQ2"] = common.get_dR(
        eta1=df[name + "_HadTopQ2_Eta"].values,
        phi1=df[name + "_HadTopQ2_Phi"].values,
        eta2=df["GenTopHad_Q2_Eta[0]"].values,
        phi2=df["GenTopHad_Q2_Phi[0]"].values)

    # ttbar kinematic differences
    df[name + "_ttbar_dPhi"] = common.get_dPhi(df[name + "_LepTop_Phi"].values,
                                               df[name + "_HadTop_Phi"].values)

    df[name + "_ttbar_dEta"] = common.get_dPhi(df[name + "_HadTop_Eta"].values,
                                               df[name + "_LepTop_Eta"].values)

    df[name+"_ttbar_dPt"] = abs(
        df[name+"_HadTop_Pt"].values - \
        df[name+"_LepTop_Pt"].values)

    df[name+"_ttbar_dR"] = np.sqrt(
        df[name+"_ttbar_dEta"].values**2 + \
        df[name+"_ttbar_dPhi"].values**2)

    df[name+"_ttbar_dKin"] = np.sqrt(
        (df[name+"_ttbar_dPhi"].values/(2.*np.pi))**2 + \
        (df[name+"_ttbar_dEta"].values/(5.))**2 + \
        (df[name+"_ttbar_dPt"].values/(1000.))**2)

    #addbb system
    df[name + "_dPhiGen_0"] = common.get_dPhi(
        df[name + "_AddB1_Phi"].values, df["AdditionalGenBJet_Phi[0]"].values)
    df[name + "_dPhiGen_1"] = common.get_dPhi(
        df[name + "_AddB2_Phi"].values, df["AdditionalGenBJet_Phi[1]"].values)
    df[name + "_dEtaGen_0"] = abs(df[name + "_AddB1_Eta"].values -
                                  df["AdditionalGenBJet_Eta[0]"].values)
    df[name + "_dEtaGen_1"] = abs(df[name + "_AddB2_Eta"].values -
                                  df["AdditionalGenBJet_Eta[1]"].values)
    df[name + "_dRGen_0"] = np.sqrt(df[name + "_dPhiGen_0"].values**2 +
                                    df[name + "_dEtaGen_0"].values**2)
    df[name + "_dRGen_1"] = np.sqrt(df[name + "_dPhiGen_1"].values**2 +
                                    df[name + "_dEtaGen_1"].values**2)

    df[name + "_bb_dPhi"] = common.get_dPhi(df[name + "_AddB1_Phi"].values,
                                            df[name + "_AddB2_Phi"])
    df[name + "_bb_dEta"] = abs(df[name + "_AddB1_Eta"].values -
                                df[name + "_AddB2_Eta"])
    df[name + "_bb_dPt"] = abs(df[name + "_AddB1_Pt"].values -
                               df[name + "_AddB2_Pt"])
    df[name + "_bb_dR"] = np.sqrt(df[name + "_bb_dPhi"].values**2 +
                                  df[name + "_bb_dEta"].values**2)
    df[name+"_bb_dKin"] = np.sqrt( (df[name+"_bb_dPhi"].values/(2.*np.pi))**2 + \
                                   (df[name+"_bb_dEta"].values/5.)**2 + \
                                   (df[name+"_bb_dPt"].values/1000.)**2 )

    vectors = common.Vectors(df, name, ["AddB1", "AddB2"])
    vectors.add(["AddB1", "AddB2"], out="bb")

    df[name + "_bb_Pt"] = vectors.get("bb", "Pt")
    df[name + "_bb_Eta"] = vectors.get("bb", "Eta")
    df[name + "_bb_M"] = vectors.get("bb", "M")
    df[name + "_bb_E"] = vectors.get("bb", "E")

    vectors.initIndexedVector(df, "AdditionalGenBJet", 0)
    vectors.initIndexedVector(df, "AdditionalGenBJet", 1)
    vectors.add(["AdditionalGenBJet_0", "AdditionalGenBJet_1"], out="genbb")

    df[name + "_genbb_Pt"] = vectors.get("genbb", "Pt")
    df[name + "_genbb_Eta"] = vectors.get("genbb", "Eta")
    df[name + "_genbb_M"] = vectors.get("genbb", "M")
    df[name + "_genbb_E"] = vectors.get("genbb", "E")

    df[name + "_genbb_dPhi"] = common.get_dPhi(
        df["AdditionalGenBJet_Phi[0]"].values,
        df["AdditionalGenBJet_Phi[1]"].values)
    df[name + "_genbb_dEta"] = abs(df["AdditionalGenBJet_Eta[0]"].values -
                                   df["AdditionalGenBJet_Eta[1]"].values)
    df[name + "_genbb_dPt"] = abs(df["AdditionalGenBJet_Pt[0]"].values -
                                  df["AdditionalGenBJet_Pt[1]"])
    df[name + "_genbb_dR"] = np.sqrt(df[name + "_genbb_dPhi"].values**2 +
                                     df[name + "_genbb_dEta"].values**2)
    df[name+"_genbb_dKin"] = np.sqrt( (df[name+"_genbb_dPhi"].values/(2.*np.pi))**2 + \
                                   (df[name+"_genbb_dEta"].values/5.)**2 + \
                                   (df[name+"_genbb_dPt"].values/1000.)**2 )

    return df
Example #5
0
def calculate_variables(df):
    '''
    calculate additional variables needed
    '''

    # genZ vectors
    genvecs = common.Vectors(df, "GenZ", ["B1", "B2"])
    genvecs.add(["B1", "B2"], out="Z")
    df["GenZ_Z_M"] = genvecs.get("Z", "M")

    # recoZ vectors
    vectors = common.Vectors(df, name, ["B1", "B2"])
    vectors.add(["B1", "B2"], out="Z")

    # recoZ variables to df
    df[name + "_Z_Pt"] = vectors.get("Z", "Pt")
    df[name + "_Z_Eta"] = vectors.get("Z", "Eta")
    df[name + "_Z_M"] = vectors.get("Z", "M")
    df[name + "_Z_E"] = vectors.get("Z", "E")

    # correction for Z mass
    df["GenZ_Z_massCorrection"] = df["GenZ_Z_M"].values / (
        df[name + "_Z_M"].values + 1e-10)

    # generator Z opening angle
    df[name + "_Z_openingAngle"] = vectors.getOpeningAngle("B1", "B2")
    df["GenZ_Z_openingAngle"] = genvecs.getOpeningAngle("B1", "B2")

    # kinematic features of Z constituents
    df[name + "_B1_Pt"] = vectors.get("B1", "Pt")
    df[name + "_B1_Eta"] = vectors.get("B1", "Eta")
    df[name + "_B1_M"] = vectors.get("B1", "M")
    df[name + "_B1_E"] = vectors.get("B1", "E")
    df[name + "_B1_Phi"] = vectors.get("B1", "Phi")

    df[name + "_B2_Pt"] = vectors.get("B2", "Pt")
    df[name + "_B2_Eta"] = vectors.get("B2", "Eta")
    df[name + "_B2_M"] = vectors.get("B2", "M")
    df[name + "_B2_E"] = vectors.get("B2", "E")
    df[name + "_B2_Phi"] = vectors.get("B2", "Phi")

    # get dR values of gen and reco top quarks
    df[name + "_dRGen_B1"] = common.get_dR(eta1=df[name + "_B1_Eta"].values,
                                           phi1=df[name + "_B1_Phi"].values,
                                           eta2=df["GenZ_B1_Eta"].values,
                                           phi2=df["GenZ_B1_Phi"].values)

    df[name + "_dRGen_B2"] = common.get_dR(eta1=df[name + "_B2_Eta"].values,
                                           phi1=df[name + "_B2_Phi"].values,
                                           eta2=df["GenZ_B2_Eta"].values,
                                           phi2=df["GenZ_B2_Phi"].values)

    # ttbar kinematic differences
    df[name + "_Z_dPhi"] = common.get_dPhi(df[name + "_B1_Phi"].values,
                                           df[name + "_B2_Phi"].values)
    df[name + "_Z_dEta"] = common.get_dPhi(df[name + "_B1_Eta"].values,
                                           df[name + "_B2_Eta"].values)
    df[name+"_Z_dPt"] = abs(
        df[name+"_B1_Pt"].values - \
        df[name+"_B2_Pt"].values)

    df[name+"_Z_dR"] = np.sqrt(
        df[name+"_Z_dEta"].values**2 + \
        df[name+"_Z_dPhi"].values**2)
    df[name+"_Z_dKin"] = np.sqrt(
        (df[name+"_Z_dPhi"].values/(2.*np.pi))**2 + \
        (df[name+"_Z_dEta"].values/(5.))**2 + \
        (df[name+"_Z_dPt"].values/(1000.))**2)
    return df
Example #6
0
def calculate_variables(df):
    '''
    calculate additional variables needed
    '''

    #### Additional b jets ####
    df[name + "_dPhiGen_0"] = common.get_dPhi(
        df[name + "_AddB1_Phi"].values, df["AdditionalGenBJet_Phi[0]"].values)
    df[name + "_dPhiGen_1"] = common.get_dPhi(
        df[name + "_AddB2_Phi"].values, df["AdditionalGenBJet_Phi[1]"].values)
    df[name + "_dEtaGen_0"] = abs(df[name + "_AddB1_Eta"].values -
                                  df["AdditionalGenBJet_Eta[0]"].values)
    df[name + "_dEtaGen_1"] = abs(df[name + "_AddB2_Eta"].values -
                                  df["AdditionalGenBJet_Eta[1]"].values)
    df[name + "_dRGen_0"] = np.sqrt(df[name + "_dPhiGen_0"].values**2 +
                                    df[name + "_dEtaGen_0"].values**2)
    df[name + "_dRGen_1"] = np.sqrt(df[name + "_dPhiGen_1"].values**2 +
                                    df[name + "_dEtaGen_1"].values**2)

    df[name + "_bb_dPhi"] = common.get_dPhi(df[name + "_AddB1_Phi"].values,
                                            df[name + "_AddB2_Phi"])
    df[name + "_bb_dEta"] = abs(df[name + "_AddB1_Eta"].values -
                                df[name + "_AddB2_Eta"])
    df[name + "_bb_dPt"] = abs(df[name + "_AddB1_Pt"].values -
                               df[name + "_AddB2_Pt"])
    df[name + "_bb_dR"] = np.sqrt(df[name + "_bb_dPhi"].values**2 +
                                  df[name + "_bb_dEta"].values**2)
    df[name+"_bb_dKin"] = np.sqrt( (df[name+"_bb_dPhi"].values/(2.*np.pi))**2 + \
                                   (df[name+"_bb_dEta"].values/5.)**2 + \
                                   (df[name+"_bb_dPt"].values/1000.)**2 )

    vectors = common.Vectors(df, name, ["AddB1", "AddB2"])
    vectors.add(["AddB1", "AddB2"], out="bb")

    df[name + "_bb_Pt"] = vectors.get("bb", "Pt")
    df[name + "_bb_Eta"] = vectors.get("bb", "Eta")
    df[name + "_bb_M"] = vectors.get("bb", "M")
    df[name + "_bb_E"] = vectors.get("bb", "E")

    vectors.initIndexedVector(df, "AdditionalGenBJet", 0)
    vectors.initIndexedVector(df, "AdditionalGenBJet", 1)
    vectors.add(["AdditionalGenBJet_0", "AdditionalGenBJet_1"], out="genbb")

    df[name + "_genbb_Pt"] = vectors.get("genbb", "Pt")
    df[name + "_genbb_Eta"] = vectors.get("genbb", "Eta")
    df[name + "_genbb_M"] = vectors.get("genbb", "M")
    df[name + "_genbb_E"] = vectors.get("genbb", "E")

    df[name + "_genbb_dPhi"] = common.get_dPhi(
        df["AdditionalGenBJet_Phi[0]"].values,
        df["AdditionalGenBJet_Phi[1]"].values)
    df[name + "_genbb_dEta"] = abs(df["AdditionalGenBJet_Eta[0]"].values -
                                   df["AdditionalGenBJet_Eta[1]"].values)
    df[name + "_genbb_dPt"] = abs(df["AdditionalGenBJet_Pt[0]"].values -
                                  df["AdditionalGenBJet_Pt[1]"])
    df[name + "_genbb_dR"] = np.sqrt(df[name + "_genbb_dPhi"].values**2 +
                                     df[name + "_genbb_dEta"].values**2)
    df[name+"_genbb_dKin"] = np.sqrt( (df[name+"_genbb_dPhi"].values/(2.*np.pi))**2 + \
                                   (df[name+"_genbb_dEta"].values/5.)**2 + \
                                   (df[name+"_genbb_dPt"].values/1000.)**2 )

    # new observables
    df[name + "_bb_dR_minus_Evt_Dr_minDrTaggedJets"] = df[
        name + "_bb_dR"].values - df["Evt_Dr_minDrTaggedJets"].values
    df[name + "_bb_M_minus_Evt_M2_minDrTaggedJets"] = df[
        name + "_bb_M"].values - df["Evt_M2_minDrTaggedJets"].values
    df[name + "_bb_dEta_minus_Evt_Deta_minDetaTaggedJets"] = df[
        name + "_bb_dEta"].values - df["Evt_Deta_minDetaTaggedJets"].values
    df[name + "_bb_M_minus_Evt_M2_minM2TaggedJets"] = df[
        name + "_bb_M"].values - df["Evt_M2_minM2TaggedJets"].values
    df[name + "_bb_M_minus_Evt_M2_maxM2TaggedJets"] = df[
        name + "_bb_M"].values - df["Evt_M2_maxM2TaggedJets"].values

    df[name + "_Jet_Pt0"] = df["Jet_Pt[0]"].values
    df[name + "_Jet_Pt1"] = df["Jet_Pt[1]"].values
    df[name + "_Jet_Pt2"] = df["Jet_Pt[2]"].values
    df[name + "_Jet_Pt3"] = df["Jet_Pt[3]"].values
    df[name + "_AddB1_Pt"] = df[name + "_AddB1_Pt"].values
    df[name + "_AddB2_Pt"] = df[name + "_AddB2_Pt"].values

    df[name + "_CSV0"] = df["CSV[0]"].values
    df[name + "_CSV1"] = df["CSV[1]"].values
    df[name + "_CSV2"] = df["CSV[2]"].values
    df[name + "_CSV3"] = df["CSV[3]"].values
    df[name + "_AddB1_CSV"] = df[name + "_AddB1_CSV"].values
    df[name + "_AddB2_CSV"] = df[name + "_AddB2_CSV"].values

    return df
Example #7
0
def calculate_variables(df):
    '''
    calculate additional variables needed
    '''

    df[name + "_dPhiGen_0"] = common.get_dPhi(
        df[name + "_AddB1_Phi"].values, df["AdditionalGenBJet_Phi[0]"].values)
    df[name + "_dPhiGen_1"] = common.get_dPhi(
        df[name + "_AddB2_Phi"].values, df["AdditionalGenBJet_Phi[1]"].values)
    df[name + "_dEtaGen_0"] = abs(df[name + "_AddB1_Eta"].values -
                                  df["AdditionalGenBJet_Eta[0]"].values)
    df[name + "_dEtaGen_1"] = abs(df[name + "_AddB2_Eta"].values -
                                  df["AdditionalGenBJet_Eta[1]"].values)
    df[name + "_dRGen_0"] = np.sqrt(df[name + "_dPhiGen_0"].values**2 +
                                    df[name + "_dEtaGen_0"].values**2)
    df[name + "_dRGen_1"] = np.sqrt(df[name + "_dPhiGen_1"].values**2 +
                                    df[name + "_dEtaGen_1"].values**2)

    df[name + "_bb_dPhi"] = common.get_dPhi(df[name + "_AddB1_Phi"].values,
                                            df[name + "_AddB2_Phi"])
    df[name + "_bb_dEta"] = abs(df[name + "_AddB1_Eta"].values -
                                df[name + "_AddB2_Eta"])
    df[name + "_bb_dPt"] = abs(df[name + "_AddB1_Pt"].values -
                               df[name + "_AddB2_Pt"])
    df[name + "_bb_dR"] = np.sqrt(df[name + "_bb_dPhi"].values**2 +
                                  df[name + "_bb_dEta"].values**2)
    df[name+"_bb_dKin"] = np.sqrt( (df[name+"_bb_dPhi"].values/(2.*np.pi))**2 + \
                                   (df[name+"_bb_dEta"].values/5.)**2 + \
                                   (df[name+"_bb_dPt"].values/1000.)**2 )

    vectors = common.Vectors(df, name, ["AddB1", "AddB2"])
    vectors.add(["AddB1", "AddB2"], out="bb")

    df[name + "_bb_Pt"] = vectors.get("bb", "Pt")
    df[name + "_bb_Eta"] = vectors.get("bb", "Eta")
    df[name + "_bb_M"] = vectors.get("bb", "M")
    df[name + "_bb_E"] = vectors.get("bb", "E")

    vectors.initIndexedVector(df, "AdditionalGenBJet", 0)
    vectors.initIndexedVector(df, "AdditionalGenBJet", 1)
    vectors.add(["AdditionalGenBJet_0", "AdditionalGenBJet_1"], out="genbb")

    df[name + "_genbb_Pt"] = vectors.get("genbb", "Pt")
    df[name + "_genbb_Eta"] = vectors.get("genbb", "Eta")
    df[name + "_genbb_M"] = vectors.get("genbb", "M")
    df[name + "_genbb_E"] = vectors.get("genbb", "E")

    df[name + "_genbb_dPhi"] = common.get_dPhi(
        df["AdditionalGenBJet_Phi[0]"].values,
        df["AdditionalGenBJet_Phi[1]"].values)
    df[name + "_genbb_dEta"] = abs(df["AdditionalGenBJet_Eta[0]"].values -
                                   df["AdditionalGenBJet_Eta[1]"].values)
    df[name + "_genbb_dPt"] = abs(df["AdditionalGenBJet_Pt[0]"].values -
                                  df["AdditionalGenBJet_Pt[1]"])
    df[name + "_genbb_dR"] = np.sqrt(df[name + "_genbb_dPhi"].values**2 +
                                     df[name + "_genbb_dEta"].values**2)
    df[name+"_genbb_dKin"] = np.sqrt( (df[name+"_genbb_dPhi"].values/(2.*np.pi))**2 + \
                                   (df[name+"_genbb_dEta"].values/5.)**2 + \
                                   (df[name+"_genbb_dPt"].values/1000.)**2 )

    return df
Example #8
0
def calculate_variables(event, wrapper):
    '''
    calculate additional variables needed
    '''
    vectors = common.Vectors(event)
    wrapper.branchArrays["Evt_ID"][0] = event.Evt_ID
    wrapper.branchArrays["Evt_Run"][0] = event.Evt_Run
    wrapper.branchArrays["Evt_Lumi"][0] = event.Evt_Lumi

    wrapper.branchArrays["N_Jets"][0] = event.N_Jets
    wrapper.branchArrays["N_BTagsM"][0] = event.N_BTagsM
    try:
        wrapper.branchArrays["N_GenJets"][0] = event.N_GenJets
        wrapper.branchArrays["N_GenBJets"][0] = event.N_GenBJets
    except:
        pass
    try:
        wrapper.branchArrays["GenEvt_I_TTPlusBB"][0] = event.GenEvt_I_TTPlusBB
        wrapper.branchArrays["GenEvt_I_TTPlusCC"][0] = event.GenEvt_I_TTPlusCC
    except:
        wrapper.branchArrays["GenEvt_I_TTPlusBB"][0] = -1
        wrapper.branchArrays["GenEvt_I_TTPlusCC"][0] = -1

    # gen level definition via additional gen b jets (this is not particle level)
    try:
        wrapper.branchArrays["N_AdditionalGenBJets"][
            0] = event.N_AdditionalGenBJets
        if event.N_AdditionalGenBJets >= 2:
            dR = common.get_dR(event.AdditionalGenBJet_Eta[0],
                               event.AdditionalGenBJet_Phi[0],
                               event.AdditionalGenBJet_Eta[1],
                               event.AdditionalGenBJet_Phi[1])
            dEta = common.get_dEta(event.AdditionalGenBJet_Eta[0],
                                   event.AdditionalGenBJet_Eta[1])
            dPhi = common.get_dPhi(event.AdditionalGenBJet_Phi[0],
                                   event.AdditionalGenBJet_Phi[1])

            vectors.initIndexedVector(event, "AdditionalGenBJet", 0)
            vectors.initIndexedVector(event, "AdditionalGenBJet", 1)
            vectors.add(["AdditionalGenBJet_0", "AdditionalGenBJet_1"],
                        out="bb")

            wrapper.branchArrays["AddGenB_M_bb"][0] = vectors.get("bb", "M")[0]
            wrapper.branchArrays["AddGenB_Eta_bb"][0] = abs(
                vectors.get("bb", "Eta")[0])
            wrapper.branchArrays["AddGenB_Phi_bb"][0] = vectors.get(
                "bb", "Phi")[0]
            wrapper.branchArrays["AddGenB_Pt_bb"][0] = vectors.get("bb",
                                                                   "Pt")[0]
            wrapper.branchArrays["AddGenB_E_bb"][0] = vectors.get("bb", "E")[0]

            wrapper.branchArrays["AddGenB_dR_bb"][0] = dR
            wrapper.branchArrays["AddGenB_dEta_bb"][0] = dEta
            wrapper.branchArrays["AddGenB_dPhi_bb"][0] = dPhi

            wrapper.branchArrays["AddGenB_Pt_1"][
                0] = event.AdditionalGenBJet_Pt[1]
            wrapper.branchArrays["AddGenB_Eta_1"][0] = abs(
                event.AdditionalGenBJet_Eta[1])
        if event.N_AdditionalGenBJets >= 1:
            wrapper.branchArrays["AddGenB_Pt_0"][
                0] = event.AdditionalGenBJet_Pt[0]
            wrapper.branchArrays["AddGenB_Eta_0"][0] = abs(
                event.AdditionalGenBJet_Eta[0])
    except:
        pass

    # gen level definition via closest particle level b jets
    try:
        if event.N_GenBJets >= 2:
            mini1 = 0
            mini2 = 0
            minVal = 999.
            maxMbb = -1.
            for i in range(event.N_GenBJets):
                vectors.initIndexedVector(event, "GenBJet", i)
            for i1 in range(event.N_GenBJets):
                for i2 in range(i1 + 1, event.N_GenBJets):
                    dR = common.get_dR(event.GenBJet_Eta[i1],
                                       event.GenBJet_Phi[i1],
                                       event.GenBJet_Eta[i2],
                                       event.GenBJet_Phi[i2])
                    if dR <= minVal:
                        minVal = dR
                        mini1 = i1
                        mini2 = i2

                    vectors.add(["GenBJet_" + str(i1), "GenBJet_" + str(i2)],
                                out="genb_{}_{}".format(i1, i2))
                    mbb = vectors.get("genb_{}_{}".format(i1, i2), "M")[0]
                    if mbb > maxMbb: maxMbb = mbb
            wrapper.branchArrays["GenBJets_maxM_bb"][0] = maxMbb

            dR = common.get_dR(event.GenBJet_Eta[mini1],
                               event.GenBJet_Phi[mini1],
                               event.GenBJet_Eta[mini2],
                               event.GenBJet_Phi[mini2])
            dEta = common.get_dEta(event.GenBJet_Eta[mini1],
                                   event.GenBJet_Eta[mini2])
            dPhi = common.get_dPhi(event.GenBJet_Phi[mini1],
                                   event.GenBJet_Phi[mini2])

            vectors.add(["GenBJet_" + str(mini1), "GenBJet_" + str(mini2)],
                        out="closestbb")

            wrapper.branchArrays["ClosestGenB_M_bb"][0] = vectors.get(
                "closestbb", "M")[0]
            wrapper.branchArrays["ClosestGenB_Eta_bb"][0] = abs(
                vectors.get("closestbb", "Eta")[0])
            wrapper.branchArrays["ClosestGenB_Phi_bb"][0] = vectors.get(
                "closestbb", "Phi")[0]
            wrapper.branchArrays["ClosestGenB_Pt_bb"][0] = vectors.get(
                "closestbb", "Pt")[0]
            wrapper.branchArrays["ClosestGenB_E_bb"][0] = vectors.get(
                "closestbb", "E")[0]

            wrapper.branchArrays["ClosestGenB_dR_bb"][0] = dR
            wrapper.branchArrays["ClosestGenB_dEta_bb"][0] = dEta
            wrapper.branchArrays["ClosestGenB_dPhi_bb"][0] = dPhi

            wrapper.branchArrays["ClosestGenB_Pt_0"][0] = event.GenBJet_Pt[
                mini1]
            wrapper.branchArrays["ClosestGenB_Eta_0"][0] = abs(
                event.GenBJet_Eta[mini1])
            wrapper.branchArrays["ClosestGenB_Pt_1"][0] = event.GenBJet_Pt[
                mini2]
            wrapper.branchArrays["ClosestGenB_Eta_1"][0] = abs(
                event.GenBJet_Eta[mini2])
    except:
        pass

    # reco level definition via closest b-tagged jets
    if event.N_BTagsM >= 2:
        min_i1 = -9.
        min_i2 = -9.
        minDr = 9999.
        maxMbb = -1.
        for i in range(event.N_Jets):
            if event.Jet_CSV[i] < btagWP: continue
            vectors.initIndexedVector(event, "Jet", i)

        for i1 in range(event.N_Jets):
            if event.Jet_CSV[i1] < btagWP: continue
            for i2 in range(event.N_Jets):
                if i2 <= i1: continue
                if event.Jet_CSV[i2] < btagWP: continue

                dR = common.get_dR(event.Jet_Eta[i1], event.Jet_Phi[i1],
                                   event.Jet_Eta[i2], event.Jet_Phi[i2])
                if dR <= minDr:
                    minDr = dR
                    min_i1 = i1
                    min_i2 = i2

                vectors.add(["Jet_" + str(i1), "Jet_" + str(i2)],
                            "bjet_{}_{}".format(i1, i2))
                mbb = vectors.get("bjet_{}_{}".format(i1, i2), "M")[0]
                if mbb > maxMbb: maxMbb = mbb

        wrapper.branchArrays["maxMbb_M_bb"][0] = maxMbb

        mindR = common.get_dR(event.Jet_Eta[min_i1], event.Jet_Phi[min_i1],
                              event.Jet_Eta[min_i2], event.Jet_Phi[min_i2])
        mindEta = common.get_dEta(event.Jet_Eta[min_i1], event.Jet_Eta[min_i2])
        mindPhi = common.get_dPhi(event.Jet_Phi[min_i1], event.Jet_Phi[min_i2])
        vectors.add(["Jet_{}".format(min_i1), "Jet_{}".format(min_i2)],
                    out="minbb")
        wrapper.branchArrays["mindRbb_M_bb"][0] = vectors.get("minbb", "M")[0]
        wrapper.branchArrays["mindRbb_Eta_bb"][0] = abs(
            vectors.get("minbb", "Eta")[0])
        wrapper.branchArrays["mindRbb_Phi_bb"][0] = vectors.get(
            "minbb", "Phi")[0]
        wrapper.branchArrays["mindRbb_Pt_bb"][0] = vectors.get("minbb",
                                                               "Pt")[0]
        wrapper.branchArrays["mindRbb_E_bb"][0] = vectors.get("minbb", "E")[0]

        wrapper.branchArrays["mindRbb_dR_bb"][0] = mindR
        wrapper.branchArrays["mindRbb_dEta_bb"][0] = mindEta
        wrapper.branchArrays["mindRbb_dPhi_bb"][0] = mindPhi

        wrapper.branchArrays["mindRbb_Pt_0"][0] = event.Jet_Pt[min_i1]
        wrapper.branchArrays["mindRbb_Pt_1"][0] = event.Jet_Pt[min_i2]
        wrapper.branchArrays["mindRbb_Eta_0"][0] = abs(event.Jet_Eta[min_i1])
        wrapper.branchArrays["mindRbb_Eta_1"][0] = abs(event.Jet_Eta[min_i2])

    return event