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_92X_cff import run2_nanoAOD_92X
8 from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv1_cff import run2_nanoAOD_94XMiniAODv1
9 from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv2_cff import run2_nanoAOD_94XMiniAODv2
10 from Configuration.Eras.Modifier_run2_nanoAOD_94X2016_cff import run2_nanoAOD_94X2016
11 
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  ),
19  WorkingPoints = cms.vstring(
20  "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-loose",
21  "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-medium",
22  "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-tight",
23  )
24 )
25 run2_miniAOD_80XLegacy.toModify(photon_id_modules_WorkingPoints_nanoAOD,
26  modules = cms.vstring(
27  'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff',
28  'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff',
29  ),
30  WorkingPoints = cms.vstring(
31  "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose",
32  "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium",
33  "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight",
34  )
35 )
36 run2_nanoAOD_94X2016.toModify(photon_id_modules_WorkingPoints_nanoAOD,
37  modules = cms.vstring(
38  'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff',
39  ),
40  WorkingPoints = cms.vstring(
41  "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose",
42  "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium",
43  "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight",
44  )
45 )
46 
47 
48 _bitmapVIDForPho_docstring = ''
49 for modname in photon_id_modules_WorkingPoints_nanoAOD.modules:
50  ids= __import__(modname, globals(), locals(), ['idName','cutFlow'])
51  for name in dir(ids):
52  _id = getattr(ids,name)
53  if hasattr(_id,'idName') and hasattr(_id,'cutFlow'):
54  if (len(photon_id_modules_WorkingPoints_nanoAOD.WorkingPoints)>0 and _id.idName==photon_id_modules_WorkingPoints_nanoAOD.WorkingPoints[0].split(':')[-1]):
55  _bitmapVIDForPho_docstring = 'VID compressed bitmap (%s), %d bits per cut'%(','.join([cut.cutName.value() for cut in _id.cutFlow]),int(ceil(log(len(photon_id_modules_WorkingPoints_nanoAOD.WorkingPoints)+1,2))))
56 
57 bitmapVIDForPho = cms.EDProducer("PhoVIDNestedWPBitmapProducer",
58  src = cms.InputTag("slimmedPhotons"),
59  WorkingPoints = photon_id_modules_WorkingPoints_nanoAOD.WorkingPoints,
60 )
61 
62 isoForPho = cms.EDProducer("PhoIsoValueMapProducer",
63  src = cms.InputTag("slimmedPhotons"),
64  relative = cms.bool(False),
65  rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"),
66  mapIsoChg = cms.InputTag("photonIDValueMapProducer:phoChargedIsolation"),
67  mapIsoNeu = cms.InputTag("photonIDValueMapProducer:phoNeutralHadronIsolation"),
68  mapIsoPho = cms.InputTag("photonIDValueMapProducer:phoPhotonIsolation"),
69  EAFile_PFIso_Chg = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt"),
70  EAFile_PFIso_Neu = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt"),
71  EAFile_PFIso_Pho = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt"),
72 )
73 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
74  modifier.toModify(isoForPho,
75  EAFile_PFIso_Chg = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfChargedHadrons_90percentBased.txt"),
76  EAFile_PFIso_Neu = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased.txt"),
77  EAFile_PFIso_Pho = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfPhotons_90percentBased.txt"),
78  )
79 
80 import RecoEgamma.EgammaTools.calibratedEgammas_cff
81 calibratedPatPhotons94Xv1 = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
82  produceCalibratedObjs = False,
83  correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_17Nov2017_v1_ele_unc")
84 )
85 
86 calibratedPatPhotons80XLegacy = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
87  produceCalibratedObjs = False,
88  correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Legacy2016_07Aug2017_FineEtaR9_v3_ele_unc"),
89 )
90 
91 slimmedPhotonsWithUserData = cms.EDProducer("PATPhotonUserDataEmbedder",
92  src = cms.InputTag("slimmedPhotons"),
93  userFloats = cms.PSet(
94  mvaID = cms.InputTag("photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v2Values"),
95  mvaIDV1 = cms.InputTag("photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v1p1Values"),
96  PFIsoChg = cms.InputTag("isoForPho:PFIsoChg"),
97  PFIsoAll = cms.InputTag("isoForPho:PFIsoAll"),
98  ),
99  userIntFromBools = cms.PSet(
100  cutbasedID_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-loose"),
101  cutbasedID_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-medium"),
102  cutbasedID_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-tight"),
103  mvaID_WP90 = cms.InputTag("egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp90"),
104  mvaID_WP80 = cms.InputTag("egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp80"),
105  cutbasedIDV1_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-loose"),
106  cutbasedIDV1_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-medium"),
107  cutbasedIDV1_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-tight"),
108  mvaIDV1_WP90 = cms.InputTag("egmPhotonIDs:mvaPhoID-RunIIFall17-v1p1-wp90"),
109  mvaIDV1_WP80 = cms.InputTag("egmPhotonIDs:mvaPhoID-RunIIFall17-v1p1-wp80"),
110  ),
111  userInts = cms.PSet(
112  VIDNestedWPBitmap = cms.InputTag("bitmapVIDForPho"),
113  ),
114 )
115 run2_miniAOD_80XLegacy.toModify(slimmedPhotonsWithUserData.userFloats,
116  mvaID = cms.InputTag("photonMVAValueMapProducer:PhotonMVAEstimatorRun2Spring16NonTrigV1Values"),
117  mvaIDV1 = None,
118 )
119 run2_miniAOD_80XLegacy.toModify(slimmedPhotonsWithUserData.userIntFromBools,
120  cutbasedID_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose"),
121  cutbasedID_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium"),
122  cutbasedID_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight"),
123  mvaID_WP90 = cms.InputTag("egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp90"),
124  mvaID_WP80 = cms.InputTag("egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp80"),
125  cutbasedIDV1_loose = None,
126  cutbasedIDV1_medium = None,
127  cutbasedIDV1_tight = None,
128  mvaIDV1_WP90 = None,
129  mvaIDV1_WP80 = None,
130 )
131 run2_nanoAOD_94X2016.toModify(slimmedPhotonsWithUserData.userFloats,
132  mvaID = None,
133  mvaIDV1 = None,
134 )
135 run2_nanoAOD_94X2016.toModify(slimmedPhotonsWithUserData.userIntFromBools,
136  cutbasedID_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose"),
137  cutbasedID_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium"),
138  cutbasedID_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight"),
139  mvaID_WP90 = None,
140  mvaID_WP80 = None,
141  cutbasedIDV1_loose = None,
142  cutbasedIDV1_medium = None,
143  cutbasedIDV1_tight = None,
144  mvaIDV1_WP90 = None,
145  mvaIDV1_WP80 = None,
146 )
147 
148 run2_miniAOD_80XLegacy.toModify(slimmedPhotonsWithUserData.userFloats,
149  ecalEnergyErrPostCorrNew = cms.InputTag("calibratedPatPhotons80XLegacy","ecalEnergyErrPostCorr"),
150  ecalEnergyPreCorrNew = cms.InputTag("calibratedPatPhotons80XLegacy","ecalEnergyPreCorr"),
151  ecalEnergyPostCorrNew = cms.InputTag("calibratedPatPhotons80XLegacy","ecalEnergyPostCorr"),
152 )
153 run2_nanoAOD_94XMiniAODv1.toModify(slimmedPhotonsWithUserData.userFloats,
154  ecalEnergyErrPostCorrNew = cms.InputTag("calibratedPatPhotons94Xv1","ecalEnergyErrPostCorr"),
155  ecalEnergyPreCorrNew = cms.InputTag("calibratedPatPhotons94Xv1","ecalEnergyPreCorr"),
156  ecalEnergyPostCorrNew = cms.InputTag("calibratedPatPhotons94Xv1","ecalEnergyPostCorr"),
157 )
158 
159 finalPhotons = cms.EDFilter("PATPhotonRefSelector",
160  src = cms.InputTag("slimmedPhotonsWithUserData"),
161  cut = cms.string("pt > 5 ")
162 )
163 
164 photonTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
165  src = cms.InputTag("linkedObjects","photons"),
166  cut = cms.string(""), #we should not filter on cross linked collections
167  name= cms.string("Photon"),
168  doc = cms.string("slimmedPhotons after basic selection (" + finalPhotons.cut.value()+")"),
169  singleton = cms.bool(False), # the number of entries is variable
170  extension = cms.bool(False), # this is the main table for the photons
171  variables = cms.PSet(CandVars,
172  jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"),
173  electronIdx = Var("?hasUserCand('electron')?userCand('electron').key():-1", int, doc="index of the associated electron (-1 if none)"),
174  energyErr = Var("getCorrectedEnergyError('regression2')",float,doc="energy error of the cluster from regression",precision=6),
175  r9 = Var("full5x5_r9()",float,doc="R9 of the supercluster, calculated with full 5x5 region",precision=10),
176  sieie = Var("full5x5_sigmaIetaIeta()",float,doc="sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=10),
177  cutBasedBitmap = Var("userInt('cutbasedID_loose')+2*userInt('cutbasedID_medium')+4*userInt('cutbasedID_tight')",int,doc="cut-based ID bitmap, 2^(0:loose, 1:medium, 2:tight)"),
178  cutBasedV1Bitmap = Var("userInt('cutbasedIDV1_loose')+2*userInt('cutbasedIDV1_medium')+4*userInt('cutbasedIDV1_tight')",int,doc="cut-based ID bitmap, Fall17 V1, 2^(0:loose, 1:medium, 2:tight)"),
179  vidNestedWPBitmap = Var("userInt('VIDNestedWPBitmap')",int,doc=_bitmapVIDForPho_docstring),
180  electronVeto = Var("passElectronVeto()",bool,doc="pass electron veto"),
181  pixelSeed = Var("hasPixelSeed()",bool,doc="has pixel seed"),
182  mvaID = Var("userFloat('mvaID')",float,doc="MVA ID score",precision=10),
183  mvaIDV1 = Var("userFloat('mvaIDV1')",float,doc="MVA ID score, Fall17 V1p1",precision=10),
184  mvaID_WP90 = Var("userInt('mvaID_WP90')",bool,doc="MVA ID WP90"),
185  mvaID_WP80 = Var("userInt('mvaID_WP80')",bool,doc="MVA ID WP80"),
186  pfRelIso03_chg = Var("userFloat('PFIsoChg')/pt",float,doc="PF relative isolation dR=0.3, charged component (with rho*EA PU corrections)"),
187  pfRelIso03_all = Var("userFloat('PFIsoAll')/pt",float,doc="PF relative isolation dR=0.3, total (with rho*EA PU corrections)"),
188  hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8),
189  isScEtaEB = Var("abs(superCluster().eta()) < 1.4442",bool,doc="is supercluster eta within barrel acceptance"),
190  isScEtaEE = Var("abs(superCluster().eta()) > 1.566 && abs(superCluster().eta()) < 2.5",bool,doc="is supercluster eta within endcap acceptance"),
191  )
192 )
193 
194 #these eras have the energy correction in the mini
195 for modifier in run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_94X2016:
196  modifier.toModify(photonTable.variables,
197  pt = Var("pt*userFloat('ecalEnergyPostCorr')/userFloat('ecalEnergyPreCorr')", float, precision=-1, doc="p_{T}"),
198  energyErr = Var("userFloat('ecalEnergyErrPostCorr')",float,doc="energy error of the cluster from regression",precision=6),
199  eCorr = Var("userFloat('ecalEnergyPostCorr')/userFloat('ecalEnergyPreCorr')",float,doc="ratio of the calibrated energy/miniaod energy"),
200  )
201 
202 #these eras need to make the energy correction, hence the "New"
203 for modifier in run2_nanoAOD_94XMiniAODv1, run2_miniAOD_80XLegacy:
204  modifier.toModify(photonTable.variables,
205  pt = Var("pt*userFloat('ecalEnergyPostCorrNew')/userFloat('ecalEnergyPreCorrNew')", float, precision=-1, doc="p_{T}"),
206  energyErr = Var("userFloat('ecalEnergyErrPostCorrNew')",float,doc="energy error of the cluster from regression",precision=6),
207  eCorr = Var("userFloat('ecalEnergyPostCorrNew')/userFloat('ecalEnergyPreCorrNew')",float,doc="ratio of the calibrated energy/miniaod energy"),
208  )
209 
210 
211 run2_nanoAOD_94X2016.toModify(photonTable.variables,
212  cutBasedBitmap = None,
213  cutBasedV1Bitmap = None,
214  cutBased = Var("userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",int,doc="cut-based Spring16-V2p2 ID (0:fail, 1::loose, 2:medium, 3:tight)"),
215  cutBased17Bitmap = Var("photonID('cutBasedPhotonID-Fall17-94X-V1-loose')+2*photonID('cutBasedPhotonID-Fall17-94X-V1-medium')+4*photonID('cutBasedPhotonID-Fall17-94X-V1-tight')",int,doc="cut-based Fall17-94X-V1 ID bitmap, 2^(0:loose, 1:medium, 2:tight)"),
216  mvaID = Var("userFloat('PhotonMVAEstimatorRun2Spring16NonTrigV1Values')",float,doc="MVA Spring16NonTrigV1 ID score",precision=10),
217  mvaIDV1 = None,
218  mvaID17 = Var("userFloat('PhotonMVAEstimatorRunIIFall17v1p1Values')",float,doc="MVA Fall17v1p1 ID score",precision=10),
219  mvaID_WP90 = Var("photonID('mvaPhoID-Spring16-nonTrig-V1-wp80')",bool,doc="MVA Spring16NonTrigV1 ID WP90"),
220  mvaID_WP80 = Var("photonID('mvaPhoID-Spring16-nonTrig-V1-wp90')",bool,doc="MVA Spring16NonTrigV1 ID WP80"),
221  mvaID17_WP90 = Var("photonID('mvaPhoID-RunIIFall17-v1p1-wp90')",bool,doc="MVA Fall17v1p1 ID WP90"),
222  mvaID17_WP80 = Var("photonID('mvaPhoID-RunIIFall17-v1p1-wp80')",bool,doc="MVA Fall17v1p1 ID WP80"),
223 )
224 run2_miniAOD_80XLegacy.toModify(photonTable.variables,
225  cutBasedBitmap = None,
226  cutBasedV1Bitmap = None,
227  mvaIDV1 = None,
228  cutBased = Var("userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",int,doc="cut-based ID (0:fail, 1::loose, 2:medium, 3:tight)"),
229 )
230 
231 
232 photonsMCMatchForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
233  src = photonTable.src, # final reco collection
234  matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
235  mcPdgId = cms.vint32(11,22), # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
236  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
237  mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
238  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
239  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
240  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
241  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
242 )
243 
244 photonMCTable = cms.EDProducer("CandMCMatchTableProducer",
245  src = photonTable.src,
246  mcMap = cms.InputTag("photonsMCMatchForTable"),
247  objName = photonTable.name,
248  objType = photonTable.name, #cms.string("Photon"),
249  branchName = cms.string("genPart"),
250  docString = cms.string("MC matching to status==1 photons or electrons"),
251 )
252 
253 photonSequence = cms.Sequence(bitmapVIDForPho + isoForPho + slimmedPhotonsWithUserData + finalPhotons)
254 photonTables = cms.Sequence ( photonTable)
255 photonMC = cms.Sequence(photonsMCMatchForTable + photonMCTable)
256 
257 _with80XScale_sequence = photonSequence.copy()
258 _with80XScale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons80XLegacy + slimmedPhotonsWithUserData)
259 run2_miniAOD_80XLegacy.toReplaceWith(photonSequence, _with80XScale_sequence)
260 
261 _with94Xv1Scale_sequence = photonSequence.copy()
262 _with94Xv1Scale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons94Xv1 + slimmedPhotonsWithUserData)
263 run2_nanoAOD_94XMiniAODv1.toReplaceWith(photonSequence, _with94Xv1Scale_sequence)
264 
def Var(expr, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
Definition: common_cff.py:20
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
dbl *** dir
Definition: mlp_gen.cc:35
double split
Definition: MVATrainer.cc:139