Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:16:09

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