CMS 3D CMS Logo

photons_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
4 
5 from math import ceil,log
6 
7 
8 photon_id_modules_WorkingPoints_nanoAOD = cms.PSet(
9  modules = cms.vstring(
10  'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff',
11  'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff',
12  'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff',
13  'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff',
14  'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff',
15  'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff',
16  ),
17  WorkingPoints = cms.vstring(
18  "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-loose",
19  "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-medium",
20  "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-tight",
21  )
22 )
23 photon_id_modules_WorkingPoints_nanoAOD_Spring16V2p2 = cms.PSet(
24  modules = photon_id_modules_WorkingPoints_nanoAOD.modules,
25  WorkingPoints = cms.vstring(
26  "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose",
27  "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium",
28  "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight",
29  )
30 )
31 
32 def make_bitmapVID_docstring(id_modules_working_points_pset):
33  pset = id_modules_working_points_pset
34 
35  for modname in pset.modules:
36  ids = __import__(modname, globals(), locals(), ['idName','cutFlow'])
37  for name in dir(ids):
38  _id = getattr(ids,name)
39  if hasattr(_id,'idName') and hasattr(_id,'cutFlow'):
40  if (len(pset.WorkingPoints)>0 and _id.idName == pset.WorkingPoints[0].split(':')[-1]):
41  cut_names = ','.join([cut.cutName.value() for cut in _id.cutFlow])
42  n_bits_per_cut = int(ceil(log(len(pset.WorkingPoints)+1,2)))
43  return 'VID compressed bitmap (%s), %d bits per cut'%(cut_names, n_bits_per_cut)
44  raise ValueError("Something is wrong in the photon ID modules parameter set!")
45 
46 bitmapVIDForPho = cms.EDProducer("PhoVIDNestedWPBitmapProducer",
47  src = cms.InputTag("slimmedPhotons"),
48  srcForID = cms.InputTag("reducedEgamma","reducedGedPhotons"),
49  WorkingPoints = photon_id_modules_WorkingPoints_nanoAOD.WorkingPoints,
50 )
51 
52 bitmapVIDForPhoSpring16V2p2 = cms.EDProducer("PhoVIDNestedWPBitmapProducer",
53  src = cms.InputTag("slimmedPhotons"),
54  WorkingPoints = photon_id_modules_WorkingPoints_nanoAOD_Spring16V2p2.WorkingPoints,
55 )
56 
57 isoForPho = cms.EDProducer("PhoIsoValueMapProducer",
58  src = cms.InputTag("slimmedPhotons"),
59  relative = cms.bool(False),
60  rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"),
61  mapIsoChg = cms.InputTag("photonIDValueMapProducer:phoChargedIsolation"),
62  mapIsoNeu = cms.InputTag("photonIDValueMapProducer:phoNeutralHadronIsolation"),
63  mapIsoPho = cms.InputTag("photonIDValueMapProducer:phoPhotonIsolation"),
64  EAFile_PFIso_Chg = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt"),
65  EAFile_PFIso_Neu = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt"),
66  EAFile_PFIso_Pho = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt"),
67 )
68 
69 seedGainPho = cms.EDProducer("PhotonSeedGainProducer", src = cms.InputTag("slimmedPhotons"))
70 
71 calibratedPatPhotonsNano = cms.EDProducer("CalibratedPatPhotonProducer",
72  correctionFile = cms.string('EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_preVFP_RunFineEtaR9Gain'),
73  mightGet = cms.optional.untracked.vstring,
74  minEtToCalibrate = cms.double(5.0),
75  produceCalibratedObjs = cms.bool(False),
76  recHitCollectionEB = cms.InputTag("reducedEgamma","reducedEBRecHits"),
77  recHitCollectionEE = cms.InputTag("reducedEgamma","reducedEERecHits"),
78  semiDeterministic = cms.bool(True),
79  src = cms.InputTag("slimmedPhotons"),
80  valueMapsStored = cms.vstring(
81  'energyScaleStatUp',
82  'energyScaleStatDown',
83  'energyScaleSystUp',
84  'energyScaleSystDown',
85  'energyScaleGainUp',
86  'energyScaleGainDown',
87  'energySigmaRhoUp',
88  'energySigmaRhoDown',
89  'energySigmaPhiUp',
90  'energySigmaPhiDown',
91  'energyScaleUp',
92  'energyScaleDown',
93  'energySigmaUp',
94  'energySigmaDown',
95  'energyScaleValue',
96  'energySigmaValue',
97  'energySmearNrSigma',
98  'ecalEnergyPreCorr',
99  'ecalEnergyErrPreCorr',
100  'ecalEnergyPostCorr',
101  'ecalEnergyErrPostCorr'
102  )
103 )
104 
105 (run2_egamma_2016 & tracker_apv_vfp30_2016).toModify(calibratedPatPhotonsNano,
106  correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_preVFP_RunFineEtaR9Gain")
107 )
108 
109 (run2_egamma_2016 & ~tracker_apv_vfp30_2016).toModify(calibratedPatPhotonsNano,
110  correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_postVFP_RunFineEtaR9Gain"),
111 )
112 
113 run2_egamma_2017.toModify(calibratedPatPhotonsNano,
114  correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_24Feb2020_runEtaR9Gain_v2")
115 )
116 
117 run2_egamma_2018.toModify(calibratedPatPhotonsNano,
118  correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2018_29Sep2020_RunFineEtaR9Gain")
119 )
120 
121 slimmedPhotonsWithUserData = cms.EDProducer("PATPhotonUserDataEmbedder",
122  src = cms.InputTag("slimmedPhotons"),
123  parentSrcs = cms.VInputTag("reducedEgamma:reducedGedPhotons"),
124  userFloats = cms.PSet(
125  mvaID = cms.InputTag("photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v2Values"),
126  PFIsoChg = cms.InputTag("isoForPho:PFIsoChg"),
127  PFIsoAll = cms.InputTag("isoForPho:PFIsoAll"),
128  ),
129  userIntFromBools = cms.PSet(
130  cutbasedID_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-loose"),
131  cutbasedID_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-medium"),
132  cutbasedID_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-tight"),
133  mvaID_WP90 = cms.InputTag("egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp90"),
134  mvaID_WP80 = cms.InputTag("egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp80"),
135  cutbasedIDV1_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-loose"),
136  cutbasedIDV1_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-medium"),
137  cutbasedIDV1_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-tight"),
138  ),
139  userInts = cms.PSet(
140  VIDNestedWPBitmap = cms.InputTag("bitmapVIDForPho"),
141  seedGain = cms.InputTag("seedGainPho"),
142  )
143 )
144 
145 
146 (run2_egamma_2016 | run2_egamma_2017 | run2_egamma_2018).toModify(slimmedPhotonsWithUserData.userFloats,
147  ecalEnergyErrPostCorrNew = cms.InputTag("calibratedPatPhotonsNano","ecalEnergyErrPostCorr"),
148  ecalEnergyPreCorrNew = cms.InputTag("calibratedPatPhotonsNano","ecalEnergyPreCorr"),
149  ecalEnergyPostCorrNew = cms.InputTag("calibratedPatPhotonsNano","ecalEnergyPostCorr"),
150  energyScaleUpNew = cms.InputTag("calibratedPatPhotonsNano","energyScaleUp"),
151  energyScaleDownNew = cms.InputTag("calibratedPatPhotonsNano","energyScaleDown"),
152  energySigmaUpNew = cms.InputTag("calibratedPatPhotonsNano","energySigmaUp"),
153  energySigmaDownNew = cms.InputTag("calibratedPatPhotonsNano","energySigmaDown"),
154  )
155 
156 
157 finalPhotons = cms.EDFilter("PATPhotonRefSelector",
158  src = cms.InputTag("slimmedPhotonsWithUserData"),
159  cut = cms.string("pt > 5 ")
160 )
161 
162 photonTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
163  src = cms.InputTag("linkedObjects","photons"),
164  cut = cms.string(""), #we should not filter on cross linked collections
165  name= cms.string("Photon"),
166  doc = cms.string("slimmedPhotons after basic selection (" + finalPhotons.cut.value()+")"),
167  singleton = cms.bool(False), # the number of entries is variable
168  extension = cms.bool(False), # this is the main table for the photons
169  variables = cms.PSet(P3Vars,
170  jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"),
171  electronIdx = Var("?hasUserCand('electron')?userCand('electron').key():-1", int, doc="index of the associated electron (-1 if none)"),
172  energyErr = Var("getCorrectedEnergyError('regression2')",float,doc="energy error of the cluster from regression",precision=6),
173  energyRaw = Var("superCluster().rawEnergy()",float,doc="raw energy of photon supercluster", precision=10),
174  r9 = Var("full5x5_r9()",float,doc="R9 of the supercluster, calculated with full 5x5 region",precision=8),
175  sieie = Var("full5x5_sigmaIetaIeta()",float,doc="sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=8),
176  sipip = Var("showerShapeVariables().sigmaIphiIphi", float, doc="sigmaIphiIphi of the supercluster", precision=8),
177  sieip = Var("full5x5_showerShapeVariables().sigmaIetaIphi",float,doc="sigma_IetaIphi of the supercluster, calculated with full 5x5 region",precision=8),
178  s4 = Var("full5x5_showerShapeVariables().e2x2/full5x5_showerShapeVariables().e5x5",float,doc="e2x2/e5x5 of the supercluster, calculated with full 5x5 region",precision=8),
179  etaWidth = Var("superCluster().etaWidth()",float,doc="Width of the photon supercluster in eta", precision=8),
180  phiWidth = Var("superCluster().phiWidth()",float,doc="Width of the photon supercluster in phi", precision=8),
181  cutBased = Var(
182  "userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",
183  int,
184  doc="cut-based ID bitmap, Fall17V2, (0:fail, 1:loose, 2:medium, 3:tight)",
185  ),
186  cutBased_Fall17V1Bitmap = Var(
187  "userInt('cutbasedIDV1_loose')+2*userInt('cutbasedIDV1_medium')+4*userInt('cutbasedIDV1_tight')",
188  int,
189  doc="cut-based ID bitmap, Fall17V1, 2^(0:loose, 1:medium, 2:tight).",
190  ),
191  vidNestedWPBitmap = Var(
192  "userInt('VIDNestedWPBitmap')",
193  int,
194  doc="Fall17V2 " + make_bitmapVID_docstring(photon_id_modules_WorkingPoints_nanoAOD),
195  ),
196  electronVeto = Var("passElectronVeto()",bool,doc="pass electron veto"),
197  pixelSeed = Var("hasPixelSeed()",bool,doc="has pixel seed"),
198  mvaID = Var("userFloat('mvaID')",float,doc="MVA ID score, Fall17V2",precision=10),
199  mvaID_WP90 = Var("userInt('mvaID_WP90')",bool,doc="MVA ID WP90, Fall17V2"),
200  mvaID_WP80 = Var("userInt('mvaID_WP80')",bool,doc="MVA ID WP80, Fall17V2"),
201  pfPhoIso03 = Var("photonIso()",float,doc="PF absolute isolation dR=0.3, photon component (uncorrected)"),
202  pfChargedIsoPFPV = Var("chargedHadronPFPVIso()",float,doc="PF absolute isolation dR=0.3, charged component (PF PV only)"),
203  pfChargedIsoWorstVtx = Var("chargedHadronWorstVtxIso()",float,doc="PF absolute isolation dR=0.3, charged component (Vertex with largest isolation)"),
204  pfRelIso03_chg = Var("userFloat('PFIsoChg')/pt",float,doc="PF relative isolation dR=0.3, charged component (with rho*EA PU corrections)"),
205  pfRelIso03_all = Var("userFloat('PFIsoAll')/pt",float,doc="PF relative isolation dR=0.3, total (with rho*EA PU corrections)"),
206  hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8),
207  isScEtaEB = Var("abs(superCluster().eta()) < 1.4442",bool,doc="is supercluster eta within barrel acceptance"),
208  isScEtaEE = Var("abs(superCluster().eta()) > 1.566 && abs(superCluster().eta()) < 2.5",bool,doc="is supercluster eta within endcap acceptance"),
209  seedGain = Var("userInt('seedGain')","uint8",doc="Gain of the seed crystal"),
210  # position of photon is best approximated by position of seed cluster, not the SC centroid
211  x_calo = Var("superCluster().seed().position().x()",float,doc="photon supercluster position on calorimeter, x coordinate (cm)",precision=10),
212  y_calo = Var("superCluster().seed().position().y()",float,doc="photon supercluster position on calorimeter, y coordinate (cm)",precision=10),
213  z_calo = Var("superCluster().seed().position().z()",float,doc="photon supercluster position on calorimeter, z coordinate (cm)",precision=10),
214  # ES variables
215  esEffSigmaRR = Var("full5x5_showerShapeVariables().effSigmaRR()", float, doc="preshower sigmaRR"),
216  esEnergyOverRawE = Var("superCluster().preshowerEnergy()/superCluster().rawEnergy()", float, doc="ratio of preshower energy to raw supercluster energy"),
217  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),
218  )
219 )
220 
221 
222 #these eras need to make the energy correction, hence the "New"
223 (run2_egamma_2016 | run2_egamma_2017 | run2_egamma_2018).toModify(photonTable.variables,
224  pt = Var("pt*userFloat('ecalEnergyPostCorrNew')/userFloat('ecalEnergyPreCorrNew')", float, precision=-1, doc="p_{T}"),
225  energyErr = Var("userFloat('ecalEnergyErrPostCorrNew')",float,doc="energy error of the cluster from regression",precision=6),
226  eCorr = Var("userFloat('ecalEnergyPostCorrNew')/userFloat('ecalEnergyPreCorrNew')",float,doc="ratio of the calibrated energy/miniaod energy"),
227  hoe = Var("hadTowOverEm()",float,doc="H over E (Run2)",precision=8),
228  )
229 
230 photonsMCMatchForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
231  src = photonTable.src, # final reco collection
232  matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
233  mcPdgId = cms.vint32(11,22), # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
234  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
235  mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
236  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
237  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
238  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
239  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
240 )
241 
242 photonMCTable = cms.EDProducer("CandMCMatchTableProducer",
243  src = photonTable.src,
244  mcMap = cms.InputTag("photonsMCMatchForTable"),
245  objName = photonTable.name,
246  objType = photonTable.name, #cms.string("Photon"),
247  branchName = cms.string("genPart"),
248  docString = cms.string("MC matching to status==1 photons or electrons"),
249 )
250 
251 from RecoEgamma.EgammaTools.egammaObjectModificationsInMiniAOD_cff import egamma8XObjectUpdateModifier,egamma9X105XUpdateModifier,prependEgamma8XObjectUpdateModifier
252 #we have dataformat changes to 106X so to read older releases we use egamma updators
253 slimmedPhotonsTo106X = cms.EDProducer("ModifiedPhotonProducer",
254  src = cms.InputTag("slimmedPhotons"),
255  modifierConfig = cms.PSet( modifications = cms.VPSet(egamma9X105XUpdateModifier) )
256 )
257 
258 
259 (run2_egamma_2016 | run2_egamma_2017 | run2_egamma_2018).toModify(photonTable.variables,
260  dEscaleUp=Var("userFloat('ecalEnergyPostCorrNew') - userFloat('energyScaleUpNew')", float, doc="ecal energy scale shifted 1 sigma up (adding gain/stat/syst in quadrature)", precision=8),
261  dEscaleDown=Var("userFloat('ecalEnergyPostCorrNew') - userFloat('energyScaleDownNew')", float, doc="ecal energy scale shifted 1 sigma down (adding gain/stat/syst in quadrature)", precision=8),
262  dEsigmaUp=Var("userFloat('ecalEnergyPostCorrNew') - userFloat('energySigmaUpNew')", float, doc="ecal energy smearing value shifted 1 sigma up", precision=8),
263  dEsigmaDown=Var("userFloat('ecalEnergyPostCorrNew') - userFloat('energySigmaDownNew')", float, doc="ecal energy smearing value shifted 1 sigma up", precision=8),
264  )
265 
266 photonTask = cms.Task(bitmapVIDForPho, isoForPho, seedGainPho, calibratedPatPhotonsNano, slimmedPhotonsWithUserData, finalPhotons)
267 photonTablesTask = cms.Task(photonTable)
268 photonMCTask = cms.Task(photonsMCMatchForTable, photonMCTable)
269 
270 
271 photonIDValueMapProducer = cms.EDProducer("PhotonIDValueMapProducer",
272  ebReducedRecHitCollection = cms.InputTag("reducedEgamma","reducedEBRecHits"),
273  eeReducedRecHitCollection = cms.InputTag("reducedEgamma","reducedEERecHits"),
274  esReducedRecHitCollection = cms.InputTag("reducedEgamma","reducedESRecHits"),
275  isAOD = cms.bool(False),
276  mightGet = cms.optional.untracked.vstring,
277  particleBasedIsolation = cms.InputTag("particleBasedIsolation","gedPhotons"),
278  pfCandidates = cms.InputTag("packedPFCandidates"),
279  src = cms.InputTag("slimmedPhotons","","@skipCurrentProcess"),
280  vertices = cms.InputTag("offlineSlimmedPrimaryVertices")
281 )
282 
283 egmPhotonIsolation = cms.EDProducer("CITKPFIsolationSumProducer",
284  isolationConeDefinitions = cms.VPSet(
285  cms.PSet(
286  coneSize = cms.double(0.3),
287  isolateAgainst = cms.string('h+'),
288  isolationAlgo = cms.string('PhotonPFIsolationWithMapBasedVeto'),
289  miniAODVertexCodes = cms.vuint32(2, 3),
290  particleBasedIsolation = cms.InputTag("particleBasedIsolation","gedPhotons"),
291  vertexIndex = cms.int32(0)
292  ),
293  cms.PSet(
294  coneSize = cms.double(0.3),
295  isolateAgainst = cms.string('h0'),
296  isolationAlgo = cms.string('PhotonPFIsolationWithMapBasedVeto'),
297  miniAODVertexCodes = cms.vuint32(2, 3),
298  particleBasedIsolation = cms.InputTag("particleBasedIsolation","gedPhotons"),
299  vertexIndex = cms.int32(0)
300  ),
301  cms.PSet(
302  coneSize = cms.double(0.3),
303  isolateAgainst = cms.string('gamma'),
304  isolationAlgo = cms.string('PhotonPFIsolationWithMapBasedVeto'),
305  miniAODVertexCodes = cms.vuint32(2, 3),
306  particleBasedIsolation = cms.InputTag("particleBasedIsolation","gedPhotons"),
307  vertexIndex = cms.int32(0)
308  )
309  ),
310  mightGet = cms.optional.untracked.vstring,
311  srcForIsolationCone = cms.InputTag("packedPFCandidates"),
312  srcToIsolate = cms.InputTag("slimmedPhotons")
313 )
314 
constexpr int32_t ceil(float num)
def Var(expr, valtype, doc=None, precision=-1)
Definition: common_cff.py:16
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def make_bitmapVID_docstring(id_modules_working_points_pset)
Definition: photons_cff.py:42