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
11 photon_id_modules_WorkingPoints_nanoAOD = cms.PSet(
12 modules = cms.vstring(
13 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff',
14 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff',
15 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff',
16 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff',
17 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff',
18 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff',
20 WorkingPoints = cms.vstring(
21 "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-loose",
22 "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-medium",
23 "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-tight",
26 photon_id_modules_WorkingPoints_nanoAOD_Spring16V2p2 = cms.PSet(
27 modules = photon_id_modules_WorkingPoints_nanoAOD.modules,
28 WorkingPoints = cms.vstring(
29 "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose",
30 "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium",
31 "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight",
36 pset = id_modules_working_points_pset
38 for modname
in pset.modules:
39 ids = __import__(modname, globals(), locals(), [
'idName',
'cutFlow'])
41 _id = getattr(ids,name)
42 if hasattr(_id,
'idName')
and hasattr(_id,
'cutFlow'):
43 if (len(pset.WorkingPoints)>0
and _id.idName == pset.WorkingPoints[0].
split(
':')[-1]):
44 cut_names =
','.
join([cut.cutName.value()
for cut
in _id.cutFlow])
45 n_bits_per_cut =
int(ceil(
log(len(pset.WorkingPoints)+1,2)))
46 return 'VID compressed bitmap (%s), %d bits per cut'%(cut_names, n_bits_per_cut)
47 raise ValueError(
"Something is wrong in the photon ID modules parameter set!")
49 bitmapVIDForPho = cms.EDProducer(
"PhoVIDNestedWPBitmapProducer",
50 src = cms.InputTag(
"slimmedPhotons"),
51 WorkingPoints = photon_id_modules_WorkingPoints_nanoAOD.WorkingPoints,
54 bitmapVIDForPhoSpring16V2p2 = cms.EDProducer(
"PhoVIDNestedWPBitmapProducer",
55 src = cms.InputTag(
"slimmedPhotons"),
56 WorkingPoints = photon_id_modules_WorkingPoints_nanoAOD_Spring16V2p2.WorkingPoints,
59 isoForPho = cms.EDProducer(
"PhoIsoValueMapProducer",
60 src = cms.InputTag(
"slimmedPhotons"),
61 relative = cms.bool(
False),
62 rho_PFIso = cms.InputTag(
"fixedGridRhoFastjetAll"),
63 mapIsoChg = cms.InputTag(
"photonIDValueMapProducer:phoChargedIsolation"),
64 mapIsoNeu = cms.InputTag(
"photonIDValueMapProducer:phoNeutralHadronIsolation"),
65 mapIsoPho = cms.InputTag(
"photonIDValueMapProducer:phoPhotonIsolation"),
66 EAFile_PFIso_Chg = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt"),
67 EAFile_PFIso_Neu = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt"),
68 EAFile_PFIso_Pho = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt"),
70 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
71 modifier.toModify(isoForPho,
72 EAFile_PFIso_Chg = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfChargedHadrons_90percentBased.txt"),
73 EAFile_PFIso_Neu = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased.txt"),
74 EAFile_PFIso_Pho = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfPhotons_90percentBased.txt"),
77 seedGainPho = cms.EDProducer(
"PhotonSeedGainProducer", src = cms.InputTag(
"slimmedPhotons"))
79 import RecoEgamma.EgammaTools.calibratedEgammas_cff
80 calibratedPatPhotons102Xv1 = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
81 produceCalibratedObjs =
False,
82 correctionFile = cms.string(
"EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2018_Step2Closure_CoarseEtaR9Gain_v2")
85 calibratedPatPhotons94Xv1 = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
86 produceCalibratedObjs =
False,
87 correctionFile = cms.string(
"EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_17Nov2017_v1_ele_unc")
90 calibratedPatPhotons80XLegacy = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
91 produceCalibratedObjs =
False,
92 correctionFile = cms.string(
"EgammaAnalysis/ElectronTools/data/ScalesSmearings/Legacy2016_07Aug2017_FineEtaR9_v3_ele_unc"),
95 slimmedPhotonsWithUserData = cms.EDProducer(
"PATPhotonUserDataEmbedder",
96 src = cms.InputTag(
"slimmedPhotons"),
97 userFloats = cms.PSet(
98 mvaID = cms.InputTag(
"photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v2Values"),
99 mvaID_Fall17V1p1 = cms.InputTag(
"photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v1p1Values"),
100 mvaID_Spring16nonTrigV1 = cms.InputTag(
"photonMVAValueMapProducer:PhotonMVAEstimatorRun2Spring16NonTrigV1Values"),
101 PFIsoChg = cms.InputTag(
"isoForPho:PFIsoChg"),
102 PFIsoAll = cms.InputTag(
"isoForPho:PFIsoAll"),
104 userIntFromBools = cms.PSet(
105 cutbasedID_loose = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-loose"),
106 cutbasedID_medium = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-medium"),
107 cutbasedID_tight = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-tight"),
108 mvaID_WP90 = cms.InputTag(
"egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp90"),
109 mvaID_WP80 = cms.InputTag(
"egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp80"),
110 cutbasedIDV1_loose = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-loose"),
111 cutbasedIDV1_medium = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-medium"),
112 cutbasedIDV1_tight = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-tight"),
113 cutID_Spring16_loose = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose"),
114 cutID_Spring16_medium = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium"),
115 cutID_Spring16_tight = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight"),
116 mvaID_Spring16nonTrigV1_WP90 = cms.InputTag(
"egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp90"),
117 mvaID_Spring16nonTrigV1_WP80 = cms.InputTag(
"egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp80"),
120 VIDNestedWPBitmap = cms.InputTag(
"bitmapVIDForPho"),
121 VIDNestedWPBitmap_Spring16V2p2 = cms.InputTag(
"bitmapVIDForPhoSpring16V2p2"),
122 seedGain = cms.InputTag(
"seedGainPho"),
126 run2_miniAOD_80XLegacy.toModify(slimmedPhotonsWithUserData.userFloats,
127 ecalEnergyErrPostCorrNew = cms.InputTag(
"calibratedPatPhotons80XLegacy",
"ecalEnergyErrPostCorr"),
128 ecalEnergyPreCorrNew = cms.InputTag(
"calibratedPatPhotons80XLegacy",
"ecalEnergyPreCorr"),
129 ecalEnergyPostCorrNew = cms.InputTag(
"calibratedPatPhotons80XLegacy",
"ecalEnergyPostCorr"),
131 run2_nanoAOD_94XMiniAODv1.toModify(slimmedPhotonsWithUserData.userFloats,
132 ecalEnergyErrPostCorrNew = cms.InputTag(
"calibratedPatPhotons94Xv1",
"ecalEnergyErrPostCorr"),
133 ecalEnergyPreCorrNew = cms.InputTag(
"calibratedPatPhotons94Xv1",
"ecalEnergyPreCorr"),
134 ecalEnergyPostCorrNew = cms.InputTag(
"calibratedPatPhotons94Xv1",
"ecalEnergyPostCorr"),
136 (~(run2_miniAOD_80XLegacy | run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94XMiniAODv2)).toModify(slimmedPhotonsWithUserData.userFloats,
137 ecalEnergyErrPostCorrNew = cms.InputTag(
"calibratedPatPhotons102Xv1",
"ecalEnergyErrPostCorr"),
138 ecalEnergyPreCorrNew = cms.InputTag(
"calibratedPatPhotons102Xv1",
"ecalEnergyPreCorr"),
139 ecalEnergyPostCorrNew = cms.InputTag(
"calibratedPatPhotons102Xv1",
"ecalEnergyPostCorr"),
142 finalPhotons = cms.EDFilter(
"PATPhotonRefSelector",
143 src = cms.InputTag(
"slimmedPhotonsWithUserData"),
144 cut = cms.string(
"pt > 5 ")
147 photonTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
148 src = cms.InputTag(
"linkedObjects",
"photons"),
149 cut = cms.string(
""),
150 name= cms.string(
"Photon"),
151 doc = cms.string(
"slimmedPhotons after basic selection (" + finalPhotons.cut.value()+
")"),
152 singleton = cms.bool(
False),
153 extension = cms.bool(
False),
154 variables = cms.PSet(CandVars,
155 jetIdx =
Var(
"?hasUserCand('jet')?userCand('jet').key():-1", int, doc=
"index of the associated jet (-1 if none)"),
156 electronIdx =
Var(
"?hasUserCand('electron')?userCand('electron').key():-1", int, doc=
"index of the associated electron (-1 if none)"),
157 energyErr =
Var(
"getCorrectedEnergyError('regression2')",float,doc=
"energy error of the cluster from regression",precision=6),
158 r9 =
Var(
"full5x5_r9()",float,doc=
"R9 of the supercluster, calculated with full 5x5 region",precision=10),
159 sieie =
Var(
"full5x5_sigmaIetaIeta()",float,doc=
"sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=10),
161 "userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",
163 doc=
"cut-based ID bitmap, Fall17V2, (0:fail, 1:loose, 2:medium, 3:tight)" 165 cutBased_Fall17V1Bitmap =
Var(
166 "userInt('cutbasedIDV1_loose')+2*userInt('cutbasedIDV1_medium')+4*userInt('cutbasedIDV1_tight')",
168 doc=
"cut-based ID bitmap, Fall17V1, 2^(0:loose, 1:medium, 2:tight).",
171 "userInt('VIDNestedWPBitmap')",
175 electronVeto =
Var(
"passElectronVeto()",bool,doc=
"pass electron veto"),
176 pixelSeed =
Var(
"hasPixelSeed()",bool,doc=
"has pixel seed"),
177 mvaID =
Var(
"userFloat('mvaID')",float,doc=
"MVA ID score, Fall17V2",precision=10),
178 mvaID_Fall17V1p1 =
Var(
"userFloat('mvaID_Fall17V1p1')",float,doc=
"MVA ID score, Fall17V1p1",precision=10),
179 mvaID_WP90 =
Var(
"userInt('mvaID_WP90')",bool,doc=
"MVA ID WP90, Fall17V2"),
180 mvaID_WP80 =
Var(
"userInt('mvaID_WP80')",bool,doc=
"MVA ID WP80, Fall17V2"),
181 cutBased_Spring16V2p2 =
Var(
182 "userInt('cutID_Spring16_loose')+userInt('cutID_Spring16_medium')+userInt('cutID_Spring16_tight')",
184 doc=
"cut-based ID bitmap, Spring16V2p2, (0:fail, 1:loose, 2:medium, 3:tight)" 186 mvaID_Spring16nonTrigV1 =
Var(
187 "userFloat('mvaID_Spring16nonTrigV1')",
189 doc=
"MVA ID score, Spring16nonTrigV1",
192 vidNestedWPBitmap_Spring16V2p2 =
Var(
193 "userInt('VIDNestedWPBitmap_Spring16V2p2')",
197 pfRelIso03_chg =
Var(
"userFloat('PFIsoChg')/pt",float,doc=
"PF relative isolation dR=0.3, charged component (with rho*EA PU corrections)"),
198 pfRelIso03_all =
Var(
"userFloat('PFIsoAll')/pt",float,doc=
"PF relative isolation dR=0.3, total (with rho*EA PU corrections)"),
199 hoe =
Var(
"hadronicOverEm()",float,doc=
"H over E",precision=8),
200 isScEtaEB =
Var(
"abs(superCluster().eta()) < 1.4442",bool,doc=
"is supercluster eta within barrel acceptance"),
201 isScEtaEE =
Var(
"abs(superCluster().eta()) > 1.566 && abs(superCluster().eta()) < 2.5",bool,doc=
"is supercluster eta within endcap acceptance"),
202 seedGain =
Var(
"userInt('seedGain')",
"uint8",doc=
"Gain of the seed crystal"),
207 for modifier
in run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_94X2016:
208 modifier.toModify(photonTable.variables,
209 pt =
Var(
"pt*userFloat('ecalEnergyPostCorr')/userFloat('ecalEnergyPreCorr')", float, precision=-1, doc=
"p_{T}"),
210 energyErr =
Var(
"userFloat('ecalEnergyErrPostCorr')",float,doc=
"energy error of the cluster from regression",precision=6),
211 eCorr =
Var(
"userFloat('ecalEnergyPostCorr')/userFloat('ecalEnergyPreCorr')",float,doc=
"ratio of the calibrated energy/miniaod energy"),
215 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_miniAOD_80XLegacy, (~(run2_miniAOD_80XLegacy | run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94XMiniAODv2)):
216 modifier.toModify(photonTable.variables,
217 pt =
Var(
"pt*userFloat('ecalEnergyPostCorrNew')/userFloat('ecalEnergyPreCorrNew')", float, precision=-1, doc=
"p_{T}"),
218 energyErr =
Var(
"userFloat('ecalEnergyErrPostCorrNew')",float,doc=
"energy error of the cluster from regression",precision=6),
219 eCorr =
Var(
"userFloat('ecalEnergyPostCorrNew')/userFloat('ecalEnergyPreCorrNew')",float,doc=
"ratio of the calibrated energy/miniaod energy"),
223 (~(run2_nanoAOD_94X2016 | run2_miniAOD_80XLegacy)).toModify(photonTable.variables,
224 cutBased_Spring16V2p2 =
None,
225 mvaID_Spring16nonTrigV1 =
None,
226 vidNestedWPBitmap_Spring16V2p2 =
None,
230 photonsMCMatchForTable = cms.EDProducer(
"MCMatcher",
231 src = photonTable.src,
232 matched = cms.InputTag(
"finalGenParticles"),
233 mcPdgId = cms.vint32(11,22),
234 checkCharge = cms.bool(
False),
235 mcStatus = cms.vint32(1),
236 maxDeltaR = cms.double(0.3),
237 maxDPtRel = cms.double(0.5),
238 resolveAmbiguities = cms.bool(
True),
239 resolveByMatchQuality = cms.bool(
True),
242 photonMCTable = cms.EDProducer(
"CandMCMatchTableProducer",
243 src = photonTable.src,
244 mcMap = cms.InputTag(
"photonsMCMatchForTable"),
245 objName = photonTable.name,
246 objType = photonTable.name,
247 branchName = cms.string(
"genPart"),
248 docString = cms.string(
"MC matching to status==1 photons or electrons"),
251 photonSequence = cms.Sequence(
253 bitmapVIDForPhoSpring16V2p2 + \
256 slimmedPhotonsWithUserData + \
260 photonTables = cms.Sequence ( photonTable)
261 photonMC = cms.Sequence(photonsMCMatchForTable + photonMCTable)
263 _with80XScale_sequence = photonSequence.copy()
264 _with80XScale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons80XLegacy + slimmedPhotonsWithUserData)
265 run2_miniAOD_80XLegacy.toReplaceWith(photonSequence, _with80XScale_sequence)
267 _with94Xv1Scale_sequence = photonSequence.copy()
268 _with94Xv1Scale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons94Xv1 + slimmedPhotonsWithUserData)
269 run2_nanoAOD_94XMiniAODv1.toReplaceWith(photonSequence, _with94Xv1Scale_sequence)
271 _with102Xv1Scale_sequence = photonSequence.copy()
272 _with102Xv1Scale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons102Xv1 + slimmedPhotonsWithUserData)
273 (~(run2_miniAOD_80XLegacy | run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94XMiniAODv2)).toReplaceWith(photonSequence, _with102Xv1Scale_sequence)
def Var(expr, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
def make_bitmapVID_docstring(id_modules_working_points_pset)
static std::string join(char **cmd)