CMS 3D CMS Logo

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