Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-04 01:26:10

0001 import FWCore.ParameterSet.Config as cms
0002 from PhysicsTools.NanoAOD.nano_eras_cff import *
0003 from PhysicsTools.NanoAOD.common_cff import *
0004 import PhysicsTools.PatAlgos.producersLayer1.electronProducer_cfi
0005 from math import ceil,log
0006 #NOTE: All definitions of modules should point to the latest flavour of the electronTable in NanoAOD.
0007 #Common modifications for past eras are done at the end whereas modifications specific to a single era is done after the original definition.
0008 from RecoEgamma.EgammaTools.egammaObjectModificationsInMiniAOD_cff import egamma8XObjectUpdateModifier,egamma9X105XUpdateModifier,prependEgamma8XObjectUpdateModifier
0009 ele9X105XUpdateModifier=egamma9X105XUpdateModifier.clone(
0010     phoPhotonIso = "",
0011     phoNeutralHadIso = "",
0012     phoChargedHadIso = "",
0013     phoChargedHadWorstVtxIso = "",
0014     phoChargedHadWorstVtxConeVetoIso = "",
0015     phoChargedHadPFPVIso = ""
0016 )
0017 #we have dataformat changes to 106X so to read older releases we use egamma updators
0018 slimmedElectronsTo106X = cms.EDProducer("ModifiedElectronProducer",
0019     src = cms.InputTag("slimmedElectrons"),
0020     modifierConfig = cms.PSet( modifications = cms.VPSet(ele9X105XUpdateModifier) )
0021 )
0022 #might as well fix 80X while we're at it although the differences are not so relavent for nano
0023 run2_miniAOD_80XLegacy.toModify( slimmedElectronsTo106X.modifierConfig.modifications, prependEgamma8XObjectUpdateModifier )
0024 
0025 # this below is used only in some eras
0026 slimmedElectronsUpdated = cms.EDProducer("PATElectronUpdater",
0027     src = cms.InputTag("slimmedElectrons"),
0028     vertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
0029     computeMiniIso = cms.bool(False),
0030     fixDxySign = cms.bool(True),
0031     pfCandsForMiniIso = cms.InputTag("packedPFCandidates"),
0032     miniIsoParamsB = PhysicsTools.PatAlgos.producersLayer1.electronProducer_cfi.patElectrons.miniIsoParamsB, # so they're in sync
0033     miniIsoParamsE = PhysicsTools.PatAlgos.producersLayer1.electronProducer_cfi.patElectrons.miniIsoParamsE, # so they're in sync
0034 )
0035 run2_miniAOD_80XLegacy.toModify( slimmedElectronsUpdated, computeMiniIso = True )
0036 ##modify the past eras
0037 for modifier in run2_miniAOD_80XLegacy,run2_nanoAOD_94X2016,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_102Xv1:
0038     modifier.toModify(slimmedElectronsUpdated, src = cms.InputTag("slimmedElectronsTo106X"))
0039 ############################FOR bitmapVIDForEle main defn#############################
0040 electron_id_modules_WorkingPoints_nanoAOD = cms.PSet(
0041     modules = cms.vstring(
0042         'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V1_cff',
0043         'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V2_cff',
0044         'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff',
0045         'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V1_cff',
0046         'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V1_cff',
0047         'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff',
0048         'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff',
0049     ),
0050     WorkingPoints = cms.vstring(
0051         "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-veto",
0052         "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-loose",
0053         "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-medium",
0054         "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-tight",
0055     )
0056 )
0057 for modifier in run2_miniAOD_80XLegacy,run2_nanoAOD_94X2016:
0058     modifier.toModify(electron_id_modules_WorkingPoints_nanoAOD,
0059         modules = cms.vstring(
0060             'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V1_cff',
0061             'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V2_cff',
0062             'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV70_cff',
0063             'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V1_cff',
0064             'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V1_cff',
0065             'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff',
0066             'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff', 
0067             'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff',
0068             'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronHLTPreselecition_Summer16_V1_cff',
0069             'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Spring15_25ns_V1_cff',
0070             'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff',
0071             'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_HZZ_V1_cff',
0072             ),
0073         WorkingPoints = cms.vstring(
0074             "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-veto",
0075             "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-loose",
0076             "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-medium",
0077             "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-tight",
0078             )
0079 )
0080  
0081 def _get_bitmapVIDForEle_docstring(modules,WorkingPoints):
0082     docstring=''
0083     for modname in modules:
0084         ids= __import__(modname, globals(), locals(), ['idName','cutFlow'])
0085         for name in dir(ids):
0086             _id = getattr(ids,name)
0087             if hasattr(_id,'idName') and hasattr(_id,'cutFlow'):
0088                 if (len(WorkingPoints)>0 and _id.idName==WorkingPoints[0].split(':')[-1]):
0089                     docstring = 'VID compressed bitmap (%s), %d bits per cut'%(','.join([cut.cutName.value() for cut in _id.cutFlow]),int(ceil(log(len(WorkingPoints)+1,2))))
0090     return docstring
0091 
0092 bitmapVIDForEle = cms.EDProducer("EleVIDNestedWPBitmapProducer",
0093     src = cms.InputTag("slimmedElectrons"),
0094     WorkingPoints = electron_id_modules_WorkingPoints_nanoAOD.WorkingPoints,
0095 )
0096 _bitmapVIDForEle_docstring = _get_bitmapVIDForEle_docstring(electron_id_modules_WorkingPoints_nanoAOD.modules,bitmapVIDForEle.WorkingPoints)
0097 
0098 bitmapVIDForEleSpring15 = bitmapVIDForEle.clone(
0099     WorkingPoints = cms.vstring(
0100         "egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-veto",
0101         "egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-loose",
0102         "egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-medium",
0103         #    "egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-tight", # not fitting in sizeof(int)
0104     )
0105 )
0106 _bitmapVIDForEleSpring15_docstring = _get_bitmapVIDForEle_docstring(electron_id_modules_WorkingPoints_nanoAOD.modules,bitmapVIDForEleSpring15.WorkingPoints)
0107 
0108 bitmapVIDForEleSum16 = bitmapVIDForEle.clone(
0109     WorkingPoints = cms.vstring(
0110         "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-veto",
0111         "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-loose",
0112         "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-medium",
0113         "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-tight",
0114     )
0115 )
0116 _bitmapVIDForEleSum16_docstring = _get_bitmapVIDForEle_docstring(electron_id_modules_WorkingPoints_nanoAOD.modules,bitmapVIDForEleSum16.WorkingPoints)
0117 
0118 bitmapVIDForEleHEEP = bitmapVIDForEle.clone(
0119     WorkingPoints = cms.vstring("egmGsfElectronIDs:heepElectronID-HEEPV70"
0120     )
0121 )
0122 _bitmapVIDForEleHEEP_docstring = _get_bitmapVIDForEle_docstring(electron_id_modules_WorkingPoints_nanoAOD.modules,bitmapVIDForEleHEEP.WorkingPoints)
0123 ############################for bitmapVIDForEle defn end#############################
0124 #######################ISO ELE defn(in principle should be an import####################
0125 ##PhysicsTools/NanoAOD/python/EleIsoValueMapProducer_cfi.py
0126 isoForEle = cms.EDProducer("EleIsoValueMapProducer",
0127     src = cms.InputTag("slimmedElectrons"),
0128     relative = cms.bool(False),
0129     rho_MiniIso = cms.InputTag("fixedGridRhoFastjetAll"),
0130     rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"),
0131     EAFile_MiniIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Fall17/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
0132     EAFile_PFIso = cms.FileInPath("RecoEgamma/ElectronIdentification/data/Fall17/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
0133 )
0134 run2_miniAOD_80XLegacy.toModify(isoForEle,
0135                                 EAFile_MiniIso = "RecoEgamma/ElectronIdentification/data/Spring15/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_25ns.txt",
0136                                 EAFile_PFIso = "RecoEgamma/ElectronIdentification/data/Summer16/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_80X.txt")
0137 run2_nanoAOD_94X2016.toModify(isoForEle,
0138                                 EAFile_MiniIso = "RecoEgamma/ElectronIdentification/data/Spring15/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_25ns.txt",
0139                                 EAFile_PFIso = "RecoEgamma/ElectronIdentification/data/Summer16/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_80X.txt")
0140 #######################################ISO ELE end#####################################
0141 ######################################ptRatioForEle#####################################
0142 ###import from hysicsTools/NanoAOD/pythonElectronJetVarProducer_cfi.py
0143 ptRatioRelForEle = cms.EDProducer("ElectronJetVarProducer",
0144     srcJet = cms.InputTag("updatedJetsPuppi"),
0145     srcLep = cms.InputTag("slimmedElectrons"),
0146     srcVtx = cms.InputTag("offlineSlimmedPrimaryVertices"),
0147 )
0148 ######################################ptRatioForEle#####################################
0149 #############3###################seedGailEle#############################
0150 seedGainEle = cms.EDProducer("ElectronSeedGainProducer", src = cms.InputTag("slimmedElectrons"))
0151 ############################################seed gainELE
0152 ############################calibratedPatElectrons##############
0153 ##this is a special one, so we leave the era modifications here#####
0154 import RecoEgamma.EgammaTools.calibratedEgammas_cff
0155 
0156 calibratedPatElectronsNano = RecoEgamma.EgammaTools.calibratedEgammas_cff.calibratedPatElectrons.clone(
0157     produceCalibratedObjs = False,
0158     src = "slimmedElectrons"
0159 )
0160 
0161 (run2_egamma_2016 & tracker_apv_vfp30_2016).toModify(calibratedPatElectronsNano,
0162     correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_preVFP_RunFineEtaR9Gain")
0163 ) 
0164 
0165 (run2_egamma_2016 & ~tracker_apv_vfp30_2016).toModify(calibratedPatElectronsNano,
0166     correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2016_UltraLegacy_postVFP_RunFineEtaR9Gain")
0167 )
0168 
0169 run2_egamma_2017.toModify(calibratedPatElectronsNano,
0170     correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_24Feb2020_runEtaR9Gain_v2")
0171 )
0172 
0173 run2_egamma_2018.toModify(calibratedPatElectronsNano,
0174     correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2018_29Sep2020_RunFineEtaR9Gain")
0175 )
0176 
0177 run2_miniAOD_80XLegacy.toModify(calibratedPatElectronsNano,
0178                                 correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Legacy2016_07Aug2017_FineEtaR9_v3_ele_unc")
0179                             )
0180 
0181 for modifier in run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2:
0182     modifier.toModify(calibratedPatElectronsNano, 
0183         correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_17Nov2017_v1_ele_unc")
0184     )
0185 
0186 run2_nanoAOD_102Xv1.toModify(calibratedPatElectronsNano,
0187     correctionFile = cms.string("EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2018_Step2Closure_CoarseEtaR9Gain_v2")
0188 )
0189 ##############################end calibratedPatElectronsNano############################33
0190 #####################Start slimmedElectronsWithUserData###############################3
0191 ##import from PhysicsTools/PatAlgos/python/electronsWithUserData_cfi.py
0192 slimmedElectronsWithUserData = cms.EDProducer("PATElectronUserDataEmbedder",
0193     src = cms.InputTag("slimmedElectrons"),
0194     userFloats = cms.PSet(
0195         mvaFall17V1Iso = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17IsoV1Values"),
0196         mvaFall17V1noIso = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV1Values"),
0197         mvaFall17V2Iso = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17IsoV2Values"),
0198         mvaFall17V2noIso = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV2Values"),
0199         miniIsoChg = cms.InputTag("isoForEle:miniIsoChg"),
0200         miniIsoAll = cms.InputTag("isoForEle:miniIsoAll"),
0201         PFIsoChg = cms.InputTag("isoForEle:PFIsoChg"),
0202         PFIsoAll = cms.InputTag("isoForEle:PFIsoAll"),
0203         PFIsoAll04 = cms.InputTag("isoForEle:PFIsoAll04"),
0204         ptRatio = cms.InputTag("ptRatioRelForEle:ptRatio"),
0205         ptRel = cms.InputTag("ptRatioRelForEle:ptRel"),
0206         jetNDauChargedMVASel = cms.InputTag("ptRatioRelForEle:jetNDauChargedMVASel"),
0207         ecalTrkEnergyErrPostCorrNew = cms.InputTag("calibratedPatElectronsNano","ecalTrkEnergyErrPostCorr"),
0208         ecalTrkEnergyPreCorrNew     = cms.InputTag("calibratedPatElectronsNano","ecalTrkEnergyPreCorr"),
0209         ecalTrkEnergyPostCorrNew    = cms.InputTag("calibratedPatElectronsNano","ecalTrkEnergyPostCorr"),
0210         energyScaleUpNew               = cms.InputTag("calibratedPatElectronsNano","energyScaleUp"),
0211         energyScaleDownNew             = cms.InputTag("calibratedPatElectronsNano","energyScaleDown"),
0212         energySigmaUpNew               = cms.InputTag("calibratedPatElectronsNano","energySigmaUp"),
0213         energySigmaDownNew             = cms.InputTag("calibratedPatElectronsNano","energySigmaDown"),
0214 
0215     ),
0216     userIntFromBools = cms.PSet(
0217 
0218         mvaFall17V1Iso_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wp90"),
0219         mvaFall17V1Iso_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wp80"),
0220         mvaFall17V1Iso_WPL = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wpLoose"),
0221         mvaFall17V1noIso_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-noIso-V1-wp90"),
0222         mvaFall17V1noIso_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-noIso-V1-wp80"),
0223         mvaFall17V1noIso_WPL = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-noIso-V1-wpLoose"),
0224 
0225         mvaFall17V2Iso_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wp90"),
0226         mvaFall17V2Iso_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wp80"),
0227         mvaFall17V2Iso_WPL = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wpLoose"),
0228         mvaFall17V2noIso_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wp90"),
0229         mvaFall17V2noIso_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wp80"),
0230         mvaFall17V2noIso_WPL = cms.InputTag("egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wpLoose"),
0231 
0232         cutbasedID_Fall17_V1_veto = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V1-veto"),
0233         cutbasedID_Fall17_V1_loose = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V1-loose"),
0234         cutbasedID_Fall17_V1_medium = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V1-medium"),
0235         cutbasedID_Fall17_V1_tight = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V1-tight"),
0236         cutbasedID_Fall17_V2_veto = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-veto"),
0237         cutbasedID_Fall17_V2_loose = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-loose"),
0238         cutbasedID_Fall17_V2_medium = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-medium"),
0239         cutbasedID_Fall17_V2_tight = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-tight"),
0240         cutbasedID_HEEP = cms.InputTag("egmGsfElectronIDs:heepElectronID-HEEPV70"),
0241     ),
0242     userInts = cms.PSet(
0243         VIDNestedWPBitmap = cms.InputTag("bitmapVIDForEle"),
0244         VIDNestedWPBitmapHEEP = cms.InputTag("bitmapVIDForEleHEEP"),
0245         seedGain = cms.InputTag("seedGainEle"),
0246     ),
0247     userCands = cms.PSet(
0248         jetForLepJetVar = cms.InputTag("ptRatioRelForEle:jetForLepJetVar") # warning: Ptr is null if no match is found
0249     ),
0250 )
0251 
0252 ###Not to update with S+S vars as they already exist for run2_nanoAOD_94X2016 era
0253 run2_nanoAOD_94X2016.toModify(slimmedElectronsWithUserData.userFloats,
0254                               ecalTrkEnergyErrPostCorrNew = None,
0255                               ecalTrkEnergyPreCorrNew = None,
0256                               ecalTrkEnergyPostCorrNew = None,
0257                               energyScaleUpNew               = None,
0258                               energyScaleDownNew             = None,
0259                               energySigmaUpNew               = None,
0260                               energySigmaDownNew             = None
0261                               
0262                               
0263 )
0264 
0265 run2_nanoAOD_94X2016.toModify(slimmedElectronsWithUserData.userIntFromBools,
0266     # MVAs and HEEP are already pre-computed. Cut-based too (except V2), but we re-add it for consistency with the nested bitmap
0267     cutbasedID_Sum16_veto = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-veto"),
0268     cutbasedID_Sum16_loose = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-loose"),
0269     cutbasedID_Sum16_medium = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-medium"),
0270     cutbasedID_Sum16_tight = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-tight"),
0271     cutbasedID_HLT = cms.InputTag("egmGsfElectronIDs:cutBasedElectronHLTPreselection-Summer16-V1"),
0272     cutbasedID_Spring15_veto = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-veto"),
0273     cutbasedID_Spring15_loose = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-loose"),
0274     cutbasedID_Spring15_medium = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-medium"),
0275     cutbasedID_Spring15_tight = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-tight"), 
0276     cutbasedID_Fall17_V2_veto = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-veto"),
0277     cutbasedID_Fall17_V2_loose = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-loose"),
0278     cutbasedID_Fall17_V2_medium = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-medium"),
0279     cutbasedID_Fall17_V2_tight = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-tight"),
0280     
0281 )
0282 
0283 run2_miniAOD_80XLegacy.toModify(slimmedElectronsWithUserData.userFloats,
0284     mvaSpring16GP = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1Values"),
0285     mvaSpring16HZZ = cms.InputTag("electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16HZZV1Values"),
0286 )
0287 
0288 run2_miniAOD_80XLegacy.toModify(slimmedElectronsWithUserData.userIntFromBools,
0289     mvaSpring16GP_WP90 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp90"),
0290     mvaSpring16GP_WP80 = cms.InputTag("egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp80"),
0291     mvaSpring16HZZ_WPL = cms.InputTag("egmGsfElectronIDs:mvaEleID-Spring16-HZZ-V1-wpLoose"),
0292     cutbasedID_Sum16_veto = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-veto"),
0293     cutbasedID_Sum16_loose = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-loose"),
0294     cutbasedID_Sum16_medium = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-medium"),
0295     cutbasedID_Sum16_tight = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-tight"),
0296     cutbasedID_HLT = cms.InputTag("egmGsfElectronIDs:cutBasedElectronHLTPreselection-Summer16-V1"),
0297     cutbasedID_Spring15_veto = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-veto"),
0298     cutbasedID_Spring15_loose = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-loose"),
0299     cutbasedID_Spring15_medium = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-medium"),
0300     cutbasedID_Spring15_tight = cms.InputTag("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-tight"),
0301 )
0302 
0303 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
0304     modifier.toModify(slimmedElectronsWithUserData.userInts,
0305                       VIDNestedWPBitmapSpring15 = cms.InputTag("bitmapVIDForEleSpring15"),
0306                       VIDNestedWPBitmapSum16 = cms.InputTag("bitmapVIDForEleSum16"),
0307                       )
0308 #################################################END slimmedElectrons with user data#####################
0309 #################################################finalElectrons#####################
0310 finalElectrons = cms.EDFilter("PATElectronRefSelector",
0311     src = cms.InputTag("slimmedElectronsWithUserData"),
0312     cut = cms.string("pt > 5 ")
0313 )
0314 #################################################finalElectrons#####################
0315 ################################################electronMVATTH#####################
0316 electronMVATTH= cms.EDProducer("EleBaseMVAValueMapProducer",
0317     src = cms.InputTag("linkedObjects","electrons"),
0318     weightFile =  cms.FileInPath("PhysicsTools/NanoAOD/data/el_BDTG_2017.weights.xml"),
0319     name = cms.string("electronMVATTH"),
0320     isClassifier = cms.bool(True),
0321     variablesOrder = cms.vstring(["LepGood_pt","LepGood_eta","LepGood_jetNDauChargedMVASel","LepGood_miniRelIsoCharged","LepGood_miniRelIsoNeutral","LepGood_jetPtRelv2","LepGood_jetDF","LepGood_jetPtRatio","LepGood_dxy","LepGood_sip3d","LepGood_dz","LepGood_mvaFall17V2noIso"]),
0322     variables = cms.PSet(
0323         LepGood_pt = cms.string("pt"),
0324         LepGood_eta = cms.string("eta"),
0325         LepGood_jetNDauChargedMVASel = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0"),
0326         LepGood_miniRelIsoCharged = cms.string("userFloat('miniIsoChg')/pt"),
0327         LepGood_miniRelIsoNeutral = cms.string("(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"),
0328         LepGood_jetPtRelv2 = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0"),
0329         LepGood_jetDF = cms.string("?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probbb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:problepb'),0.0):0.0"),
0330         LepGood_jetPtRatio = cms.string("?userCand('jetForLepJetVar').isNonnull()?min(userFloat('ptRatio'),1.5):1.0/(1.0+userFloat('PFIsoAll04')/pt)"),
0331         LepGood_dxy = cms.string("log(abs(dB('PV2D')))"),
0332         LepGood_sip3d = cms.string("abs(dB('PV3D')/edB('PV3D'))"),
0333         LepGood_dz = cms.string("log(abs(dB('PVDZ')))"),
0334         LepGood_mvaFall17V2noIso = cms.string("userFloat('mvaFall17V2noIso')"),
0335     )
0336 )
0337 run2_egamma_2016.toModify(electronMVATTH,
0338     weightFile = "PhysicsTools/NanoAOD/data/el_BDTG_2016.weights.xml",
0339 )
0340 ################################################electronMVATTH end#####################
0341 ################################################electronTable defn #####################
0342 electronTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
0343     src = cms.InputTag("linkedObjects","electrons"),
0344     cut = cms.string(""), #we should not filter on cross linked collections
0345     name= cms.string("Electron"),
0346     doc = cms.string("slimmedElectrons after basic selection (" + finalElectrons.cut.value()+")"),
0347     singleton = cms.bool(False), # the number of entries is variable
0348     extension = cms.bool(False), # this is the main table for the electrons
0349     variables = cms.PSet(CandVars,
0350         jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"),
0351         photonIdx = Var("?overlaps('photons').size()>0?overlaps('photons')[0].key():-1", int, doc="index of the associated photon (-1 if none)"),
0352         energyErr = Var("p4Error('P4_COMBINATION')",float,doc="energy error of the cluster-track combination",precision=6),
0353         dz = Var("dB('PVDZ')",float,doc="dz (with sign) wrt first PV, in cm",precision=10),
0354         dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6),
0355         dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10),
0356         dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6),
0357         ip3d = Var("abs(dB('PV3D'))",float,doc="3D impact parameter wrt first PV, in cm",precision=10),
0358         sip3d = Var("abs(dB('PV3D')/edB('PV3D'))",float,doc="3D impact parameter significance wrt first PV, in cm",precision=10),
0359         deltaEtaSC = Var("superCluster().eta()-eta()",float,doc="delta eta (SC,ele) with sign",precision=10),
0360         r9 = Var("full5x5_r9()",float,doc="R9 of the supercluster, calculated with full 5x5 region",precision=10),
0361         sieie = Var("full5x5_sigmaIetaIeta()",float,doc="sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=10),
0362         eInvMinusPInv = Var("(1-eSuperClusterOverP())/ecalEnergy()",float,doc="1/E_SC - 1/p_trk",precision=10),
0363         scEtOverPt = Var("(superCluster().energy()/(pt*cosh(superCluster().eta())))-1",float,doc="(supercluster transverse energy)/pt-1",precision=8),
0364 
0365         mvaFall17V2Iso = Var("userFloat('mvaFall17V2Iso')",float,doc="MVA Iso ID V2 score"),
0366         mvaFall17V2Iso_WP80 = Var("userInt('mvaFall17V2Iso_WP80')",bool,doc="MVA Iso ID V2 WP80"),
0367         mvaFall17V2Iso_WP90 = Var("userInt('mvaFall17V2Iso_WP90')",bool,doc="MVA Iso ID V2 WP90"),
0368         mvaFall17V2Iso_WPL = Var("userInt('mvaFall17V2Iso_WPL')",bool,doc="MVA Iso ID V2 loose WP"),
0369         mvaFall17V2noIso = Var("userFloat('mvaFall17V2noIso')",float,doc="MVA noIso ID V2 score"),
0370         mvaFall17V2noIso_WP80 = Var("userInt('mvaFall17V2noIso_WP80')",bool,doc="MVA noIso ID V2 WP80"),
0371         mvaFall17V2noIso_WP90 = Var("userInt('mvaFall17V2noIso_WP90')",bool,doc="MVA noIso ID V2 WP90"),
0372         mvaFall17V2noIso_WPL = Var("userInt('mvaFall17V2noIso_WPL')",bool,doc="MVA noIso ID V2 loose WP"),
0373 
0374         cutBased = Var("userInt('cutbasedID_Fall17_V2_veto')+userInt('cutbasedID_Fall17_V2_loose')+userInt('cutbasedID_Fall17_V2_medium')+userInt('cutbasedID_Fall17_V2_tight')",int,doc="cut-based ID Fall17 V2 (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)"),
0375         vidNestedWPBitmap = Var("userInt('VIDNestedWPBitmap')",int,doc=_bitmapVIDForEle_docstring),
0376         vidNestedWPBitmapHEEP = Var("userInt('VIDNestedWPBitmapHEEP')",int,doc=_bitmapVIDForEleHEEP_docstring),
0377         cutBased_HEEP = Var("userInt('cutbasedID_HEEP')",bool,doc="cut-based HEEP ID"),
0378         miniPFRelIso_chg = Var("userFloat('miniIsoChg')/pt",float,doc="mini PF relative isolation, charged component"),
0379         miniPFRelIso_all = Var("userFloat('miniIsoAll')/pt",float,doc="mini PF relative isolation, total (with scaled rho*EA PU corrections)"),
0380         pfRelIso03_chg = Var("userFloat('PFIsoChg')/pt",float,doc="PF relative isolation dR=0.3, charged component"),
0381         pfRelIso03_all = Var("userFloat('PFIsoAll')/pt",float,doc="PF relative isolation dR=0.3, total (with rho*EA PU corrections)"),
0382         jetRelIso = Var("?userCand('jetForLepJetVar').isNonnull()?(1./userFloat('ptRatio'))-1.:userFloat('PFIsoAll04')/pt",float,doc="Relative isolation in matched jet (1/ptRatio-1, pfRelIso04_all if no matched jet)",precision=8),
0383         jetPtRelv2 = Var("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0",float,doc="Relative momentum of the lepton with respect to the closest jet after subtracting the lepton",precision=8),
0384         dr03TkSumPt = Var("?pt>35?dr03TkSumPt():0",float,doc="Non-PF track isolation within a delta R cone of 0.3 with electron pt > 35 GeV",precision=8),
0385         dr03TkSumPtHEEP = Var("?pt>35?dr03TkSumPtHEEP():0",float,doc="Non-PF track isolation within a delta R cone of 0.3 with electron pt > 35 GeV used in HEEP ID",precision=8),
0386         dr03EcalRecHitSumEt = Var("?pt>35?dr03EcalRecHitSumEt():0",float,doc="Non-PF Ecal isolation within a delta R cone of 0.3 with electron pt > 35 GeV",precision=8),
0387         dr03HcalDepth1TowerSumEt = Var("?pt>35?dr03HcalTowerSumEt(1):0",float,doc="Non-PF Hcal isolation within a delta R cone of 0.3 with electron pt > 35 GeV",precision=8),
0388         hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8),
0389         tightCharge = Var("isGsfCtfScPixChargeConsistent() + isGsfScPixChargeConsistent()",int,doc="Tight charge criteria (0:none, 1:isGsfScPixChargeConsistent, 2:isGsfCtfScPixChargeConsistent)"),
0390         convVeto = Var("passConversionVeto()",bool,doc="pass conversion veto"),
0391         lostHits = Var("gsfTrack.hitPattern.numberOfLostHits('MISSING_INNER_HITS')","uint8",doc="number of missing inner hits"),
0392         isPFcand = Var("pfCandidateRef().isNonnull()",bool,doc="electron is PF candidate"),
0393         seedGain = Var("userInt('seedGain')","uint8",doc="Gain of the seed crystal"),
0394         jetNDauCharged = Var("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0", "uint8", doc="number of charged daughters of the closest jet"),
0395     ),
0396     externalVariables = cms.PSet(
0397         mvaTTH = ExtVar(cms.InputTag("electronMVATTH"),float, doc="TTH MVA lepton ID score",precision=14),
0398         fsrPhotonIdx = ExtVar(cms.InputTag("leptonFSRphotons:eleFsrIndex"),int, doc="Index of the lowest-dR/ET2 among associated FSR photons"),
0399     ),
0400 )
0401 
0402 #for technical reasons
0403 for modifier in run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_miniAOD_80XLegacy,run2_nanoAOD_102Xv1,run2_nanoAOD_106Xv1,run2_nanoAOD_106Xv2:
0404     modifier.toModify(electronTable.variables,            
0405         pt = Var("pt*userFloat('ecalTrkEnergyPostCorrNew')/userFloat('ecalTrkEnergyPreCorrNew')", float, precision=-1, doc="p_{T}"),
0406         energyErr = Var("userFloat('ecalTrkEnergyErrPostCorrNew')", float, precision=6, doc="energy error of the cluster-track combination"),
0407         eCorr = Var("userFloat('ecalTrkEnergyPostCorrNew')/userFloat('ecalTrkEnergyPreCorrNew')", float, doc="ratio of the calibrated energy/miniaod energy"),
0408         scEtOverPt = Var("(superCluster().energy()/(pt*userFloat('ecalTrkEnergyPostCorrNew')/userFloat('ecalTrkEnergyPreCorrNew')*cosh(superCluster().eta())))-1",float,doc="(supercluster transverse energy)/pt-1",precision=8),
0409         dEscaleUp=Var("userFloat('ecalTrkEnergyPostCorrNew')-userFloat('energyScaleUpNew')", float,  doc="ecal energy scale shifted 1 sigma up(adding gain/stat/syst in quadrature)", precision=8),
0410         dEscaleDown=Var("userFloat('ecalTrkEnergyPostCorrNew')-userFloat('energyScaleDownNew')", float,  doc="ecal energy scale shifted 1 sigma down (adding gain/stat/syst in quadrature)", precision=8),
0411         dEsigmaUp=Var("userFloat('ecalTrkEnergyPostCorrNew')-userFloat('energySigmaUpNew')", float, doc="ecal energy smearing value shifted 1 sigma up", precision=8),
0412         dEsigmaDown=Var("userFloat('ecalTrkEnergyPostCorrNew')-userFloat('energySigmaDownNew')", float,  doc="ecal energy smearing value shifted 1 sigma up", precision=8),
0413 
0414 )
0415 ##Keeping the possibilty of using V1 working points in older eras
0416 (run2_nanoAOD_92X | run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94XMiniAODv2 | run2_nanoAOD_94X2016 | run2_nanoAOD_102Xv1).toModify(electronTable.variables,
0417         mvaFall17V1Iso = Var("userFloat('mvaFall17V1Iso')",float,doc="MVA Iso ID V1 score"),
0418         mvaFall17V1Iso_WP80 = Var("userInt('mvaFall17V1Iso_WP80')",bool,doc="MVA Iso ID V1 WP80"),
0419         mvaFall17V1Iso_WP90 = Var("userInt('mvaFall17V1Iso_WP90')",bool,doc="MVA Iso ID V1 WP90"),
0420         mvaFall17V1Iso_WPL = Var("userInt('mvaFall17V1Iso_WPL')",bool,doc="MVA Iso ID V1 loose WP"),
0421         mvaFall17V1noIso = Var("userFloat('mvaFall17V1noIso')",float,doc="MVA noIso ID V1 score"),
0422         mvaFall17V1noIso_WP80 = Var("userInt('mvaFall17V1noIso_WP80')",bool,doc="MVA noIso ID V1 WP80"),
0423         mvaFall17V1noIso_WP90 = Var("userInt('mvaFall17V1noIso_WP90')",bool,doc="MVA noIso ID V1 WP90"),
0424         mvaFall17V1noIso_WPL = Var("userInt('mvaFall17V1noIso_WPL')",bool,doc="MVA noIso ID V1 loose WP"),
0425         cutBased_Fall17_V1 = Var("userInt('cutbasedID_Fall17_V1_veto')+userInt('cutbasedID_Fall17_V1_loose')+userInt('cutbasedID_Fall17_V1_medium')+userInt('cutbasedID_Fall17_V1_tight')",int,doc="cut-based ID Fall17 V1 (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)"),
0426 )
0427 
0428 #the94X miniAOD V2 had a bug in the scale and smearing for electrons in the E/p comb
0429 #therefore we redo it but but we need use a new name for the userFloat as we cant override existing userfloats
0430 # scale and smearing only when available#ONLY needed for this era
0431 run2_nanoAOD_94X2016.toModify(electronTable.variables,
0432     cutBased_Sum16 = Var("userInt('cutbasedID_Sum16_veto')+userInt('cutbasedID_Sum16_loose')+userInt('cutbasedID_Sum16_medium')+userInt('cutbasedID_Sum16_tight')",int,doc="cut-based Summer16 ID (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)"),
0433     cutBased_Fall17_V1 = Var("electronID('cutBasedElectronID-Fall17-94X-V1-veto')+electronID('cutBasedElectronID-Fall17-94X-V1-loose')+electronID('cutBasedElectronID-Fall17-94X-V1-medium')+electronID('cutBasedElectronID-Fall17-94X-V1-tight')",int,doc="cut-based Fall17 ID (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)"),
0434     #cutBased in 2016 corresponds to Spring16 not Fall17V2, so have to add in V2 ID explicitly
0435     #it also doesnt exist in the miniAOD so have to redo it
0436     cutBased = Var("userInt('cutbasedID_Fall17_V2_veto')+userInt('cutbasedID_Fall17_V2_loose')+userInt('cutbasedID_Fall17_V2_medium')+userInt('cutbasedID_Fall17_V2_tight')",int,doc="cut-based ID Fall17 V2 (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)"),
0437     cutBased_HLTPreSel = Var("userInt('cutbasedID_HLT')",int,doc="cut-based HLT pre-selection ID"),
0438     cutBased_HEEP = Var("electronID('heepElectronID-HEEPV70')",bool,doc="cut-based HEEP ID"),
0439     cutBased_Spring15 = Var("userInt('cutbasedID_Spring15_veto')+userInt('cutbasedID_Spring15_loose')+userInt('cutbasedID_Spring15_medium')+userInt('cutbasedID_Spring15_tight')",int,doc="cut-based Spring15 ID (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)"),
0440     mvaSpring16GP = Var("userFloat('ElectronMVAEstimatorRun2Spring16GeneralPurposeV1Values')",float,doc="MVA Spring16 general-purpose ID score"),
0441     mvaSpring16GP_WP80 = Var("electronID('mvaEleID-Spring16-GeneralPurpose-V1-wp80')",bool,doc="MVA Spring16 general-purpose ID WP80"),
0442     mvaSpring16GP_WP90 = Var("electronID('mvaEleID-Spring16-GeneralPurpose-V1-wp90')",bool,doc="MVA Spring16 general-purpose ID WP90"),
0443     mvaSpring16HZZ = Var("userFloat('ElectronMVAEstimatorRun2Spring16HZZV1Values')",float,doc="MVA Spring16 HZZ ID score"),
0444     mvaSpring16HZZ_WPL = Var("electronID('mvaEleID-Spring16-HZZ-V1-wpLoose')",bool,doc="MVA Spring16 HZZ ID loose WP"),
0445     mvaFall17V1Iso = Var("userFloat('ElectronMVAEstimatorRun2Fall17IsoV1Values')",float,doc="MVA Fall17 V1 Iso ID score"),
0446     mvaFall17V1Iso_WP80 = Var("electronID('mvaEleID-Fall17-iso-V1-wp80')",bool,doc="MVA Fall17 V1 Iso ID WP80"),
0447     mvaFall17V1Iso_WP90 = Var("electronID('mvaEleID-Fall17-iso-V1-wp90')",bool,doc="MVA Fall17 V1 Iso ID WP90"),
0448     mvaFall17V1Iso_WPL = Var("electronID('mvaEleID-Fall17-iso-V1-wpLoose')",bool,doc="MVA Fall17 V1 Iso ID loose WP"),
0449     mvaFall17V1noIso = Var("userFloat('ElectronMVAEstimatorRun2Fall17NoIsoV1Values')",float,doc="MVA Fall17 V1 noIso ID score"),
0450     mvaFall17V1noIso_WP80 = Var("electronID('mvaEleID-Fall17-noIso-V1-wp80')",bool,doc="MVA Fall17 V1 noIso ID WP80"),
0451     mvaFall17V1noIso_WP90 = Var("electronID('mvaEleID-Fall17-noIso-V1-wp90')",bool,doc="MVA Fall17 V1 noIso ID WP90"),
0452     mvaFall17V1noIso_WPL = Var("electronID('mvaEleID-Fall17-noIso-V1-wpLoose')",bool,doc="MVA Fall17 V1 noIso ID loose WP"),
0453     vidNestedWPBitmapSpring15 = Var("userInt('VIDNestedWPBitmapSpring15')",int,doc=_bitmapVIDForEleSpring15_docstring),
0454     vidNestedWPBitmapSum16 = Var("userInt('VIDNestedWPBitmapSum16')",int,doc=_bitmapVIDForEleSum16_docstring),
0455     pt = Var("pt*userFloat('ecalTrkEnergyPostCorr')/userFloat('ecalTrkEnergyPreCorr')", float, precision=-1, doc="p_{T}"),
0456     energyErr = Var("userFloat('ecalTrkEnergyErrPostCorr')", float, precision=6, doc="energy error of the cluster-track combination"),
0457     eCorr = Var("userFloat('ecalTrkEnergyPostCorr')/userFloat('ecalTrkEnergyPreCorr')", float, doc="ratio of the calibrated energy/miniaod energy"),
0458     scEtOverPt = Var("(superCluster().energy()/(pt*userFloat('ecalTrkEnergyPostCorr')/userFloat('ecalTrkEnergyPreCorr')*cosh(superCluster().eta())))-1",float,doc="(supercluster transverse energy)/pt-1",precision=8),
0459     dEscaleUp=Var("userFloat('ecalTrkEnergyPostCorr')-userFloat('energyScaleUp')", float,  doc="ecal energy scale shifted 1 sigma up (adding gain/stat/syst in quadrature)", precision=8),
0460     dEscaleDown=Var("userFloat('ecalTrkEnergyPostCorr')-userFloat('energyScaleDown')", float,  doc="ecal energy scale shifted 1 sigma down (adding gain/stat/syst in quadrature)", precision=8),
0461     dEsigmaUp=Var("userFloat('ecalTrkEnergyPostCorr')-userFloat('energySigmaUp')", float, doc="ecal energy smearing value shifted 1 sigma up", precision=8),
0462     dEsigmaDown=Var("userFloat('ecalTrkEnergyPostCorr')-userFloat('energySigmaDown')", float,  doc="ecal energy smearing value shifted 1 sigma up", precision=8),
0463 )
0464 ###
0465 run2_miniAOD_80XLegacy.toModify(electronTable.variables,
0466     cutBased_Sum16 = Var("userInt('cutbasedID_Sum16_veto')+userInt('cutbasedID_Sum16_loose')+userInt('cutbasedID_Sum16_medium')+userInt('cutbasedID_Sum16_tight')",int,doc="cut-based Summer16 ID (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)"),
0467     cutBased_HLTPreSel = Var("userInt('cutbasedID_HLT')",int,doc="cut-based HLT pre-selection ID"),
0468     cutBased_Spring15 = Var("userInt('cutbasedID_Spring15_veto')+userInt('cutbasedID_Spring15_loose')+userInt('cutbasedID_Spring15_medium')+userInt('cutbasedID_Spring15_tight')",int,doc="cut-based Spring15 ID (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)"),
0469     mvaSpring16GP = Var("userFloat('mvaSpring16GP')",float,doc="MVA general-purpose ID score"),
0470     mvaSpring16GP_WP80 = Var("userInt('mvaSpring16GP_WP80')",bool,doc="MVA general-purpose ID WP80"),
0471     mvaSpring16GP_WP90 = Var("userInt('mvaSpring16GP_WP90')",bool,doc="MVA general-purpose ID WP90"),
0472     mvaSpring16HZZ = Var("userFloat('mvaSpring16HZZ')",float,doc="MVA HZZ ID score"),
0473     mvaSpring16HZZ_WPL = Var("userInt('mvaSpring16HZZ_WPL')",bool,doc="MVA HZZ ID loose WP"),
0474 
0475     vidNestedWPBitmapSpring15 = Var("userInt('VIDNestedWPBitmapSpring15')",int,doc=_bitmapVIDForEleSpring15_docstring),
0476     vidNestedWPBitmapSum16 = Var("userInt('VIDNestedWPBitmapSum16')",int,doc=_bitmapVIDForEleSum16_docstring),
0477 
0478 )
0479 #############electron Table END#####################
0480 # Depends on particlelevel producer run in particlelevel_cff
0481 tautaggerForMatching = cms.EDProducer("GenJetTauTaggerProducer",
0482                                       src = cms.InputTag('particleLevel:leptons')
0483 )
0484  ##PhysicsTools/NanoAOD/plugins/GenJetGenPartMerger.cc##this class misses fillDescription#TODO
0485 matchingElecPhoton = cms.EDProducer("GenJetGenPartMerger",
0486                                     srcJet =cms.InputTag("particleLevel:leptons"),
0487                                     srcPart=cms.InputTag("particleLevel:photons"),
0488                                     cut = cms.string("pt > 3"),
0489                                     hasTauAnc=cms.InputTag("tautaggerForMatching"),
0490 )
0491 electronsMCMatchForTableAlt = cms.EDProducer("GenJetMatcherDRPtByDR",  # cut on deltaR, deltaPt/Pt; pick best by deltaR
0492     src         = electronTable.src,                 # final reco collection
0493     matched     = cms.InputTag("matchingElecPhoton:merged"), # final mc-truth particle collection
0494     mcPdgId     = cms.vint32(11,22),                 # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
0495     checkCharge = cms.bool(False),              # True = require RECO and MC objects to have the same charge
0496     mcStatus    = cms.vint32(),
0497     maxDeltaR   = cms.double(0.3),              # Minimum deltaR for the match
0498     maxDPtRel   = cms.double(0.5),              # Minimum deltaPt/Pt for the match
0499     resolveAmbiguities    = cms.bool(True),     # Forbid two RECO objects to match to the same GEN object
0500     resolveByMatchQuality = cms.bool(True),    # False = just match input in order; True = pick lowest deltaR pair first
0501 ) 
0502 electronsMCMatchForTable = cms.EDProducer("MCMatcher",  # cut on deltaR, deltaPt/Pt; pick best by deltaR
0503     src         = electronTable.src,                 # final reco collection
0504     matched     = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
0505     mcPdgId     = cms.vint32(11,22),                 # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
0506     checkCharge = cms.bool(False),              # True = require RECO and MC objects to have the same charge
0507     mcStatus    = cms.vint32(1),                # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
0508     maxDeltaR   = cms.double(0.3),              # Minimum deltaR for the match
0509     maxDPtRel   = cms.double(0.5),              # Minimum deltaPt/Pt for the match
0510     resolveAmbiguities    = cms.bool(True),     # Forbid two RECO objects to match to the same GEN object
0511     resolveByMatchQuality = cms.bool(True),    # False = just match input in order; True = pick lowest deltaR pair first
0512 )
0513 #should be cloned from PhysicsTools/NanoAOD/python/candMcMatchTable_cfi.py 
0514 electronMCTable = cms.EDProducer("CandMCMatchTableProducer",
0515     src     = electronTable.src,
0516     mcMapDressedLep = cms.InputTag("electronsMCMatchForTableAlt"),
0517     mcMap   = cms.InputTag("electronsMCMatchForTable"),
0518     mapTauAnc = cms.InputTag("matchingElecPhoton:hasTauAnc"),
0519     objName = electronTable.name,
0520     objType = electronTable.name, #cms.string("Electron"),
0521     branchName = cms.string("genPart"),
0522     docString = cms.string("MC matching to status==1 electrons or photons"),
0523     genparticles     = cms.InputTag("finalGenParticles"), 
0524 )
0525 
0526 electronTask = cms.Task(bitmapVIDForEle,bitmapVIDForEleHEEP,isoForEle,ptRatioRelForEle,seedGainEle,calibratedPatElectronsNano,slimmedElectronsWithUserData,finalElectrons)
0527 electronTablesTask = cms.Task(electronMVATTH, electronTable)
0528 electronMCTask = cms.Task(tautaggerForMatching, matchingElecPhoton, electronsMCMatchForTable, electronsMCMatchForTableAlt, electronMCTable)
0529 
0530 ## TEMPORARY as no ID for Run3 yet
0531 (run3_nanoAOD_devel).toReplaceWith(electronTask, electronTask.copyAndExclude([bitmapVIDForEle,bitmapVIDForEleHEEP]))
0532 (run3_nanoAOD_devel).toModify(slimmedElectronsWithUserData, userIntFromBools = cms.PSet())
0533 (run3_nanoAOD_devel).toModify(slimmedElectronsWithUserData.userInts,
0534                                                     VIDNestedWPBitmap = None,
0535                                                     VIDNestedWPBitmapHEEP = None)
0536 (run3_nanoAOD_devel).toModify(slimmedElectronsWithUserData.userFloats,
0537                                                     mvaFall17V1Iso = None,
0538                                                     mvaFall17V1noIso = None,
0539                                                     mvaFall17V2Iso = None,
0540                                                     mvaFall17V2noIso = None,
0541                                                 )
0542 (run3_nanoAOD_devel).toModify(electronTable.variables,
0543                               mvaFall17V2Iso = None,
0544                               mvaFall17V2Iso_WP80 = None,
0545                               mvaFall17V2Iso_WP90 = None,
0546                               mvaFall17V2Iso_WPL = None,
0547                               mvaFall17V2noIso = None,
0548                               mvaFall17V2noIso_WP80 = None,
0549                               mvaFall17V2noIso_WP90 = None,
0550                               mvaFall17V2noIso_WPL = None,
0551                               vidNestedWPBitmapHEEP = None,
0552                               vidNestedWPBitmap = None,
0553                               cutBased = None,
0554                               cutBased_HEEP = None,
0555 )
0556 
0557 (run3_nanoAOD_devel).toReplaceWith(electronTablesTask, electronTablesTask.copyAndExclude([electronMVATTH]))
0558 (run3_nanoAOD_devel).toModify(electronTable, externalVariables = cms.PSet(fsrPhotonIdx = ExtVar(cms.InputTag("leptonFSRphotons:eleFsrIndex"),int, doc="Index of the  lowest-dR/ET2 among associated FSR photons")),
0559 )
0560 ##### end TEMPORARY Run3
0561 
0562 # Revert back to AK4 CHS jets for Run 2
0563 run2_nanoAOD_ANY.toModify(ptRatioRelForEle,srcJet="updatedJets")
0564 
0565 
0566 #for NANO from reminAOD, no need to run slimmedElectronsUpdated, other modules of electron sequence will run on slimmedElectrons
0567 for modifier in run2_miniAOD_80XLegacy,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_94X2016,run2_nanoAOD_102Xv1,run2_nanoAOD_106Xv1:
0568     modifier.toModify(bitmapVIDForEle, src = "slimmedElectronsUpdated")
0569     modifier.toModify(bitmapVIDForEleSpring15, src = "slimmedElectronsUpdated")
0570     modifier.toModify(bitmapVIDForEleSum16, src = "slimmedElectronsUpdated")
0571     modifier.toModify(bitmapVIDForEleHEEP, src = "slimmedElectronsUpdated")
0572     modifier.toModify(isoForEle, src = "slimmedElectronsUpdated")
0573     modifier.toModify(ptRatioRelForEle, srcLep = "slimmedElectronsUpdated")
0574     modifier.toModify(seedGainEle, src = "slimmedElectronsUpdated")
0575     modifier.toModify(slimmedElectronsWithUserData, src = "slimmedElectronsUpdated")
0576     modifier.toModify(calibratedPatElectronsNano, src = "slimmedElectronsUpdated")
0577     ###this sequence should run for all eras except run2_nanoAOD_106Xv2 which should run the electronSequence as above
0578     _withULAndUpdate_Task = cms.Task(slimmedElectronsUpdated)
0579     _withULAndUpdate_Task.add(electronTask.copy())
0580     modifier.toReplaceWith(electronTask, _withULAndUpdate_Task)
0581 
0582 from RecoEgamma.ElectronIdentification.heepIdVarValueMapProducer_cfi import heepIDVarValueMaps
0583 _withTo106XAndUpdate_Task = cms.Task(heepIDVarValueMaps,slimmedElectronsTo106X)
0584 _withTo106XAndUpdate_Task.add(electronTask.copy())
0585 heepIDVarValueMaps.dataFormat = 2
0586 
0587 for modifier in run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_94X2016, run2_nanoAOD_102Xv1, run2_nanoAOD_94XMiniAODv1:
0588     modifier.toReplaceWith(electronTask, _withTo106XAndUpdate_Task)
0589 
0590 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
0591     _withTo106XAndUpdateAnd80XLegacyScale_Task = cms.Task(bitmapVIDForEleSpring15,bitmapVIDForEleSum16)
0592     _withTo106XAndUpdateAnd80XLegacyScale_Task.add(_withTo106XAndUpdate_Task.copy())
0593     modifier.toReplaceWith(electronTask, _withTo106XAndUpdateAnd80XLegacyScale_Task)
0594 
0595 _withTo106XAndUpdateAnd94XScale_Task = _withTo106XAndUpdate_Task.copy()
0596 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_102Xv1:
0597     modifier.toReplaceWith(electronTask, _withTo106XAndUpdate_Task)