CMS 3D CMS Logo

electrons_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
3 from Configuration.Eras.Modifier_run2_nanoAOD_92X_cff import run2_nanoAOD_92X
6 from math import ceil,log
7 
8 # this below is used only in some eras
9 slimmedElectronsUpdated = cms.EDProducer("PATElectronUpdater",
10  src = cms.InputTag("slimmedElectrons"),
11  vertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
12  computeMiniIso = cms.bool(False),
13  pfCandsForMiniIso = cms.InputTag("packedPFCandidates"),
14  miniIsoParamsB = PhysicsTools.PatAlgos.producersLayer1.electronProducer_cfi.patElectrons.miniIsoParamsB, # so they're in sync
15  miniIsoParamsE = PhysicsTools.PatAlgos.producersLayer1.electronProducer_cfi.patElectrons.miniIsoParamsE, # so they're in sync
16 )
17 run2_miniAOD_80XLegacy.toModify( slimmedElectronsUpdated, computeMiniIso = True )
18 
19 from PhysicsTools.SelectorUtils.tools.vid_id_tools import setupVIDSelection
22 
23 electronMVAValueMapProducer.srcMiniAOD = cms.InputTag("slimmedElectrons")
24 run2_miniAOD_80XLegacy.toModify(electronMVAValueMapProducer, srcMiniAOD = "slimmedElectronsUpdated")
25 run2_nanoAOD_92X.toModify(electronMVAValueMapProducer, srcMiniAOD = "slimmedElectronsUpdated")
26 
27 egmGsfElectronIDs.physicsObjectIDs = cms.VPSet()
28 egmGsfElectronIDs.physicsObjectSrc = cms.InputTag('slimmedElectrons')
29 run2_miniAOD_80XLegacy.toModify(egmGsfElectronIDs, physicsObjectSrc = "slimmedElectronsUpdated")
30 run2_nanoAOD_92X.toModify(egmGsfElectronIDs, physicsObjectSrc = "slimmedElectronsUpdated")
31 
32 heepIDVarValueMaps.elesMiniAOD = cms.InputTag('slimmedElectrons')
33 run2_miniAOD_80XLegacy.toModify(heepIDVarValueMaps, elesMiniAOD = "slimmedElectronsUpdated")
34 run2_nanoAOD_92X.toModify(heepIDVarValueMaps, elesMiniAOD = "slimmedElectronsUpdated")
35 
36 _electron_id_vid_modules=[
37 'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff',
38 'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronHLTPreselecition_Summer16_V1_cff',
39 'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff',
40 'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff',
41 'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_HZZ_V1_cff',
42 ]
43 _bitmapVIDForEle_WorkingPoints = cms.vstring(
44  "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-loose",
45  "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-medium",
46  "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-tight",
47 )
48 _bitmapVIDForEle_docstring = ''
49 for modname in _electron_id_vid_modules:
50  ids= __import__(modname, globals(), locals(), ['idName','cutFlow'])
51  for name in dir(ids):
52  _id = getattr(ids,name)
53  if hasattr(_id,'idName') and hasattr(_id,'cutFlow'):
54  setupVIDSelection(egmGsfElectronIDs,_id)
55  if (len(_bitmapVIDForEle_WorkingPoints)>0 and _id.idName==_bitmapVIDForEle_WorkingPoints[0].split(':')[-1]):
56  _bitmapVIDForEle_docstring = 'VID compressed bitmap (%s), %d bits per cut'%(','.join([cut.cutName.value() for cut in _id.cutFlow]),int(ceil(log(len(_bitmapVIDForEle_WorkingPoints)+1,2))))
57 
58 bitmapVIDForEle = cms.EDProducer("EleVIDNestedWPBitmapProducer",
59  src = cms.InputTag("slimmedElectrons"),
60  WorkingPoints = _bitmapVIDForEle_WorkingPoints,
61 )
62 run2_miniAOD_80XLegacy.toModify(bitmapVIDForEle, src = "slimmedElectronsUpdated")
63 run2_nanoAOD_92X.toModify(bitmapVIDForEle, src = "slimmedElectronsUpdated")
64 
65 isoForEle = cms.EDProducer("EleIsoValueMapProducer",
66  src = cms.InputTag("slimmedElectrons"),
67  relative = cms.bool(False),
68  rho_MiniIso = cms.InputTag("fixedGridRhoFastjetAll"),
69  rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"),
70  EAFile_MiniIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Spring15/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_25ns.txt"),
71  EAFile_PFIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Summer16/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_80X.txt"),
72 )
73 run2_miniAOD_80XLegacy.toModify(isoForEle, src = "slimmedElectronsUpdated")
74 run2_nanoAOD_92X.toModify(isoForEle, src = "slimmedElectronsUpdated")
75 
76 ptRatioRelForEle = cms.EDProducer("ElectronJetVarProducer",
77  srcJet = cms.InputTag("slimmedJets"),
78  srcLep = cms.InputTag("slimmedElectrons"),
79  srcVtx = cms.InputTag("offlineSlimmedPrimaryVertices"),
80 )
81 run2_miniAOD_80XLegacy.toModify(ptRatioRelForEle, srcLep = "slimmedElectronsUpdated")
82 run2_nanoAOD_92X.toModify(ptRatioRelForEle, srcLep = "slimmedElectronsUpdated")
83 
84 from EgammaAnalysis.ElectronTools.calibratedElectronsRun2_cfi import calibratedPatElectrons
85 calibratedPatElectrons.correctionFile = cms.string("PhysicsTools/NanoAOD/data/80X_ichepV1_2016_ele") # hack, should go somewhere in EgammaAnalysis
86 calibratedPatElectrons.semiDeterministic = cms.bool(True)
87 run2_miniAOD_80XLegacy.toModify(calibratedPatElectrons, electrons = "slimmedElectronsUpdated")
88 run2_nanoAOD_92X.toModify(calibratedPatElectrons, electrons = "slimmedElectronsUpdated")
89 
90 energyCorrForEle = cms.EDProducer("ElectronEnergyVarProducer",
91  srcRaw = cms.InputTag("slimmedElectrons"),
92  srcCorr = cms.InputTag("calibratedPatElectrons"),
93 )
94 run2_miniAOD_80XLegacy.toModify(energyCorrForEle, srcRaw = "slimmedElectronsUpdated")
95 run2_nanoAOD_92X.toModify(energyCorrForEle, srcRaw = "slimmedElectronsUpdated")
96 
97 
98 slimmedElectronsWithUserData = cms.EDProducer("PATElectronUserDataEmbedder",
99  src = cms.InputTag("slimmedElectrons"),
100  userFloats = cms.PSet(
101  mvaSpring16GP = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1Values"),
102  mvaSpring16HZZ = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16HZZV1Values"),
103  miniIsoChg = cms.InputTag("isoForEle:miniIsoChg"),
104  miniIsoAll = cms.InputTag("isoForEle:miniIsoAll"),
105  PFIsoChg = cms.InputTag("isoForEle:PFIsoChg"),
106  PFIsoAll = cms.InputTag("isoForEle:PFIsoAll"),
107  ptRatio = cms.InputTag("ptRatioRelForEle:ptRatio"),
108  ptRel = cms.InputTag("ptRatioRelForEle:ptRel"),
109  jetNDauChargedMVASel = cms.InputTag("ptRatioRelForEle:jetNDauChargedMVASel"),
110  eCorr = cms.InputTag("energyCorrForEle:eCorr"),
111  ),
112  userIntFromBools = cms.PSet(
113  mvaSpring16GP_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp90"),
114  mvaSpring16GP_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp80"),
115  mvaSpring16HZZ_WPL = cms.InputTag("egmGsfElectronIDs:mvaEleID-Spring16-HZZ-V1-wpLoose"),
116  cutbasedID_veto = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-veto"),
117  cutbasedID_loose = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-loose"),
118  cutbasedID_medium = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-medium"),
119  cutbasedID_tight = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-tight"),
120  cutbasedID_HLT = cms.InputTag("egmGsfElectronIDs:cutBasedElectronHLTPreselection-Summer16-V1"),
121  cutbasedID_HEEP = cms.InputTag("egmGsfElectronIDs:heepElectronID-HEEPV70"),
122  ),
123  userInts = cms.PSet(
124  VIDNestedWPBitmap = cms.InputTag("bitmapVIDForEle"),
125  ),
126  userCands = cms.PSet(
127  jetForLepJetVar = cms.InputTag("ptRatioRelForEle:jetForLepJetVar") # warning: Ptr is null if no match is found
128  ),
129 )
130 run2_miniAOD_80XLegacy.toModify(slimmedElectronsWithUserData, src = "slimmedElectronsUpdated")
131 run2_nanoAOD_92X.toModify(slimmedElectronsWithUserData, src = "slimmedElectronsUpdated")
132 
133 finalElectrons = cms.EDFilter("PATElectronRefSelector",
134  src = cms.InputTag("slimmedElectronsWithUserData"),
135  cut = cms.string("pt > 5 ")
136 )
137 
138 electronMVATTH= cms.EDProducer("EleBaseMVAValueMapProducer",
139  src = cms.InputTag("linkedObjects","electrons"),
140  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/el_BDTG.weights.xml"),
141  name = cms.string("electronMVATTH"),
142  isClassifier = cms.bool(True),
143  variablesOrder = cms.vstring(["LepGood_pt","LepGood_eta","LepGood_jetNDauChargedMVASel","LepGood_miniRelIsoCharged","LepGood_miniRelIsoNeutral","LepGood_jetPtRelv2","LepGood_jetPtRatio","LepGood_jetBTagCSV","LepGood_sip3d","LepGood_dxy","LepGood_dz","LepGood_mvaIdSpring16HZZ"]),
144  variables = cms.PSet(
145  LepGood_pt = cms.string("pt"),
146  LepGood_eta = cms.string("eta"),
147  LepGood_jetNDauChargedMVASel = cms.string("userFloat('jetNDauChargedMVASel')"),
148  LepGood_miniRelIsoCharged = cms.string("userFloat('miniIsoChg')/pt"),
149  LepGood_miniRelIsoNeutral = cms.string("(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"),
150  LepGood_jetPtRelv2 = cms.string("userFloat('ptRel')"),
151  LepGood_jetPtRatio = cms.string("min(userFloat('ptRatio'),1.5)"),
152  LepGood_jetBTagCSV = cms.string("?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags'),0.0):-99.0"),
153  LepGood_sip3d = cms.string("abs(dB('PV3D')/edB('PV3D'))"),
154  LepGood_dxy = cms.string("log(abs(dB('PV2D')))"),
155  LepGood_dz = cms.string("log(abs(dB('PVDZ')))"),
156  LepGood_mvaIdSpring16HZZ = cms.string("userFloat('mvaSpring16HZZ')"),
157  )
158 )
159 
160 electronTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
161  src = cms.InputTag("linkedObjects","electrons"),
162  cut = cms.string(""), #we should not filter on cross linked collections
163  name= cms.string("Electron"),
164  doc = cms.string("slimmedElectrons after basic selection (" + finalElectrons.cut.value()+")"),
165  singleton = cms.bool(False), # the number of entries is variable
166  extension = cms.bool(False), # this is the main table for the electrons
167  variables = cms.PSet(CandVars,
168  jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"),
169  photonIdx = Var("?overlaps('photons').size()>0?overlaps('photons')[0].key():-1", int, doc="index of the associated photon (-1 if none)"),
170  energyErr = Var("p4Error('P4_COMBINATION')*userFloat('eCorr')",float,doc="energy error of the cluster-track combination",precision=6),
171  eCorr = Var("userFloat('eCorr')",float,doc="ratio of the calibrated energy/miniaod energy"),
172  dz = Var("dB('PVDZ')",float,doc="dz (with sign) wrt first PV, in cm",precision=10),
173  dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6),
174  dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10),
175  dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6),
176  ip3d = Var("abs(dB('PV3D'))",float,doc="3D impact parameter wrt first PV, in cm",precision=10),
177  sip3d = Var("abs(dB('PV3D')/edB('PV3D'))",float,doc="3D impact parameter significance wrt first PV, in cm",precision=10),
178  deltaEtaSC = Var("superCluster().eta()-eta()",float,doc="delta eta (SC,ele) with sign",precision=10),
179  r9 = Var("full5x5_r9()",float,doc="R9 of the supercluster, calculated with full 5x5 region",precision=10),
180  sieie = Var("full5x5_sigmaIetaIeta()",float,doc="sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=10),
181  eInvMinusPInv = Var("(1-eSuperClusterOverP())/ecalEnergy()",float,doc="1/E_SC - 1/p_trk",precision=10),
182  mvaSpring16GP = Var("userFloat('mvaSpring16GP')",float,doc="MVA general-purpose ID score"),
183  mvaSpring16GP_WP80 = Var("userInt('mvaSpring16GP_WP80')",bool,doc="MVA general-purpose ID WP80"),
184  mvaSpring16GP_WP90 = Var("userInt('mvaSpring16GP_WP90')",bool,doc="MVA general-purpose ID WP90"),
185  mvaSpring16HZZ = Var("userFloat('mvaSpring16HZZ')",float,doc="MVA HZZ ID score"),
186  mvaSpring16HZZ_WPL = Var("userInt('mvaSpring16HZZ_WPL')",bool,doc="MVA HZZ ID loose WP"),
187  cutBased = Var("userInt('cutbasedID_veto')+userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",int,doc="cut-based ID (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)"),
188  vidNestedWPBitmap = Var("userInt('VIDNestedWPBitmap')",int,doc=_bitmapVIDForEle_docstring),
189  cutBased_HLTPreSel = Var("userInt('cutbasedID_HLT')",int,doc="cut-based HLT pre-selection ID"),
190  cutBased_HEEP = Var("userInt('cutbasedID_HEEP')",bool,doc="cut-based HEEP ID"),
191  miniPFRelIso_chg = Var("userFloat('miniIsoChg')/pt",float,doc="mini PF relative isolation, charged component"),
192  miniPFRelIso_all = Var("userFloat('miniIsoAll')/pt",float,doc="mini PF relative isolation, total (with scaled rho*EA PU corrections)"),
193  pfRelIso03_chg = Var("userFloat('PFIsoChg')/pt",float,doc="PF relative isolation dR=0.3, charged component"),
194  pfRelIso03_all = Var("userFloat('PFIsoAll')/pt",float,doc="PF relative isolation dR=0.3, total (with rho*EA PU corrections)"),
195  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),
196  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),
197  dr03HcalDepth1TowerSumEt = Var("?pt>35?dr03HcalDepth1TowerSumEt():0",float,doc="Non-PF Hcal isolation within a delta R cone of 0.3 with electron pt > 35 GeV",precision=8),
198  hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8),
199  tightCharge = Var("isGsfCtfScPixChargeConsistent() + isGsfScPixChargeConsistent()",int,doc="Tight charge criteria (0:none, 1:isGsfScPixChargeConsistent, 2:isGsfCtfScPixChargeConsistent)"),
200  convVeto = Var("passConversionVeto()",bool,doc="pass conversion veto"),
201  lostHits = Var("gsfTrack.hitPattern.numberOfLostHits('MISSING_INNER_HITS')","uint8",doc="number of missing inner hits"),
202  isPFcand = Var("pfCandidateRef().isNonnull()",bool,doc="electron is PF candidate"),
203  ),
204  externalVariables = cms.PSet(
205  mvaTTH = ExtVar(cms.InputTag("electronMVATTH"),float, doc="TTH MVA lepton ID score",precision=14),
206  ),
207 )
208 electronTable.variables.pt = Var("pt*userFloat('eCorr')", float, precision=-1, doc="p_{T} after energy correction & smearing")
209 
210 electronsMCMatchForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
211  src = electronTable.src, # final reco collection
212  matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
213  mcPdgId = cms.vint32(11,22), # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
214  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
215  mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
216  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
217  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
218  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
219  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
220 )
221 
222 electronMCTable = cms.EDProducer("CandMCMatchTableProducer",
223  src = electronTable.src,
224  mcMap = cms.InputTag("electronsMCMatchForTable"),
225  objName = electronTable.name,
226  objType = electronTable.name, #cms.string("Electron"),
227  branchName = cms.string("genPart"),
228  docString = cms.string("MC matching to status==1 electrons or photons"),
229 )
230 
231 electronSequence = cms.Sequence(heepIDVarValueMaps + egmGsfElectronIDSequence + bitmapVIDForEle + isoForEle + ptRatioRelForEle + calibratedPatElectrons + energyCorrForEle + slimmedElectronsWithUserData + finalElectrons)
232 electronTables = cms.Sequence (electronMVATTH + electronTable)
233 electronMC = cms.Sequence(electronsMCMatchForTable + electronMCTable)
234 
235 _withUpdate_sequence = cms.Sequence(slimmedElectronsUpdated + electronSequence.copy())
236 run2_nanoAOD_92X.toReplaceWith(electronSequence, _withUpdate_sequence)
237 run2_miniAOD_80XLegacy.toReplaceWith(electronSequence, _withUpdate_sequence)
def ExtVar(tag, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
Definition: common_cff.py:31
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