From 2472181e774968729acaa219480c8c946b597bca Mon Sep 17 00:00:00 2001 From: Dinko Ferencek Date: Wed, 30 Dec 2015 10:04:24 -0600 Subject: [PATCH 1/6] added updateJetCollection function (cherry picked from commit 02a81ade5dd1b4665c2077318ec3b148db35074e) --- .../python/producersLayer1/jetUpdater_cff.py | 8 +- .../python/producersLayer1/jetUpdater_cfi.py | 4 +- .../PatAlgos/python/tools/jetTools.py | 809 +++++++++++------- 3 files changed, 522 insertions(+), 299 deletions(-) diff --git a/PhysicsTools/PatAlgos/python/producersLayer1/jetUpdater_cff.py b/PhysicsTools/PatAlgos/python/producersLayer1/jetUpdater_cff.py index 16d4fd7e70a40..eed5aa4938a67 100644 --- a/PhysicsTools/PatAlgos/python/producersLayer1/jetUpdater_cff.py +++ b/PhysicsTools/PatAlgos/python/producersLayer1/jetUpdater_cff.py @@ -3,13 +3,13 @@ from PhysicsTools.PatAlgos.recoLayer0.jetCorrections_cff import * from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cfi import * -patJetCorrFactorsUpdated = patJetCorrFactors.clone( +updatedPatJetCorrFactors = patJetCorrFactors.clone( src = cms.InputTag("slimmedJets"), primaryVertices = cms.InputTag("offlineSlimmedPrimaryVertices") ) ## for scheduled mode -makePatJetsUpdated = cms.Sequence( - patJetCorrFactorsUpdated * - patJetsUpdated +makeUpdatedPatJets = cms.Sequence( + updatedPatJetCorrFactors * + updatedPatJets ) diff --git a/PhysicsTools/PatAlgos/python/producersLayer1/jetUpdater_cfi.py b/PhysicsTools/PatAlgos/python/producersLayer1/jetUpdater_cfi.py index 210227c7161fa..729cdb9f47262 100644 --- a/PhysicsTools/PatAlgos/python/producersLayer1/jetUpdater_cfi.py +++ b/PhysicsTools/PatAlgos/python/producersLayer1/jetUpdater_cfi.py @@ -1,6 +1,6 @@ import FWCore.ParameterSet.Config as cms -patJetsUpdated = cms.EDProducer("PATJetUpdater", +updatedPatJets = cms.EDProducer("PATJetUpdater", # input jetSource = cms.InputTag("slimmedJets"), # add user data @@ -27,7 +27,7 @@ ), # jet energy corrections addJetCorrFactors = cms.bool(True), - jetCorrFactorsSource = cms.VInputTag(cms.InputTag("patJetCorrFactorsUpdated") ), + jetCorrFactorsSource = cms.VInputTag(cms.InputTag("updatedPatJetCorrFactors") ), ) diff --git a/PhysicsTools/PatAlgos/python/tools/jetTools.py b/PhysicsTools/PatAlgos/python/tools/jetTools.py index 93bd4ac97be41..47553d0355734 100644 --- a/PhysicsTools/PatAlgos/python/tools/jetTools.py +++ b/PhysicsTools/PatAlgos/python/tools/jetTools.py @@ -13,6 +13,151 @@ , 'kt' : 'Kt' } +def checkJetCorrectionsFormat(jetCorrections): + ## check for the correct format + if type(jetCorrections) != type(('PAYLOAD-LABEL',['CORRECTION-LEVEL-A','CORRECTION-LEVEL-B'], 'MET-LABEL')): + raise ValueError, "In addJetCollection: 'jetCorrections' must be 'None' (as a python value w/o quotation marks), or of type ('PAYLOAD-LABEL', ['CORRECTION-LEVEL-A', \ + 'CORRECTION-LEVEL-B', ...], 'MET-LABEL'). Note that 'MET-LABEL' can be set to 'None' (as a string in quotation marks) in case you do not want to apply MET(Type1) \ + corrections." + + +def setupJetCorrections(process, knownModules, jetCorrections, jetSource, pvSource, patJets, labelName, postfix): + ## determine type of jet constituents from jetSource; supported + ## jet constituent types are calo, pf, jpt, for pf also particleflow + ## is aloowed as part of the jetSource label, which might be used + ## in CommonTools.ParticleFlow + _type="NONE" + if jetCorrections[0].count('PF')>0: + _type='PF' + elif jetCorrections[0].count('Calo')>0: + _type='Calo' + elif jetCorrections[0].count('JPT')>0: + _type='JPT' + else: + raise TypeError, "In addJetCollection: Jet energy corrections are only supported for PF, JPT and Calo jets." + from PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi import patJetCorrFactors + if 'patJetCorrFactors'+labelName+postfix in knownModules : + _newPatJetCorrFactors=getattr(process, 'patJetCorrFactors'+labelName+postfix) + _newPatJetCorrFactors.src=jetSource + _newPatJetCorrFactors.primaryVertices=pvSource + else: + setattr(process, 'patJetCorrFactors'+labelName+postfix, patJetCorrFactors.clone(src=jetSource, primaryVertices=pvSource)) + _newPatJetCorrFactors=getattr(process, "patJetCorrFactors"+labelName+postfix) + _newPatJetCorrFactors.payload=jetCorrections[0] + _newPatJetCorrFactors.levels=jetCorrections[1] + ## check whether L1Offset or L1FastJet is part of levels + error=False + for x in jetCorrections[1]: + if x == 'L1Offset' : + if not error : + _newPatJetCorrFactors.useNPV=True + _newPatJetCorrFactors.primaryVertices='offlinePrimaryVertices' + _newPatJetCorrFactors.useRho=False + ## we set this to True now as a L1 correction type should appear only once + ## otherwise levels is miss configured + error=True + else: + raise ValueError, "In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \ + once. Check the list of correction levels you requested to be applied: ", jetCorrections[1] + if x == 'L1FastJet' : + if not error : + if _type == "JPT" : + raise TypeError, "In addJetCollection: L1FastJet corrections are only supported for PF and Calo jets." + ## configure module + _newPatJetCorrFactors.useRho=True + if "PF" in _type : + _newPatJetCorrFactors.rho=cms.InputTag('fixedGridRhoFastjetAll') + else : + _newPatJetCorrFactors.rho=cms.InputTag('fixedGridRhoFastjetAllCalo') + ## we set this to True now as a L1 correction type should appear only once + ## otherwise levels is miss configured + error=True + else: + raise ValueError, "In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \ + once. Check the list of correction levels you requested to be applied: ", jetCorrections[1] + patJets.jetCorrFactorsSource=cms.VInputTag(cms.InputTag('patJetCorrFactors'+labelName+postfix)) + ## configure MET(Type1) corrections + if jetCorrections[2].lower() != 'none' and jetCorrections[2] != '': + if not jetCorrections[2].lower() == 'type-1' and not jetCorrections[2].lower() == 'type-2': + raise valueError, "In addJetCollection: Wrong choice of MET corrections for new jet collection. Possible choices are None (or empty string), Type-1, Type-2 (i.e.\ + Type-1 and Type-2 corrections applied). This choice is not case sensitive. Your choice was: ", jetCorrections[2] + if _type == "JPT": + raise ValueError, "In addJecCollection: MET(type1) corrections are not supported for JPTJets. Please set the MET-LABEL to \"None\" (as string in quatiation \ + marks) and use raw tcMET together with JPTJets." + ## set up jet correctors for MET corrections + process.load( "JetMETCorrections.Configuration.JetCorrectorsAllAlgos_cff") # FIXME: This adds a lot of garbage + + _payloadType = jetCorrections[0].split(_type)[0].lower()+_type + if "PF" in _type : + setattr(process, jetCorrections[0]+'L1FastJet', getattr(process, _payloadType+'L1FastjetCorrector').clone(srcRho=cms.InputTag('fixedGridRhoFastjetAll'))) + else : + setattr(process, jetCorrections[0]+'L1FastJet', getattr(process, _payloadType+'L1FastjetCorrector').clone(srcRho=cms.InputTag('fixedGridRhoFastjetAllCalo'))) + setattr(process, jetCorrections[0]+'L1Offset', getattr(process, _payloadType+'L1OffsetCorrector').clone()) + setattr(process, jetCorrections[0]+'L2Relative', getattr(process, _payloadType+'L2RelativeCorrector').clone()) + setattr(process, jetCorrections[0]+'L3Absolute', getattr(process, _payloadType+'L3AbsoluteCorrector').clone()) + setattr(process, jetCorrections[0]+'L2L3Residual', getattr(process, _payloadType+'ResidualCorrector').clone()) + setattr(process, jetCorrections[0]+'CombinedCorrector', cms.EDProducer( 'ChainedJetCorrectorProducer', correctors = cms.VInputTag())) + for x in jetCorrections[1]: + if x != 'L1FastJet' and x != 'L1Offset' and x != 'L2Relative' and x != 'L3Absolute' and x != 'L2L3Residual': + raise ValueError, 'In addJetCollection: Unsupported JEC for MET(Type1). Currently supported jet correction levels are L1FastJet, L1Offset, L2Relative, L3Asolute, L2L3Residual. Requested was: %s'%(x) + else: + _corrector = _payloadType + if x == 'L1FastJet': + _corrector += 'L1Fastjet' + elif x == 'L2L3Residual': + _corrector += 'Residual' + else: + _corrector += x + _corrector += 'Corrector' + getattr(process, jetCorrections[0]+'CombinedCorrector').correctors.append(cms.InputTag(_corrector)) + + ## set up MET(Type1) correction modules + _labelCorrName = labelName + if labelName != '': + _labelCorrName = 'For' + labelName + if _type == 'Calo': + from JetMETCorrections.Type1MET.correctionTermsCaloMet_cff import corrCaloMetType1 + from JetMETCorrections.Type1MET.correctionTermsCaloMet_cff import corrCaloMetType2 + from JetMETCorrections.Type1MET.correctedMet_cff import caloMetT1 + from JetMETCorrections.Type1MET.correctedMet_cff import caloMetT1T2 + setattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, corrCaloMetType1.clone(src=jetSource,srcMET = "caloMetM",jetCorrLabel = cms.InputTag(jetCorrections[0]+'CombinedCorrector'))) + setattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr2'+postfix, corrCaloMetType2.clone(srcUnclEnergySums = cms.VInputTag(cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type2'),cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'offset'),cms.InputTag('muCaloMetCorr')))) + setattr(process,jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix, caloMetT1.clone(src = "caloMetM", srcCorrections = cms.VInputTag(cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1')))) + setattr(process,jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix, caloMetT1T2.clone(src = "caloMetM", srcCorrections = cms.VInputTag(cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'), cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr2'+postfix)))) + + elif _type == 'PF': + from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfJetsPtrForMetCorr + from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfCandsNotInJetsPtrForMetCorr + from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfCandsNotInJetsForMetCorr + from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfCandMETcorr + from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import corrPfMetType1 + from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import corrPfMetType2 + from JetMETCorrections.Type1MET.correctedMet_cff import pfMetT1 + from JetMETCorrections.Type1MET.correctedMet_cff import pfMetT1T2 + setattr(process,jetCorrections[0]+_labelCorrName+'pfJetsPtrForMetCorr'+postfix,pfJetsPtrForMetCorr.clone(src = jetSource)) + setattr(process,jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsPtrForMetCorr'+postfix,pfCandsNotInJetsPtrForMetCorr.clone(topCollection = jetCorrections[0]+_labelCorrName+'pfJetsPtrForMetCorr'+postfix)) + setattr(process,jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsForMetCorr'+postfix,pfCandsNotInJetsForMetCorr.clone(src = jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsPtrForMetCorr'+postfix)) + setattr(process,jetCorrections[0]+_labelCorrName+'CandMETcorr'+postfix, pfCandMETcorr.clone(src = cms.InputTag(jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsForMetCorr'+postfix))) + setattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, corrPfMetType1.clone(src = jetSource, jetCorrLabel = cms.InputTag(jetCorrections[0]+'CombinedCorrector'))) # FIXME: Originally w/o jet corrections? + setattr(process,jetCorrections[0]+_labelCorrName+'corrPfMetType2'+postfix, corrPfMetType2.clone(srcUnclEnergySums = cms.VInputTag(cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type2'),cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'offset'),cms.InputTag(jetCorrections[0]+_labelCorrName+'CandMETcorr'+postfix)))) + setattr(process,jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix, pfMetT1.clone(srcCorrections = cms.VInputTag(cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1')))) + setattr(process,jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix, pfMetT1T2.clone(srcCorrections = cms.VInputTag(cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'), jetCorrections[0]+_labelCorrName+'corrPfMetType2'+postfix))) + + ## common configuration for Calo and PF + if ('L1FastJet' in jetCorrections[1] or 'L1Fastjet' in jetCorrections[1]): + getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag(jetCorrections[0]+'L1FastJet') + #FIXME: What is wrong here? + #elif ('L1Offset' in jetCorrections[1]): + #getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag(jetCorrections[0]+'L1Offset') + else: + getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag('') + + from PhysicsTools.PatAlgos.producersLayer1.metProducer_cfi import patMETs + if jetCorrections[2].lower() == 'type-1': + setattr(process, 'patMETs'+labelName+postfix, patMETs.clone(metSource = cms.InputTag(jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix), addMuonCorrections = False)) + elif jetCorrections[2].lower() == 'type-2': + setattr(process, 'patMETs'+labelName+postfix, patMETs.clone(metSource = cms.InputTag(jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix), addMuonCorrections = False)) + def setupSVClustering(btagInfo, algo, rParam, fatJets=cms.InputTag(''), groomedFatJets=cms.InputTag('')): btagInfo.useSVClustering = cms.bool(True) @@ -24,6 +169,158 @@ def setupSVClustering(btagInfo, algo, rParam, fatJets=cms.InputTag(''), groomedF btagInfo.groomedFatJets = groomedFatJets +def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSource, elSource, muSource, runIVF, svClustering, fatJets, groomedFatJets, + algo, rParam, btagDiscriminators, btagInfos, patJets, labelName, postfix): + ## expand tagInfos to what is explicitely required by user + implicit + ## requirements that come in from one or the other discriminator + requiredTagInfos = list(btagInfos) + for btagDiscr in btagDiscriminators : + for requiredTagInfo in supportedBtagDiscr[btagDiscr] : + tagInfoCovered = False + for tagInfo in requiredTagInfos : + if requiredTagInfo == tagInfo : + tagInfoCovered = True + break + if not tagInfoCovered : + requiredTagInfos.append(requiredTagInfo) + ## load sequences and setups needed for btagging + ## This loads all available btagger, but the ones we need are added to the process by hand later. Only needed to get the ESProducer. Needs improvement + if hasattr( process, 'candidateJetProbabilityComputer' ) == False : + #process.load("RecoBTag.Configuration.RecoBTag_cff") # commented out to prevent loading of IVF modules already run in the standard reconstruction. Instead, loading individual cffs from RecoBTag_cff + process.load("RecoBTag.ImpactParameter.impactParameter_cff") + process.load("RecoBTag.SecondaryVertex.secondaryVertex_cff") + process.load("RecoBTag.SoftLepton.softLepton_cff") + process.load("RecoBTag.Combined.combinedMVA_cff") + process.load("RecoBTag.CTagging.RecoCTagging_cff") + #addESProducers(process,'RecoBTag.Configuration.RecoBTag_cff') + import RecoBTag.Configuration.RecoBTag_cff as btag + import RecoJets.JetProducers.caTopTaggers_cff as toptag + + ## setup all required btagInfos : we give a dedicated treatment for different + ## types of tagInfos here. A common treatment is possible but might require a more + ## general approach anyway in coordination with the btagging POG. + acceptedTagInfos = list() + for btagInfo in requiredTagInfos: + if hasattr(btag,btagInfo): + if btagInfo == 'pfImpactParameterTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.pfImpactParameterTagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates)) + if explicitJTA: + _btagInfo = getattr(process, btagInfo+labelName+postfix) + _btagInfo.explicitJTA = cms.bool(explicitJTA) + if btagInfo == 'pfImpactParameterTagInfosAK8': + setattr(process, btagInfo+labelName+postfix, btag.pfImpactParameterTagInfosAK8.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates)) + if explicitJTA: + _btagInfo = getattr(process, btagInfo+labelName+postfix) + _btagInfo.explicitJTA = cms.bool(explicitJTA) + if btagInfo == 'pfImpactParameterTagInfosCA15': + setattr(process, btagInfo+labelName+postfix, btag.pfImpactParameterTagInfosCA15.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates)) + if explicitJTA: + _btagInfo = getattr(process, btagInfo+labelName+postfix) + _btagInfo.explicitJTA = cms.bool(explicitJTA) + if btagInfo == 'pfSecondaryVertexTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.pfSecondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfos'+labelName+postfix))) + if btagInfo == 'pfInclusiveSecondaryVertexFinderTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.pfInclusiveSecondaryVertexFinderTagInfos.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfos'+labelName+postfix), extSVCollection=svSource)) + if svClustering: + setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets) + if btagInfo == 'pfInclusiveSecondaryVertexFinderTagInfosAK8': + setattr(process, btagInfo+labelName+postfix, btag.pfInclusiveSecondaryVertexFinderTagInfosAK8.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfosAK8'+labelName+postfix), extSVCollection=svSource)) + if svClustering: + setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets) + if btagInfo == 'pfInclusiveSecondaryVertexFinderTagInfosCA15': + setattr(process, btagInfo+labelName+postfix, btag.pfInclusiveSecondaryVertexFinderTagInfosCA15.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfosCA15'+labelName+postfix), extSVCollection=svSource)) + if btagInfo == 'pfInclusiveSecondaryVertexFinderCvsLTagInfos': + setattr( + process, + btagInfo+labelName+postfix, + btag.pfInclusiveSecondaryVertexFinderCvsLTagInfos.clone( + trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfos'+labelName+postfix), + extSVCollection=svSource + ) + ) + if svClustering: + setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets) + if btagInfo == 'pfInclusiveSecondaryVertexFinderCvsBTagInfos': + setattr( + process, + btagInfo+labelName+postfix, + btag.pfInclusiveSecondaryVertexFinderCvsBTagInfos.clone( + trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfos'+labelName+postfix), + extSVCollection=svSource + ) + ) + if svClustering: + setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets) + if btagInfo == 'pfSecondaryVertexNegativeTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.pfSecondaryVertexNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfos'+labelName+postfix))) + if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.pfInclusiveSecondaryVertexFinderNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfos'+labelName+postfix), extSVCollection=svSource)) + if svClustering: + setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets) + if btagInfo == 'impactParameterTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.impactParameterTagInfos.clone(jetTracks = cms.InputTag('jetTracksAssociatorAtVertex'+labelName+postfix), primaryVertex=pvSource)) + if btagInfo == 'secondaryVertexTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.secondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+labelName+postfix))) + if btagInfo == 'inclusiveSecondaryVertexFinderTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.inclusiveSecondaryVertexFinderTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+labelName+postfix))) + if svClustering: + setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets) + if btagInfo == 'inclusiveSecondaryVertexFinderFilteredTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.inclusiveSecondaryVertexFinderFilteredTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+labelName+postfix))) + if svClustering: + setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets) + if btagInfo == 'secondaryVertexNegativeTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.secondaryVertexNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+labelName+postfix))) + if btagInfo == 'inclusiveSecondaryVertexFinderNegativeTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.inclusiveSecondaryVertexFinderNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+labelName+postfix))) + if btagInfo == 'inclusiveSecondaryVertexFinderFilteredNegativeTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.inclusiveSecondaryVertexFinderFilteredNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+labelName+postfix))) + if btagInfo == 'softMuonTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.softMuonTagInfos.clone(jets = jetSource, primaryVertex=pvSource)) + if btagInfo == 'softPFMuonsTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.softPFMuonsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, muons=muSource)) + if btagInfo == 'softPFElectronsTagInfos': + setattr(process, btagInfo+labelName+postfix, btag.softPFElectronsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, electrons=elSource)) + acceptedTagInfos.append(btagInfo) + elif hasattr(toptag, btagInfo) : + acceptedTagInfos.append(btagInfo) + else: + print ' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagInfo) + ## setup all required btagDiscriminators + acceptedBtagDiscriminators = list() + for btagDiscr in btagDiscriminators : + if hasattr(btag,btagDiscr): + setattr(process, btagDiscr+labelName+postfix, getattr(btag, btagDiscr).clone(tagInfos = cms.VInputTag( *[ cms.InputTag(x+labelName+postfix) for x in supportedBtagDiscr[btagDiscr] ] ))) + acceptedBtagDiscriminators.append(btagDiscr) + else: + print ' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr) + ## replace corresponding tags for pat jet production + patJets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(x+labelName+postfix) for x in acceptedTagInfos ] ) + patJets.discriminatorSources = cms.VInputTag( *[ cms.InputTag(x+labelName+postfix) for x in acceptedBtagDiscriminators ] ) + if len(acceptedBtagDiscriminators) > 0 : + patJets.addBTagInfo = True + if runIVF: + rerunningIVF() + if 'pfInclusiveSecondaryVertexFinderTagInfos' in acceptedTagInfos: + if not hasattr( process, 'inclusiveCandidateVertexing' ): + process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' ) + if 'inclusiveSecondaryVertexFinderTagInfos' in acceptedTagInfos: + if not hasattr( process, 'inclusiveVertexing' ): + process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' ) + if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos: + if not hasattr( process, 'inclusiveVertexing' ): + process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' ) + if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos: + if not hasattr( process, 'inclusiveSecondaryVerticesFiltered' ): + process.load( 'RecoBTag.SecondaryVertex.secondaryVertex_cff' ) + if not hasattr( process, 'bToCharmDecayVertexMerged' ): + process.load( 'RecoBTag.SecondaryVertex.bToCharmDecayVertexMerger_cfi' ) + if 'caTopTagInfos' in acceptedTagInfos : + patJets.addTagInfos = True + if not hasattr( process, 'caTopTagInfos' ) and not hasattr( process, 'caTopTagInfosAK8' ): + process.load( 'RecoJets.JetProducers.caTopTaggers_cff' ) + + class AddJetCollection(ConfigToolBase): """ Tool to add a new jet collection to your PAT Tuple or to modify an existing one. @@ -220,11 +517,10 @@ def toolCode(self, process): bTaggingLegacy=(len(btagDiscriminators)>tags or len(btagInfos)>infos) ## construct postfix label for auxiliary modules; this postfix ## label will start with a capitalized first letter following - ## the CMS nameing conventions and for improved readablility + ## the CMS naming conventions and for improved readablility _labelName=labelName[:1].upper()+labelName[1:] - #_labelName=labelName - ## supported algo types are ak, ca, and kt + ## supported algo types are ak, ca, and kt _algo='' for x in ["ak", "ca", "kt"]: if x in algo.lower(): @@ -232,7 +528,6 @@ def toolCode(self, process): break if _algo=='': unsupportedJetAlgorithm(self) - #print _algo ## add new patJets to process (keep instance for later further modifications) from PhysicsTools.PatAlgos.producersLayer1.jetProducer_cfi import patJets if 'patJets'+_labelName+postfix in knownModules : @@ -251,7 +546,7 @@ def toolCode(self, process): setattr(process, 'selectedPatJets'+_labelName+postfix, selectedPatJets.clone(src='patJets'+_labelName+postfix)) knownModules.append('selectedPatJets'+_labelName+postfix) - ## add new patJetPartonMatch to process + ## add new patJetPartonMatch to process from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetPartonMatch if 'patJetPartonMatch'+_labelName+postfix in knownModules : _newPatJetPartonMatch=getattr(process, 'patJetPartonMatch'+_labelName+postfix) @@ -380,154 +675,8 @@ def toolCode(self, process): _newPatJets.jetChargeSource='' ## run btagging if required by user if (bTagging): - ## expand tagInfos to what is explicitely required by user + implicit - ## requirements that come in from one or the other discriminator - requiredTagInfos = list(btagInfos) - for btagDiscr in btagDiscriminators : - for requiredTagInfo in supportedBtagDiscr[btagDiscr] : - tagInfoCovered = False - for tagInfo in requiredTagInfos : - if requiredTagInfo == tagInfo : - tagInfoCovered = True - break - if not tagInfoCovered : - requiredTagInfos.append(requiredTagInfo) - ## load sequences and setups needed for btagging - ## This loads all available btagger, but the ones we need are added to the process by hand later. Only needed to get the ESProducer. Needs improvement - if hasattr( process, 'candidateJetProbabilityComputer' ) == False : - #process.load("RecoBTag.Configuration.RecoBTag_cff") # commented out to prevent loading of IVF modules already run in the standard reconstruction. Instead, loading individual cffs from RecoBTag_cff - process.load("RecoBTag.ImpactParameter.impactParameter_cff") - process.load("RecoBTag.SecondaryVertex.secondaryVertex_cff") - process.load("RecoBTag.SoftLepton.softLepton_cff") - process.load("RecoBTag.Combined.combinedMVA_cff") - process.load("RecoBTag.CTagging.RecoCTagging_cff") - #addESProducers(process,'RecoBTag.Configuration.RecoBTag_cff') - import RecoBTag.Configuration.RecoBTag_cff as btag - import RecoJets.JetProducers.caTopTaggers_cff as toptag - - ## setup all required btagInfos : we give a dedicated treatment for different - ## types of tagInfos here. A common treatment is possible but might require a more - ## general approach anyway in coordination with the btagging POG. - acceptedTagInfos = list() - for btagInfo in requiredTagInfos: - if hasattr(btag,btagInfo): - if btagInfo == 'pfImpactParameterTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.pfImpactParameterTagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates)) - if explicitJTA: - _btagInfo = getattr(process, btagInfo+_labelName+postfix) - _btagInfo.explicitJTA = cms.bool(explicitJTA) - if btagInfo == 'pfImpactParameterTagInfosAK8': - setattr(process, btagInfo+_labelName+postfix, btag.pfImpactParameterTagInfosAK8.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates)) - if explicitJTA: - _btagInfo = getattr(process, btagInfo+_labelName+postfix) - _btagInfo.explicitJTA = cms.bool(explicitJTA) - if btagInfo == 'pfImpactParameterTagInfosCA15': - setattr(process, btagInfo+_labelName+postfix, btag.pfImpactParameterTagInfosCA15.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates)) - if explicitJTA: - _btagInfo = getattr(process, btagInfo+_labelName+postfix) - _btagInfo.explicitJTA = cms.bool(explicitJTA) - if btagInfo == 'pfSecondaryVertexTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.pfSecondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfos'+_labelName+postfix))) - if btagInfo == 'pfInclusiveSecondaryVertexFinderTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.pfInclusiveSecondaryVertexFinderTagInfos.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfos'+_labelName+postfix), extSVCollection=svSource)) - if svClustering: - setupSVClustering(getattr(process, btagInfo+_labelName+postfix), _algo, rParam, fatJets, groomedFatJets) - if btagInfo == 'pfInclusiveSecondaryVertexFinderTagInfosAK8': - setattr(process, btagInfo+_labelName+postfix, btag.pfInclusiveSecondaryVertexFinderTagInfosAK8.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfosAK8'+_labelName+postfix), extSVCollection=svSource)) - if svClustering: - setupSVClustering(getattr(process, btagInfo+_labelName+postfix), _algo, rParam, fatJets, groomedFatJets) - if btagInfo == 'pfInclusiveSecondaryVertexFinderTagInfosCA15': - setattr(process, btagInfo+_labelName+postfix, btag.pfInclusiveSecondaryVertexFinderTagInfosCA15.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfosCA15'+_labelName+postfix), extSVCollection=svSource)) - if btagInfo == 'pfInclusiveSecondaryVertexFinderCvsLTagInfos': - setattr( - process, - btagInfo+_labelName+postfix, - btag.pfInclusiveSecondaryVertexFinderCvsLTagInfos.clone( - trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfos'+_labelName+postfix), - extSVCollection=svSource - ) - ) - if svClustering: - setupSVClustering(getattr(process, btagInfo+_labelName+postfix), _algo, rParam, fatJets, groomedFatJets) - if btagInfo == 'pfInclusiveSecondaryVertexFinderCvsBTagInfos': - setattr( - process, - btagInfo+_labelName+postfix, - btag.pfInclusiveSecondaryVertexFinderCvsBTagInfos.clone( - trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfos'+_labelName+postfix), - extSVCollection=svSource - ) - ) - if svClustering: - setupSVClustering(getattr(process, btagInfo+_labelName+postfix), _algo, rParam, fatJets, groomedFatJets) - if btagInfo == 'pfSecondaryVertexNegativeTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.pfSecondaryVertexNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfos'+_labelName+postfix))) - if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.pfInclusiveSecondaryVertexFinderNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfos'+_labelName+postfix), extSVCollection=svSource)) - if svClustering: - setupSVClustering(getattr(process, btagInfo+_labelName+postfix), _algo, rParam, fatJets, groomedFatJets) - if btagInfo == 'impactParameterTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.impactParameterTagInfos.clone(jetTracks = cms.InputTag('jetTracksAssociatorAtVertex'+_labelName+postfix), primaryVertex=pvSource)) - if btagInfo == 'secondaryVertexTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.secondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+_labelName+postfix))) - if btagInfo == 'inclusiveSecondaryVertexFinderTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.inclusiveSecondaryVertexFinderTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+_labelName+postfix))) - if svClustering: - setupSVClustering(getattr(process, btagInfo+_labelName+postfix), _algo, rParam, fatJets, groomedFatJets) - if btagInfo == 'inclusiveSecondaryVertexFinderFilteredTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.inclusiveSecondaryVertexFinderFilteredTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+_labelName+postfix))) - if svClustering: - setupSVClustering(getattr(process, btagInfo+_labelName+postfix), _algo, rParam, fatJets, groomedFatJets) - if btagInfo == 'secondaryVertexNegativeTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.secondaryVertexNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+_labelName+postfix))) - if btagInfo == 'inclusiveSecondaryVertexFinderNegativeTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.inclusiveSecondaryVertexFinderNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+_labelName+postfix))) - if btagInfo == 'inclusiveSecondaryVertexFinderFilteredNegativeTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.inclusiveSecondaryVertexFinderFilteredNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+_labelName+postfix))) - if btagInfo == 'softMuonTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.softMuonTagInfos.clone(jets = jetSource, primaryVertex=pvSource)) - if btagInfo == 'softPFMuonsTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.softPFMuonsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, muons=muSource)) - if btagInfo == 'softPFElectronsTagInfos': - setattr(process, btagInfo+_labelName+postfix, btag.softPFElectronsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, electrons=elSource)) - acceptedTagInfos.append(btagInfo) - elif hasattr(toptag, btagInfo) : - acceptedTagInfos.append(btagInfo) - else: - print ' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagInfo) - ## setup all required btagDiscriminators - acceptedBtagDiscriminators = list() - for btagDiscr in btagDiscriminators : - if hasattr(btag,btagDiscr): - setattr(process, btagDiscr+_labelName+postfix, getattr(btag, btagDiscr).clone(tagInfos = cms.VInputTag( *[ cms.InputTag(x+_labelName+postfix) for x in supportedBtagDiscr[btagDiscr] ] ))) - acceptedBtagDiscriminators.append(btagDiscr) - else: - print ' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr) - ## replace corresponding tags for pat jet production - _newPatJets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(x+_labelName+postfix) for x in acceptedTagInfos ] ) - _newPatJets.discriminatorSources = cms.VInputTag( *[ cms.InputTag(x+_labelName+postfix) for x in acceptedBtagDiscriminators ] ) - if len(acceptedBtagDiscriminators) > 0 : - _newPatJets.addBTagInfo = True - if runIVF: - rerunningIVF() - if 'pfInclusiveSecondaryVertexFinderTagInfos' in acceptedTagInfos: - if not hasattr( process, 'inclusiveCandidateVertexing' ): - process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' ) - if 'inclusiveSecondaryVertexFinderTagInfos' in acceptedTagInfos: - if not hasattr( process, 'inclusiveVertexing' ): - process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' ) - if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos: - if not hasattr( process, 'inclusiveVertexing' ): - process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' ) - if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos: - if not hasattr( process, 'inclusiveSecondaryVerticesFiltered' ): - process.load( 'RecoBTag.SecondaryVertex.secondaryVertex_cff' ) - if not hasattr( process, 'bToCharmDecayVertexMerged' ): - process.load( 'RecoBTag.SecondaryVertex.bToCharmDecayVertexMerger_cfi' ) - if 'caTopTagInfos' in acceptedTagInfos : - _newPatJets.addTagInfos = True - if not hasattr( process, 'caTopTagInfos' ) and not hasattr( process, 'caTopTagInfosAK8' ): - process.load( 'RecoJets.JetProducers.caTopTaggers_cff' ) + setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSource, elSource, muSource, runIVF, svClustering, fatJets, groomedFatJets, + _algo, rParam, btagDiscriminators, btagInfos, _newPatJets, _labelName, postfix) else: _newPatJets.addBTagInfo = False _newPatJets.addTagInfos = False @@ -538,146 +687,10 @@ def toolCode(self, process): ## add jet correction factors if required by user if (jetCorrections != None): - ## check for the correct format - if type(jetCorrections) != type(('PAYLOAD-LABEL',['CORRECTION-LEVEL-A','CORRECTION-LEVEL-B'], 'MET-LABEL')): - raise ValueError, "In addJetCollection: 'jetCorrections' must be 'None' (as a python value w/o quotation marks), or of type ('PAYLOAD-LABEL', ['CORRECTION-LEVEL-A', \ - 'CORRECTION-LEVEL-B', ...], 'MET-LABEL'). Note that 'MET-LABEL' can be set to 'None' (as a string in quotation marks) in case you do not want to apply MET(Type1) \ - corrections." - ## determine type of jet constituents from jetSource; supported - ## jet constituent types are calo, pf, jpt, for pf also particleflow - ## is aloowed as part of the jetSource label, which might be used - ## in CommonTools.ParticleFlow - _type="NONE" - if jetCorrections[0].count('PF')>0: - _type='PF' - elif jetCorrections[0].count('Calo')>0: - _type='Calo' - elif jetCorrections[0].count('JPT')>0: - _type='JPT' - else: - raise TypeError, "In addJetCollection: Jet energy corrections are only supported for PF, JPT and Calo jets." - from PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi import patJetCorrFactors - if 'patJetCorrFactors'+_labelName+postfix in knownModules : - _newPatJetCorrFactors=getattr(process, 'patJetCorrFactors'+_labelName+postfix) - _newPatJetCorrFactors.src=jetSource - _newPatJetCorrFactors.primaryVertices=pvSource - else: - setattr(process, 'patJetCorrFactors'+_labelName+postfix, patJetCorrFactors.clone(src=jetSource, primaryVertices=pvSource)) - _newPatJetCorrFactors=getattr(process, "patJetCorrFactors"+_labelName+postfix) - _newPatJetCorrFactors.payload=jetCorrections[0] - _newPatJetCorrFactors.levels=jetCorrections[1] - ## check whether L1Offset or L1FastJet is part of levels - error=False - for x in jetCorrections[1]: - if x == 'L1Offset' : - if not error : - _newPatJetCorrFactors.useNPV=True - _newPatJetCorrFactors.primaryVertices='offlinePrimaryVertices' - _newPatJetCorrFactors.useRho=False - ## we set this to True now as a L1 correction type should appear only once - ## otherwise levels is miss configured - error=True - else: - raise ValueError, "In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \ - once. Check the list of correction levels you requested to be applied: ", jetCorrections[1] - if x == 'L1FastJet' : - if not error : - if _type == "JPT" : - raise TypeError, "In addJetCollection: L1FastJet corrections are only supported for PF and Calo jets." - ## configure module - _newPatJetCorrFactors.useRho=True - if "PF" in _type : - _newPatJetCorrFactors.rho=cms.InputTag('fixedGridRhoFastjetAll') - else : - _newPatJetCorrFactors.rho=cms.InputTag('fixedGridRhoFastjetAllCalo') - ## we set this to True now as a L1 correction type should appear only once - ## otherwise levels is miss configured - error=True - else: - raise ValueError, "In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \ - once. Check the list of correction levels you requested to be applied: ", jetCorrections[1] - _newPatJets.jetCorrFactorsSource=cms.VInputTag(cms.InputTag('patJetCorrFactors'+_labelName+postfix)) - ## configure MET(Type1) corrections - if jetCorrections[2].lower() != 'none' and jetCorrections[2] != '': - if not jetCorrections[2].lower() == 'type-1' and not jetCorrections[2].lower() == 'type-2': - raise valueError, "In addJetCollection: Wrong choice of MET corrections for new jet collection. Possible choices are None (or empty string), Type-1, Type-2 (i.e.\ - Type-1 and Type-2 corrections applied). This choice is not case sensitive. Your choice was: ", jetCorrections[2] - if _type == "JPT": - raise ValueError, "In addJecCollection: MET(type1) corrections are not supported for JPTJets. Please set the MET-LABEL to \"None\" (as string in quatiation \ - marks) and use raw tcMET together with JPTJets." - ## set up jet correctors for MET corrections - process.load( "JetMETCorrections.Configuration.JetCorrectorsAllAlgos_cff") # FIXME: This adds a lot of garbage - - _payloadType = jetCorrections[0].split(_type)[0].lower()+_type - if "PF" in _type : - setattr(process, jetCorrections[0]+'L1FastJet', getattr(process, _payloadType+'L1FastjetCorrector').clone(srcRho=cms.InputTag('fixedGridRhoFastjetAll'))) - else : - setattr(process, jetCorrections[0]+'L1FastJet', getattr(process, _payloadType+'L1FastjetCorrector').clone(srcRho=cms.InputTag('fixedGridRhoFastjetAllCalo'))) - setattr(process, jetCorrections[0]+'L1Offset', getattr(process, _payloadType+'L1OffsetCorrector').clone()) - setattr(process, jetCorrections[0]+'L2Relative', getattr(process, _payloadType+'L2RelativeCorrector').clone()) - setattr(process, jetCorrections[0]+'L3Absolute', getattr(process, _payloadType+'L3AbsoluteCorrector').clone()) - setattr(process, jetCorrections[0]+'L2L3Residual', getattr(process, _payloadType+'ResidualCorrector').clone()) - setattr(process, jetCorrections[0]+'CombinedCorrector', cms.EDProducer( 'ChainedJetCorrectorProducer', correctors = cms.VInputTag())) - for x in jetCorrections[1]: - if x != 'L1FastJet' and x != 'L1Offset' and x != 'L2Relative' and x != 'L3Absolute' and x != 'L2L3Residual': - raise ValueError, 'In addJetCollection: Unsupported JEC for MET(Type1). Currently supported jet correction levels are L1FastJet, L1Offset, L2Relative, L3Asolute, L2L3Residual. Requested was: %s'%(x) - else: - _corrector = _payloadType - if x == 'L1FastJet': - _corrector += 'L1Fastjet' - elif x == 'L2L3Residual': - _corrector += 'Residual' - else: - _corrector += x - _corrector += 'Corrector' - getattr(process, jetCorrections[0]+'CombinedCorrector').correctors.append(cms.InputTag(_corrector)) - - ## set up MET(Type1) correction modules - _labelCorrName = _labelName - if _labelName != '': - _labelCorrName = 'For' + _labelName - if _type == 'Calo': - from JetMETCorrections.Type1MET.correctionTermsCaloMet_cff import corrCaloMetType1 - from JetMETCorrections.Type1MET.correctionTermsCaloMet_cff import corrCaloMetType2 - from JetMETCorrections.Type1MET.correctedMet_cff import caloMetT1 - from JetMETCorrections.Type1MET.correctedMet_cff import caloMetT1T2 - setattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, corrCaloMetType1.clone(src=jetSource,srcMET = "caloMetM",jetCorrLabel = cms.InputTag(jetCorrections[0]+'CombinedCorrector'))) - setattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr2'+postfix, corrCaloMetType2.clone(srcUnclEnergySums = cms.VInputTag(cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type2'),cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'offset'),cms.InputTag('muCaloMetCorr')))) - setattr(process,jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix, caloMetT1.clone(src = "caloMetM", srcCorrections = cms.VInputTag(cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1')))) - setattr(process,jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix, caloMetT1T2.clone(src = "caloMetM", srcCorrections = cms.VInputTag(cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'), cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr2'+postfix)))) - - elif _type == 'PF': - from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfJetsPtrForMetCorr - from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfCandsNotInJetsPtrForMetCorr - from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfCandsNotInJetsForMetCorr - from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfCandMETcorr - from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import corrPfMetType1 - from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import corrPfMetType2 - from JetMETCorrections.Type1MET.correctedMet_cff import pfMetT1 - from JetMETCorrections.Type1MET.correctedMet_cff import pfMetT1T2 - setattr(process,jetCorrections[0]+_labelCorrName+'pfJetsPtrForMetCorr'+postfix,pfJetsPtrForMetCorr.clone(src = jetSource)) - setattr(process,jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsPtrForMetCorr'+postfix,pfCandsNotInJetsPtrForMetCorr.clone(topCollection = jetCorrections[0]+_labelCorrName+'pfJetsPtrForMetCorr'+postfix)) - setattr(process,jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsForMetCorr'+postfix,pfCandsNotInJetsForMetCorr.clone(src = jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsPtrForMetCorr'+postfix)) - setattr(process,jetCorrections[0]+_labelCorrName+'CandMETcorr'+postfix, pfCandMETcorr.clone(src = cms.InputTag(jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsForMetCorr'+postfix))) - setattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, corrPfMetType1.clone(src = jetSource, jetCorrLabel = cms.InputTag(jetCorrections[0]+'CombinedCorrector'))) # FIXME: Originally w/o jet corrections? - setattr(process,jetCorrections[0]+_labelCorrName+'corrPfMetType2'+postfix, corrPfMetType2.clone(srcUnclEnergySums = cms.VInputTag(cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type2'),cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'offset'),cms.InputTag(jetCorrections[0]+_labelCorrName+'CandMETcorr'+postfix)))) - setattr(process,jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix, pfMetT1.clone(srcCorrections = cms.VInputTag(cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1')))) - setattr(process,jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix, pfMetT1T2.clone(srcCorrections = cms.VInputTag(cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'), jetCorrections[0]+_labelCorrName+'corrPfMetType2'+postfix))) - - ## common configuration for Calo and PF - if ('L1FastJet' in jetCorrections[1] or 'L1Fastjet' in jetCorrections[1]): - getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag(jetCorrections[0]+'L1FastJet') - #FIXME: What is wrong here? - #elif ('L1Offset' in jetCorrections[1]): - #getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag(jetCorrections[0]+'L1Offset') - else: - getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag('') - - from PhysicsTools.PatAlgos.producersLayer1.metProducer_cfi import patMETs - if jetCorrections[2].lower() == 'type-1': - setattr(process, 'patMETs'+_labelName+postfix, patMETs.clone(metSource = cms.InputTag(jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix), addMuonCorrections = False)) - elif jetCorrections[2].lower() == 'type-2': - setattr(process, 'patMETs'+_labelName+postfix, patMETs.clone(metSource = cms.InputTag(jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix), addMuonCorrections = False)) + ## check the jet corrections format + checkJetCorrectionsFormat(jetCorrections) + ## setup jet energy corrections and MET corrections + setupJetCorrections(process, knownModules, jetCorrections, jetSource, pvSource, _newPatJets, _labelName, postfix) else: ## switch jetCorrFactors off _newPatJets.addJetCorrFactors=False @@ -878,6 +891,216 @@ def toolCode(self, process): switchJetCollection=SwitchJetCollection() + +class UpdateJetCollection(ConfigToolBase): + """ + Tool to update a jet collection in your PAT Tuple (primarily intended for MiniAOD for which the default input argument values have been set). + """ + _label='updateJetCollection' + _defaultParameters=dicttypes.SortedKeysDict() + + def __init__(self): + """ + Initialize elements of the class. Note that the tool needs to be derived from ConfigToolBase to be usable in the configEditor. + """ + ## initialization of the base class + ConfigToolBase.__init__(self) + ## add all parameters that should be known to the class + self.addParameter(self._defaultParameters,'labelName', '', "Label name of the new patJet collection.", str) + self.addParameter(self._defaultParameters,'postfix','', "Postfix from usePF2PAT.", str) + self.addParameter(self._defaultParameters,'jetSource','', "Label of the input collection from which the new patJet collection should be created", cms.InputTag) + self.addParameter(self._defaultParameters,'pfCandidates',cms.InputTag('packedPFCandidates'), "Label of the input collection for candidatecandidatese used in b-tagging", cms.InputTag) + self.addParameter(self._defaultParameters,'explicitJTA', False, "Use explicit jet-track association") + self.addParameter(self._defaultParameters,'pvSource',cms.InputTag('offlineSlimmedPrimaryVertices'), "Label of the input collection for primary vertices used in b-tagging", cms.InputTag) + self.addParameter(self._defaultParameters,'svSource',cms.InputTag('slimmedSecondaryVertices'), "Label of the input collection for IVF vertices used in b-tagging", cms.InputTag) + self.addParameter(self._defaultParameters,'elSource',cms.InputTag('slimmedElectrons'), "Label of the input collection for electrons used in b-tagging", cms.InputTag) + self.addParameter(self._defaultParameters,'muSource',cms.InputTag('slimmedMuons'), "Label of the input collection for muons used in b-tagging", cms.InputTag) + self.addParameter(self._defaultParameters,'runIVF', False, "Re-run IVF secondary vertex reconstruction") + self.addParameter(self._defaultParameters,'svClustering', False, "Secondary vertices ghost-associated to jets using jet clustering (mostly intended for subjets)") + self.addParameter(self._defaultParameters,'fatJets', cms.InputTag(''), "Fat jet collection used for secondary vertex clustering", cms.InputTag) + self.addParameter(self._defaultParameters,'groomedFatJets', cms.InputTag(''), "Groomed fat jet collection used for secondary vertex clustering", cms.InputTag) + self.addParameter(self._defaultParameters,'algo', 'AK', "Jet algorithm of the input collection from which the new patJet collection should be created") + self.addParameter(self._defaultParameters,'rParam', 0.4, "Jet size (distance parameter R used in jet clustering)") + self.addParameter(self._defaultParameters,'jetCorrections',None, "Add all relevant information about jet energy corrections that you want to be added to your new patJet \ + collection. The format has to be given in a python tuple of type: (\'AK4Calo\',[\'L2Relative\', \'L3Absolute\'], patMet). Here the first argument corresponds to the payload \ + in the CMS Conditions database for the given jet collection; the second argument corresponds to the jet energy correction levels that you want to be embedded into your \ + new patJet collection. This should be given as a list of strings. Available values are L1Offset, L1FastJet, L1JPTOffset, L2Relative, L3Absolute, L5Falvour, L7Parton; the \ + third argument indicates whether MET(Type1/2) corrections should be applied corresponding to the new patJetCollection. If so a new patMet collection will be added to your PAT \ + Tuple in addition to the raw patMet. This new patMet collection will have the MET(Type1/2) corrections applied. The argument can have the following types: \'type-1\' for \ + type-1 corrected MET; \'type-2\' for type-1 plus type-2 corrected MET; \'\' or \'none\' if no further MET corrections should be applied to your MET. The arguments \'type-1\' \ + and \'type-2\' are not case sensitive.", tuple, acceptNoneValue=True) + self.addParameter(self._defaultParameters,'btagDiscriminators',['None'], "If you are interested in btagging, in most cases just the labels of the btag discriminators that \ + you are interested in is all relevant information that you need for a high level analysis. Add here all btag discriminators, that you are interested in as a list of strings. \ + If this list is empty no btag discriminator information will be added to your new patJet collection.", allowedValues=supportedBtagDiscr.keys(),Type=list) + self.addParameter(self._defaultParameters,'btagInfos',['None'], "The btagInfos objects contain all relevant information from which all discriminators of a certain \ + type have been calculated. You might be interested in keeping this information for low level tests or to re-calculate some discriminators from hand. Note that this information \ + on the one hand can be very space consuming and that it is not necessary to access the pre-calculated btag discriminator information that has been derived from it. Only in very \ + special cases the btagInfos might really be needed in your analysis. Add here all btagInfos, that you are interested in as a list of strings. If this list is empty no btagInfos \ + will be added to your new patJet collection.", allowedValues=supportedBtagInfos,Type=list) + self.addParameter(self._defaultParameters,'outputModules',['out'],"Add a list of all output modules to which you would like the new jet collection to be added. Usually this is \ + just one single output module with name \'out\', which corresponds also the default configuration of the tool. There is cases though where you might want to add this collection \ + to more than one output module.") + ## set defaults + self._parameters=copy.deepcopy(self._defaultParameters) + ## add comments + self._comment = "This is a tool to add more patJet collectinos to your PAT Tuple or to re-configure the default collection. You can add and embed additional information like jet\ + energy correction factors, btag infomration and generator match information to the new patJet collection depending on the parameters that you pass on to this function. Consult \ + the descriptions of each parameter for more information." + + def getDefaultParameters(self): + """ + Return default parameters of the class + """ + return self._defaultParameters + + def __call__(self,process,labelName=None,postfix=None,jetSource=None,pfCandidates=None,explicitJTA=None,pvSource=None,svSource=None,elSource=None,muSource=None,runIVF=None,svClustering=None,fatJets=None,groomedFatJets=None,algo=None,rParam=None,jetCorrections=None,btagDiscriminators=None,btagInfos=None): + """ + Function call wrapper. This will check the parameters and call the actual implementation that + can be found in toolCode via the base class function apply. + """ + if labelName is None: + labelName=self._defaultParameters['labelName'].value + self.setParameter('labelName', labelName) + if postfix is None: + postfix=self._defaultParameters['postfix'].value + self.setParameter('postfix', postfix) + if jetSource is None: + jetSource=self._defaultParameters['jetSource'].value + self.setParameter('jetSource', jetSource) + if pfCandidates is None: + pfCandidates=self._defaultParameters['pfCandidates'].value + self.setParameter('pfCandidates', pfCandidates) + if explicitJTA is None: + explicitJTA=self._defaultParameters['explicitJTA'].value + self.setParameter('explicitJTA', explicitJTA) + if pvSource is None: + pvSource=self._defaultParameters['pvSource'].value + self.setParameter('pvSource', pvSource) + if svSource is None: + svSource=self._defaultParameters['svSource'].value + self.setParameter('svSource', svSource) + if elSource is None: + elSource=self._defaultParameters['elSource'].value + self.setParameter('elSource', elSource) + if muSource is None: + muSource=self._defaultParameters['muSource'].value + self.setParameter('muSource', muSource) + if runIVF is None: + runIVF=self._defaultParameters['runIVF'].value + self.setParameter('runIVF', runIVF) + if svClustering is None: + svClustering=self._defaultParameters['svClustering'].value + self.setParameter('svClustering', svClustering) + if fatJets is None: + fatJets=self._defaultParameters['fatJets'].value + self.setParameter('fatJets', fatJets) + if groomedFatJets is None: + groomedFatJets=self._defaultParameters['groomedFatJets'].value + self.setParameter('groomedFatJets', groomedFatJets) + if algo is None: + algo=self._defaultParameters['algo'].value + self.setParameter('algo', algo) + if rParam is None: + rParam=self._defaultParameters['rParam'].value + self.setParameter('rParam', rParam) + if jetCorrections is None: + jetCorrections=self._defaultParameters['jetCorrections'].value + self.setParameter('jetCorrections', jetCorrections) + if btagDiscriminators is None: + btagDiscriminators=self._defaultParameters['btagDiscriminators'].value + self.setParameter('btagDiscriminators', btagDiscriminators) + if btagInfos is None: + btagInfos=self._defaultParameters['btagInfos'].value + self.setParameter('btagInfos', btagInfos) + self.apply(process) + + def toolCode(self, process): + """ + Tool code implementation + """ + ## initialize parameters + labelName=self._parameters['labelName'].value + postfix=self._parameters['postfix'].value + jetSource=self._parameters['jetSource'].value + pfCandidates=self._parameters['pfCandidates'].value + explicitJTA=self._parameters['explicitJTA'].value + pvSource=self._parameters['pvSource'].value + svSource=self._parameters['svSource'].value + elSource=self._parameters['elSource'].value + muSource=self._parameters['muSource'].value + runIVF=self._parameters['runIVF'].value + svClustering=self._parameters['svClustering'].value + fatJets=self._parameters['fatJets'].value + groomedFatJets=self._parameters['groomedFatJets'].value + algo=self._parameters['algo'].value + rParam=self._parameters['rParam'].value + jetCorrections=self._parameters['jetCorrections'].value + btagDiscriminators=list(self._parameters['btagDiscriminators'].value) + btagInfos=list(self._parameters['btagInfos'].value) + + ## a list of all producer modules, which are already known to process + knownModules = process.producerNames().split() + ## determine whether btagging information is required or not + if btagDiscriminators.count('None')>0: + btagDiscriminators.remove('None') + if btagInfos.count('None')>0: + btagInfos.remove('None') + bTagging=(len(btagDiscriminators)>0 or len(btagInfos)>0) + + ## construct postfix label for auxiliary modules; this postfix + ## label will start with a capitalized first letter following + ## the CMS naming conventions and for improved readablility + _labelName=labelName[:1].upper()+labelName[1:] + + ## supported algo types are ak, ca, and kt + _algo='' + for x in ["ak", "ca", "kt"]: + if x in algo.lower(): + _algo=supportedJetAlgos[x] + break + if _algo=='': + unsupportedJetAlgorithm(self) + ## add new updatedPatJets to process (keep instance for later further modifications) + from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cfi import updatedPatJets + if 'updatedPatJets'+_labelName+postfix in knownModules : + _newPatJets=getattr(process, 'updatedPatJets'+_labelName+postfix) + _newPatJets.jetSource=jetSource + else : + setattr(process, 'updatedPatJets'+_labelName+postfix, updatedPatJets.clone(jetSource=jetSource)) + _newPatJets=getattr(process, 'updatedPatJets'+_labelName+postfix) + knownModules.append('updatedPatJets'+_labelName+postfix) + ## add new selectedUpdatedPatJets to process + from PhysicsTools.PatAlgos.selectionLayer1.jetSelector_cfi import selectedPatJets + if 'selectedUpdatedPatJets'+_labelName+postfix in knownModules : + _newSelectedPatJets=getattr(process, 'selectedUpdatedPatJets'+_labelName+postfix) + _newSelectedPatJets.src='updatedPatJets'+_labelName+postfix + else : + setattr(process, 'selectedUpdatedPatJets'+_labelName+postfix, selectedPatJets.clone(src='updatedPatJets'+_labelName+postfix)) + knownModules.append('selectedUpdatedPatJets'+_labelName+postfix) + + ## add jet correction factors if required by user + if (jetCorrections != None): + ## check the jet corrections format + checkJetCorrectionsFormat(jetCorrections) + ## reset MET corrrection + if jetCorrections[2].lower() != 'none' and jetCorrections[2] != '': + print "-------------------------------------------------------------------" + print " Warning: MET correction was set to " + jetCorrections[2] + " but" + print " will be ignored. Please set it to \"None\" to avoid" + print " getting this warning." + print "-------------------------------------------------------------------" + jetCorrectionsList = list(jetCorrections) + jetCorrectionsList[2] = 'None' + jetCorrections = tuple(jetCorrectionsList) + ## setup jet energy corrections + setupJetCorrections(process, knownModules, jetCorrections, jetSource, pvSource, _newPatJets, _labelName, postfix) + else: + ## switch jetCorrFactors off + _newPatJets.addJetCorrFactors=False + +updateJetCollection=UpdateJetCollection() + + class AddJetID(ConfigToolBase): """ Compute jet id for process From 66f042d81630342f5d829717837f6026162102c4 Mon Sep 17 00:00:00 2001 From: Dinko Ferencek Date: Wed, 30 Dec 2015 10:04:33 -0600 Subject: [PATCH 2/6] updated example (cherry picked from commit 672af81715804b8ec1e5d6dda30c13e6b6303afc) --- .../patTuple_updateJets_fromMiniAOD_cfg.py | 67 +++++++++++++++++++ PhysicsTools/PatAlgos/test/runtests.sh | 5 +- .../PatAlgos/test/update_jets_from_MiniAOD.py | 61 ----------------- 3 files changed, 70 insertions(+), 63 deletions(-) create mode 100644 PhysicsTools/PatAlgos/test/patTuple_updateJets_fromMiniAOD_cfg.py delete mode 100644 PhysicsTools/PatAlgos/test/update_jets_from_MiniAOD.py diff --git a/PhysicsTools/PatAlgos/test/patTuple_updateJets_fromMiniAOD_cfg.py b/PhysicsTools/PatAlgos/test/patTuple_updateJets_fromMiniAOD_cfg.py new file mode 100644 index 0000000000000..30f8a585133dd --- /dev/null +++ b/PhysicsTools/PatAlgos/test/patTuple_updateJets_fromMiniAOD_cfg.py @@ -0,0 +1,67 @@ +# This configuration is an example that recalibrates the slimmedJets from MiniAOD +# and adds a new userfloat "oldJetMass" to it + +## import skeleton process +from PhysicsTools.PatAlgos.patTemplate_cfg import * +## switch to uncheduled mode +process.options.allowUnscheduled = cms.untracked.bool(True) +#process.Tracer = cms.Service("Tracer") + +## uncomment the following line to update different jet collections +## and add them to the event content +from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection + +## An example where the jet energy correction are updated to the current GlobalTag +## and a userFloat containing the previous mass of the jet is added +from RecoJets.Configuration.RecoPFJets_cff import ak8PFJetsCHSSoftDropMass +process.oldJetMass = ak8PFJetsCHSSoftDropMass.clone( + src = cms.InputTag("slimmedJets"), + matched = cms.InputTag("slimmedJets") ) + +updateJetCollection( + process, + jetSource = cms.InputTag('slimmedJets'), + jetCorrections = ('AK4PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute']), 'None') +) +process.updatedPatJets.userData.userFloats.src += ['oldJetMass'] + +## An example where the jet correction is undone +updateJetCollection( + process, + labelName = 'UndoneJEC', + jetSource = cms.InputTag('slimmedJets'), + jetCorrections = ('AK4PFchs', cms.vstring([]), 'None') +) +process.updatedPatJetsUndoneJEC.userData.userFloats.src = [] + +## An example where the jet correction are reapplied +updateJetCollection( + process, + labelName = 'ReappliedJEC', + jetSource = cms.InputTag('selectedUpdatedPatJetsUndoneJEC'), + jetCorrections = ('AK4PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute']), 'None') +) +process.updatedPatJetsReappliedJEC.userData.userFloats.src = [] + +## ------------------------------------------------------ +# In addition you usually want to change the following +# parameters: +## ------------------------------------------------------ +# +# process.GlobalTag.globaltag = ... ## (according to https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideFrontierConditions) +# ## +from PhysicsTools.PatAlgos.patInputFiles_cff import filesRelValTTbarPileUpMINIAODSIM +process.source.fileNames = filesRelValTTbarPileUpMINIAODSIM +# ## +process.maxEvents.input = 100 +# ## +from Configuration.EventContent.EventContent_cff import MINIAODSIMEventContent +process.out.outputCommands = MINIAODSIMEventContent.outputCommands +process.out.outputCommands.append('keep *_selectedUpdatedPatJets*_*_*') +process.out.outputCommands.append('drop *_selectedUpdatedPatJets*_caloTowers_*') +process.out.outputCommands.append('drop *_selectedUpdatedPatJets*_genJets_*') +process.out.outputCommands.append('drop *_selectedUpdatedPatJets*_pfCandidates_*') +# ## +process.out.fileName = 'patTuple_updateJets_fromMiniAOD.root' +# ## +# process.options.wantSummary = False ## (to suppress the long output at the end of the job) diff --git a/PhysicsTools/PatAlgos/test/runtests.sh b/PhysicsTools/PatAlgos/test/runtests.sh index 7e6681817197a..b322cbccd5ae3 100755 --- a/PhysicsTools/PatAlgos/test/runtests.sh +++ b/PhysicsTools/PatAlgos/test/runtests.sh @@ -15,8 +15,7 @@ cmsRun ${LOCAL_TEST_DIR}/patTuple_addDecayInFlight_cfg.py || die 'Failure using cmsRun ${LOCAL_TEST_DIR}/patTuple_addBTagging_cfg.py || die 'Failure using patTuple_addBTagging_cfg.py' $? -#broken now -#cmsRun ${LOCAL_TEST_DIR}/patTuple_addJets_cfg.py || die 'Failure using patTuple_addJets_cfg.py' $? +cmsRun ${LOCAL_TEST_DIR}/patTuple_addJets_cfg.py || die 'Failure using patTuple_addJets_cfg.py' $? cmsRun ${LOCAL_TEST_DIR}/patTuple_addTracks_cfg.py || die 'Failure using patTuple_addTracks_cfg.py' $? @@ -36,6 +35,8 @@ cmsRun ${LOCAL_TEST_DIR}/patTuple_fastsim_cfg.py || die 'Failure using patTuple_ cmsRun ${LOCAL_TEST_DIR}/patTuple_metUncertainties_cfg.py || die 'Failure using patTuple_metUncertainties_cfg.py' $? +cmsRun ${LOCAL_TEST_DIR}/patTuple_updateJets_fromMiniAOD_cfg.py || die 'Failure using patTuple_updateJets_fromMiniAOD_cfg.py' $? + #---- disabled while the release is still open and changes to AOD event content are still allowed #cmsRun ${LOCAL_TEST_DIR}/patMiniAOD_standard_cfg.py || die 'Failure using patMiniAOD_standard_cfg.py' $? diff --git a/PhysicsTools/PatAlgos/test/update_jets_from_MiniAOD.py b/PhysicsTools/PatAlgos/test/update_jets_from_MiniAOD.py deleted file mode 100644 index c5f01917256d3..0000000000000 --- a/PhysicsTools/PatAlgos/test/update_jets_from_MiniAOD.py +++ /dev/null @@ -1,61 +0,0 @@ -# This configuration is an example that recalibrates the slimmedJets from MiniAOD -# and adds a new userfloat "oldJetMass" to it - -import FWCore.ParameterSet.Config as cms - -process = cms.Process("PATUPDATE") -process.load("FWCore.MessageLogger.MessageLogger_cfi") - -from PhysicsTools.PatAlgos.patInputFiles_cff import filesRelValTTbarPileUpMINIAODSIM -process.source = cms.Source("PoolSource", - fileNames = filesRelValTTbarPileUpMINIAODSIM -) - -process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(100) ) - -process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") -from Configuration.AlCa.GlobalTag import GlobalTag -process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc') - -process.load("PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff") - -# An example where the jet energy correction are updated to the GlobalTag given above -# and a usedfloat containing the previous mass of the jet is added -from RecoJets.Configuration.RecoPFJets_cff import ak8PFJetsCHSSoftDropMass -process.oldJetMass = ak8PFJetsCHSSoftDropMass.clone( - src = cms.InputTag("slimmedJets"), - matched = cms.InputTag("slimmedJets") ) -process.patJetsUpdated.userData.userFloats.src += ['oldJetMass'] -process.p = cms.Path( process.oldJetMass + process.makePatJetsUpdated ) - -# An example where the jet correction is undone -process.patJetCorrFactorsUndoJEC = process.patJetCorrFactorsUpdated.clone( - src = cms.InputTag("patJetsUpdated"), - levels = [] ) -process.patJetsUndoJEC = process.patJetsUpdated.clone( - jetSource = cms.InputTag("patJetsUpdated"), - jetCorrFactorsSource = cms.VInputTag(cms.InputTag("patJetCorrFactorsUndoJEC")) - ) -process.patJetsUndoJEC.userData.userFloats.src = [] -process.p += cms.Sequence( process.patJetCorrFactorsUndoJEC + process. patJetsUndoJEC ) - -# An example where the jet correction are reapplied -process.patJetCorrFactorsReapplyJEC = process.patJetCorrFactorsUpdated.clone( - src = cms.InputTag("patJetsUndoJEC"), - levels = ['L1FastJet', - 'L2Relative', - 'L3Absolute'] ) -process.patJetsReapplyJEC = process.patJetsUpdated.clone( - jetSource = cms.InputTag("patJetsUndoJEC"), - jetCorrFactorsSource = cms.VInputTag(cms.InputTag("patJetCorrFactorsReapplyJEC")) - ) -process.patJetsReapplyJEC.userData.userFloats.src = [] -process.p += cms.Sequence( process.patJetCorrFactorsReapplyJEC + process. patJetsReapplyJEC ) - -process.out = cms.OutputModule("PoolOutputModule", - fileName = cms.untracked.string("patTupleUpdated.root"), - outputCommands = cms.untracked.vstring('keep *') - ) - -process.endpath = cms.EndPath(process.out) - From 12c6649024c3eb4026d7a2b5dab87319a33b0350 Mon Sep 17 00:00:00 2001 From: Dinko Ferencek Date: Wed, 30 Dec 2015 15:50:12 -0600 Subject: [PATCH 3/6] quieting down warning printouts (cherry picked from commit b8e893473480f0a5ea971c06d3ab74f8b8d39c76) --- PhysicsTools/PatAlgos/plugins/PATJetProducer.cc | 12 ++++++------ PhysicsTools/PatAlgos/plugins/PATJetProducer.h | 2 ++ PhysicsTools/PatAlgos/plugins/PATJetUpdater.cc | 12 ++++++------ PhysicsTools/PatAlgos/plugins/PATJetUpdater.h | 2 ++ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATJetProducer.cc b/PhysicsTools/PatAlgos/plugins/PATJetProducer.cc index d91d211279c97..2b8fa66a89738 100755 --- a/PhysicsTools/PatAlgos/plugins/PATJetProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATJetProducer.cc @@ -41,7 +41,8 @@ using namespace pat; PATJetProducer::PATJetProducer(const edm::ParameterSet& iConfig) : - useUserData_(iConfig.exists("userData")) + useUserData_(iConfig.exists("userData")), + printWarning_(true) { // initialize configurables jetsToken_ = consumes >(iConfig.getParameter( "jetSource" )); @@ -220,7 +221,6 @@ void PATJetProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup edm::RefProd h_pfCandidatesOut = iEvent.getRefBeforePut ( "pfCandidates" ); edm::RefProd > h_tagInfosOut = iEvent.getRefBeforePut > ( "tagInfos" ); - bool first=true; // this is introduced to issue warnings only for the first jet for (edm::View::const_iterator itJet = jets->begin(); itJet != jets->end(); itJet++) { // construct the Jet from the ref -> save ref to original object @@ -292,10 +292,10 @@ void PATJetProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup } else{ ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("Uncorrected")); - if(first){ - edm::LogWarning("L3Absolute not found") << "L2L3Residual and L3Absolute are not part of the correction applied jetCorrFactors \n" - << "of module " << jetCorrs[0][jetRef].jecSet() << " jets will remain" - << " uncorrected."; first=false; + if(printWarning_){ + edm::LogWarning("L3Absolute not found") << "L2L3Residual and L3Absolute are not part of the jetCorrFactors\n" + << "of module " << jetCorrs[0][jetRef].jecSet() << ". Jets will remain" + << " uncorrected."; printWarning_=false; } } } diff --git a/PhysicsTools/PatAlgos/plugins/PATJetProducer.h b/PhysicsTools/PatAlgos/plugins/PATJetProducer.h index ea2b24b15222d..37e70f2b8c2f1 100644 --- a/PhysicsTools/PatAlgos/plugins/PATJetProducer.h +++ b/PhysicsTools/PatAlgos/plugins/PATJetProducer.h @@ -104,6 +104,8 @@ namespace pat { bool useUserData_; pat::PATUserDataHelper userDataHelper_; + // + bool printWarning_; // this is introduced to issue warnings only once per job diff --git a/PhysicsTools/PatAlgos/plugins/PATJetUpdater.cc b/PhysicsTools/PatAlgos/plugins/PATJetUpdater.cc index ffd4e1a40abf6..654e2d971c305 100755 --- a/PhysicsTools/PatAlgos/plugins/PATJetUpdater.cc +++ b/PhysicsTools/PatAlgos/plugins/PATJetUpdater.cc @@ -26,7 +26,8 @@ using namespace pat; PATJetUpdater::PATJetUpdater(const edm::ParameterSet& iConfig) : - useUserData_(iConfig.exists("userData")) + useUserData_(iConfig.exists("userData")), + printWarning_(true) { // initialize configurables jetsToken_ = consumes >(iConfig.getParameter( "jetSource" )); @@ -65,7 +66,6 @@ void PATJetUpdater::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) // loop over jets std::auto_ptr< std::vector > patJets ( new std::vector() ); - bool first=true; // this is introduced to issue warnings only for the first jet for (edm::View::const_iterator itJet = jets->begin(); itJet != jets->end(); itJet++) { // construct the Jet from the ref -> save ref to original object @@ -94,10 +94,10 @@ void PATJetUpdater::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) } else{ ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("Uncorrected"), JetCorrFactors::NONE, setindex); - if(first){ - edm::LogWarning("L3Absolute not found") << "L2L3Residual and L3Absolute are not part of the correction applied jetCorrFactors \n" - << "of module " << jetCorrs[0][jetRef].jecSet() << " jets will remain" - << " uncorrected."; first=false; + if(printWarning_){ + edm::LogWarning("L3Absolute not found") << "L2L3Residual and L3Absolute are not part of the jetCorrFactors\n" + << "of module " << jetCorrs[0][jetRef].jecSet() << ". Jets will remain" + << " uncorrected."; printWarning_=false; } } } diff --git a/PhysicsTools/PatAlgos/plugins/PATJetUpdater.h b/PhysicsTools/PatAlgos/plugins/PATJetUpdater.h index 99e8fff150088..4f171f90d6ced 100644 --- a/PhysicsTools/PatAlgos/plugins/PATJetUpdater.h +++ b/PhysicsTools/PatAlgos/plugins/PATJetUpdater.h @@ -53,6 +53,8 @@ namespace pat { bool useUserData_; pat::PATUserDataHelper userDataHelper_; + // + bool printWarning_; // this is introduced to issue warnings only once per job }; From d4f7055d5d46d511c967078ee58e661d3275a375 Mon Sep 17 00:00:00 2001 From: Dinko Ferencek Date: Wed, 30 Dec 2015 17:38:12 -0600 Subject: [PATCH 4/6] added b-tag info to the PATJetUpdater (cherry picked from commit e3b98e2080909aae1afff9554ec6f113419a38f8) --- .../PatAlgos/plugins/PATJetUpdater.cc | 118 ++++++++++++++++-- PhysicsTools/PatAlgos/plugins/PATJetUpdater.h | 12 +- .../python/producersLayer1/jetUpdater_cfi.py | 9 ++ .../PatAlgos/python/tools/jetTools.py | 46 ++++++- .../patTuple_updateJets_fromMiniAOD_cfg.py | 8 +- 5 files changed, 180 insertions(+), 13 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATJetUpdater.cc b/PhysicsTools/PatAlgos/plugins/PATJetUpdater.cc index 654e2d971c305..c7408b62c9d41 100755 --- a/PhysicsTools/PatAlgos/plugins/PATJetUpdater.cc +++ b/PhysicsTools/PatAlgos/plugins/PATJetUpdater.cc @@ -30,15 +30,50 @@ PATJetUpdater::PATJetUpdater(const edm::ParameterSet& iConfig) : printWarning_(true) { // initialize configurables - jetsToken_ = consumes >(iConfig.getParameter( "jetSource" )); + jetsToken_ = consumes >(iConfig.getParameter( "jetSource" )); addJetCorrFactors_ = iConfig.getParameter( "addJetCorrFactors" ); - jetCorrFactorsTokens_ = edm::vector_transform(iConfig.getParameter >( "jetCorrFactorsSource" ), [this](edm::InputTag const & tag){return mayConsume >(tag);}); + if( addJetCorrFactors_ ) { + jetCorrFactorsTokens_ = edm::vector_transform(iConfig.getParameter >( "jetCorrFactorsSource" ), [this](edm::InputTag const & tag){return mayConsume >(tag);}); + } + addBTagInfo_ = iConfig.getParameter( "addBTagInfo" ); + addDiscriminators_ = iConfig.getParameter( "addDiscriminators" ); + discriminatorTags_ = iConfig.getParameter >( "discriminatorSources" ); + discriminatorTokens_ = edm::vector_transform(discriminatorTags_, [this](edm::InputTag const & tag){return mayConsume(tag);}); + addTagInfos_ = iConfig.getParameter( "addTagInfos" ); + tagInfoTags_ = iConfig.getParameter >( "tagInfoSources" ); + tagInfoTokens_ =edm::vector_transform(tagInfoTags_, [this](edm::InputTag const & tag){return mayConsume >(tag);}); + if (discriminatorTags_.empty()) { + addDiscriminators_ = false; + } else { + for (std::vector::const_iterator it = discriminatorTags_.begin(), ed = discriminatorTags_.end(); it != ed; ++it) { + std::string label = it->label(); + std::string::size_type pos = label.find("JetTags"); + if ((pos != std::string::npos) && (pos != label.length() - 7)) { + label.erase(pos+7); // trim a tail after "JetTags" + } + discriminatorLabels_.push_back(label); + } + } + if (tagInfoTags_.empty()) { + addTagInfos_ = false; + } else { + for (std::vector::const_iterator it = tagInfoTags_.begin(), ed = tagInfoTags_.end(); it != ed; ++it) { + std::string label = it->label(); + std::string::size_type pos = label.find("TagInfos"); + if ((pos != std::string::npos) && (pos != label.length() - 8)) { + label.erase(pos+8); // trim a tail after "TagInfos" + } + tagInfoLabels_.push_back(label); + } + } + if (!addBTagInfo_) { addDiscriminators_ = false; addTagInfos_ = false; } // Check to see if the user wants to add user data if ( useUserData_ ) { userDataHelper_ = PATUserDataHelper(iConfig.getParameter("userData"), consumesCollector()); } // produces vector of jets produces >(); + produces > ("tagInfos"); } @@ -50,7 +85,7 @@ PATJetUpdater::~PATJetUpdater() { void PATJetUpdater::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) { // Get the vector of jets - edm::Handle > jets; + edm::Handle > jets; iEvent.getByToken(jetsToken_, jets); // read in the jet correction factors ValueMap @@ -63,16 +98,36 @@ void PATJetUpdater::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) } } + // Get the vector of jet tags with b-tagging info + std::vector > jetDiscriminators; + if (addBTagInfo_ && addDiscriminators_) { + jetDiscriminators.resize(discriminatorTokens_.size()); + for (size_t i = 0; i < discriminatorTokens_.size(); ++i) { + iEvent.getByToken(discriminatorTokens_[i], jetDiscriminators[i]); + } + } + std::vector > > jetTagInfos; + if (addBTagInfo_ && addTagInfos_) { + jetTagInfos.resize(tagInfoTokens_.size()); + for (size_t i = 0; i < tagInfoTokens_.size(); ++i) { + iEvent.getByToken(tagInfoTokens_[i], jetTagInfos[i]); + } + } + // loop over jets std::auto_ptr< std::vector > patJets ( new std::vector() ); - for (edm::View::const_iterator itJet = jets->begin(); itJet != jets->end(); itJet++) { + std::auto_ptr > tagInfosOut ( new edm::OwnVector() ); + + edm::RefProd > h_tagInfosOut = iEvent.getRefBeforePut > ( "tagInfos" ); + + for (edm::View::const_iterator itJet = jets->begin(); itJet != jets->end(); itJet++) { // construct the Jet from the ref -> save ref to original object unsigned int idx = itJet - jets->begin(); - edm::RefToBase jetRef = jets->refAt(idx); - edm::Ptr jetPtr = jets->ptrAt(idx); - Jet ajet(jetPtr); + edm::RefToBase jetRef = jets->refAt(idx); + edm::Ptr jetPtr = jets->ptrAt(idx); + Jet ajet( edm::RefToBase(jetRef.castTo()) ); if (addJetCorrFactors_) { unsigned int setindex = ajet.availableJECSets().size(); @@ -102,6 +157,42 @@ void PATJetUpdater::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) } } + // add b-tag info if available & required + if (addBTagInfo_) { + if (addDiscriminators_) { + for (size_t k=0; k & taginfos = *jetTagInfos[k]; + // This is not associative, so we have to search the jet + edm::Ptr match; + // Try first by 'same index' + if ((idx < taginfos.size()) && (taginfos[idx].jet() == jetRef)) { + match = taginfos.ptrAt(idx); + } else { + // otherwise fail back to a simple search + for (edm::View::const_iterator itTI = taginfos.begin(), edTI = taginfos.end(); itTI != edTI; ++itTI) { + if (itTI->jet() == jetRef) { match = taginfos.ptrAt( itTI - taginfos.begin() ); break; } + } + } + if (match.isNonnull()) { + tagInfosOut->push_back( match->clone() ); + // set the "forward" ptr to the thinned collection + edm::Ptr tagInfoForwardPtr ( h_tagInfosOut.id(), &tagInfosOut->back(), tagInfosOut->size() - 1 ); + // set the "backward" ptr to the original collection for association + edm::Ptr tagInfoBackPtr ( match ); + // make FwdPtr + TagInfoFwdPtrCollection::value_type tagInfoFwdPtr( tagInfoForwardPtr, tagInfoBackPtr ) ; + ajet.addTagInfo(tagInfoLabels_[k], tagInfoFwdPtr ); + } + } + } + } + if ( useUserData_ ) { userDataHelper_.add( ajet, iEvent, iSetup ); } @@ -115,6 +206,8 @@ void PATJetUpdater::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) // put genEvt in Event iEvent.put(patJets); + iEvent.put( tagInfosOut, "tagInfos" ); + } // ParameterSet description for module @@ -126,11 +219,20 @@ void PATJetUpdater::fillDescriptions(edm::ConfigurationDescriptions & descriptio // input source iDesc.add("jetSource", edm::InputTag("no default"))->setComment("input collection"); + // tag info + iDesc.add("addTagInfos", true); + std::vector emptyVInputTags; + iDesc.add >("tagInfoSources", emptyVInputTags); + // jet energy corrections iDesc.add("addJetCorrFactors", true); - std::vector emptyVInputTags; iDesc.add >("jetCorrFactorsSource", emptyVInputTags); + // btag discriminator tags + iDesc.add("addBTagInfo",true); + iDesc.add("addDiscriminators", true); + iDesc.add >("discriminatorSources", emptyVInputTags); + // Check to see if the user wants to add user data edm::ParameterSetDescription userDataPSet; PATUserDataHelper::fillDescription(userDataPSet); diff --git a/PhysicsTools/PatAlgos/plugins/PATJetUpdater.h b/PhysicsTools/PatAlgos/plugins/PATJetUpdater.h index 4f171f90d6ced..ffd61c8dff919 100644 --- a/PhysicsTools/PatAlgos/plugins/PATJetUpdater.h +++ b/PhysicsTools/PatAlgos/plugins/PATJetUpdater.h @@ -45,10 +45,20 @@ namespace pat { private: // configurables - edm::EDGetTokenT > jetsToken_; + edm::EDGetTokenT > jetsToken_; bool addJetCorrFactors_; std::vector > > jetCorrFactorsTokens_; + bool addBTagInfo_; + bool addDiscriminators_; + std::vector discriminatorTags_; + std::vector > discriminatorTokens_; + std::vector discriminatorLabels_; + bool addTagInfos_; + std::vector tagInfoTags_; + std::vector > > tagInfoTokens_; + std::vector tagInfoLabels_; + GreaterByPt pTComparator_; bool useUserData_; diff --git a/PhysicsTools/PatAlgos/python/producersLayer1/jetUpdater_cfi.py b/PhysicsTools/PatAlgos/python/producersLayer1/jetUpdater_cfi.py index 729cdb9f47262..f0c493dbdfac0 100644 --- a/PhysicsTools/PatAlgos/python/producersLayer1/jetUpdater_cfi.py +++ b/PhysicsTools/PatAlgos/python/producersLayer1/jetUpdater_cfi.py @@ -28,6 +28,15 @@ # jet energy corrections addJetCorrFactors = cms.bool(True), jetCorrFactorsSource = cms.VInputTag(cms.InputTag("updatedPatJetCorrFactors") ), + # btag information + addBTagInfo = cms.bool(True), ## master switch + addDiscriminators = cms.bool(True), ## addition of btag discriminators + discriminatorSources = cms.VInputTag(), + # clone tag infos ATTENTION: these take lots of space! + # usually the discriminators from the default algos + # are sufficient + addTagInfos = cms.bool(False), + tagInfoSources = cms.VInputTag() ) diff --git a/PhysicsTools/PatAlgos/python/tools/jetTools.py b/PhysicsTools/PatAlgos/python/tools/jetTools.py index 47553d0355734..8d8d611c1f29d 100644 --- a/PhysicsTools/PatAlgos/python/tools/jetTools.py +++ b/PhysicsTools/PatAlgos/python/tools/jetTools.py @@ -1078,8 +1078,49 @@ def toolCode(self, process): setattr(process, 'selectedUpdatedPatJets'+_labelName+postfix, selectedPatJets.clone(src='updatedPatJets'+_labelName+postfix)) knownModules.append('selectedUpdatedPatJets'+_labelName+postfix) + ## run btagging if required by user + if (bTagging): + print "**************************************************************" + print "b tagging needs to be run on uncorrected jets. Hence, the JECs" + print "will first be undone for 'updatedPatJets%s' and then applied to"%(_labelName+postfix) + print "'updatedPatJetsTransientCorrected%s'."%(_labelName+postfix) + print "**************************************************************" + _jetSource = cms.InputTag('updatedPatJets'+_labelName+postfix) + ## insert new jet collection with jet corrections applied and btag info added + self( + process, + labelName = ('TransientCorrected'+_labelName), + jetSource = _jetSource, + pfCandidates=pfCandidates, + explicitJTA=explicitJTA, + pvSource=pvSource, + svSource=svSource, + elSource=elSource, + muSource=muSource, + runIVF=runIVF, + svClustering=svClustering, + fatJets=fatJets, + groomedFatJets=groomedFatJets, + algo=algo, + rParam=rParam, + jetCorrections = jetCorrections, + postfix = postfix + ) + ## setup btagging + _patJets=getattr(process, 'updatedPatJetsTransientCorrected'+_labelName+postfix) + setupBTagging(process, _jetSource, pfCandidates, explicitJTA, pvSource, svSource, elSource, muSource, runIVF, svClustering, fatJets, groomedFatJets, + _algo, rParam, btagDiscriminators, btagInfos, _patJets, _labelName, postfix) + ## update final selected jets + _newSelectedPatJets=getattr(process, 'selectedUpdatedPatJets'+_labelName+postfix) + _newSelectedPatJets.src='updatedPatJetsTransientCorrected'+_labelName+postfix + ## remove automatically added but redundant 'TransientCorrected' selected jets + delattr(process, 'selectedUpdatedPatJetsTransientCorrected'+_labelName+postfix) + else: + _newPatJets.addBTagInfo = False + _newPatJets.addTagInfos = False + ## add jet correction factors if required by user - if (jetCorrections != None): + if (jetCorrections != None or bTagging): ## check the jet corrections format checkJetCorrectionsFormat(jetCorrections) ## reset MET corrrection @@ -1092,6 +1133,9 @@ def toolCode(self, process): jetCorrectionsList = list(jetCorrections) jetCorrectionsList[2] = 'None' jetCorrections = tuple(jetCorrectionsList) + ## if running b tagging, need to use uncorrected jets + if (bTagging): + jetCorrections = ('AK4PFchs', cms.vstring([]), 'None') ## setup jet energy corrections setupJetCorrections(process, knownModules, jetCorrections, jetSource, pvSource, _newPatJets, _labelName, postfix) else: diff --git a/PhysicsTools/PatAlgos/test/patTuple_updateJets_fromMiniAOD_cfg.py b/PhysicsTools/PatAlgos/test/patTuple_updateJets_fromMiniAOD_cfg.py index 30f8a585133dd..c5e83fd0a3c20 100644 --- a/PhysicsTools/PatAlgos/test/patTuple_updateJets_fromMiniAOD_cfg.py +++ b/PhysicsTools/PatAlgos/test/patTuple_updateJets_fromMiniAOD_cfg.py @@ -1,5 +1,5 @@ # This configuration is an example that recalibrates the slimmedJets from MiniAOD -# and adds a new userfloat "oldJetMass" to it +# and adds a new userfloat "oldJetMass" and an additional b-tag discriminator to them ## import skeleton process from PhysicsTools.PatAlgos.patTemplate_cfg import * @@ -12,7 +12,8 @@ from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection ## An example where the jet energy correction are updated to the current GlobalTag -## and a userFloat containing the previous mass of the jet is added +## and a userFloat containing the previous mass of the jet and an additional +## b-tag discriminator are added from RecoJets.Configuration.RecoPFJets_cff import ak8PFJetsCHSSoftDropMass process.oldJetMass = ak8PFJetsCHSSoftDropMass.clone( src = cms.InputTag("slimmedJets"), @@ -21,7 +22,8 @@ updateJetCollection( process, jetSource = cms.InputTag('slimmedJets'), - jetCorrections = ('AK4PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute']), 'None') + jetCorrections = ('AK4PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute']), 'None'), + btagDiscriminators = ['pfCombinedSecondaryVertexBJetTags'] ## adding an old (Run 1) version of the CSV discriminator ) process.updatedPatJets.userData.userFloats.src += ['oldJetMass'] From 03aa581fd8be2185901dad7727ec0117ff51bc40 Mon Sep 17 00:00:00 2001 From: Dinko Ferencek Date: Thu, 31 Dec 2015 16:28:20 -0600 Subject: [PATCH 5/6] reverse loops to get the latest b-tag info first (cherry picked from commit 2e95cd64bd5154d15b35b70e81458e4588997e01) --- DataFormats/PatCandidates/src/Jet.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/DataFormats/PatCandidates/src/Jet.cc b/DataFormats/PatCandidates/src/Jet.cc index 9abea8bf20e9c..bec721f72558b 100644 --- a/DataFormats/PatCandidates/src/Jet.cc +++ b/DataFormats/PatCandidates/src/Jet.cc @@ -352,23 +352,24 @@ const std::vector > & Jet::getPairDiscri() const { /// get b discriminant from label name float Jet::bDiscriminator(const std::string & aLabel) const { float discriminator = -1000.; - const std::string & theLabel = ((aLabel == "" || aLabel == "default")) ? "trackCountingHighEffBJetTags" : aLabel; - for(unsigned int i=0; i!=pairDiscriVector_.size(); i++){ - if(pairDiscriVector_[i].first == theLabel){ + for(int i=(int(pairDiscriVector_.size())-1); i>=0; i--){ + if(pairDiscriVector_[i].first == aLabel){ discriminator = pairDiscriVector_[i].second; + break; } } return discriminator; } const reco::BaseTagInfo * Jet::tagInfo(const std::string &label) const { - std::vector::const_iterator it = std::find(tagInfoLabels_.begin(), tagInfoLabels_.end(), label); - if (it != tagInfoLabels_.end()) { - if ( tagInfosFwdPtr_.size() > 0 ) return tagInfosFwdPtr_[it - tagInfoLabels_.begin()].get(); - else if ( tagInfos_.size() > 0 ) return & tagInfos_[it - tagInfoLabels_.begin()]; + for(int i=(int(tagInfoLabels_.size())-1); i>=0; i--){ + if (tagInfoLabels_[i] == label) { + if ( tagInfosFwdPtr_.size() > 0 ) return tagInfosFwdPtr_[i].get(); + else if ( tagInfos_.size() > 0 ) return & tagInfos_[i]; return 0; } - return 0; + } + return 0; } From 4d5fff25a7c151be733a4f155d7aa36119dc0db5 Mon Sep 17 00:00:00 2001 From: Dinko Ferencek Date: Thu, 14 Jan 2016 16:49:59 +0100 Subject: [PATCH 6/6] added missing SV clustering if statements (cherry picked from commit 5f36e28484ba1968cb793e0a5866313712b80576) --- PhysicsTools/PatAlgos/python/tools/jetTools.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/PhysicsTools/PatAlgos/python/tools/jetTools.py b/PhysicsTools/PatAlgos/python/tools/jetTools.py index 8d8d611c1f29d..b7c374b69dc3b 100644 --- a/PhysicsTools/PatAlgos/python/tools/jetTools.py +++ b/PhysicsTools/PatAlgos/python/tools/jetTools.py @@ -229,6 +229,8 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets) if btagInfo == 'pfInclusiveSecondaryVertexFinderTagInfosCA15': setattr(process, btagInfo+labelName+postfix, btag.pfInclusiveSecondaryVertexFinderTagInfosCA15.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterTagInfosCA15'+labelName+postfix), extSVCollection=svSource)) + if svClustering: + setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets) if btagInfo == 'pfInclusiveSecondaryVertexFinderCvsLTagInfos': setattr( process, @@ -273,8 +275,12 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou setattr(process, btagInfo+labelName+postfix, btag.secondaryVertexNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+labelName+postfix))) if btagInfo == 'inclusiveSecondaryVertexFinderNegativeTagInfos': setattr(process, btagInfo+labelName+postfix, btag.inclusiveSecondaryVertexFinderNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+labelName+postfix))) + if svClustering: + setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets) if btagInfo == 'inclusiveSecondaryVertexFinderFilteredNegativeTagInfos': setattr(process, btagInfo+labelName+postfix, btag.inclusiveSecondaryVertexFinderFilteredNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+labelName+postfix))) + if svClustering: + setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets) if btagInfo == 'softMuonTagInfos': setattr(process, btagInfo+labelName+postfix, btag.softMuonTagInfos.clone(jets = jetSource, primaryVertex=pvSource)) if btagInfo == 'softPFMuonsTagInfos':