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