Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-09 00:51:19

0001 import FWCore.ParameterSet.Config as cms
0002 from PhysicsTools.NanoAOD.nano_eras_cff import *
0003 from PhysicsTools.NanoAOD.common_cff import *
0004 
0005 from math import ceil,log
0006 
0007 
0008 photon_id_modules_WorkingPoints_nanoAOD = cms.PSet(
0009     modules = cms.vstring(
0010         'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_TrueVtx_cff',
0011         'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff',
0012         'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1p1_cff',
0013         'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff',
0014         'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff',
0015         'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff',
0016    ),
0017    WorkingPoints = cms.vstring(
0018     "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-loose",
0019     "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-medium",
0020     "egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-tight",
0021    )
0022 )
0023 photon_id_modules_WorkingPoints_nanoAOD_Spring16V2p2 = cms.PSet(
0024     modules = photon_id_modules_WorkingPoints_nanoAOD.modules,
0025    WorkingPoints = cms.vstring(
0026     "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose",
0027     "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium",
0028     "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight",
0029    )
0030 )
0031 
0032 def make_bitmapVID_docstring(id_modules_working_points_pset):
0033     pset = id_modules_working_points_pset
0034 
0035     for modname in pset.modules:
0036         ids = __import__(modname, globals(), locals(), ['idName','cutFlow'])
0037         for name in dir(ids):
0038             _id = getattr(ids,name)
0039             if hasattr(_id,'idName') and hasattr(_id,'cutFlow'):
0040                 if (len(pset.WorkingPoints)>0 and _id.idName == pset.WorkingPoints[0].split(':')[-1]):
0041                     cut_names = ','.join([cut.cutName.value() for cut in _id.cutFlow])
0042                     n_bits_per_cut = int(ceil(log(len(pset.WorkingPoints)+1,2)))
0043                     return 'VID compressed bitmap (%s), %d bits per cut'%(cut_names, n_bits_per_cut)
0044     raise ValueError("Something is wrong in the photon ID modules parameter set!")
0045 
0046 bitmapVIDForPho = cms.EDProducer("PhoVIDNestedWPBitmapProducer",
0047     src = cms.InputTag("slimmedPhotons"),
0048     WorkingPoints = photon_id_modules_WorkingPoints_nanoAOD.WorkingPoints,
0049 )
0050 
0051 bitmapVIDForPhoSpring16V2p2 = cms.EDProducer("PhoVIDNestedWPBitmapProducer",
0052     src = cms.InputTag("slimmedPhotons"),
0053     WorkingPoints = photon_id_modules_WorkingPoints_nanoAOD_Spring16V2p2.WorkingPoints,
0054 )
0055 
0056 isoForPho = cms.EDProducer("PhoIsoValueMapProducer",
0057     src = cms.InputTag("slimmedPhotons"),
0058     relative = cms.bool(False),
0059     rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"),
0060     mapIsoChg = cms.InputTag("photonIDValueMapProducer:phoChargedIsolation"),
0061     mapIsoNeu = cms.InputTag("photonIDValueMapProducer:phoNeutralHadronIsolation"),
0062     mapIsoPho = cms.InputTag("photonIDValueMapProducer:phoPhotonIsolation"),
0063     EAFile_PFIso_Chg = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt"),
0064     EAFile_PFIso_Neu = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt"),
0065     EAFile_PFIso_Pho = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt"),
0066 )
0067 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
0068     modifier.toModify(isoForPho,
0069         EAFile_PFIso_Chg = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfChargedHadrons_90percentBased.txt"),
0070         EAFile_PFIso_Neu = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased.txt"),
0071         EAFile_PFIso_Pho = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfPhotons_90percentBased.txt"),
0072     )
0073 
0074 seedGainPho = cms.EDProducer("PhotonSeedGainProducer", src = cms.InputTag("slimmedPhotons"))
0075 
0076 import RecoEgamma.EgammaTools.calibratedEgammas_cff
0077 
0078 calibratedPatPhotonsNano = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatPhotons.clone(
0079     produceCalibratedObjs = False,
0080     correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_preVFP_RunFineEtaR9Gain"),
0081 )
0082 
0083 (run2_egamma_2016 & tracker_apv_vfp30_2016).toModify(calibratedPatPhotonsNano,
0084     correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_preVFP_RunFineEtaR9Gain")
0085 )
0086 
0087 (run2_egamma_2016 & ~tracker_apv_vfp30_2016).toModify(calibratedPatPhotonsNano,
0088     correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_postVFP_RunFineEtaR9Gain"),
0089 )
0090 
0091 run2_egamma_2017.toModify(calibratedPatPhotonsNano,
0092     correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_24Feb2020_runEtaR9Gain_v2")
0093 )
0094 
0095 run2_egamma_2018.toModify(calibratedPatPhotonsNano,
0096     correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2018_29Sep2020_RunFineEtaR9Gain")
0097 )
0098 
0099 run2_nanoAOD_102Xv1.toModify(calibratedPatPhotonsNano,
0100     correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2018_Step2Closure_CoarseEtaR9Gain_v2")
0101 )
0102 
0103 run2_nanoAOD_94XMiniAODv1.toModify(calibratedPatPhotonsNano,
0104     correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_17Nov2017_v1_ele_unc")
0105 )
0106 
0107 run2_nanoAOD_94XMiniAODv2.toModify(calibratedPatPhotonsNano,
0108     correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_17Nov2017_v1_ele_unc")
0109 )
0110 
0111 
0112 run2_miniAOD_80XLegacy.toModify(calibratedPatPhotonsNano,
0113                                 correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Legacy2016_07Aug2017_FineEtaR9_v3_ele_unc")
0114 )
0115 
0116 
0117 slimmedPhotonsWithUserData = cms.EDProducer("PATPhotonUserDataEmbedder",
0118     src = cms.InputTag("slimmedPhotons"),
0119     userFloats = cms.PSet(
0120         mvaID = cms.InputTag("photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v2Values"),
0121         PFIsoChg = cms.InputTag("isoForPho:PFIsoChg"),
0122         PFIsoAll = cms.InputTag("isoForPho:PFIsoAll"),
0123     ),
0124     userIntFromBools = cms.PSet(
0125         cutbasedID_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-loose"),
0126         cutbasedID_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-medium"),
0127         cutbasedID_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-tight"),
0128         mvaID_WP90 = cms.InputTag("egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp90"),
0129         mvaID_WP80 = cms.InputTag("egmPhotonIDs:mvaPhoID-RunIIFall17-v2-wp80"),
0130         cutbasedIDV1_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-loose"),
0131         cutbasedIDV1_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-medium"),
0132         cutbasedIDV1_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-tight"),
0133     ),
0134     userInts = cms.PSet(
0135         VIDNestedWPBitmap = cms.InputTag("bitmapVIDForPho"),
0136         seedGain = cms.InputTag("seedGainPho"),
0137     )
0138 )
0139 
0140 
0141 for modifier in run2_egamma_2016, run2_egamma_2017, run2_egamma_2018:
0142     modifier.toModify(slimmedPhotonsWithUserData.userFloats,
0143                       ecalEnergyErrPostCorrNew = cms.InputTag("calibratedPatPhotonsNano","ecalEnergyErrPostCorr"),
0144                       ecalEnergyPreCorrNew     = cms.InputTag("calibratedPatPhotonsNano","ecalEnergyPreCorr"),
0145                       ecalEnergyPostCorrNew    = cms.InputTag("calibratedPatPhotonsNano","ecalEnergyPostCorr"),
0146                       energyScaleUpNew            = cms.InputTag("calibratedPatPhotonsNano","energyScaleUp"),
0147                       energyScaleDownNew          = cms.InputTag("calibratedPatPhotonsNano","energyScaleDown"),
0148                       energySigmaUpNew            = cms.InputTag("calibratedPatPhotonsNano","energySigmaUp"),
0149                       energySigmaDownNew          = cms.InputTag("calibratedPatPhotonsNano","energySigmaDown"),
0150                   )
0151 
0152 
0153 run2_nanoAOD_94X2016.toModify(slimmedPhotonsWithUserData.userFloats,
0154                       ecalEnergyErrPostCorrNew = None,
0155                       ecalEnergyPreCorrNew     = None,
0156                       ecalEnergyPostCorrNew    = None,
0157                       energyScaleUpNew            = None,
0158                       energyScaleDownNew          = None,
0159                       energySigmaUpNew            = None,
0160                       energySigmaDownNew          = None
0161                   )
0162 
0163 
0164 finalPhotons = cms.EDFilter("PATPhotonRefSelector",
0165     src = cms.InputTag("slimmedPhotonsWithUserData"),
0166     cut = cms.string("pt > 5 ")
0167 )
0168 
0169 photonTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
0170     src = cms.InputTag("linkedObjects","photons"),
0171     cut = cms.string(""), #we should not filter on cross linked collections
0172     name= cms.string("Photon"),
0173     doc = cms.string("slimmedPhotons after basic selection (" + finalPhotons.cut.value()+")"),
0174     singleton = cms.bool(False), # the number of entries is variable
0175     extension = cms.bool(False), # this is the main table for the photons
0176     variables = cms.PSet(P3Vars,
0177         jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"),
0178         electronIdx = Var("?hasUserCand('electron')?userCand('electron').key():-1", int, doc="index of the associated electron (-1 if none)"),
0179         energyErr = Var("getCorrectedEnergyError('regression2')",float,doc="energy error of the cluster from regression",precision=6),
0180         energyRaw = Var("superCluster().rawEnergy()",float,doc="raw energy of photon supercluster", precision=10),
0181         r9 = Var("full5x5_r9()",float,doc="R9 of the supercluster, calculated with full 5x5 region",precision=8),
0182         sieie = Var("full5x5_sigmaIetaIeta()",float,doc="sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=8),
0183         sipip = Var("showerShapeVariables().sigmaIphiIphi", float, doc="sigmaIphiIphi of the supercluster", precision=8),
0184         sieip = Var("full5x5_showerShapeVariables().sigmaIetaIphi",float,doc="sigma_IetaIphi of the supercluster, calculated with full 5x5 region",precision=8),
0185         s4 = Var("full5x5_showerShapeVariables().e2x2/full5x5_showerShapeVariables().e5x5",float,doc="e2x2/e5x5 of the supercluster, calculated with full 5x5 region",precision=8),
0186         etaWidth = Var("superCluster().etaWidth()",float,doc="Width of the photon supercluster in eta", precision=8),
0187         phiWidth = Var("superCluster().phiWidth()",float,doc="Width of the photon supercluster in phi", precision=8),
0188         cutBased = Var(
0189             "userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",
0190             int,
0191             doc="cut-based ID bitmap, Fall17V2, (0:fail, 1:loose, 2:medium, 3:tight)",
0192         ),
0193         cutBased_Fall17V1Bitmap = Var(
0194             "userInt('cutbasedIDV1_loose')+2*userInt('cutbasedIDV1_medium')+4*userInt('cutbasedIDV1_tight')",
0195             int,
0196             doc="cut-based ID bitmap, Fall17V1, 2^(0:loose, 1:medium, 2:tight).",
0197         ),
0198         vidNestedWPBitmap = Var(
0199             "userInt('VIDNestedWPBitmap')",
0200             int,
0201             doc="Fall17V2 " + make_bitmapVID_docstring(photon_id_modules_WorkingPoints_nanoAOD),
0202         ),
0203         electronVeto = Var("passElectronVeto()",bool,doc="pass electron veto"),
0204         pixelSeed = Var("hasPixelSeed()",bool,doc="has pixel seed"),
0205         mvaID = Var("userFloat('mvaID')",float,doc="MVA ID score, Fall17V2",precision=10),
0206         mvaID_WP90 = Var("userInt('mvaID_WP90')",bool,doc="MVA ID WP90, Fall17V2"),
0207         mvaID_WP80 = Var("userInt('mvaID_WP80')",bool,doc="MVA ID WP80, Fall17V2"),
0208         pfPhoIso03 = Var("photonIso()",float,doc="PF absolute isolation dR=0.3, photon component (uncorrected)"),
0209         pfChargedIsoPFPV = Var("chargedHadronPFPVIso()",float,doc="PF absolute isolation dR=0.3, charged component (PF PV only)"),
0210         pfChargedIsoWorstVtx = Var("chargedHadronWorstVtxIso()",float,doc="PF absolute isolation dR=0.3, charged component (Vertex with largest isolation)"),
0211         pfRelIso03_chg = Var("userFloat('PFIsoChg')/pt",float,doc="PF relative isolation dR=0.3, charged component (with rho*EA PU corrections)"),
0212         pfRelIso03_all = Var("userFloat('PFIsoAll')/pt",float,doc="PF relative isolation dR=0.3, total (with rho*EA PU corrections)"),
0213         hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8),
0214         isScEtaEB = Var("abs(superCluster().eta()) < 1.4442",bool,doc="is supercluster eta within barrel acceptance"),
0215         isScEtaEE = Var("abs(superCluster().eta()) > 1.566 && abs(superCluster().eta()) < 2.5",bool,doc="is supercluster eta within endcap acceptance"),
0216         seedGain = Var("userInt('seedGain')","uint8",doc="Gain of the seed crystal"),
0217         # position of photon is best approximated by position of seed cluster, not the SC centroid
0218         x_calo = Var("superCluster().seed().position().x()",float,doc="photon supercluster position on calorimeter, x coordinate (cm)",precision=10),
0219         y_calo = Var("superCluster().seed().position().y()",float,doc="photon supercluster position on calorimeter, y coordinate (cm)",precision=10),
0220         z_calo = Var("superCluster().seed().position().z()",float,doc="photon supercluster position on calorimeter, z coordinate (cm)",precision=10),
0221         # ES variables
0222         esEffSigmaRR = Var("full5x5_showerShapeVariables().effSigmaRR()", float, doc="preshower sigmaRR"),
0223         esEnergyOverRawE = Var("superCluster().preshowerEnergy()/superCluster().rawEnergy()", float, doc="ratio of preshower energy to raw supercluster energy"),
0224     )
0225 )
0226 
0227 
0228 #these eras need to make the energy correction, hence the "New"
0229 for modifier in run2_egamma_2016, run2_egamma_2017, run2_egamma_2018 :
0230     modifier.toModify(photonTable.variables,
0231         pt = Var("pt*userFloat('ecalEnergyPostCorrNew')/userFloat('ecalEnergyPreCorrNew')", float, precision=-1, doc="p_{T}"),
0232         energyErr = Var("userFloat('ecalEnergyErrPostCorrNew')",float,doc="energy error of the cluster from regression",precision=6),
0233         eCorr = Var("userFloat('ecalEnergyPostCorrNew')/userFloat('ecalEnergyPreCorrNew')",float,doc="ratio of the calibrated energy/miniaod energy"),
0234         hoe = Var("hadTowOverEm()",float,doc="H over E (Run2)",precision=8),
0235     )
0236 
0237 #these eras have the energy correction in the mini
0238 for modifier in run2_nanoAOD_94X2016,:
0239     modifier.toModify(photonTable.variables,
0240         pt = Var("pt*userFloat('ecalEnergyPostCorr')/userFloat('ecalEnergyPreCorr')", float, precision=-1, doc="p_{T}"),
0241         energyErr = Var("userFloat('ecalEnergyErrPostCorr')",float,doc="energy error of the cluster from regression",precision=6),
0242         eCorr = Var("userFloat('ecalEnergyPostCorr')/userFloat('ecalEnergyPreCorr')",float,doc="ratio of the calibrated energy/miniaod energy"),
0243                       
0244     )
0245 
0246 for modifier in run2_nanoAOD_94X2016, run2_miniAOD_80XLegacy:
0247     modifier.toModify(slimmedPhotonsWithUserData.userFloats,
0248         mvaID_Spring16nonTrigV1 = cms.InputTag("photonMVAValueMapProducer:PhotonMVAEstimatorRun2Spring16NonTrigV1Values"),
0249                   )
0250     modifier.toModify(slimmedPhotonsWithUserData.userIntFromBools,
0251         cutID_Spring16_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose"),
0252         cutID_Spring16_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium"),
0253         cutID_Spring16_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight"),
0254         mvaID_Spring16nonTrigV1_WP90 = cms.InputTag("egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp90"),
0255         mvaID_Spring16nonTrigV1_WP80 = cms.InputTag("egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp80"),
0256 
0257     )
0258     modifier.toModify(slimmedPhotonsWithUserData.userInts,
0259         VIDNestedWPBitmap_Spring16V2p2 = cms.InputTag("bitmapVIDForPhoSpring16V2p2"),
0260     )
0261 
0262 for modifier in run2_nanoAOD_94X2016, run2_miniAOD_80XLegacy:
0263    modifier.toModify(photonTable.variables,
0264         cutBased_Spring16V2p2 = Var(
0265             "userInt('cutID_Spring16_loose')+userInt('cutID_Spring16_medium')+userInt('cutID_Spring16_tight')",
0266             int,
0267             doc="cut-based ID bitmap, Spring16V2p2, (0:fail, 1:loose, 2:medium, 3:tight)"
0268         ),
0269         vidNestedWPBitmap_Spring16V2p2 = Var(
0270             "userInt('VIDNestedWPBitmap_Spring16V2p2')",
0271             int,
0272             doc="Spring16V2p2 " + make_bitmapVID_docstring(photon_id_modules_WorkingPoints_nanoAOD_Spring16V2p2)
0273         ),
0274         mvaID_Spring16nonTrigV1 = Var(
0275             "userFloat('mvaID_Spring16nonTrigV1')",
0276             float,
0277             doc="MVA ID score, Spring16nonTrigV1",
0278             precision=10
0279         ),
0280     )
0281 
0282 photonsMCMatchForTable = cms.EDProducer("MCMatcher",  # cut on deltaR, deltaPt/Pt; pick best by deltaR
0283     src         = photonTable.src,                 # final reco collection
0284     matched     = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
0285     mcPdgId     = cms.vint32(11,22),                 # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
0286     checkCharge = cms.bool(False),              # True = require RECO and MC objects to have the same charge
0287     mcStatus    = cms.vint32(1),                # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
0288     maxDeltaR   = cms.double(0.3),              # Minimum deltaR for the match
0289     maxDPtRel   = cms.double(0.5),              # Minimum deltaPt/Pt for the match
0290     resolveAmbiguities    = cms.bool(True),     # Forbid two RECO objects to match to the same GEN object
0291     resolveByMatchQuality = cms.bool(True),    # False = just match input in order; True = pick lowest deltaR pair first
0292 )
0293 
0294 photonMCTable = cms.EDProducer("CandMCMatchTableProducer",
0295     src     = photonTable.src,
0296     mcMap   = cms.InputTag("photonsMCMatchForTable"),
0297     objName = photonTable.name,
0298     objType = photonTable.name, #cms.string("Photon"),
0299     branchName = cms.string("genPart"),
0300     docString = cms.string("MC matching to status==1 photons or electrons"),
0301 )
0302 
0303 from RecoEgamma.EgammaTools.egammaObjectModificationsInMiniAOD_cff import egamma8XObjectUpdateModifier,egamma9X105XUpdateModifier,prependEgamma8XObjectUpdateModifier
0304 #we have dataformat changes to 106X so to read older releases we use egamma updators
0305 slimmedPhotonsTo106X = cms.EDProducer("ModifiedPhotonProducer",
0306     src = cms.InputTag("slimmedPhotons"),
0307     modifierConfig = cms.PSet( modifications = cms.VPSet(egamma9X105XUpdateModifier) )
0308 )
0309 #might as well fix 80X while we're at it although the differences are not so relavent for nano
0310 run2_miniAOD_80XLegacy.toModify( slimmedPhotonsTo106X.modifierConfig.modifications, prependEgamma8XObjectUpdateModifier )
0311 
0312 for modifier in run2_miniAOD_80XLegacy,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_94X2016 ,run2_nanoAOD_102Xv1:
0313     modifier.toModify(bitmapVIDForPho, src = "slimmedPhotonsTo106X")
0314     modifier.toModify(bitmapVIDForPhoSpring16V2p2, src = "slimmedPhotonsTo106X")
0315     modifier.toModify(isoForPho, src = "slimmedPhotonsTo106X")
0316     modifier.toModify(calibratedPatPhotonsNano, src = "slimmedPhotonsTo106X")
0317     modifier.toModify(slimmedPhotonsWithUserData, src = "slimmedPhotonsTo106X")
0318     modifier.toModify(seedGainPho, src = "slimmedPhotonsTo106X")
0319 
0320 
0321 ##adding 4 most imp scale & smearing variables to table
0322 for modifier in run2_egamma_2016, run2_egamma_2017, run2_egamma_2018:
0323     modifier.toModify(photonTable.variables,
0324                       dEscaleUp=Var("userFloat('ecalEnergyPostCorrNew') - userFloat('energyScaleUpNew')", float, doc="ecal energy scale shifted 1 sigma up (adding gain/stat/syst in quadrature)", precision=8),
0325                       dEscaleDown=Var("userFloat('ecalEnergyPostCorrNew') - userFloat('energyScaleDownNew')", float, doc="ecal energy scale shifted 1 sigma down (adding gain/stat/syst in quadrature)", precision=8),
0326                       dEsigmaUp=Var("userFloat('ecalEnergyPostCorrNew') - userFloat('energySigmaUpNew')", float, doc="ecal energy smearing value shifted 1 sigma up", precision=8),
0327                       dEsigmaDown=Var("userFloat('ecalEnergyPostCorrNew') - userFloat('energySigmaDownNew')", float, doc="ecal energy smearing value shifted 1 sigma up", precision=8),
0328     )
0329 
0330 for modifier in run2_nanoAOD_94X2016,:
0331     modifier.toModify(photonTable.variables,
0332                       dEscaleUp=Var("userFloat('ecalEnergyPostCorr') - userFloat('energyScaleUp')", float,  doc="ecal energy scale shifted 1 sigma up (adding gain/stat/syst in quadrature)", precision=8),
0333                       dEscaleDown=Var("userFloat('ecalEnergyPostCorr') - userFloat('energyScaleDown')", float,  doc="ecal energy scale shifted 1 sigma down (adding gain/stat/syst in quadrature)", precision=8),
0334                       dEsigmaUp=Var("userFloat('ecalEnergyPostCorr') - userFloat('energySigmaUp')", float, doc="ecal energy smearing value shifted 1 sigma up", precision=8),
0335                       dEsigmaDown=Var("userFloat('ecalEnergyPostCorr') - userFloat('energySigmaDown')", float,  doc="ecal energy smearing value shifted 1 sigma up", precision=8),
0336     )
0337 
0338 photonTask = cms.Task(bitmapVIDForPho, isoForPho, seedGainPho, calibratedPatPhotonsNano, slimmedPhotonsWithUserData, finalPhotons)
0339 photonTablesTask = cms.Task(photonTable)
0340 photonMCTask = cms.Task(photonsMCMatchForTable, photonMCTable)
0341 
0342 
0343 ## TEMPORARY as no ID for Run3 yet
0344 (run3_nanoAOD_devel).toReplaceWith(photonTask, photonTask.copyAndExclude([bitmapVIDForPho]))
0345 (run3_nanoAOD_devel).toModify(slimmedPhotonsWithUserData, userIntFromBools = cms.PSet())
0346 (run3_nanoAOD_devel).toModify(slimmedPhotonsWithUserData.userInts,
0347                               VIDNestedWPBitmap = None,)
0348 (run3_nanoAOD_devel).toModify(slimmedPhotonsWithUserData.userFloats,
0349                               mvaID = None)
0350 (run3_nanoAOD_devel).toModify(photonTable.variables,
0351                               cutBased = None,
0352                               cutBased_Fall17V1Bitmap = None,
0353                               vidNestedWPBitmap = None,
0354                               mvaID = None,
0355                               mvaID_WP90 = None,
0356                               mvaID_WP80 = None,
0357 )
0358 #### end TEMPORARY Run3
0359 
0360 from RecoEgamma.EgammaIsolationAlgos.egmPhotonIsolationMiniAOD_cff import egmPhotonIsolation
0361 from RecoEgamma.PhotonIdentification.photonIDValueMapProducer_cff import photonIDValueMapProducer
0362 
0363 _withUpdatePho_Task = cms.Task(egmPhotonIsolation,photonIDValueMapProducer,slimmedPhotonsTo106X)
0364 _withUpdatePho_Task.add(photonTask.copy())
0365 
0366 for modifier in run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_94X2016 ,run2_nanoAOD_102Xv1,run2_nanoAOD_94XMiniAODv1:
0367     modifier.toReplaceWith(photonTask, _withUpdatePho_Task)
0368 
0369 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
0370     _withSpring16V2p2_Task = cms.Task(bitmapVIDForPhoSpring16V2p2)
0371     _withSpring16V2p2_Task.add(_withUpdatePho_Task.copy())
0372     modifier.toReplaceWith(photonTask, _withSpring16V2p2_Task)