1 import FWCore.ParameterSet.Config
as cms
4 from PhysicsTools.NanoAOD.simpleCandidateFlatTableProducer_cfi
import simpleCandidateFlatTableProducer
5 from math
import ceil,log
8 photon_id_modules_WorkingPoints_nanoAOD = cms.PSet(
10 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_RunIIIWinter22_122X_V1_cff',
11 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Winter22_122X_V1_cff',
13 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff',
14 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff',
16 WorkingPoints = cms.vstring(
17 "egmPhotonIDs:cutBasedPhotonID-RunIIIWinter22-122X-V1-loose",
18 "egmPhotonIDs:cutBasedPhotonID-RunIIIWinter22-122X-V1-medium",
19 "egmPhotonIDs:cutBasedPhotonID-RunIIIWinter22-122X-V1-tight",
23 photon_id_modules_WorkingPoints_nanoAOD_Run2 = cms.PSet(
24 modules = cms.vstring(
25 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff',
26 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff',
28 WorkingPoints = cms.vstring(
29 "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-loose",
30 "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-medium",
31 "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-tight",
37 run2_egamma.toModify(photon_id_modules_WorkingPoints_nanoAOD,
38 modules=photon_id_modules_WorkingPoints_nanoAOD_Run2.modules).\
39 toModify(photon_id_modules_WorkingPoints_nanoAOD,
40 WorkingPoints=photon_id_modules_WorkingPoints_nanoAOD_Run2.WorkingPoints)
43 pset = id_modules_working_points_pset
45 for modname
in pset.modules:
46 ids = __import__(modname, globals(), locals(), [
'idName',
'cutFlow'])
48 _id = getattr(ids,name)
49 if hasattr(_id,
'idName')
and hasattr(_id,
'cutFlow'):
50 if (len(pset.WorkingPoints)>0
and _id.idName == pset.WorkingPoints[0].
split(
':')[-1]):
51 cut_names =
','.
join([cut.cutName.value()
for cut
in _id.cutFlow])
52 n_bits_per_cut =
int(
ceil(
log(len(pset.WorkingPoints)+1,2)))
53 return 'VID compressed bitmap (%s), %d bits per cut'%(cut_names, n_bits_per_cut)
54 raise ValueError(
"Something is wrong in the photon ID modules parameter set!")
57 bitmapVIDForPho = cms.EDProducer(
"PhoVIDNestedWPBitmapProducer",
58 src = cms.InputTag(
"slimmedPhotons"),
59 srcForID = cms.InputTag(
"reducedEgamma",
"reducedGedPhotons"),
60 WorkingPoints = photon_id_modules_WorkingPoints_nanoAOD.WorkingPoints,
64 bitmapVIDForPhoRun2 = bitmapVIDForPho.clone(
65 WorkingPoints = photon_id_modules_WorkingPoints_nanoAOD_Run2.WorkingPoints,
69 isoForPho = cms.EDProducer(
"PhoIsoValueMapProducer",
70 src = cms.InputTag(
"slimmedPhotons"),
71 relative = cms.bool(
False),
72 doQuadratic = cms.bool(
True),
73 rho_PFIso = cms.InputTag(
"fixedGridRhoFastjetAll"),
74 QuadraticEAFile_PFIso_Chg = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/RunIII_Winter22/effectiveArea_ChgHadronIso_95percentBased.txt"),
75 QuadraticEAFile_PFIso_ECal = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/RunIII_Winter22/effectiveArea_ECalClusterIso_95percentBased.txt"),
76 QuadraticEAFile_PFIso_HCal = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/RunIII_Winter22/effectiveArea_HCalClusterIso_95percentBased.txt"),
79 hOverEForPho = cms.EDProducer(
"PhoHoverEValueMapProducer",
80 src = cms.InputTag(
"slimmedPhotons"),
81 relative = cms.bool(
False),
82 rho = cms.InputTag(
"fixedGridRhoFastjetAll"),
83 QuadraticEAFile_HoverE = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/RunIII_Winter22/effectiveArea_coneBasedHoverE_95percentBased.txt"),
86 isoForPhoFall17V2 = isoForPho.clone(
87 doQuadratic = cms.bool(
False),
88 EAFile_PFIso_Chg = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt"),
89 EAFile_PFIso_Neu = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt"),
90 EAFile_PFIso_Pho = cms.FileInPath(
"RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt"),
94 seedGainPho = cms.EDProducer(
"PhotonSeedGainProducer", src = cms.InputTag(
"slimmedPhotons"))
96 import RecoEgamma.EgammaTools.calibratedEgammas_cff
98 calibratedPatPhotonsNano = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
99 produceCalibratedObjs =
False,
100 correctionFile = cms.string(
"EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_preVFP_RunFineEtaR9Gain"),
103 (run2_egamma_2016 & tracker_apv_vfp30_2016).toModify(
104 calibratedPatPhotonsNano,
105 correctionFile = cms.string(
"EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_preVFP_RunFineEtaR9Gain")
108 (run2_egamma_2016 & ~tracker_apv_vfp30_2016).toModify(
109 calibratedPatPhotonsNano,
110 correctionFile = cms.string(
"EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_postVFP_RunFineEtaR9Gain"),
113 run2_egamma_2017.toModify(
114 calibratedPatPhotonsNano,
115 correctionFile = cms.string(
"EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_24Feb2020_runEtaR9Gain_v2")
118 run2_egamma_2018.toModify(
119 calibratedPatPhotonsNano,
120 correctionFile = cms.string(
"EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2018_29Sep2020_RunFineEtaR9Gain")
123 slimmedPhotonsWithUserData = cms.EDProducer(
"PATPhotonUserDataEmbedder",
124 src = cms.InputTag(
"slimmedPhotons"),
125 parentSrcs = cms.VInputTag(
"reducedEgamma:reducedGedPhotons"),
126 userFloats = cms.PSet(
127 mvaID = cms.InputTag(
"photonMVAValueMapProducer:PhotonMVAEstimatorRunIIIWinter22v1Values"),
128 PFIsoChgQuadratic = cms.InputTag(
"isoForPho:PFIsoChgQuadratic"),
129 PFIsoAllQuadratic = cms.InputTag(
"isoForPho:PFIsoAllQuadratic"),
130 HoverEQuadratic = cms.InputTag(
"hOverEForPho:HoEForPhoEACorr"),
131 mvaID_Fall17V2 = cms.InputTag(
"photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v2Values"),
132 PFIsoChgFall17V2 = cms.InputTag(
"isoForPhoFall17V2:PFIsoChg"),
133 PFIsoAllFall17V2 = cms.InputTag(
"isoForPhoFall17V2:PFIsoAll"),
135 userIntFromBools = cms.PSet(
136 cutBasedID_loose = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-RunIIIWinter22-122X-V1-loose"),
137 cutBasedID_medium = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-RunIIIWinter22-122X-V1-medium"),
138 cutBasedID_tight = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-RunIIIWinter22-122X-V1-tight"),
139 cutBasedID_Fall17V2_loose = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-loose"),
140 cutBasedID_Fall17V2_medium = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-medium"),
141 cutBasedID_Fall17V2_tight = cms.InputTag(
"egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-tight"),
142 mvaID_WP90 = cms.InputTag(
"egmPhotonIDs:mvaPhoID-RunIIIWinter22-v1-wp90"),
143 mvaID_WP80 = cms.InputTag(
"egmPhotonIDs:mvaPhoID-RunIIIWinter22-v1-wp80"),
144 mvaID_Fall17V2_WP90 = cms.InputTag(
"egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp90"),
145 mvaID_Fall17V2_WP80 = cms.InputTag(
"egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp80"),
148 VIDNestedWPBitmap = cms.InputTag(
"bitmapVIDForPho"),
149 VIDNestedWPBitmapFall17V2 = cms.InputTag(
"bitmapVIDForPhoRun2"),
150 seedGain = cms.InputTag(
"seedGainPho"),
156 run2_egamma.toModify(slimmedPhotonsWithUserData.userFloats,
158 PFIsoChgQuadratic =
None,
159 PFIsoAllQuadratic =
None,
160 HoverEQuadratic =
None).\
161 toModify(slimmedPhotonsWithUserData.userIntFromBools,
162 cutBasedID_loose =
None,
163 cutBasedID_medium =
None,
164 cutBasedID_tight =
None,
167 toModify(slimmedPhotonsWithUserData.userInts,
168 VIDNestedWPBitmap =
None)
170 run2_egamma.toModify(
171 slimmedPhotonsWithUserData.userFloats,
172 ecalEnergyErrPostCorrNew = cms.InputTag(
"calibratedPatPhotonsNano",
"ecalEnergyErrPostCorr"),
173 ecalEnergyPreCorrNew = cms.InputTag(
"calibratedPatPhotonsNano",
"ecalEnergyPreCorr"),
174 ecalEnergyPostCorrNew = cms.InputTag(
"calibratedPatPhotonsNano",
"ecalEnergyPostCorr"),
175 energyScaleUpNew = cms.InputTag(
"calibratedPatPhotonsNano",
"energyScaleUp"),
176 energyScaleDownNew = cms.InputTag(
"calibratedPatPhotonsNano",
"energyScaleDown"),
177 energySigmaUpNew = cms.InputTag(
"calibratedPatPhotonsNano",
"energySigmaUp"),
178 energySigmaDownNew = cms.InputTag(
"calibratedPatPhotonsNano",
"energySigmaDown"),
182 finalPhotons = cms.EDFilter(
"PATPhotonRefSelector",
183 src = cms.InputTag(
"slimmedPhotonsWithUserData"),
184 cut = cms.string(
"pt > 5 ")
187 photonTable = simpleCandidateFlatTableProducer.clone(
188 src = cms.InputTag(
"linkedObjects",
"photons"),
189 name= cms.string(
"Photon"),
190 doc = cms.string(
"slimmedPhotons after basic selection (" + finalPhotons.cut.value()+
")"),
191 variables = cms.PSet(P3Vars,
192 jetIdx =
Var(
"?hasUserCand('jet')?userCand('jet').key():-1",
"int16", doc=
"index of the associated jet (-1 if none)"),
193 electronIdx =
Var(
"?hasUserCand('electron')?userCand('electron').key():-1",
"int16", doc=
"index of the associated electron (-1 if none)"),
194 energyErr =
Var(
"getCorrectedEnergyError('regression2')",float,doc=
"energy error of the cluster from regression",precision=10),
195 energyRaw =
Var(
"superCluster().rawEnergy()",float,doc=
"raw energy of photon supercluster", precision=10),
196 superclusterEta =
Var(
"superCluster().eta()",float,doc=
"supercluster eta",precision=10),
197 r9 =
Var(
"full5x5_r9()",float,doc=
"R9 of the supercluster, calculated with full 5x5 region",precision=10),
198 sieie =
Var(
"full5x5_sigmaIetaIeta()",float,doc=
"sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=10),
199 sipip =
Var(
"showerShapeVariables().sigmaIphiIphi", float, doc=
"sigmaIphiIphi of the supercluster", precision=10),
200 sieip =
Var(
"full5x5_showerShapeVariables().sigmaIetaIphi",float,doc=
"sigma_IetaIphi of the supercluster, calculated with full 5x5 region",precision=10),
201 s4 =
Var(
"full5x5_showerShapeVariables().e2x2/full5x5_showerShapeVariables().e5x5",float,doc=
"e2x2/e5x5 of the supercluster, calculated with full 5x5 region",precision=10),
202 etaWidth =
Var(
"superCluster().etaWidth()",float,doc=
"Width of the photon supercluster in eta", precision=10),
203 phiWidth =
Var(
"superCluster().phiWidth()",float,doc=
"Width of the photon supercluster in phi", precision=10),
205 "userInt('cutBasedID_loose')+userInt('cutBasedID_medium')+userInt('cutBasedID_tight')",
207 doc=
"cut-based ID bitmap, RunIIIWinter22V1, (0:fail, 1:loose, 2:medium, 3:tight)",
210 "userInt('VIDNestedWPBitmap')",
212 doc=
"RunIIIWinter22V1 " + _bitmapVIDForPho_docstring
214 electronVeto =
Var(
"passElectronVeto()",bool,doc=
"pass electron veto"),
215 pixelSeed =
Var(
"hasPixelSeed()",bool,doc=
"has pixel seed"),
216 hasConversionTracks =
Var(
"hasConversionTracks()",bool,doc=
"Variable specifying if photon has associated conversion tracks (one-legged or two-legged)"),
217 mvaID =
Var(
"userFloat('mvaID')",float,doc=
"MVA ID score, Winter22V1",precision=10),
218 mvaID_WP90 =
Var(
"userInt('mvaID_WP90')",bool,doc=
"MVA ID WP90, Winter22V1"),
219 mvaID_WP80 =
Var(
"userInt('mvaID_WP80')",bool,doc=
"MVA ID WP80, Winter22V1"),
220 trkSumPtHollowConeDR03 =
Var(
"trkSumPtHollowConeDR03()",float,doc=
"Sum of track pT in a hollow cone of outer radius, inner radius", precision=10),
221 trkSumPtSolidConeDR04 =
Var(
"trkSumPtSolidConeDR04()",float,doc=
"Sum of track pT in a cone of dR=0.4", precision=10),
222 ecalPFClusterIso =
Var(
"ecalPFClusterIso()",float,doc=
"sum pt of ecal clusters, vetoing clusters part of photon", precision=10),
223 hcalPFClusterIso =
Var(
"hcalPFClusterIso()",float,doc=
"sum pt of hcal clusters, vetoing clusters part of photon", precision=10),
224 pfPhoIso03 =
Var(
"photonIso()",float,doc=
"PF absolute isolation dR=0.3, photon component (uncorrected)"),
225 pfChargedIso =
Var(
"chargedHadronIso()",float,doc=
"PF absolute isolation dR=0.3, charged component with dxy,dz match to PV", precision=8),
226 pfChargedIsoPFPV =
Var(
"chargedHadronPFPVIso()",float,doc=
"PF absolute isolation dR=0.3, charged component (PF PV only)"),
227 pfChargedIsoWorstVtx =
Var(
"chargedHadronWorstVtxIso()",float,doc=
"PF absolute isolation dR=0.3, charged component (Vertex with largest isolation)"),
228 pfRelIso03_chg_quadratic =
Var(
"userFloat('PFIsoChgQuadratic')/pt",float,doc=
"PF relative isolation dR=0.3, charged hadron component (with quadraticEA*rho*rho + linearEA*rho Winter22V1 corrections)"),
229 pfRelIso03_all_quadratic =
Var(
"userFloat('PFIsoAllQuadratic')/pt",float,doc=
"PF relative isolation dR=0.3, total (with quadraticEA*rho*rho + linearEA*rho Winter22V1 corrections)"),
230 hoe =
Var(
"hadronicOverEm()",float,doc=
"H over E",precision=8),
231 hoe_PUcorr =
Var(
"userFloat('HoverEQuadratic')",float,doc=
"PU corrected H/E (cone-based with quadraticEA*rho*rho + linearEA*rho Winter22V1 corrections)",precision=8),
232 isScEtaEB =
Var(
"abs(superCluster().eta()) < 1.4442",bool,doc=
"is supercluster eta within barrel acceptance"),
233 isScEtaEE =
Var(
"abs(superCluster().eta()) > 1.566 && abs(superCluster().eta()) < 2.5",bool,doc=
"is supercluster eta within endcap acceptance"),
234 seedGain =
Var(
"userInt('seedGain')",
"uint8",doc=
"Gain of the seed crystal"),
235 seediEtaOriX =
Var(
"superCluster().seedCrysIEtaOrIx",
"int16",doc=
"iEta or iX of seed crystal. iEta is barrel-only, iX is endcap-only. iEta runs from -85 to +85, with no crystal at iEta=0. iX runs from 1 to 100."),
236 seediPhiOriY =
Var(
"superCluster().seedCrysIPhiOrIy",
"int16",doc=
"iPhi or iY of seed crystal. iPhi is barrel-only, iY is endcap-only. iPhi runs from 1 to 360. iY runs from 1 to 100."),
238 x_calo =
Var(
"superCluster().seed().position().x()",float,doc=
"photon supercluster position on calorimeter, x coordinate (cm)",precision=10),
239 y_calo =
Var(
"superCluster().seed().position().y()",float,doc=
"photon supercluster position on calorimeter, y coordinate (cm)",precision=10),
240 z_calo =
Var(
"superCluster().seed().position().z()",float,doc=
"photon supercluster position on calorimeter, z coordinate (cm)",precision=10),
242 esEffSigmaRR =
Var(
"full5x5_showerShapeVariables().effSigmaRR()", float, doc=
"preshower sigmaRR"),
243 esEnergyOverRawE =
Var(
"superCluster().preshowerEnergy()/superCluster().rawEnergy()", float, doc=
"ratio of preshower energy to raw supercluster energy"),
244 haloTaggerMVAVal =
Var(
"haloTaggerMVAVal()",float,doc=
"Value of MVA based BDT based beam halo tagger in the Ecal endcap (valid for pT > 200 GeV)",precision=8),
250 run2_egamma.toModify(
251 photonTable.variables,
252 pt =
Var(
"pt*userFloat('ecalEnergyPostCorrNew')/userFloat('ecalEnergyPreCorrNew')", float, precision=-1, doc=
"p_{T}"),
253 energyErr =
Var(
"userFloat('ecalEnergyErrPostCorrNew')",float,doc=
"energy error of the cluster from regression",precision=6),
254 eCorr =
Var(
"userFloat('ecalEnergyPostCorrNew')/userFloat('ecalEnergyPreCorrNew')",float,doc=
"ratio of the calibrated energy/miniaod energy"),
255 hoe =
Var(
"hadTowOverEm()",float,doc=
"H over E (Run2)",precision=8),
257 "userInt('cutBasedID_Fall17V2_loose')+userInt('cutBasedID_Fall17V2_medium')+userInt('cutBasedID_Fall17V2_tight')",
259 doc=
"cut-based ID bitmap, Fall17V2, (0:fail, 1:loose, 2:medium, 3:tight)",
261 vidNestedWPBitmap =
Var(
262 "userInt('VIDNestedWPBitmapFall17V2')",
264 doc=
"Fall17V2 " + _bitmapVIDForPhoRun2_docstring
266 mvaID =
Var(
"userFloat('mvaID_Fall17V2')",float,doc=
"MVA ID score, Fall17V2",precision=10),
267 mvaID_WP90 =
Var(
"userInt('mvaID_Fall17V2_WP90')",bool,doc=
"MVA ID WP90, Fall17V2"),
268 mvaID_WP80 =
Var(
"userInt('mvaID_Fall17V2_WP80')",bool,doc=
"MVA ID WP80, Fall17V2"),
269 pfRelIso03_chg =
Var(
"userFloat('PFIsoChgFall17V2')/pt",float,doc=
"PF relative isolation dR=0.3, charged component (with Fall17V2rho*EA PU corrections)"),
270 pfRelIso03_all =
Var(
"userFloat('PFIsoAllFall17V2')/pt",float,doc=
"PF relative isolation dR=0.3, total (with Fall17V2 rho*EA PU corrections)"),
271 pfRelIso03_chg_quadratic=
None,
272 pfRelIso03_all_quadratic=
None,
276 photonsMCMatchForTable = cms.EDProducer(
"MCMatcher",
277 src = photonTable.src,
278 matched = cms.InputTag(
"finalGenParticles"),
279 mcPdgId = cms.vint32(11,22),
280 checkCharge = cms.bool(
False),
281 mcStatus = cms.vint32(1),
282 maxDeltaR = cms.double(0.3),
283 maxDPtRel = cms.double(0.5),
284 resolveAmbiguities = cms.bool(
True),
285 resolveByMatchQuality = cms.bool(
True),
288 photonMCTable = cms.EDProducer(
"CandMCMatchTableProducer",
289 src = photonTable.src,
290 mcMap = cms.InputTag(
"photonsMCMatchForTable"),
291 objName = photonTable.name,
292 objType = photonTable.name,
293 branchName = cms.string(
"genPart"),
294 docString = cms.string(
"MC matching to status==1 photons or electrons"),
298 run2_egamma.toModify(
299 photonTable.variables,
300 dEscaleUp=
Var(
"userFloat('ecalEnergyPostCorrNew') - userFloat('energyScaleUpNew')", float, doc=
"ecal energy scale shifted 1 sigma up (adding gain/stat/syst in quadrature)", precision=8),
301 dEscaleDown=
Var(
"userFloat('ecalEnergyPostCorrNew') - userFloat('energyScaleDownNew')", float, doc=
"ecal energy scale shifted 1 sigma down (adding gain/stat/syst in quadrature)", precision=8),
302 dEsigmaUp=
Var(
"userFloat('ecalEnergyPostCorrNew') - userFloat('energySigmaUpNew')", float, doc=
"ecal energy smearing value shifted 1 sigma up", precision=8),
303 dEsigmaDown=
Var(
"userFloat('ecalEnergyPostCorrNew') - userFloat('energySigmaDownNew')", float, doc=
"ecal energy smearing value shifted 1 sigma up", precision=8),
307 photonTask = cms.Task(bitmapVIDForPho, bitmapVIDForPhoRun2, isoForPho, hOverEForPho, isoForPhoFall17V2, seedGainPho, slimmedPhotonsWithUserData, finalPhotons)
309 photonTablesTask = cms.Task(photonTable)
310 photonMCTask = cms.Task(photonsMCMatchForTable, photonMCTable)
312 _photonTask_Run2 = photonTask.copy()
313 _photonTask_Run2.remove(bitmapVIDForPho)
314 _photonTask_Run2.remove(isoForPho)
315 _photonTask_Run2.remove(hOverEForPho)
316 _photonTask_Run2.add(calibratedPatPhotonsNano)
317 run2_egamma.toReplaceWith(photonTask, _photonTask_Run2)
constexpr int32_t ceil(float num)
def Var(expr, valtype, doc=None, precision=-1)
def make_bitmapVID_docstring(id_modules_working_points_pset)
def split(sequence, size)
static std::string join(char **cmd)