Example #1
0
def KstarMuMuMC(process):
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.genDecayConstructor import genDecayConstructor
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.genRecoMatcher import genRecoMatcher
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.compositeRecoMatcher import compositeRecoMatcher
    GenDecay = genDecayConstructor(
        momPdgId=511,
        daughtersPdgId=[13, -13, 321, -211],
        outputMomColl="genB",
        interDecay=["313->321,-211"],
        outputDaughterColls=["genMu1", "genMu2", "genK", "genPi"])
    process.append(GenDecay)
    RecoMu1 = genRecoMatcher(recoInput="Muon",
                             genInput="genMu1",
                             output="recoMu1",
                             branches=["pt", "eta", "phi"])
    process.append(RecoMu1)
    RecoMu2 = genRecoMatcher(recoInput="Muon",
                             genInput="genMu2",
                             output="recoMu2",
                             branches=["pt", "eta", "phi"])
    process.append(RecoMu2)
    RecoK = genRecoMatcher(recoInput="ProbeTracks",
                           genInput="genK",
                           output="recoK",
                           branches=["pt", "eta", "phi"])
    process.append(RecoK)
    RecoPi = genRecoMatcher(recoInput="ProbeTracks",
                            genInput="genPi",
                            output="recoPi",
                            branches=["pt", "eta", "phi"])
    process.append(RecoPi)
    RecoB = compositeRecoMatcher(
        compositeColl="BToKsMuMu",
        lepCompositeIdxs=["l1_idx", "l2_idx"],
        hadronCompositeIdxs=["trk1_idx", "trk2_idx"],
        lepMatchedRecoIdxs=["recoMu1_Idx", "recoMu2_Idx"],
        hadronMatchedRecoIdxs=["recoK_Idx", "recoPi_Idx"],
        outputColl="recoB",
        branches=["pt", "eta", "phi"])
    process.append(RecoB)
    return process
def KEEMC(process, Jpsi=[], use_PF=False, use_1lowPt_1PF=False):
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.genDecayConstructorPython import genDecayConstructorPython
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.genRecoMatcher import genRecoMatcher
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.compositeRecoMatcher import compositeRecoMatcher
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.branchCreatorMC import branchCreatorMC

    cuts_on_lep = lambda l: True
    cuts_on_B = "True"
    cuts_on_B_vars = []
    if use_PF and not use_1lowPt_1PF:
        cuts_on_lep = lambda l: l.isPF == 1 and l.pfmvaId > -5000
        cuts_on_B_vars = ["recoE1_pfmvaId", "recoE2_pfmvaId"]
        cuts_on_B = cuts_on_B + " and ( {0}>-300.5 or {1}>-300.5 )"
    elif use_1lowPt_1PF and not use_PF:
        cuts_on_lep = lambda l: (
            (l.isPF == 1 and l.pfmvaId > -1.25) or
            (l.isPF == 0 and l.isPFoverlap == 0 and l.mvaId > -1.5))
        cuts_on_B_vars = ["recoE1_isPF", "recoE2_isPF"]
        cuts_on_B = cuts_on_B + " and ( ({0}==1 and {1}==0) or  ( {0}==0 and {1}==1) )"

    GenDecay = genDecayConstructorPython(
        momPdgId=521,
        daughtersPdgId=[11, -11, 321],
        outputMomColl="genB",
        intermediateDecay=Jpsi,
        trgMuonPtEtaThresholds=[],  #was 7,1.6
        outputDaughterColls=["genE1", "genE2", "genK"])
    process.append(GenDecay)
    RecoE1 = genRecoMatcher(recoInput="Electron",
                            genInput="genE1",
                            output="recoE1",
                            branches=[
                                "pt", "eta", "phi", "vx", "vy", "vz", "isPF",
                                "pfmvaId", "isPFoverlap", "mvaId"
                            ],
                            cuts=cuts_on_lep,
                            skipNotMatched=False)
    process.append(RecoE1)
    RecoE2 = genRecoMatcher(recoInput="Electron",
                            genInput="genE2",
                            output="recoE2",
                            branches=[
                                "pt", "eta", "phi", "vx", "vy", "vz", "isPF",
                                "pfmvaId", "isPFoverlap", "mvaId"
                            ],
                            cuts=cuts_on_lep,
                            skipNotMatched=False)
    process.append(RecoE2)
    RecoK = genRecoMatcher(recoInput="ProbeTracks",
                           genInput="genK",
                           output="recoK",
                           branches=["pt", "eta", "phi", "vx", "vy", "vz"],
                           skipNotMatched=False)
    process.append(RecoK)
    RecoB = compositeRecoMatcher(
        compositeColl="BToKEE",
        lepCompositeIdxs=["l1Idx", "l2Idx"],
        hadronCompositeIdxs=["kIdx"],
        lepMatchedRecoIdxs=["recoE1_Idx", "recoE2_Idx"],
        hadronMatchedRecoIdxs=["recoK_Idx"],
        outputColl="recoB",
        cuts_vars=cuts_on_B_vars,
        cuts=cuts_on_B,
        branches=[
            "fit_pt",
            "fit_eta",
            "fit_phi",
            "fit_mass",
            "l_xy",
            "l_xy_unc",
            "fit_cos2D",
            "svprob",
            "fit_massErr",
            "b_iso04",
            "mll_fullfit",
            "l1Idx",
            "l2Idx",
            "kIdx",
            "vtx_x",
            "vtx_y",
            "vtx_z",
            "fit_l1_pt",
            "fit_l1_eta",
            "fit_l1_phi",
            "l1_iso04",
            "fit_l2_pt",
            "fit_l2_eta",
            "fit_l2_phi",
            "l2_iso04",
            "fit_k_pt",
            "fit_k_eta",
            "fit_k_phi",
            "k_iso04",
        ],
        sortTwoLepByIdx=True,
        lepLabelsToSort=[
            "l1", "l2"
        ]  # branches need to have lep labels between "_" eg fit_l1_pt or l1_iso - lep indexes also sorted
    )
    process.append(RecoB)
    # in case of inf in L_xy/unc produces -99
    CreateVars = branchCreatorMC(
        inputBranches=[["recoB_l_xy", "recoB_l_xy_unc"],
                       ["recoE1_vz", "recoE2_vz"],
                       ["recoK_vz", "recoE1_vz", "recoE2_vz"],
                       [
                           "recoE1_eta", "recoE1_phi", "recoE2_eta",
                           "recoE2_phi"
                       ],
                       [
                           "recoK_eta", "recoK_phi", "recoE1_eta",
                           "recoE1_phi", "recoE2_eta", "recoE2_phi"
                       ]],
        operation=[
            "{0}/{1}", "abs({0}-{1})", "min(abs({0}-{1}),abs({0}-{2}))",
            "deltaR({0},{1},{2},{3})",
            "min(deltaR({0},{1},{2},{3}),deltaR({0},{1},{4},{5}))"
        ],
        createdBranches=[
            "recoB_l_xy_sig", "recoB_l1l2Dz", "recoB_lKDz", "recoB_l1l2Dr",
            "recoB_lKDr"
        ],
        checkForBCandBranch=
        "recoB_l_xy"  #if provided branch puts -99 when branch value is -99. eg Useful for evt where recoK is found but
    )
    process.append(CreateVars)
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.functionWrapper import functionWrapper
    TagVars = functionWrapper(
        functionName="TagVarsMC",
        collections=[
            "ProbeTracks", "TriggerMuon", "recoB_fit_pt", "recoB_fit_eta",
            "recoB_fit_phi", "recoB_fit_mass"
        ],
        createdBranches=[
            "recoB_TagMuEtRatio", "recoB_TagMuDphi", "recoB_TagMu4Prod"
        ],
    )
    process.append(TagVars)
    ClosestTrkVars = functionWrapper(
        functionName="ClosestTrkVarsMC",
        collections=[
            "ProbeTracks", "BToKEE", "recoB_Idx", "Electron", "recoB_l1Idx",
            "recoB_l2Idx"
        ],
        createdBranches=[
            "recoB_l1_trk_mass", "recoB_l2_trk_mass", "recoB_trk_minxy1",
            "recoB_trk_minxy2", "recoB_trk_minxy3", "recoB_trk_mean"
        ],
    )
    process.append(ClosestTrkVars)
    return process
Example #3
0
def KEEMC(process, Jpsi=[]):
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.genDecayConstructorPython import genDecayConstructorPython
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.genRecoMatcher import genRecoMatcher
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.compositeRecoMatcher import compositeRecoMatcher
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.branchCreatorMC import branchCreatorMC
    GenDecay = genDecayConstructorPython(
        momPdgId=521,
        daughtersPdgId=[11, -11, 321],
        outputMomColl="genB",
        intermediateDecay=Jpsi,
        trgMuonPtEtaThresholds=[],  #was 7,1.6
        selectTrgMuon=False,
        excludeTrgMuon=False,
        outputDaughterColls=["genE1", "genE2", "genK"])
    process.append(GenDecay)
    RecoE1 = genRecoMatcher(
        recoInput="Electron",
        genInput="genE1",
        output="recoE1",
        branches=["pt", "eta", "phi", "fBrem", "vz", "hoe"],
        skipNotMatched=False)
    process.append(RecoE1)
    RecoE2 = genRecoMatcher(
        recoInput="Electron",
        genInput="genE2",
        output="recoE2",
        branches=["pt", "eta", "phi", "fBrem", "vz", "hoe"],
        skipNotMatched=False)
    process.append(RecoE2)
    RecoK = genRecoMatcher(recoInput="ProbeTracks",
                           genInput="genK",
                           output="recoK",
                           branches=["pt", "eta", "phi", "vz"],
                           skipNotMatched=False)
    process.append(RecoK)
    RecoB = compositeRecoMatcher(
        compositeColl="BToKEE",
        lepCompositeIdxs=["l1Idx", "l2Idx"],
        hadronCompositeIdxs=["kIdx"],
        lepMatchedRecoIdxs=["recoE1_Idx", "recoE2_Idx"],
        hadronMatchedRecoIdxs=["recoK_Idx"],
        outputColl="recoB",
        branches=[
            "fit_pt", "fit_eta", "fit_phi", "fit_mass", "mll_fullfit", "l_xy",
            "l_xy_unc", "fit_cos2D", "svprob", "l1Idx", "l2Idx", "kIdx"
        ])
    process.append(RecoB)
    CreateVars = branchCreatorMC(
        inputBranches=[["recoB_l_xy", "recoB_l_xy_unc"],
                       ["recoE1_vz", "recoE2_vz"],
                       ["recoK_vz", "recoE1_vz", "recoE2_vz"],
                       [
                           "recoE1_eta", "recoE1_phi", "recoE2_eta",
                           "recoE2_phi"
                       ],
                       [
                           "recoK_eta", "recoK_phi", "recoE1_eta",
                           "recoE1_phi", "recoE2_eta", "recoE2_phi"
                       ]],
        operation=[
            "{0}/{1}", "abs({0}-{1})", "min(abs({0}-{1}),abs({0}-{2}))",
            "deltaR({0},{1},{2},{3})",
            "min(deltaR({0},{1},{2},{3}),deltaR({0},{1},{4},{5}))"
        ],
        createdBranches=[
            "recoB_l_xy_sig", "recoB_e1e2Dz", "recoB_eKDz", "recoB_e1e2Dr",
            "recoB_eKDr"
        ])
    process.append(CreateVars)
    return process
def KMuMuMC(process, Jpsi=[]):
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.genDecayConstructorPython import genDecayConstructorPython
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.genRecoMatcher import genRecoMatcher
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.compositeRecoMatcher import compositeRecoMatcher
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.branchCreatorMC import branchCreatorMC
    from PhysicsTools.NanoAODTools.postprocessing.modules.bpark.genTriggerMuon import genTriggerMuon
    #cuts_on_lep = lambda l: True
    cuts_on_B = "True"
    cuts_on_B_vars = []
    GenDecay = genDecayConstructorPython(
        momPdgId=521,
        daughtersPdgId=[13, -13, 321],
        outputMomColl="genB",
        intermediateDecay=Jpsi,
        trgMuonPtEtaThresholds=
        [],  #best for training - probe/tag side kinematics no trigger eff reduction
        selectTrgMuon=False,
        excludeTrgMuon=False,
        outputDaughterColls=["genMu1", "genMu2", "genK"])
    process.append(GenDecay)
    RecoMu1 = genRecoMatcher(recoInput="Muon",
                             genInput="genMu1",
                             output="recoMu1",
                             branches=[
                                 "pt", "eta", "phi", "softId", "vz",
                                 "pfRelIso03_all", "dxy", "dxyErr"
                             ],
                             addChargeMatching=False,
                             skipNotMatched=False,
                             DRcut=0.1)
    process.append(RecoMu1)
    RecoMu2 = genRecoMatcher(recoInput="Muon",
                             genInput="genMu2",
                             output="recoMu2",
                             branches=[
                                 "pt", "eta", "phi", "softId", "vz",
                                 "pfRelIso03_all", "dxy", "dxyErr"
                             ],
                             addChargeMatching=False,
                             skipNotMatched=False,
                             DRcut=0.1)
    process.append(RecoMu2)
    #deal with trg muon
    TriggerObj = genTriggerMuon(trgBranch="Muon_isTriggering",
                                skipNoTrgEvt=True,
                                skipProbe=False,
                                skipTag=True,
                                selectionPathList=["HLT_Mu9_IP6"],
                                outputColl="trgMu",
                                recoIdx=["recoMu1_Idx", "recoMu2_Idx"],
                                trgMuMinPt=8.5,
                                branches=["pt", "eta", "phi", "dxy", "dxyErr"])
    process.append(TriggerObj)
    RecoK = genRecoMatcher(recoInput="ProbeTracks",
                           genInput="genK",
                           output="recoK",
                           branches=["vz"],
                           skipNotMatched=False,
                           DRcut=0.1)
    process.append(RecoK)
    RecoB = compositeRecoMatcher(
        compositeColl="BToKMuMu",
        lepCompositeIdxs=["l1Idx", "l2Idx"],
        hadronCompositeIdxs=["kIdx"],
        lepMatchedRecoIdxs=["recoMu1_Idx", "recoMu2_Idx"],
        hadronMatchedRecoIdxs=["recoK_Idx"],
        outputColl="recoB",
        cuts_vars=cuts_on_B_vars,
        cuts=cuts_on_B,
        branches=[
            "fit_pt", "fit_eta", "fit_phi", "fit_mass", "mll_fullfit", "l_xy",
            "l_xy_unc", "fit_cos2D", "svprob", "fit_massErr", "b_iso04",
            "vtx_x", "vtx_y", "vtx_z", "l1Idx", "l2Idx", "kIdx", "fit_l1_pt",
            "fit_l1_eta", "fit_l1_phi", "l1_iso04", "n_l1_used", "fit_l2_pt",
            "fit_l2_eta", "fit_l2_phi", "l2_iso04", "n_l2_used", "fit_k_pt",
            "fit_k_eta", "fit_k_phi", "k_iso04", "n_k_used"
        ],
        sortTwoLepByIdx=True,
        lepLabelsToSort=[
            "l1", "l2"
        ]  # branches need to have lep labels between "_" eg fit_l1_pt or l1_iso - lep indexes also sorted
    )
    process.append(RecoB)
    # in case of inf in L_xy/unc produces -99
    CreateVars = branchCreatorMC(
        inputBranches=[["recoB_l_xy", "recoB_l_xy_unc"],
                       ["recoMu1_vz", "recoMu2_vz"],
                       ["recoK_vz", "recoMu1_vz", "recoMu2_vz"],
                       [
                           "recoB_fit_l1_eta", "recoB_fit_l1_phi",
                           "recoB_fit_l2_eta", "recoB_fit_l2_phi"
                       ],
                       [
                           "recoB_fit_k_eta", "recoB_fit_k_phi",
                           "recoB_fit_l1_eta", "recoB_fit_l1_phi",
                           "recoB_fit_l2_eta", "recoB_fit_l2_phi"
                       ]],
        operation=[
            "{0}/{1}", "abs({0}-{1})", "min(abs({0}-{1}),abs({0}-{2}))",
            "deltaR({0},{1},{2},{3})",
            "min(deltaR({0},{1},{2},{3}),deltaR({0},{1},{4},{5}))"
        ],
        createdBranches=[
            "recoB_l_xy_sig", "recoB_l1l2Dz", "recoB_lKDz", "recoB_l1l2Dr",
            "recoB_lKDr"
        ],
        checkForBCandBranch=
        "recoB_l_xy"  #if provided branch puts -99 when branch value is -99. eg Useful for evt where recoK is found but B not
    )
    process.append(CreateVars)
    return process