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