Skip to content

Commit

Permalink
Merge pull request #15394 from cms-btv-pog/SubjetTagInfosNoClustering…
Browse files Browse the repository at this point in the history
…-PR_from-CMSSW_8_0_12

Subjet TagInfo updates (80X)
  • Loading branch information
davidlange6 authored Aug 10, 2016
2 parents 63d4e06 + 1f3a33b commit 7e24b0b
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 60 deletions.
10 changes: 7 additions & 3 deletions PhysicsTools/PatAlgos/plugins/PATJetUpdater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ void PATJetUpdater::produce(edm::Event & iEvent, const edm::EventSetup & iSetup)

// construct the Jet from the ref -> save ref to original object
unsigned int idx = itJet - jets->begin();
edm::RefToBase<reco::Jet> jetRef = jets->refAt(idx);
edm::Ptr<reco::Jet> jetPtr = jets->ptrAt(idx);
Jet ajet( edm::RefToBase<Jet>(jetRef.castTo<JetRef>()) );
const edm::RefToBase<reco::Jet> jetRef = jets->refAt(idx);
const edm::RefToBase<Jet> patJetRef(jetRef.castTo<JetRef>());
Jet ajet( patJetRef );

if (addJetCorrFactors_) {
// undo previous jet energy corrections
Expand Down Expand Up @@ -198,6 +198,10 @@ void PATJetUpdater::produce(edm::Event & iEvent, const edm::EventSetup & iSetup)
userDataHelper_.add( ajet, iEvent, iSetup );
}

// reassign the original object reference to preserve reference to the original jet the input PAT jet was derived from
// (this needs to be done at the end since cloning the input PAT jet would interfere with adding UserData)
ajet.refToOrig_ = patJetRef->originalObjectRef();

patJets->push_back(ajet);
}

Expand Down
61 changes: 31 additions & 30 deletions PhysicsTools/PatAlgos/python/tools/jetTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,15 @@ def setupJetCorrections(process, knownModules, jetCorrections, jetSource, pvSour
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)
btagInfo.jetAlgorithm = cms.string(algo)
btagInfo.rParam = cms.double(rParam)
## if the jets is actually a subjet
if fatJets != cms.InputTag('') and groomedFatJets != cms.InputTag(''):
btagInfo.fatJets = fatJets
btagInfo.groomedFatJets = groomedFatJets
def setupSVClustering(btagInfo, svClustering, algo, rParam, fatJets=cms.InputTag(''), groomedFatJets=cms.InputTag('')):
btagInfo.useSVClustering = cms.bool(svClustering)
btagInfo.jetAlgorithm = cms.string(algo)
btagInfo.rParam = cms.double(rParam)
## if the jet is actually a subjet
if fatJets != cms.InputTag(''):
btagInfo.fatJets = fatJets
if groomedFatJets != cms.InputTag(''):
btagInfo.groomedFatJets = groomedFatJets


def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSource, elSource, muSource, runIVF, loadStdRecoBTag, svClustering, fatJets, groomedFatJets,
Expand Down Expand Up @@ -225,16 +226,16 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
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 svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfInclusiveSecondaryVertexFinderAK8TagInfos':
setattr(process, btagInfo+labelName+postfix, btag.pfInclusiveSecondaryVertexFinderAK8TagInfos.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterAK8TagInfos'+labelName+postfix), extSVCollection=svSource))
if svClustering:
setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfInclusiveSecondaryVertexFinderCA15TagInfos':
setattr(process, btagInfo+labelName+postfix, btag.pfInclusiveSecondaryVertexFinderCA15TagInfos.clone(trackIPTagInfos = cms.InputTag('pfImpactParameterCA15TagInfos'+labelName+postfix), extSVCollection=svSource))
if svClustering:
setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfInclusiveSecondaryVertexFinderCvsLTagInfos':
setattr(
process,
Expand All @@ -244,8 +245,8 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
extSVCollection=svSource
)
)
if svClustering:
setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfInclusiveSecondaryVertexFinderCvsBTagInfos':
setattr(
process,
Expand All @@ -255,8 +256,8 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
extSVCollection=svSource
)
)
if svClustering:
setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos':
setattr(
process,
Expand All @@ -266,36 +267,36 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
extSVCollection=svSource
)
)
if svClustering:
setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagInfo+labelName+postfix), svClustering, 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 svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagInfo+labelName+postfix), svClustering, 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 svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagInfo+labelName+postfix), svClustering, 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 svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagInfo+labelName+postfix), svClustering, 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 svClustering:
setupSVClustering(getattr(process, btagInfo+labelName+postfix), algo, rParam, fatJets, groomedFatJets)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagInfo+labelName+postfix), svClustering, 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 svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'softMuonTagInfos':
setattr(process, btagInfo+labelName+postfix, btag.softMuonTagInfos.clone(jets = jetSource, primaryVertex=pvSource))
if btagInfo == 'softPFMuonsTagInfos':
Expand Down
20 changes: 18 additions & 2 deletions PhysicsTools/PatAlgos/test/patTuple_updateJets_fromMiniAOD_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)
process.updatedPatJets.userData.userFloats.src += ['oldJetMass']

## An example where the jet correction is undone
## An example where the jet corrections are undone
updateJetCollection(
process,
labelName = 'UndoneJEC',
Expand All @@ -36,7 +36,7 @@
)
process.updatedPatJetsUndoneJEC.userData.userFloats.src = []

## An example where the jet correction are reapplied
## An example where the jet corrections are reapplied
updateJetCollection(
process,
labelName = 'ReappliedJEC',
Expand All @@ -45,6 +45,22 @@
)
process.updatedPatJetsReappliedJEC.userData.userFloats.src = []

## An example where the jet energy corrections are updated to the current GlobalTag
## and specified b-tag discriminators are rerun and added to SoftDrop subjets
updateJetCollection(
process,
labelName = 'SoftDropSubjets',
jetSource = cms.InputTag('slimmedJetsAK8PFCHSSoftDropPacked:SubJets'),
jetCorrections = ('AK4PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute']), 'None'),
btagDiscriminators = ['pfCombinedSecondaryVertexV2BJetTags', 'pfCombinedInclusiveSecondaryVertexV2BJetTags'],
explicitJTA = True, # needed for subjet b tagging
svClustering = False, # needed for subjet b tagging (IMPORTANT: Needs to be set to False to disable ghost-association which does not work with slimmed jets)
fatJets = cms.InputTag('slimmedJetsAK8'), # needed for subjet b tagging
rParam = 0.8, # needed for subjet b tagging
algo = 'ak' # has to be defined but is not used with svClustering=False
)
process.updatedPatJetsSoftDropSubjets.userData.userFloats.src = []

## ------------------------------------------------------
# In addition you usually want to change the following
# parameters:
Expand Down
Loading

0 comments on commit 7e24b0b

Please sign in to comment.