1 import FWCore.ParameterSet.Config
as cms
2 from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff
import run2_miniAOD_80XLegacy
4 from math
import ceil,log
6 from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff
import run2_miniAOD_80XLegacy
7 from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv1_cff
import run2_nanoAOD_94XMiniAODv1
8 from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv2_cff
import run2_nanoAOD_94XMiniAODv2
9 from Configuration.Eras.Modifier_run2_nanoAOD_94X2016_cff
import run2_nanoAOD_94X2016
10 from Configuration.Eras.Modifier_run2_nanoAOD_102Xv1_cff
import run2_nanoAOD_102Xv1
12 photon_id_modules_WorkingPoints_nanoAOD = cms.PSet(
13 modules = cms.vstring(
14 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff',
15 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff',
16 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff',
17 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff',
18 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff',
19 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff',
21 WorkingPoints = cms.vstring(
22 "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-loose",
23 "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-medium",
24 "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-tight",
27 photon_id_modules_WorkingPoints_nanoAOD_Spring16V2p2 = cms.PSet(
28 modules = photon_id_modules_WorkingPoints_nanoAOD.modules,
29 WorkingPoints = cms.vstring(
30 "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose",
31 "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium",
32 "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight",
37 pset = id_modules_working_points_pset
39 for modname
in pset.modules:
40 ids = __import__(modname, globals(), locals(), [
'idName',
'cutFlow'])
42 _id = getattr(ids,name)
43 if hasattr(_id,
'idName')
and hasattr(_id,
'cutFlow'):
44 if (len(pset.WorkingPoints)>0
and _id.idName == pset.WorkingPoints[0].
split(
':')[-1]):
45 cut_names =
','.
join([cut.cutName.value()
for cut
in _id.cutFlow])
46 n_bits_per_cut =
int(
ceil(
log(len(pset.WorkingPoints)+1,2)))
47 return 'VID compressed bitmap (%s), %d bits per cut'%(cut_names, n_bits_per_cut)
48 raise ValueError(
"Something is wrong in the photon ID modules parameter set!")
50 bitmapVIDForPho = cms.EDProducer(
"PhoVIDNestedWPBitmapProducer",
51 src = cms.InputTag(
"slimmedPhotons"),
52 WorkingPoints = photon_id_modules_WorkingPoints_nanoAOD.WorkingPoints,
55 bitmapVIDForPhoSpring16V2p2 = cms.EDProducer(
"PhoVIDNestedWPBitmapProducer",
56 src = cms.InputTag(
"slimmedPhotons"),
57 WorkingPoints = photon_id_modules_WorkingPoints_nanoAOD_Spring16V2p2.WorkingPoints,
60 isoForPho = cms.EDProducer(
"PhoIsoValueMapProducer",
61 src = cms.InputTag(
"slimmedPhotons"),
62 relative = cms.bool(
False),
63 rho_PFIso = cms.InputTag(
"fixedGridRhoFastjetAll"),
64 mapIsoChg = cms.InputTag(
"photonIDValueMapProducer:phoChargedIsolation"),
65 mapIsoNeu = cms.InputTag(
"photonIDValueMapProducer:phoNeutralHadronIsolation"),
66 mapIsoPho = cms.InputTag(
"photonIDValueMapProducer:phoPhotonIsolation"),
67 EAFile_PFIso_Chg = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt"),
68 EAFile_PFIso_Neu = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt"),
69 EAFile_PFIso_Pho = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt"),
71 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
72 modifier.toModify(isoForPho,
73 EAFile_PFIso_Chg = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfChargedHadrons_90percentBased.txt"),
74 EAFile_PFIso_Neu = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased.txt"),
75 EAFile_PFIso_Pho = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfPhotons_90percentBased.txt"),
78 seedGainPho = cms.EDProducer(
"PhotonSeedGainProducer", src = cms.InputTag(
"slimmedPhotons"))
80 import RecoEgamma.EgammaTools.calibratedEgammas_cff
81 calibratedPatPhotons102Xv1 = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
82 produceCalibratedObjs =
False,
83 correctionFile = cms.string(
"EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2018_Step2Closure_CoarseEtaR9Gain_v2")
86 calibratedPatPhotons94Xv1 = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
87 produceCalibratedObjs =
False,
88 correctionFile = cms.string(
"EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_17Nov2017_v1_ele_unc")
91 calibratedPatPhotons80XLegacy = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
92 produceCalibratedObjs =
False,
93 correctionFile = cms.string(
"EgammaAnalysis/ElectronTools/data/ScalesSmearings/Legacy2016_07Aug2017_FineEtaR9_v3_ele_unc"),
96 slimmedPhotonsWithUserData = cms.EDProducer(
"PATPhotonUserDataEmbedder",
97 src = cms.InputTag(
"slimmedPhotons"),
98 userFloats = cms.PSet(
99 mvaID = cms.InputTag(
"photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v2Values"),
100 mvaID_Fall17V1p1 = cms.InputTag(
"photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v1p1Values"),
101 mvaID_Spring16nonTrigV1 = cms.InputTag(
"photonMVAValueMapProducer:PhotonMVAEstimatorRun2Spring16NonTrigV1Values"),
102 PFIsoChg = cms.InputTag(
"isoForPho:PFIsoChg"),
103 PFIsoAll = cms.InputTag(
"isoForPho:PFIsoAll"),
105 userIntFromBools = cms.PSet(
106 cutbasedID_loose = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-loose"),
107 cutbasedID_medium = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-medium"),
108 cutbasedID_tight = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-tight"),
109 mvaID_WP90 = cms.InputTag(
"egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp90"),
110 mvaID_WP80 = cms.InputTag(
"egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp80"),
111 cutbasedIDV1_loose = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-loose"),
112 cutbasedIDV1_medium = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-medium"),
113 cutbasedIDV1_tight = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-tight"),
114 cutID_Spring16_loose = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose"),
115 cutID_Spring16_medium = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium"),
116 cutID_Spring16_tight = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight"),
117 mvaID_Spring16nonTrigV1_WP90 = cms.InputTag(
"egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp90"),
118 mvaID_Spring16nonTrigV1_WP80 = cms.InputTag(
"egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp80"),
121 VIDNestedWPBitmap = cms.InputTag(
"bitmapVIDForPho"),
122 VIDNestedWPBitmap_Spring16V2p2 = cms.InputTag(
"bitmapVIDForPhoSpring16V2p2"),
123 seedGain = cms.InputTag(
"seedGainPho"),
127 run2_miniAOD_80XLegacy.toModify(slimmedPhotonsWithUserData.userFloats,
128 ecalEnergyErrPostCorrNew = cms.InputTag(
"calibratedPatPhotons80XLegacy",
"ecalEnergyErrPostCorr"),
129 ecalEnergyPreCorrNew = cms.InputTag(
"calibratedPatPhotons80XLegacy",
"ecalEnergyPreCorr"),
130 ecalEnergyPostCorrNew = cms.InputTag(
"calibratedPatPhotons80XLegacy",
"ecalEnergyPostCorr"),
132 run2_nanoAOD_94XMiniAODv1.toModify(slimmedPhotonsWithUserData.userFloats,
133 ecalEnergyErrPostCorrNew = cms.InputTag(
"calibratedPatPhotons94Xv1",
"ecalEnergyErrPostCorr"),
134 ecalEnergyPreCorrNew = cms.InputTag(
"calibratedPatPhotons94Xv1",
"ecalEnergyPreCorr"),
135 ecalEnergyPostCorrNew = cms.InputTag(
"calibratedPatPhotons94Xv1",
"ecalEnergyPostCorr"),
137 run2_nanoAOD_102Xv1.toModify(slimmedPhotonsWithUserData.userFloats,
138 ecalEnergyErrPostCorrNew = cms.InputTag(
"calibratedPatPhotons102Xv1",
"ecalEnergyErrPostCorr"),
139 ecalEnergyPreCorrNew = cms.InputTag(
"calibratedPatPhotons102Xv1",
"ecalEnergyPreCorr"),
140 ecalEnergyPostCorrNew = cms.InputTag(
"calibratedPatPhotons102Xv1",
"ecalEnergyPostCorr"),
143 finalPhotons = cms.EDFilter(
"PATPhotonRefSelector",
144 src = cms.InputTag(
"slimmedPhotonsWithUserData"),
145 cut = cms.string(
"pt > 5 ")
148 photonTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
149 src = cms.InputTag(
"linkedObjects",
"photons"),
150 cut = cms.string(
""),
151 name= cms.string(
"Photon"),
152 doc = cms.string(
"slimmedPhotons after basic selection (" + finalPhotons.cut.value()+
")"),
153 singleton = cms.bool(
False),
154 extension = cms.bool(
False),
155 variables = cms.PSet(CandVars,
156 jetIdx =
Var(
"?hasUserCand('jet')?userCand('jet').key():-1", int, doc=
"index of the associated jet (-1 if none)"),
157 electronIdx =
Var(
"?hasUserCand('electron')?userCand('electron').key():-1", int, doc=
"index of the associated electron (-1 if none)"),
158 energyErr =
Var(
"getCorrectedEnergyError('regression2')",float,doc=
"energy error of the cluster from regression",precision=6),
159 r9 =
Var(
"full5x5_r9()",float,doc=
"R9 of the supercluster, calculated with full 5x5 region",precision=10),
160 sieie =
Var(
"full5x5_sigmaIetaIeta()",float,doc=
"sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=10),
162 "userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",
164 doc=
"cut-based ID bitmap, Fall17V2, (0:fail, 1:loose, 2:medium, 3:tight)"
166 cutBased_Fall17V1Bitmap =
Var(
167 "userInt('cutbasedIDV1_loose')+2*userInt('cutbasedIDV1_medium')+4*userInt('cutbasedIDV1_tight')",
169 doc=
"cut-based ID bitmap, Fall17V1, 2^(0:loose, 1:medium, 2:tight).",
172 "userInt('VIDNestedWPBitmap')",
176 electronVeto =
Var(
"passElectronVeto()",bool,doc=
"pass electron veto"),
177 pixelSeed =
Var(
"hasPixelSeed()",bool,doc=
"has pixel seed"),
178 mvaID =
Var(
"userFloat('mvaID')",float,doc=
"MVA ID score, Fall17V2",precision=10),
179 mvaID_Fall17V1p1 =
Var(
"userFloat('mvaID_Fall17V1p1')",float,doc=
"MVA ID score, Fall17V1p1",precision=10),
180 mvaID_WP90 =
Var(
"userInt('mvaID_WP90')",bool,doc=
"MVA ID WP90, Fall17V2"),
181 mvaID_WP80 =
Var(
"userInt('mvaID_WP80')",bool,doc=
"MVA ID WP80, Fall17V2"),
182 cutBased_Spring16V2p2 =
Var(
183 "userInt('cutID_Spring16_loose')+userInt('cutID_Spring16_medium')+userInt('cutID_Spring16_tight')",
185 doc=
"cut-based ID bitmap, Spring16V2p2, (0:fail, 1:loose, 2:medium, 3:tight)"
187 mvaID_Spring16nonTrigV1 =
Var(
188 "userFloat('mvaID_Spring16nonTrigV1')",
190 doc=
"MVA ID score, Spring16nonTrigV1",
193 vidNestedWPBitmap_Spring16V2p2 =
Var(
194 "userInt('VIDNestedWPBitmap_Spring16V2p2')",
198 pfRelIso03_chg =
Var(
"userFloat('PFIsoChg')/pt",float,doc=
"PF relative isolation dR=0.3, charged component (with rho*EA PU corrections)"),
199 pfRelIso03_all =
Var(
"userFloat('PFIsoAll')/pt",float,doc=
"PF relative isolation dR=0.3, total (with rho*EA PU corrections)"),
200 hoe =
Var(
"hadronicOverEm()",float,doc=
"H over E",precision=8),
201 isScEtaEB =
Var(
"abs(superCluster().eta()) < 1.4442",bool,doc=
"is supercluster eta within barrel acceptance"),
202 isScEtaEE =
Var(
"abs(superCluster().eta()) > 1.566 && abs(superCluster().eta()) < 2.5",bool,doc=
"is supercluster eta within endcap acceptance"),
203 seedGain =
Var(
"userInt('seedGain')",
"uint8",doc=
"Gain of the seed crystal"),
208 for modifier
in run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_94X2016:
209 modifier.toModify(photonTable.variables,
210 pt =
Var(
"pt*userFloat('ecalEnergyPostCorr')/userFloat('ecalEnergyPreCorr')", float, precision=-1, doc=
"p_{T}"),
211 energyErr =
Var(
"userFloat('ecalEnergyErrPostCorr')",float,doc=
"energy error of the cluster from regression",precision=6),
212 eCorr =
Var(
"userFloat('ecalEnergyPostCorr')/userFloat('ecalEnergyPreCorr')",float,doc=
"ratio of the calibrated energy/miniaod energy"),
216 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_miniAOD_80XLegacy, run2_nanoAOD_102Xv1:
217 modifier.toModify(photonTable.variables,
218 pt =
Var(
"pt*userFloat('ecalEnergyPostCorrNew')/userFloat('ecalEnergyPreCorrNew')", float, precision=-1, doc=
"p_{T}"),
219 energyErr =
Var(
"userFloat('ecalEnergyErrPostCorrNew')",float,doc=
"energy error of the cluster from regression",precision=6),
220 eCorr =
Var(
"userFloat('ecalEnergyPostCorrNew')/userFloat('ecalEnergyPreCorrNew')",float,doc=
"ratio of the calibrated energy/miniaod energy"),
224 (~(run2_nanoAOD_94X2016 | run2_miniAOD_80XLegacy)).toModify(photonTable.variables,
225 cutBased_Spring16V2p2 =
None,
226 mvaID_Spring16nonTrigV1 =
None,
227 vidNestedWPBitmap_Spring16V2p2 =
None,
231 photonsMCMatchForTable = cms.EDProducer(
"MCMatcher",
232 src = photonTable.src,
233 matched = cms.InputTag(
"finalGenParticles"),
234 mcPdgId = cms.vint32(11,22),
235 checkCharge = cms.bool(
False),
236 mcStatus = cms.vint32(1),
237 maxDeltaR = cms.double(0.3),
238 maxDPtRel = cms.double(0.5),
239 resolveAmbiguities = cms.bool(
True),
240 resolveByMatchQuality = cms.bool(
True),
243 photonMCTable = cms.EDProducer(
"CandMCMatchTableProducer",
244 src = photonTable.src,
245 mcMap = cms.InputTag(
"photonsMCMatchForTable"),
246 objName = photonTable.name,
247 objType = photonTable.name,
248 branchName = cms.string(
"genPart"),
249 docString = cms.string(
"MC matching to status==1 photons or electrons"),
252 from RecoEgamma.EgammaTools.egammaObjectModificationsInMiniAOD_cff
import egamma8XObjectUpdateModifier,egamma9X105XUpdateModifier,prependEgamma8XObjectUpdateModifier
254 slimmedPhotonsTo106X = cms.EDProducer(
"ModifiedPhotonProducer",
255 src = cms.InputTag(
"slimmedPhotons"),
256 modifierConfig = cms.PSet( modifications = cms.VPSet(egamma9X105XUpdateModifier) )
259 run2_miniAOD_80XLegacy.toModify( slimmedPhotonsTo106X.modifierConfig.modifications, prependEgamma8XObjectUpdateModifier )
261 for modifier
in run2_miniAOD_80XLegacy,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_94X2016 ,run2_nanoAOD_102Xv1:
262 modifier.toModify(bitmapVIDForPho, src =
"slimmedPhotonsTo106X")
263 modifier.toModify(bitmapVIDForPhoSpring16V2p2, src =
"slimmedPhotonsTo106X")
264 modifier.toModify(isoForPho, src =
"slimmedPhotonsTo106X")
265 modifier.toModify(calibratedPatPhotons102Xv1, src =
"slimmedPhotonsTo106X")
266 modifier.toModify(calibratedPatPhotons94Xv1, src =
"slimmedPhotonsTo106X")
267 modifier.toModify(calibratedPatPhotons80XLegacy, src =
"slimmedPhotonsTo106X")
268 modifier.toModify(slimmedPhotonsWithUserData, src =
"slimmedPhotonsTo106X")
269 modifier.toModify(seedGainPho, src =
"slimmedPhotonsTo106X")
272 photonSequence = cms.Sequence(
274 bitmapVIDForPhoSpring16V2p2 + \
277 slimmedPhotonsWithUserData + \
281 photonTables = cms.Sequence ( photonTable)
282 photonMC = cms.Sequence(photonsMCMatchForTable + photonMCTable)
284 from RecoEgamma.EgammaIsolationAlgos.egmPhotonIsolationMiniAOD_cff
import egmPhotonIsolation
285 from RecoEgamma.PhotonIdentification.photonIDValueMapProducer_cff
import photonIDValueMapProducer
286 _updatePhoTo106X_sequence =cms.Sequence(egmPhotonIsolation + photonIDValueMapProducer + slimmedPhotonsTo106X)
287 _withUpdatePho_sequence = photonSequence.copy()
288 _withUpdatePho_sequence.insert(0,_updatePhoTo106X_sequence)
289 for modifier
in run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_94X2016 ,run2_nanoAOD_102Xv1:
290 modifier.toReplaceWith(photonSequence, _withUpdatePho_sequence)
292 _with80XScale_sequence = _withUpdatePho_sequence.copy()
293 _with80XScale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons80XLegacy + slimmedPhotonsWithUserData)
294 run2_miniAOD_80XLegacy.toReplaceWith(photonSequence, _with80XScale_sequence)
296 _with94Xv1Scale_sequence = _withUpdatePho_sequence.copy()
297 _with94Xv1Scale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons94Xv1 + slimmedPhotonsWithUserData)
298 run2_nanoAOD_94XMiniAODv1.toReplaceWith(photonSequence, _with94Xv1Scale_sequence)
300 _with102Xv1Scale_sequence = photonSequence.copy()
301 _with102Xv1Scale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons102Xv1 + slimmedPhotonsWithUserData)
302 run2_nanoAOD_102Xv1.toReplaceWith(photonSequence, _with102Xv1Scale_sequence)