Пример #1
0
def addTauAnalyses(process, prefix, prototype, commonSequence,
                   additionalCounters):
    def disableRtau(module):
        return module.clone(rtauCut=-1)

    values = [
        HChSignalAnalysisParameters.tauSelectionHPSLooseTauBased,
        disableRtau(HChSignalAnalysisParameters.tauSelectionHPSLooseTauBased),
        disableRtau(HChSignalAnalysisParameters.tauSelectionHPSMediumTauBased),
        disableRtau(HChSignalAnalysisParameters.tauSelectionHPSTauBased),
        disableRtau(
            HChSignalAnalysisParameters.tauSelectionShrinkingConeCutBased),
    ]
    names = [
        "TauSelectionHPSLooseTauBased",
        "TauSelectionHPSLooseTauNoRtauBased",
        "TauSelectionHPSMediumTauNoRtauBased",
        "TauSelectionHPSTightTauNoRtauBased",
        "TauSelectionShrinkingConeCutNoRtauBased",
    ]

    HChTools.addAnalysisArray(process,
                              prefix,
                              prototype,
                              HChSignalAnalysisParameters.setTauSelection,
                              values=values,
                              names=names,
                              preSequence=commonSequence,
                              additionalCounters=additionalCounters)
Пример #2
0
def addGenuineTauPreselection(process,
                              sequence,
                              param,
                              prefix="genuineTauPreselection",
                              pileupWeight=None,
                              maxGenTaus=None):
    counters = []

    genTauSequence = cms.Sequence()
    # Create PU weight producer for the counters
    if pileupWeight == None:
        puModule = cms.EDProducer(
            "HPlusVertexWeightProducer",
            alias=cms.string("pileupWeight"),
            histogramAmbientLevel=cms.untracked.string("Systematics"))
        HChTools.insertPSetContentsTo(param.vertexWeight.clone(), puModule)
        pileupWeight = prefix + "PileupWeight"
        setattr(process, pileupWeight, puModule)
        genTauSequence *= puModule

    counterPrototype = cms.EDProducer("HPlusEventCountProducer",
                                      weightSrc=cms.InputTag(pileupWeight))

    allCount = counterPrototype.clone()
    setattr(process, prefix + "AllCount", allCount)
    counters.append(prefix + "AllCount")

    # Generator taus (if you modify this, remember to modify similar in below)
    genTaus = cms.EDFilter("GenParticleSelector",
                           src=cms.InputTag("genParticles"),
                           cut=cms.string(generatorTauSelection %
                                          generatorTauPt))
    genTausName = prefix + "GenTau"
    setattr(process, genTausName, genTaus)

    if maxGenTaus is not None:
        genTausFilter = cms.EDFilter(
            "PATCandViewCountFilter",
            src=cms.InputTag(genTausName),
            minNumber=cms.uint32(1),
            maxNumber=cms.uint32(maxGenTaus),
        )
    else:
        genTausFilter = cms.EDFilter(
            "CandViewCountFilter",
            src=cms.InputTag(genTausName),
            minNumber=cms.uint32(1),
        )
    setattr(process, prefix + "GenTauFilter", genTausFilter)

    genTausCount = counterPrototype.clone()
    setattr(process, prefix + "GenTauCount", genTausCount)
    counters.append(prefix + "GenTauCount")

    genTauSequence *= (allCount * genTaus * genTausFilter * genTausCount)
    setattr(process, prefix + "Sequence", genTauSequence)
    sequence *= genTauSequence

    return counters
Пример #3
0
def addGenuineTauPreselection(process, sequence, param, prefix="genuineTauPreselection", pileupWeight=None, maxGenTaus=None):
    counters = []

    genTauSequence = cms.Sequence()
    # Create PU weight producer for the counters
    if pileupWeight == None:
        puModule = cms.EDProducer("HPlusVertexWeightProducer",
            alias = cms.string("pileupWeight"),
            histogramAmbientLevel = cms.untracked.string("Systematics")
        )
        HChTools.insertPSetContentsTo(param.vertexWeight.clone(), puModule)
        pileupWeight = prefix+"PileupWeight"
        setattr(process, pileupWeight, puModule)
        genTauSequence *= puModule
    
    counterPrototype = cms.EDProducer("HPlusEventCountProducer",
        weightSrc = cms.InputTag(pileupWeight)
    )

    allCount = counterPrototype.clone()
    setattr(process, prefix+"AllCount", allCount)
    counters.append(prefix+"AllCount")

    # Generator taus (if you modify this, remember to modify similar in below)
    genTaus = cms.EDFilter("GenParticleSelector",
        src = cms.InputTag("genParticles"),
        cut = cms.string(generatorTauSelection % generatorTauPt)
    )
    genTausName = prefix+"GenTau"
    setattr(process, genTausName, genTaus)

    if maxGenTaus is not None:
        genTausFilter = cms.EDFilter("PATCandViewCountFilter",
            src = cms.InputTag(genTausName),
            minNumber = cms.uint32(1),
            maxNumber = cms.uint32(maxGenTaus),
        )
    else:
        genTausFilter = cms.EDFilter("CandViewCountFilter",
            src = cms.InputTag(genTausName),
            minNumber = cms.uint32(1),
        )
    setattr(process, prefix+"GenTauFilter", genTausFilter)

    genTausCount = counterPrototype.clone()
    setattr(process, prefix+"GenTauCount", genTausCount)
    counters.append(prefix+"GenTauCount")

    genTauSequence *= (
        allCount *
        genTaus * genTausFilter * genTausCount
    )
    setattr(process, prefix+"Sequence", genTauSequence)
    sequence *= genTauSequence

    return counters
Пример #4
0
 def muonCleaningFromJet(self):
     m = self.muonJetCleanerPrototype.clone(src=self.selectedMuons)
     m.checkOverlaps.jets.src = self.selectedJets
     self.selectedMuons = self.analysis.addAnalysisModule("MuonCleaningFromJet",
         selector = m,
         filter = HChTools.makeCountFilter(cms.InputTag("dummy"), minNumber=1),
         counter=True).getSelectorInputTag()
     self.cloneAnalyzers("MuonJetDR", muonSrc=self.selectedMuons)
Пример #5
0
def addGenuineTauPreselection(process, sequence, param, prefix="genuineTauPreselection"):
    counters = []

    # Create PU weight producer for the counters
    pileupWeight = cms.EDProducer("HPlusVertexWeightProducer",
        alias = cms.string("pileupWeight"),
    )
    HChTools.insertPSetContentsTo(param.vertexWeight.clone(), pileupWeight)
    setattr(process, prefix+"PileupWeight", pileupWeight)

    counterPrototype = cms.EDProducer("HPlusEventCountProducer",
        weightSrc = cms.InputTag(prefix+"PileupWeight")
    )

    allCount = counterPrototype.clone()
    setattr(process, prefix+"AllCount", allCount)
    counters.append(prefix+"AllCount")

    # Generator taus (if you modify this, remember to modify similar in below)
    genTaus = cms.EDFilter("GenParticleSelector",
        src = cms.InputTag("genParticles"),
        cut = cms.string("abs(pdgId()) == 15 && pt() > 40 && abs(eta()) < 2.1")
    )
    genTausName = prefix+"GenTau"
    setattr(process, genTausName, genTaus)

    genTausFilter = cms.EDFilter("CandViewCountFilter",
        src = cms.InputTag(genTausName),
        minNumber = cms.uint32(1),
    )
    setattr(process, prefix+"GenTauFilter", genTausFilter)

    genTausCount = counterPrototype.clone()
    setattr(process, prefix+"GenTauCount", genTausCount)
    counters.append(prefix+"GenTauCount")

    genTauSequence = cms.Sequence(
        pileupWeight *
        allCount *
        genTaus * genTausFilter * genTausCount
    )
    setattr(process, prefix+"Sequence", genTauSequence)
    sequence *= genTauSequence

    return counters
Пример #6
0
 def muonExactlyOne(self):
     name = "MuonExactlyOne"
     self.analysis.addAnalysisModule(name,
         filter = HChTools.makeCountFilter(self.selectedMuons, minNumber=1, maxNumber=1),
         counter = True
     )
     if not self.afterOtherCuts:
         self.cloneHistoAnalyzer(name)
     return name
Пример #7
0
 def muonVertexDiff(self):
     name = "MuonVertexDiff"
     maxVertexZ = 1.0 # cm
     self.selectedMuons = self.analysis.addAnalysisModule(name,
         selector = cms.EDFilter("HPlusPATMuonViewPtrVertexZSelector",
                                 src = self.selectedMuons,
                                 vertexSrc = self.selectedPrimaryVertex,
                                 maxZ = cms.double(maxVertexZ)),
         filter = HChTools.makeCountFilter(cms.InputTag("dummy"), minNumber=1),
         counter = True).getSelectorInputTag()
     self.cloneAnalyzers(name, muonSrc=self.selectedMuons)
     return name
Пример #8
0
def addTauAnalyses(process, prefix, prototype, commonSequence, additionalCounters):
    def disableRtau(module):
        return module.clone(rtauCut = -1)

    values = [
        HChSignalAnalysisParameters.tauSelectionHPSLooseTauBased,
        disableRtau(HChSignalAnalysisParameters.tauSelectionHPSLooseTauBased),
        disableRtau(HChSignalAnalysisParameters.tauSelectionHPSMediumTauBased),
        disableRtau(HChSignalAnalysisParameters.tauSelectionHPSTauBased),
        disableRtau(HChSignalAnalysisParameters.tauSelectionShrinkingConeCutBased),
        ]
    names = [
        "TauSelectionHPSLooseTauBased",
        "TauSelectionHPSLooseTauNoRtauBased",
        "TauSelectionHPSMediumTauNoRtauBased",
        "TauSelectionHPSTightTauNoRtauBased",
        "TauSelectionShrinkingConeCutNoRtauBased",
        ]

    HChTools.addAnalysisArray(process, prefix, prototype, HChSignalAnalysisParameters.setTauSelection,
                              values=values, names=names,
                              preSequence=commonSequence, additionalCounters=additionalCounters)
Пример #9
0
    def muonIsolationWithTau(self):
        name = "MuonIsolationWithTau"
        self.selectedMuons = self.analysis.addAnalysisModule(
            name,
            selector = cms.EDProducer("HPlusTauIsolationPATMuonViewPtrSelector",
                                      candSrc = self.selectedMuons,
#                                      tauSrc = cms.InputTag("selectedPatTausShrinkingConePFTau"),
                                      tauSrc = cms.InputTag("selectedPatTausHpsPFTau"),
                                      isolationDiscriminator = cms.string(self._isolationWithTauDiscriminator),
                                      againstMuonDiscriminator = cms.string("againstMuonLoose"),
                                      deltaR = cms.double(0.15),
                                      minCands = cms.uint32(1)),
            filter = HChTools.makeCountFilter(cms.InputTag("dummy"), 1),
            counter=True).getSelectorInputTag()
        self.cloneAnalyzers(name, muonSrc=self.selectedMuons)
def setEfficiency(pset, isolation, againstMuon, againstElectron):
    pset.data = HChTools.getEfficiencyJsonFullPath(
        "met trigger scale factors", "metLegTriggerEfficiency2012",
        "%s_%s_%s" % (isolation, againstMuon, againstElectron))
Пример #11
0
def addMuonIsolationAnalyses(process, prefix, prototype, commonSequence, additionalCounters, modify=_signalAnalysisSetMuon, signalAnalysisCounters=True):
    import muonAnalysis

    detRelIso = muonAnalysis.isolations["sumIsoRel"]
    pfRelIso = muonAnalysis.isolations["pfSumIsoRel"]

    isolations = [
        ("RelIso05", detRelIso+" < 0.05"),
        ("RelIso10", detRelIso+" < 0.10"),
        ("RelIso15", detRelIso+" < 0.15"),
#        ("RelIso20", detRelIso+" < 0.20"),
        ("RelIso25", detRelIso+" < 0.25"),
        ("RelIso50", detRelIso+" < 0.50"),

        ("PfRelIso05", pfRelIso+" < 0.05"),
        ("PfRelIso10", pfRelIso+" < 0.10"),
        ("PfRelIso15", pfRelIso+" < 0.15"),
#        ("PfRelIso20", pfRelIso+" < 0.20"),
        ("PfRelIso25", pfRelIso+" < 0.25"),
        ("PfRelIso50", pfRelIso+" < 0.50"),

        ("IsoTauLikeVLoose", muonAnalysis.isolations["tauVLooseIso"]+" == 0"),
        ("IsoTauLikeLoose",  muonAnalysis.isolations["tauLooseIso"] +" == 0"),
        ("IsoTauLikeMedium", muonAnalysis.isolations["tauMediumIso"]+" == 0"),
        ("IsoTauLikeTight",  muonAnalysis.isolations["tauTightIso"] +" == 0"),
        ("IsoTauLikeTightSc015", muonAnalysis.isolations["tauTightSc015Iso"] +" == 0" ),
        ("IsoTauLikeTightSc02", muonAnalysis.isolations["tauTightSc02Iso"] +" == 0" ),

        ("IsoTauLikeTightIc04",  muonAnalysis.isolations["tauTightIc04Iso"] +" == 0"),
        ("IsoTauLikeTightSc015Ic04", muonAnalysis.isolations["tauTightSc015Ic04Iso"] +" == 0" ),
        ("IsoTauLikeTightSc02Ic04", muonAnalysis.isolations["tauTightSc02Ic04Iso"] +" == 0" ),


        ("IsoTauLikeTightSumPtRel10",  muonAnalysis.isolations["tauTightIso"] +" < 0.1"),
        ("IsoTauLikeTightSumPtRel15",  muonAnalysis.isolations["tauTightIso"] +" < 0.15"),

        ("IsoTauLikeTightSc0SumPtRel10",  muonAnalysis.isolations["tauTightSc0SumPtIsoRel"] +" < 0.1"),
        ("IsoTauLikeTightSc0SumPtRel15",  muonAnalysis.isolations["tauTightSc0SumPtIsoRel"] +" < 0.15"),

        ("IsoTauLikeTightSc0Ic04SumPtRel10",  muonAnalysis.isolations["tauTightSc0Ic04SumPtIsoRel"] +" < 0.1"),
        ("IsoTauLikeTightSc0Ic04SumPtRel15",  muonAnalysis.isolations["tauTightSc0Ic04SumPtIsoRel"] +" < 0.15"),

        ("IsoTauLikeTightSc0Ic04NoqSumPtRel10",  muonAnalysis.isolations["tauTightSc0Ic04NoqSumPtIsoRel"] +" < 0.1"),
        ("IsoTauLikeTightSc0Ic04NoqSumPtRel10",  muonAnalysis.isolations["tauTightSc0Ic04NoqSumPtIsoRel"] +" < 0.15"),

        ]

    tauIsolations = [
#        "VLoose",
#        "Loose",
#        "Medium",
#        "Tight"
        ]

    for name, cut in isolations:
        (sequence, counters, muons) = addMuonSelection(process, name, cut)
        cseq = cms.Sequence(commonSequence*sequence)
        setattr(process, prefix+name+"CommonSequence", cseq)

        module = prototype.clone()
        modify(module, muons)

        HChTools.addAnalysis(process, prefix+name, module, cseq, additionalCounters+counters, signalAnalysisCounters)

    for name in tauIsolations:
        (sequence, counters, muons) = addMuonTauIsolation(process, "IsoTau"+name, "by%sIsolation"%name)
        cseq = cms.Sequence(commonSequence*sequence)
        setattr(process, prefix+"IsoTau"+name+"CommonSequence", cseq)

        module = prototype.clone()
        modify(module, muons)

        HChTools.addAnalysis(process, prefix+"IsoTau"+name, module, cseq, additionalCounters+counters, signalAnalysisCounters)
def setEfficiency(pset):
    pset.data = HChTools.getEfficiencyJsonFullPath("met trigger scale factors", "metLegTriggerEfficiency2011", "loose")
Пример #13
0
def addEmbeddingLikePreselection(process, sequence, param, prefix="embeddingLikePreselection", disableTrigger=True):
    counters = []

    # Create PU weight producer for the counters
    pileupWeight = cms.EDProducer("HPlusVertexWeightProducer",
        alias = cms.string("pileupWeight"),
    )
    HChTools.insertPSetContentsTo(param.vertexWeight.clone(), pileupWeight)
    setattr(process, prefix+"PileupWeight", pileupWeight)

    counterPrototype = cms.EDProducer("HPlusEventCountProducer",
        weightSrc = cms.InputTag(prefix+"PileupWeight")
    )

    # Disable trigger
    if disableTrigger:
        param.trigger.selectionType = "disabled"
        param.triggerEfficiencyScaleFactor.mode = "disabled"

    allCount = counterPrototype.clone()
    setattr(process, prefix+"AllCount", allCount)
    counters.append(prefix+"AllCount")

    # Primary vertex
    pvFilter = cms.EDFilter("VertexCountFilter",
        src = cms.InputTag("selectedPrimaryVertex"),
        minNumber = cms.uint32(1),
        maxNumber = cms.uint32(999)
    )
    pvFilterCount = counterPrototype.clone()
    setattr(process, prefix+"PrimaryVertex", pvFilter)
    setattr(process, prefix+"PrimaryVertexCount", pvFilterCount)
    counters.append(prefix+"PrimaryVertexCount")

    # Generator taus (if you modify this, remember to modify similar in above)
    genTaus = cms.EDFilter("GenParticleSelector",
        src = cms.InputTag("genParticles"),
        cut = cms.string("abs(pdgId()) == 15 && pt() > 40 && abs(eta()) < 2.1")
    )
    genTausName = prefix+"GenTau"
    setattr(process, genTausName, genTaus)

    genTausFilter = cms.EDFilter("CandViewCountFilter",
        src = cms.InputTag(genTausName),
        minNumber = cms.uint32(1),
    )
    setattr(process, prefix+"GenTauFilter", genTausFilter)

    genTausCount = counterPrototype.clone()
    setattr(process, prefix+"GenTauCount", genTausCount)
    counters.append(prefix+"GenTauCount")

    # Select first generator tau for the jet cleaning and tau selection
    genTauFirst = cms.EDProducer("HPlusFirstCandidateSelector",
        src = cms.InputTag(genTausName)
    )
    genTauFirstName = prefix+"First"
    setattr(process, genTauFirstName, genTauFirst)

    # Tau selection
    genTauReco = cms.EDProducer("HPlusPATTauCandViewDeltaRSelector",
        src = cms.InputTag("selectedPatTausHpsPFTau"), # not trigger matched
        refSrc = cms.InputTag(genTauFirstName),
        deltaR = cms.double(0.5),
    )
    if not disableTrigger:
        genTauReco.src = param.tauSelection.src.value()
    genTauRecoName = prefix+"Reco"
    setattr(process, genTauRecoName, genTauReco)
    param.tauSelection.src = genTauRecoName

    genTauCleanPSet = cms.PSet(
        src                 = cms.InputTag(genTauFirstName),
        algorithm           = cms.string("byDeltaR"),
        preselection        = cms.string(""),
        deltaR              = cms.double(0.5),
        checkRecoComponents = cms.bool(False),
        pairCut             = cms.string(""),
        requireNoOverlaps   = cms.bool(True),
    )

    # Clean the selected generator tau from the electrons and muons
    # for the e/mu veto. We don't want to reject events where the e/mu
    # comes from the tau decay.
    from PhysicsTools.PatAlgos.cleaningLayer1.electronCleaner_cfi import cleanPatElectrons
    from PhysicsTools.PatAlgos.cleaningLayer1.muonCleaner_cfi import cleanPatMuons
    cleanedElectrons = cleanPatElectrons.clone(
        src = cms.InputTag(param.GlobalElectronVeto.ElectronCollectionName.value()),
        checkOverlaps = cms.PSet(
            genTaus = genTauCleanPSet.clone()
        )
    )
    cleanedElectronsName = prefix+"CleanedElectrons"
    param.GlobalElectronVeto.ElectronCollectionName = cleanedElectronsName
    setattr(process, cleanedElectronsName, cleanedElectrons)
    cleanedMuons = cleanPatMuons.clone(
        src = cms.InputTag(param.GlobalMuonVeto.MuonCollectionName.value()),
        checkOverlaps = cms.PSet(
            genTaus = genTauCleanPSet.clone()
        )
    )
    cleanedMuonsName = prefix+"CleanedMuons"
    param.GlobalMuonVeto.MuonCollectionName = cleanedMuonsName
    setattr(process, cleanedMuonsName, cleanedMuons)

    # Electron and muon veto
    eveto = ElectronVeto.hPlusGlobalElectronVetoFilter.clone()
    evetoCount = counterPrototype.clone()
    muveto = MuonVeto.hPlusGlobalMuonVetoFilter.clone() 
    muvetoCount = counterPrototype.clone()
    setattr(process, prefix+"ElectronVeto", eveto)
    setattr(process, prefix+"ElectronVetoCount", evetoCount)
    setattr(process, prefix+"MuonVeto", muveto)
    setattr(process, prefix+"MuonVetoCount", muvetoCount)
    counters.extend([prefix+"ElectronVetoCount", prefix+"MuonVetoCount"])

    # 3 jets
    from PhysicsTools.PatAlgos.cleaningLayer1.jetCleaner_cfi import cleanPatJets
    cleanedJets = cleanPatJets.clone(
        src = cms.InputTag(param.jetSelection.src.value()),
        preselection = cms.string(jetSelection),
        checkOverlaps = cms.PSet(
            genTaus = genTauCleanPSet.clone()
        )
    )
    cleanedJetsName = prefix+"CleanedJets"
    setattr(process, cleanedJetsName, cleanedJets)

    cleanedJetsFilter = cms.EDFilter("CandViewCountFilter",
        src = cms.InputTag(cleanedJetsName),
        minNumber = cms.uint32(3)
    )
    setattr(process, cleanedJetsName+"Filter", cleanedJetsFilter)

    cleanedJetsCount = counterPrototype.clone()
    setattr(process, cleanedJetsName+"Count", cleanedJetsCount)
    counters.append(cleanedJetsName+"Count")

    genTauSequence = cms.Sequence(
        pileupWeight *
        allCount *
        pvFilter * pvFilterCount *
        genTaus * genTausFilter * genTausCount * genTauFirst * genTauReco *
        cleanedElectrons * cleanedMuons *
        eveto * evetoCount *
        muveto * muvetoCount *
        cleanedJets * cleanedJetsFilter * cleanedJetsCount 
    )
    setattr(process, prefix+"Sequence", genTauSequence)
    sequence *= genTauSequence

    return counters
Пример #14
0
def setEfficiency(pset):
    pset.data = HChTools.getEfficiencyJsonFullPath(
        "met trigger scale factors", "metLegTriggerEfficiency2011", "loose")
Пример #15
0
def addMuonIsolationAnalyses(process, prefix, prototype, commonSequence, additionalCounters, modify=_signalAnalysisSetMuon, signalAnalysisCounters=True):
    import muonAnalysis

    detRelIso = muonAnalysis.isolations["sumIsoRel"]
    pfRelIso = muonAnalysis.isolations["pfSumIsoRel"]

    isolations = [
        ("RelIso05", detRelIso+" < 0.05"),
        ("RelIso10", detRelIso+" < 0.10"),
        ("RelIso15", detRelIso+" < 0.15"),
#        ("RelIso20", detRelIso+" < 0.20"),
        ("RelIso25", detRelIso+" < 0.25"),
        ("RelIso50", detRelIso+" < 0.50"),

        ("PfRelIso05", pfRelIso+" < 0.05"),
        ("PfRelIso10", pfRelIso+" < 0.10"),
        ("PfRelIso15", pfRelIso+" < 0.15"),
#        ("PfRelIso20", pfRelIso+" < 0.20"),
        ("PfRelIso25", pfRelIso+" < 0.25"),
        ("PfRelIso50", pfRelIso+" < 0.50"),

        ("IsoTauLikeVLoose", muonAnalysis.isolations["tauVLooseIso"]+" == 0"),
        ("IsoTauLikeLoose",  muonAnalysis.isolations["tauLooseIso"] +" == 0"),
        ("IsoTauLikeMedium", muonAnalysis.isolations["tauMediumIso"]+" == 0"),
        ("IsoTauLikeTight",  muonAnalysis.isolations["tauTightIso"] +" == 0"),
        ("IsoTauLikeTightSc015", muonAnalysis.isolations["tauTightSc015Iso"] +" == 0" ),
        ("IsoTauLikeTightSc02", muonAnalysis.isolations["tauTightSc02Iso"] +" == 0" ),

        ("IsoTauLikeTightIc04",  muonAnalysis.isolations["tauTightIc04Iso"] +" == 0"),
        ("IsoTauLikeTightSc015Ic04", muonAnalysis.isolations["tauTightSc015Ic04Iso"] +" == 0" ),
        ("IsoTauLikeTightSc02Ic04", muonAnalysis.isolations["tauTightSc02Ic04Iso"] +" == 0" ),


        ("IsoTauLikeTightSumPtRel10",  muonAnalysis.isolations["tauTightIso"] +" < 0.1"),
        ("IsoTauLikeTightSumPtRel15",  muonAnalysis.isolations["tauTightIso"] +" < 0.15"),

        ("IsoTauLikeTightSc0SumPtRel10",  muonAnalysis.isolations["tauTightSc0SumPtIsoRel"] +" < 0.1"),
        ("IsoTauLikeTightSc0SumPtRel15",  muonAnalysis.isolations["tauTightSc0SumPtIsoRel"] +" < 0.15"),

        ("IsoTauLikeTightSc0Ic04SumPtRel10",  muonAnalysis.isolations["tauTightSc0Ic04SumPtIsoRel"] +" < 0.1"),
        ("IsoTauLikeTightSc0Ic04SumPtRel15",  muonAnalysis.isolations["tauTightSc0Ic04SumPtIsoRel"] +" < 0.15"),

        ("IsoTauLikeTightSc0Ic04NoqSumPtRel10",  muonAnalysis.isolations["tauTightSc0Ic04NoqSumPtIsoRel"] +" < 0.1"),
        ("IsoTauLikeTightSc0Ic04NoqSumPtRel10",  muonAnalysis.isolations["tauTightSc0Ic04NoqSumPtIsoRel"] +" < 0.15"),

        ]

    tauIsolations = [
#        "VLoose",
#        "Loose",
#        "Medium",
#        "Tight"
        ]

    for name, cut in isolations:
        (sequence, counters, muons) = addMuonSelection(process, name, cut)
        cseq = cms.Sequence(commonSequence*sequence)
        setattr(process, prefix+name+"CommonSequence", cseq)

        module = prototype.clone()
        modify(module, muons)

        HChTools.addAnalysis(process, prefix+name, module, cseq, additionalCounters+counters, signalAnalysisCounters)

    for name in tauIsolations:
        (sequence, counters, muons) = addMuonTauIsolation(process, "IsoTau"+name, "by%sIsolation"%name)
        cseq = cms.Sequence(commonSequence*sequence)
        setattr(process, prefix+"IsoTau"+name+"CommonSequence", cseq)

        module = prototype.clone()
        modify(module, muons)

        HChTools.addAnalysis(process, prefix+"IsoTau"+name, module, cseq, additionalCounters+counters, signalAnalysisCounters)
def setEfficiency(pset, isolation, againstMuon, againstElectron):
    pset.data = HChTools.getEfficiencyJsonFullPath("met trigger scale factors", "metLegTriggerEfficiency2012", "%s_%s_%s" % (isolation, againstMuon, againstElectron))
def setEfficiency(pset, isolation, againstMuon, againstElectron):
    pset.data = HChTools.getEfficiencyJsonFullPath("tau trigger scale factors (low purity)", "tauLegTriggerEfficiency2012lowPurity", "%s_%s_%s" % (isolation, againstMuon, againstElectron))
Пример #18
0
def setEfficiency(pset, isolation, againstMuon, againstElectron):
    pset.data = HChTools.getEfficiencyJsonFullPath("l1etm trigger scale factors", "metLegL1ETM40Efficiency2012", "2011Like")
]
puWeights = AnalysisConfiguration.addPuWeightProducers(dataVersion, process, process.commonSequence, dataEras)

# Add GenTau skim counters
import HiggsAnalysis.HeavyChHiggsToTauNu.CustomGenTauSkim as tauSkim
additionalCounters = tauSkim.getCounters() + additionalCounters
import HiggsAnalysis.HeavyChHiggsToTauNu.tauEmbedding.customisations as customisations
process.genTaus = cms.EDFilter("GenParticleSelector",
    src = cms.InputTag("genParticles"),
    cut = cms.string(customisations.generatorTauSelection % customisations.generatorTauPt),
)
process.commonSequence += process.genTaus

# Add configuration information to histograms.root
import HiggsAnalysis.HeavyChHiggsToTauNu.HChTools as HChTools
process.infoPath = HChTools.addConfigInfo(process, options, dataVersion)

# PV selection
import HiggsAnalysis.HeavyChHiggsToTauNu.HChPrimaryVertex as HChPrimaryVertex
HChPrimaryVertex.addPrimaryVertexSelection(process, process.commonSequence)

# Jet selection
import HiggsAnalysis.HeavyChHiggsToTauNu.tauEmbedding.muonSelectionPF as muonSelection
muonSelection.addMuonSelectionForEmbedding(process)
process.commonSequence += process.goodJets

# Muon selection (for muons coming from "the other W"), must the same as for embedding
process.commonSequence += process.tightMuons
process.load("HiggsAnalysis.HeavyChHiggsToTauNu.tauEmbedding.PFEmbeddingSource_cff")
process.commonSequence += process.tightenedMuons
Пример #20
0
#    "tauTightSc0Ic04Iso":    _tauIso("TightSc0Ic04"),
#    "tauTightSc0Ic04NoqIso": _tauIso("TightSc0Ic04Noq"),
    }
for key, value in tauIsolations.items():
    userFloat = value.replace("userInt", "userFloat")
    base = key.replace("Iso", "")
    tauIsolations[base+"SumPtIso"] = userFloat.replace("Occupancy", "SumPt")
    tauIsolations[base+"SumPtIsoRel"] = "(%s)/pt()" % userFloat.replace("Occupancy", "SumPt")
    if "+" in userFloat:
        tauIsolations[base+"MaxPtIso"] = "max(" + userFloat.replace("Occupancy", "MaxPt").replace("+", ", ") + ")"
    else:
        tauIsolations[base+"MaxPtIso"] = userFloat.replace("Occupancy", "MaxPt")
isolations.update(tauIsolations)

# Define the histograms
histoPt = HChTools.Histo("pt", "pt()", min=0., max=800., nbins=800, description="pt (GeV/c)")
histoEta = HChTools.Histo("eta", "eta()", min=-3, max=3, nbins=120, description="eta")
histoPhi = HChTools.Histo("phi", "phi()", min=-3.5, max=3.5, nbins=70, description="phi")

histoIsos = {}
for name, value in isolations.iteritems():
    h = None
    if "IsoRel" in name or "SumPtRel" in name:
        h = HChTools.Histo(name, value, min=0, max=0.5, nbins=100, description=name)
        histoIsos[name+"Full"] = HChTools.Histo(name+"Full", value, min=0, max=5.0, nbins=500, description=name)
    else:
        h = HChTools.Histo(name, value, min=0, max=100.0, nbins=100, description=name)
    histoIsos[name] = h
    

histoDB = HChTools.Histo("trackDB", "dB()", min=-0.1, max=0.1, nbins=50, description="Track ip @ PV (cm)")
Пример #21
0
    def __init__(self, process, dataVersion, additionalCounters, 
                 prefix="", beginSequence=None, afterOtherCuts=False,
                 trigger=None,
                 muons="selectedPatMuons", allMuons="selectedPatMuons", muonPtCut=30,
                 doIsolationWithTau=False, isolationWithTauDiscriminator="byTightIsolation",
                 doMuonIsolation=False, muonIsolation="sumIsoRel", muonIsolationCut=0.05,
                 electrons="selectedPatElectrons",
                 met="patMETsPF", metCut=20,
                 jets="selectedPatJetsAK5PF", njets=3,
                 vertexCollections=["offlinePrimaryVertices", "goodPrimaryVertices", "goodPrimaryVertices10"],
                 weightSrc=None):
        self.process = process
        self.dataVersion = dataVersion
        self.prefix = prefix
        self.afterOtherCuts = afterOtherCuts
        self.doIsolationWithTau = doIsolationWithTau
        self.doMuonIsolation = doMuonIsolation
        self._trigger = trigger
        self._muons = cms.InputTag(muons)
        self._allMuons = cms.InputTag(allMuons)
        self._ptCut = "pt() > %d" % muonPtCut
        self._etaCut = "abs(eta()) < 2.1"
        self._electrons = electrons
        self._met = met
        self._metCut = "et() > %d" % metCut
        self._njets = njets
        self._jets = cms.InputTag(jets)
        self._muonIsolation = muonIsolation
        self._isolationCut = "%s < %f" % (isolations[muonIsolation], muonIsolationCut)
        self._isolationWithTauDiscriminator = isolationWithTauDiscriminator

        if self._trigger == None:
            raise Exception("Must specify trigger!")

        self.analysis = HChTools.Analysis(self.process, "analysis", prefix, additionalCounters=additionalCounters, weightSrc=weightSrc)
        #self.analysis.getCountAnalyzer().printMainCounter = cms.untracked.bool(True)
        #self.analysis.getCountAnalyzer().printSubCounters = cms.untracked.bool(True)
        #self.analysis.getCountAnalyzer().printAvailableCounters = cms.untracked.bool(True)

        if beginSequence != None:
            self.analysis.appendToSequence(beginSequence)
        self.multipName = "Multiplicity"
        self.pileupName = "VertexCount"

        self.selectedMuons = cms.InputTag(muons)
        self.selectedJets = self._jets

        # Setup the analyzers
        if not self.afterOtherCuts:
            self.histoAnalyzer = self.analysis.addMultiHistoAnalyzer("AllMuons", [
                    ("muon_", self.selectedMuons, histosBeginning),
                    ("jet_", self.selectedJets, histosJet),
                    ("met_", cms.InputTag(met), histosMet)])
            self.multipAnalyzer = self.analysis.addAnalyzer(self.multipName, cms.EDAnalyzer("HPlusCandViewMultiplicityAnalyzer",
                    allMuons = cms.untracked.PSet(
                        src = self.selectedMuons,
                        min = cms.untracked.int32(0),
                        max = cms.untracked.int32(10),
                        nbins = cms.untracked.int32(10)
                    ),
                    selMuons = cms.untracked.PSet(
                        src = self.selectedMuons,
                        min = cms.untracked.int32(0),
                        max = cms.untracked.int32(10),
                        nbins = cms.untracked.int32(10)
                    ),
                    jets = cms.untracked.PSet(
                        src = self.selectedJets,
                        min = cms.untracked.int32(0),
                        max = cms.untracked.int32(20),
                        nbins = cms.untracked.int32(20)
                    ),
            ))
            if weightSrc != None:
                self.histoAnalyzer.weights = cms.untracked.InputTag(weightSrc)
                self.multipAnalyzer.weights = cms.untracked.InputTag(weightSrc)
        self.pileupAnalyzer = None
        if beginSequence == None:
            self.pileupAnalyzer = self.analysis.addAnalyzer(self.pileupName, cms.EDAnalyzer("HPlusVertexCountAnalyzer",
                    src = cms.untracked.VInputTag([cms.untracked.InputTag(x) for x in vertexCollections]),
                    min = cms.untracked.double(0),
                    max = cms.untracked.double(20),
                    nbins = cms.untracked.int32(20),
            ))
            if weightSrc != None:
                self.pileupAnalyzer.weights = cms.untracked.InputTag(weightSrc)

        # Create the prototype for muon cleaner
        from PhysicsTools.PatAlgos.cleaningLayer1.muonCleaner_cfi import cleanPatMuons
        self.muonJetCleanerPrototype = cleanPatMuons.clone(
            src = cms.InputTag("dummy"),
            checkOverlaps = cms.PSet(
                jets = cms.PSet(
                    src                 = cms.InputTag("dummy"),
                    algorithm           = cms.string("byDeltaR"),
                    preselection        = cms.string(""),
                    deltaR              = cms.double(0.3),
                    checkRecoComponents = cms.bool(False),
                    pairCut             = cms.string(""),
                    requireNoOverlaps   = cms.bool(True)
                )
            )
        )
        # Create the prototype for jet cleaner
        from PhysicsTools.PatAlgos.cleaningLayer1.jetCleaner_cfi import cleanPatJets
        self.jetMuonCleanerPrototype = cleanPatJets.clone(
            src = cms.InputTag("dummy"),
            checkOverlaps = cms.PSet(
                muons = cms.PSet(
                    src                 = cms.InputTag("dummy"),
                    algorithm           = cms.string("byDeltaR"),
                    preselection        = cms.string(""),
                    deltaR              = cms.double(0.1),
                    checkRecoComponents = cms.bool(False),
                    pairCut             = cms.string(""),
                    requireNoOverlaps   = cms.bool(True)
                )
            )
        )

        # Create the prototype for candidate combiner
        self.candCombinerPrototype = cms.EDProducer("CandViewShallowCloneCombiner",
            checkCharge = cms.bool(False),
            cut = cms.string(""),
            decay = cms.string("dummy")
        )

        # Setup the afterOtherCuts prototypes
        if self.afterOtherCuts:
            self.afterOtherCutsModule = cms.EDAnalyzer("HPlusCandViewHistoAfterOtherCutsAnalyzer",
                src = cms.InputTag("dummy"),
                histograms = cms.VPSet(
                    histoPt.pset().clone(cut=cms.untracked.string(self._ptCut)),
                    histoEta.pset().clone(cut=cms.untracked.string(self._etaCut)),
                )
            )
            if weightSrc != None:
                self.afterOtherCutsModule.weights = cms.untracked.InputTag(weightSrc)
            self.afterOtherCutsModuleIso = self.afterOtherCutsModule.clone()
            self.afterOtherCutsModuleIso.histograms.append(histoIsos[muonIsolation].pset().clone(
                    cut=cms.untracked.string(self._isolationCut)
            ))
Пример #22
0
def addEmbeddingLikePreselection(process, sequence, param, prefix="embeddingLikePreselection", disableTrigger=True, pileupWeight=None, selectOnlyFirstGenTau=False, maxGenTaus=None):
    counters = []

    genTauSequence = cms.Sequence()
    # Create PU weight producer for the counters
    if pileupWeight == None:
        puModule = cms.EDProducer("HPlusVertexWeightProducer",
            alias = cms.string("pileupWeight"),
            histogramAmbientLevel = cms.untracked.string("Systematics")
        )
        HChTools.insertPSetContentsTo(param.vertexWeight.clone(), puModule)
        pileupWeight = prefix+"PileupWeight"
        setattr(process, pileupWeight, puModule)
        genTauSequence *= puModule
    
    counterPrototype = cms.EDProducer("HPlusEventCountProducer",
        weightSrc = cms.InputTag(pileupWeight)
    )

    # Disable trigger
    if disableTrigger:
        param.trigger.selectionType = "disabled"
        param.tauTriggerEfficiencyScaleFactor.mode = "disabled"
        param.metTriggerEfficiencyScaleFactor.mode = "disabled"

    allCount = counterPrototype.clone()
    setattr(process, prefix+"AllCount", allCount)
    genTauSequence *= allCount
    counters.append(prefix+"AllCount")

    # Primary vertex
    pvFilter = cms.EDFilter("VertexCountFilter",
        src = cms.InputTag("selectedPrimaryVertex"),
        minNumber = cms.uint32(1),
        maxNumber = cms.uint32(999)
    )
    pvFilterCount = counterPrototype.clone()
    setattr(process, prefix+"PrimaryVertex", pvFilter)
    setattr(process, prefix+"PrimaryVertexCount", pvFilterCount)
    genTauSequence *= (pvFilter * pvFilterCount)
    counters.append(prefix+"PrimaryVertexCount")

    # Generator taus (if you modify this, remember to modify similar in above)
    genTaus = cms.EDFilter("GenParticleSelector",
        src = cms.InputTag("genParticles"),
        cut = cms.string(generatorTauSelection % generatorTauPt)
    )
    genTausName = prefix+"GenTau"
    setattr(process, genTausName, genTaus)
    genTauSequence *= genTaus

    if maxGenTaus is not None:
        genTausFilter = cms.EDFilter("PATCandViewCountFilter",
            src = cms.InputTag(genTausName),
            minNumber = cms.uint32(1),
            maxNumber = cms.uint32(maxGenTaus),
        )
    else:
        genTausFilter = cms.EDFilter("CandViewCountFilter",
            src = cms.InputTag(genTausName),
            minNumber = cms.uint32(1),
        )
    setattr(process, prefix+"GenTauFilter", genTausFilter)
    genTauSequence *= genTausFilter

    genTausCount = counterPrototype.clone()
    setattr(process, prefix+"GenTauCount", genTausCount)
    genTauSequence *= genTausCount
    counters.append(prefix+"GenTauCount")

    # Select first generator tau for e/mu veto, and if the flag is
    # true, also for the jet cleaning and tau selection
    genTauFirst = cms.EDProducer("HPlusFirstGenParticleSelector",
        src = cms.InputTag(genTausName)
    )
    genTauFirstName = prefix+"GenTauFirst"
    setattr(process, genTauFirstName, genTauFirst)
    genTauSequence *= genTauFirst
    if selectOnlyFirstGenTau:
         genTausName = genTauFirstName

    genTausVisible = cms.EDProducer("HPlusGenVisibleTauComputer",
        src = cms.InputTag(genTausName)
    )
    genTausVisibleName = prefix+"GenTauVisible"
    setattr(process, genTausVisibleName, genTausVisible)
    genTauSequence *= genTausVisible

    genTauFirstVisible = cms.EDProducer("HPlusGenVisibleTauComputer",
        src = cms.InputTag(genTauFirstName)
    )
    genTauFirstVisibleName = prefix+"GenTauFirstVisible"
    setattr(process, genTauFirstVisibleName, genTauFirstVisible)
    genTauSequence *= genTauFirstVisible
    
    # Tau selection
    # genTauReco = cms.EDProducer("HPlusPATTauCandViewClosestDeltaRSelector",
    #     src = cms.InputTag("selectedPatTausHpsPFTau"),
    #     refSrc = cms.InputTag(genTausName),
    #     maxDeltaR = cms.double(0.5),
    # )
    genTauReco = cms.EDProducer("HPlusPATTauLorentzVectorViewClosestDeltaRSelector",
#        src = cms.InputTag("selectedPatTaus"+PF2PATVersion), # not trigger matched
#        src = cms.InputTag("selectedPatTausHpsPFTau"), # 2011
        src = cms.InputTag("selectedPatTaus"),
        refSrc = cms.InputTag(genTausVisibleName),
        maxDeltaR = cms.double(0.5),
    )

#     if PF2PATVersion != "":
#         raise Exception("I don't support PF2PAT at the moment")
    if not disableTrigger:
        genTauReco.src = param.tauSelection.src.value()
    genTauRecoName = prefix+"TauMCMatched"
    setattr(process, genTauRecoName, genTauReco)
    genTauSequence *= genTauReco
    param.tauSelection.src = genTauRecoName

    genTauFirstReco = genTauReco.clone(
        refSrc = genTauFirstVisibleName
    )
    genTauFirstRecoName = prefix+"FirstTauMCMatched"
    setattr(process, genTauFirstRecoName, genTauFirstReco)
    genTauSequence *= genTauFirstReco

    if not selectOnlyFirstGenTau:
        # Select the tau candidate which is most likely going to pass the identification
        genTauSelected = cms.EDProducer("HPlusPATTauMostLikelyIdentifiedSelector",
            eventCounter = param.eventCounter.clone(enabled = cms.untracked.bool(False)),
            tauSelection = param.tauSelection.clone(),
            vertexSrc = cms.InputTag(param.primaryVertexSelection.selectedSrc.value()),
            histogramAmbientLevel = cms.untracked.string("Systematics"),
        )
        genTauSelectedName = prefix+"TauSelected"
        setattr(process, genTauSelectedName, genTauSelected)
        genTauSequence *= genTauSelected
        param.tauSelection.src = genTauSelectedName
    
    genTauCleanPSet = cms.PSet(
#        src                 = cms.InputTag(param.tauSelection.src.value()),
        src                 = cms.InputTag(genTauFirstRecoName),
        algorithm           = cms.string("byDeltaR"),
        preselection        = cms.string(""),
        deltaR              = cms.double(0.5),
        checkRecoComponents = cms.bool(False),
        pairCut             = cms.string(""),
        requireNoOverlaps   = cms.bool(True),
    )

    # Clean the selected generator tau from the electrons and muons
    # for the e/mu veto. We don't want to reject events where the e/mu
    # comes from the tau decay.
    from PhysicsTools.PatAlgos.cleaningLayer1.electronCleaner_cfi import cleanPatElectrons
    from PhysicsTools.PatAlgos.cleaningLayer1.muonCleaner_cfi import cleanPatMuons
    cleanedElectrons = cleanPatElectrons.clone(
        src = cms.InputTag(param.ElectronSelection.ElectronCollectionName.value()),
        checkOverlaps = cms.PSet(
            genTaus = genTauCleanPSet.clone()
        )
    )
    cleanedElectronsName = prefix+"CleanedElectrons"
    param.ElectronSelection.ElectronCollectionName = cleanedElectronsName
    setattr(process, cleanedElectronsName, cleanedElectrons)
    cleanedMuons = cleanPatMuons.clone(
        src = cms.InputTag(param.MuonSelection.MuonCollectionName.value()),
        checkOverlaps = cms.PSet(
            genTaus = genTauCleanPSet.clone()
        )
    )
    cleanedMuonsName = prefix+"CleanedMuons"
    param.MuonSelection.MuonCollectionName = cleanedMuonsName
    setattr(process, cleanedMuonsName, cleanedMuons)
    genTauSequence *= (cleanedElectrons * cleanedMuons)

    # Electron and muon veto
    import HiggsAnalysis.HeavyChHiggsToTauNu.HChGlobalElectronVetoFilter_cfi as ElectronVeto
    eveto = ElectronVeto.hPlusGlobalElectronVetoFilter.clone(
        histogramAmbientLevel = "Systematics"
    )
    eveto.eventCounter.enabled = cms.untracked.bool(False)
    evetoCount = counterPrototype.clone()
    import HiggsAnalysis.HeavyChHiggsToTauNu.HChGlobalMuonVetoFilter_cfi as MuonVeto
    muveto = MuonVeto.hPlusGlobalMuonVetoFilter.clone(
        histogramAmbientLevel = "Systematics"
    )
    muveto.eventCounter.enabled = cms.untracked.bool(False)
    muvetoCount = counterPrototype.clone()
    setattr(process, prefix+"ElectronVeto", eveto)
    setattr(process, prefix+"ElectronVetoCount", evetoCount)
    setattr(process, prefix+"MuonVeto", muveto)
    setattr(process, prefix+"MuonVetoCount", muvetoCount)
    counters.extend([prefix+"ElectronVetoCount", prefix+"MuonVetoCount"])
    genTauSequence *= (
        eveto * evetoCount *
        muveto * muvetoCount
    )

    # 3 jets
    # from PhysicsTools.PatAlgos.cleaningLayer1.jetCleaner_cfi import cleanPatJets
    # cleanedJets = cleanPatJets.clone(
    #     src = cms.InputTag(param.jetSelection.src.value()),
    #     preselection = cms.string(jetSelection),
    #     checkOverlaps = cms.PSet(
    #         genTaus = genTauCleanPSet.clone()
    #     )
    # )
    # cleanedJetsName = prefix+"CleanedJets"
    # setattr(process, cleanedJetsName, cleanedJets)

    # cleanedJetsFilter = cms.EDFilter("CandViewCountFilter",
    #     src = cms.InputTag(cleanedJetsName),
    #     minNumber = cms.uint32(3)
    # )
    # setattr(process, cleanedJetsName+"Filter", cleanedJetsFilter)
    import HiggsAnalysis.HeavyChHiggsToTauNu.HChJetFilter_cfi as jetFilter_cfi
    cleanedJets = jetFilter_cfi.hPlusJetPtrSelectorFilter.clone(
        tauSrc = param.tauSelection.src.value(),
        allowEmptyTau = True,
        histogramAmbientLevel = "Systematics",
    )
    cleanedJets.eventCounter.enabled = cms.untracked.bool(False)
    cleanedJetsName = prefix+"CleanedJets"
    setattr(process, cleanedJetsName, cleanedJets)

    cleanedJetsCount = counterPrototype.clone()
    setattr(process, cleanedJetsName+"Count", cleanedJetsCount)
    counters.append(cleanedJetsName+"Count")

    genTauSequence *= (
        cleanedJets * #cleanedJetsFilter *
        cleanedJetsCount 
    )
    setattr(process, prefix+"Sequence", genTauSequence)
    sequence *= genTauSequence

    return counters
Пример #23
0
def addEmbeddingLikePreselection(process,
                                 sequence,
                                 param,
                                 prefix="embeddingLikePreselection",
                                 disableTrigger=True,
                                 pileupWeight=None,
                                 selectOnlyFirstGenTau=False,
                                 maxGenTaus=None):
    counters = []

    genTauSequence = cms.Sequence()
    # Create PU weight producer for the counters
    if pileupWeight == None:
        puModule = cms.EDProducer(
            "HPlusVertexWeightProducer",
            alias=cms.string("pileupWeight"),
            histogramAmbientLevel=cms.untracked.string("Systematics"))
        HChTools.insertPSetContentsTo(param.vertexWeight.clone(), puModule)
        pileupWeight = prefix + "PileupWeight"
        setattr(process, pileupWeight, puModule)
        genTauSequence *= puModule

    counterPrototype = cms.EDProducer("HPlusEventCountProducer",
                                      weightSrc=cms.InputTag(pileupWeight))

    # Disable trigger
    if disableTrigger:
        param.trigger.selectionType = "disabled"
        param.tauTriggerEfficiencyScaleFactor.mode = "disabled"
        param.metTriggerEfficiencyScaleFactor.mode = "disabled"

    allCount = counterPrototype.clone()
    setattr(process, prefix + "AllCount", allCount)
    genTauSequence *= allCount
    counters.append(prefix + "AllCount")

    # Primary vertex
    pvFilter = cms.EDFilter("VertexCountFilter",
                            src=cms.InputTag("selectedPrimaryVertex"),
                            minNumber=cms.uint32(1),
                            maxNumber=cms.uint32(999))
    pvFilterCount = counterPrototype.clone()
    setattr(process, prefix + "PrimaryVertex", pvFilter)
    setattr(process, prefix + "PrimaryVertexCount", pvFilterCount)
    genTauSequence *= (pvFilter * pvFilterCount)
    counters.append(prefix + "PrimaryVertexCount")

    # Generator taus (if you modify this, remember to modify similar in above)
    genTaus = cms.EDFilter("GenParticleSelector",
                           src=cms.InputTag("genParticles"),
                           cut=cms.string(generatorTauSelection %
                                          generatorTauPt))
    genTausName = prefix + "GenTau"
    setattr(process, genTausName, genTaus)
    genTauSequence *= genTaus

    if maxGenTaus is not None:
        genTausFilter = cms.EDFilter(
            "PATCandViewCountFilter",
            src=cms.InputTag(genTausName),
            minNumber=cms.uint32(1),
            maxNumber=cms.uint32(maxGenTaus),
        )
    else:
        genTausFilter = cms.EDFilter(
            "CandViewCountFilter",
            src=cms.InputTag(genTausName),
            minNumber=cms.uint32(1),
        )
    setattr(process, prefix + "GenTauFilter", genTausFilter)
    genTauSequence *= genTausFilter

    genTausCount = counterPrototype.clone()
    setattr(process, prefix + "GenTauCount", genTausCount)
    genTauSequence *= genTausCount
    counters.append(prefix + "GenTauCount")

    # Select first generator tau for e/mu veto, and if the flag is
    # true, also for the jet cleaning and tau selection
    genTauFirst = cms.EDProducer("HPlusFirstGenParticleSelector",
                                 src=cms.InputTag(genTausName))
    genTauFirstName = prefix + "GenTauFirst"
    setattr(process, genTauFirstName, genTauFirst)
    genTauSequence *= genTauFirst
    if selectOnlyFirstGenTau:
        genTausName = genTauFirstName

    genTausVisible = cms.EDProducer("HPlusGenVisibleTauComputer",
                                    src=cms.InputTag(genTausName))
    genTausVisibleName = prefix + "GenTauVisible"
    setattr(process, genTausVisibleName, genTausVisible)
    genTauSequence *= genTausVisible

    genTauFirstVisible = cms.EDProducer("HPlusGenVisibleTauComputer",
                                        src=cms.InputTag(genTauFirstName))
    genTauFirstVisibleName = prefix + "GenTauFirstVisible"
    setattr(process, genTauFirstVisibleName, genTauFirstVisible)
    genTauSequence *= genTauFirstVisible

    # Tau selection
    # genTauReco = cms.EDProducer("HPlusPATTauCandViewClosestDeltaRSelector",
    #     src = cms.InputTag("selectedPatTausHpsPFTau"),
    #     refSrc = cms.InputTag(genTausName),
    #     maxDeltaR = cms.double(0.5),
    # )
    genTauReco = cms.EDProducer(
        "HPlusPATTauLorentzVectorViewClosestDeltaRSelector",
        #        src = cms.InputTag("selectedPatTaus"+PF2PATVersion), # not trigger matched
        #        src = cms.InputTag("selectedPatTausHpsPFTau"), # 2011
        src=cms.InputTag("selectedPatTaus"),
        refSrc=cms.InputTag(genTausVisibleName),
        maxDeltaR=cms.double(0.5),
    )

    #     if PF2PATVersion != "":
    #         raise Exception("I don't support PF2PAT at the moment")
    if not disableTrigger:
        genTauReco.src = param.tauSelection.src.value()
    genTauRecoName = prefix + "TauMCMatched"
    setattr(process, genTauRecoName, genTauReco)
    genTauSequence *= genTauReco
    param.tauSelection.src = genTauRecoName

    genTauFirstReco = genTauReco.clone(refSrc=genTauFirstVisibleName)
    genTauFirstRecoName = prefix + "FirstTauMCMatched"
    setattr(process, genTauFirstRecoName, genTauFirstReco)
    genTauSequence *= genTauFirstReco

    if not selectOnlyFirstGenTau:
        # Select the tau candidate which is most likely going to pass the identification
        genTauSelected = cms.EDProducer(
            "HPlusPATTauMostLikelyIdentifiedSelector",
            eventCounter=param.eventCounter.clone(
                enabled=cms.untracked.bool(False)),
            tauSelection=param.tauSelection.clone(),
            vertexSrc=cms.InputTag(
                param.primaryVertexSelection.selectedSrc.value()),
            histogramAmbientLevel=cms.untracked.string("Systematics"),
        )
        genTauSelectedName = prefix + "TauSelected"
        setattr(process, genTauSelectedName, genTauSelected)
        genTauSequence *= genTauSelected
        param.tauSelection.src = genTauSelectedName

    genTauCleanPSet = cms.PSet(
        #        src                 = cms.InputTag(param.tauSelection.src.value()),
        src=cms.InputTag(genTauFirstRecoName),
        algorithm=cms.string("byDeltaR"),
        preselection=cms.string(""),
        deltaR=cms.double(0.5),
        checkRecoComponents=cms.bool(False),
        pairCut=cms.string(""),
        requireNoOverlaps=cms.bool(True),
    )

    # Clean the selected generator tau from the electrons and muons
    # for the e/mu veto. We don't want to reject events where the e/mu
    # comes from the tau decay.
    from PhysicsTools.PatAlgos.cleaningLayer1.electronCleaner_cfi import cleanPatElectrons
    from PhysicsTools.PatAlgos.cleaningLayer1.muonCleaner_cfi import cleanPatMuons
    cleanedElectrons = cleanPatElectrons.clone(
        src=cms.InputTag(
            param.ElectronSelection.ElectronCollectionName.value()),
        checkOverlaps=cms.PSet(genTaus=genTauCleanPSet.clone()))
    cleanedElectronsName = prefix + "CleanedElectrons"
    param.ElectronSelection.ElectronCollectionName = cleanedElectronsName
    setattr(process, cleanedElectronsName, cleanedElectrons)
    cleanedMuons = cleanPatMuons.clone(
        src=cms.InputTag(param.MuonSelection.MuonCollectionName.value()),
        checkOverlaps=cms.PSet(genTaus=genTauCleanPSet.clone()))
    cleanedMuonsName = prefix + "CleanedMuons"
    param.MuonSelection.MuonCollectionName = cleanedMuonsName
    setattr(process, cleanedMuonsName, cleanedMuons)
    genTauSequence *= (cleanedElectrons * cleanedMuons)

    # Electron and muon veto
    import HiggsAnalysis.HeavyChHiggsToTauNu.HChGlobalElectronVetoFilter_cfi as ElectronVeto
    eveto = ElectronVeto.hPlusGlobalElectronVetoFilter.clone(
        histogramAmbientLevel="Systematics")
    eveto.eventCounter.enabled = cms.untracked.bool(False)
    evetoCount = counterPrototype.clone()
    import HiggsAnalysis.HeavyChHiggsToTauNu.HChGlobalMuonVetoFilter_cfi as MuonVeto
    muveto = MuonVeto.hPlusGlobalMuonVetoFilter.clone(
        histogramAmbientLevel="Systematics")
    muveto.eventCounter.enabled = cms.untracked.bool(False)
    muvetoCount = counterPrototype.clone()
    setattr(process, prefix + "ElectronVeto", eveto)
    setattr(process, prefix + "ElectronVetoCount", evetoCount)
    setattr(process, prefix + "MuonVeto", muveto)
    setattr(process, prefix + "MuonVetoCount", muvetoCount)
    counters.extend([prefix + "ElectronVetoCount", prefix + "MuonVetoCount"])
    genTauSequence *= (eveto * evetoCount * muveto * muvetoCount)

    # 3 jets
    # from PhysicsTools.PatAlgos.cleaningLayer1.jetCleaner_cfi import cleanPatJets
    # cleanedJets = cleanPatJets.clone(
    #     src = cms.InputTag(param.jetSelection.src.value()),
    #     preselection = cms.string(jetSelection),
    #     checkOverlaps = cms.PSet(
    #         genTaus = genTauCleanPSet.clone()
    #     )
    # )
    # cleanedJetsName = prefix+"CleanedJets"
    # setattr(process, cleanedJetsName, cleanedJets)

    # cleanedJetsFilter = cms.EDFilter("CandViewCountFilter",
    #     src = cms.InputTag(cleanedJetsName),
    #     minNumber = cms.uint32(3)
    # )
    # setattr(process, cleanedJetsName+"Filter", cleanedJetsFilter)
    import HiggsAnalysis.HeavyChHiggsToTauNu.HChJetFilter_cfi as jetFilter_cfi
    cleanedJets = jetFilter_cfi.hPlusJetPtrSelectorFilter.clone(
        tauSrc=param.tauSelection.src.value(),
        allowEmptyTau=True,
        histogramAmbientLevel="Systematics",
    )
    cleanedJets.eventCounter.enabled = cms.untracked.bool(False)
    cleanedJetsName = prefix + "CleanedJets"
    setattr(process, cleanedJetsName, cleanedJets)

    cleanedJetsCount = counterPrototype.clone()
    setattr(process, cleanedJetsName + "Count", cleanedJetsCount)
    counters.append(cleanedJetsName + "Count")

    genTauSequence *= (
        cleanedJets *  #cleanedJetsFilter *
        cleanedJetsCount)
    setattr(process, prefix + "Sequence", genTauSequence)
    sequence *= genTauSequence

    return counters
                                                            )
import HiggsAnalysis.HeavyChHiggsToTauNu.AnalysisConfiguration as AnalysisConfiguration
dataEras = [
    "Run2011AB",
    "Run2011A",
    "Run2011B",
]
puWeights = AnalysisConfiguration.addPuWeightProducers(dataVersion, process, process.commonSequence, dataEras)

# Add GenTau skim counters
import HiggsAnalysis.HeavyChHiggsToTauNu.CustomGenTauSkim as tauSkim
additionalCounters = tauSkim.getCounters() + additionalCounters

# Add configuration information to histograms.root
import HiggsAnalysis.HeavyChHiggsToTauNu.HChTools as HChTools
process.infoPath = HChTools.addConfigInfo(process, options, dataVersion)

# Jet selection
doJetSelection = False
#doJetSelection = True
jetSrc = "selectedPatJets"
if doJetSelection:
    # Do also PV selection when doing jet selection
    import HiggsAnalysis.HeavyChHiggsToTauNu.HChPrimaryVertex as HChPrimaryVertex
    HChPrimaryVertex.addPrimaryVertexSelection(process, process.commonSequence)
    process.selectedPrimaryVertexFilter = cms.EDFilter("VertexCountFilter",
        src = cms.InputTag("selectedPrimaryVertex"),
        minNumber = cms.uint32(1),
        maxNumber = cms.uint32(999)
    )
    process.selectedPrimaryVertexCount = cms.EDProducer("EventCountProducer")
Пример #25
0
dataEras = [
    "Run2011AB",
    "Run2011A",
    "Run2011B",
]
puWeights = AnalysisConfiguration.addPuWeightProducers(dataVersion, process,
                                                       process.commonSequence,
                                                       dataEras)

# Add GenTau skim counters
import HiggsAnalysis.HeavyChHiggsToTauNu.CustomGenTauSkim as tauSkim
additionalCounters = tauSkim.getCounters() + additionalCounters

# Add configuration information to histograms.root
import HiggsAnalysis.HeavyChHiggsToTauNu.HChTools as HChTools
process.infoPath = HChTools.addConfigInfo(process, options, dataVersion)

# Jet selection
doJetSelection = False
#doJetSelection = True
jetSrc = "selectedPatJets"
if doJetSelection:
    # Do also PV selection when doing jet selection
    import HiggsAnalysis.HeavyChHiggsToTauNu.HChPrimaryVertex as HChPrimaryVertex
    HChPrimaryVertex.addPrimaryVertexSelection(process, process.commonSequence)
    process.selectedPrimaryVertexFilter = cms.EDFilter(
        "VertexCountFilter",
        src=cms.InputTag("selectedPrimaryVertex"),
        minNumber=cms.uint32(1),
        maxNumber=cms.uint32(999))
    process.selectedPrimaryVertexCount = cms.EDProducer("EventCountProducer")