Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-18 03:27:25

0001 import FWCore.ParameterSet.Config as cms
0002 from PhysicsTools.NanoAOD.nano_eras_cff import *
0003 from PhysicsTools.NanoAOD.common_cff import *
0004 
0005 ################################################################################
0006 # Modules
0007 ################################################################################
0008 
0009 from RecoEgamma.EgammaTools.lowPtElectronModifier_cfi import lowPtElectronModifier
0010 modifiedLowPtElectrons = cms.EDProducer(
0011     "ModifiedElectronProducer",
0012     src = cms.InputTag("slimmedLowPtElectrons"),
0013     modifierConfig = cms.PSet(
0014         modifications = cms.VPSet(lowPtElectronModifier)
0015     )
0016 )
0017 
0018 import PhysicsTools.PatAlgos.producersLayer1.electronProducer_cfi
0019 updatedLowPtElectrons = cms.EDProducer(
0020     "PATElectronUpdater",
0021     src = cms.InputTag("modifiedLowPtElectrons"),
0022     vertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
0023     computeMiniIso = cms.bool(True),
0024     fixDxySign = cms.bool(False),
0025     pfCandsForMiniIso = cms.InputTag("packedPFCandidates"),
0026     miniIsoParamsB = PhysicsTools.PatAlgos.producersLayer1.electronProducer_cfi.patElectrons.miniIsoParamsB,
0027     miniIsoParamsE = PhysicsTools.PatAlgos.producersLayer1.electronProducer_cfi.patElectrons.miniIsoParamsE,
0028 )
0029 
0030 isoForLowPtEle = cms.EDProducer(
0031     "EleIsoValueMapProducer",
0032     src = cms.InputTag("updatedLowPtElectrons"),
0033     relative = cms.bool(True),
0034     rho_MiniIso = cms.InputTag("fixedGridRhoFastjetAll"),
0035     rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"),
0036     EAFile_MiniIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Fall17/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
0037     EAFile_PFIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Fall17/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
0038 )
0039 
0040 updatedLowPtElectronsWithUserData = cms.EDProducer(
0041     "PATElectronUserDataEmbedder",
0042     src = cms.InputTag("updatedLowPtElectrons"),
0043     userFloats = cms.PSet(
0044         miniIsoChg = cms.InputTag("isoForLowPtEle:miniIsoChg"),
0045         miniIsoAll = cms.InputTag("isoForLowPtEle:miniIsoAll"),
0046     ),
0047     userIntFromBools = cms.PSet(),
0048     userInts = cms.PSet(),
0049     userCands = cms.PSet(),
0050 )
0051 
0052 finalLowPtElectrons = cms.EDFilter(
0053     "PATElectronRefSelector",
0054     src = cms.InputTag("updatedLowPtElectronsWithUserData"),
0055     cut = cms.string("pt > 1. && electronID('ID') > -0.25"),
0056 )
0057 
0058 ################################################################################
0059 # electronTable 
0060 ################################################################################
0061 
0062 lowPtElectronTable = cms.EDProducer(
0063     "SimpleCandidateFlatTableProducer",
0064     src = cms.InputTag("linkedObjects","lowPtElectrons"),
0065     cut = cms.string(""),
0066     name= cms.string("LowPtElectron"),
0067     doc = cms.string("slimmedLowPtElectrons after basic selection (" + finalLowPtElectrons.cut.value()+")"),
0068     singleton = cms.bool(False), # the number of entries is variable
0069     extension = cms.bool(False), # this is the main table for the electrons
0070     variables = cms.PSet(
0071         # Basic variables
0072         CandVars,
0073         # Overlaps with PF electron
0074         electronIdx = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", int, doc="index of the overlapping PF electron (-1 if none)"),
0075         # BDT scores and WPs
0076         ID = Var("electronID('ID')",float,doc="ID, BDT (raw) score"),
0077         unbiased = Var("electronID('unbiased')",float,doc="ElectronSeed, pT- and dxy- agnostic BDT (raw) score"),
0078         ptbiased = Var("electronID('ptbiased')",float,doc="ElectronSeed, pT- and dxy- dependent BDT (raw) score"),
0079         # Isolation
0080         miniPFRelIso_chg = Var("userFloat('miniIsoChg')",float,
0081                                doc="mini PF relative isolation, charged component"),
0082         miniPFRelIso_all = Var("userFloat('miniIsoAll')",float,
0083                                doc="mini PF relative isolation, total (with scaled rho*EA PU corrections)"),
0084         # Conversions
0085         convVeto = Var("passConversionVeto()",bool,doc="pass conversion veto"),
0086         convWP = Var("userInt('convOpen')*1 + userInt('convLoose')*2 + userInt('convTight')*4",
0087                      int,doc="conversion flag bit map: 1=Veto, 2=Loose, 3=Tight"),
0088         convVtxRadius = Var("userFloat('convVtxRadius')",float,doc="conversion vertex radius (cm)",precision=7),
0089         # Tracking
0090         lostHits = Var("gsfTrack.hitPattern.numberOfLostHits('MISSING_INNER_HITS')","uint8",doc="number of missing inner hits"),
0091         # Cluster-related
0092         energyErr = Var("p4Error('P4_COMBINATION')",float,doc="energy error of the cluster-track combination",precision=6),
0093         deltaEtaSC = Var("superCluster().eta()-eta()",float,doc="delta eta (SC,ele) with sign",precision=10),
0094         r9 = Var("full5x5_r9()",float,doc="R9 of the SC, calculated with full 5x5 region",precision=10),
0095         sieie = Var("full5x5_sigmaIetaIeta()",float,doc="sigma_IetaIeta of the SC, calculated with full 5x5 region",precision=10),
0096         eInvMinusPInv = Var("(1-eSuperClusterOverP())/ecalEnergy()",float,doc="1/E_SC - 1/p_trk",precision=10),
0097         scEtOverPt = Var("(superCluster().energy()/(pt*cosh(superCluster().eta())))-1",float,doc="(SC energy)/pt-1",precision=8),
0098         hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8),
0099         # Displacement
0100         dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10),
0101         dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6),
0102         dz = Var("dB('PVDZ')",float,doc="dz (with sign) wrt first PV, in cm",precision=10),
0103         dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6),
0104         # Cross-referencing
0105         #jetIdx
0106         #photonIdx
0107     ),
0108 )
0109 
0110 ################################################################################
0111 # electronTable (MC)
0112 ################################################################################
0113 
0114 # Depends on tautaggerForMatching being run in electrons_cff
0115 matchingLowPtElecPhoton = cms.EDProducer(
0116     "GenJetGenPartMerger",
0117     srcJet =cms.InputTag("particleLevel:leptons"),
0118     srcPart=cms.InputTag("particleLevel:photons"),
0119     cut = cms.string(""),
0120     hasTauAnc=cms.InputTag("tautaggerForMatching"),
0121 )
0122 
0123 lowPtElectronsMCMatchForTableAlt = cms.EDProducer(
0124     "GenJetMatcherDRPtByDR",                # cut on deltaR, deltaPt/Pt; pick best by deltaR
0125     src         = lowPtElectronTable.src,   # final reco collection
0126     matched     = cms.InputTag("matchingLowPtElecPhoton:merged"), # final mc-truth particle collection
0127     mcPdgId     = cms.vint32(11,22),        # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
0128     checkCharge = cms.bool(False),          # True = require RECO and MC objects to have the same charge
0129     mcStatus    = cms.vint32(),
0130     maxDeltaR   = cms.double(0.3),          # Minimum deltaR for the match
0131     maxDPtRel   = cms.double(0.5),          # Minimum deltaPt/Pt for the match
0132     resolveAmbiguities    = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
0133     resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
0134 ) 
0135 
0136 lowPtElectronsMCMatchForTable = cms.EDProducer(
0137     "MCMatcher",                            # cut on deltaR, deltaPt/Pt; pick best by deltaR
0138     src         = lowPtElectronTable.src,   # final reco collection
0139     matched     = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
0140     mcPdgId     = cms.vint32(11),           # one or more PDG ID (11 = ele); absolute values (see below)
0141     checkCharge = cms.bool(False),          # True = require RECO and MC objects to have the same charge
0142     mcStatus    = cms.vint32(1),            # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
0143     maxDeltaR   = cms.double(0.3),          # Minimum deltaR for the match
0144     maxDPtRel   = cms.double(0.5),          # Minimum deltaPt/Pt for the match
0145     resolveAmbiguities    = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
0146     resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
0147 )
0148 
0149 from PhysicsTools.NanoAOD.electrons_cff import electronMCTable
0150 lowPtElectronMCTable = cms.EDProducer(
0151     "CandMCMatchTableProducer",
0152     src = lowPtElectronTable.src,
0153     mcMapDressedLep = cms.InputTag("lowPtElectronsMCMatchForTableAlt"),
0154     mcMap = cms.InputTag("lowPtElectronsMCMatchForTable"),
0155     mapTauAnc = cms.InputTag("matchingLowPtElecPhoton:hasTauAnc"),
0156     objName = lowPtElectronTable.name,
0157     objType = electronMCTable.objType,
0158     branchName = cms.string("genPart"),
0159     docString = cms.string("MC matching to status==1 electrons or photons"),
0160     genparticles = cms.InputTag("finalGenParticles"), 
0161 )
0162 
0163 ################################################################################
0164 # Tasks
0165 ################################################################################
0166 
0167 lowPtElectronTask = cms.Task(modifiedLowPtElectrons,
0168                              updatedLowPtElectrons,
0169                              isoForLowPtEle,
0170                              updatedLowPtElectronsWithUserData,
0171                              finalLowPtElectrons)
0172 
0173 lowPtElectronTablesTask = cms.Task(lowPtElectronTable)
0174 
0175 lowPtElectronMCTask = cms.Task(
0176     matchingLowPtElecPhoton,
0177     lowPtElectronsMCMatchForTable,
0178     lowPtElectronsMCMatchForTableAlt,
0179     lowPtElectronMCTable)
0180 
0181 ################################################################################
0182 # Modifiers
0183 ################################################################################
0184 
0185 _modifiers = ( run2_miniAOD_80XLegacy |
0186                run2_nanoAOD_94XMiniAODv1 |
0187                run2_nanoAOD_94XMiniAODv2 |
0188                run2_nanoAOD_94X2016 |
0189                run2_nanoAOD_102Xv1 |
0190                run2_nanoAOD_106Xv1 )
0191 (_modifiers).toReplaceWith(lowPtElectronTask,cms.Task())
0192 (_modifiers).toReplaceWith(lowPtElectronTablesTask,cms.Task())
0193 (_modifiers).toReplaceWith(lowPtElectronMCTask,cms.Task())
0194 
0195 # To preserve "nano v9" functionality ...
0196 
0197 from RecoEgamma.EgammaElectronProducers.lowPtGsfElectrons_cfi import lowPtRegressionModifier
0198 run2_nanoAOD_106Xv2.toModify(modifiedLowPtElectrons.modifierConfig,
0199                              modifications = cms.VPSet(lowPtElectronModifier,
0200                                                        lowPtRegressionModifier))
0201 
0202 run2_nanoAOD_106Xv2.toModify(updatedLowPtElectronsWithUserData.userFloats,
0203                              ID = cms.InputTag("lowPtPATElectronID"))
0204 
0205 run2_nanoAOD_106Xv2.toModify(finalLowPtElectrons,
0206                              cut = "pt > 1. && userFloat('ID') > -0.25")
0207 
0208 run2_nanoAOD_106Xv2.toModify(lowPtElectronTable.variables,
0209                              embeddedID = Var("electronID('ID')",float,doc="ID, BDT (raw) score"),
0210                              ID = Var("userFloat('ID')",float,doc="New ID, BDT (raw) score"))
0211 
0212 from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronID_cfi import lowPtGsfElectronID
0213 lowPtPATElectronID = lowPtGsfElectronID.clone(
0214     usePAT = True,
0215     electrons = "updatedLowPtElectrons",
0216     unbiased = "",
0217     ModelWeights = [
0218         'RecoEgamma/ElectronIdentification/data/LowPtElectrons/LowPtElectrons_ID_2020Nov28.root',
0219     ],
0220 )
0221 
0222 _lowPtElectronTask = cms.Task(lowPtPATElectronID)
0223 _lowPtElectronTask.add(lowPtElectronTask.copy())
0224 run2_nanoAOD_106Xv2.toReplaceWith(lowPtElectronTask,_lowPtElectronTask)