def switchToPFJets(process, input=cms.InputTag('pfNoTau'), algo='AK5', postfix = "", jetCorrections=('AK5PFchs', ['L1FastJet','L2Relative', 'L3Absolute']), type1=False, outputModules=['out']): print "Switching to PFJets, ", algo print "************************ " print "input collection: ", input if( algo == 'IC5' ): genJetCollection = cms.InputTag('iterativeCone5GenJetsNoNu') elif algo == 'AK5': genJetCollection = cms.InputTag('ak5GenJetsNoNu') elif algo == 'AK7': genJetCollection = cms.InputTag('ak7GenJetsNoNu') else: print 'bad jet algorithm:', algo, '! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin' sys.exit(1) # changing the jet collection in PF2PAT: from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo inputCollection = getattr(process,"pfJets"+postfix).src setattr(process,"pfJets"+postfix,jetAlgo(algo)) # problem for cfgBrowser getattr(process,"pfJets"+postfix).src = inputCollection inputJetCorrLabel=jetCorrections switchJetCollection(process, input, jetIdLabel = algo, doJTA=True, doBTagging=True, jetCorrLabel=inputJetCorrLabel, doType1MET=type1, genJetCollection = genJetCollection, doJetID = True, postfix = postfix, outputModules = outputModules ) # check whether L1FastJet is in the list of correction levels or not applyPostfix(process, "patJetCorrFactors", postfix).useRho = False for corr in inputJetCorrLabel[1]: if corr == 'L1FastJet': applyPostfix(process, "patJetCorrFactors", postfix).useRho = True applyPostfix(process, "pfJets", postfix).doAreaFastjet = True # do correct treatment for TypeI MET corrections if type1: for mod in getattr(process,'patPF2PATSequence'+postfix).moduleNames(): if mod.startswith("kt6"): prefix = mod.replace(postfix,'') prefix = prefix.replace('kt6PFJets','') prefix = prefix.replace('kt6CaloJets','') prefix = getattr(process,'patJetCorrFactors'+prefix+postfix).payload.pythonValue().replace("'","") for essource in process.es_sources_().keys(): if essource == prefix+'L1FastJet': setattr(process,essource+postfix,getattr(process,essource).clone(srcRho=cms.InputTag(mod,'rho'))) setattr(process,prefix+'CombinedCorrector'+postfix,getattr(process,prefix+'CombinedCorrector').clone()) getattr(process,prefix+'CorMet'+postfix).corrector = prefix+'CombinedCorrector'+postfix for cor in getattr(process,prefix+'CombinedCorrector'+postfix).correctors: if cor == essource: idx = getattr(process,prefix+'CombinedCorrector'+postfix).correctors.index(essource); getattr(process,prefix+'CombinedCorrector'+postfix).correctors[idx] = essource+postfix applyPostfix(process, "patJets", postfix).embedCaloTowers = False applyPostfix(process, "patJets", postfix).embedPFCandidates = True
def useOtherMuonCollection(process, postfix, sourceMuons, useParticleFlow, dR = "03"): module = applyPostfix(process,"patMuons",postfix) module.pfMuonSource = sourceMuons module.useParticleFlow = useParticleFlow muPFIsoDepositCharged.src = sourceMuons muPFIsoDepositChargedAll.src = sourceMuons muPFIsoDepositNeutral.src = sourceMuons muPFIsoDepositGamma.src = sourceMuons muPFIsoDepositPU.src = sourceMuons module.isoDeposits = cms.PSet( pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" ), pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" ), pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" ), pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" ), pfPhotons = cms.InputTag("muPFIsoDepositGamma" ), ) module.isolationValues = cms.PSet( pfChargedHadrons = cms.InputTag("muPFIsoValueCharged"+dR), pfChargedAll = cms.InputTag("muPFIsoValueChargedAll"+dR), pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU"+dR ), pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral"+dR ), pfPhotons = cms.InputTag("muPFIsoValueGamma"+dR ), ) applyPostfix(process,"muonMatch",postfix).src = module.pfMuonSource getattr(process,'patDefaultSequence'+postfix).replace( getattr(process,"patMuons"+postfix), pfParticleSelectionSequence+ pfMuonIsolationSequence+ getattr(process,"patMuons"+postfix) )
def useRecoMuon(process, postfix, dR="03"): sourceMuons = 'muons' #take it from reco collection module = applyPostfix(process, "patMuons", postfix) module.pfMuonSource = sourceMuons module.useParticleFlow = False muPFIsoDepositCharged.src = sourceMuons muPFIsoDepositChargedAll.src = sourceMuons muPFIsoDepositNeutral.src = sourceMuons muPFIsoDepositGamma.src = sourceMuons muPFIsoDepositPU.src = sourceMuons module.isoDeposits = cms.PSet( pfChargedHadrons=cms.InputTag("muPFIsoDepositCharged"), pfChargedAll=cms.InputTag("muPFIsoDepositChargedAll"), pfPUChargedHadrons=cms.InputTag("muPFIsoDepositPU"), pfNeutralHadrons=cms.InputTag("muPFIsoDepositNeutral"), pfPhotons=cms.InputTag("muPFIsoDepositGamma"), ) module.isolationValues = cms.PSet( pfChargedHadrons=cms.InputTag("muPFIsoValueCharged" + dR), pfChargedAll=cms.InputTag("muPFIsoValueChargedAll" + dR), pfPUChargedHadrons=cms.InputTag("muPFIsoValuePU" + dR), pfNeutralHadrons=cms.InputTag("muPFIsoValueNeutral" + dR), pfPhotons=cms.InputTag("muPFIsoValueGamma" + dR), ) applyPostfix(process, "muonMatch", postfix).src = module.pfMuonSource getattr(process, 'patDefaultSequence' + postfix).replace( getattr(process, "patMuons" + postfix), pfParticleSelectionSequence + pfMuonIsolationSequence + getattr(process, "patMuons" + postfix))
def addPFCandidates(process,src,patLabel='PFParticles',cut="",postfix=""): from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles # make modules producer = patPFParticles.clone(pfCandidateSource = src) filter = cms.EDFilter("PATPFParticleSelector", src = cms.InputTag("pat" + patLabel), cut = cms.string(cut)) counter = cms.EDFilter("PATCandViewCountFilter", minNumber = cms.uint32(0), maxNumber = cms.uint32(999999), src = cms.InputTag("pat" + patLabel)) # add modules to process setattr(process, "pat" + patLabel, producer) setattr(process, "selectedPat" + patLabel, filter) setattr(process, "countPat" + patLabel, counter) ###no longer needed in unscheduled mode### # insert into sequence #getattr(process, "patPF2PATSequence"+postfix).replace( #applyPostfix(process, "patCandidateSummary", postfix), #producer+applyPostfix(process, "patCandidateSummary", postfix) #) #getattr(process, "patPF2PATSequence"+postfix).replace( #applyPostfix(process, "selectedPatCandidateSummary", postfix), #filter+applyPostfix(process, "selectedPatCandidateSummary", postfix) #) #index = len( applyPostfix( process, "patPF2PATSequence", postfix ).moduleNames() ) #applyPostfix( process, "patPF2PATSequence", postfix ).insert( index, counter ) # summary tables applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel)) applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
def switchToPFMET(process, input=cms.InputTag('pfMET'), type1=False, postfix=""): print 'MET: using ', input if (not type1): oldMETSource = applyPostfix(process, "patMETs", postfix).metSource applyPostfix(process, "patMETs", postfix).metSource = input applyPostfix(process, "patMETs", postfix).addMuonCorrections = False getattr(process, "patDefaultSequence" + postfix).remove( applyPostfix(process, "patMETCorrections", postfix)) else: # type1 corrected MET # name of coreccted MET hardcoded in PAT and meaningless print 'Apply type1 corrections for MET' applyPostfix(process, "metJESCorAK5CaloJet", postfix).inputUncorMetLabel = input.getModuleLabel() applyPostfix(process, "metJESCorAK5CaloJet", postfix).metType = 'PFMET' applyPostfix(process, "metJESCorAK5CaloJet", postfix).jetPTthreshold = 1.0 applyPostfix(process, "patMETs", postfix).metSource = "metJESCorAK5CaloJet" + postfix applyPostfix(process, "patMETs", postfix).addMuonCorrections = False getattr(process, "patDefaultSequence" + postfix).remove( applyPostfix(process, "metJESCorAK5CaloJetMuons", postfix))
def usePFIso(process, postfix = "PFIso"): print "Building particle-based isolation " print "***************** " process.load("CommonTools.ParticleFlow.Isolation.pfElectronIsolation_cff") process.load("CommonTools.ParticleFlow.Isolation.pfMuonIsolation_cff") setupPFElectronIso(process, 'gsfElectrons', postfix) setupPFMuonIso(process, 'muons', postfix) adaptPFIsoMuons( process, applyPostfix(process,"patMuons",""), postfix) adaptPFIsoElectrons( process, applyPostfix(process,"patElectrons",""), postfix)
def addPFCandidates(process,src,patLabel='PFParticles',cut="",postfix=""): from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles # make modules producer = patPFParticles.clone(pfCandidateSource = src) filter = cms.EDFilter("PATPFParticleSelector", src = cms.InputTag("pat" + patLabel), cut = cms.string(cut)) counter = cms.EDFilter("PATCandViewCountFilter", minNumber = cms.uint32(0), maxNumber = cms.uint32(999999), src = cms.InputTag("pat" + patLabel)) # add modules to process setattr(process, "pat" + patLabel, producer) setattr(process, "selectedPat" + patLabel, filter) setattr(process, "countPat" + patLabel, counter) # insert into sequence getattr(process, "patDefaultSequence"+postfix).replace( applyPostfix(process, "patCandidateSummary", postfix), producer+applyPostfix(process, "patCandidateSummary", postfix) ) getattr(process, "patDefaultSequence"+postfix).replace( applyPostfix(process, "selectedPatCandidateSummary", postfix), filter+applyPostfix(process, "selectedPatCandidateSummary", postfix) ) tmpCountPatCandidates = applyPostfix(process, "countPatCandidates", postfix) tmpCountPatCandidates+=counter # summary tables applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel)) applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
def switchToPFMET(process,input=cms.InputTag('pfMET'), type1=False, postfix=""): print 'MET: using ', input if( not type1 ): oldMETSource = applyPostfix(process, "patMETs",postfix).metSource applyPostfix(process, "patMETs",postfix).metSource = input applyPostfix(process, "patMETs",postfix).addMuonCorrections = False getattr(process, "patDefaultSequence"+postfix).remove(applyPostfix(process, "patMETCorrections",postfix)) else: # type1 corrected MET # name of corrected MET hardcoded in PAT and meaningless print 'Apply TypeI corrections for MET' getattr(process, "patDefaultSequence"+postfix).remove(applyPostfix(process, "makePatMETs",postfix)) jecLabel = getattr(process,'patJetCorrFactors'+postfix).levels if not hasattr(process,'producePatPFMETCorrections'): process.load("PhysicsTools.PatUtils.patPFMETCorrections_cff") #here add to the current path and give proper postfix if not hasattr(process,'producePatPFMETCorrections'+postfix): cloneProcessingSnippet(process,process.producePatPFMETCorrections,postfix) getattr(process,'patPFMet'+postfix).metSource = cms.InputTag('pfMET'+postfix) getattr(process,'selectedPatJetsForMETtype1p2Corr'+postfix).src = cms.InputTag('selectedPatJets'+postfix) getattr(process,'selectedPatJetsForMETtype2Corr'+postfix).src = cms.InputTag('selectedPatJets'+postfix) getattr(process,'pfCandMETcorr'+postfix).src = cms.InputTag('pfNoJet'+postfix) getattr(process,'patPFJetMETtype1p2Corr'+postfix).offsetCorrLabel = cms.string(jecLabel[0]) getattr(process,'patPFJetMETtype1p2Corr'+postfix).jetCorrLabel = cms.string(jecLabel[-1]) getattr(process,'patPFJetMETtype1p2Corr'+postfix).type1JetPtThreshold = cms.double(10.0) getattr(process,'patPFJetMETtype1p2Corr'+postfix).skipEM = cms.bool(False) getattr(process,'patPFJetMETtype1p2Corr'+postfix).skipMuons = cms.bool(False) getattr(process,'patPFJetMETtype2Corr'+postfix).offsetCorrLabel = cms.string(jecLabel[0]) getattr(process,'patPFJetMETtype2Corr'+postfix).jetCorrLabel = cms.string(jecLabel[-1]) getattr(process,'patPFJetMETtype2Corr'+postfix).type1JetPtThreshold = cms.double(10.0) getattr(process,'patPFJetMETtype2Corr'+postfix).skipEM = cms.bool(False) getattr(process,'patPFJetMETtype2Corr'+postfix).skipMuons = cms.bool(False) getattr(process,'patType1CorrectedPFMet'+postfix).srcType1Corrections = cms.VInputTag( cms.InputTag("patPFJetMETtype1p2Corr"+postfix,"type1"), #cms.InputTag("patPFMETtype0Corr"+postfix), ) getattr(process,'patType1p2CorrectedPFMet'+postfix).srcType1Corrections = cms.VInputTag( cms.InputTag("patPFJetMETtype1p2Corr"+postfix,"type1"), #cms.InputTag("patPFMETtype0Corr"+postfix), ) getattr(process,'patMETs'+postfix).metSource = 'patType1CorrectedPFMet'+postfix getattr(process,"patDefaultSequence"+postfix).replace( getattr(process,'selectedPatJets'+postfix), getattr(process,'selectedPatJets'+postfix) *getattr(process,'producePatPFMETCorrections'+postfix) *getattr(process,'patMETs'+postfix) )
def usePFIso(process, postfix = "PFIso"): print "Building particle-based isolation " print "***************** " process.eleIsoSequence = setupPFElectronIso(process, 'gsfElectrons', postfix) process.muIsoSequence = setupPFMuonIso(process, 'muons', postfix) adaptPFIsoMuons( process, applyPostfix(process,"patMuons",""), postfix) adaptPFIsoElectrons( process, applyPostfix(process,"patElectrons",""), postfix) getattr(process,'patDefaultSequence').replace( getattr(process,"patCandidates"), process.pfParticleSelectionSequence + process.eleIsoSequence + process.muIsoSequence + getattr(process,"patCandidates") )
def usePFIso(process, postfix="PFIso"): print "Building particle-based isolation " print "***************** " process.eleIsoSequence = setupPFElectronIso(process, 'gsfElectrons', postfix) process.muIsoSequence = setupPFMuonIso(process, 'muons', postfix) adaptPFIsoMuons(process, applyPostfix(process, "patMuons", ""), postfix) adaptPFIsoElectrons(process, applyPostfix(process, "patElectrons", ""), postfix) getattr(process, 'patDefaultSequence').replace( getattr(process, "patCandidates"), process.pfParticleSelectionSequence + process.eleIsoSequence + process.muIsoSequence + getattr(process, "patCandidates"))
def switchToPFMET(process,input=cms.InputTag('pfMET'), type1=False, postfix=""): print 'MET: using ', input if( not type1 ): oldMETSource = applyPostfix(process, "patMETs",postfix).metSource applyPostfix(process, "patMETs",postfix).metSource = input applyPostfix(process, "patMETs",postfix).addMuonCorrections = False else: # type1 corrected MET # name of corrected MET hardcoded in PAT and meaningless print 'Apply TypeI corrections for MET' #getattr(process, "patPF2PATSequence"+postfix).remove(applyPostfix(process, "patMETCorrections",postfix)) jecLabel = getattr(process,'patJetCorrFactors'+postfix).payload.pythonValue().replace("'","") getattr(process,jecLabel+'Type1CorMet'+postfix).src = input.getModuleLabel()
def switchToPFMET(process,input=cms.InputTag('pfMET'), type1=False, postfix=""): print 'MET: using ', input if( not type1 ): oldMETSource = applyPostfix(process, "patMETs",postfix).metSource applyPostfix(process, "patMETs",postfix).metSource = input applyPostfix(process, "patMETs",postfix).addMuonCorrections = False else: # type1 corrected MET # name of corrected MET hardcoded in PAT and meaningless print 'Apply TypeI corrections for MET' #getattr(process, "patPF2PATSequence"+postfix).remove(applyPostfix(process, "patMETCorrections",postfix)) jecLabel = getattr(process,'patJetCorrFactors'+postfix).payload.pythonValue().replace("'","") getattr(process,jecLabel+'Type1CorMet'+postfix).src = input.getModuleLabel()
def adaptSelectedPFJetForHPSTau(process, jetSelection="", postfix=""): print "Preselecting the jets used to make taus : " + jetSelection process.pfJetsForHPSTau = selectedPfJets.clone() process.pfJetsForHPSTau.src = "pfJets" + postfix process.pfJetsForHPSTau.cut = cms.string(jetSelection) setattr(process, "pfJetsForHPSTau" + postfix, process.pfJetsForHPSTau) getattr(process, "pfTausPreSequence" + postfix).insert( 0, getattr(process, "pfJetsForHPSTau" + postfix)) applyPostfix(process, "pfTausBase", postfix).jetSrc = "pfJetsForHPSTau" + postfix # need to fix the tau presequence because it depends on the new jet collection applyPostfix(process, "pfJetTracksAssociatorAtVertex", postfix).jets = "pfJetsForHPSTau" + postfix applyPostfix(process, "pfTauPFJets08Region", postfix).src = "pfJetsForHPSTau" + postfix applyPostfix(process, "pfJetsPiZeros", postfix).jetSrc = "pfJetsForHPSTau" + postfix applyPostfix(process, "pfJetsLegacyTaNCPiZeros", postfix).jetSrc = "pfJetsForHPSTau" + postfix applyPostfix(process, "pfJetsLegacyHPSPiZeros", postfix).jetSrc = "pfJetsForHPSTau" + postfix # fix because the TopProjection in pfNoTau does not work because the taus come from the selected jets applyPostfix(process, "pfNoTau", postfix).bottomCollection = "pfJetsForHPSTau" + postfix # must use the pfJets for the patJets otherwise we will have the above selection on the pfJetsForHPSTau ( pfNoTau is a jet collection) print 'Warning!!!!!!!!!!!!!: switching patJet.jetSource from pfNoTau to pfJets because Tau cleaning on the jets cannot be applied currently' applyPostfix(process, "patJets", postfix).jetSource = "pfJets" + postfix
def adaptPFMuons(process, module, postfix=""): print "Adapting PF Muons " print "***************** " warningIsolation() print module.useParticleFlow = True module.userIsolation = cms.PSet() module.isoDeposits = cms.PSet( pfChargedHadrons=cms.InputTag("muPFIsoDepositCharged" + postfix), pfPUChargedHadrons=cms.InputTag("muPFIsoDepositPU" + postfix), pfNeutralHadrons=cms.InputTag("muPFIsoDepositNeutral" + postfix), pfPhotons=cms.InputTag("muPFIsoDepositGamma" + postfix)) module.isolationValues = cms.PSet( pfChargedHadrons=cms.InputTag("muPFIsoValueCharged04" + postfix), pfPUChargedHadrons=cms.InputTag("muPFIsoValuePU04" + postfix), pfNeutralHadrons=cms.InputTag("muPFIsoValueNeutral04" + postfix), pfPhotons=cms.InputTag("muPFIsoValueGamma04" + postfix)) # matching the pfMuons, not the standard muons. applyPostfix(process, "muonMatch", postfix).src = module.pfMuonSource print " muon source:", module.pfMuonSource print " isolation :", print module.isolationValues print " isodeposits: " print module.isoDeposits print
def switchToPFTauHPS( process, pfTauLabelOld=cms.InputTag("hpsPFTauProducer"), pfTauLabelNew=cms.InputTag("hpsPFTauProducer"), patTauLabel="", jecLevels=[], postfix="", ): hpsTauJECpayloadMapping = pfTauJECpayloadMapping _switchToPFTau( process, pfTauLabelOld, pfTauLabelNew, "hpsPFTau", hpsTauIDSources, jecLevels, hpsTauJECpayloadMapping, patTauLabel=patTauLabel, postfix=postfix, ) # CV: enable tau lifetime information for HPS PFTaus applyPostfix( process, "patTaus" + patTauLabel, postfix ).tauTransverseImpactParameterSource = pfTauLabelNew.value().replace("Producer", "TransverseImpactParameters") ## adapt cleanPatTaus if hasattr(process, "cleanPatTaus" + patTauLabel + postfix): getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = ( 'pt > 15 & abs(eta) < 2.3 & tauID("decayModeFinding") > 0.5 & tauID("byLooseIsolation") > 0.5' + ' & tauID("againstMuonTight") > 0.5 & tauID("againstElectronLoose") > 0.5' )
def switchToPFTauHPS(process, pfTauLabelOld=cms.InputTag('hpsPFTauProducer'), pfTauLabelNew=cms.InputTag('hpsPFTauProducer'), patTauLabel="", jecLevels=[], postfix=""): hpsTauJECpayloadMapping = pfTauJECpayloadMapping _switchToPFTau(process, pfTauLabelOld, pfTauLabelNew, 'hpsPFTau', hpsTauIDSources, jecLevels, hpsTauJECpayloadMapping, patTauLabel=patTauLabel, postfix=postfix) # CV: enable tau lifetime information for HPS PFTaus applyPostfix( process, "patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource = pfTauLabelNew.value( ).replace("Producer", "TransverseImpactParameters") ## adapt cleanPatTaus if hasattr(process, "cleanPatTaus" + patTauLabel + postfix): getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = \ 'pt > 15 & abs(eta) < 2.3 & tauID("decayModeFinding") > 0.5 & tauID("byLooseIsolation") > 0.5' \ + ' & tauID("againstMuonTight") > 0.5 & tauID("againstElectronLoose") > 0.5'
def adaptPFMuons(process, module, postfix="", muonMatchModule=None): print "Adapting PF Muons " print "***************** " #warningIsolation() print module.useParticleFlow = True module.pfMuonSource = cms.InputTag("pfIsolatedMuonsPFBRECO" + postfix) module.userIsolation = cms.PSet() ## module.isoDeposits = cms.PSet( ## pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix), ## pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix), ## pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix), ## pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix), ## pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix) ## ) ## module.isolationValues = cms.PSet( ## pfChargedHadrons = cms.InputTag("muPFIsoValueCharged04"+ postfix), ## pfChargedAll = cms.InputTag("muPFIsoValueChargedAll04"+ postfix), ## pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU04" + postfix), ## pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral04" + postfix), ## pfPhotons = cms.InputTag("muPFIsoValueGamma04" + postfix) ## ) # matching the pfMuons, not the standard muons. if muonMatchModule == None: applyPostfix(process, "muonMatch", postfix).src = module.pfMuonSource else: muonMatchModule.src = module.pfMuonSource print " muon source:", module.pfMuonSource ## print " isolation :", ## print module.isolationValues ## print " isodeposits: " ## print module.isoDeposits print
def adaptPFMuons(process,module,postfix="" ): print "Adapting PF Muons " print "***************** " warningIsolation() print module.useParticleFlow = True module.userIsolation = cms.PSet() module.isoDeposits = cms.PSet( pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix), pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix), pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix), pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix), pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix) ) module.isolationValues = cms.PSet( pfChargedHadrons = cms.InputTag("muPFIsoValueCharged04"+ postfix), pfChargedAll = cms.InputTag("muPFIsoValueChargedAll04"+ postfix), pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU04" + postfix), pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral04" + postfix), pfPhotons = cms.InputTag("muPFIsoValueGamma04" + postfix) ) # matching the pfMuons, not the standard muons. applyPostfix(process,"muonMatch",postfix).src = module.pfMuonSource print " muon source:", module.pfMuonSource print " isolation :", print module.isolationValues print " isodeposits: " print module.isoDeposits print
def adaptPFMuons(process,module,postfix="", muonMatchModule=None ): print "Adapting PF Muons " print "***************** " #warningIsolation() print module.useParticleFlow = True module.pfMuonSource = cms.InputTag("pfIsolatedMuons" + postfix) module.userIsolation = cms.PSet() ## module.isoDeposits = cms.PSet( ## pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix), ## pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix), ## pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix), ## pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix), ## pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix) ## ) ## module.isolationValues = cms.PSet( ## pfChargedHadrons = cms.InputTag("muPFIsoValueCharged04"+ postfix), ## pfChargedAll = cms.InputTag("muPFIsoValueChargedAll04"+ postfix), ## pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU04" + postfix), ## pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral04" + postfix), ## pfPhotons = cms.InputTag("muPFIsoValueGamma04" + postfix) ## ) # matching the pfMuons, not the standard muons. if muonMatchModule == None : applyPostfix(process,"muonMatch",postfix).src = module.pfMuonSource else : muonMatchModule.src = module.pfMuonSource print " muon source:", module.pfMuonSource ## print " isolation :", ## print module.isolationValues ## print " isodeposits: " ## print module.isoDeposits print
def removeHPSTauIsolation(process, postfix = ""): print "removing tau isolation discriminators and applying only the decayModeFinding " #note that isolation discriminators have an implicit decayModeFinding requirement getattr(process,"pfTausBaseSequence"+postfix).remove(applyPostfix(process,"pfTausBaseDiscriminationByLooseCombinedIsolationDBSumPtCorr",postfix)) getattr(process,"pfTaus"+postfix).discriminators = [cms.PSet(discriminator = cms.InputTag("pfTausBaseDiscriminationByDecayModeFinding"+postfix), selectionCut = cms.double(0.5) )]
def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""): # Set up the collection used as a preselection to use this tau type if tauType != 'hpsPFTau' : reconfigurePF2PATTaus(process, tauType, postfix=postfix) else: reconfigurePF2PATTaus(process, tauType, ["DiscriminationByLooseCombinedIsolationDBSumPtCorr"], ["DiscriminationByDecayModeFinding"], postfix=postfix) # new default use unselected taus (selected only for jet cleaning) if tauType != 'hpsPFTau' : applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTausBase"+postfix) else: applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix) # to use preselected collection (old default) uncomment line below #applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix) redoPFTauDiscriminators(process, cms.InputTag(tauType+'Producer'), applyPostfix(process,"patTaus", postfix).tauSource, tauType, postfix=postfix) switchToPFTauByType(process, pfTauType=tauType, pfTauLabelNew=applyPostfix(process,"patTaus", postfix).tauSource, pfTauLabelOld=cms.InputTag(tauType+'Producer'), postfix=postfix) applyPostfix(process,"makePatTaus", postfix).remove( applyPostfix(process,"patPFCandidateIsoDepositSelection", postfix) )
def switchToCaloTau(process, pfTauLabelOld = cms.InputTag('shrinkingConePFTauProducer'), pfTauLabelNew = cms.InputTag('caloRecoTauProducer'), patTauLabel = "", postfix = ""): print ' Taus: ', pfTauLabelOld, '->', pfTauLabelNew caloTauLabel = pfTauLabelNew applyPostfix(process, "tauMatch" + patTauLabel, postfix).src = caloTauLabel applyPostfix(process, "tauGenJetMatch"+ patTauLabel, postfix).src = caloTauLabel applyPostfix(process, "patTaus" + patTauLabel, postfix).tauSource = caloTauLabel applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = _buildIDSourcePSet('caloRecoTau', classicTauIDSources, postfix) # applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = cms.PSet( # leadingTrackFinding = cms.InputTag("caloRecoTauDiscriminationByLeadingTrackFinding" + postfix), # leadingTrackPtCut = cms.InputTag("caloRecoTauDiscriminationByLeadingTrackPtCut" + postfix), # trackIsolation = cms.InputTag("caloRecoTauDiscriminationByTrackIsolation" + postfix), # ecalIsolation = cms.InputTag("caloRecoTauDiscriminationByECALIsolation" + postfix), # byIsolation = cms.InputTag("caloRecoTauDiscriminationByIsolation" + postfix), # againstElectron = cms.InputTag("caloRecoTauDiscriminationAgainstElectron" + postfix), # againstMuon = cms.InputTag("caloRecoTauDiscriminationAgainstMuon" + postfix) # ) ## Isolation is somewhat an issue, so we start just by turning it off print "NO PF Isolation will be computed for CaloTau (this could be improved later)" applyPostfix(process, "patTaus" + patTauLabel, postfix).isolation = cms.PSet() applyPostfix(process, "patTaus" + patTauLabel, postfix).isoDeposits = cms.PSet() applyPostfix(process, "patTaus" + patTauLabel, postfix).userIsolation = cms.PSet() ## adapt cleanPatTaus if hasattr(process, "cleanPatTaus" + patTauLabel + postfix): getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = \ 'tauID("leadingTrackFinding") > 0.5 & tauID("leadingTrackPtCut") > 0.5' \ + ' & tauID("byIsolation") > 0.5 & tauID("againstElectron") > 0.5 & (signalTracks.size() = 1 | signalTracks.size() = 3)'
def addPFCandidates(process,src,patLabel='PFParticles',cut="",postfix=""): from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles # make modules producer = patPFParticles.clone(pfCandidateSource = src) filter = cms.EDFilter("PATPFParticleSelector", src = cms.InputTag("pat" + patLabel), cut = cms.string(cut)) counter = cms.EDFilter("PATCandViewCountFilter", minNumber = cms.uint32(0), maxNumber = cms.uint32(999999), src = cms.InputTag("pat" + patLabel)) # add modules to process setattr(process, "pat" + patLabel, producer) setattr(process, "selectedPat" + patLabel, filter) setattr(process, "countPat" + patLabel, counter) # summary tables applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel)) applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
def addPFCandidates(process,src,patLabel='PFParticles',cut="",postfix=""): from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles # make modules producer = patPFParticles.clone(pfCandidateSource = src) filter = cms.EDFilter("PATPFParticleSelector", src = cms.InputTag("pat" + patLabel), cut = cms.string(cut)) counter = cms.EDFilter("PATCandViewCountFilter", minNumber = cms.uint32(0), maxNumber = cms.uint32(999999), src = cms.InputTag("pat" + patLabel)) # add modules to process task = getPatAlgosToolsTask(process) addToProcessAndTask("pat" + patLabel, producer, process, task) addToProcessAndTask("selectedPat" + patLabel, filter, process, task) addToProcessAndTask("countPat" + patLabel, counter, process, task) # summary tables applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel)) applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
def switchToPFMET(process,input=cms.InputTag('pfMET'), type1=False, postfix=""): print 'MET: using ', input if( not type1 ): oldMETSource = applyPostfix(process, "patMETs",postfix).metSource applyPostfix(process, "patMETs",postfix).metSource = input applyPostfix(process, "patMETs",postfix).addMuonCorrections = False getattr(process, "patDefaultSequence"+postfix).remove( applyPostfix(process, "patMETCorrections",postfix) ) else: # type1 corrected MET # name of coreccted MET hardcoded in PAT and meaningless print 'Apply type1 corrections for MET' applyPostfix(process, "metJESCorAK5CaloJet",postfix).inputUncorMetLabel = input.getModuleLabel() applyPostfix(process, "metJESCorAK5CaloJet",postfix).metType = 'PFMET' applyPostfix(process, "metJESCorAK5CaloJet",postfix).jetPTthreshold = 1.0 applyPostfix(process, "patMETs",postfix).metSource = "metJESCorAK5CaloJet"+postfix applyPostfix(process, "patMETs",postfix).addMuonCorrections = False getattr(process, "patDefaultSequence"+postfix).remove( applyPostfix(process, "metJESCorAK5CaloJetMuons",postfix) )
def adaptPFTaus(process, tauType='shrinkingConePFTau', postfix=""): # Set up the collection used as a preselection to use this tau type if tauType != 'hpsPFTau': reconfigurePF2PATTaus(process, tauType, postfix=postfix) else: reconfigurePF2PATTaus(process, tauType, [ "DiscriminationByLooseChargedIsolation", "DiscriminationByLooseIsolation" ], ["DiscriminationByDecayModeFinding"], postfix=postfix) applyPostfix(process, "patTaus", postfix).tauSource = cms.InputTag("pfTaus" + postfix) redoPFTauDiscriminators(process, cms.InputTag(tauType + 'Producer'), applyPostfix(process, "patTaus", postfix).tauSource, tauType, postfix=postfix) switchToPFTauByType(process, pfTauType=tauType, pfTauLabelNew=applyPostfix(process, "patTaus", postfix).tauSource, pfTauLabelOld=cms.InputTag(tauType + 'Producer'), postfix=postfix) applyPostfix(process, "makePatTaus", postfix).remove( applyPostfix(process, "patPFCandidateIsoDepositSelection", postfix))
def switchToPFTauHPS(process, pfTauLabelOld = cms.InputTag('hpsPFTauProducer'), pfTauLabelNew = cms.InputTag('hpsPFTauProducer'), patTauLabel = "", jecLevels = [], postfix = ""): hpsTauJECpayloadMapping = pfTauJECpayloadMapping _switchToPFTau(process, pfTauLabelOld, pfTauLabelNew, 'hpsPFTau', hpsTauIDSources, jecLevels, hpsTauJECpayloadMapping, patTauLabel = patTauLabel, postfix = postfix) # CV: enable tau lifetime information for HPS PFTaus applyPostfix(process, "patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource = pfTauLabelOld.value().replace("Producer", "TransverseImpactParameters")+patTauLabel+postfix applyPostfix(process, "hpsPFTauPrimaryVertexProducer"+ patTauLabel, postfix).PFTauTag = pfTauLabelNew applyPostfix(process, "hpsPFTauSecondaryVertexProducer" + patTauLabel, postfix).PFTauTag = pfTauLabelNew applyPostfix(process, "hpsPFTauTransverseImpactParameters" +patTauLabel, postfix).PFTauTag = pfTauLabelNew applyPostfix(process, "hpsPFTauTransverseImpactParameters" +patTauLabel, postfix).PFTauPVATag = "hpsPFTauPrimaryVertexProducer"+patTauLabel+postfix applyPostfix(process, "hpsPFTauTransverseImpactParameters" +patTauLabel, postfix).PFTauSVATag = "hpsPFTauSecondaryVertexProducer"+patTauLabel+postfix ## adapt cleanPatTaus if hasattr(process, "cleanPatTaus" + patTauLabel + postfix): getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = \ 'pt > 20 & abs(eta) < 2.3 & tauID("decayModeFindingOldDMs") > 0.5 & tauID("byLooseCombinedIsolationDeltaBetaCorr3Hits") > 0.5' \ + ' & tauID("againstMuonTight3") > 0.5 & tauID("againstElectronLoose") > 0.5'
def useGsfElectrons(process, postfix, dR = "04"): print "using Gsf Electrons in PF2PAT" print "WARNING: this will destory the feature of top projection which solves the ambiguity between leptons and jets because" print "WARNING: there will be overlap between non-PF electrons and jets even though top projection is ON!" print "********************* " module = applyPostfix(process,"patElectrons",postfix) module.useParticleFlow = False print "Building particle-based isolation for GsfElectrons in PF2PAT(PFBRECO)" print "********************* " adaptPFIsoElectrons( process, module, postfix+"PFIso", dR ) getattr(process,'patDefaultSequence'+postfix).replace( getattr(process,"patElectrons"+postfix), setupPFElectronIso(process, 'gsfElectrons', "PFIso", postfix, runPF2PAT=True) + getattr(process,"patElectrons"+postfix) )
def removeHPSTauIsolation(process, postfix=""): print "removing tau isolation discriminators and applying only the decayModeFinding " #note that isolation discriminators have an implicit decayModeFinding requirement getattr(process, "pfTausBaseSequence" + postfix).remove( applyPostfix( process, "pfTausBaseDiscriminationByLooseCombinedIsolationDBSumPtCorr", postfix)) getattr(process, "pfTaus" + postfix).discriminators = [ cms.PSet(discriminator=cms.InputTag( "pfTausBaseDiscriminationByDecayModeFinding" + postfix), selectionCut=cms.double(0.5)) ]
def switchToCaloTau(process, pfTauLabelOld=cms.InputTag('hpsPFTauProducer'), pfTauLabelNew=cms.InputTag('caloRecoTauProducer'), patTauLabel="", postfix=""): print ' Taus: ', pfTauLabelOld, '->', pfTauLabelNew caloTauLabel = pfTauLabelNew applyPostfix(process, "tauMatch" + patTauLabel, postfix).src = caloTauLabel applyPostfix(process, "tauGenJetMatch" + patTauLabel, postfix).src = caloTauLabel applyPostfix(process, "patTaus" + patTauLabel, postfix).tauSource = caloTauLabel # CV: reconstruction of tau lifetime information not implemented for CaloTaus yet applyPostfix(process, "patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource = "" applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = _buildIDSourcePSet( 'caloRecoTau', classicTauIDSources, postfix) # applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = cms.PSet( # leadingTrackFinding = cms.InputTag("caloRecoTauDiscriminationByLeadingTrackFinding" + postfix), # leadingTrackPtCut = cms.InputTag("caloRecoTauDiscriminationByLeadingTrackPtCut" + postfix), # trackIsolation = cms.InputTag("caloRecoTauDiscriminationByTrackIsolation" + postfix), # ecalIsolation = cms.InputTag("caloRecoTauDiscriminationByECALIsolation" + postfix), # byIsolation = cms.InputTag("caloRecoTauDiscriminationByIsolation" + postfix), # againstElectron = cms.InputTag("caloRecoTauDiscriminationAgainstElectron" + postfix), # againstMuon = cms.InputTag("caloRecoTauDiscriminationAgainstMuon" + postfix) # ) ## Isolation is somewhat an issue, so we start just by turning it off print "NO PF Isolation will be computed for CaloTau (this could be improved later)" applyPostfix(process, "patTaus" + patTauLabel, postfix).isolation = cms.PSet() applyPostfix(process, "patTaus" + patTauLabel, postfix).isoDeposits = cms.PSet() applyPostfix(process, "patTaus" + patTauLabel, postfix).userIsolation = cms.PSet() ## no tau-jet energy corrections determined for CaloTaus yet # applyPostfix(process, "patTauJetCorrFactors" + patTauLabel, postfix).src = caloTauLabel # applyPostfix(process, "patTaus" + patTauLabel, postfix).addTauJetCorrFactors = cms.bool(False) ## adapt cleanPatTaus if hasattr(process, "cleanPatTaus" + patTauLabel + postfix): getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = \ 'tauID("leadingTrackFinding") > 0.5 & tauID("leadingTrackPtCut") > 0.5' \ + ' & tauID("byIsolation") > 0.5 & tauID("againstElectron") > 0.5 & (signalTracks.size() = 1 | signalTracks.size() = 3)'
def switchToPFJets(process, input=cms.InputTag('pfNoTau'), algo='AK5', postfix = "", jetCorrections=['L1Offset','L2Relative', 'L3Absolute']): print "Switching to PFJets, ", algo print "************************ " print "input collection: ", input if( algo == 'IC5' ): genJetCollection = cms.InputTag('iterativeCone5GenJetsNoNu') elif algo == 'AK5': genJetCollection = cms.InputTag('ak5GenJetsNoNu') elif algo == 'AK7': genJetCollection = cms.InputTag('ak7GenJetsNoNu') else: print 'bad jet algorithm:', algo, '! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin' sys.exit(1) # changing the jet collection in PF2PAT: from PhysicsTools.PFCandProducer.Tools.jetTools import jetAlgo inputCollection = getattr(process,"pfJets"+postfix).src setattr(process, "pfJets"+postfix, jetAlgo( algo ) ) # problem for cfgBrowser getattr(process,"pfJets"+postfix).src = inputCollection inputJetCorrLabel=(algo+'PF',jetCorrections) switchJetCollection(process, input, jetIdLabel = algo, doJTA=True, doBTagging=True, jetCorrLabel=inputJetCorrLabel, #doType1MET=False, doType1MET=True, genJetCollection = genJetCollection, doJetID = True, postfix = postfix ) applyPostfix(process, "patJets", postfix).embedCaloTowers = False applyPostfix(process, "patJets", postfix).embedPFCandidates = True
def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""): # Set up the collection used as a preselection to use this tau type if tauType != 'hpsPFTau' : reconfigurePF2PATTaus(process, tauType, postfix=postfix) else: reconfigurePF2PATTaus(process, tauType, ["DiscriminationByLooseCombinedIsolationDBSumPtCorr"], ["DiscriminationByDecayModeFinding"], postfix=postfix) # new default use unselected taus (selected only for jet cleaning) if tauType != 'hpsPFTau' : applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTausBase"+postfix) else: applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix) # to use preselected collection (old default) uncomment line below #applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix) ### apparently not needed anymore, function gone from tauTools.py### #redoPFTauDiscriminators(process, #cms.InputTag(tauType+'Producer'), #applyPostfix(process,"patTaus", postfix).tauSource, #tauType, postfix=postfix) if tauType != 'hpsPFTau' : switchToPFTauByType(process, pfTauType=tauType, patTauLabel="pfTausBase"+postfix, tauSource=cms.InputTag(tauType+'Producer'+postfix), postfix=postfix) applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTausBase"+postfix) else: switchToPFTauByType(process, pfTauType=tauType, patTauLabel="", tauSource=cms.InputTag(tauType+'Producer'+postfix), postfix=postfix) applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
def useGsfElectrons(process, postfix, dR="04"): print "using Gsf Electrons in PF2PAT" print "WARNING: this will destory the feature of top projection which solves the ambiguity between leptons and jets because" print "WARNING: there will be overlap between non-PF electrons and jets even though top projection is ON!" print "********************* " module = applyPostfix(process, "patElectrons", postfix) module.useParticleFlow = False print "Building particle-based isolation for GsfElectrons in PF2PAT(PFBRECO)" print "********************* " adaptPFIsoElectrons(process, module, postfix + "PFIso", dR) getattr(process, 'patDefaultSequence' + postfix).replace( getattr(process, "patElectrons" + postfix), setupPFElectronIso( process, 'gsfElectrons', "PFIso", postfix, runPF2PAT=True) + getattr(process, "patElectrons" + postfix))
def switchToCaloTau( process, pfTauLabelOld=cms.InputTag("hpsPFTauProducer"), pfTauLabelNew=cms.InputTag("caloRecoTauProducer"), patTauLabel="", postfix="", ): print " Taus: ", pfTauLabelOld, "->", pfTauLabelNew caloTauLabel = pfTauLabelNew applyPostfix(process, "tauMatch" + patTauLabel, postfix).src = caloTauLabel applyPostfix(process, "tauGenJetMatch" + patTauLabel, postfix).src = caloTauLabel applyPostfix(process, "patTaus" + patTauLabel, postfix).tauSource = caloTauLabel # CV: reconstruction of tau lifetime information not implemented for CaloTaus yet applyPostfix(process, "patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource = "" applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = _buildIDSourcePSet( "caloRecoTau", classicTauIDSources, postfix ) # applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = cms.PSet( # leadingTrackFinding = cms.InputTag("caloRecoTauDiscriminationByLeadingTrackFinding" + postfix), # leadingTrackPtCut = cms.InputTag("caloRecoTauDiscriminationByLeadingTrackPtCut" + postfix), # trackIsolation = cms.InputTag("caloRecoTauDiscriminationByTrackIsolation" + postfix), # ecalIsolation = cms.InputTag("caloRecoTauDiscriminationByECALIsolation" + postfix), # byIsolation = cms.InputTag("caloRecoTauDiscriminationByIsolation" + postfix), # againstElectron = cms.InputTag("caloRecoTauDiscriminationAgainstElectron" + postfix), # againstMuon = cms.InputTag("caloRecoTauDiscriminationAgainstMuon" + postfix) # ) ## Isolation is somewhat an issue, so we start just by turning it off print "NO PF Isolation will be computed for CaloTau (this could be improved later)" applyPostfix(process, "patTaus" + patTauLabel, postfix).isolation = cms.PSet() applyPostfix(process, "patTaus" + patTauLabel, postfix).isoDeposits = cms.PSet() applyPostfix(process, "patTaus" + patTauLabel, postfix).userIsolation = cms.PSet() ## no tau-jet energy corrections determined for CaloTaus yet # applyPostfix(process, "patTauJetCorrFactors" + patTauLabel, postfix).src = caloTauLabel # applyPostfix(process, "patTaus" + patTauLabel, postfix).addTauJetCorrFactors = cms.bool(False) ## adapt cleanPatTaus if hasattr(process, "cleanPatTaus" + patTauLabel + postfix): getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = ( 'tauID("leadingTrackFinding") > 0.5 & tauID("leadingTrackPtCut") > 0.5' + ' & tauID("byIsolation") > 0.5 & tauID("againstElectron") > 0.5 & (signalTracks.size() = 1 | signalTracks.size() = 3)' )
def switchToPFJets(process, input=cms.InputTag('pfNoTau'), algo='AK5', postfix="", jetCorrections=('AK5PFchs', ['L1FastJet', 'L2Relative', 'L3Absolute']), outputModules=['out']): print "Switching to PFJets, ", algo print "************************ " print "input collection: ", input if (algo == 'IC5'): genJetCollection = cms.InputTag('iterativeCone5GenJetsNoNu') elif algo == 'AK5': genJetCollection = cms.InputTag('ak5GenJetsNoNu') elif algo == 'AK7': genJetCollection = cms.InputTag('ak7GenJetsNoNu') else: print 'bad jet algorithm:', algo, '! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin' sys.exit(1) # changing the jet collection in PF2PAT: from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo inputCollection = getattr(process, "pfJets" + postfix).src setattr(process, "pfJets" + postfix, jetAlgo(algo)) # problem for cfgBrowser getattr(process, "pfJets" + postfix).src = inputCollection inputJetCorrLabel = jetCorrections switchJetCollection( process, input, jetIdLabel=algo, doJTA=True, doBTagging=True, jetCorrLabel=inputJetCorrLabel, #doType1MET=False, doType1MET=True, genJetCollection=genJetCollection, doJetID=True, postfix=postfix, outputModules=outputModules) # check whether L1FastJet is in the list of correction levels or not applyPostfix(process, "patJetCorrFactors", postfix).useRho = False for corr in inputJetCorrLabel[1]: if corr == 'L1FastJet': applyPostfix(process, "patJetCorrFactors", postfix).useRho = True applyPostfix(process, "pfJets", postfix).doAreaFastjet = True applyPostfix(process, "kt6PFJets", postfix).src = inputCollection applyPostfix(process, "patJets", postfix).embedCaloTowers = False applyPostfix(process, "patJets", postfix).embedPFCandidates = True
def adaptSelectedPFJetForHPSTau(process, jetSelection = "", postfix = ""): print "Preselecting the jets used to make taus : "+jetSelection process.pfJetsForHPSTau = selectedPfJets.clone() process.pfJetsForHPSTau.src = "pfJets"+postfix process.pfJetsForHPSTau.cut = cms.string(jetSelection) setattr(process,"pfJetsForHPSTau"+postfix, process.pfJetsForHPSTau) getattr(process,"pfTausPreSequence"+postfix).insert(0,getattr(process,"pfJetsForHPSTau"+postfix)) applyPostfix(process,"pfTausBase",postfix).jetSrc = "pfJetsForHPSTau"+postfix # need to fix the tau presequence because it depends on the new jet collection applyPostfix(process,"pfJetTracksAssociatorAtVertex",postfix).jets = "pfJetsForHPSTau"+postfix applyPostfix(process,"pfTauPFJets08Region",postfix).src = "pfJetsForHPSTau"+postfix applyPostfix(process,"pfJetsPiZeros",postfix).jetSrc = "pfJetsForHPSTau"+postfix applyPostfix(process,"pfJetsLegacyTaNCPiZeros",postfix).jetSrc = "pfJetsForHPSTau"+postfix applyPostfix(process,"pfJetsLegacyHPSPiZeros",postfix).jetSrc = "pfJetsForHPSTau"+postfix # fix because the TopProjection in pfNoTau does not work because the taus come from the selected jets applyPostfix(process,"pfNoTau",postfix).bottomCollection = "pfJetsForHPSTau"+postfix # must use the pfJets for the patJets otherwise we will have the above selection on the pfJetsForHPSTau ( pfNoTau is a jet collection) print 'Warning!!!!!!!!!!!!!: switching patJet.jetSource from pfNoTau to pfJets because Tau cleaning on the jets cannot be applied currently' applyPostfix(process,"patJets",postfix).jetSource = "pfJets"+postfix
def switchToPFJets(process, input=cms.InputTag('pfNoTau'), algo='AK5', postfix = "", jetCorrections=('AK5PFchs', ['L1FastJet','L2Relative', 'L3Absolute']), outputModules=['out']): print "Switching to PFJets, ", algo print "************************ " print "input collection: ", input if( algo == 'IC5' ): genJetCollection = cms.InputTag('iterativeCone5GenJetsNoNu') elif algo == 'AK5': genJetCollection = cms.InputTag('ak5GenJetsNoNu') elif algo == 'AK7': genJetCollection = cms.InputTag('ak7GenJetsNoNu') else: print 'bad jet algorithm:', algo, '! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin' sys.exit(1) # changing the jet collection in PF2PAT: from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo inputCollection = getattr(process,"pfJets"+postfix).src setattr(process,"pfJets"+postfix,jetAlgo(algo)) # problem for cfgBrowser getattr(process,"pfJets"+postfix).src = inputCollection inputJetCorrLabel=jetCorrections switchJetCollection(process, input, jetIdLabel = algo, doJTA=True, doBTagging=True, jetCorrLabel=inputJetCorrLabel, #doType1MET=False, doType1MET=True, genJetCollection = genJetCollection, doJetID = True, postfix = postfix, outputModules = outputModules ) # check whether L1FastJet is in the list of correction levels or not applyPostfix(process, "patJetCorrFactors", postfix).useRho = False for corr in inputJetCorrLabel[1]: if corr == 'L1FastJet': applyPostfix(process, "patJetCorrFactors", postfix).useRho = True applyPostfix(process, "pfJets", postfix).doAreaFastjet = True applyPostfix(process, "kt6PFJets", postfix).src = inputCollection applyPostfix(process, "patJets", postfix).embedCaloTowers = False applyPostfix(process, "patJets", postfix).embedPFCandidates = True
def adaptPFTaus(process, tauType='shrinkingConePFTau', postfix=""): # Set up the collection used as a preselection to use this tau type if tauType != 'hpsPFTau': reconfigurePF2PATTaus(process, tauType, postfix=postfix) else: reconfigurePF2PATTaus( process, tauType, ["DiscriminationByLooseCombinedIsolationDBSumPtCorr"], ["DiscriminationByDecayModeFinding"], postfix=postfix) # new default use unselected taus (selected only for jet cleaning) if tauType != 'hpsPFTau': applyPostfix(process, "patTaus", postfix).tauSource = cms.InputTag("pfTausBase" + postfix) else: applyPostfix(process, "patTaus", postfix).tauSource = cms.InputTag("hpsPFTauProducer" + postfix) # to use preselected collection (old default) uncomment line below #applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix) redoPFTauDiscriminators(process, cms.InputTag(tauType + 'Producer'), applyPostfix(process, "patTaus", postfix).tauSource, tauType, postfix=postfix) switchToPFTauByType(process, pfTauType=tauType, pfTauLabelNew=applyPostfix(process, "patTaus", postfix).tauSource, pfTauLabelOld=cms.InputTag(tauType + 'Producer'), postfix=postfix) applyPostfix(process, "makePatTaus", postfix).remove( applyPostfix(process, "patPFCandidateIsoDepositSelection", postfix))
def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""): # Set up the collection used as a preselection to use this tau type if tauType != 'hpsPFTau' : reconfigurePF2PATTaus(process, tauType, postfix=postfix) else: reconfigurePF2PATTaus(process, tauType, ["DiscriminationByLooseChargedIsolation","DiscriminationByLooseIsolation"], ["DiscriminationByDecayModeFinding"], postfix=postfix) applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix) redoPFTauDiscriminators(process, cms.InputTag(tauType+'Producer'), applyPostfix(process,"patTaus", postfix).tauSource, tauType, postfix=postfix) switchToPFTauByType(process, pfTauType=tauType, pfTauLabelNew=applyPostfix(process,"patTaus", postfix).tauSource, pfTauLabelOld=cms.InputTag(tauType+'Producer'), postfix=postfix) applyPostfix(process,"makePatTaus", postfix).remove( applyPostfix(process,"patPFCandidateIsoDepositSelection", postfix) )
def _switchToPFTau(process, pfTauLabelOld, pfTauLabelNew, pfTauType, idSources, jecLevels, jecPayloadMapping, patTauLabel = "", postfix = ""): """internal auxiliary function to switch to **any** PFTau collection""" print ' Taus: ', pfTauLabelOld, '->', pfTauLabelNew applyPostfix(process, "tauMatch" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauGenJetMatch" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFCandidates" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFCandidates" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFGammas" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFGammas" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew #applyPostfix(process, "patTauJetCorrFactors" + patTauLabel, postfix).src = pfTauLabelNew #if len(jecLevels) > 0: # applyPostfix(process, "patTaus" + patTauLabel, postfix).addTauJetCorrFactors = cms.bool(True) # applyPostfix(process, "patTauJetCorrFactors" + patTauLabel, postfix).parameters = jecPayloadMapping #else: # applyPostfix(process, "patTaus" + patTauLabel, postfix).addTauJetCorrFactors = cms.bool(False) applyPostfix(process, "patTaus" + patTauLabel, postfix).tauSource = pfTauLabelNew applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = _buildIDSourcePSet(pfTauType, idSources, postfix) applyPostfix(process, "cleanPatTaus" + patTauLabel, postfix).preselection = \ 'tauID("leadingTrackFinding") > 0.5 & tauID("leadingPionPtCut") > 0.5 & tauID("byIsolationUsingLeadingPion") > 0.5' \ + ' & tauID("againstMuon") > 0.5 & tauID("againstElectron") > 0.5' \ + ' & (signalPFChargedHadrCands.size() = 1 | signalPFChargedHadrCands.size() = 3)'
def _switchToPFTau(process, pfTauLabelOld, pfTauLabelNew, pfTauType, idSources, jecLevels, jecPayloadMapping, patTauLabel="", postfix=""): """internal auxiliary function to switch to **any** PFTau collection""" print ' Taus: ', pfTauLabelOld, '->', pfTauLabelNew applyPostfix(process, "tauMatch" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauGenJetMatch" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFCandidates" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFCandidates" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFGammas" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFGammas" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew # applyPostfix(process, "patTauJetCorrFactors" + patTauLabel, postfix).src = pfTauLabelNew # if len(jecLevels) > 0: # applyPostfix(process, "patTaus" + patTauLabel, postfix).addTauJetCorrFactors = cms.bool(True) # applyPostfix(process, "patTauJetCorrFactors" + patTauLabel, postfix).parameters = jecPayloadMapping # else: # applyPostfix(process, "patTaus" + patTauLabel, postfix).addTauJetCorrFactors = cms.bool(False) applyPostfix(process, "patTaus" + patTauLabel, postfix).tauSource = pfTauLabelNew applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = _buildIDSourcePSet( pfTauType, idSources, postfix) if hasattr(process, "cleanPatTaus" + patTauLabel + postfix): getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = \ 'tauID("leadingTrackFinding") > 0.5 & tauID("leadingPionPtCut") > 0.5 & tauID("byIsolationUsingLeadingPion") > 0.5' \ + ' & tauID("againstMuon") > 0.5 & tauID("againstElectron") > 0.5' \ + ' & (signalPFChargedHadrCands.size() = 1 | signalPFChargedHadrCands.size() = 3)'
def redoPFTauDiscriminators(process, oldPFTauLabel=cms.InputTag('hpsPFTauProducer'), newPFTauLabel=cms.InputTag('hpsPFTauProducer'), tauType='hpsPFTau', postfix=""): print 'Tau discriminators: ', oldPFTauLabel, '->', newPFTauLabel print 'Tau type: ', tauType #oldPFTauLabel.setModuleLabel(oldPFTauLabel.getModuleLabel()+postfix) tauSrc = 'PFTauProducer' tauDiscriminationSequence = None if tauType == 'hpsPFTau': process.patHPSPFTauDiscrimination = process.produceAndDiscriminateHPSPFTaus.copy( ) # remove producers for iname in process.patHPSPFTauDiscrimination.moduleNames(): if not (iname.find("DiscriminationBy") > -1 or iname.find("DiscriminationAgainst") > -1): process.patHPSPFTauDiscrimination.remove( getattr(process, iname)) tauDiscriminationSequence = cloneProcessingSnippet( process, process.patHPSPFTauDiscrimination, postfix) elif tauType == 'hpsTancTaus': #to be checked if correct process.patHPSTaNCPFTauDiscrimination = process.hpsTancTauInitialSequence.copy( ) process.patHPSTaNCPFTauDiscrimination *= process.hpsTancTauDiscriminantSequence # remove producers for iname in process.patHPSTaNCPFTauDiscrimination.moduleNames(): if not (iname.find("DiscriminationBy") > -1 or iname.find("DiscriminationAgainst") > -1): process.patHPSTaNCPFTauDiscrimination.remove( getattr(process, iname)) tauDiscriminationSequence = cloneProcessingSnippet( process, process.patHPSTaNCPFTauDiscrimination, postfix) elif tauType == 'fixedConePFTau': process.patFixedConePFTauDiscrimination = process.produceAndDiscriminateFixedConePFTaus.copy( ) # remove producers for iname in process.patFixedConePFTauDiscrimination.moduleNames(): if not (iname.find("DiscriminationBy") > -1 or iname.find("DiscriminationAgainst") > -1): process.patFixedConePFTauDiscrimination.remove( getattr(process, iname)) tauDiscriminationSequence = cloneProcessingSnippet( process, process.patFixedConePFTauDiscrimination, postfix) elif tauType == 'shrinkingConePFTau': #shr cone with TaNC process.patShrinkingConePFTauDiscrimination = process.produceAndDiscriminateShrinkingConePFTaus.copy( ) process.patShrinkingConePFTauDiscrimination *= process.produceShrinkingConeDiscriminationByTauNeuralClassifier # remove producers for iname in process.patShrinkingConePFTauDiscrimination.moduleNames(): if not (iname.find("DiscriminationBy") > -1 or iname.find("DiscriminationAgainst") > -1): process.patShrinkingConePFTauDiscrimination.remove( getattr(process, iname)) tauDiscriminationSequence = cloneProcessingSnippet( process, process.patShrinkingConePFTauDiscrimination, postfix) elif tauType == 'caloTau': # fill calo sequence by discriminants process.patCaloTauDiscrimination = process.tautagging.copy() # remove producers for iname in process.patCaloTauDiscrimination.moduleNames(): if not (iname.find("DiscriminationBy") > -1 or iname.find("DiscriminationAgainst") > -1): process.patCaloTauDiscrimination.remove(getattr( process, iname)) tauDiscriminationSequence = cloneProcessingSnippet( process, process.patCaloTauDiscrimination, postfix) tauSrc = 'CaloTauProducer' else: raise StandardError, "Unkown tauType: '%s'" % tauType applyPostfix(process, "patDefaultSequence", postfix).replace( applyPostfix(process, "patTaus", postfix), tauDiscriminationSequence * applyPostfix(process, "patTaus", postfix)) massSearchReplaceParam(tauDiscriminationSequence, tauSrc, oldPFTauLabel, newPFTauLabel)
def usePF2PAT(process,runPF2PAT=True, jetAlgo='AK4', runOnMC=True, postfix="", jetCorrections=('AK4PFchs', ['L1FastJet','L2Relative','L3Absolute'],'None'), pvCollection=cms.InputTag('goodOfflinePrimaryVerticesPFlow',), typeIMetCorrections=False, outputModules=['out'],excludeFromTopProjection=['Tau']): # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT. # CREATE ADDITIONAL FUNCTIONS IF NEEDED. if typeIMetCorrections: jetCorrections = (jetCorrections[0],jetCorrections[1],'Type-1') """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence""" # -------- CORE --------------- from PhysicsTools.PatAlgos.tools.helpers import loadWithPostfix if runPF2PAT: loadWithPostfix(process,'PhysicsTools.PatAlgos.patSequences_cff',postfix) loadWithPostfix(process,"CommonTools.ParticleFlow.PF2PAT_cff",postfix) else: loadWithPostfix(process,'PhysicsTools.PatAlgos.patSequences_cff',postfix) # -------- OBJECTS ------------ # Muons adaptPFMuons(process, applyPostfix(process,"patMuons",postfix), postfix) # Electrons adaptPFElectrons(process, applyPostfix(process,"patElectrons",postfix), postfix) # Photons #print "Temporarily switching off photons completely" #removeSpecificPATObjects(process,names=['Photons'],outputModules=outputModules,postfix=postfix) # Jets if runOnMC : switchToPFJets( process, cms.InputTag('pfNoTauClones'+postfix), jetAlgo, postfix=postfix, jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules ) else : if not 'L2L3Residual' in jetCorrections[1]: ### think of a more accurate warning print '#################################################' print 'WARNING! Not using L2L3Residual but this is data.' print 'If this is okay with you, disregard this message.' print '#################################################' switchToPFJets( process, cms.InputTag('pfNoTauClones'+postfix), jetAlgo, postfix=postfix, jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules ) # Taus #adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix ) #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix ) adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix ) # MET switchToPFMET(process, cms.InputTag('pfMET'+postfix), type1=typeIMetCorrections, postfix=postfix) # Unmasked PFCandidates addPFCandidates(process,cms.InputTag('pfNoJetClones'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix) # adapt primary vertex collection adaptPVs(process, pvCollection=pvCollection, postfix=postfix) if not runOnMC: runOnData(process,postfix=postfix,outputModules=outputModules) # Configure Top Projections getattr(process,"pfNoPileUpJME"+postfix).enable = True getattr(process,"pfNoMuonJME"+postfix).enable = True getattr(process,"pfNoElectronJME"+postfix).enable = True getattr(process,"pfNoTau"+postfix).enable = False getattr(process,"pfNoJet"+postfix).enable = True exclusionList = '' for object in excludeFromTopProjection: jme = '' if object in ['Muon','Electron']: jme = 'JME' getattr(process,"pfNo"+object+jme+postfix).enable = False exclusionList=exclusionList+object+',' exclusionList=exclusionList.rstrip(',') print "Done: PF2PAT interfaced to PAT, postfix=", postfix,", Excluded from Top Projection:",exclusionList
def applyFilter(sample, process, postfix): applyPostfix(process, "GenZmassFilter", postfix).applyFilter = False applyPostfix(process, "topDecayGenFilter", postfix).applyFilter = False if sample.find("Run") != -1: applyPostfix(process, "JetEnergyScale", postfix).globalTag = cms.untracked.string('GR_R_52_V9') applyPostfix(process, "JetEnergyScale", postfix).doResJec = cms.untracked.bool(True) applyJSON(process, json) else: applyPostfix(process, "JetEnergyScale", postfix).globalTag = cms.untracked.string('START52_V11') applyPostfix(process, "JetEnergyScale", postfix).doResJec = cms.untracked.bool(False) if sample.find("ZJets") != -1 or sample.find("ZtauDecay") != -1: applyPostfix(process, "GenZmassFilter", postfix).applyFilter = True if sample.find("tau") != -1: applyPostfix(process, "GenZmassFilter", postfix).decayMode = [15] else: applyPostfix(process, "GenZmassFilter", postfix).decayMode = [11, 13] if sample.find("TTbar") != -1: process.topWLeptonGenFilter.applyFilter = True applyPostfix(process, "topDecayGenFilter", postfix).applyFilter = True if sample.find("Others") != -1: process.p.replace( applyPostfix(process, "topDecayGenFilter", postfix), ~applyPostfix(process, "topDecayGenFilter", postfix)) process.p2.replace( applyPostfix(process, "topDecayGenFilter", postfix), ~applyPostfix(process, "topDecayGenFilter", postfix)) process.p3.replace( applyPostfix(process, "topDecayGenFilter", postfix), ~applyPostfix(process, "topDecayGenFilter", postfix))
def switchToPFJets(process, input=cms.InputTag('pfNoTau'), algo='AK5', postfix="", jetCorrections=('AK5PFchs', ['L1FastJet', 'L2Relative', 'L3Absolute']), type1=False, outputModules=['out']): print "Switching to PFJets, ", algo print "************************ " print "input collection: ", input if (algo == 'IC5'): genJetCollection = cms.InputTag('iterativeCone5GenJetsNoNu') elif algo == 'AK5': genJetCollection = cms.InputTag('ak5GenJetsNoNu') elif algo == 'AK7': genJetCollection = cms.InputTag('ak7GenJetsNoNu') else: print 'bad jet algorithm:', algo, '! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin' sys.exit(1) # changing the jet collection in PF2PAT: from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo inputCollection = getattr(process, "pfJets" + postfix).src setattr(process, "pfJets" + postfix, jetAlgo(algo)) # problem for cfgBrowser getattr(process, "pfJets" + postfix).src = inputCollection inputJetCorrLabel = jetCorrections switchJetCollection(process, input, jetIdLabel=algo, doJTA=True, doBTagging=True, jetCorrLabel=inputJetCorrLabel, doType1MET=type1, genJetCollection=genJetCollection, doJetID=True, postfix=postfix, outputModules=outputModules) # check whether L1FastJet is in the list of correction levels or not applyPostfix(process, "patJetCorrFactors", postfix).useRho = False for corr in inputJetCorrLabel[1]: if corr == 'L1FastJet': applyPostfix(process, "patJetCorrFactors", postfix).useRho = True applyPostfix(process, "pfJets", postfix).doAreaFastjet = True # do correct treatment for TypeI MET corrections if type1: for mod in getattr(process, 'patPF2PATSequence' + postfix).moduleNames(): if mod.startswith("kt6") and mod.endswith("Jets" + postfix): prefix = mod.replace(postfix, '') prefix = prefix.replace('kt6PFJets', '') prefix = prefix.replace('kt6CaloJets', '') prefix = getattr( process, 'patJetCorrFactors' + prefix + postfix).payload.pythonValue().replace("'", "") for essource in process.es_sources_().keys(): if essource == prefix + 'L1FastJet': setattr( process, essource + postfix, getattr(process, essource).clone( srcRho=cms.InputTag(mod, 'rho'))) setattr( process, prefix + 'CombinedCorrector' + postfix, getattr(process, prefix + 'CombinedCorrector').clone()) getattr( process, prefix + 'CorMet' + postfix ).corrector = prefix + 'CombinedCorrector' + postfix for cor in getattr( process, prefix + 'CombinedCorrector' + postfix).correctors: if cor == essource: idx = getattr( process, prefix + 'CombinedCorrector' + postfix).correctors.index(essource) getattr( process, prefix + 'CombinedCorrector' + postfix ).correctors[idx] = essource + postfix applyPostfix(process, "patJets", postfix).embedCaloTowers = False applyPostfix(process, "patJets", postfix).embedPFCandidates = True
def switchToPFJets(process, input=cms.InputTag('pfNoTauClones'), algo='AK4', postfix = "", jetCorrections=('AK4PFchs', ['L1FastJet','L2Relative', 'L3Absolute']), type1=False, outputModules=['out']): print "Switching to PFJets, ", algo print "************************ " print "input collection: ", input if algo == 'AK4': genJetCollection = cms.InputTag('ak4GenJetsNoNu'+postfix) rParam=0.4 elif algo == 'AK7': genJetCollection = cms.InputTag('ak7GenJetsNoNu'+postfix) rParam=0.7 else: print 'bad jet algorithm:', algo, '! for now, only AK4 and AK7 are allowed. If you need other algorithms, please contact Colin' sys.exit(1) # changing the jet collection in PF2PAT: from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo inputCollection = getattr(process,"pfJets"+postfix).src setattr(process,"pfJets"+postfix,jetAlgo(algo)) # problem for cfgBrowser getattr(process,"pfJets"+postfix).src = inputCollection inputJetCorrLabel=jetCorrections switchJetCollection(process, jetSource = input, algo=algo, rParam=rParam, genJetCollection=genJetCollection, postfix=postfix, jetTrackAssociation=True, jetCorrections=inputJetCorrLabel, outputModules = outputModules, ) # check whether L1FastJet is in the list of correction levels or not applyPostfix(process, "patJetCorrFactors", postfix).useRho = False for corr in inputJetCorrLabel[1]: if corr == 'L1FastJet': applyPostfix(process, "patJetCorrFactors", postfix).useRho = True applyPostfix(process, "pfJets", postfix).doAreaFastjet = True # do correct treatment for TypeI MET corrections #type1=True if type1: for mod in process.producerNames().split(' '): if mod.startswith("kt6") and mod.endswith("Jets"+postfix) and not 'GenJets' in mod: prefix = mod.replace(postfix,'') prefix = prefix.replace('kt6PFJets','') prefix = prefix.replace('kt6CaloJets','') prefix = getattr(process,'patJetCorrFactors'+prefix+postfix).payload.pythonValue().replace("'","") for essource in process.es_sources_().keys(): if essource == prefix+'L1FastJet': setattr(process,essource+postfix,getattr(process,essource).clone(srcRho=cms.InputTag(mod,'rho'))) setattr(process,prefix+'CombinedCorrector'+postfix,getattr(process,prefix+'CombinedCorrector').clone()) getattr(process,prefix+'CorMet'+postfix).corrector = prefix+'CombinedCorrector'+postfix for cor in getattr(process,prefix+'CombinedCorrector'+postfix).correctors: if cor == essource: idx = getattr(process,prefix+'CombinedCorrector'+postfix).correctors.index(essource); getattr(process,prefix+'CombinedCorrector'+postfix).correctors[idx] = essource+postfix if hasattr( getattr( process, "patJets" + postfix), 'embedCaloTowers' ): # optional parameter, which defaults to 'False' anyway applyPostfix(process, "patJets", postfix).embedCaloTowers = False applyPostfix(process, "patJets", postfix).embedPFCandidates = True
def _switchToPFTau(process, pfTauLabelOld, pfTauLabelNew, pfTauType, idSources, jecLevels, jecPayloadMapping, patTauLabel="", postfix=""): """internal auxiliary function to switch to **any** PFTau collection""" print ' Taus: ', pfTauLabelOld, '->', pfTauLabelNew applyPostfix(process, "tauMatch" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauGenJetMatch" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFCandidates" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFCandidates" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFGammas" + patTauLabel, postfix).src = pfTauLabelNew applyPostfix(process, "tauIsoDepositPFGammas" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew # applyPostfix(process, "patTauJetCorrFactors" + patTauLabel, postfix).src = pfTauLabelNew # if len(jecLevels) > 0: # applyPostfix(process, "patTaus" + patTauLabel, postfix).addTauJetCorrFactors = cms.bool(True) # applyPostfix(process, "patTauJetCorrFactors" + patTauLabel, postfix).parameters = jecPayloadMapping # else: # applyPostfix(process, "patTaus" + patTauLabel, postfix).addTauJetCorrFactors = cms.bool(False) UpdateDiscriminators = True try: from RecoTauTag.Configuration.updateHPSPFTaus_cff import updateHPSPFTaus except ImportError: UpdateDiscriminators = False if UpdateDiscriminators: idSources += [ ("byIsolationMVAraw", "DiscriminationByIsolationMVAraw"), ("byLooseIsolationMVA", "DiscriminationByLooseIsolationMVA"), ("byMediumIsolationMVA", "DiscriminationByMediumIsolationMVA"), ("byTightIsolationMVA", "DiscriminationByTightIsolationMVA"), ("byIsolationMVA2raw", "DiscriminationByIsolationMVA2raw"), ("byLooseIsolationMVA2", "DiscriminationByLooseIsolationMVA2"), ("byMediumIsolationMVA2", "DiscriminationByMediumIsolationMVA2"), ("byTightIsolationMVA2", "DiscriminationByTightIsolationMVA2"), # ("againstElectronMVA2raw", "DiscriminationByMVA2rawElectronRejection"), # ("againstElectronMVA2category", "DiscriminationByMVA2rawElectronRejection:category"), # ("againstElectronVLooseMVA2", "DiscriminationByMVA2VLooseElectronRejection"), # ("againstElectronLooseMVA2", "DiscriminationByMVA2LooseElectronRejection"), # ("againstElectronMediumMVA2", "DiscriminationByMVA2MediumElectronRejection"), # ("againstElectronTightMVA2", "DiscriminationByMVA2TightElectronRejection"), ("byLooseCombinedIsolationDeltaBetaCorr3Hits", "DiscriminationByLooseCombinedIsolationDBSumPtCorr3Hits"), ("byMediumCombinedIsolationDeltaBetaCorr3Hits", "DiscriminationByMediumCombinedIsolationDBSumPtCorr3Hits"), ("byTightCombinedIsolationDeltaBetaCorr3Hits", "DiscriminationByTightCombinedIsolationDBSumPtCorr3Hits"), ("byCombinedIsolationDeltaBetaCorrRaw3Hits", "DiscriminationByRawCombinedIsolationDBSumPtCorr3Hits"), ("againstElectronMVA3raw", "DiscriminationByMVA3rawElectronRejection"), ("againstElectronMVA3category", "DiscriminationByMVA3rawElectronRejection:category"), ("againstElectronLooseMVA3", "DiscriminationByMVA3LooseElectronRejection"), ("againstElectronMediumMVA3", "DiscriminationByMVA3MediumElectronRejection"), ("againstElectronTightMVA3", "DiscriminationByMVA3TightElectronRejection"), ("againstElectronVTightMVA3", "DiscriminationByMVA3VTightElectronRejection"), ("againstElectronDeadECAL", "DiscriminationByDeadECALElectronRejection"), ("againstMuonLoose2", "DiscriminationByLooseMuonRejection2"), ("againstMuonMedium2", "DiscriminationByMediumMuonRejection2"), ("againstMuonTight2", "DiscriminationByTightMuonRejection2"), ("againstMuonLoose3", "DiscriminationByLooseMuonRejection3"), ("againstMuonTight3", "DiscriminationByTightMuonRejection3") ] applyPostfix(process, "patTaus" + patTauLabel, postfix).tauSource = pfTauLabelNew applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = _buildIDSourcePSet( pfTauType, idSources, postfix) if hasattr(process, "cleanPatTaus" + patTauLabel + postfix): getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = \ 'tauID("leadingTrackFinding") > 0.5 & tauID("leadingPionPtCut") > 0.5 & tauID("byIsolationUsingLeadingPion") > 0.5' \ + ' & tauID("againstMuon") > 0.5 & tauID("againstElectron") > 0.5' \ + ' & (signalPFChargedHadrCands.size() = 1 | signalPFChargedHadrCands.size() = 3)'
def tauTypeInPF2PAT(process,tauType='shrinkingConePFTau', postfix = ""): process.load("CommonTools.ParticleFlow.pfTaus_cff") applyPostfix(process, "pfTaus",postfix).src = cms.InputTag(tauType+'Producer'+postfix)
def usePF2PAT(process, runPF2PAT=True, jetAlgo='AK4', runOnMC=True, postfix="", jetCorrections=('AK4PFchs', ['L1FastJet', 'L2Relative', 'L3Absolute'], 'None'), pvCollection=cms.InputTag('goodOfflinePrimaryVerticesPFlow', ), typeIMetCorrections=False, outputModules=['out'], excludeFromTopProjection=['Tau']): # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT. # CREATE ADDITIONAL FUNCTIONS IF NEEDED. if typeIMetCorrections: jetCorrections = (jetCorrections[0], jetCorrections[1], 'Type-1') """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence""" # -------- CORE --------------- from PhysicsTools.PatAlgos.tools.helpers import loadWithPostfix patAlgosToolsTask = getPatAlgosToolsTask(process) taskLabel = patAlgosToolsTask.label() if runPF2PAT: loadWithPostfix(process, 'PhysicsTools.PatAlgos.patSequences_cff', postfix, loadedProducersAndFilters=taskLabel) loadWithPostfix(process, "CommonTools.ParticleFlow.PFBRECO_cff", postfix, loadedProducersAndFilters=taskLabel) else: loadWithPostfix(process, 'PhysicsTools.PatAlgos.patSequences_cff', postfix, loadedProducersAndFilters=taskLabel) # -------- OBJECTS ------------ # Muons adaptPFMuons(process, applyPostfix(process, "patMuons", postfix), postfix) # Electrons adaptPFElectrons(process, applyPostfix(process, "patElectrons", postfix), postfix) # Photons #print "Temporarily switching off photons completely" #removeSpecificPATObjects(process,names=['Photons'],outputModules=outputModules,postfix=postfix) # Jets if runOnMC: switchToPFJets(process, cms.InputTag('pfNoTauClonesPFBRECO' + postfix), jetAlgo, postfix=postfix, jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules) else: if not 'L2L3Residual' in jetCorrections[1]: ### think of a more accurate warning print '#################################################' print 'WARNING! Not using L2L3Residual but this is data.' print 'If this is okay with you, disregard this message.' print '#################################################' switchToPFJets(process, cms.InputTag('pfNoTauClonesPFBRECO' + postfix), jetAlgo, postfix=postfix, jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules) # Taus #adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix ) #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix ) adaptPFTaus(process, tauType='hpsPFTau', postfix=postfix) # MET switchToPFMET(process, cms.InputTag('pfMETPFBRECO' + postfix), type1=typeIMetCorrections, postfix=postfix) # Unmasked PFCandidates addPFCandidates(process, cms.InputTag('pfNoJetClones' + postfix), patLabel='PFParticles' + postfix, cut="", postfix=postfix) # adapt primary vertex collection adaptPVs(process, pvCollection=pvCollection, postfix=postfix) if not runOnMC: runOnData(process, postfix=postfix, outputModules=outputModules) # Configure Top Projections getattr(process, "pfNoPileUpJME" + postfix).enable = True getattr(process, "pfNoMuonJMEPFBRECO" + postfix).enable = True getattr(process, "pfNoElectronJMEPFBRECO" + postfix).enable = True getattr(process, "pfNoTauPFBRECO" + postfix).enable = False getattr(process, "pfNoJetPFBRECO" + postfix).enable = True exclusionList = '' for object in excludeFromTopProjection: jme = '' if object in ['Muon', 'Electron']: jme = 'JME' getattr(process, "pfNo" + object + jme + 'PFBRECO' + postfix).enable = False exclusionList = exclusionList + object + ',' exclusionList = exclusionList.rstrip(',') print "Done: PFBRECO interfaced to PAT, postfix=", postfix, ", Excluded from Top Projection:", exclusionList
def reconfigurePF2PATTaus( process, tauType='shrinkingConePFTau', pf2patSelection=[ "DiscriminationByIsolation", "DiscriminationByLeadingPionPtCut" ], selectionDependsOn=["DiscriminationByLeadingTrackFinding"], producerFromType=lambda producer: producer + "Producer", postfix=""): print "patTaus will be produced from taus of type: %s that pass %s" \ % (tauType, pf2patSelection) # Get the prototype of tau producer to make, i.e. fixedConePFTauProducer producerName = producerFromType(tauType) # Set as the source for the pf2pat taus (pfTaus) selector applyPostfix(process, "pfTaus", postfix).src = producerName + postfix # Start our pf2pat taus base sequence oldTauSansRefs = getattr(process, 'pfTausProducerSansRefs' + postfix) oldTau = getattr(process, 'pfTausProducer' + postfix) ## copy tau and setup it properly newTauSansRefs = None newTau = getattr(process, producerName + postfix).clone() ## adapted to new structure in RecoTauProducers PLEASE CHECK!!! if tauType == 'shrinkingConePFTau': newTauSansRefs = getattr(process, producerName + "SansRefs").clone() newTauSansRefs.modifiers[1] = cms.PSet( pfTauTagInfoSrc=cms.InputTag("pfTauTagInfoProducer" + postfix), name=cms.string('pfTauTTIworkaround' + postfix), plugin=cms.string('RecoTauTagInfoWorkaroundModifer')) newTau.modifiers[1] = newTauSansRefs.modifiers[1] newTauSansRefs.piZeroSrc = "pfJetsLegacyTaNCPiZeros" + postfix newTau.piZeroSrc = newTauSansRefs.piZeroSrc newTauSansRefs.builders[0].pfCandSrc = oldTauSansRefs.builders[ 0].pfCandSrc newTauSansRefs.jetRegionSrc = oldTauSansRefs.jetRegionSrc newTauSansRefs.jetSrc = oldTauSansRefs.jetSrc elif tauType == 'fixedConePFTau': newTau.piZeroSrc = "pfJetsLegacyTaNCPiZeros" + postfix elif tauType == 'hpsPFTau': newTau = getattr(process, 'combinatoricRecoTaus' + postfix).clone() newTau.piZeroSrc = "pfJetsLegacyHPSPiZeros" + postfix newTau.modifiers[3] = cms.PSet( pfTauTagInfoSrc=cms.InputTag("pfTauTagInfoProducer" + postfix), name=cms.string('pfTauTTIworkaround' + postfix), plugin=cms.string('RecoTauTagInfoWorkaroundModifer')) from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet #cloneProcessingSnippet(process, process.produceHPSPFTaus, postfix, addToTask = True) setattr( process, 'produceHPSPFTaus' + postfix, cms.Sequence( applyPostfix(process, 'hpsSelectionDiscriminator', postfix) + applyPostfix(process, 'hpsPFTauProducerSansRefs', postfix) + applyPostfix(process, 'hpsPFTauProducer', postfix))) massSearchReplaceParam(getattr(process, "produceHPSPFTaus" + postfix), "PFTauProducer", cms.InputTag("combinatoricRecoTaus" + postfix), cms.InputTag("pfTausBase" + postfix)) massSearchReplaceParam(getattr(process, "produceHPSPFTaus" + postfix), "src", cms.InputTag("combinatoricRecoTaus" + postfix), cms.InputTag("pfTausBase" + postfix)) ### Next three lines crash, oldTau does not have any of these attributes. Why?### #newTau.builders[0].pfCandSrc = oldTau.builders[0].pfCandSrc #newTau.jetRegionSrc = oldTau.jetRegionSrc #newTau.jetSrc = oldTau.jetSrc #newTau.builders[0].pfCandSrc = cms.InputTag("pfNoElectronJME" + postfix) #newTau.jetRegionSrc = cms.InputTag("pfTauPFJets08Region" + postfix) #newTau.jetSrc = cms.InputTag("pfJetsPFBRECO" + postfix) # replace old tau producer by new one put it into baseSequence task = getPatAlgosToolsTask(process) addToProcessAndTask("pfTausBase" + postfix, newTau, process, task) if tauType == 'shrinkingConePFTau': addToProcessAndTask("pfTausBaseSansRefs" + postfix, newTauSansRefs, process, task) getattr(process, "pfTausBase" + postfix).src = "pfTausBaseSansRefs" + postfix baseSequence += getattr(process, "pfTausBaseSansRefs" + postfix) #make custom mapper to take postfix into account (could have gone with lambda of lambda but... ) def producerIsTauTypeMapperWithPostfix(tauProducer): return lambda x: producerIsTauTypeMapper(tauProducer) + x.group( 1) + postfix def recoTauTypeMapperWithGroup(tauProducer): return "%s(.*)" % recoTauTypeMapper(tauProducer) # Get our prediscriminants for predisc in selectionDependsOn: # Get the prototype originalName = tauType + predisc # i.e. fixedConePFTauProducerDiscriminationByLeadingTrackFinding clonedName = "pfTausBase" + predisc + postfix clonedDisc = getattr(process, originalName).clone() addToProcessAndTask(clonedName, clonedDisc, process, task) tauCollectionToSelect = None if tauType != 'hpsPFTau': tauCollectionToSelect = "pfTausBase" + postfix #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix) else: tauCollectionToSelect = "hpsPFTauProducer" + postfix # Adapt this discriminator for the cloned prediscriminators adaptTauDiscriminator( clonedDisc, newTauProducer="pfTausBase", oldTauTypeMapper=recoTauTypeMapperWithGroup, newTauTypeMapper=producerIsTauTypeMapperWithPostfix, preservePFTauProducer=True) clonedDisc.PFTauProducer = tauCollectionToSelect # Reconfigure the pf2pat PFTau selector discrimination sources getattr(process, "pfTaus" + postfix).discriminators = cms.VPSet() for selection in pf2patSelection: # Get our discriminator that will be used to select pfTaus originalName = tauType + selection clonedName = "pfTausBase" + selection + postfix clonedDisc = getattr(process, originalName).clone() addToProcessAndTask(clonedName, clonedDisc, process, task) tauCollectionToSelect = None if tauType != 'hpsPFTau': tauCollectionToSelect = cms.InputTag("pfTausBase" + postfix) #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix) else: tauCollectionToSelect = cms.InputTag("hpsPFTauProducer" + postfix) #Adapt our cloned discriminator to the new prediscriminants adaptTauDiscriminator( clonedDisc, newTauProducer="pfTausBase", oldTauTypeMapper=recoTauTypeMapperWithGroup, newTauTypeMapper=producerIsTauTypeMapperWithPostfix, preservePFTauProducer=True) clonedDisc.PFTauProducer = tauCollectionToSelect # Add this selection to our pfTau selectors getattr(process, "pfTaus" + postfix).discriminators.append( cms.PSet(discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5))) # Set the input of the final selector. if tauType != 'hpsPFTau': getattr(process, "pfTaus" + postfix).src = "pfTausBase" + postfix else: # If we are using HPS taus, we need to take the output of the clenaed # collection getattr(process, "pfTaus" + postfix).src = "hpsPFTauProducer" + postfix
def switchToPFJets(process, input=cms.InputTag('pfNoTauClones'), algo='AK4', postfix="", jetCorrections=('AK4PFchs', ['L1FastJet', 'L2Relative', 'L3Absolute']), type1=False, outputModules=['out']): print "Switching to PFJets, ", algo print "************************ " print "input collection: ", input if algo == 'AK4': genJetCollection = cms.InputTag('ak4GenJetsNoNu' + postfix) rParam = 0.4 elif algo == 'AK7': genJetCollection = cms.InputTag('ak7GenJetsNoNu' + postfix) rParam = 0.7 else: print 'bad jet algorithm:', algo, '! for now, only AK4 and AK7 are allowed. If you need other algorithms, please contact Colin' sys.exit(1) # changing the jet collection in PF2PAT: from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo inputCollection = getattr(process, "pfJetsPFBRECO" + postfix).src setattr(process, "pfJetsPFBRECO" + postfix, jetAlgo(algo)) # problem for cfgBrowser getattr(process, "pfJetsPFBRECO" + postfix).src = inputCollection inputJetCorrLabel = jetCorrections switchJetCollection( process, jetSource=input, algo=algo, rParam=rParam, genJetCollection=genJetCollection, postfix=postfix, jetTrackAssociation=True, jetCorrections=inputJetCorrLabel, outputModules=outputModules, ) # check whether L1FastJet is in the list of correction levels or not applyPostfix(process, "patJetCorrFactors", postfix).useRho = False task = getPatAlgosToolsTask(process) for corr in inputJetCorrLabel[1]: if corr == 'L1FastJet': applyPostfix(process, "patJetCorrFactors", postfix).useRho = True applyPostfix(process, "pfJetsPFBRECO", postfix).doAreaFastjet = True # do correct treatment for TypeI MET corrections #type1=True if type1: for mod in process.producerNames().split(' '): if mod.startswith("kt6") and mod.endswith( "Jets" + postfix) and not 'GenJets' in mod: prefix = mod.replace(postfix, '') prefix = prefix.replace('kt6PFJets', '') prefix = prefix.replace('kt6CaloJets', '') prefix = getattr( process, 'patJetCorrFactors' + prefix + postfix).payload.pythonValue().replace("'", "") for essource in process.es_sources_().keys(): if essource == prefix + 'L1FastJet': setattr( process, essource + postfix, getattr(process, essource).clone( srcRho=cms.InputTag(mod, 'rho'))) addToProcessAndTask( prefix + 'CombinedCorrector' + postfix, getattr(process, prefix + 'CombinedCorrector').clone(), process, task) getattr( process, prefix + 'CorMet' + postfix ).corrector = prefix + 'CombinedCorrector' + postfix for cor in getattr( process, prefix + 'CombinedCorrector' + postfix).correctors: if cor == essource: idx = getattr( process, prefix + 'CombinedCorrector' + postfix).correctors.index(essource) getattr( process, prefix + 'CombinedCorrector' + postfix ).correctors[idx] = essource + postfix if hasattr(getattr(process, "patJets" + postfix), 'embedCaloTowers' ): # optional parameter, which defaults to 'False' anyway applyPostfix(process, "patJets", postfix).embedCaloTowers = False applyPostfix(process, "patJets", postfix).embedPFCandidates = True
def tauTypeInPF2PAT(process, tauType='shrinkingConePFTau', postfix=""): process.load("CommonTools.ParticleFlow.pfTaus_cff") applyPostfix(process, "pfTaus", postfix).src = cms.InputTag(tauType + 'Producer' + postfix)
def switchToPFMET(process, input=cms.InputTag('pfMET'), type1=False, postfix=""): print 'MET: using ', input if (not type1): oldMETSource = applyPostfix(process, "patMETs", postfix).metSource applyPostfix(process, "patMETs", postfix).metSource = input applyPostfix(process, "patMETs", postfix).addMuonCorrections = False getattr(process, "patDefaultSequence" + postfix).remove( applyPostfix(process, "patMETCorrections", postfix)) else: # type1 corrected MET # name of corrected MET hardcoded in PAT and meaningless print 'Apply TypeI corrections for MET' getattr(process, "patDefaultSequence" + postfix).remove( applyPostfix(process, "makePatMETs", postfix)) jecLabel = getattr(process, 'patJetCorrFactors' + postfix).levels if not hasattr(process, 'producePatPFMETCorrections'): process.load("PhysicsTools.PatUtils.patPFMETCorrections_cff") #here add to the current path and give proper postfix if not hasattr(process, 'producePatPFMETCorrections' + postfix): cloneProcessingSnippet(process, process.producePatPFMETCorrections, postfix) getattr(process, 'patPFMet' + postfix).metSource = cms.InputTag('pfMET' + postfix) getattr(process, 'selectedPatJetsForMETtype1p2Corr' + postfix).src = cms.InputTag('selectedPatJets' + postfix) getattr(process, 'selectedPatJetsForMETtype2Corr' + postfix).src = cms.InputTag('selectedPatJets' + postfix) getattr(process, 'pfCandMETcorr' + postfix).src = cms.InputTag('pfNoJet' + postfix) getattr(process, 'patPFJetMETtype1p2Corr' + postfix).offsetCorrLabel = cms.string(jecLabel[0]) getattr(process, 'patPFJetMETtype1p2Corr' + postfix).jetCorrLabel = cms.string(jecLabel[-1]) getattr(process, 'patPFJetMETtype1p2Corr' + postfix).type1JetPtThreshold = cms.double(10.0) getattr(process, 'patPFJetMETtype1p2Corr' + postfix).skipEM = cms.bool(False) getattr(process, 'patPFJetMETtype1p2Corr' + postfix).skipMuons = cms.bool(False) getattr(process, 'patPFJetMETtype2Corr' + postfix).offsetCorrLabel = cms.string(jecLabel[0]) getattr(process, 'patPFJetMETtype2Corr' + postfix).jetCorrLabel = cms.string(jecLabel[-1]) getattr(process, 'patPFJetMETtype2Corr' + postfix).type1JetPtThreshold = cms.double(10.0) getattr(process, 'patPFJetMETtype2Corr' + postfix).skipEM = cms.bool(False) getattr(process, 'patPFJetMETtype2Corr' + postfix).skipMuons = cms.bool(False) getattr(process, 'patType1CorrectedPFMet' + postfix).srcType1Corrections = cms.VInputTag( cms.InputTag("patPFJetMETtype1p2Corr" + postfix, "type1"), #cms.InputTag("patPFMETtype0Corr"+postfix), ) getattr(process, 'patType1p2CorrectedPFMet' + postfix).srcType1Corrections = cms.VInputTag( cms.InputTag("patPFJetMETtype1p2Corr" + postfix, "type1"), #cms.InputTag("patPFMETtype0Corr"+postfix), ) getattr(process, 'patMETs' + postfix).metSource = 'patType1CorrectedPFMet' + postfix getattr(process, "patDefaultSequence" + postfix).replace( getattr(process, 'selectedPatJets' + postfix), getattr(process, 'selectedPatJets' + postfix) * getattr(process, 'producePatPFMETCorrections' + postfix) * getattr(process, 'patMETs' + postfix))
def redoPFTauDiscriminators(process, oldPFTauLabel = cms.InputTag('shrinkingConePFTauProducer'), newPFTauLabel = cms.InputTag('shrinkingConePFTauProducer'), tauType = 'shrinkingConePFTau', postfix = ""): print 'Tau discriminators: ', oldPFTauLabel, '->', newPFTauLabel print 'Tau type: ', tauType #oldPFTauLabel.setModuleLabel(oldPFTauLabel.getModuleLabel()+postfix) tauSrc = 'PFTauProducer' tauDiscriminationSequence = None if tauType == 'hpsPFTau': process.patHPSPFTauDiscrimination = process.produceAndDiscriminateHPSPFTaus.copy() # remove producers for iname in process.patHPSPFTauDiscrimination.moduleNames(): if not (iname.find("DiscriminationBy")>-1 or iname.find("DiscriminationAgainst")>-1): process.patHPSPFTauDiscrimination.remove(getattr(process,iname) ) tauDiscriminationSequence = cloneProcessingSnippet(process, process.patHPSPFTauDiscrimination, postfix) elif tauType == 'hpsTancTaus': #to be checked if correct process.patHPSTaNCPFTauDiscrimination = process.hpsTancTauInitialSequence.copy() process.patHPSTaNCPFTauDiscrimination *= process.hpsTancTauDiscriminantSequence # remove producers for iname in process.patHPSTaNCPFTauDiscrimination.moduleNames(): if not (iname.find("DiscriminationBy")>-1 or iname.find("DiscriminationAgainst")>-1): process.patHPSTaNCPFTauDiscrimination.remove(getattr(process,iname) ) tauDiscriminationSequence = cloneProcessingSnippet(process, process.patHPSTaNCPFTauDiscrimination, postfix) elif tauType == 'fixedConePFTau': process.patFixedConePFTauDiscrimination = process.produceAndDiscriminateFixedConePFTaus.copy() # remove producers for iname in process.patFixedConePFTauDiscrimination.moduleNames(): if not (iname.find("DiscriminationBy")>-1 or iname.find("DiscriminationAgainst")>-1): process.patFixedConePFTauDiscrimination.remove(getattr(process,iname) ) tauDiscriminationSequence = cloneProcessingSnippet(process, process.patFixedConePFTauDiscrimination, postfix) elif tauType == 'shrinkingConePFTau': #shr cone with TaNC process.patShrinkingConePFTauDiscrimination = process.produceAndDiscriminateShrinkingConePFTaus.copy() process.patShrinkingConePFTauDiscrimination *= process.produceShrinkingConeDiscriminationByTauNeuralClassifier # remove producers for iname in process.patShrinkingConePFTauDiscrimination.moduleNames(): if not (iname.find("DiscriminationBy")>-1 or iname.find("DiscriminationAgainst")>-1): process.patShrinkingConePFTauDiscrimination.remove(getattr(process,iname) ) tauDiscriminationSequence = cloneProcessingSnippet(process, process.patShrinkingConePFTauDiscrimination, postfix) elif tauType == 'caloTau': # fill calo sequence by discriminants process.patCaloTauDiscrimination = process.tautagging.copy() # remove producers for iname in process.patCaloTauDiscrimination.moduleNames(): if not (iname.find("DiscriminationBy")>-1 or iname.find("DiscriminationAgainst")>-1): process.patCaloTauDiscrimination.remove(getattr(process,iname) ) tauDiscriminationSequence = cloneProcessingSnippet(process, process.patCaloTauDiscrimination, postfix) tauSrc = 'CaloTauProducer' else: raise StandardError, "Unkown tauType: '%s'"%tauType applyPostfix(process,"patDefaultSequence",postfix).replace( applyPostfix(process,"patTaus",postfix), tauDiscriminationSequence*applyPostfix(process,"patTaus",postfix) ) massSearchReplaceParam(tauDiscriminationSequence, tauSrc, oldPFTauLabel, newPFTauLabel)
def reconfigurePF2PATTaus( process, tauType='shrinkingConePFTau', pf2patSelection=[ "DiscriminationByIsolation", "DiscriminationByLeadingPionPtCut" ], selectionDependsOn=["DiscriminationByLeadingTrackFinding"], producerFromType=lambda producer: producer + "Producer", postfix=""): print "patTaus will be produced from taus of type: %s that pass %s" \ % (tauType, pf2patSelection) #get baseSequence baseSequence = getattr(process, "pfTausBaseSequence" + postfix) #clean baseSequence from old modules for oldBaseModuleName in baseSequence.moduleNames(): oldBaseModule = getattr(process, oldBaseModuleName) baseSequence.remove(oldBaseModule) # Get the prototype of tau producer to make, i.e. fixedConePFTauProducer producerName = producerFromType(tauType) # Set as the source for the pf2pat taus (pfTaus) selector applyPostfix(process, "pfTaus", postfix).src = producerName + postfix # Start our pf2pat taus base sequence oldTau = getattr(process, 'pfTausProducer' + postfix) ## copy tau and setup it properly newTau = getattr(process, producerName).clone() ## adapted to new structure in RecoTauProducers PLEASE CHECK!!! if tauType == 'shrinkingConePFTau': #Only shrCone tau has modifiers??? # like this, it should have it already definied?? newTau.modifiers[1] = cms.PSet( pfTauTagInfoSrc=cms.InputTag("pfTauTagInfoProducer" + postfix), name=cms.string('pfTauTTIworkaround' + postfix), plugin=cms.string('RecoTauTagInfoWorkaroundModifer')) newTau.piZeroSrc = "pfJetsLegacyTaNCPiZeros" + postfix elif tauType == 'fixedConePFTau': newTau.piZeroSrc = "pfJetsPiZeros" + postfix elif tauType == 'hpsPFTau': newTau = process.combinatoricRecoTaus.clone() newTau.piZeroSrc = "pfJetsLegacyHPSPiZeros" + postfix newTau.modifiers[2] = cms.PSet( pfTauTagInfoSrc=cms.InputTag("pfTauTagInfoProducer" + postfix), name=cms.string('pfTauTTIworkaround' + postfix), plugin=cms.string('RecoTauTagInfoWorkaroundModifer')) from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet cloneProcessingSnippet(process, process.produceHPSPFTaus, postfix) massSearchReplaceParam(getattr(process, "produceHPSPFTaus" + postfix), "PFTauProducer", cms.InputTag("combinatoricRecoTaus"), cms.InputTag("pfTausBase" + postfix)) getattr(process, "hpsPFTauProducer" + postfix).src = "pfTausBase" + postfix newTau.builders[0].pfCandSrc = oldTau.builders[0].pfCandSrc newTau.jetRegionSrc = oldTau.jetRegionSrc newTau.jetSrc = oldTau.jetSrc # replace old tau producer by new one put it into baseSequence setattr(process, "pfTausBase" + postfix, newTau) baseSequence += getattr(process, "pfTausBase" + postfix) if tauType == 'hpsPFTau': baseSequence += getattr(process, "produceHPSPFTaus" + postfix) #make custom mapper to take postfix into account (could have gone with lambda of lambda but... ) def producerIsTauTypeMapperWithPostfix(tauProducer): return lambda x: producerIsTauTypeMapper(tauProducer) + x.group( 1) + postfix def recoTauTypeMapperWithGroup(tauProducer): return "%s(.*)" % recoTauTypeMapper(tauProducer) # Get our prediscriminants for predisc in selectionDependsOn: # Get the prototype originalName = tauType + predisc # i.e. fixedConePFTauProducerDiscriminationByLeadingTrackFinding clonedName = "pfTausBase" + predisc + postfix clonedDisc = getattr(process, originalName).clone() # Register in our process setattr(process, clonedName, clonedDisc) baseSequence += getattr(process, clonedName) tauCollectionToSelect = None if tauType != 'hpsPFTau': tauCollectionToSelect = "pfTausBase" + postfix #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix) else: tauCollectionToSelect = "hpsPFTauProducer" + postfix # Adapt this discriminator for the cloned prediscriminators adaptTauDiscriminator( clonedDisc, newTauProducer="pfTausBase", oldTauTypeMapper=recoTauTypeMapperWithGroup, newTauTypeMapper=producerIsTauTypeMapperWithPostfix, preservePFTauProducer=True) clonedDisc.PFTauProducer = tauCollectionToSelect # Reconfigure the pf2pat PFTau selector discrimination sources applyPostfix(process, "pfTaus", postfix).discriminators = cms.VPSet() for selection in pf2patSelection: # Get our discriminator that will be used to select pfTaus originalName = tauType + selection clonedName = "pfTausBase" + selection + postfix clonedDisc = getattr(process, originalName).clone() # Register in our process setattr(process, clonedName, clonedDisc) tauCollectionToSelect = None if tauType != 'hpsPFTau': tauCollectionToSelect = cms.InputTag("pfTausBase" + postfix) #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix) else: tauCollectionToSelect = cms.InputTag("hpsPFTauProducer" + postfix) #Adapt our cloned discriminator to the new prediscriminants adaptTauDiscriminator( clonedDisc, newTauProducer="pfTausBase", oldTauTypeMapper=recoTauTypeMapperWithGroup, newTauTypeMapper=producerIsTauTypeMapperWithPostfix, preservePFTauProducer=True) clonedDisc.PFTauProducer = tauCollectionToSelect baseSequence += clonedDisc # Add this selection to our pfTau selectors applyPostfix(process, "pfTaus", postfix).discriminators.append( cms.PSet(discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5))) # Set the input of the final selector. if tauType != 'hpsPFTau': applyPostfix(process, "pfTaus", postfix).src = "pfTausBase" + postfix else: # If we are using HPS taus, we need to take the output of the clenaed # collection applyPostfix(process, "pfTaus", postfix).src = "hpsPFTauProducer" + postfix
def applyFilter(sample, process, postfix): applyPostfix(process,"GenZmassFilter",postfix).applyFilter = False applyPostfix(process,"topDecayGenFilter",postfix).applyFilter = False if sample.find("Run") != -1: applyPostfix(process,"JetEnergyScale",postfix).globalTag = cms.untracked.string('GR_R_52_V9') applyPostfix(process,"JetEnergyScale",postfix).doResJec = cms.untracked.bool(True) applyJSON(process, json ) else: applyPostfix(process,"JetEnergyScale",postfix).globalTag = cms.untracked.string('START52_V11') applyPostfix(process,"JetEnergyScale",postfix).doResJec = cms.untracked.bool(False) if sample.find("ZJets") != -1 or sample.find("ZtauDecay") != -1: applyPostfix(process,"GenZmassFilter",postfix).applyFilter = True if sample.find("tau") != -1: applyPostfix(process,"GenZmassFilter",postfix).decayMode = [15] else: applyPostfix(process,"GenZmassFilter",postfix).decayMode = [11,13] if sample.find("TTbar") != -1: process.topWLeptonGenFilter.applyFilter = True applyPostfix(process,"topDecayGenFilter",postfix).applyFilter = True if sample.find("Others") != -1: process.p.replace( applyPostfix(process,"topDecayGenFilter",postfix),~applyPostfix(process,"topDecayGenFilter",postfix)) process.p2.replace( applyPostfix(process,"topDecayGenFilter",postfix),~applyPostfix(process,"topDecayGenFilter",postfix)) process.p3.replace( applyPostfix(process,"topDecayGenFilter",postfix),~applyPostfix(process,"topDecayGenFilter",postfix))
def usePF2PAT(process, runPF2PAT=True, jetAlgo='AK5', runOnMC=True, postfix="", jetCorrections=('AK5PFchs', ['L1FastJet', 'L2Relative', 'L3Absolute']), pvCollection=cms.InputTag('offlinePrimaryVertices'), typeIMetCorrections=False, outputModules=['out']): # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT. # CREATE ADDITIONAL FUNCTIONS IF NEEDED. """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence""" # -------- CORE --------------- if runPF2PAT: process.load("CommonTools.ParticleFlow.PF2PAT_cff") #add Pf2PAT *before* cloning so that overlapping modules are cloned too #process.patDefaultSequence.replace( process.patCandidates, process.PF2PAT+process.patCandidates) process.patPF2PATSequence = cms.Sequence(process.PF2PAT + process.patDefaultSequence) else: process.patPF2PATSequence = cms.Sequence(process.patDefaultSequence) if not postfix == "": from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet cloneProcessingSnippet(process, process.patPF2PATSequence, postfix) #delete everything pat PF2PAT modules! if you want to test the postfixing for completeness #from PhysicsTools.PatAlgos.tools.helpers import listModules,listSequences #for module in listModules(process.patDefaultSequence): # if not module.label() is None: process.__delattr__(module.label()) #for sequence in listSequences(process.patDefaultSequence): # if not sequence.label() is None: process.__delattr__(sequence.label()) #del process.patDefaultSequence removeCleaning(process, postfix=postfix, outputModules=outputModules) # -------- OBJECTS ------------ # Muons adaptPFMuons(process, applyPostfix(process, "patMuons", postfix), postfix) # Electrons adaptPFElectrons(process, applyPostfix(process, "patElectrons", postfix), postfix) # Photons print "Temporarily switching off photons completely" removeSpecificPATObjects(process, names=['Photons'], outputModules=outputModules, postfix=postfix) removeIfInSequence(process, "patPhotonIsolation", "patDefaultSequence", postfix) # Jets if runOnMC: switchToPFJets(process, cms.InputTag('pfNoTau' + postfix), jetAlgo, postfix=postfix, jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules) applyPostfix(process, "patDefaultSequence", postfix).replace( applyPostfix(process, "patJetGenJetMatch", postfix), getattr(process, "genForPF2PATSequence") * applyPostfix(process, "patJetGenJetMatch", postfix)) else: if not 'L2L3Residual' in jetCorrections[1]: print '#################################################' print 'WARNING! Not using L2L3Residual but this is data.' print 'If this is okay with you, disregard this message.' print '#################################################' switchToPFJets(process, cms.InputTag('pfNoTau' + postfix), jetAlgo, postfix=postfix, jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules) # Taus #adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix ) #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix ) adaptPFTaus(process, tauType='hpsPFTau', postfix=postfix) # MET switchToPFMET(process, cms.InputTag('pfMET' + postfix), type1=typeIMetCorrections, postfix=postfix) if not runOnMC: if hasattr(process, 'patPFMet' + postfix): getattr(process, 'patPFMet' + postfix).addGenMET = cms.bool(False) # Unmasked PFCandidates addPFCandidates(process, cms.InputTag('pfNoJet' + postfix), patLabel='PFParticles' + postfix, cut="", postfix=postfix) # adapt primary vertex collection adaptPVs(process, pvCollection=pvCollection, postfix=postfix) if runOnMC: process.load("CommonTools.ParticleFlow.genForPF2PAT_cff") getattr(process, "patDefaultSequence" + postfix).replace( applyPostfix(process, "patCandidates", postfix), process.genForPF2PATSequence + applyPostfix(process, "patCandidates", postfix)) else: removeMCMatchingPF2PAT(process, postfix=postfix, outputModules=outputModules) print "Done: PF2PAT interfaced to PAT, postfix=", postfix