CMS 3D CMS Logo

electrons_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 from PhysicsTools.NanoAOD.simpleCandidateFlatTableProducer_cfi import simpleCandidateFlatTableProducer
5 from math import ceil,log
6 
7 
8 electron_id_modules_WorkingPoints_nanoAOD = cms.PSet(
9  modules = cms.vstring(
10  'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff',
11  # HZZ ID
12  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer16UL_ID_ISO_cff',
13  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer17UL_ID_ISO_cff',
14  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer18UL_ID_ISO_cff',
15  # Fall17: need to include the modules too to make sure they are run
16  'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V2_cff',
17  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff',
18  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff',
19  # Run3Winter22:
20  'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Winter22_122X_V1_cff',
21  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_RunIIIWinter22_iso_V1_cff',
22  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_RunIIIWinter22_noIso_V1_cff',
23  ),
24  WorkingPoints = cms.vstring(
25  "egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-veto",
26  "egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-loose",
27  "egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-medium",
28  "egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-tight",
29  )
30 )
31 
32 # Use Fall17-94X-V2 as default for Run 2
33 electron_id_modules_WorkingPoints_nanoAOD_Run2 = cms.PSet(
34  modules = cms.vstring(
35  'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V2_cff',
36  'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff',
37  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff',
38  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff',
39  # HZZ ID
40  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer16UL_ID_ISO_cff',
41  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer17UL_ID_ISO_cff',
42  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer18UL_ID_ISO_cff',
43  ),
44  WorkingPoints = cms.vstring(
45  "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-veto",
46  "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-loose",
47  "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-medium",
48  "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-tight",
49  )
50 )
51 
52 # make Fall17 the default one in Run2
53 run2_egamma.toModify(electron_id_modules_WorkingPoints_nanoAOD,
54  modules=electron_id_modules_WorkingPoints_nanoAOD_Run2.modules).\
55  toModify(electron_id_modules_WorkingPoints_nanoAOD,
56  WorkingPoints=electron_id_modules_WorkingPoints_nanoAOD_Run2.WorkingPoints)
57 
58 def _get_bitmapVIDForEle_docstring(modules,WorkingPoints):
59  docstring=''
60  for modname in modules:
61  ids= __import__(modname, globals(), locals(), ['idName','cutFlow'])
62  for name in dir(ids):
63  _id = getattr(ids,name)
64  if hasattr(_id,'idName') and hasattr(_id,'cutFlow'):
65  if (len(WorkingPoints)>0 and _id.idName==WorkingPoints[0].split(':')[-1]):
66  docstring = 'VID compressed bitmap (%s), %d bits per cut'%(','.join([cut.cutName.value() for cut in _id.cutFlow]),int(ceil(log(len(WorkingPoints)+1,2))))
67  return docstring
68 
69 bitmapVIDForEle = cms.EDProducer("EleVIDNestedWPBitmapProducer",
70  src = cms.InputTag("slimmedElectrons"),
71  srcForID = cms.InputTag("reducedEgamma","reducedGedGsfElectrons"),
72  WorkingPoints = electron_id_modules_WorkingPoints_nanoAOD.WorkingPoints,
73 )
74 _bitmapVIDForEle_docstring = _get_bitmapVIDForEle_docstring(electron_id_modules_WorkingPoints_nanoAOD.modules,bitmapVIDForEle.WorkingPoints)
75 
76 bitmapVIDForEleFall17V2 = bitmapVIDForEle.clone(
77  WorkingPoints = electron_id_modules_WorkingPoints_nanoAOD_Run2.WorkingPoints
78  )
79 _bitmapVIDForEleFall17V2_docstring = _get_bitmapVIDForEle_docstring(electron_id_modules_WorkingPoints_nanoAOD.modules, bitmapVIDForEleFall17V2.WorkingPoints)
80 
81 bitmapVIDForEleHEEP = bitmapVIDForEle.clone(
82  WorkingPoints = cms.vstring("egmGsfElectronIDs:heepElectronID-HEEPV70"
83  )
84 )
85 _bitmapVIDForEleHEEP_docstring = _get_bitmapVIDForEle_docstring(electron_id_modules_WorkingPoints_nanoAOD.modules,bitmapVIDForEleHEEP.WorkingPoints)
86 
87 
88 
90 isoForEle = cms.EDProducer("EleIsoValueMapProducer",
91  src = cms.InputTag("slimmedElectrons"),
92  relative = cms.bool(False),
93  rho_MiniIso = cms.InputTag("fixedGridRhoFastjetAll"),
94  rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"),
95  EAFile_MiniIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Run3_Winter22/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_122X.txt"),
96  EAFile_PFIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Run3_Winter22/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_122X.txt"),
97 )
98 
99 isoForEleFall17V2 = isoForEle.clone(
100  EAFile_MiniIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Fall17/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
101  EAFile_PFIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Fall17/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
102 )
103 
104 
105 
107 ptRatioRelForEle = cms.EDProducer("ElectronJetVarProducer",
108  srcJet = cms.InputTag("updatedJetsPuppi"),
109  srcLep = cms.InputTag("slimmedElectrons"),
110  srcVtx = cms.InputTag("offlineSlimmedPrimaryVertices"),
111 )
112 
113 
114 
115 seedGainEle = cms.EDProducer("ElectronSeedGainProducer", src = cms.InputTag("slimmedElectrons"))
116 
117 
118 
120 import RecoEgamma.EgammaTools.calibratedEgammas_cff
121 
122 calibratedPatElectronsNano = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatElectrons.clone(
123  produceCalibratedObjs = False,
124  src = "slimmedElectrons"
125 )
126 
127 (run2_egamma_2016 & tracker_apv_vfp30_2016).toModify(
128  calibratedPatElectronsNano,
129  correctionFile = "EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_preVFP_RunFineEtaR9Gain"
130 )
131 
132 (run2_egamma_2016 & ~tracker_apv_vfp30_2016).toModify(
133  calibratedPatElectronsNano,
134  correctionFile = "EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_postVFP_RunFineEtaR9Gain"
135 )
136 
137 run2_egamma_2017.toModify(
138  calibratedPatElectronsNano,
139  correctionFile = "EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_24Feb2020_runEtaR9Gain_v2"
140 )
141 
142 run2_egamma_2018.toModify(
143  calibratedPatElectronsNano,
144  correctionFile = "EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2018_29Sep2020_RunFineEtaR9Gain"
145 )
146 
147 
148 
150 slimmedElectronsWithUserData = cms.EDProducer("PATElectronUserDataEmbedder",
151  src = cms.InputTag("slimmedElectrons"),
152  parentSrcs = cms.VInputTag("reducedEgamma:reducedGedGsfElectrons"),
153  userFloats = cms.PSet(
154  mvaIso_Fall17V2 = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17IsoV2Values"),
155  mvaNoIso_Fall17V2 = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV2Values"),
156  mvaIso = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2RunIIIWinter22IsoV1Values"),
157  mvaNoIso = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2RunIIIWinter22NoIsoV1Values"),
158  mvaHZZIso = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Summer18ULIdIsoValues"),
159 
160  miniIsoChg = cms.InputTag("isoForEle:miniIsoChg"),
161  miniIsoAll = cms.InputTag("isoForEle:miniIsoAll"),
162  PFIsoChg = cms.InputTag("isoForEle:PFIsoChg"),
163  PFIsoAll = cms.InputTag("isoForEle:PFIsoAll"),
164  PFIsoAll04 = cms.InputTag("isoForEle:PFIsoAll04"),
165 
166  miniIsoChg_Fall17V2 = cms.InputTag("isoForEleFall17V2:miniIsoChg"),
167  miniIsoAll_Fall17V2 = cms.InputTag("isoForEleFall17V2:miniIsoAll"),
168  PFIsoChg_Fall17V2 = cms.InputTag("isoForEleFall17V2:PFIsoChg"),
169  PFIsoAll_Fall17V2 = cms.InputTag("isoForEleFall17V2:PFIsoAll"),
170  PFIsoAll04_Fall17V2 = cms.InputTag("isoForEleFall17V2:PFIsoAll04"),
171 
172  ptRatio = cms.InputTag("ptRatioRelForEle:ptRatio"),
173  ptRel = cms.InputTag("ptRatioRelForEle:ptRel"),
174  jetNDauChargedMVASel = cms.InputTag("ptRatioRelForEle:jetNDauChargedMVASel"),
175  ),
176  userIntFromBools = cms.PSet(
177  mvaIso_Fall17V2_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wp90"),
178  mvaIso_Fall17V2_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wp80"),
179  mvaIso_Fall17V2_WPL = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wpLoose"),
180  mvaIso_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-RunIIIWinter22-iso-V1-wp90"),
181  mvaIso_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-RunIIIWinter22-iso-V1-wp80"),
182  mvaNoIso_Fall17V2_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wp90"),
183  mvaNoIso_Fall17V2_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wp80"),
184  mvaNoIso_Fall17V2_WPL = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wpLoose"),
185  mvaNoIso_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-RunIIIWinter22-noIso-V1-wp90"),
186  mvaNoIso_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-RunIIIWinter22-noIso-V1-wp80"),
187 
188  cutBasedID_veto = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-veto"),
189  cutBasedID_loose = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-loose"),
190  cutBasedID_medium = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-medium"),
191  cutBasedID_tight = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-tight"),
192  cutBasedID_Fall17V2_veto = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-veto"),
193  cutBasedID_Fall17V2_loose = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-loose"),
194  cutBasedID_Fall17V2_medium = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-medium"),
195  cutBasedID_Fall17V2_tight = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-tight"),
196  cutBasedID_HEEP = cms.InputTag("egmGsfElectronIDs:heepElectronID-HEEPV70"),
197  ),
198  userInts = cms.PSet(
199  VIDNestedWPBitmap = cms.InputTag("bitmapVIDForEle"),
200  VIDNestedWPBitmap_Fall17V2 = cms.InputTag("bitmapVIDForEleFall17V2"),
201  VIDNestedWPBitmapHEEP = cms.InputTag("bitmapVIDForEleHEEP"),
202  seedGain = cms.InputTag("seedGainEle"),
203 
204  ),
205  userCands = cms.PSet(
206  jetForLepJetVar = cms.InputTag("ptRatioRelForEle:jetForLepJetVar") # warning: Ptr is null if no match is found
207  ),
208 )
209 
210 # no need for the Run3 IDs in Run2
211 run2_egamma.toModify(slimmedElectronsWithUserData.userFloats,
212  mvaIso = None,
213  mvaNoIso = None,
214  miniIsoChg = None,
215  miniIsoAll = None,
216  PFIsoChg = None,
217  PFIsoAll = None,
218  PFIsoAll04 = None).\
219  toModify(slimmedElectronsWithUserData.userIntFromBools,
220  mvaIso_WP90 = None,
221  mvaIso_WP80 = None,
222  mvaNoIso_WP90 = None,
223  mvaNoIso_WP80 = None,
224  cutBasedID_veto = None,
225  cutBasedID_loose = None,
226  cutBasedID_medium = None,
227  cutBasedID_tight = None).\
228  toModify(slimmedElectronsWithUserData.userInts,
229  VIDNestedWPBitmap = None)
230 
231 run2_egamma.toModify(
232  slimmedElectronsWithUserData.userFloats,
233  ecalTrkEnergyErrPostCorrNew = cms.InputTag("calibratedPatElectronsNano","ecalTrkEnergyErrPostCorr"),
234  ecalTrkEnergyPreCorrNew = cms.InputTag("calibratedPatElectronsNano","ecalTrkEnergyPreCorr"),
235  ecalTrkEnergyPostCorrNew = cms.InputTag("calibratedPatElectronsNano","ecalTrkEnergyPostCorr"),
236  energyScaleUpNew = cms.InputTag("calibratedPatElectronsNano","energyScaleUp"),
237  energyScaleDownNew = cms.InputTag("calibratedPatElectronsNano","energyScaleDown"),
238  energySigmaUpNew = cms.InputTag("calibratedPatElectronsNano","energySigmaUp"),
239  energySigmaDownNew = cms.InputTag("calibratedPatElectronsNano","energySigmaDown")
240 )
241 
242 (run2_egamma_2016).toModify(
243  slimmedElectronsWithUserData.userFloats,
244  mvaHZZIso = "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Summer16ULIdIsoValues"
245 )
246 (run2_egamma_2017).toModify(
247  slimmedElectronsWithUserData.userFloats,
248  mvaHZZIso = "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Summer17ULIdIsoValues"
249 )
250 (run2_egamma_2018).toModify(
251  slimmedElectronsWithUserData.userFloats,
252  mvaHZZIso = "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Summer18ULIdIsoValues"
253 )
254 
255 
256 
257 finalElectrons = cms.EDFilter("PATElectronRefSelector",
258  src = cms.InputTag("slimmedElectronsWithUserData"),
259  cut = cms.string("pt > 5 ")
260 )
261 
262 
263 
264 electronMVATTH= cms.EDProducer("EleBaseMVAValueMapProducer",
265  src = cms.InputTag("linkedObjects","electrons"),
266  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/el_BDTG_2017.weights.xml"),
267  name = cms.string("electronMVATTH"),
268  isClassifier = cms.bool(True),
269  variablesOrder = cms.vstring(["LepGood_pt","LepGood_eta","LepGood_jetNDauChargedMVASel","LepGood_miniRelIsoCharged","LepGood_miniRelIsoNeutral","LepGood_jetPtRelv2","LepGood_jetDF","LepGood_jetPtRatio","LepGood_dxy","LepGood_sip3d","LepGood_dz","LepGood_mvaFall17V2noIso"]),
270  variables = cms.PSet(
271  LepGood_pt = cms.string("pt"),
272  LepGood_eta = cms.string("eta"),
273  LepGood_jetNDauChargedMVASel = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0"),
274  # NB: only using Fall17V2 iso here
275  LepGood_miniRelIsoCharged = cms.string("userFloat('miniIsoChg_Fall17V2')/pt"),
276  LepGood_miniRelIsoNeutral = cms.string("(userFloat('miniIsoAll_Fall17V2')-userFloat('miniIsoChg_Fall17V2'))/pt"),
277  LepGood_jetPtRelv2 = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0"),
278  LepGood_jetDF = cms.string("?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probbb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:problepb'),0.0):0.0"),
279  LepGood_jetPtRatio = cms.string("?userCand('jetForLepJetVar').isNonnull()?min(userFloat('ptRatio'),1.5):1.0/(1.0+userFloat('PFIsoAll04_Fall17V2')/pt)"),
280  LepGood_dxy = cms.string("log(abs(dB('PV2D')))"),
281  LepGood_sip3d = cms.string("abs(dB('PV3D')/edB('PV3D'))"),
282  LepGood_dz = cms.string("log(abs(dB('PVDZ')))"),
283  LepGood_mvaFall17V2noIso = cms.string("userFloat('mvaNoIso_Fall17V2')"),
284  )
285 )
286 run2_egamma_2016.toModify(
287  electronMVATTH,
288  weightFile = "PhysicsTools/NanoAOD/data/el_BDTG_2016.weights.xml",
289 )
290 
291 
292 
293 electronTable = simpleCandidateFlatTableProducer.clone(
294  src = cms.InputTag("linkedObjects","electrons"),
295  name= cms.string("Electron"),
296  doc = cms.string("slimmedElectrons after basic selection (" + finalElectrons.cut.value()+")"),
297  variables = cms.PSet(CandVars,
298  jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", "int16", doc="index of the associated jet (-1 if none)"),
299  photonIdx = Var("?overlaps('photons').size()>0?overlaps('photons')[0].key():-1", "int16", doc="index of the first associated photon (-1 if none)"),
300  svIdx = Var("?hasUserCand('vertex')?userCand('vertex').key():-1", "int16", doc="index of matching secondary vertex"),
301  fbrem = Var("fbrem()",float,doc="Fraction of brem",precision=10),
302  rawEnergy = Var("superCluster.rawEnergy",float,doc="raw energy of Supercluster",precision=10),
303  PreshowerEnergy = Var("superCluster.preshowerEnergy",float,doc="energy deposited in preshower",precision=10),
304  ecalEnergy = Var("ecalEnergy()",float,doc="energy after ECAL-only regression applied",precision=10),
305  ecalEnergyError = Var("ecalEnergyError",float,doc="ecalEnergy error",precision=10),
306  energyErr = Var("p4Error('P4_COMBINATION')",float,doc="energy error of the cluster-track combination",precision=6),
307  gsfTrkpMode = Var("gsfTrack().pMode()",float,doc="GSF track pMode",precision=10),
308  gsfTrkpModeErr = Var("abs(gsfTrack().qoverpModeError())*gsfTrack().pMode()*gsfTrack().pMode()",float,doc="GSF track pMode error",precision=8),
309  gsfTrketaMode = Var("gsfTrack().etaMode()",float,doc="GSF track etaMode",precision=10),
310  gsfTrkphiMode = Var("gsfTrack().phiMode()",float,doc="GSF track phiMode",precision=10),
311  isEcalDriven = Var("ecalDrivenSeed",bool,doc="is ECAL driven if true"),
312  isEB = Var("isEB",bool,doc="object in barrel if true derived from the seedCrystal and detID information"),
313  dz = Var("dB('PVDZ')",float,doc="dz (with sign) wrt first PV, in cm",precision=10),
314  dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6),
315  dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10),
316  dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6),
317  ip3d = Var("abs(dB('PV3D'))",float,doc="3D impact parameter wrt first PV, in cm",precision=10),
318  sip3d = Var("abs(dB('PV3D')/edB('PV3D'))",float,doc="3D impact parameter significance wrt first PV, in cm",precision=10),
319  deltaEtaSC = Var("superCluster().eta()-eta()",float,doc="delta eta (SC,ele) with sign",precision=10),
320  r9 = Var("full5x5_r9()",float,doc="R9 of the supercluster, calculated with full 5x5 region",precision=10),
321  sieie = Var("full5x5_sigmaIetaIeta()",float,doc="sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=10),
322  eInvMinusPInv = Var("(1-eSuperClusterOverP())/ecalEnergy()",float,doc="1/E_SC - 1/p_trk",precision=10),
323  scEtOverPt = Var("(superCluster().energy()/(pt*cosh(superCluster().eta())))-1",float,doc="(supercluster transverse energy)/pt-1",precision=8),
324 
325  mvaIso = Var("userFloat('mvaIso')",float,doc="MVA Iso ID score, Winter22V1"),
326  mvaIso_WP80 = Var("userInt('mvaIso_WP80')",bool,doc="MVA Iso ID WP80, Winter22V1"),
327  mvaIso_WP90 = Var("userInt('mvaIso_WP90')",bool,doc="MVA Iso ID WP90, Winter22V1"),
328  mvaNoIso = Var("userFloat('mvaNoIso')",float,doc="MVA noIso ID score, Winter22V1"),
329  mvaNoIso_WP80 = Var("userInt('mvaNoIso_WP80')",bool,doc="MVA noIso ID WP80, Winter22V1"),
330  mvaNoIso_WP90 = Var("userInt('mvaNoIso_WP90')",bool,doc="MVA noIso ID WP90, Winter22V1"),
331  mvaHZZIso = Var("userFloat('mvaHZZIso')", float,doc="HZZ MVA Iso ID score"),
332 
333  cutBased = Var("userInt('cutBasedID_veto')+userInt('cutBasedID_loose')+userInt('cutBasedID_medium')+userInt('cutBasedID_tight')", "uint8", doc="cut-based ID RunIII Winter22 (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)"),
334  vidNestedWPBitmap = Var("userInt('VIDNestedWPBitmap')", int, doc=_bitmapVIDForEle_docstring),
335  vidNestedWPBitmapHEEP = Var("userInt('VIDNestedWPBitmapHEEP')", int, doc=_bitmapVIDForEleHEEP_docstring),
336  cutBased_HEEP = Var("userInt('cutBasedID_HEEP')",bool,doc="cut-based HEEP ID"),
337  miniPFRelIso_chg = Var("userFloat('miniIsoChg')/pt",float,doc="mini PF relative isolation, charged component"),
338  miniPFRelIso_all = Var("userFloat('miniIsoAll')/pt",float,doc="mini PF relative isolation, total (with scaled rho*EA PU Winter22V1 corrections)"),
339  pfRelIso03_chg = Var("userFloat('PFIsoChg')/pt",float,doc="PF relative isolation dR=0.3, charged component"),
340  pfRelIso03_all = Var("userFloat('PFIsoAll')/pt",float,doc="PF relative isolation dR=0.3, total (with rho*EA PU Winter22V1 corrections)"),
341  jetRelIso = Var("?userCand('jetForLepJetVar').isNonnull()?(1./userFloat('ptRatio'))-1.:userFloat('PFIsoAll04')/pt",float,doc="Relative isolation in matched jet (1/ptRatio-1, pfRelIso04_all if no matched jet)",precision=8),
342  jetPtRelv2 = Var("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0",float,doc="Relative momentum of the lepton with respect to the closest jet after subtracting the lepton",precision=8),
343  dr03TkSumPt = Var("?pt>35?dr03TkSumPt():0",float,doc="Non-PF track isolation within a delta R cone of 0.3 with electron pt > 35 GeV",precision=8),
344  dr03TkSumPtHEEP = Var("?pt>35?dr03TkSumPtHEEP():0",float,doc="Non-PF track isolation within a delta R cone of 0.3 with electron pt > 35 GeV used in HEEP ID",precision=8),
345  dr03EcalRecHitSumEt = Var("?pt>35?dr03EcalRecHitSumEt():0",float,doc="Non-PF Ecal isolation within a delta R cone of 0.3 with electron pt > 35 GeV",precision=8),
346  dr03HcalDepth1TowerSumEt = Var("?pt>35?dr03HcalTowerSumEt(1):0",float,doc="Non-PF Hcal isolation within a delta R cone of 0.3 with electron pt > 35 GeV",precision=8),
347  hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8),
348  tightCharge = Var("isGsfCtfScPixChargeConsistent() + isGsfScPixChargeConsistent()", "uint8", doc="Tight charge criteria (0:none, 1:isGsfScPixChargeConsistent, 2:isGsfCtfScPixChargeConsistent)"),
349  convVeto = Var("passConversionVeto()",bool,doc="pass conversion veto"),
350  lostHits = Var("gsfTrack.hitPattern.numberOfLostHits('MISSING_INNER_HITS')","uint8",doc="number of missing inner hits"),
351  isPFcand = Var("pfCandidateRef().isNonnull()",bool,doc="electron is PF candidate"),
352  seedGain = Var("userInt('seedGain')","uint8",doc="Gain of the seed crystal"),
353  seediEtaOriX = Var("superCluster().seedCrysIEtaOrIx","int8",doc="iEta or iX of seed crystal. iEta is barrel-only, iX is endcap-only. iEta runs from -85 to +85, with no crystal at iEta=0. iX runs from 1 to 100."),
354  seediPhiOriY = Var("superCluster().seedCrysIPhiOrIy",int,doc="iPhi or iY of seed crystal. iPhi is barrel-only, iY is endcap-only. iPhi runs from 1 to 360. iY runs from 1 to 100."),
355  jetNDauCharged = Var("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0", "uint8", doc="number of charged daughters of the closest jet"),
356  ),
357  externalVariables = cms.PSet(
358  mvaTTH = ExtVar(cms.InputTag("electronMVATTH"),float, doc="TTH MVA lepton ID score",precision=14),
359  fsrPhotonIdx = ExtVar(cms.InputTag("leptonFSRphotons:eleFsrIndex"), "int16", doc="Index of the lowest-dR/ET2 among associated FSR photons"),
360  ),
361 )
362 
363 (run2_egamma).toModify(
364  # energy scale/smearing: only for Run2
365  electronTable.variables,
366  pt = Var("pt*userFloat('ecalTrkEnergyPostCorrNew')/userFloat('ecalTrkEnergyPreCorrNew')", float, precision=-1, doc="p_{T}"),
367  energyErr = Var("userFloat('ecalTrkEnergyErrPostCorrNew')", float, precision=6, doc="energy error of the cluster-track combination"),
368  eCorr = Var("userFloat('ecalTrkEnergyPostCorrNew')/userFloat('ecalTrkEnergyPreCorrNew')", float, doc="ratio of the calibrated energy/miniaod energy"),
369  scEtOverPt = Var("(superCluster().energy()/(pt*userFloat('ecalTrkEnergyPostCorrNew')/userFloat('ecalTrkEnergyPreCorrNew')*cosh(superCluster().eta())))-1",float,doc="(supercluster transverse energy)/pt-1",precision=8),
370  dEscaleUp=Var("userFloat('ecalTrkEnergyPostCorrNew')-userFloat('energyScaleUpNew')", float, doc="ecal energy scale shifted 1 sigma up(adding gain/stat/syst in quadrature)", precision=8),
371  dEscaleDown=Var("userFloat('ecalTrkEnergyPostCorrNew')-userFloat('energyScaleDownNew')", float, doc="ecal energy scale shifted 1 sigma down (adding gain/stat/syst in quadrature)", precision=8),
372  dEsigmaUp=Var("userFloat('ecalTrkEnergyPostCorrNew')-userFloat('energySigmaUpNew')", float, doc="ecal energy smearing value shifted 1 sigma up", precision=8),
373  dEsigmaDown=Var("userFloat('ecalTrkEnergyPostCorrNew')-userFloat('energySigmaDownNew')", float, doc="ecal energy smearing value shifted 1 sigma up", precision=8),
374  # Fall17V2 IDs and isolations are only for Run2. The names of these IDs and isolations are same as in Run3.
375  mvaIso = Var("userFloat('mvaIso_Fall17V2')",float,doc="MVA Iso ID score, Fall17V2"),
376  mvaIso_WP80 = Var("userInt('mvaIso_Fall17V2_WP80')",bool,doc="MVA Iso ID WP80, Fall17V2"),
377  mvaIso_WP90 = Var("userInt('mvaIso_Fall17V2_WP90')",bool,doc="MVA Iso ID WP90, Fall17V2"),
378  mvaIso_WPL = Var("userInt('mvaIso_Fall17V2_WPL')",bool,doc="MVA Iso ID loose WP, Fall17V2"),
379  mvaNoIso = Var("userFloat('mvaNoIso_Fall17V2')",float,doc="MVA noIso ID score, Fall17V2"),
380  mvaNoIso_WP80 = Var("userInt('mvaNoIso_Fall17V2_WP80')",bool,doc="MVA noIso ID WP80, Fall17V2"),
381  mvaNoIso_WP90 = Var("userInt('mvaNoIso_Fall17V2_WP90')",bool,doc="MVA noIso ID WP90, Fall17V2"),
382  mvaNoIso_WPL = Var("userInt('mvaNoIso_Fall17V2_WPL')",bool,doc="MVA noIso ID loose WP, Fall17V2"),
383  cutBased = Var("userInt('cutBasedID_Fall17V2_veto')+userInt('cutBasedID_Fall17V2_loose')+userInt('cutBasedID_Fall17V2_medium')+userInt('cutBasedID_Fall17V2_tight')", "uint8", doc="cut-based ID Fall17V2 (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)"),
384  vidNestedWPBitmap = Var("userInt('VIDNestedWPBitmap_Fall17V2')", int, doc=_bitmapVIDForEleFall17V2_docstring),
385  miniPFRelIso_chg = Var("userFloat('miniIsoChg_Fall17V2')/pt",float,doc="mini PF relative isolation, charged component in Run2"),
386  miniPFRelIso_all = Var("userFloat('miniIsoAll_Fall17V2')/pt",float,doc="mini PF relative isolation, total (with scaled rho*EA Fall17V2 PU corrections) in Run2"),
387  pfRelIso03_chg = Var("userFloat('PFIsoChg_Fall17V2')/pt",float,doc="PF relative isolation dR=0.3 with 94 EffArea, charged component in Run2"),
388  pfRelIso03_all = Var("userFloat('PFIsoAll_Fall17V2')/pt",float,doc="PF relative isolation dR=0.3 with 94 EffArea, total (with rho*EA Fall17V2 PU corrections) in Run2"),
389  jetRelIso = Var("?userCand('jetForLepJetVar').isNonnull()?(1./userFloat('ptRatio'))-1.:userFloat('PFIsoAll04_Fall17V2')/pt",float,doc="Relative isolation in matched jet (1/ptRatio-1, pfRelIso04_all if no matched jet in Run2)",precision=8),
390 )
391 
392 
394 tautaggerForMatching = cms.EDProducer("GenJetTauTaggerProducer",
395  src = cms.InputTag('particleLevel:leptons')
396 )
397 
398 matchingElecPhoton = cms.EDProducer("GenJetGenPartMerger",
399  srcJet =cms.InputTag("particleLevel:leptons"),
400  srcPart=cms.InputTag("particleLevel:photons"),
401  cut = cms.string("pt > 3"),
402  hasTauAnc=cms.InputTag("tautaggerForMatching"),
403 )
404 electronsMCMatchForTableAlt = cms.EDProducer("GenJetMatcherDRPtByDR", # cut on deltaR, deltaPt/Pt; pick best by deltaR
405  src = electronTable.src, # final reco collection
406  matched = cms.InputTag("matchingElecPhoton:merged"), # final mc-truth particle collection
407  mcPdgId = cms.vint32(11,22), # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
408  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
409  mcStatus = cms.vint32(),
410  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
411  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
412  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
413  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
414 )
415 electronsMCMatchForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
416  src = electronTable.src, # final reco collection
417  matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
418  mcPdgId = cms.vint32(11,22), # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
419  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
420  mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
421  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
422  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
423  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
424  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
425 )
426 #should be cloned from PhysicsTools/NanoAOD/python/candMcMatchTable_cfi.py
427 electronMCTable = cms.EDProducer("CandMCMatchTableProducer",
428  src = electronTable.src,
429  mcMapDressedLep = cms.InputTag("electronsMCMatchForTableAlt"),
430  mcMap = cms.InputTag("electronsMCMatchForTable"),
431  mapTauAnc = cms.InputTag("matchingElecPhoton:hasTauAnc"),
432  objName = electronTable.name,
433  objType = electronTable.name, #cms.string("Electron"),
434  branchName = cms.string("genPart"),
435  docString = cms.string("MC matching to status==1 electrons or photons"),
436  genparticles = cms.InputTag("finalGenParticles"),
437 )
438 
439 electronTask = cms.Task(bitmapVIDForEle,bitmapVIDForEleFall17V2,bitmapVIDForEleHEEP,isoForEle,isoForEleFall17V2,ptRatioRelForEle,seedGainEle,calibratedPatElectronsNano,slimmedElectronsWithUserData,finalElectrons)
440 electronTablesTask = cms.Task(electronMVATTH, electronTable)
441 electronMCTask = cms.Task(tautaggerForMatching, matchingElecPhoton, electronsMCMatchForTable, electronsMCMatchForTableAlt, electronMCTable)
442 
443 _electronTask_Run2 = electronTask.copy()
444 _electronTask_Run2.remove(bitmapVIDForEle)
445 _electronTask_Run2.remove(isoForEle)
446 _electronTask_Run2.add(calibratedPatElectronsNano)
447 run2_egamma.toReplaceWith(electronTask, _electronTask_Run2)
448 
449 # Revert back to AK4 CHS jets for Run2 inputs
450 run2_nanoAOD_ANY.toModify(
451  ptRatioRelForEle,srcJet="updatedJets")
constexpr int32_t ceil(float num)
def ExtVar(tag, valtype, doc=None, precision=-1)
Definition: common_cff.py:27
def Var(expr, valtype, doc=None, precision=-1)
Definition: common_cff.py:16
def _get_bitmapVIDForEle_docstring(modules, WorkingPoints)
static std::string join(char **cmd)
Definition: RemoteFile.cc:19