Skip to content

Commit

Permalink
Merge pull request cms-sw#357 from Sam-Harper/EG2018SSNano_102X
Browse files Browse the repository at this point in the history
add e/gamma scale & smearing for 2018 data/MC
  • Loading branch information
peruzzim authored May 14, 2019
2 parents 9645035 + 5a2a511 commit c784d1b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
19 changes: 18 additions & 1 deletion PhysicsTools/NanoAOD/python/electrons_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv1_cff import run2_nanoAOD_94XMiniAODv1
from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv2_cff import run2_nanoAOD_94XMiniAODv2
from Configuration.Eras.Modifier_run2_nanoAOD_94X2016_cff import run2_nanoAOD_94X2016
from Configuration.Eras.Modifier_run2_nanoAOD_102Xv1_cff import run2_nanoAOD_102Xv1

from PhysicsTools.NanoAOD.common_cff import *
import PhysicsTools.PatAlgos.producersLayer1.electronProducer_cfi
from math import ceil,log
Expand Down Expand Up @@ -142,6 +144,11 @@ def _get_bitmapVIDForEle_docstring(modules,WorkingPoints):
correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_17Nov2017_v1_ele_unc"),
)

calibratedPatElectrons102X = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatElectrons.clone(
produceCalibratedObjs = False,
correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2018_Step2Closure_CoarseEtaR9Gain_v2"),
)

slimmedElectronsWithUserData = cms.EDProducer("PATElectronUserDataEmbedder",
src = cms.InputTag("slimmedElectrons"),
userFloats = cms.PSet(
Expand Down Expand Up @@ -218,6 +225,13 @@ def _get_bitmapVIDForEle_docstring(modules,WorkingPoints):
ecalTrkEnergyPostCorrNew = cms.InputTag("calibratedPatElectrons94X","ecalTrkEnergyPostCorr"),
)

run2_nanoAOD_102Xv1.toModify(slimmedElectronsWithUserData.userFloats,
ecalTrkEnergyErrPostCorrNew = cms.InputTag("calibratedPatElectrons102X","ecalTrkEnergyErrPostCorr"),
ecalTrkEnergyPreCorrNew = cms.InputTag("calibratedPatElectrons102X","ecalTrkEnergyPreCorr"),
ecalTrkEnergyPostCorrNew = cms.InputTag("calibratedPatElectrons102X","ecalTrkEnergyPostCorr"),
)


run2_miniAOD_80XLegacy.toModify(slimmedElectronsWithUserData.userIntFromBools,
mvaSpring16GP_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp90"),
mvaSpring16GP_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp80"),
Expand Down Expand Up @@ -363,7 +377,7 @@ def _get_bitmapVIDForEle_docstring(modules,WorkingPoints):
#the94X miniAOD V2 had a bug in the scale and smearing for electrons in the E/p comb
#therefore we redo it but but we need use a new name for the userFloat as we cant override existing userfloats
#for technical reasons
for modifier in run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_miniAOD_80XLegacy:
for modifier in run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_miniAOD_80XLegacy,run2_nanoAOD_102Xv1:
modifier.toModify(electronTable.variables,
pt = Var("pt*userFloat('ecalTrkEnergyPostCorrNew')/userFloat('ecalTrkEnergyPreCorrNew')", float, precision=-1, doc="p_{T}"),
energyErr = Var("userFloat('ecalTrkEnergyErrPostCorrNew')", float, precision=6, doc="energy error of the cluster-track combination"),
Expand Down Expand Up @@ -450,3 +464,6 @@ def _get_bitmapVIDForEle_docstring(modules,WorkingPoints):
_with_bitmapVIDForEleSpring15AndSum16_sequence.replace(slimmedElectronsWithUserData, bitmapVIDForEleSpring15 + bitmapVIDForEleSum16 + slimmedElectronsWithUserData)
run2_nanoAOD_94X2016.toReplaceWith(electronSequence, _with_bitmapVIDForEleSpring15AndSum16_sequence)

_with102XScale_sequence = electronSequence.copy()
_with102XScale_sequence.replace(slimmedElectronsWithUserData, calibratedPatElectrons102X + slimmedElectronsWithUserData)
run2_nanoAOD_102Xv1.toReplaceWith(electronSequence, _with102XScale_sequence)
43 changes: 17 additions & 26 deletions PhysicsTools/NanoAOD/python/nanoDQM_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,22 @@
for modifier in eras.run2_nanoAOD_94XMiniAODv1, eras.run2_nanoAOD_94XMiniAODv2:
modifier.toModify(nanoDQM.vplots, METFixEE2017 = _METFixEE2017_DQMentry)

_Electron_plots_with_eCorr = copy.deepcopy(nanoDQM.vplots.Electron.plots)
_Electron_plots_with_eCorr.append(Plot1D('eCorr', 'eCorr', 20, 0.8, 1.2, 'ratio of the calibrated energy/miniaod energy'))
_Electron_plots_2016 = copy.deepcopy(nanoDQM.vplots.Electron.plots)
_Electron_plots_2016.append(Plot1D('cutBased_HLTPreSel', 'cutBased_HLTPreSel', 2, -0.5, 1.5, 'cut-based HLT pre-selection ID'))
_Electron_plots_2016.append(Plot1D('cutBased_Spring15', 'cutBased_Spring15', 5, -0.5, 4.5, 'cut-based Spring15 ID (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)'))
_Electron_plots_2016.append(Plot1D('mvaSpring16GP', 'mvaSpring16GP', 20, -1, 1, 'MVA Spring16 general-purpose ID score'))
_Electron_plots_2016.append(Plot1D('mvaSpring16GP_WP80', 'mvaSpring16GP_WP80', 2, -0.5, 1.5, 'MVA Spring16 general-purpose ID WP80'))
_Electron_plots_2016.append(Plot1D('mvaSpring16GP_WP90', 'mvaSpring16GP_WP90', 2, -0.5, 1.5, 'MVA Spring16 general-purpose ID WP90'))
_Electron_plots_2016.append(Plot1D('mvaSpring16HZZ', 'mvaSpring16HZZ', 20, -1, 1, 'MVA Spring16 HZZ ID score'))
_Electron_plots_2016.append(Plot1D('mvaSpring16HZZ_WPL', 'mvaSpring16HZZ_WPL', 2, -0.5, 1.5, 'MVA Spring16 HZZ ID loose WP'))
_Electron_plots_2016.append(NoPlot('vidNestedWPBitmapSpring15'))

_Electron_plots_with_eCorr_2016 = copy.deepcopy(_Electron_plots_with_eCorr)
_Electron_plots_with_eCorr_2016.append(Plot1D('cutBased_HLTPreSel', 'cutBased_HLTPreSel', 2, -0.5, 1.5, 'cut-based HLT pre-selection ID'))
_Electron_plots_with_eCorr_2016.append(Plot1D('cutBased_Spring15', 'cutBased_Spring15', 5, -0.5, 4.5, 'cut-based Spring15 ID (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)'))
_Electron_plots_with_eCorr_2016.append(Plot1D('mvaSpring16GP', 'mvaSpring16GP', 20, -1, 1, 'MVA Spring16 general-purpose ID score'))
_Electron_plots_with_eCorr_2016.append(Plot1D('mvaSpring16GP_WP80', 'mvaSpring16GP_WP80', 2, -0.5, 1.5, 'MVA Spring16 general-purpose ID WP80'))
_Electron_plots_with_eCorr_2016.append(Plot1D('mvaSpring16GP_WP90', 'mvaSpring16GP_WP90', 2, -0.5, 1.5, 'MVA Spring16 general-purpose ID WP90'))
_Electron_plots_with_eCorr_2016.append(Plot1D('mvaSpring16HZZ', 'mvaSpring16HZZ', 20, -1, 1, 'MVA Spring16 HZZ ID score'))
_Electron_plots_with_eCorr_2016.append(Plot1D('mvaSpring16HZZ_WPL', 'mvaSpring16HZZ_WPL', 2, -0.5, 1.5, 'MVA Spring16 HZZ ID loose WP'))
_Electron_plots_with_eCorr_2016.append(NoPlot('vidNestedWPBitmapSpring15'))

_Photon_plots_with_eCorr = copy.deepcopy(nanoDQM.vplots.Photon.plots)
_Photon_plots_with_eCorr.append(Plot1D('eCorr', 'eCorr', 20, 0.8, 1.2, 'ratio of the calibrated energy/miniaod energy'))

_Photon_plots_with_eCorr_2016 = copy.deepcopy(_Photon_plots_with_eCorr)
_Photon_plots_with_eCorr_2016.append(Plot1D('cutBased', 'cutBased', 4, -0.5, 3.5, 'cut-based Spring16-V2p2 ID (0:fail, 1::loose, 2:medium, 3:tight)'))
_Photon_plots_with_eCorr_2016.append(Plot1D('cutBased17Bitmap', 'cutBased17Bitmap', 8, -0.5, 7.5, 'cut-based Fall17-94X-V1 ID bitmap, 2^(0:loose, 1:medium, 2:tight)'))
_Photon_plots_with_eCorr_2016.append(Plot1D('mvaID17', 'mvaID17', 20, -1, 1, 'MVA Fall17v1p1 ID score'))
_Photon_plots_with_eCorr_2016.append(Plot1D('mvaID17_WP80', 'mvaID17_WP80', 2, -0.5, 1.5, 'MVA Fall17v1p1 ID WP80'))
_Photon_plots_with_eCorr_2016.append(Plot1D('mvaID17_WP90', 'mvaID17_WP90', 2, -0.5, 1.5, 'MVA Fall17v1p1 ID WP90'))
_Photon_plots_2016 = copy.deepcopy(nanoDQM.vplots.Photon.plots)
_Photon_plots_2016.append(Plot1D('cutBased', 'cutBased', 4, -0.5, 3.5, 'cut-based Spring16-V2p2 ID (0:fail, 1::loose, 2:medium, 3:tight)'))
_Photon_plots_2016.append(Plot1D('cutBased17Bitmap', 'cutBased17Bitmap', 8, -0.5, 7.5, 'cut-based Fall17-94X-V1 ID bitmap, 2^(0:loose, 1:medium, 2:tight)'))
_Photon_plots_2016.append(Plot1D('mvaID17', 'mvaID17', 20, -1, 1, 'MVA Fall17v1p1 ID score'))
_Photon_plots_2016.append(Plot1D('mvaID17_WP80', 'mvaID17_WP80', 2, -0.5, 1.5, 'MVA Fall17v1p1 ID WP80'))
_Photon_plots_2016.append(Plot1D('mvaID17_WP90', 'mvaID17_WP90', 2, -0.5, 1.5, 'MVA Fall17v1p1 ID WP90'))

_FatJet_plots_80x = copy.deepcopy(nanoDQM.vplots.FatJet.plots)
_FatJet_plots_80x.append(Plot1D('msoftdrop_chs', 'msoftdrop_chs', 20, -300, 300, 'Legacy uncorrected soft drop mass with CHS'))
Expand All @@ -61,12 +55,9 @@
_Flag_plots_80x.append(Plot1D('BadGlobalMuon', 'BadGlobalMuon', 2, -0.5, 1.5, 'Bad muon flag'))
_Flag_plots_80x.append(Plot1D('CloneGlobalMuon', 'CloneGlobalMuon', 2, -0.5, 1.5, 'Clone muon flag'))

for modifier in eras.run2_nanoAOD_94XMiniAODv1, eras.run2_nanoAOD_94XMiniAODv2:
modifier.toModify(nanoDQM.vplots.Electron, plots = _Electron_plots_with_eCorr)
modifier.toModify(nanoDQM.vplots.Photon, plots = _Photon_plots_with_eCorr)
for modifier in eras.run2_miniAOD_80XLegacy, eras.run2_nanoAOD_94X2016:
modifier.toModify(nanoDQM.vplots.Electron, plots = _Electron_plots_with_eCorr_2016)
modifier.toModify(nanoDQM.vplots.Photon, plots = _Photon_plots_with_eCorr_2016)
modifier.toModify(nanoDQM.vplots.Electron, plots = _Electron_plots_2016)
modifier.toModify(nanoDQM.vplots.Photon, plots = _Photon_plots_2016)
eras.run2_miniAOD_80XLegacy.toModify(nanoDQM.vplots.FatJet, plots = _FatJet_plots_80x)
eras.run2_miniAOD_80XLegacy.toModify(nanoDQM.vplots.Flag, plots = _Flag_plots_80x)

Expand Down
2 changes: 2 additions & 0 deletions PhysicsTools/NanoAOD/python/nanoDQM_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
Plot1D('dxyErr', 'dxyErr', 20, 0, 0.2, 'dxy uncertainty, in cm'),
Plot1D('dz', 'dz', 20, -0.3, 0.3, 'dz (with sign) wrt first PV, in cm'),
Plot1D('dzErr', 'dzErr', 20, 0, 0.2, 'dz uncertainty, in cm'),
Plot1D('eCorr', 'eCorr', 20, 0.8, 1.2, 'ratio of the calibrated energy/miniaod energy'),
Plot1D('eInvMinusPInv', 'eInvMinusPInv', 20, -0.1, 0.1, '1/E_SC - 1/p_trk'),
Plot1D('energyErr', 'energyErr', 20, 0, 90, 'energy error of the cluster-track combination'),
Plot1D('eta', 'eta', 20, -3, 3, 'eta'),
Expand Down Expand Up @@ -405,6 +406,7 @@
Plot1D('cleanmask', 'cleanmask', 1, 0.5, 1.5, 'simple cleaning mask with priority to leptons'),
Plot1D('cutBasedBitmap', 'cutBasedBitmap', 8, -0.5, 7.5, 'cut-based ID bitmap, 2^(0:loose, 1:medium, 2:tight)'),
Plot1D('cutBasedV1Bitmap', 'cutBasedV1Bitmap', 8, -0.5, 7.5, 'cut-based ID bitmap, Fall17 V1, 2^(0:loose, 1:medium, 2:tight)'),
Plot1D('eCorr', 'eCorr', 20, 0.8, 1.2, 'ratio of the calibrated energy/miniaod energy'),
NoPlot('electronIdx'),
Plot1D('electronVeto', 'electronVeto', 2, -0.5, 1.5, 'pass electron veto'),
Plot1D('energyErr', 'energyErr', 20, 0, 300, 'energy error of the cluster from regression'),
Expand Down
16 changes: 15 additions & 1 deletion PhysicsTools/NanoAOD/python/photons_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv1_cff import run2_nanoAOD_94XMiniAODv1
from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv2_cff import run2_nanoAOD_94XMiniAODv2
from Configuration.Eras.Modifier_run2_nanoAOD_94X2016_cff import run2_nanoAOD_94X2016
from Configuration.Eras.Modifier_run2_nanoAOD_102Xv1_cff import run2_nanoAOD_102Xv1

photon_id_modules_WorkingPoints_nanoAOD = cms.PSet(
modules = cms.vstring(
Expand Down Expand Up @@ -79,6 +80,11 @@
seedGainPho = cms.EDProducer("PhotonSeedGainProducer", src = cms.InputTag("slimmedPhotons"))

import RecoEgamma.EgammaTools.calibratedEgammas_cff
calibratedPatPhotons102Xv1 = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
produceCalibratedObjs = False,
correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2018_Step2Closure_CoarseEtaR9Gain_v2")
)

calibratedPatPhotons94Xv1 = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
produceCalibratedObjs = False,
correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_17Nov2017_v1_ele_unc")
Expand Down Expand Up @@ -157,6 +163,11 @@
ecalEnergyPreCorrNew = cms.InputTag("calibratedPatPhotons94Xv1","ecalEnergyPreCorr"),
ecalEnergyPostCorrNew = cms.InputTag("calibratedPatPhotons94Xv1","ecalEnergyPostCorr"),
)
run2_nanoAOD_102Xv1.toModify(slimmedPhotonsWithUserData.userFloats,
ecalEnergyErrPostCorrNew = cms.InputTag("calibratedPatPhotons102Xv1","ecalEnergyErrPostCorr"),
ecalEnergyPreCorrNew = cms.InputTag("calibratedPatPhotons102Xv1","ecalEnergyPreCorr"),
ecalEnergyPostCorrNew = cms.InputTag("calibratedPatPhotons102Xv1","ecalEnergyPostCorr"),
)

finalPhotons = cms.EDFilter("PATPhotonRefSelector",
src = cms.InputTag("slimmedPhotonsWithUserData"),
Expand Down Expand Up @@ -203,7 +214,7 @@
)

#these eras need to make the energy correction, hence the "New"
for modifier in run2_nanoAOD_94XMiniAODv1, run2_miniAOD_80XLegacy:
for modifier in run2_nanoAOD_94XMiniAODv1, run2_miniAOD_80XLegacy, run2_nanoAOD_102Xv1:
modifier.toModify(photonTable.variables,
pt = Var("pt*userFloat('ecalEnergyPostCorrNew')/userFloat('ecalEnergyPreCorrNew')", float, precision=-1, doc="p_{T}"),
energyErr = Var("userFloat('ecalEnergyErrPostCorrNew')",float,doc="energy error of the cluster from regression",precision=6),
Expand Down Expand Up @@ -265,3 +276,6 @@
_with94Xv1Scale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons94Xv1 + slimmedPhotonsWithUserData)
run2_nanoAOD_94XMiniAODv1.toReplaceWith(photonSequence, _with94Xv1Scale_sequence)

_with102Xv1Scale_sequence = photonSequence.copy()
_with102Xv1Scale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons102Xv1 + slimmedPhotonsWithUserData)
run2_nanoAOD_102Xv1.toReplaceWith(photonSequence, _with102Xv1Scale_sequence)

0 comments on commit c784d1b

Please sign in to comment.