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.simplePATElectronFlatTableProducer_cfi import simplePATElectronFlatTableProducer
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  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Winter22_HZZ_V1_cff',
16  # Fall17: need to include the modules too to make sure they are run
17  'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V2_cff',
18  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff',
19  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff',
20  # Run3Winter22:
21  'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Winter22_122X_V1_cff',
22  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_RunIIIWinter22_iso_V1_cff',
23  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_RunIIIWinter22_noIso_V1_cff',
24  ),
25  WorkingPoints = cms.vstring(
26  "egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-veto",
27  "egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-loose",
28  "egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-medium",
29  "egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-tight",
30  )
31 )
32 
33 # Use Fall17-94X-V2 as default for Run 2
34 electron_id_modules_WorkingPoints_nanoAOD_Run2 = cms.PSet(
35  modules = cms.vstring(
36  'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V2_cff',
37  'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff',
38  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff',
39  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff',
40  # HZZ ID
41  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer16UL_ID_ISO_cff',
42  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer17UL_ID_ISO_cff',
43  'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Summer18UL_ID_ISO_cff',
44  ),
45  WorkingPoints = cms.vstring(
46  "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-veto",
47  "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-loose",
48  "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-medium",
49  "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-tight",
50  )
51 )
52 
53 # make Fall17 the default one in Run2
54 run2_egamma.toModify(electron_id_modules_WorkingPoints_nanoAOD,
55  modules=electron_id_modules_WorkingPoints_nanoAOD_Run2.modules).\
56  toModify(electron_id_modules_WorkingPoints_nanoAOD,
57  WorkingPoints=electron_id_modules_WorkingPoints_nanoAOD_Run2.WorkingPoints)
58 
59 def _get_bitmapVIDForEle_docstring(modules,WorkingPoints):
60  docstring=''
61  for modname in modules:
62  ids= __import__(modname, globals(), locals(), ['idName','cutFlow'])
63  for name in dir(ids):
64  _id = getattr(ids,name)
65  if hasattr(_id,'idName') and hasattr(_id,'cutFlow'):
66  if (len(WorkingPoints)>0 and _id.idName==WorkingPoints[0].split(':')[-1]):
67  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))))
68  return docstring
69 
70 bitmapVIDForEle = cms.EDProducer("EleVIDNestedWPBitmapProducer",
71  src = cms.InputTag("slimmedElectrons"),
72  srcForID = cms.InputTag("reducedEgamma","reducedGedGsfElectrons"),
73  WorkingPoints = electron_id_modules_WorkingPoints_nanoAOD.WorkingPoints,
74 )
75 _bitmapVIDForEle_docstring = _get_bitmapVIDForEle_docstring(electron_id_modules_WorkingPoints_nanoAOD.modules,bitmapVIDForEle.WorkingPoints)
76 
77 bitmapVIDForEleFall17V2 = bitmapVIDForEle.clone(
78  WorkingPoints = electron_id_modules_WorkingPoints_nanoAOD_Run2.WorkingPoints
79  )
80 _bitmapVIDForEleFall17V2_docstring = _get_bitmapVIDForEle_docstring(electron_id_modules_WorkingPoints_nanoAOD.modules, bitmapVIDForEleFall17V2.WorkingPoints)
81 
82 bitmapVIDForEleHEEP = bitmapVIDForEle.clone(
83  WorkingPoints = cms.vstring("egmGsfElectronIDs:heepElectronID-HEEPV70"
84  )
85 )
86 _bitmapVIDForEleHEEP_docstring = _get_bitmapVIDForEle_docstring(electron_id_modules_WorkingPoints_nanoAOD.modules,bitmapVIDForEleHEEP.WorkingPoints)
87 
88 
89 
91 isoForEle = cms.EDProducer("EleIsoValueMapProducer",
92  src = cms.InputTag("slimmedElectrons"),
93  relative = cms.bool(False),
94  rho_MiniIso = cms.InputTag("fixedGridRhoFastjetAll"),
95  rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"),
96  EAFile_MiniIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Run3_Winter22/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_122X.txt"),
97  EAFile_PFIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Run3_Winter22/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_122X.txt"),
98 )
99 
100 isoForEleFall17V2 = isoForEle.clone(
101  EAFile_MiniIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Fall17/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
102  EAFile_PFIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Fall17/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
103 )
104 
105 
106 
108 ptRatioRelForEle = cms.EDProducer("ElectronJetVarProducer",
109  srcJet = cms.InputTag("updatedJetsPuppi"),
110  srcLep = cms.InputTag("slimmedElectrons"),
111  srcVtx = cms.InputTag("offlineSlimmedPrimaryVertices"),
112 )
113 
114 
115 
116 seedGainEle = cms.EDProducer("ElectronSeedGainProducer", src = cms.InputTag("slimmedElectrons"))
117 
118 
119 
121 import RecoEgamma.EgammaTools.calibratedEgammas_cff
122 
123 calibratedPatElectronsNano = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatElectrons.clone(
124  produceCalibratedObjs = False,
125  src = "slimmedElectrons"
126 )
127 
128 (run2_egamma_2016 & tracker_apv_vfp30_2016).toModify(
129  calibratedPatElectronsNano,
130  correctionFile = "EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_preVFP_RunFineEtaR9Gain"
131 )
132 
133 (run2_egamma_2016 & ~tracker_apv_vfp30_2016).toModify(
134  calibratedPatElectronsNano,
135  correctionFile = "EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_postVFP_RunFineEtaR9Gain"
136 )
137 
138 run2_egamma_2017.toModify(
139  calibratedPatElectronsNano,
140  correctionFile = "EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_24Feb2020_runEtaR9Gain_v2"
141 )
142 
143 run2_egamma_2018.toModify(
144  calibratedPatElectronsNano,
145  correctionFile = "EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2018_29Sep2020_RunFineEtaR9Gain"
146 )
147 
148 
149 
151 slimmedElectronsWithUserData = cms.EDProducer("PATElectronUserDataEmbedder",
152  src = cms.InputTag("slimmedElectrons"),
153  parentSrcs = cms.VInputTag("reducedEgamma:reducedGedGsfElectrons"),
154  userFloats = cms.PSet(
155  mvaIso_Fall17V2 = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17IsoV2Values"),
156  mvaNoIso_Fall17V2 = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV2Values"),
157  mvaIso = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2RunIIIWinter22IsoV1Values"),
158  mvaNoIso = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2RunIIIWinter22NoIsoV1Values"),
159  mvaHZZIso = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Winter22HZZV1Values"),
160 
161  miniIsoChg = cms.InputTag("isoForEle:miniIsoChg"),
162  miniIsoAll = cms.InputTag("isoForEle:miniIsoAll"),
163  PFIsoChg = cms.InputTag("isoForEle:PFIsoChg"),
164  PFIsoAll = cms.InputTag("isoForEle:PFIsoAll"),
165  PFIsoAll04 = cms.InputTag("isoForEle:PFIsoAll04"),
166 
167  miniIsoChg_Fall17V2 = cms.InputTag("isoForEleFall17V2:miniIsoChg"),
168  miniIsoAll_Fall17V2 = cms.InputTag("isoForEleFall17V2:miniIsoAll"),
169  PFIsoChg_Fall17V2 = cms.InputTag("isoForEleFall17V2:PFIsoChg"),
170  PFIsoAll_Fall17V2 = cms.InputTag("isoForEleFall17V2:PFIsoAll"),
171  PFIsoAll04_Fall17V2 = cms.InputTag("isoForEleFall17V2:PFIsoAll04"),
172 
173  ptRatio = cms.InputTag("ptRatioRelForEle:ptRatio"),
174  ptRel = cms.InputTag("ptRatioRelForEle:ptRel"),
175  jetNDauChargedMVASel = cms.InputTag("ptRatioRelForEle:jetNDauChargedMVASel"),
176  ),
177  userIntFromBools = cms.PSet(
178  mvaIso_Fall17V2_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wp90"),
179  mvaIso_Fall17V2_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wp80"),
180  mvaIso_Fall17V2_WPL = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wpLoose"),
181  mvaIso_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-RunIIIWinter22-iso-V1-wp90"),
182  mvaIso_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-RunIIIWinter22-iso-V1-wp80"),
183  mvaNoIso_Fall17V2_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wp90"),
184  mvaNoIso_Fall17V2_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wp80"),
185  mvaNoIso_Fall17V2_WPL = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wpLoose"),
186  mvaNoIso_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-RunIIIWinter22-noIso-V1-wp90"),
187  mvaNoIso_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-RunIIIWinter22-noIso-V1-wp80"),
188  mvaIso_WPHZZ = cms.InputTag("egmGsfElectronIDs:mvaEleID-Winter22-HZZ-V1"),
189 
190  cutBasedID_veto = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-veto"),
191  cutBasedID_loose = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-loose"),
192  cutBasedID_medium = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-medium"),
193  cutBasedID_tight = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-RunIIIWinter22-V1-tight"),
194  cutBasedID_Fall17V2_veto = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-veto"),
195  cutBasedID_Fall17V2_loose = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-loose"),
196  cutBasedID_Fall17V2_medium = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-medium"),
197  cutBasedID_Fall17V2_tight = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-tight"),
198  cutBasedID_HEEP = cms.InputTag("egmGsfElectronIDs:heepElectronID-HEEPV70"),
199  ),
200  userInts = cms.PSet(
201  VIDNestedWPBitmap = cms.InputTag("bitmapVIDForEle"),
202  VIDNestedWPBitmap_Fall17V2 = cms.InputTag("bitmapVIDForEleFall17V2"),
203  VIDNestedWPBitmapHEEP = cms.InputTag("bitmapVIDForEleHEEP"),
204  seedGain = cms.InputTag("seedGainEle"),
205 
206  ),
207  userCands = cms.PSet(
208  jetForLepJetVar = cms.InputTag("ptRatioRelForEle:jetForLepJetVar") # warning: Ptr is null if no match is found
209  ),
210 )
211 
212 # no need for the Run3 IDs in Run2
213 run2_egamma.toModify(slimmedElectronsWithUserData.userFloats,
214  mvaIso = None,
215  mvaNoIso = None,
216  miniIsoChg = None,
217  miniIsoAll = None,
218  PFIsoChg = None,
219  PFIsoAll = None,
220  PFIsoAll04 = None).\
221  toModify(slimmedElectronsWithUserData.userIntFromBools,
222  mvaIso_WPHZZ = None,
223  mvaIso_WP90 = None,
224  mvaIso_WP80 = None,
225  mvaNoIso_WP90 = None,
226  mvaNoIso_WP80 = None,
227  cutBasedID_veto = None,
228  cutBasedID_loose = None,
229  cutBasedID_medium = None,
230  cutBasedID_tight = None).\
231  toModify(slimmedElectronsWithUserData.userInts,
232  VIDNestedWPBitmap = None)
233 
234 run2_egamma.toModify(
235  slimmedElectronsWithUserData.userFloats,
236  ecalTrkEnergyErrPostCorrNew = cms.InputTag("calibratedPatElectronsNano","ecalTrkEnergyErrPostCorr"),
237  ecalTrkEnergyPreCorrNew = cms.InputTag("calibratedPatElectronsNano","ecalTrkEnergyPreCorr"),
238  ecalTrkEnergyPostCorrNew = cms.InputTag("calibratedPatElectronsNano","ecalTrkEnergyPostCorr"),
239  energyScaleUpNew = cms.InputTag("calibratedPatElectronsNano","energyScaleUp"),
240  energyScaleDownNew = cms.InputTag("calibratedPatElectronsNano","energyScaleDown"),
241  energySigmaUpNew = cms.InputTag("calibratedPatElectronsNano","energySigmaUp"),
242  energySigmaDownNew = cms.InputTag("calibratedPatElectronsNano","energySigmaDown")
243 )
244 
245 (run2_egamma_2016).toModify(
246  slimmedElectronsWithUserData.userFloats,
247  mvaHZZIso = "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Summer16ULIdIsoValues"
248 )
249 (run2_egamma_2017).toModify(
250  slimmedElectronsWithUserData.userFloats,
251  mvaHZZIso = "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Summer17ULIdIsoValues"
252 )
253 (run2_egamma_2018).toModify(
254  slimmedElectronsWithUserData.userFloats,
255  mvaHZZIso = "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Summer18ULIdIsoValues"
256 )
257 
258 
259 
260 finalElectrons = cms.EDFilter("PATElectronRefSelector",
261  src = cms.InputTag("slimmedElectronsWithUserData"),
262  cut = cms.string("pt > 5 ")
263 )
264 
265 
266 
267 electronPROMPTMVA= cms.EDProducer("EleBaseMVAValueMapProducer",
268  src = cms.InputTag("linkedObjects","electrons"),
269  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/el_BDTG_2017.weights.xml"),
270  name = cms.string("electronPROMPTMVA"),
271  backend = cms.string("TMVA"),
272  isClassifier = cms.bool(True),
273  variables = cms.VPSet(
274  cms.PSet( name = cms.string("LepGood_pt"), expr = cms.string("pt")),
275  cms.PSet( name = cms.string("LepGood_eta"), expr = cms.string("eta")),
276  cms.PSet( name = cms.string("LepGood_jetNDauChargedMVASel"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0")),
277  cms.PSet( name = cms.string("LepGood_miniRelIsoCharged"), expr = cms.string("userFloat('miniIsoChg_Fall17V2')/pt")),
278  cms.PSet( name = cms.string("LepGood_miniRelIsoNeutral"), expr = cms.string("(userFloat('miniIsoAll_Fall17V2')-userFloat('miniIsoChg_Fall17V2'))/pt")),
279  cms.PSet( name = cms.string("LepGood_jetPtRelv2"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0")),
280  cms.PSet( name = cms.string("LepGood_jetDF"), expr = 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")),
281  cms.PSet( name = cms.string("LepGood_jetPtRatio"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?min(userFloat('ptRatio'),1.5):1.0/(1.0+userFloat('PFIsoAll04_Fall17V2')/pt)")),
282  cms.PSet( name = cms.string("LepGood_dxy"), expr = cms.string("log(abs(dB('PV2D')))")),
283  cms.PSet( name = cms.string("LepGood_sip3d"), expr = cms.string("abs(dB('PV3D')/edB('PV3D'))")),
284  cms.PSet( name = cms.string("LepGood_dz"), expr = cms.string("log(abs(dB('PVDZ')))")),
285  cms.PSet( name = cms.string("LepGood_mvaFall17V2noIso"), expr = cms.string("userFloat('mvaNoIso_Fall17V2')")),
286  )
287 )
288 run2_egamma_2016.toModify(
289  electronPROMPTMVA,
290  weightFile = "PhysicsTools/NanoAOD/data/el_BDTG_2016.weights.xml",
291 )
292 
293 
294 
295 electronTable = simplePATElectronFlatTableProducer.clone(
296  src = cms.InputTag("linkedObjects","electrons"),
297  name= cms.string("Electron"),
298  doc = cms.string("slimmedElectrons after basic selection (" + finalElectrons.cut.value()+")"),
299  variables = cms.PSet(CandVars,
300  jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", "int16", doc="index of the associated jet (-1 if none)"),
301  photonIdx = Var("?overlaps('photons').size()>0?overlaps('photons')[0].key():-1", "int16", doc="index of the first associated photon (-1 if none)"),
302  svIdx = Var("?hasUserCand('vertex')?userCand('vertex').key():-1", "int16", doc="index of matching secondary vertex"),
303  fbrem = Var("fbrem()",float,doc="Fraction of brem",precision=10),
304  rawEnergy = Var("superCluster.rawEnergy",float,doc="raw energy of Supercluster",precision=10),
305  PreshowerEnergy = Var("superCluster.preshowerEnergy",float,doc="energy deposited in preshower",precision=10),
306  ecalEnergy = Var("ecalEnergy()",float,doc="energy after ECAL-only regression applied",precision=10),
307  ecalEnergyError = Var("ecalEnergyError",float,doc="ecalEnergy error",precision=10),
308  energyErr = Var("p4Error('P4_COMBINATION')",float,doc="energy error of the cluster-track combination",precision=6),
309  gsfTrkpMode = Var("gsfTrack().pMode()",float,doc="GSF track pMode",precision=10),
310  gsfTrkpModeErr = Var("abs(gsfTrack().qoverpModeError())*gsfTrack().pMode()*gsfTrack().pMode()",float,doc="GSF track pMode error",precision=8),
311  gsfTrketaMode = Var("gsfTrack().etaMode()",float,doc="GSF track etaMode",precision=10),
312  gsfTrkphiMode = Var("gsfTrack().phiMode()",float,doc="GSF track phiMode",precision=10),
313  isEcalDriven = Var("ecalDrivenSeed",bool,doc="is ECAL driven if true"),
314  isEB = Var("isEB",bool,doc="object in barrel if true derived from the seedCrystal and detID information"),
315  dz = Var("dB('PVDZ')",float,doc="dz (with sign) wrt first PV, in cm",precision=10),
316  dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6),
317  dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10),
318  dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6),
319  ip3d = Var("abs(dB('PV3D'))",float,doc="3D impact parameter wrt first PV, in cm",precision=10),
320  sip3d = Var("abs(dB('PV3D')/edB('PV3D'))",float,doc="3D impact parameter significance wrt first PV, in cm",precision=10),
321  deltaEtaSC = Var("superCluster().eta()-eta()",float,doc="delta eta (SC,ele) with sign",precision=10),
322  r9 = Var("full5x5_r9()",float,doc="R9 of the supercluster, calculated with full 5x5 region",precision=10),
323  sieie = Var("full5x5_sigmaIetaIeta()",float,doc="sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=10),
324  eInvMinusPInv = Var("(1-eSuperClusterOverP())/ecalEnergy()",float,doc="1/E_SC - 1/p_trk",precision=10),
325  scEtOverPt = Var("(superCluster().energy()/(pt*cosh(superCluster().eta())))-1",float,doc="(supercluster transverse energy)/pt-1",precision=8),
326 
327  mvaIso = Var("userFloat('mvaIso')",float,doc="MVA Iso ID score, Winter22V1"),
328  mvaIso_WP80 = Var("userInt('mvaIso_WP80')",bool,doc="MVA Iso ID WP80, Winter22V1"),
329  mvaIso_WP90 = Var("userInt('mvaIso_WP90')",bool,doc="MVA Iso ID WP90, Winter22V1"),
330  mvaNoIso = Var("userFloat('mvaNoIso')",float,doc="MVA noIso ID score, Winter22V1"),
331  mvaNoIso_WP80 = Var("userInt('mvaNoIso_WP80')",bool,doc="MVA noIso ID WP80, Winter22V1"),
332  mvaNoIso_WP90 = Var("userInt('mvaNoIso_WP90')",bool,doc="MVA noIso ID WP90, Winter22V1"),
333  mvaHZZIso = Var("userFloat('mvaHZZIso')", float,doc="HZZ MVA Iso ID score"),
334  mvaIso_WPHZZ = Var("userInt('mvaIso_WPHZZ')",bool,doc="MVA Iso ID WPHZZ, Winter22V1"),
335 
336  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)"),
337  vidNestedWPBitmap = Var("userInt('VIDNestedWPBitmap')", int, doc=_bitmapVIDForEle_docstring),
338  vidNestedWPBitmapHEEP = Var("userInt('VIDNestedWPBitmapHEEP')", int, doc=_bitmapVIDForEleHEEP_docstring),
339  cutBased_HEEP = Var("userInt('cutBasedID_HEEP')",bool,doc="cut-based HEEP ID"),
340  miniPFRelIso_chg = Var("userFloat('miniIsoChg')/pt",float,doc="mini PF relative isolation, charged component"),
341  miniPFRelIso_all = Var("userFloat('miniIsoAll')/pt",float,doc="mini PF relative isolation, total (with scaled rho*EA PU Winter22V1 corrections)"),
342  pfRelIso03_chg = Var("userFloat('PFIsoChg')/pt",float,doc="PF relative isolation dR=0.3, charged component"),
343  pfRelIso03_all = Var("userFloat('PFIsoAll')/pt",float,doc="PF relative isolation dR=0.3, total (with rho*EA PU Winter22V1 corrections)"),
344  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),
345  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),
346  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),
347  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),
348  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),
349  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),
350  hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8),
351  tightCharge = Var("isGsfCtfScPixChargeConsistent() + isGsfScPixChargeConsistent()", "uint8", doc="Tight charge criteria (0:none, 1:isGsfScPixChargeConsistent, 2:isGsfCtfScPixChargeConsistent)"),
352  convVeto = Var("passConversionVeto()",bool,doc="pass conversion veto"),
353  lostHits = Var("gsfTrack.hitPattern.numberOfLostHits('MISSING_INNER_HITS')","uint8",doc="number of missing inner hits"),
354  isPFcand = Var("pfCandidateRef().isNonnull()",bool,doc="electron is PF candidate"),
355  seedGain = Var("userInt('seedGain')","uint8",doc="Gain of the seed crystal"),
356  seediEtaOriX = Var("superCluster().seedCrysIEtaOrIx","int16",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."),
357  seediPhiOriY = Var("superCluster().seedCrysIPhiOrIy","int16",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."),
358  jetNDauCharged = Var("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0", "uint8", doc="number of charged daughters of the closest jet"),
359  ),
360  externalVariables = cms.PSet(
361  promptMVA = ExtVar(cms.InputTag("electronPROMPTMVA"),float, doc="Prompt MVA lepton ID score. Corresponds to the previous mvaTTH",precision=14),
362  fsrPhotonIdx = ExtVar(cms.InputTag("leptonFSRphotons:eleFsrIndex"), "int16", doc="Index of the lowest-dR/ET2 among associated FSR photons"),
363  ),
364 )
365 
366 # extra variables for e/gamma custom nano
367 _eleVarsExtra = cms.PSet(
368  r9Frac = Var("r9()",float,doc="Fractional R9 of the supercluster",precision=10),
369  DeltaEtaInSC = Var("deltaEtaSuperClusterTrackAtVtx",float,doc="dEta(Inner track, supercluster)",precision=10),
370  DeltaEtaInSeed = Var("deltaEtaSeedClusterTrackAtCalo",float,doc="dEta(Inner track, seedcluster)",precision=10),
371  DeltaPhiInSC = Var("deltaPhiSuperClusterTrackAtVtx",float,doc="dPhi(Inner track, supercluster)",precision=10),
372  DeltaPhiInSeed = Var("deltaPhiSeedClusterTrackAtCalo",float,doc="dPhi(Inner track, seedcluster)",precision=10),
373  full5x5HoverE = Var("full5x5_hcalOverEcal",float,doc="full5x5 H/E",precision=10),
374  eSCOverP = Var("eSuperClusterOverP",float,doc="E/P",precision=10),
375  eEleOverPout = Var("eEleClusterOverPout",float,doc="EleE/Pouter",precision=10),
376  e1x5 = Var("full5x5_e1x5",float,doc="energy in 1x5",precision=10),
377  e2x5max = Var("full5x5_e2x5Max",float,doc="energy in 2x5",precision=10),
378  e5x5 = Var("full5x5_e5x5",float,doc="energy in 5x5",precision=10),
379  closestKFchi2 = Var("closestCtfTrackNormChi2",float,doc="KF track Chi2",precision=10),
380  closestKFNLayers = Var("closestCtfTrackNLayers",int,doc="KF track number of layers"),
381  dr03HcalTowerSumEt = Var("dr03HcalTowerSumEt",float,doc="HCal isolation",precision=10),
382  GSFchi2 = Var("gsfTrack.normalizedChi2",float,doc="GSF track Chi2",precision=10),
383  superclusterEta = Var("superCluster.eta",float,doc="supercluster eta",precision=10),
384  ecalPFClusIso = Var("ecalPFClusterIso",float,doc="ECAL PF cluster isolation",precision=10),
385  hcalPFClusIso = Var("hcalPFClusterIso",float,doc="HCAL PF cluster isolation",precision=10),
386  nBrem = Var("numberOfBrems",int,doc="number of brems"),
387  pfPhotonIso = Var("pfIsolationVariables.sumPhotonEt",float,doc="PF photon isolation (no PU correction)",precision=10),
388  pfChargedHadIso = Var("pfIsolationVariables.sumChargedHadronPt",float,doc="PF charged-hadron isolation (no PU correction)",precision=10),
389  pfNeutralHadIso = Var("pfIsolationVariables.sumNeutralHadronEt",float,doc="PF neutral-hadron isolation (no PU correction)",precision=10),
390  sigmaIphiIphiFull5x5 = Var("full5x5_sigmaIphiIphi",float,doc="Full5x5 sigmaIPhiIPhi",precision=10),
391  etaWidth = Var("superCluster.etaWidth",float,doc="etawidth of supercluster",precision=10),
392  phiWidth = Var("superCluster.phiWidth",float,doc="phiwidth of supercluster",precision=10),
393  seedClusEnergy = Var("superCluster.seed.energy",float,doc="seed cluster energy",precision=10),
394  hoeSingleTower = Var("hcalOverEcalBc",float,doc="Single HCAL tower based H/E",precision=10),
395  hoeFull5x5 = Var("full5x5_hcalOverEcal",float,doc="Full5x5 cone-based H/E",precision=10),
396  sigmaIetaIphiFull5x5 = Var("full5x5_showerShape.sigmaIetaIphi",float,doc="Full5x5 sigmaIEtaIPhi",precision=10),
397  eMax = Var("full5x5_showerShape.eMax",float,doc="Emax",precision=10),
398  e2nd = Var("full5x5_showerShape.e2nd",float,doc="E2nd",precision=10),
399  eTop = Var("full5x5_showerShape.eTop",float,doc="Etop",precision=10),
400  eBottom = Var("full5x5_showerShape.eBottom",float,doc="Ebottom",precision=10),
401  eLeft = Var("full5x5_showerShape.eLeft",float,doc="Eleft",precision=10),
402  eRight = Var("full5x5_showerShape.eRight",float,doc="Eright",precision=10),
403  e2x5Top = Var("full5x5_showerShape.e2x5Top",float,doc="E2x5Top",precision=10),
404  e2x5Bottom = Var("full5x5_showerShape.e2x5Bottom",float,doc="E2x5Bottom",precision=10),
405  e2x5Left = Var("full5x5_showerShape.e2x5Left",float,doc="E2x5Left",precision=10),
406  e2x5Right = Var("full5x5_showerShape.e2x5Right",float,doc="E2x5Right",precision=10),
407  nSaturatedXtals = Var("nSaturatedXtals",int,doc="number of saturated crystals"),
408  numberOfClusters = Var("superCluster.clusters.size",int,doc="number of clusters"),
409  istrackerDriven = Var("trackerDrivenSeed",bool,doc="is tracker driven if true"),
410  superclusterPhi = Var("superCluster().phi()",float,doc="supercluster phi",precision=10),
411  seedClusterEta = Var("superCluster().seed().eta()",float,doc="seed cluster eta",precision=10),
412  seedClusterPhi = Var("superCluster().seed().phi()",float,doc="seed cluster phi",precision=10),
413  superclusterEnergy = Var("superCluster().energy()",float,doc="only PF cluster energy is corrected, no object-level regression",precision=10),
414  energy = Var("energy()",float,doc="energy after final regression",precision=10),
415  trackMomentumError = Var("trackMomentumError",float,doc="trackMomentum error",precision=10),
416  trackMomentum = Var("trackMomentumAtVtx().R()",float,doc="trackMomentum at vertex",precision=10),
417  trkLayersWithMeas = Var("gsfTrack.hitPattern.trackerLayersWithMeasurement",int,doc="trackerLayersWithMeasurement"),
418  nValidPixBarrelHits = Var("gsfTrack.hitPattern.numberOfValidPixelBarrelHits",int,doc="numberOfValidPixelBarrelHits"),
419  nValidPixEndcapHits = Var("gsfTrack.hitPattern.numberOfValidPixelEndcapHits",int,doc="numberOfValidPixelEndcapHits"),
420  superClusterFbrem = Var("superClusterFbrem",float,doc="superClusterFbrem",precision=10),
421  convVtxFitProb = Var("convVtxFitProb",float,doc="convVtxFitProb",precision=10),
422  clustersSize = Var("superCluster.clustersSize",int,doc="clustersSize"),
423  iEtaMod5 = Var("?superCluster.seedCrysIEtaOrIx>0?(superCluster.seedCrysIEtaOrIx-1)%5:(superCluster.seedCrysIEtaOrIx+1)%5",int,doc="iEtaMod5"),
424  iEtaMod20 = Var("?abs(superCluster.seedCrysIEtaOrIx)<=25?(superCluster.seedCrysIEtaOrIx-(?superCluster.seedCrysIEtaOrIx>0?+1:-1))%20:(superCluster.seedCrysIEtaOrIx-(?superCluster.seedCrysIEtaOrIx>0?+26:-26))%20",int,doc="iEtaMod20"),
425  iPhiMod2 = Var("(superCluster.seedCrysIPhiOrIy-1)%2",int,doc="iPhiMod2"),
426  iPhiMod20 = Var("(superCluster.seedCrysIPhiOrIy-1)%20",int,doc="iPhiMod20"),
427 )
428 
429 (run2_egamma).toModify(
430  # energy scale/smearing: only for Run2
431  electronTable.variables,
432  pt = Var("pt*userFloat('ecalTrkEnergyPostCorrNew')/userFloat('ecalTrkEnergyPreCorrNew')", float, precision=-1, doc="p_{T}"),
433  energyErr = Var("userFloat('ecalTrkEnergyErrPostCorrNew')", float, precision=6, doc="energy error of the cluster-track combination"),
434  eCorr = Var("userFloat('ecalTrkEnergyPostCorrNew')/userFloat('ecalTrkEnergyPreCorrNew')", float, doc="ratio of the calibrated energy/miniaod energy"),
435  scEtOverPt = Var("(superCluster().energy()/(pt*userFloat('ecalTrkEnergyPostCorrNew')/userFloat('ecalTrkEnergyPreCorrNew')*cosh(superCluster().eta())))-1",float,doc="(supercluster transverse energy)/pt-1",precision=8),
436  dEscaleUp=Var("userFloat('ecalTrkEnergyPostCorrNew')-userFloat('energyScaleUpNew')", float, doc="ecal energy scale shifted 1 sigma up(adding gain/stat/syst in quadrature)", precision=8),
437  dEscaleDown=Var("userFloat('ecalTrkEnergyPostCorrNew')-userFloat('energyScaleDownNew')", float, doc="ecal energy scale shifted 1 sigma down (adding gain/stat/syst in quadrature)", precision=8),
438  dEsigmaUp=Var("userFloat('ecalTrkEnergyPostCorrNew')-userFloat('energySigmaUpNew')", float, doc="ecal energy smearing value shifted 1 sigma up", precision=8),
439  dEsigmaDown=Var("userFloat('ecalTrkEnergyPostCorrNew')-userFloat('energySigmaDownNew')", float, doc="ecal energy smearing value shifted 1 sigma up", precision=8),
440  # Fall17V2 IDs and isolations are only for Run2. The names of these IDs and isolations are same as in Run3.
441  mvaIso = Var("userFloat('mvaIso_Fall17V2')",float,doc="MVA Iso ID score, Fall17V2"),
442  mvaIso_WP80 = Var("userInt('mvaIso_Fall17V2_WP80')",bool,doc="MVA Iso ID WP80, Fall17V2"),
443  mvaIso_WP90 = Var("userInt('mvaIso_Fall17V2_WP90')",bool,doc="MVA Iso ID WP90, Fall17V2"),
444  mvaIso_WPL = Var("userInt('mvaIso_Fall17V2_WPL')",bool,doc="MVA Iso ID loose WP, Fall17V2"),
445  mvaNoIso = Var("userFloat('mvaNoIso_Fall17V2')",float,doc="MVA noIso ID score, Fall17V2"),
446  mvaNoIso_WP80 = Var("userInt('mvaNoIso_Fall17V2_WP80')",bool,doc="MVA noIso ID WP80, Fall17V2"),
447  mvaIso_WPHZZ = None,
448  mvaNoIso_WP90 = Var("userInt('mvaNoIso_Fall17V2_WP90')",bool,doc="MVA noIso ID WP90, Fall17V2"),
449  mvaNoIso_WPL = Var("userInt('mvaNoIso_Fall17V2_WPL')",bool,doc="MVA noIso ID loose WP, Fall17V2"),
450  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)"),
451  vidNestedWPBitmap = Var("userInt('VIDNestedWPBitmap_Fall17V2')", int, doc=_bitmapVIDForEleFall17V2_docstring),
452  miniPFRelIso_chg = Var("userFloat('miniIsoChg_Fall17V2')/pt",float,doc="mini PF relative isolation, charged component in Run2"),
453  miniPFRelIso_all = Var("userFloat('miniIsoAll_Fall17V2')/pt",float,doc="mini PF relative isolation, total (with scaled rho*EA Fall17V2 PU corrections) in Run2"),
454  pfRelIso03_chg = Var("userFloat('PFIsoChg_Fall17V2')/pt",float,doc="PF relative isolation dR=0.3 with 94 EffArea, charged component in Run2"),
455  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"),
456  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),
457 )
458 
459 
461 tautaggerForMatching = cms.EDProducer("GenJetTauTaggerProducer",
462  src = cms.InputTag('particleLevel:leptons')
463 )
464 
465 matchingElecPhoton = cms.EDProducer("GenJetGenPartMerger",
466  srcJet =cms.InputTag("particleLevel:leptons"),
467  srcPart=cms.InputTag("particleLevel:photons"),
468  cut = cms.string("pt > 3"),
469  hasTauAnc=cms.InputTag("tautaggerForMatching"),
470 )
471 electronsMCMatchForTableAlt = cms.EDProducer("GenJetMatcherDRPtByDR", # cut on deltaR, deltaPt/Pt; pick best by deltaR
472  src = electronTable.src, # final reco collection
473  matched = cms.InputTag("matchingElecPhoton:merged"), # final mc-truth particle collection
474  mcPdgId = cms.vint32(11,22), # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
475  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
476  mcStatus = cms.vint32(),
477  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
478  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
479  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
480  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
481 )
482 electronsMCMatchForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
483  src = electronTable.src, # final reco collection
484  matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
485  mcPdgId = cms.vint32(11,22), # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
486  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
487  mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
488  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
489  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
490  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
491  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
492 )
493 #should be cloned from PhysicsTools/NanoAOD/python/candMcMatchTable_cfi.py
494 electronMCTable = cms.EDProducer("CandMCMatchTableProducer",
495  src = electronTable.src,
496  mcMapDressedLep = cms.InputTag("electronsMCMatchForTableAlt"),
497  mcMap = cms.InputTag("electronsMCMatchForTable"),
498  mapTauAnc = cms.InputTag("matchingElecPhoton:hasTauAnc"),
499  objName = electronTable.name,
500  objType = electronTable.name, #cms.string("Electron"),
501  branchName = cms.string("genPart"),
502  docString = cms.string("MC matching to status==1 electrons or photons"),
503  genparticles = cms.InputTag("finalGenParticles"),
504 )
505 
506 electronTask = cms.Task(bitmapVIDForEle,bitmapVIDForEleFall17V2,bitmapVIDForEleHEEP,isoForEle,isoForEleFall17V2,ptRatioRelForEle,seedGainEle,calibratedPatElectronsNano,slimmedElectronsWithUserData,finalElectrons)
507 electronTablesTask = cms.Task(electronPROMPTMVA, electronTable)
508 electronMCTask = cms.Task(tautaggerForMatching, matchingElecPhoton, electronsMCMatchForTable, electronsMCMatchForTableAlt, electronMCTable)
509 
510 _electronTask_Run2 = electronTask.copy()
511 _electronTask_Run2.remove(bitmapVIDForEle)
512 _electronTask_Run2.remove(isoForEle)
513 _electronTask_Run2.add(calibratedPatElectronsNano)
514 run2_egamma.toReplaceWith(electronTask, _electronTask_Run2)
515 
516 # Revert back to AK4 CHS jets for Run2 inputs
517 run2_nanoAOD_ANY.toModify(
518  ptRatioRelForEle,srcJet="updatedJets")
constexpr int32_t ceil(float num)
def Var(expr, valtype, doc=None, precision=-1, lazyEval=False)
Definition: common_cff.py:17
def ExtVar(tag, valtype, doc=None, precision=-1)
Definition: common_cff.py:28
def _get_bitmapVIDForEle_docstring(modules, WorkingPoints)
static std::string join(char **cmd)
Definition: RemoteFile.cc:19