diff --git a/PhysicsTools/NanoAOD/python/jets_cff.py b/PhysicsTools/NanoAOD/python/jets_cff.py index 9dd55841396af..327f4eb4a1d7e 100644 --- a/PhysicsTools/NanoAOD/python/jets_cff.py +++ b/PhysicsTools/NanoAOD/python/jets_cff.py @@ -16,7 +16,7 @@ from RecoJets.JetProducers.ak4PFJets_cfi import ak4PFJets chsForSATkJets = cms.EDFilter("CandPtrSelector", src = cms.InputTag("packedPFCandidates"), cut = cms.string('charge()!=0 && pvAssociationQuality()>=5 && vertexRef().key()==0')) -softActivityJets = ak4PFJets.clone(src = 'chsForSATkJets', doAreaFastjet = False, jetPtMin=1) +softActivityJets = ak4PFJets.clone(src = 'chsForSATkJets', doAreaFastjet = False, jetPtMin=1) softActivityJets10 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("softActivityJets"), cut = cms.string('pt>10')) softActivityJets5 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("softActivityJets"), cut = cms.string('pt>5')) softActivityJets2 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("softActivityJets"), cut = cms.string('pt>2')) @@ -128,7 +128,7 @@ ) jercVars = cms.EDProducer("BetaStarPackedCandidateVarProducer", - srcJet = cms.InputTag("updatedJets"), + srcJet = cms.InputTag("updatedJets"), srcPF = cms.InputTag("packedPFCandidates"), maxDR = cms.double(0.4) ) @@ -154,16 +154,18 @@ qgl = cms.InputTag('qgtagger:qgLikelihood'), puId94XDisc = cms.InputTag('pileupJetId94X:fullDiscriminant'), puId102XDisc = cms.InputTag('pileupJetId102X:fullDiscriminant'), + puId106XUL17Disc = cms.InputTag('pileupJetId106XUL17:fullDiscriminant'), chFPV0EF = cms.InputTag("jercVars:chargedFromPV0EnergyFraction"), chFPV1EF = cms.InputTag("jercVars:chargedFromPV1EnergyFraction"), chFPV2EF = cms.InputTag("jercVars:chargedFromPV2EnergyFraction"), - chFPV3EF = cms.InputTag("jercVars:chargedFromPV3EnergyFraction"), + chFPV3EF = cms.InputTag("jercVars:chargedFromPV3EnergyFraction"), ), userInts = cms.PSet( tightId = cms.InputTag("tightJetId"), tightIdLepVeto = cms.InputTag("tightJetIdLepVeto"), vtxNtrk = cms.InputTag("bJetVars:vtxNtrk"), leptonPdgId = cms.InputTag("bJetVars:leptonPdgId"), + puId106XUL17Id = cms.InputTag('pileupJetId106XUL17:fullId'), ), ) for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016: @@ -235,8 +237,8 @@ btagDeepFlavCvL = Var("?(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg'))>0?bDiscriminator('pfDeepFlavourJetTags:probc')/(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg')):-1",float,doc="DeepJet c vs uds+g discriminator",precision=10), btagDeepFlavCvB = Var("?(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb'))>0?bDiscriminator('pfDeepFlavourJetTags:probc')/(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')):-1",float,doc="DeepJet c vs b+bb+lepb discriminator",precision=10), btagDeepFlavQG = Var("?(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds'))>0?bDiscriminator('pfDeepFlavourJetTags:probg')/(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds')):-1",float,doc="DeepJet g vs uds discriminator",precision=10), - puIdDisc = Var("userFloat('puId102XDisc')",float,doc="Pilup ID discriminant with 102X (2018) training",precision=10), - puId = Var("userInt('pileupJetId:fullId')",int,doc="Pilup ID flags with 80X (2016) training"), + puIdDisc = Var("userFloat('puId102XDisc')",float,doc="Pileup ID discriminant with 102X (2018) training",precision=10), + puId = Var("userInt('pileupJetId:fullId')",int,doc="Pileup ID flags for pre-UL trainings"), jetId = Var("userInt('tightId')*2+4*userInt('tightIdLepVeto')",int,doc="Jet ID flags bit1 is loose (always false in 2017 since it does not exist), bit2 is tight, bit3 is tightLepVeto"), qgl = Var("userFloat('qgl')",float,doc="Quark vs Gluon likelihood discriminator",precision=10), hfsigmaEtaEta = Var("userFloat('hfJetShowerShape:sigmaEtaEta')",float,doc="sigmaEtaEta for HF jets (noise discriminating variable)",precision=10), @@ -269,9 +271,14 @@ btagDeepFlavC = Var("bDiscriminator('pfDeepFlavourJetTags:probc')",float,doc="DeepFlavour charm tag discriminator",precision=10), ) for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016: - modifier.toModify( jetTable.variables, jetId = Var("userInt('tightIdLepVeto')*4+userInt('tightId')*2+userInt('looseId')",int,doc="Jet ID flags bit1 is loose, bit2 is tight, bit3 is tightLepVeto")) -run2_jme_2016.toModify( jetTable.variables, puIdDisc = Var("userFloat('pileupJetId:fullDiscriminant')",float,doc="Pilup ID discriminant with 80X (2016) training",precision=10)) -run2_jme_2017.toModify( jetTable.variables, puIdDisc = Var("userFloat('puId94XDisc')", float,doc="Pilup ID discriminant with 94X (2017) training",precision=10)) + modifier.toModify( jetTable.variables, jetId = Var("userInt('tightIdLepVeto')*4+userInt('tightId')*2+userInt('looseId')",int,doc="Jet ID flags bit1 is loose, bit2 is tight, bit3 is tightLepVeto")) +run2_jme_2016.toModify( jetTable.variables, puIdDisc = Var("userFloat('pileupJetId:fullDiscriminant')",float,doc="Pileup ID discriminant with 80X (2016) training",precision=10)) +run2_jme_2017.toModify( jetTable.variables, puId = Var("userInt('puId106XUL17Id')", int,doc="Pileup ID flags with 106X (2017) training")) +run2_jme_2017.toModify( jetTable.variables, puIdDisc = Var("userFloat('puId106XUL17Disc')", float,doc="Pileup ID discriminant with 106X (2017) training",precision=10)) +for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2: + modifier.toModify( jetTable.variables, puIdDisc = Var("userFloat('puId94XDisc')", float,doc="Pileup ID discriminant with 94X (2017) training",precision=10)) + modifier.toModify( jetTable.variables, puId = Var("userInt('pileupJetId:fullId')",int,doc="Pileup ID flags for 2016/2017/2018 EOY trainings")) + bjetNN= cms.EDProducer("BJetEnergyRegressionMVA", backend = cms.string("TF"), @@ -470,7 +477,7 @@ doc="index of second subjet"), # btagDeepC = Var("bDiscriminator('pfDeepCSVJetTags:probc')",float,doc="CMVA V2 btag discriminator",precision=10), -#puIdDisc = Var("userFloat('pileupJetId:fullDiscriminant')",float,doc="Pilup ID discriminant",precision=10), +#puIdDisc = Var("userFloat('pileupJetId:fullDiscriminant')",float,doc="Pileup ID discriminant",precision=10), # nConstituents = Var("numberOfDaughters()",int,doc="Number of particles in the jet"), # rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6), ), @@ -487,12 +494,12 @@ # Deprecated after 106X modifier.toModify( fatJetTable.variables, btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10), - btagDDBvL_noMD = Var("bDiscriminator('pfDeepDoubleBvLJetTags:probHbb')",float,doc="DeepDoubleX discriminator (no mass-decorrelation) for H(Z)->bb vs QCD",precision=10), - btagDDCvL_noMD = Var("bDiscriminator('pfDeepDoubleCvLJetTags:probHcc')",float,doc="DeepDoubleX discriminator (no mass-decorrelation) for H(Z)->cc vs QCD",precision=10), - btagDDCvB_noMD = Var("bDiscriminator('pfDeepDoubleCvBJetTags:probHcc')",float,doc="DeepDoubleX discriminator (no mass-decorrelation) for H(Z)->cc vs H(Z)->bb",precision=10), - btagDDBvL = Var("bDiscriminator('pfMassIndependentDeepDoubleBvLJetTags:probHbb')",float,doc="DeepDoubleX (mass-decorrelated) discriminator for H(Z)->bb vs QCD",precision=10), - btagDDCvL = Var("bDiscriminator('pfMassIndependentDeepDoubleCvLJetTags:probHcc')",float,doc="DeepDoubleX (mass-decorrelated) discriminator for H(Z)->cc vs QCD",precision=10), - btagDDCvB = Var("bDiscriminator('pfMassIndependentDeepDoubleCvBJetTags:probHcc')",float,doc="DeepDoubleX (mass-decorrelated) discriminator for H(Z)->cc vs H(Z)->bb",precision=10), + btagDDBvL_noMD = Var("bDiscriminator('pfDeepDoubleBvLJetTags:probHbb')",float,doc="DeepDoubleX discriminator (no mass-decorrelation) for H(Z)->bb vs QCD",precision=10), + btagDDCvL_noMD = Var("bDiscriminator('pfDeepDoubleCvLJetTags:probHcc')",float,doc="DeepDoubleX discriminator (no mass-decorrelation) for H(Z)->cc vs QCD",precision=10), + btagDDCvB_noMD = Var("bDiscriminator('pfDeepDoubleCvBJetTags:probHcc')",float,doc="DeepDoubleX discriminator (no mass-decorrelation) for H(Z)->cc vs H(Z)->bb",precision=10), + btagDDBvL = Var("bDiscriminator('pfMassIndependentDeepDoubleBvLJetTags:probHbb')",float,doc="DeepDoubleX (mass-decorrelated) discriminator for H(Z)->bb vs QCD",precision=10), + btagDDCvL = Var("bDiscriminator('pfMassIndependentDeepDoubleCvLJetTags:probHcc')",float,doc="DeepDoubleX (mass-decorrelated) discriminator for H(Z)->cc vs QCD",precision=10), + btagDDCvB = Var("bDiscriminator('pfMassIndependentDeepDoubleCvBJetTags:probHcc')",float,doc="DeepDoubleX (mass-decorrelated) discriminator for H(Z)->cc vs H(Z)->bb",precision=10), ) run2_miniAOD_80XLegacy.toModify( fatJetTable.variables, msoftdrop_chs = Var("userFloat('ak8PFJetsCHSSoftDropMass')",float, doc="Legacy uncorrected soft drop mass with CHS",precision=10)) run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.tau1, expr = cms.string("userFloat(\'ak8PFJetsPuppiValueMap:NjettinessAK8PuppiTau1\')"),) @@ -528,7 +535,7 @@ variables = cms.PSet(P4Vars, btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="DeepCSV b+bb tag discriminator",precision=10), btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10), - rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6), + rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6), tau1 = Var("userFloat('NjettinessAK8Subjets:tau1')",float, doc="Nsubjettiness (1 axis)",precision=10), tau2 = Var("userFloat('NjettinessAK8Subjets:tau2')",float, doc="Nsubjettiness (2 axis)",precision=10), tau3 = Var("userFloat('NjettinessAK8Subjets:tau3')",float, doc="Nsubjettiness (3 axis)",precision=10), @@ -698,12 +705,13 @@ qgtagger=QGTagger.clone(srcJets="updatedJets",srcVertexCollection="offlineSlimmedPrimaryVertices") -from RecoJets.JetProducers.PileupJetID_cfi import pileupJetId, _chsalgos_94x, _chsalgos_102x +from RecoJets.JetProducers.PileupJetID_cfi import pileupJetId, _chsalgos_94x, _chsalgos_102x, _chsalgos_106X_UL17 pileupJetId94X=pileupJetId.clone(jets="updatedJets",algos = cms.VPSet(_chsalgos_94x),inputIsCorrected=True,applyJec=False,vertexes="offlineSlimmedPrimaryVertices") pileupJetId102X=pileupJetId.clone(jets="updatedJets",algos = cms.VPSet(_chsalgos_102x),inputIsCorrected=True,applyJec=False,vertexes="offlineSlimmedPrimaryVertices") +pileupJetId106XUL17=pileupJetId.clone(jets="updatedJets",algos = cms.VPSet(_chsalgos_106X_UL17),inputIsCorrected=True,applyJec=False,vertexes="offlineSlimmedPrimaryVertices") #before cross linking -jetSequence = cms.Sequence(jetCorrFactorsNano+updatedJets+tightJetId+tightJetIdLepVeto+bJetVars+qgtagger+jercVars+pileupJetId94X+pileupJetId102X+updatedJetsWithUserData+jetCorrFactorsAK8+updatedJetsAK8+tightJetIdAK8+tightJetIdLepVetoAK8+updatedJetsAK8WithUserData+chsForSATkJets+softActivityJets+softActivityJets2+softActivityJets5+softActivityJets10+finalJets+finalJetsAK8) +jetSequence = cms.Sequence(jetCorrFactorsNano+updatedJets+tightJetId+tightJetIdLepVeto+bJetVars+qgtagger+jercVars+pileupJetId94X+pileupJetId102X+pileupJetId106XUL17+updatedJetsWithUserData+jetCorrFactorsAK8+updatedJetsAK8+tightJetIdAK8+tightJetIdLepVetoAK8+updatedJetsAK8WithUserData+chsForSATkJets+softActivityJets+softActivityJets2+softActivityJets5+softActivityJets10+finalJets+finalJetsAK8) _jetSequence_2016 = jetSequence.copy() @@ -712,8 +720,8 @@ for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016: modifier.toReplaceWith(jetSequence, _jetSequence_2016) -#HF shower shape recomputation -#Only run if needed (i.e. if default MINIAOD info is missing or outdated because of new JECs...) +#HF shower shape recomputation +#Only run if needed (i.e. if default MINIAOD info is missing or outdated because of new JECs...) from RecoJets.JetProducers.hfJetShowerShape_cfi import hfJetShowerShape hfJetShowerShapeforNanoAOD = hfJetShowerShape.clone(jets="updatedJets",vertices="offlineSlimmedPrimaryVertices") for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1: @@ -723,7 +731,7 @@ ) modifier.toModify(updatedJetsWithUserData.userInts, hfcentralEtaStripSize = cms.InputTag('hfJetShowerShapeforNanoAOD:centralEtaStripSize'), - hfadjacentEtaStripsSize = cms.InputTag('hfJetShowerShapeforNanoAOD:adjacentEtaStripsSize'), + hfadjacentEtaStripsSize = cms.InputTag('hfJetShowerShapeforNanoAOD:adjacentEtaStripsSize'), ) modifier.toModify( jetTable.variables, hfsigmaEtaEta = Var("userFloat('hfsigmaEtaEta')",float,doc="sigmaEtaEta for HF jets (noise discriminating variable)",precision=10)) modifier.toModify( jetTable.variables, hfsigmaPhiPhi = Var("userFloat('hfsigmaPhiPhi')",float,doc="sigmaPhiPhi for HF jets (noise discriminating variable)",precision=10)) diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index ba04f43671ec4..d80e2d7b0203b 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -67,7 +67,7 @@ discNames = cms.vstring( "pfCombinedInclusiveSecondaryVertexV2BJetTags", "pfDeepCSVJetTags:probb+pfDeepCSVJetTags:probbb", #if multiple MiniAOD branches need to be summed up (e.g., DeepCSV b+bb), separate them using '+' delimiter - "pfCombinedMVAV2BJetTags" + "pfCombinedMVAV2BJetTags" ), discShortNames = cms.vstring( "CSVV2", @@ -76,7 +76,7 @@ ), weightFiles = cms.vstring( #default settings are for 2017 94X. toModify function is called later for other eras. btagSFdir+"CSVv2_94XSF_V2_B_F.csv", - btagSFdir+"DeepCSV_94XSF_V2_B_F.csv", + btagSFdir+"DeepCSV_94XSF_V2_B_F.csv", "unavailable" #if SFs for an algorithm in an era is unavailable, the corresponding branch will not be stored ), operatingPoints = cms.vstring("3","3","3"), #loose = 0, medium = 1, tight = 2, reshaping = 3 @@ -87,12 +87,12 @@ ) for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016: # to be updated when SF for Summer16MiniAODv3 MC will be available - modifier.toModify(btagWeightTable, + modifier.toModify(btagWeightTable, cut = cms.string("pt > 25. && abs(eta) < 2.4"), #80X corresponds to 2016, |eta| < 2.4 weightFiles = cms.vstring( #80X corresponds to 2016 SFs - btagSFdir+"CSVv2_Moriond17_B_H.csv", - "unavailable", - btagSFdir+"cMVAv2_Moriond17_B_H.csv" + btagSFdir+"CSVv2_Moriond17_B_H.csv", + "unavailable", + btagSFdir+"cMVAv2_Moriond17_B_H.csv" ) ) @@ -100,7 +100,7 @@ lheInfoTable = cms.EDProducer("LHETablesProducer", lheInfo = cms.VInputTag(cms.InputTag("externalLHEProducer"), cms.InputTag("source")), precision = cms.int32(14), - storeLHEParticles = cms.bool(True) + storeLHEParticles = cms.bool(True) ) l1bits=cms.EDProducer("L1TriggerResultsConverter", src=cms.InputTag("gtStage2Digis"), legacyL1=cms.bool(False), @@ -109,7 +109,7 @@ nanoSequenceCommon = cms.Sequence( nanoMetadata + jetSequence + muonSequence + tauSequence + electronSequence+photonSequence+vertexSequence+ - isoTrackSequence + jetLepSequence + # must be after all the leptons + isoTrackSequence + jetLepSequence + # must be after all the leptons linkedObjects + jetTables + muonTables + tauTables + electronTables + photonTables + globalTables +vertexTables+ metTables+simpleCleanerTable + isoTrackTables ) @@ -211,7 +211,35 @@ def nanoAOD_recalibrateMETs(process,isData): table.variables.muonSubtrFactor = Var("1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc="1-(muon-subtracted raw pt)/(raw pt)",precision=6) process.metTables += process.corrT1METJetTable # makePuppiesFromMiniAOD(process,True) # call this before in the global customizer otherwise it would reset photon IDs in VID - runMetCorAndUncFromMiniAOD(process,isData=isData,metType="Puppi",postfix="Puppi",jetFlavor="AK4PFPuppi") + nanoAOD_PuppiV15_switch = cms.PSet( + recoMetFromPFCs = cms.untracked.bool(False), + reclusterJets = cms.untracked.bool(False), + ) + run2_nanoAOD_106Xv1.toModify(nanoAOD_PuppiV15_switch,recoMetFromPFCs=True,reclusterJets=True) + runMetCorAndUncFromMiniAOD(process,isData=isData,metType="Puppi",postfix="Puppi",jetFlavor="AK4PFPuppi", recoMetFromPFCs=bool(nanoAOD_PuppiV15_switch.recoMetFromPFCs), reclusterJets=bool(nanoAOD_PuppiV15_switch.reclusterJets)) + if nanoAOD_PuppiV15_switch.reclusterJets: + from RecoJets.JetProducers.ak4PFJets_cfi import ak4PFJets + from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask + task = getPatAlgosToolsTask(process) + addToProcessAndTask('ak4PuppiJets', ak4PFJets.clone (src = 'puppi', doAreaFastjet = True, jetPtMin = 10.), process, task) + from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection + addJetCollection(process, + labelName = 'Puppi', + jetSource = cms.InputTag('ak4PuppiJets'), + algo = 'AK', rParam=0.4, + genJetCollection=cms.InputTag('slimmedGenJets'), + jetCorrections = ('AK4PFPuppi', ['L1FastJet', 'L2Relative', 'L3Absolute','L2L3Residual'], 'None'), + pfCandidates = cms.InputTag('packedPFCandidates'), + pvSource = cms.InputTag('offlineSlimmedPrimaryVertices'), + svSource = cms.InputTag('slimmedSecondaryVertices'), + muSource =cms.InputTag( 'slimmedMuons'), + elSource = cms.InputTag('slimmedElectrons'), + genParticles= cms.InputTag('prunedGenParticles'), + getJetMCFlavour=False + ) + + process.patJetsPuppi.addGenPartonMatch = cms.bool(False) + process.patJetsPuppi.addGenJetMatch = cms.bool(False) process.nanoSequenceCommon.insert(process.nanoSequenceCommon.index(process.jetSequence),cms.Sequence(process.puppiMETSequence+process.fullPatMetSequencePuppi)) return process @@ -287,7 +315,7 @@ def nanoAOD_runMETfixEE2017(process,isData): process.nanoSequenceCommon.insert(process.nanoSequenceCommon.index(jetSequence),process.fullPatMetSequenceFixEE2017) def nanoAOD_customizeCommon(process): - makePuppiesFromMiniAOD(process,True) + makePuppiesFromMiniAOD(process,True) process.puppiNoLep.useExistingWeights = True process.puppi.useExistingWeights = True run2_nanoAOD_106Xv1.toModify(process.puppiNoLep, useExistingWeights = False) @@ -355,7 +383,7 @@ def nanoAOD_customizeMC(process): ### Era dependent customization _80x_sequence = nanoSequenceCommon.copy() -#remove stuff +#remove stuff _80x_sequence.remove(isoTrackTables) _80x_sequence.remove(isoTrackSequence) #add stuff diff --git a/PhysicsTools/PatUtils/python/tools/runMETCorrectionsAndUncertainties.py b/PhysicsTools/PatUtils/python/tools/runMETCorrectionsAndUncertainties.py index 0a9bd9ccf157c..c8dad033f2f64 100644 --- a/PhysicsTools/PatUtils/python/tools/runMETCorrectionsAndUncertainties.py +++ b/PhysicsTools/PatUtils/python/tools/runMETCorrectionsAndUncertainties.py @@ -254,10 +254,10 @@ def __call__(self, process, self.setParameter('CHS',False), #enabling puppi flag - self.setParameter('Puppi',self._defaultParameters['Puppi'].value) + self.setParameter('Puppi',self._defaultParameters['Puppi'].value) if metType == "Puppi": - self.setParameter('metType',"PF") - self.setParameter('Puppi',True) + self.setParameter('metType',"PF") + self.setParameter('Puppi',True) #jet energy scale uncertainty needs if manualJetConfig: @@ -274,7 +274,7 @@ def __call__(self, process, if fixEE2017: if recoMetFromPFCsIsNone: self.setParameter('recoMetFromPFCs',True) if reclusterJetsIsNone: self.setParameter('reclusterJets',False) - + #met reprocessing and jet reclustering if recoMetFromPFCs and reclusterJetsIsNone and not fixEE2017: self.setParameter('reclusterJets',True) @@ -312,11 +312,11 @@ def toolCode(self, process): fixEE2017 = self._parameters['fixEE2017'].value fixEE2017Params = self._parameters['fixEE2017Params'].value extractDeepMETs = self._parameters['extractDeepMETs'].value - + #prepare jet configuration jetUncInfos = { "jCorrPayload":jetFlavor, "jCorLabelUpToL3":jetCorLabelUpToL3, "jCorLabelL3Res":jetCorLabelL3Res, "jecUncFile":jecUncertaintyFile, - "jecUncTag":"Uncertainty" } + "jecUncTag":"Uncertainty" } if (jecUncertaintyFile!="" and jecUncertaintyTag==None): jetUncInfos[ "jecUncTag" ] = "" @@ -338,8 +338,8 @@ def toolCode(self, process): # recompute the MET (and thus the jets as well for correction) from scratch if recoMetFromPFCs: - self.recomputeRawMetFromPfcs(process, - pfCandCollection, + self.recomputeRawMetFromPfcs(process, + pfCandCollection, onMiniAOD, patMetModuleSequence, postfix) @@ -350,7 +350,7 @@ def toolCode(self, process): #jet AK4 reclustering if needed for JECs if reclusterJets: - jetCollectionUnskimmed = self.ak4JetReclustering(process, pfCandCollection, + jetCollectionUnskimmed = self.ak4JetReclustering(process, pfCandCollection, patMetModuleSequence, postfix) # or reapplication of jecs @@ -359,17 +359,17 @@ def toolCode(self, process): jetCollectionUnskimmed = self.updateJECs(process, jetCollectionUnskimmed, patMetModuleSequence, postfix) - #getting the jet collection that will be used for corrections + #getting the jet collection that will be used for corrections #and uncertainty computation - jetCollection = self.getJetCollectionForCorsAndUncs(process, + jetCollection = self.getJetCollectionForCorsAndUncs(process, jetCollectionUnskimmed, jetSelection, autoJetCleaning, patMetModuleSequence, postfix) - #pre-preparation to run over miniAOD - if onMiniAOD: + #pre-preparation to run over miniAOD + if onMiniAOD: self.miniAODConfigurationPre(process, patMetModuleSequence, pfCandCollection, postfix) else: from PhysicsTools.PatUtils.pfeGammaToCandidate_cfi import pfeGammaToCandidate @@ -388,14 +388,14 @@ def toolCode(self, process): - #preparation to run over miniAOD (met reproduction) + #preparation to run over miniAOD (met reproduction) if onMiniAOD: - self.miniAODConfiguration(process, + self.miniAODConfiguration(process, pfCandCollection, jetCollection, patMetModuleSequence, postfix - ) + ) # correct the MET patMetCorrectionSequence, metModName = self.getCorrectedMET(process, metType, correctionLevel, @@ -455,7 +455,7 @@ def toolCode(self, process): else: if not len(configtools.listModules(patShiftedModuleSequence))==0: setattr(process, metModName+"patShiftedModuleSequence"+postfix , patShiftedModuleSequence) - tmpSeq = getattr(process, "patShiftedModuleSequence"+postfix) + tmpSeq = getattr(process, "patShiftedModuleSequence"+postfix) tmpSeq += getattr(process, metModName+"patShiftedModuleSequence"+postfix) if not hasattr(process, "patMetModuleSequence"+postfix): @@ -538,7 +538,7 @@ def produceMET(self, process, metType, metModuleSequence, postfix): metModuleSequence += getattr(process, _myPatMet ) #==================================================================================================== - def getCorrectedMET(self, process, metType, correctionLevel,produceIntermediateCorrections, + def getCorrectedMET(self, process, metType, correctionLevel,produceIntermediateCorrections, jetCollection, metModuleSequence, postfix ): # default outputs @@ -598,13 +598,13 @@ def getCorrectedMET(self, process, metType, correctionLevel,produceIntermediateC #"T2":cms.InputTag('patPFMetT2Corr'+postfix, 'type2'), #"Txy": cms.InputTag('patPFMetTxyCorr'+postfix), #"Smear":cms.InputTag('patPFMetT1T2SmearCorr'+postfix, 'type1'), - #"T2Smear":cms.InputTag('patPFMetT2SmearCorr'+postfix, 'type2') + #"T2Smear":cms.InputTag('patPFMetT2SmearCorr'+postfix, 'type2') "T0":['patPFMetT0Corr'+postfix,''], "T1":['patPFMetT1T2Corr'+postfix, 'type1'], "T2":['patPFMetT2Corr'+postfix, 'type2'], "Txy": ['patPFMetTxyCorr'+postfix,''], "Smear":['patPFMetT1T2SmearCorr'+postfix, 'type1'], - "T2Smear":['patPFMetT2SmearCorr'+postfix, 'type2'] + "T2Smear":['patPFMetT2SmearCorr'+postfix, 'type2'] } corScheme="" @@ -675,7 +675,7 @@ def getCorrectedMET(self, process, metType, correctionLevel,produceIntermediateC task = getPatAlgosToolsTask(process) #T1 parameter tuning when CHS jets are not used - if "T1" in correctionLevel and not self._parameters["CHS"].value: + if "T1" in correctionLevel and not self._parameters["CHS"].value: addToProcessAndTask("corrPfMetType1"+postfix, getattr(process, "corrPfMetType1" ).clone(), process, task) getattr(process, "corrPfMetType1"+postfix).src = cms.InputTag("ak4PFJets"+postfix) getattr(process, "corrPfMetType1"+postfix).jetCorrLabel = cms.InputTag("ak4PFL1FastL2L3Corrector") @@ -683,7 +683,7 @@ def getCorrectedMET(self, process, metType, correctionLevel,produceIntermediateC getattr(process, "corrPfMetType1"+postfix).offsetCorrLabel = cms.InputTag("ak4PFL1FastjetCorrector") getattr(process, "basicJetsForMet"+postfix).offsetCorrLabel = cms.InputTag("ak4PFL1FastjetCorrector") - if "T1" in correctionLevel and self._parameters["Puppi"].value: + if "T1" in correctionLevel and self._parameters["Puppi"].value: addToProcessAndTask("corrPfMetType1"+postfix, getattr(process, "corrPfMetType1" ).clone(), process, task) getattr(process, "corrPfMetType1"+postfix).src = cms.InputTag("ak4PFJets"+postfix) getattr(process, "corrPfMetType1"+postfix).jetCorrLabel = cms.InputTag("ak4PFPuppiL1FastL2L3Corrector") @@ -800,8 +800,8 @@ def addIntermediateMETs(self, process, metType, correctionLevel, corScheme, corT #==================================================================================================== def getMETUncertainties(self, process, metType, metModName, electronCollection, - photonCollection, muonCollection, tauCollection, - pfCandCollection, jetCollection, jetUncInfos, + photonCollection, muonCollection, tauCollection, + pfCandCollection, jetCollection, jetUncInfos, postfix): @@ -816,7 +816,7 @@ def getMETUncertainties(self, process, metType, metModName, electronCollection, #=================================================================================== if not isValidInputTag(jetCollection): #or jetCollection=="": print("INFO : jet collection %s does not exists, no energy resolution shifting will be performed in MET uncertainty tools" % jetCollection) - else: + else: preId="" if "Smear" in metModName: preId="Smeared" @@ -833,15 +833,15 @@ def getMETUncertainties(self, process, metType, metModName, electronCollection, if not hasattr(process, "pfCandsForUnclusteredUnc"+postfix): #Jet projection == - pfCandsNoJets = cms.EDProducer("CandPtrProjector", - src = pfCandCollection, + pfCandsNoJets = cms.EDProducer("CandPtrProjector", + src = pfCandCollection, veto = copy.copy(jetCollection), ) addToProcessAndTask("pfCandsNoJets"+postfix, pfCandsNoJets, process, task) metUncSequence += getattr(process, "pfCandsNoJets"+postfix) #electron projection == - pfCandsNoJetsNoEle = cms.EDProducer("CandPtrProjector", + pfCandsNoJetsNoEle = cms.EDProducer("CandPtrProjector", src = cms.InputTag("pfCandsNoJets"+postfix), veto = copy.copy(electronCollection), ) @@ -851,7 +851,7 @@ def getMETUncertainties(self, process, metType, metModName, electronCollection, metUncSequence += getattr(process, "pfCandsNoJetsNoEle"+postfix) #muon projection == - pfCandsNoJetsNoEleNoMu = cms.EDProducer("CandPtrProjector", + pfCandsNoJetsNoEleNoMu = cms.EDProducer("CandPtrProjector", src = cms.InputTag("pfCandsNoJetsNoEle"+postfix), veto = copy.copy(muonCollection), ) @@ -859,7 +859,7 @@ def getMETUncertainties(self, process, metType, metModName, electronCollection, metUncSequence += getattr(process, "pfCandsNoJetsNoEleNoMu"+postfix) #tau projection == - pfCandsNoJetsNoEleNoMuNoTau = cms.EDProducer("CandPtrProjector", + pfCandsNoJetsNoEleNoMuNoTau = cms.EDProducer("CandPtrProjector", src = cms.InputTag("pfCandsNoJetsNoEleNoMu"+postfix), veto = copy.copy(tauCollection), ) @@ -867,7 +867,7 @@ def getMETUncertainties(self, process, metType, metModName, electronCollection, metUncSequence += getattr(process, "pfCandsNoJetsNoEleNoMuNoTau"+postfix) #photon projection == - pfCandsForUnclusteredUnc = cms.EDProducer("CandPtrProjector", + pfCandsForUnclusteredUnc = cms.EDProducer("CandPtrProjector", src = cms.InputTag("pfCandsNoJetsNoEleNoMuNoTau"+postfix), veto = copy.copy(photonCollection), ) @@ -879,7 +879,7 @@ def getMETUncertainties(self, process, metType, metModName, electronCollection, #=================================================================================== # energy shifts #=================================================================================== - # PFMuons, PFElectrons, PFPhotons, and PFTaus will be used + # PFMuons, PFElectrons, PFPhotons, and PFTaus will be used # to calculate MET Uncertainties. #=================================================================================== #-------------- @@ -938,7 +938,7 @@ def getMETUncertainties(self, process, metType, metModName, electronCollection, tauCollection = cms.InputTag("pfTaus"+postfix) photonCollection = cms.InputTag("pfPhotons"+postfix) - + objectCollections = { "Jet":jetCollection, "Electron":electronCollection, "Photon":photonCollection, @@ -999,7 +999,7 @@ def createEnergyScaleShiftedUpModule(self, process,identifier, objectCollection, srcWeights = cms.InputTag("") ) - if identifier == "Unclustered": + if identifier == "Unclustered": shiftedModuleUp = cms.EDProducer("ShiftedParticleProducer", src = objectCollection, binning = cms.VPSet( @@ -1107,11 +1107,11 @@ def tuneTxyParameters(self, process, corScheme, postfix): "T0pcT1T2SmearTxy_25ns":metCors.patMultPhiCorrParams_T0pcT1T2SmearTxy_25ns } - getattr(process, "patPFMetTxyCorr"+postfix).parameters = xyTags[corScheme+"_25ns"] + getattr(process, "patPFMetTxyCorr"+postfix).parameters = xyTags[corScheme+"_25ns"] #==================================================================================================== - def getVariations(self, process, metModName, identifier,preId, objectCollection, varType, + def getVariations(self, process, metModName, identifier,preId, objectCollection, varType, metUncSequence, jetUncInfos=None, postfix="" ): # temporary hardcoded varyByNSigma value @@ -1137,7 +1137,7 @@ def getVariations(self, process, metModName, identifier,preId, objectCollection, shiftedCollModules['Up'] = self.createShiftedJetResModule(process, smear, objectCollection, +1.*varyByNsigmas, "Up", postfix) shiftedCollModules['Down'] = self.createShiftedJetResModule(process, smear, objectCollection, -1.*varyByNsigmas, - "Down", postfix) + "Down", postfix) else: shiftedCollModules['Up'] = self.createEnergyScaleShiftedUpModule(process, identifier, objectCollection, varyByNsigmas, jetUncInfos, postfix) shiftedCollModules['Down'] = shiftedCollModules['Up'].clone( shiftBy = cms.double(-1.*varyByNsigmas) ) @@ -1153,7 +1153,7 @@ def getVariations(self, process, metModName, identifier,preId, objectCollection, if identifier=="Jet" and varType=="Res" and self._parameters["runOnData"].value: shiftedMetProducers = self.copyCentralMETProducer(process, shiftedCollModules, identifier, metModName, varType, postfix) else: - shiftedMetProducers = self.createShiftedModules(process, shiftedCollModules, identifier, preId, objectCollection, + shiftedMetProducers = self.createShiftedModules(process, shiftedCollModules, identifier, preId, objectCollection, metModName, varType, metUncSequence, postfix) return shiftedMetProducers @@ -1182,7 +1182,7 @@ def createShiftedJetResModule(self, process, smear, objectCollection, varyByNsig #======================================================================================== - def createShiftedModules(self, process, shiftedCollModules, identifier, preId, objectCollection, + def createShiftedModules(self, process, shiftedCollModules, identifier, preId, objectCollection, metModName, varType, metUncSequence, postfix): shiftedMetProducers = {} @@ -1229,12 +1229,12 @@ def createShiftedModules(self, process, shiftedCollModules, identifier, preId, o #MM: FIXME MVA #MVA MET, duplication of the MVA MET producer ============================================ #if "MVA" in metModName: - # print "name: ",metModName, modName + # print "name: ",metModName, modName # shiftedMETModule = self.createMVAMETModule(process, identifier, modName, True) # modName = baseName+identifier+varType+mod+postfix # setattr(process, modName, shiftedMETModule) # shiftedMetProducers[ modName ] = shiftedMETModule - # + # # #pileupjetId and ===== # if identifier == "Jet": # #special collection replacement for the MVAMET for the jet case ====== @@ -1319,7 +1319,7 @@ def createMVAMETModule(self, process, identifier="", shiftedCollection="", isShi leptons.append = tauCollection - mvaMetProducer=getattr(process, "pfMVAMEt").clone( + mvaMetProducer=getattr(process, "pfMVAMEt").clone( srcCorrJets = corJetCollection, srcUncorrJets = uncorJetCollection, srcPFCandidates = pfCandCollection, @@ -1350,8 +1350,8 @@ def getUnclusteredVariationsForMVAMET(self, process, var, val, metUncSequence, pfCandCollection = self._parameters["pfCandCollection"].value #top projection on jets - pfCandsNotInJets = cms.EDProducer("CandPtrProjector", - src = pfCandCollection, + pfCandsNotInJets = cms.EDProducer("CandPtrProjector", + src = pfCandCollection, veto = cms.InputTag("ak4PFJets") ) setattr(process, "pfCandsNotInJetsUnclusteredEn"+var+postfix, pfCandsNotInJets) @@ -1410,8 +1410,8 @@ def createSmearedJetModule(self, process, jetCollection, smear, varyByNsigmas, v enabled = cms.bool(smear), variation = cms.int32( int(varyByNsigmas) ), genJets = genJetsCollection, - ) - + ) + #MM: FIXME MVA #if "MVA" == self._parameters["metType"].value: # from RecoMET.METProducers.METSigParams_cfi import * @@ -1535,8 +1535,8 @@ def updateJECs(self,process,jetCollection, patMetModuleSequence, postfix): patJetCorrFactorsReapplyJEC = updatedPatJetCorrFactors.clone( src = jetCollection, - levels = ['L1FastJet', - 'L2Relative', + levels = ['L1FastJet', + 'L2Relative', 'L3Absolute'], payload = 'AK4PFchs' if not self._parameters["Puppi"].value else 'AK4PFPuppi' ) # always CHS from miniAODs, except for puppi @@ -1559,7 +1559,7 @@ def updateJECs(self,process,jetCollection, patMetModuleSequence, postfix): return cms.InputTag("patJetsReapplyJEC"+postfix) - def getJetCollectionForCorsAndUncs(self, process, jetCollectionUnskimmed, + def getJetCollectionForCorsAndUncs(self, process, jetCollectionUnskimmed, jetSelection, autoJetCleaning,patMetModuleSequence, postfix): task = getPatAlgosToolsTask(process) @@ -1605,7 +1605,7 @@ def ak4JetReclustering(self,process, pfCandCollection, patMetModuleSequence, pos jetColName="ak4PFJetsCHS" pfCHS=None - if self._parameters["onMiniAOD"].value: + if self._parameters["onMiniAOD"].value: pfCHS = cms.EDFilter("CandPtrSelector", src = pfCandCollection, cut = cms.string("fromPV")) pfCandColl = cms.InputTag("pfNoPileUpJME"+postfix) addToProcessAndTask("pfNoPileUpJME"+postfix, pfCHS, process, task) @@ -1631,13 +1631,13 @@ def ak4JetReclustering(self,process, pfCandCollection, patMetModuleSequence, pos from RecoJets.JetProducers.ak4PFJets_cfi import ak4PFJets #if chs: addToProcessAndTask(jetColName, ak4PFJets.clone(), process, task) - getattr(process, jetColName).src = pfCandColl + getattr(process, jetColName).src = pfCandColl getattr(process, jetColName).doAreaFastjet = True #puppi if self._parameters["Puppi"].value: getattr(process, jetColName).srcWeights = cms.InputTag("puppi") - getattr(process, jetColName).applyWeights = True + getattr(process, jetColName).applyWeight = True patMetModuleSequence += getattr(process, jetColName) @@ -1651,11 +1651,11 @@ def ak4JetReclustering(self,process, pfCandCollection, patMetModuleSequence, pos postfix=postfix ) - getattr(process,"patJets"+postfix).addGenJetMatch = False - getattr(process,"patJets"+postfix).addGenPartonMatch = False - getattr(process,"patJets"+postfix).addPartonJetMatch = False - getattr(process,"patJets"+postfix).embedGenPartonMatch = False - getattr(process,"patJets"+postfix).embedGenJetMatch = False + getattr(process,"patJets"+postfix).addGenJetMatch = False + getattr(process,"patJets"+postfix).addGenPartonMatch = False + getattr(process,"patJets"+postfix).addPartonJetMatch = False + getattr(process,"patJets"+postfix).embedGenPartonMatch = False + getattr(process,"patJets"+postfix).embedGenJetMatch = False if self._parameters['onMiniAOD'].value: del getattr(process,"patJets"+postfix).JetFlavourInfoSource del getattr(process,"patJets"+postfix).JetPartonMapSource @@ -1757,7 +1757,7 @@ def miniAODConfigurationPost(self, process, postfix): def miniAODConfiguration(self, process, pfCandCollection, jetCollection, - patMetModuleSequence, postfix ): + patMetModuleSequence, postfix ): if self._parameters["metType"].value == "PF": # not hasattr(process, "pfMet"+postfix) if "T1" in self._parameters['correctionLevel'].value: getattr(process, "patPFMet"+postfix).srcJets = jetCollection @@ -1852,10 +1852,10 @@ def jetCleaning(self, process, jetCollectionName, autoJetCleaning, jetProduction task = getPatAlgosToolsTask(process) if autoJetCleaning == "Full" : # auto clean taus, photons and jets - if isValidInputTag(tauCollection): + if isValidInputTag(tauCollection): process.load("PhysicsTools.PatAlgos.cleaningLayer1.tauCleaner_cfi") task.add(process.cleanPatTaus) - cleanPatTauProducer = getattr(process, "cleanPatTaus").clone( + cleanPatTauProducer = getattr(process, "cleanPatTaus").clone( src = tauCollection ) cleanPatTauProducer.checkOverlaps.electrons.src = electronCollection @@ -1864,10 +1864,10 @@ def jetCleaning(self, process, jetCollectionName, autoJetCleaning, jetProduction jetProductionSequence += getattr(process, "cleanedPatTaus"+postfix) tauCollection = cms.InputTag("cleanedPatTaus"+postfix) - if isValidInputTag(photonCollection): + if isValidInputTag(photonCollection): process.load("PhysicsTools.PatAlgos.cleaningLayer1.photonCleaner_cfi") task.add(process.cleanPatPhotons) - cleanPatPhotonProducer = getattr(process, "cleanPatPhotons").clone( + cleanPatPhotonProducer = getattr(process, "cleanPatPhotons").clone( src = photonCollection ) cleanPatPhotonProducer.checkOverlaps.electrons.src = electronCollection @@ -1878,7 +1878,7 @@ def jetCleaning(self, process, jetCollectionName, autoJetCleaning, jetProduction #jet cleaning have_cleanPatJets = hasattr(process, "cleanPatJets") process.load("PhysicsTools.PatAlgos.cleaningLayer1.jetCleaner_cfi") - cleanPatJetProducer = getattr(process, "cleanPatJets").clone( + cleanPatJetProducer = getattr(process, "cleanPatJets").clone( src = cms.InputTag(jetCollectionName) ) #do not leave it hanging