示例#1
0
leptonTypeSusy = NTupleObjectType(
    "leptonSusy",
    baseObjectTypes=[leptonType],
    variables=[
        #NTupleVariable("eleMVAId",     lambda x : (x.electronID("POG_MVA_ID_NonTrig_full5x5") + 2*x.electronID("POG_MVA_ID_Trig_full5x5")) if abs(x.pdgId()) == 11 else -1, int, help="Electron mva id working point (2012, full5x5 shapes): 0=none, 1=non-trig, 2=trig, 3=both"),
        #NTupleVariable("mvaId",         lambda lepton : lepton.mvaNonTrigV0(full5x5=True) if abs(lepton.pdgId()) == 11 else 1, help="EGamma POG MVA ID for non-triggering electrons (as HZZ); 1 for muons"),
        #NTupleVariable("mvaIdTrig",     lambda lepton : lepton.mvaTrigV0(full5x5=True)    if abs(lepton.pdgId()) == 11 else 1, help="EGamma POG MVA ID for triggering electrons; 1 for muons"),
        NTupleVariable(
            "mvaIdPhys14",
            lambda lepton: lepton.mvaRun2("NonTrigPhys14")
            if abs(lepton.pdgId()) == 11 else 1,
            help=
            "EGamma POG MVA ID for non-triggering electrons, Phys14 re-training; 1 for muons"
        ),
        # Lepton MVA-id related variables
        NTupleVariable("mvaTTH",
                       lambda lepton: getattr(lepton, 'mvaValueTTH', -1),
                       help="Lepton MVA (TTH version)"),
        NTupleVariable("mvaSusy",
                       lambda lepton: getattr(lepton, 'mvaValueSusy', -1),
                       help="Lepton MVA (SUSY version)"),
        NTupleVariable("jetPtRatio",
                       lambda lepton: lepton.pt() / lepton.jet.pt()
                       if hasattr(lepton, 'jet') else -1,
                       help="pt(lepton)/pt(nearest jet)"),
        NTupleVariable(
            "jetPtRel",
            lambda lepton: ptRelv1(lepton.p4(), lepton.jet.p4())
            if hasattr(lepton, 'jet') else -1,
            help=
            "pt of the lepton transverse to the jet axis (subtracting the lepton)"
        ),
        NTupleVariable(
            "jetBTagCSV",
            lambda lepton: lepton.jet.btag(
                'pfCombinedInclusiveSecondaryVertexV2BJetTags')
            if hasattr(lepton, 'jet') and hasattr(lepton.jet, 'btag') else -99,
            help="CSV btag of nearest jet"),
        NTupleVariable(
            "jetBTagCMVA",
            lambda lepton: lepton.jet.btag('pfCombinedMVABJetTags')
            if hasattr(lepton, 'jet') and hasattr(lepton.jet, 'btag') else -99,
            help="CMA btag of nearest jet"),
        NTupleVariable("jetDR",
                       lambda lepton: deltaR(lepton.eta(), lepton.phi(
                       ), lepton.jet.eta(), lepton.jet.phi())
                       if hasattr(lepton, 'jet') else -1,
                       help="deltaR(lepton, nearest jet)"),
    ])
示例#2
0
leptonTypeWMassPruned = NTupleObjectType(
    "leptonWMass",
    baseObjectTypes=[leptonTypeSmaller],
    variables=[
        NTupleVariable(
            "chIso04",
            lambda lepton: lepton.chargedHadronIsoR(0.4),
            help="Lepton charged hadron isolation in a cone DeltaR=0.4"),
        NTupleVariable(
            "nhIso04",
            lambda lepton: lepton.neutralHadronIsoR(0.4),
            help="Lepton neutral hadron isolation in a cone DeltaR=0.4"),
        NTupleVariable("phIso04",
                       lambda lepton: lepton.photonIsoR(0.4),
                       help="Lepton photon isolation in a cone DeltaR=0.4"),
        # More
        NTupleVariable(
            "tightChargeFix",
            lambda lepton: (lepton.isGsfCtfScPixChargeConsistent() + lepton.
                            isGsfScPixChargeConsistent())
            if abs(lepton.pdgId()) == 11 else 2 * (lepton.muonBestTrack(
            ).ptError() / lepton.muonBestTrack().pt() < 0.2),
            int,
            help=
            "Tight charge criteria: for electrons, 2 if isGsfCtfScPixChargeConsistent, 1 if only isGsfScPixChargeConsistent, 0 otherwise; for muons, 2 if ptError/pt < 0.20, 0 otherwise (using the muon best track)"
        ),
        NTupleVariable(
            "muonTrackType",
            lambda lepton: 1
            if abs(lepton.pdgId()) == 11 else lepton.muonBestTrackType(),
            int,
            help="Muon best track type"),
        NTupleVariable("ptErrTk",
                       lambda lepton: (lepton.gsfTrack().ptError())
                       if abs(lepton.pdgId()) == 11 else
                       (lepton.muonBestTrack().ptError()),
                       help="pt error, for the gsf track or muon best track"),
        NTupleVariable(
            "matchedTrgObjMuPt",
            lambda x: x.matchedTrgObjwmassMu.pt()
            if x.matchedTrgObjwmassMu else -999.,
            help="Matched trigger object (cone dR<0.3) pT to IsoMu24"),
        NTupleVariable(
            "matchedTrgObjMuDR",
            lambda x: deltaR(x, x.matchedTrgObjwmassMu)
            if x.matchedTrgObjwmassMu else -999.,
            help="Matched trigger object (cone dR<0.3) dR to IsoMu24"),
        NTupleVariable(
            "matchedTrgObjTkMuPt",
            lambda x: x.matchedTrgObjwmassTkMu.pt()
            if x.matchedTrgObjwmassTkMu else -999.,
            help="Matched trigger object (cone dR<0.3) pT to IsoTkMu24"),
        NTupleVariable(
            "matchedTrgObjTkMuDR",
            lambda x: deltaR(x, x.matchedTrgObjwmassTkMu)
            if x.matchedTrgObjwmassTkMu else -999.,
            help="Matched trigger object (cone dR<0.3) dR to IsoTkMu24"),
        NTupleVariable("matchedTrgObjMu50Pt",
                       lambda x: x.matchedTrgObjwmassMu50.pt()
                       if x.matchedTrgObjwmassMu50 else -999.,
                       help="Matched trigger object (cone dR<0.3) pT to Mu50"),
        NTupleVariable("matchedTrgObjMu50DR",
                       lambda x: deltaR(x, x.matchedTrgObjwmassMu50)
                       if x.matchedTrgObjwmassMu50 else -999.,
                       help="Matched trigger object (cone dR<0.3) dR to Mu50"),
        NTupleVariable(
            "nLayersInner",
            lambda lepton: lepton.innerTrack().hitPattern(
            ).trackerLayersWithMeasurement()
            if abs(lepton.pdgId()) == 13 else -999.,
            help=
            "Number of layers with measurements in inner track hit pattern for muons."
        ),
    ])
示例#3
0
leptonTypeWMass = NTupleObjectType(
    "leptonWMass",
    baseObjectTypes=[leptonType],
    variables=[
        # Lepton MVA-id related variables
        NTupleVariable("jetDR",
                       lambda lepton: deltaR(lepton.eta(), lepton.phi(
                       ), lepton.jet.eta(), lepton.jet.phi())
                       if hasattr(lepton, 'jet') else -1,
                       help="deltaR(lepton, nearest jet)"),
        NTupleVariable(
            "r9",
            lambda lepton: lepton.full5x5_r9()
            if abs(lepton.pdgId()) == 11 else -99,
            help=
            "SuperCluster 5x5 r9 variable, only for electrons; -99 for muons"),
        NTupleVariable(
            "chIso04",
            lambda lepton: lepton.chargedHadronIsoR(0.4),
            help="Lepton charged hadron isolation in a cone DeltaR=0.4"),
        NTupleVariable(
            "nhIso04",
            lambda lepton: lepton.neutralHadronIsoR(0.4),
            help="Lepton neutral hadron isolation in a cone DeltaR=0.4"),
        NTupleVariable("phIso04",
                       lambda lepton: lepton.photonIsoR(0.4),
                       help="Lepton photon isolation in a cone DeltaR=0.4"),
        #2016 muon Id
        NTupleVariable("softMuonId2016",
                       lambda lepton: _soft_MuonId_2016ICHEP(lepton),
                       help="Soft muon ID retuned for ICHEP 2016"),
        NTupleVariable("mediumMuonID2016",
                       lambda lepton: _medium_MuonId_2016ICHEP(lepton),
                       help="Medium muon ID retuned for ICHEP 2016"),
        # More
        NTupleVariable(
            "tightChargeFix",
            lambda lepton: (lepton.isGsfCtfScPixChargeConsistent() + lepton.
                            isGsfScPixChargeConsistent())
            if abs(lepton.pdgId()) == 11 else 2 *
            (lepton.muonBestTrack().ptError() / lepton.muonBestTrack().pt() <
             0.2),
            int,
            help=
            "Tight charge criteria: for electrons, 2 if isGsfCtfScPixChargeConsistent, 1 if only isGsfScPixChargeConsistent, 0 otherwise; for muons, 2 if ptError/pt < 0.20, 0 otherwise (using the muon best track)"
        ),
        NTupleVariable(
            "muonTrackType",
            lambda lepton: 1
            if abs(lepton.pdgId()) == 11 else lepton.muonBestTrackType(),
            int,
            help="Muon best track type"),
        NTupleVariable(
            "chargeConsistency",
            lambda lepton: (lepton.isGsfCtfScPixChargeConsistent() + lepton.
                            isGsfScPixChargeConsistent())
            if abs(lepton.pdgId()) == 11 else abs(
                lepton.muonBestTrack().charge() + lepton.innerTrack().charge(
                ) + lepton.tunePMuonBestTrack().charge() +
                (lepton.globalTrack().charge() + lepton.outerTrack().charge()
                 if lepton.isGlobalMuon() else 0)),
            int,
            help=
            "Tight charge criteria: for electrons, 2 if isGsfCtfScPixChargeConsistent, 1 if only isGsfScPixChargeConsistent, 0 otherwise; for muons, absolute value of the sum of all the charges (5 for global-muons, 3 for global muons)"
        ),
        NTupleVariable("ptErrTk",
                       lambda lepton: (lepton.gsfTrack().ptError())
                       if abs(lepton.pdgId()) == 11 else
                       (lepton.muonBestTrack().ptError()),
                       help="pt error, for the gsf track or muon best track"),
        # variables for isolated electron trigger matching cuts
        NTupleVariable("ecalPFClusterIso",
                       lambda lepton: lepton.ecalPFClusterIso()
                       if abs(lepton.pdgId()) == 11 else -999,
                       help="Electron ecalPFClusterIso"),
        NTupleVariable("hcalPFClusterIso",
                       lambda lepton: lepton.hcalPFClusterIso()
                       if abs(lepton.pdgId()) == 11 else -999,
                       help="Electron hcalPFClusterIso"),
        NTupleVariable("dr03TkSumPt",
                       lambda lepton: lepton.dr03TkSumPt()
                       if abs(lepton.pdgId()) == 11 else -999,
                       help="Electron dr03TkSumPt isolation"),
        NTupleVariable("trackIso",
                       lambda lepton: lepton.trackIso()
                       if abs(lepton.pdgId()) == 11 else -999,
                       help="Electron trackIso (in cone of 0.4)"),
        NTupleVariable("etaSc",
                       lambda x: x.superCluster().eta()
                       if abs(x.pdgId()) == 11 else -100,
                       help="Electron supercluster pseudorapidity"),
        NTupleVariable("energySc",
                       lambda x: x.superCluster().energy()
                       if abs(x.pdgId()) == 11 else -100,
                       help="Electron supercluster pseudorapidity"),
        NTupleVariable(
            "e5x5",
            lambda x: x.full5x5_e5x5()
            if (abs(x.pdgId()) == 11 and hasattr(x, "full5x5_e5x5")) else -999,
            help="Electron full5x5_e5x5"),
        NTupleVariable("sigmaIetaIeta",
                       lambda x: x.full5x5_sigmaIetaIeta()
                       if (abs(x.pdgId()) == 11 and hasattr(
                           x, "full5x5_sigmaIetaIeta")) else -999,
                       help="Electron full5x5_sigmaIetaIeta"),
        NTupleVariable("hcalOverEcal",
                       lambda x: x.full5x5_hcalOverEcal()
                       if (abs(x.pdgId()) == 11 and hasattr(
                           x, "full5x5_hcalOverEcal")) else -999,
                       help="Electron full5x5_hcalOverEcal"),
        NTupleVariable("eSuperClusterOverP",
                       lambda x: x.eSuperClusterOverP()
                       if (abs(x.pdgId()) == 11 and hasattr(
                           x, "eSuperClusterOverP")) else -999,
                       help="Electron eSuperClusterOverP"),
    ])
示例#4
0
leptonTypeSusy = NTupleObjectType(
    "leptonSusy",
    baseObjectTypes=[leptonType],
    variables=[
        # Lepton MVA-id related variables
        NTupleVariable("mvaTTH",
                       lambda lepton: getattr(lepton, 'mvaValueTTH', -1),
                       help="Lepton MVA (TTH version)"),
        NTupleVariable("mvaSUSY",
                       lambda lepton: getattr(lepton, 'mvaValueSUSY', -1),
                       help="Lepton MVA (SUSY version)"),
        NTupleVariable(
            "jetPtRatiov2",
            lambda lepton: lepton.pt() / jetLepAwareJEC(lepton).Pt()
            if hasattr(lepton, 'jet') else -1,
            help="pt(lepton)/[rawpt(jet-PU-lep)*L2L3Res+pt(lepton)]"),
        NTupleVariable(
            "jetPtRelv2",
            lambda lepton: ptRelv2(lepton) if hasattr(lepton, 'jet') else -1,
            help=
            "pt of the lepton transverse to the jet axis (subtracting the lepton) - v2"
        ),
        NTupleVariable(
            "jetBTagCSV",
            lambda lepton: lepton.jet.btag(
                'pfCombinedInclusiveSecondaryVertexV2BJetTags')
            if hasattr(lepton, 'jet') and hasattr(lepton.jet, 'btag') else -99,
            help="CSV btag of nearest jet"),
        NTupleVariable("jetBTagDeepCSV",
                       lambda lepton: (lambda x: -99 if isnan(x) else x)
                       (lepton.jet.btag('pfDeepCSVJetTags:probb') + lepton.jet.
                        btag('pfDeepCSVJetTags:probbb')
                        if hasattr(lepton, 'jet') and hasattr(
                            lepton.jet, 'btag') else -99),
                       help="DeepCSV btag of nearest jet, BvsAll = b+bb"),
        NTupleVariable("jetBTagDeepCSVCvsB",
                       lambda lepton: (lambda x: -99 if isnan(x) else x)
                       ((lepton.jet.btag('pfDeepCSVJetTags:probc') /
                         (lepton.jet.btag('pfDeepCSVJetTags:probc') + lepton.
                          jet.btag('pfDeepCSVJetTags:probb') + lepton.jet.btag(
                              'pfDeepCSVJetTags:probbb')))
                        if hasattr(lepton, 'jet') and hasattr(
                            lepton.jet, 'btag') else -99),
                       help="DeepCSV btag of nearest jet, CvsB = c/(c+b+bb)"),
        NTupleVariable("jetBTagDeepCSVCvsL",
                       lambda lepton: (lambda x: -99 if isnan(x) else x)
                       ((lepton.jet.btag('pfDeepCSVJetTags:probc') /
                         (lepton.jet.btag('pfDeepCSVJetTags:probc') + lepton.
                          jet.btag('pfDeepCSVJetTags:probudsg')))
                        if hasattr(lepton, 'jet') and hasattr(
                            lepton.jet, 'btag') else -99),
                       help="DeepCSV btag of nearest jet, CvsL = c/(c+udsg)"),
        NTupleVariable(
            "miniRelIsoCharged",
            lambda x: getattr(x, 'miniAbsIsoCharged', -99) / x.pt()),
        NTupleVariable(
            "miniRelIsoNeutral",
            lambda x: getattr(x, 'miniAbsIsoNeutral', -99) / x.pt()),
        NTupleVariable(
            "jetNDauChargedMVASel",
            lambda lepton: sum((deltaR(x.eta(), x.phi(), lepton.jet.eta(
            ), lepton.jet.phi()) <= 0.4 and x.charge() != 0 and x.fromPV() > 1
                                and x.hasTrackDetails() and qualityTrk(
                                    x.pseudoTrack(), lepton.associatedVertex))
                               for x in lepton.jet.daughterPtrVector())
            if hasattr(lepton, 'jet') and lepton.jet != lepton else 0,
            help=
            "n charged daughters (with selection for ttH lepMVA) of nearest jet"
        ),
        # More ID
        NTupleVariable("chargedHadRelIso04",
                       lambda x: x.chargedHadronIso(0.4) / x.pt(),
                       help="PF Rel Iso, R=0.4, charged hadrons only"),
        NTupleVariable("trackerLayers",
                       lambda x:
                       (x.track()
                        if abs(x.pdgId()) == 13 else x.gsfTrack()).hitPattern(
                        ).trackerLayersWithMeasurement(),
                       int,
                       help="Tracker Layers"),
        NTupleVariable("pixelLayers",
                       lambda x:
                       (x.track()
                        if abs(x.pdgId()) == 13 else x.gsfTrack()).hitPattern(
                        ).pixelLayersWithMeasurement(),
                       int,
                       help="Pixel Layers"),
        NTupleVariable(
            "chargeConsistency",
            lambda lepton: (lepton.isGsfCtfScPixChargeConsistent() + lepton.
                            isGsfScPixChargeConsistent())
            if abs(lepton.pdgId()) == 11 else abs(
                lepton.muonBestTrack().charge() + lepton.innerTrack().charge(
                ) + lepton.tunePMuonBestTrack().charge() +
                (lepton.globalTrack().charge() + lepton.outerTrack().charge()
                 if lepton.isGlobalMuon() else 0)),
            int,
            help=
            "Tight charge criteria: for electrons, 2 if isGsfCtfScPixChargeConsistent, 1 if only isGsfScPixChargeConsistent, 0 otherwise; for muons, absolute value of the sum of all the charges (5 for global-muons, 3 for global muons)"
        ),
        NTupleVariable("ptErrTk",
                       lambda lepton: (lepton.gsfTrack().ptError())
                       if abs(lepton.pdgId()) == 11 else
                       (lepton.muonBestTrack().ptError()),
                       help="pt error, for the gsf track or muon best track"),
        # More ID: muons
        NTupleVariable(
            "nStations",
            lambda lepton: lepton.numberOfMatchedStations()
            if abs(lepton.pdgId()) == 13 else 4,
            help="Number of matched muons stations (4 for electrons)"),
        NTupleVariable("segmentCompatibility",
                       lambda lepton: lepton.segmentCompatibility()
                       if abs(lepton.pdgId()) == 13 else 0,
                       help="Segment-based compatibility"),
        NTupleVariable("softMuonId",
                       lambda x: x.muonID("POG_ID_Soft")
                       if abs(x.pdgId()) == 13 else 1,
                       int,
                       help="Muon POG Soft id"),
        NTupleVariable("softMuonId2016",
                       lambda lepton: _soft_MuonId_2016ICHEP(lepton),
                       help="Soft muon ID retuned for ICHEP 2016"),
        NTupleVariable("mediumMuonID2016",
                       lambda lepton: _medium_MuonId_2016ICHEP(lepton),
                       help="Medium muon ID retuned for ICHEP 2016"),
        NTupleVariable(
            "muonTrackType",
            lambda lepton: 1
            if abs(lepton.pdgId()) == 11 else lepton.muonBestTrackType(),
            int,
            help="Muon best track type"),
        # More ID: electrons
        NTupleVariable("mvaIdSpring16HZZ",
                       lambda lepton: lepton.mvaRun2("Spring16HZZ")
                       if abs(lepton.pdgId()) == 11 else 1,
                       help="EGamma POG MVA ID, Spring16, HZZ; 1 for muons"),
        NTupleVariable(
            "mvaIdSpring16GP",
            lambda lepton: lepton.mvaRun2("Spring16GP")
            if abs(lepton.pdgId()) == 11 else 1,
            help="EGamma POG MVA ID, Spring16, GeneralPurpose; 1 for muons"),
        NTupleVariable(
            "mvaIdFall17noIso",
            lambda lepton: lepton.mvaRun2("Fall17noIso")
            if abs(lepton.pdgId()) == 11 else 1,
            help=
            "EGamma POG MVA ID, Fall17 training, without isolation; 1 for muons"
        ),
        NTupleVariable(
            "mvaIdFall17Iso",
            lambda lepton: lepton.mvaRun2("Fall17Iso")
            if abs(lepton.pdgId()) == 11 else 1,
            help=
            "EGamma POG MVA ID, Fall17 training, with isolation; 1 for muons"),
        NTupleVariable(
            "r9",
            lambda lepton: lepton.full5x5_r9()
            if abs(lepton.pdgId()) == 11 else -99,
            help=
            "SuperCluster 5x5 r9 variable, only for electrons; -99 for muons"),
        NTupleVariable(
            "sigmaIEtaIEta",
            lambda x: x.full5x5_sigmaIetaIeta() if abs(x.pdgId()) == 11 else 0,
            help="Electron sigma(ieta ieta), with full5x5 cluster shapes"),
        NTupleVariable(
            "dEtaScTrkIn",
            lambda x: x.deltaEtaSuperClusterTrackAtVtx()
            if abs(x.pdgId()) == 11 else 0,
            help=
            "Electron deltaEtaSuperClusterTrackAtVtx (without absolute value!)"
        ),
        NTupleVariable(
            "dPhiScTrkIn",
            lambda x: x.deltaPhiSuperClusterTrackAtVtx()
            if abs(x.pdgId()) == 11 else 0,
            help=
            "Electron deltaPhiSuperClusterTrackAtVtx (without absolute value!)"
        ),
        NTupleVariable("hadronicOverEm",
                       lambda x: x.hadronicOverEm()
                       if abs(x.pdgId()) == 11 else 0,
                       help="Electron hadronicOverEm"),
        NTupleVariable(
            "eInvMinusPInv",
            lambda x:
            ((1.0 / x.ecalEnergy() - x.eSuperClusterOverP() / x.ecalEnergy())
             if x.ecalEnergy() > 0. else 9e9) if abs(x.pdgId()) == 11 else 0,
            help="Electron 1/E - 1/p  (without absolute value!)"),
        NTupleVariable(
            "eInvMinusPInv_tkMom",
            lambda x: ((1.0 / x.ecalEnergy()) -
                       (1.0 / x.trackMomentumAtVtx().R())
                       if (x.ecalEnergy() > 0. and x.trackMomentumAtVtx().R()
                           > 0.) else 9e9) if abs(x.pdgId()) == 11 else 0,
            help="Electron 1/E - 1/p_tk_vtx  (without absolute value!)"),
        NTupleVariable("ecalPFClusterIso",
                       lambda lepton: lepton.ecalPFClusterIso()
                       if abs(lepton.pdgId()) == 11 else -999,
                       help="Electron ecalPFClusterIso"),
        NTupleVariable("hcalPFClusterIso",
                       lambda lepton: lepton.hcalPFClusterIso()
                       if abs(lepton.pdgId()) == 11 else -999,
                       help="Electron hcalPFClusterIso"),
        NTupleVariable("dr03TkSumPt",
                       lambda lepton: lepton.dr03TkSumPt()
                       if abs(lepton.pdgId()) == 11 else -999,
                       help="Electron dr03TkSumPt isolation"),
        NTupleVariable("trackIso",
                       lambda lepton: lepton.trackIso()
                       if abs(lepton.pdgId()) == 11 else -999,
                       help="Electron trackIso (in cone of 0.4)"),
        NTupleVariable("etaSc",
                       lambda x: x.superCluster().eta()
                       if abs(x.pdgId()) == 11 else -100,
                       help="Electron supercluster pseudorapidity"),
        NTupleVariable("energySc",
                       lambda x: x.superCluster().energy()
                       if abs(x.pdgId()) == 11 else -100,
                       help="Electron supercluster pseudorapidity"),
        NTupleVariable(
            "idEmuTTH",
            lambda lepton: _ttH_idEmu_cuts_E2_obj(lepton),
            help="Electron pass trigger ID emulation cuts (TTH, E2)"),
        # More: MC
        NTupleVariable(
            "mcMatchPdgId",
            lambda x: x.mcLep.pdgId()
            if getattr(x, 'mcLep', None) != None else -99,
            int,
            mcOnly=True,
            help=
            "Match to source from hard scatter (pdgId of heaviest particle in chain, 25 for H, 6 for t, 23/24 for W/Z): pdgId of the matched gen-level lepton, zero if non-prompt or fake"
        ),
        NTupleVariable("mcPrompt",
                       lambda x: x.mcMatchAny_gp.isPromptFinalState()
                       if getattr(x, "mcMatchAny_gp", None) else 0,
                       int,
                       mcOnly=True,
                       help="isPromptFinalState"),
        NTupleVariable("mcPromptTau",
                       lambda x: x.mcMatchAny_gp.
                       isDirectPromptTauDecayProductFinalState()
                       if getattr(x, "mcMatchAny_gp", None) else 0,
                       int,
                       mcOnly=True,
                       help="isDirectPromptTauDecayProductFinalState"),
        NTupleVariable("mcPromptGamma",
                       lambda x: x.mcPho.isPromptFinalState()
                       if getattr(x, "mcPho", None) else 0,
                       int,
                       mcOnly=True,
                       help="Photon isPromptFinalState"),
        NTupleVariable("mcGamma",
                       lambda x: getattr(x, "mcPho", None) != None,
                       int,
                       mcOnly=True,
                       help="Matched to a photon"),
    ])
示例#5
0
##------------------------------------------  
## LEPTON
##------------------------------------------  

leptonTypeSusy = NTupleObjectType("leptonSusy", baseObjectTypes = [ leptonType ], variables = [
    NTupleVariable("mvaIdSpring15",   lambda lepton : lepton.mvaRun2("NonTrigSpring15MiniAOD") if abs(lepton.pdgId()) == 11 else 1, help="EGamma POG MVA ID for non-triggering electrons, Spring15 re-training; 1 for muons"),
    # Lepton MVA-id related variables
    NTupleVariable("mvaTTH",    lambda lepton : getattr(lepton, 'mvaValueTTH', -1), help="Lepton MVA (TTH version)"),
    NTupleVariable("mvaSUSY",    lambda lepton : getattr(lepton, 'mvaValueSUSY', -1), help="Lepton MVA (SUSY version)"),
    NTupleVariable("jetPtRatiov1", lambda lepton : lepton.pt()/lepton.jet.pt() if hasattr(lepton,'jet') else -1, help="pt(lepton)/pt(nearest jet)"),
    NTupleVariable("jetPtRelv1", lambda lepton : ptRelv1(lepton.p4(),lepton.jet.p4()) if hasattr(lepton,'jet') else -1, help="pt of the lepton transverse to the jet axis (subtracting the lepton)"),
    NTupleVariable("jetPtRatiov2", lambda lepton: lepton.pt()/jetLepAwareJEC(lepton).Pt() if hasattr(lepton,'jet') else -1, help="pt(lepton)/[rawpt(jet-PU-lep)*L2L3Res+pt(lepton)]"),
    NTupleVariable("jetPtRelv2", lambda lepton : ptRelv2(lepton) if hasattr(lepton,'jet') else -1, help="pt of the lepton transverse to the jet axis (subtracting the lepton) - v2"),
    NTupleVariable("jetBTagCSV", lambda lepton : lepton.jet.btag('pfCombinedInclusiveSecondaryVertexV2BJetTags') if hasattr(lepton,'jet') and hasattr(lepton.jet, 'btag') else -99, help="CSV btag of nearest jet"),
    NTupleVariable("jetBTagCMVA", lambda lepton : lepton.jet.btag('pfCombinedMVABJetTags') if hasattr(lepton,'jet') and hasattr(lepton.jet, 'btag') else -99, help="CMA btag of nearest jet"),
    NTupleVariable("jetDR",      lambda lepton : deltaR(lepton.eta(),lepton.phi(),lepton.jet.eta(),lepton.jet.phi()) if hasattr(lepton,'jet') else -1, help="deltaR(lepton, nearest jet)"),
    NTupleVariable("r9",      lambda lepton : lepton.full5x5_r9() if abs(lepton.pdgId()) == 11 else -99, help="SuperCluster 5x5 r9 variable, only for electrons; -99 for muons"),
    #2016 muon Id
    NTupleVariable("softMuonId2016", lambda lepton: _soft_MuonId_2016ICHEP(lepton), help="Soft muon ID retuned for ICHEP 2016"),
    NTupleVariable("mediumMuonID2016", lambda lepton: _medium_MuonId_2016ICHEP(lepton), help="Medium muon ID retuned for ICHEP 2016"),
    # More
    NTupleVariable("tightChargeFix",  lambda lepton : ( lepton.isGsfCtfScPixChargeConsistent() + lepton.isGsfScPixChargeConsistent() ) if abs(lepton.pdgId()) == 11 else 2*(lepton.muonBestTrack().ptError()/lepton.muonBestTrack().pt() < 0.2), int, help="Tight charge criteria: for electrons, 2 if isGsfCtfScPixChargeConsistent, 1 if only isGsfScPixChargeConsistent, 0 otherwise; for muons, 2 if ptError/pt < 0.20, 0 otherwise (using the muon best track)"),
    NTupleVariable("muonTrackType",  lambda lepton : 1 if abs(lepton.pdgId()) == 11 else lepton.muonBestTrackType(), int, help="Muon best track type"),
    NTupleVariable("chargeConsistency",  lambda lepton : ( lepton.isGsfCtfScPixChargeConsistent() + lepton.isGsfScPixChargeConsistent() ) if abs(lepton.pdgId()) == 11 else abs(lepton.muonBestTrack().charge() + lepton.innerTrack().charge() + lepton.tunePMuonBestTrack().charge() + ( lepton.globalTrack().charge() + lepton.outerTrack().charge() if lepton.isGlobalMuon() else 0) ), int, help="Tight charge criteria: for electrons, 2 if isGsfCtfScPixChargeConsistent, 1 if only isGsfScPixChargeConsistent, 0 otherwise; for muons, absolute value of the sum of all the charges (5 for global-muons, 3 for global muons)"),
    NTupleVariable("ptErrTk",  lambda lepton : ( lepton.gsfTrack().ptError() ) if abs(lepton.pdgId()) == 11 else (lepton.muonBestTrack().ptError()), help="pt error, for the gsf track or muon best track"),
])


leptonTypeSusyExtraLight = NTupleObjectType("leptonSusyExtraLight", baseObjectTypes = [ leptonTypeSusy, leptonTypeExtra ], variables = [
    NTupleVariable("miniRelIsoCharged",   lambda x : getattr(x,'miniAbsIsoCharged',-99)/x.pt()),
    NTupleVariable("miniRelIsoNeutral",   lambda x : getattr(x,'miniAbsIsoNeutral',-99)/x.pt()),
示例#6
0
leptonTypeSusyExtra = NTupleObjectType("leptonSusyExtra", baseObjectTypes = [ leptonTypeSusy, leptonTypeExtra ], variables = [
    NTupleVariable("miniRelIsoCharged",   lambda x : getattr(x,'miniAbsIsoCharged',-99)/x.pt()),
    NTupleVariable("miniRelIsoNeutral",   lambda x : getattr(x,'miniAbsIsoNeutral',-99)/x.pt()),
    # IVF variables
    NTupleVariable("hasSV",   lambda x : (2 if getattr(x,'ivfAssoc','') == "byref" else (0 if getattr(x,'ivf',None) == None else 1)), int, help="2 if lepton track is from a SV, 1 if loosely matched, 0 if no SV found."),
    NTupleVariable("svRedPt", lambda x : getattr(x, 'ivfRedPt', 0), help="pT of associated SV, removing the lepton track"),
    NTupleVariable("svRedM",  lambda x : getattr(x, 'ivfRedM', 0), help="mass of associated SV, removing the lepton track"),
    NTupleVariable("svLepSip3d", lambda x : getattr(x, 'ivfSip3d', 0), help="sip3d of lepton wrt SV"),
    NTupleVariable("svSip3d", lambda x : x.ivf.d3d.significance() if getattr(x,'ivf',None) != None else -99, help="S_{ip3d} of associated SV"),
    NTupleVariable("svNTracks", lambda x : x.ivf.numberOfDaughters() if getattr(x,'ivf',None) != None else -99, help="Number of tracks of associated SV"),
    NTupleVariable("svChi2n", lambda x : x.ivf.vertexChi2()/x.ivf.vertexNdof() if getattr(x,'ivf',None) != None else -99, help="Normalized chi2 of associated SV"),
    NTupleVariable("svDxy", lambda x : x.ivf.dxy.value() if getattr(x,'ivf',None) != None else -99, help="dxy of associated SV"),
    NTupleVariable("svMass", lambda x : x.ivf.mass() if getattr(x,'ivf',None) != None else -99, help="mass of associated SV"),
    NTupleVariable("svPt", lambda x : x.ivf.pt() if getattr(x,'ivf',None) != None else -99, help="pt of associated SV"),
    NTupleVariable("svMCMatchFraction", lambda x : x.ivf.mcMatchFraction if getattr(x,'ivf',None) != None else -99, mcOnly=True, help="Fraction of mc-matched tracks from b/c matched to a single hadron (if >= 2 tracks found), for associated SV"),
    NTupleVariable("svMva", lambda x : x.ivf.mva if getattr(x,'ivf',None) != None else -99, help="mva value of associated SV"),
    # Additional jet-lepton related variables
    NTupleVariable("jetNDau",    lambda lepton : lepton.jet.numberOfDaughters() if hasattr(lepton,'jet') and lepton.jet != lepton else -1, help="n daughters of nearest jet"),
    NTupleVariable("jetNDauCharged",    lambda lepton : sum(x.charge()!=0 for x in lepton.jet.daughterPtrVector()) if hasattr(lepton,'jet') and lepton.jet != lepton else -1, help="n charged daughters of nearest jet"),
    NTupleVariable("jetNDauPV",    lambda lepton : sum(x.charge()!=0 and x.fromPV()==3 for x in lepton.jet.daughterPtrVector()) if hasattr(lepton,'jet') and lepton.jet != lepton else -1, help="n charged daughters from PV of nearest jet"),
    NTupleVariable("jetNDauNotPV",    lambda lepton : sum(x.charge()!=0 and x.fromPV()<=2 for x in lepton.jet.daughterPtrVector()) if hasattr(lepton,'jet') and lepton.jet != lepton else -1, help="n charged daughters from PV of nearest jet"),
    NTupleVariable("jetNDauChargedMVASel",    lambda lepton : sum((deltaR(x.eta(),x.phi(),lepton.jet.eta(),lepton.jet.phi())<=0.4 and x.charge()!=0 and x.fromPV()>1 and qualityTrk(x.pseudoTrack(),lepton.associatedVertex)) for x in lepton.jet.daughterPtrVector()) if hasattr(lepton,'jet') and lepton.jet != lepton else 0, help="n charged daughters (with selection for ttH lepMVA) of nearest jet"),
    NTupleVariable("jetmaxSignedSip3D",    lambda lepton :  maxSignedSip3Djettracks(lepton), help="max signed Sip3D among jet's tracks"),
    NTupleVariable("jetmaxSip3D",    lambda lepton :   maxSip3Djettracks(lepton), help="max Sip3D among jet's tracks"),
    NTupleVariable("jetmaxSignedSip2D",    lambda lepton  : maxSignedSip2Djettracks(lepton) , help="max signed Sip2D among jet's tracks"),
    NTupleVariable("jetmaxSip2D",    lambda lepton :   maxSip2Djettracks(lepton), help="max Sip2D among jet's tracks"),
    NTupleVariable("jetPtRelv0",   lambda lepton : ptRel(lepton.p4(),lepton.jet.p4()) if hasattr(lepton,'jet') else -1, help="pt of the lepton transverse to the jet axis (not subtracting the lepton)"),
    NTupleVariable("jetMass",      lambda lepton : lepton.jet.mass() if hasattr(lepton,'jet') else -1, help="Mass of associated jet"),
    NTupleVariable("jetPrunedMass",      lambda lepton : getattr(lepton.jet, 'prunedP4', lepton.jet.p4()).M() if hasattr(lepton,'jet') else -1, help="Pruned mass of associated jet"),
    NTupleVariable("jetDecDR",      lambda lepton : lepton.jetDecDR if hasattr(lepton,'jetDecDR') else -1, help="deltaR(lepton, nearest jet) after declustering"),
    NTupleVariable("jetDecPtRel", lambda lepton : lepton.jetDecPtRel if hasattr(lepton,'jetDecPtRel') else -1, help="pt of the lepton transverse to the jet axis (subtracting the lepton), after declustering"),
    NTupleVariable("jetDecPtRatio", lambda lepton :  lepton.jetDecPtRatio if hasattr(lepton,'jetDecPtRatio') else -1, help="pt(lepton)/pt(nearest jet) after declustering"),
    NTupleVariable("jetDecPrunedMass", lambda lepton :  lepton.jetDecPrunedMass if hasattr(lepton,'jetDecPrunedMass') else -1, help="pt(lepton)/pt(nearest jet) after declustering and pruning"),
    NTupleVariable("jetDecPrunedPtRatio", lambda lepton :  lepton.jetDecPrunedPtRatio if hasattr(lepton,'jetDecPrunedPtRatio') else -1, help="pt(lepton)/pt(nearest jet) after declustering and pruning"),
    NTupleVariable("jetDec02DR",      lambda lepton : lepton.jetDec02DR if hasattr(lepton,'jetDec02DR') else -1, help="deltaR(lepton, nearest jet) after declustering 02"),
    NTupleVariable("jetDec02PtRel", lambda lepton : lepton.jetDec02PtRel if hasattr(lepton,'jetDec02PtRel') else -1, help="pt of the lepton transverse to the jet axis (subtracting the lepton), after declustering 02"),
    NTupleVariable("jetDec02PtRatio", lambda lepton :  lepton.jetDec02PtRatio if hasattr(lepton,'jetDec02PtRatio') else -1, help="pt(lepton)/pt(nearest jet) after declustering 02"),
    NTupleVariable("jetDec02PrunedPtRatio", lambda lepton :  lepton.jetDec02PrunedPtRatio if hasattr(lepton,'jetDec02PrunedPtRatio') else -1, help="pt(lepton)/pt(nearest jet) after declustering 02 and pruning"),
    NTupleVariable("jetDec02PrunedMass", lambda lepton :  lepton.jetDec02PrunedMass if hasattr(lepton,'jetDec02PrunedMass') else -1, help="pt(lepton)/pt(nearest jet) after declustering 02 and pruning"),
    NTupleVariable("jetRawPt", lambda x: x.jet.pt() * x.jet.rawFactor() if x.jet!=x else x.pt(), help="matched jet raw pt"),
    NTupleVariable("jetCorrFactor_L1", lambda x: x.jet.CorrFactor_L1 if hasattr(x.jet,'CorrFactor_L1') else 1, help="matched jet L1 correction factor"),
    NTupleVariable("jetCorrFactor_L1L2", lambda x: x.jet.CorrFactor_L1L2 if hasattr(x.jet,'CorrFactor_L1L2') else 1, help="matched jet L1L2 correction factor"),
    NTupleVariable("jetCorrFactor_L1L2L3", lambda x: x.jet.CorrFactor_L1L2L3 if hasattr(x.jet,'CorrFactor_L1L2L3') else 1, help="matched jet L1L2L3 correction factor"),
    NTupleVariable("jetCorrFactor_L1L2L3Res", lambda x: x.jet.CorrFactor_L1L2L3Res if hasattr(x.jet,'CorrFactor_L1L2L3Res') else 1, help="matched jet L1L2L3Res correction factor"),
    NTupleVariable("jetPtRatio_Raw", lambda lepton : -1 if not hasattr(lepton,'jet') else lepton.pt()/lepton.jet.pt() if not hasattr(lepton.jet,'rawFactor') else lepton.pt()/(lepton.jet.pt()*lepton.jet.rawFactor()), help="pt(lepton)/rawpt(nearest jet)"),
    NTupleVariable("jetPtRelHv2", lambda lepton : ptRelHv2(lepton) if hasattr(lepton,'jet') else -1, help="pt of the jet (subtracting the lepton) transverse to the lepton axis - v2"),
    # variables for isolated electron trigger matching cuts
    NTupleVariable("ecalPFClusterIso", lambda lepton :  lepton.ecalPFClusterIso() if abs(lepton.pdgId())==11 else -999, help="Electron ecalPFClusterIso"),
    NTupleVariable("hcalPFClusterIso", lambda lepton :  lepton.hcalPFClusterIso() if abs(lepton.pdgId())==11 else -999, help="Electron hcalPFClusterIso"),
    NTupleVariable("dr03TkSumPt", lambda lepton: lepton.dr03TkSumPt() if abs(lepton.pdgId())==11 else -999, help="Electron dr03TkSumPt isolation"),
    NTupleVariable("trackIso", lambda lepton :  lepton.trackIso() if abs(lepton.pdgId())==11 else -999, help="Electron trackIso (in cone of 0.4)"),
    NTupleVariable("idEmu", lambda lepton: _susy2lss_idEmu_cuts(lepton), help="Electron pass trigger ID emulation cuts"),
    NTupleVariable("idIsoEmu", lambda lepton: _susy2lss_idIsoEmu_cuts(lepton), help="Electron pass trigger ID+ISO emulation cuts"),
])
示例#7
0
from PhysicsTools.HeppyCore.utils.deltar import deltaR

from CMGTools.TTHAnalysis.signedSip import *
from CMGTools.TTHAnalysis.tools.emulateElectronTriggerCuts import _susy2lss_idEmu_cuts,_susy2lss_idIsoEmu_cuts

##------------------------------------------  
## LEPTON
##------------------------------------------  

leptonTypeSusy = NTupleObjectType("leptonSusy", baseObjectTypes = [ leptonType ], variables = [
    NTupleVariable("mvaIdSpring15",   lambda lepton : lepton.mvaRun2("NonTrigSpring15MiniAOD") if abs(lepton.pdgId()) == 11 else 1, help="EGamma POG MVA ID for non-triggering electrons, Spring15 re-training; 1 for muons"),
    # Lepton MVA-id related variables
    NTupleVariable("mvaTTH",    lambda lepton : getattr(lepton, 'mvaValueTTH', -1), help="Lepton MVA (TTH version)"),
    NTupleVariable("jetPtRatiov1", lambda lepton : lepton.pt()/lepton.jet.pt() if hasattr(lepton,'jet') else -1, help="pt(lepton)/pt(nearest jet)"),
    NTupleVariable("jetPtRelv1", lambda lepton : ptRelv1(lepton.p4(),lepton.jet.p4()) if hasattr(lepton,'jet') else -1, help="pt of the lepton transverse to the jet axis (subtracting the lepton)"),
    NTupleVariable("jetPtRatiov2", lambda lepton: lepton.pt()/jetLepAwareJEC(lepton).Pt() if hasattr(lepton,'jet') else -1, help="pt(lepton)/[rawpt(jet-PU-lep)*L2L3Res+pt(lepton)]"),
    NTupleVariable("jetPtRelv2", lambda lepton : ptRelv2(lepton) if hasattr(lepton,'jet') else -1, help="pt of the lepton transverse to the jet axis (subtracting the lepton) - v2"),
    NTupleVariable("jetBTagCSV", lambda lepton : lepton.jet.btag('pfCombinedInclusiveSecondaryVertexV2BJetTags') if hasattr(lepton,'jet') and hasattr(lepton.jet, 'btag') else -99, help="CSV btag of nearest jet"),
    NTupleVariable("jetBTagCMVA", lambda lepton : lepton.jet.btag('pfCombinedMVABJetTags') if hasattr(lepton,'jet') and hasattr(lepton.jet, 'btag') else -99, help="CMA btag of nearest jet"),
    NTupleVariable("jetDR",      lambda lepton : deltaR(lepton.eta(),lepton.phi(),lepton.jet.eta(),lepton.jet.phi()) if hasattr(lepton,'jet') else -1, help="deltaR(lepton, nearest jet)"),
    NTupleVariable("r9",      lambda lepton : lepton.full5x5_r9() if abs(lepton.pdgId()) == 11 else -99, help="SuperCluster 5x5 r9 variable, only for electrons; -99 for muons"),
])


leptonTypeSusyExtraLight = NTupleObjectType("leptonSusyExtraLight", baseObjectTypes = [ leptonTypeSusy, leptonTypeExtra ], variables = [
    NTupleVariable("miniRelIsoCharged",   lambda x : getattr(x,'miniAbsIsoCharged',-99)/x.pt()),
    NTupleVariable("miniRelIsoNeutral",   lambda x : getattr(x,'miniAbsIsoNeutral',-99)/x.pt()),
    NTupleVariable("jetNDauChargedMVASel",    lambda lepton : sum((deltaR(x.eta(),x.phi(),lepton.jet.eta(),lepton.jet.phi())<=0.4 and x.charge()!=0 and x.fromPV()>1 and qualityTrk(x.pseudoTrack(),lepton.associatedVertex)) for x in lepton.jet.daughterPtrVector()) if hasattr(lepton,'jet') and lepton.jet != lepton else 0, help="n charged daughters (with selection for ttH lepMVA) of nearest jet"),
    NTupleVariable("jetCorrFactor_L1", lambda x: x.jet.CorrFactor_L1 if hasattr(x.jet,'CorrFactor_L1') else 1, help="matched jet L1 correction factor"),
    NTupleVariable("jetCorrFactor_L1L2", lambda x: x.jet.CorrFactor_L1L2 if hasattr(x.jet,'CorrFactor_L1L2') else 1, help="matched jet L1L2 correction factor"),
    NTupleVariable("jetCorrFactor_L1L2L3", lambda x: x.jet.CorrFactor_L1L2L3 if hasattr(x.jet,'CorrFactor_L1L2L3') else 1, help="matched jet L1L2L3 correction factor"),