CMS 3D CMS Logo

photons_cff.py
Go to the documentation of this file.
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
5 
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 
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',
19  ),
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",
24  )
25 )
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",
32  )
33 )
34 
35 def make_bitmapVID_docstring(id_modules_working_points_pset):
36  pset = id_modules_working_points_pset
37 
38  for modname in pset.modules:
39  ids = __import__(modname, globals(), locals(), ['idName','cutFlow'])
40  for name in dir(ids):
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!")
48 
49 bitmapVIDForPho = cms.EDProducer("PhoVIDNestedWPBitmapProducer",
50  src = cms.InputTag("slimmedPhotons"),
51  WorkingPoints = photon_id_modules_WorkingPoints_nanoAOD.WorkingPoints,
52 )
53 
54 bitmapVIDForPhoSpring16V2p2 = cms.EDProducer("PhoVIDNestedWPBitmapProducer",
55  src = cms.InputTag("slimmedPhotons"),
56  WorkingPoints = photon_id_modules_WorkingPoints_nanoAOD_Spring16V2p2.WorkingPoints,
57 )
58 
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"),
69 )
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"),
75  )
76 
77 seedGainPho = cms.EDProducer("PhotonSeedGainProducer", src = cms.InputTag("slimmedPhotons"))
78 
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")
83 )
84 
85 calibratedPatPhotons94Xv1 = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
86  produceCalibratedObjs = False,
87  correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_17Nov2017_v1_ele_unc")
88 )
89 
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"),
93 )
94 
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"),
103  ),
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"),
118  ),
119  userInts = cms.PSet(
120  VIDNestedWPBitmap = cms.InputTag("bitmapVIDForPho"),
121  VIDNestedWPBitmap_Spring16V2p2 = cms.InputTag("bitmapVIDForPhoSpring16V2p2"),
122  seedGain = cms.InputTag("seedGainPho"),
123  ),
124 )
125 
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"),
130 )
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"),
135 )
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"),
140 )
141 
142 finalPhotons = cms.EDFilter("PATPhotonRefSelector",
143  src = cms.InputTag("slimmedPhotonsWithUserData"),
144  cut = cms.string("pt > 5 ")
145 )
146 
147 photonTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
148  src = cms.InputTag("linkedObjects","photons"),
149  cut = cms.string(""), #we should not filter on cross linked collections
150  name= cms.string("Photon"),
151  doc = cms.string("slimmedPhotons after basic selection (" + finalPhotons.cut.value()+")"),
152  singleton = cms.bool(False), # the number of entries is variable
153  extension = cms.bool(False), # this is the main table for the photons
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),
160  cutBased = Var(
161  "userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",
162  int,
163  doc="cut-based ID bitmap, Fall17V2, (0:fail, 1:loose, 2:medium, 3:tight)"
164  ),
165  cutBased_Fall17V1Bitmap = Var(
166  "userInt('cutbasedIDV1_loose')+2*userInt('cutbasedIDV1_medium')+4*userInt('cutbasedIDV1_tight')",
167  int,
168  doc="cut-based ID bitmap, Fall17V1, 2^(0:loose, 1:medium, 2:tight).",
169  ),
170  vidNestedWPBitmap = Var(
171  "userInt('VIDNestedWPBitmap')",
172  int,
173  doc="Fall17V2 " + make_bitmapVID_docstring(photon_id_modules_WorkingPoints_nanoAOD)
174  ),
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')",
183  int,
184  doc="cut-based ID bitmap, Spring16V2p2, (0:fail, 1:loose, 2:medium, 3:tight)"
185  ),
186  mvaID_Spring16nonTrigV1 = Var(
187  "userFloat('mvaID_Spring16nonTrigV1')",
188  float,
189  doc="MVA ID score, Spring16nonTrigV1",
190  precision=10
191  ),
192  vidNestedWPBitmap_Spring16V2p2 = Var(
193  "userInt('VIDNestedWPBitmap_Spring16V2p2')",
194  int,
195  doc="Spring16V2p2 " + make_bitmapVID_docstring(photon_id_modules_WorkingPoints_nanoAOD_Spring16V2p2)
196  ),
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"),
203  )
204 )
205 
206 #these eras have the energy correction in the mini
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"),
212  )
213 
214 #these eras need to make the energy correction, hence the "New"
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"),
220  )
221 
222 # only add the Spring16 IDs for 2016 nano
223 (~(run2_nanoAOD_94X2016 | run2_miniAOD_80XLegacy)).toModify(photonTable.variables,
224  cutBased_Spring16V2p2 = None,
225  mvaID_Spring16nonTrigV1 = None,
226  vidNestedWPBitmap_Spring16V2p2 = None,
227 )
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 photonSequence = cms.Sequence(
252  bitmapVIDForPho + \
253  bitmapVIDForPhoSpring16V2p2 + \
254  isoForPho + \
255  seedGainPho + \
256  slimmedPhotonsWithUserData + \
257  finalPhotons
258 )
259 
260 photonTables = cms.Sequence ( photonTable)
261 photonMC = cms.Sequence(photonsMCMatchForTable + photonMCTable)
262 
263 _with80XScale_sequence = photonSequence.copy()
264 _with80XScale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons80XLegacy + slimmedPhotonsWithUserData)
265 run2_miniAOD_80XLegacy.toReplaceWith(photonSequence, _with80XScale_sequence)
266 
267 _with94Xv1Scale_sequence = photonSequence.copy()
268 _with94Xv1Scale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons94Xv1 + slimmedPhotonsWithUserData)
269 run2_nanoAOD_94XMiniAODv1.toReplaceWith(photonSequence, _with94Xv1Scale_sequence)
270 
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)
Definition: common_cff.py:20
def make_bitmapVID_docstring(id_modules_working_points_pset)
Definition: photons_cff.py:35
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
dbl *** dir
Definition: mlp_gen.cc:35
double split
Definition: MVATrainer.cc:139