CMS 3D CMS Logo

lowPtElectrons_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
4 
5 
8 
9 from RecoEgamma.EgammaTools.lowPtElectronModifier_cfi import lowPtElectronModifier
10 modifiedLowPtElectrons = cms.EDProducer(
11  "ModifiedElectronProducer",
12  src = cms.InputTag("slimmedLowPtElectrons"),
13  modifierConfig = cms.PSet(
14  modifications = cms.VPSet(lowPtElectronModifier)
15  )
16 )
17 
19 updatedLowPtElectrons = cms.EDProducer(
20  "PATElectronUpdater",
21  src = cms.InputTag("modifiedLowPtElectrons"),
22  vertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
23  computeMiniIso = cms.bool(True),
24  fixDxySign = cms.bool(False),
25  pfCandsForMiniIso = cms.InputTag("packedPFCandidates"),
26  miniIsoParamsB = PhysicsTools.PatAlgos.producersLayer1.electronProducer_cfi.patElectrons.miniIsoParamsB,
27  miniIsoParamsE = PhysicsTools.PatAlgos.producersLayer1.electronProducer_cfi.patElectrons.miniIsoParamsE,
28 )
29 
30 isoForLowPtEle = cms.EDProducer(
31  "EleIsoValueMapProducer",
32  src = cms.InputTag("updatedLowPtElectrons"),
33  relative = cms.bool(True),
34  rho_MiniIso = cms.InputTag("fixedGridRhoFastjetAll"),
35  rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"),
36  EAFile_MiniIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Fall17/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
37  EAFile_PFIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Fall17/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
38 )
39 
40 updatedLowPtElectronsWithUserData = cms.EDProducer(
41  "PATElectronUserDataEmbedder",
42  src = cms.InputTag("updatedLowPtElectrons"),
43  userFloats = cms.PSet(
44  miniIsoChg = cms.InputTag("isoForLowPtEle:miniIsoChg"),
45  miniIsoAll = cms.InputTag("isoForLowPtEle:miniIsoAll"),
46  ),
47  userIntFromBools = cms.PSet(),
48  userInts = cms.PSet(),
49  userCands = cms.PSet(),
50 )
51 
52 finalLowPtElectrons = cms.EDFilter(
53  "PATElectronRefSelector",
54  src = cms.InputTag("updatedLowPtElectronsWithUserData"),
55  cut = cms.string("pt > 1. && electronID('ID') > -0.25"),
56 )
57 
58 
61 
62 lowPtElectronTable = cms.EDProducer(
63  "SimpleCandidateFlatTableProducer",
64  src = cms.InputTag("linkedObjects","lowPtElectrons"),
65  cut = cms.string(""),
66  name= cms.string("LowPtElectron"),
67  doc = cms.string("slimmedLowPtElectrons after basic selection (" + finalLowPtElectrons.cut.value()+")"),
68  singleton = cms.bool(False), # the number of entries is variable
69  extension = cms.bool(False), # this is the main table for the electrons
70  variables = cms.PSet(
71  # Basic variables
72  CandVars,
73  # Overlaps with PF electron
74  electronIdx = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", int, doc="index of the overlapping PF electron (-1 if none)"),
75  # BDT scores and WPs
76  ID = Var("electronID('ID')",float,doc="ID, BDT (raw) score"),
77  unbiased = Var("electronID('unbiased')",float,doc="ElectronSeed, pT- and dxy- agnostic BDT (raw) score"),
78  ptbiased = Var("electronID('ptbiased')",float,doc="ElectronSeed, pT- and dxy- dependent BDT (raw) score"),
79  # Isolation
80  miniPFRelIso_chg = Var("userFloat('miniIsoChg')",float,
81  doc="mini PF relative isolation, charged component"),
82  miniPFRelIso_all = Var("userFloat('miniIsoAll')",float,
83  doc="mini PF relative isolation, total (with scaled rho*EA PU corrections)"),
84  # Conversions
85  convVeto = Var("passConversionVeto()",bool,doc="pass conversion veto"),
86  convWP = Var("userInt('convOpen')*1 + userInt('convLoose')*2 + userInt('convTight')*4",
87  int,doc="conversion flag bit map: 1=Veto, 2=Loose, 3=Tight"),
88  convVtxRadius = Var("userFloat('convVtxRadius')",float,doc="conversion vertex radius (cm)",precision=7),
89  # Tracking
90  lostHits = Var("gsfTrack.hitPattern.numberOfLostHits('MISSING_INNER_HITS')","uint8",doc="number of missing inner hits"),
91  # Cluster-related
92  energyErr = Var("p4Error('P4_COMBINATION')",float,doc="energy error of the cluster-track combination",precision=6),
93  deltaEtaSC = Var("superCluster().eta()-eta()",float,doc="delta eta (SC,ele) with sign",precision=10),
94  r9 = Var("full5x5_r9()",float,doc="R9 of the SC, calculated with full 5x5 region",precision=10),
95  sieie = Var("full5x5_sigmaIetaIeta()",float,doc="sigma_IetaIeta of the SC, calculated with full 5x5 region",precision=10),
96  eInvMinusPInv = Var("(1-eSuperClusterOverP())/ecalEnergy()",float,doc="1/E_SC - 1/p_trk",precision=10),
97  scEtOverPt = Var("(superCluster().energy()/(pt*cosh(superCluster().eta())))-1",float,doc="(SC energy)/pt-1",precision=8),
98  hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8),
99  # Displacement
100  dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10),
101  dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6),
102  dz = Var("dB('PVDZ')",float,doc="dz (with sign) wrt first PV, in cm",precision=10),
103  dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6),
104  # Cross-referencing
105  #jetIdx
106  #photonIdx
107  ),
108 )
109 
110 
113 
114 # Depends on tautaggerForMatching being run in electrons_cff
115 matchingLowPtElecPhoton = cms.EDProducer(
116  "GenJetGenPartMerger",
117  srcJet =cms.InputTag("particleLevel:leptons"),
118  srcPart=cms.InputTag("particleLevel:photons"),
119  cut = cms.string(""),
120  hasTauAnc=cms.InputTag("tautaggerForMatching"),
121 )
122 
123 lowPtElectronsMCMatchForTableAlt = cms.EDProducer(
124  "GenJetMatcherDRPtByDR", # cut on deltaR, deltaPt/Pt; pick best by deltaR
125  src = lowPtElectronTable.src, # final reco collection
126  matched = cms.InputTag("matchingLowPtElecPhoton:merged"), # final mc-truth particle collection
127  mcPdgId = cms.vint32(11,22), # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
128  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
129  mcStatus = cms.vint32(),
130  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
131  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
132  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
133  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
134 )
135 
136 lowPtElectronsMCMatchForTable = cms.EDProducer(
137  "MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
138  src = lowPtElectronTable.src, # final reco collection
139  matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
140  mcPdgId = cms.vint32(11), # one or more PDG ID (11 = ele); absolute values (see below)
141  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
142  mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
143  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
144  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
145  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
146  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
147 )
148 
149 from PhysicsTools.NanoAOD.electrons_cff import electronMCTable
150 lowPtElectronMCTable = cms.EDProducer(
151  "CandMCMatchTableProducer",
152  src = lowPtElectronTable.src,
153  mcMapDressedLep = cms.InputTag("lowPtElectronsMCMatchForTableAlt"),
154  mcMap = cms.InputTag("lowPtElectronsMCMatchForTable"),
155  mapTauAnc = cms.InputTag("matchingLowPtElecPhoton:hasTauAnc"),
156  objName = lowPtElectronTable.name,
157  objType = electronMCTable.objType,
158  branchName = cms.string("genPart"),
159  docString = cms.string("MC matching to status==1 electrons or photons"),
160  genparticles = cms.InputTag("finalGenParticles"),
161 )
162 
163 
166 
167 lowPtElectronTask = cms.Task(modifiedLowPtElectrons,
168  updatedLowPtElectrons,
169  isoForLowPtEle,
170  updatedLowPtElectronsWithUserData,
171  finalLowPtElectrons)
172 
173 lowPtElectronTablesTask = cms.Task(lowPtElectronTable)
174 
175 lowPtElectronMCTask = cms.Task(
176  matchingLowPtElecPhoton,
177  lowPtElectronsMCMatchForTable,
178  lowPtElectronsMCMatchForTableAlt,
179  lowPtElectronMCTable)
180 
181 
184 
185 _modifiers = ( run2_miniAOD_80XLegacy |
186  run2_nanoAOD_94XMiniAODv1 |
187  run2_nanoAOD_94XMiniAODv2 |
188  run2_nanoAOD_94X2016 |
189  run2_nanoAOD_102Xv1 |
190  run2_nanoAOD_106Xv1 )
191 (_modifiers).toReplaceWith(lowPtElectronTask,cms.Task())
192 (_modifiers).toReplaceWith(lowPtElectronTablesTask,cms.Task())
193 (_modifiers).toReplaceWith(lowPtElectronMCTask,cms.Task())
194 
195 # To preserve "nano v9" functionality ...
196 
197 from RecoEgamma.EgammaElectronProducers.lowPtGsfElectrons_cfi import lowPtRegressionModifier
198 run2_nanoAOD_106Xv2.toModify(modifiedLowPtElectrons.modifierConfig,
199  modifications = cms.VPSet(lowPtElectronModifier,
200  lowPtRegressionModifier))
201 
202 run2_nanoAOD_106Xv2.toModify(updatedLowPtElectronsWithUserData.userFloats,
203  ID = cms.InputTag("lowPtPATElectronID"))
204 
205 run2_nanoAOD_106Xv2.toModify(finalLowPtElectrons,
206  cut = "pt > 1. && userFloat('ID') > -0.25")
207 
208 run2_nanoAOD_106Xv2.toModify(lowPtElectronTable.variables,
209  embeddedID = Var("electronID('ID')",float,doc="ID, BDT (raw) score"),
210  ID = Var("userFloat('ID')",float,doc="New ID, BDT (raw) score"))
211 
212 from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronID_cfi import lowPtGsfElectronID
213 lowPtPATElectronID = lowPtGsfElectronID.clone(
214  usePAT = True,
215  electrons = "updatedLowPtElectrons",
216  unbiased = "",
217  ModelWeights = [
218  'RecoEgamma/ElectronIdentification/data/LowPtElectrons/LowPtElectrons_ID_2020Nov28.root',
219  ],
220 )
221 
222 _lowPtElectronTask = cms.Task(lowPtPATElectronID)
223 _lowPtElectronTask.add(lowPtElectronTask.copy())
224 run2_nanoAOD_106Xv2.toReplaceWith(lowPtElectronTask,_lowPtElectronTask)
def Var(expr, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
Definition: common_cff.py:20