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 EgammaAnalysis.ElectronTools.calibratedPhotonsRun2_cfi
81 calibratedPatPhotons80X = EgammaAnalysis.ElectronTools.calibratedPhotonsRun2_cfi.calibratedPatPhotons.clone(
82  correctionFile = cms.string("PhysicsTools/NanoAOD/data/80X_ichepV2_2016_pho"), # hack, should go somewhere in EgammaAnalysis
83  semiDeterministic = cms.bool(True),
84 )
85 energyCorrForPhoton80X = cms.EDProducer("PhotonEnergyVarProducer",
86  srcRaw = cms.InputTag("slimmedPhotons"),
87  srcCorr = cms.InputTag("calibratedPatPhotons80X"),
88 )
89 import RecoEgamma.EgammaTools.calibratedEgammas_cff
90 calibratedPatPhotons94Xv1 = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
91  produceCalibratedObjs = False
92 )
93 
94 
95 slimmedPhotonsWithUserData = cms.EDProducer("PATPhotonUserDataEmbedder",
96  src = cms.InputTag("slimmedPhotons"),
97  userFloats = cms.PSet(
98  mvaID = cms.InputTag("photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v2Values"),
99  mvaIDV1 = cms.InputTag("photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v1p1Values"),
100  PFIsoChg = cms.InputTag("isoForPho:PFIsoChg"),
101  PFIsoAll = cms.InputTag("isoForPho:PFIsoAll"),
102  ),
103  userIntFromBools = cms.PSet(
104  cutbasedID_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-loose"),
105  cutbasedID_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-medium"),
106  cutbasedID_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-tight"),
107  mvaID_WP90 = cms.InputTag("egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp90"),
108  mvaID_WP80 = cms.InputTag("egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp80"),
109  cutbasedIDV1_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-loose"),
110  cutbasedIDV1_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-medium"),
111  cutbasedIDV1_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-tight"),
112  mvaIDV1_WP90 = cms.InputTag("egmPhotonIDs:mvaPhoID-RunIIFall17-v1p1-wp90"),
113  mvaIDV1_WP80 = cms.InputTag("egmPhotonIDs:mvaPhoID-RunIIFall17-v1p1-wp80"),
114  ),
115  userInts = cms.PSet(
116  VIDNestedWPBitmap = cms.InputTag("bitmapVIDForPho"),
117  ),
118 )
119 run2_miniAOD_80XLegacy.toModify(slimmedPhotonsWithUserData.userFloats,
120  mvaID = cms.InputTag("photonMVAValueMapProducer:PhotonMVAEstimatorRun2Spring16NonTrigV1Values"),
121  mvaIDV1 = None,
122  eCorr = cms.InputTag("energyCorrForPhoton80X","eCorr")
123 )
124 run2_miniAOD_80XLegacy.toModify(slimmedPhotonsWithUserData.userIntFromBools,
125  cutbasedID_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose"),
126  cutbasedID_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium"),
127  cutbasedID_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight"),
128  mvaID_WP90 = cms.InputTag("egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp90"),
129  mvaID_WP80 = cms.InputTag("egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp80"),
130  cutbasedIDV1_loose = None,
131  cutbasedIDV1_medium = None,
132  cutbasedIDV1_tight = None,
133  mvaIDV1_WP90 = None,
134  mvaIDV1_WP80 = None,
135 )
136 run2_nanoAOD_94X2016.toModify(slimmedPhotonsWithUserData.userFloats,
137  mvaID = None,
138  mvaIDV1 = None,
139 )
140 run2_nanoAOD_94X2016.toModify(slimmedPhotonsWithUserData.userIntFromBools,
141  cutbasedID_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose"),
142  cutbasedID_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium"),
143  cutbasedID_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight"),
144  mvaID_WP90 = None,
145  mvaID_WP80 = None,
146  cutbasedIDV1_loose = None,
147  cutbasedIDV1_medium = None,
148  cutbasedIDV1_tight = None,
149  mvaIDV1_WP90 = None,
150  mvaIDV1_WP80 = None,
151 )
152 
153 run2_nanoAOD_94XMiniAODv1.toModify(slimmedPhotonsWithUserData.userFloats,
154  ecalEnergyErrPostCorr = cms.InputTag("calibratedPatPhotons94Xv1","ecalEnergyErrPostCorr"),
155  ecalEnergyPreCorr = cms.InputTag("calibratedPatPhotons94Xv1","ecalEnergyPreCorr"),
156  ecalEnergyPostCorr = 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 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_94X2016:
194  modifier.toModify(photonTable.variables,
195  pt = Var("pt*userFloat('ecalEnergyPostCorr')/userFloat('ecalEnergyPreCorr')", float, precision=-1, doc="p_{T}"),
196  energyErr = Var("userFloat('ecalEnergyErrPostCorr')",float,doc="energy error of the cluster from regression",precision=6),
197  eCorr = Var("userFloat('ecalEnergyPostCorr')/userFloat('ecalEnergyPreCorr')",float,doc="ratio of the calibrated energy/miniaod energy"),
198  )
199 run2_nanoAOD_94X2016.toModify(photonTable.variables,
200  cutBasedBitmap = None,
201  cutBasedV1Bitmap = None,
202  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)"),
203  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)"),
204  mvaID = Var("userFloat('PhotonMVAEstimatorRun2Spring16NonTrigV1Values')",float,doc="MVA Spring16NonTrigV1 ID score",precision=10),
205  mvaIDV1 = None,
206  mvaID17 = Var("userFloat('PhotonMVAEstimatorRunIIFall17v1p1Values')",float,doc="MVA Fall17v1p1 ID score",precision=10),
207  mvaID_WP90 = Var("photonID('mvaPhoID-Spring16-nonTrig-V1-wp80')",bool,doc="MVA Spring16NonTrigV1 ID WP90"),
208  mvaID_WP80 = Var("photonID('mvaPhoID-Spring16-nonTrig-V1-wp90')",bool,doc="MVA Spring16NonTrigV1 ID WP80"),
209  mvaID17_WP90 = Var("photonID('mvaPhoID-RunIIFall17-v1p1-wp90')",bool,doc="MVA Fall17v1p1 ID WP90"),
210  mvaID17_WP80 = Var("photonID('mvaPhoID-RunIIFall17-v1p1-wp80')",bool,doc="MVA Fall17v1p1 ID WP80"),
211 )
212 run2_miniAOD_80XLegacy.toModify(photonTable.variables,
213  cutBasedBitmap = None,
214  cutBasedV1Bitmap = None,
215  mvaIDV1 = None,
216  cutBased = Var("userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",int,doc="cut-based ID (0:fail, 1::loose, 2:medium, 3:tight)"),
217  pt = Var("pt*userFloat('eCorr')", float, precision=-1, doc="p_{T} (no energy correction & smearing)"),
218  energyErr = Var("getCorrectedEnergyError('regression2')*userFloat('eCorr')",float,doc="energy error of the cluster from regression",precision=6),
219  eCorr = Var("userFloat('eCorr')",float,doc="ratio of the calibrated energy/miniaod energy"),
220 )
221 
222 
223 photonsMCMatchForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
224  src = photonTable.src, # final reco collection
225  matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
226  mcPdgId = cms.vint32(11,22), # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
227  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
228  mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
229  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
230  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
231  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
232  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
233 )
234 
235 photonMCTable = cms.EDProducer("CandMCMatchTableProducer",
236  src = photonTable.src,
237  mcMap = cms.InputTag("photonsMCMatchForTable"),
238  objName = photonTable.name,
239  objType = photonTable.name, #cms.string("Photon"),
240  branchName = cms.string("genPart"),
241  docString = cms.string("MC matching to status==1 photons or electrons"),
242 )
243 
244 photonSequence = cms.Sequence(bitmapVIDForPho + isoForPho + slimmedPhotonsWithUserData + finalPhotons)
245 photonTables = cms.Sequence ( photonTable)
246 photonMC = cms.Sequence(photonsMCMatchForTable + photonMCTable)
247 
248 _with80XScale_sequence = photonSequence.copy()
249 _with80XScale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons80X + energyCorrForPhoton80X + slimmedPhotonsWithUserData)
250 run2_miniAOD_80XLegacy.toReplaceWith(photonSequence, _with80XScale_sequence)
251 
252 _with94Xv1Scale_sequence = photonSequence.copy()
253 _with94Xv1Scale_sequence.replace(slimmedPhotonsWithUserData, calibratedPatPhotons94Xv1 + slimmedPhotonsWithUserData)
254 run2_nanoAOD_94XMiniAODv1.toReplaceWith(photonSequence, _with94Xv1Scale_sequence)
255 
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