calibratedEBRechits = cms.InputTag('reducedEgamma', 'reducedEBRecHits'),
                  reCalibratedEBRechits = cms.InputTag('unCalibrateMe', 'EcalRecalibRecHitsEB'),
                  updateEnergy = cms.bool(True)
              )
        )            

# electron matching
if invertEleVeto and customize.doeleId:
    eleSource="flashggSelectedElectrons" if not "EXOSpring16_v2" in  customize.datasetName() else "flashggElectrons"
    if customize.eleId == "isHLTsafe":
        from flashgg.MicroAOD.flashggHltSafeElectrons_cfi import flashggHltSafeElectrons
        process.flashggIdentifiedElectrons = flashggHltSafeElectrons.clone(src=cms.InputTag(eleSource))
    else:
        from flashgg.MicroAOD.flashggLeptonSelectors_cff import flashggSelectedElectrons
        process.flashggIdentifiedElectrons = flashggSelectedElectrons.clone( 
            src=cms.InputTag(eleSource),
            cut=cms.string(customize.eleId)
            )
    extraSysModules.append(
        cms.PSet( PhotonMethodName = cms.string("FlashggPhotonEleMatch"),
                  MethodName = cms.string("FlashggDiPhotonFromPhoton"),
                  Label = cms.string("eleMatch"),
                  NSigmas = cms.vint32(),
                  ApplyCentralValue = cms.bool(True),
                  electronsSrc = cms.InputTag("flashggIdentifiedElectrons"),
                  )
        )
    variables.extend( ["leadEleMatch    := leadingPhoton.hasUserCand('eleMatch')",
                       "subleadEleMatch := subLeadingPhoton.hasUserCand('eleMatch')"
                       ] )
    # store cut-based IDs
    for eid in "Loose", "Medium", "Tight":
        )
    ## for obj in ["Egm", "Jet"]:
    for obj in ["Egm"]:
        variables.extend(  ["leadL1%sMatch   := leadingPhoton.userInt('l1%sMatch')"                                                      % (obj,obj),                
                            "leadL1%sDr      := ?leadingPhoton.userInt('l1%sMatch')==1?leadingPhoton.userFloat('l1%sCandDR'):999."       % (obj,obj,obj),
                            "leadL1%sPt      := ?leadingPhoton.userInt('l1%sMatch')==1?leadingPhoton.userFloat('l1%sCandPt'):0."         % (obj,obj,obj),
                            "subleadL1%sMatch:= subLeadingPhoton.userInt('l1%sMatch')"                                                   % (obj,obj),                
                            "subleadL1%sDr   := ?subLeadingPhoton.userInt('l1%sMatch')==1?subLeadingPhoton.userFloat('l1%sCandDR'):999." % (obj,obj,obj),
                            "subleadL1%sPt   := ?subLeadingPhoton.userInt('l1%sMatch')==1?subLeadingPhoton.userFloat('l1%sCandPt'):0."   % (obj,obj,obj),
                            ] )

# electron matching
if invertEleVeto and customize.doeleId:
    from flashgg.MicroAOD.flashggLeptonSelectors_cff import flashggSelectedElectrons
    process.flashggIdentifiedElectrons = flashggSelectedElectrons.clone( 
        src=cms.InputTag("flashggSelectedElectrons"),
        cut=cms.string(customize.eleId)
        )
    # process.flashggSelectedElectrons.cut = customize.eleId
    extraSysModules.append(
        cms.PSet( PhotonMethodName = cms.string("FlashggPhotonEleMatch"),
                  MethodName = cms.string("FlashggDiPhotonFromPhoton"),
                  Label = cms.string("eleMatch"),
                  NSigmas = cms.vint32(),
                  ApplyCentralValue = cms.bool(True),
                  electronsSrc = cms.InputTag("flashggIdentifiedElectrons"),
                  )
        )
    variables.extend( ["leadEleMatch    := leadingPhoton.hasUserCand('eleMatch')",
                       "subleadEleMatch := subLeadingPhoton.hasUserCand('eleMatch')"
                       ] )
    # store cut-based IDs
# Get Trigger paths

matchTriggerPaths = []
dataTriggers = customize.options.trigger.split(",")
strippedNames = list(map(lambda x: x.rstrip("*"), dataTriggers))
matchTriggerPaths = "&& ".join(
    map(lambda x: "userInt('%s')" % x, strippedNames))
print(matchTriggerPaths)
dumpBits = list(strippedNames)

# ----------------------------------------------------------------------------------------------------
# Do electron ID

from flashgg.MicroAOD.flashggLeptonSelectors_cff import flashggSelectedElectrons
process.flashggIdentifiedElectrons = flashggSelectedElectrons.clone(
    src=cms.InputTag("flashggSelectedElectrons"),
    cut=cms.string("passTightId"))

# ----------------------------------------------------------------------------------------------------
# Do scale and smearing corrections

sysmodule = importlib.import_module(
    "flashgg.Systematics." +
    customize.metaConditions["flashggDiPhotonSystematics"])
systModules2D = cms.VPSet()
systModules = cms.VPSet()

if customize.processId == "Data":
    systModules.append(sysmodule.MCScaleHighR9EB_EGM)
    systModules.append(sysmodule.MCScaleLowR9EB_EGM)
    systModules.append(sysmodule.MCScaleHighR9EE_EGM)
                            "subleadL1%sDr   := ?subLeadingPhoton.userInt('l1%sMatch')==1?subLeadingPhoton.userFloat('l1%sCandDR'):999." % (obj,obj,obj),
                            "subleadL1%sPt   := ?subLeadingPhoton.userInt('l1%sMatch')==1?subLeadingPhoton.userFloat('l1%sCandPt'):0."   % (obj,obj,obj),
                            ] )
        if doSinglePho:
            variablesSinglePho.extend(
                ["phoL1%sMatch   := userInt('l1%sMatch')"                                        % (obj,obj),                
                 "phoL1%sDr      := ?userInt('l1%sMatch')==1?userFloat('l1%sCandDR'):999."       % (obj,obj,obj),
                 "phoL1%sPt      := ?userInt('l1%sMatch')==1?userFloat('l1%sCandPt'):0."         % (obj,obj,obj),
                 ]
                )
# electron matching
if invertEleVeto and customize.doeleId:
    from flashgg.MicroAOD.flashggLeptonSelectors_cff import flashggSelectedElectrons
    process.flashggIdentifiedElectrons = flashggSelectedElectrons.clone( 
#        src=cms.InputTag("flashggSelectedElectrons"),
        src=cms.InputTag("flashggElectrons"),
        cut=cms.string(customize.eleId)
        )
    # process.flashggSelectedElectrons.cut = customize.eleId
    extraSysModules.append(
        cms.PSet( PhotonMethodName = cms.string("FlashggPhotonEleMatch"),
                  MethodName = cms.string("FlashggDiPhotonFromPhoton"),
                  Label = cms.string("eleMatch"),
                  NSigmas = cms.vint32(),
                  ApplyCentralValue = cms.bool(True),
                  electronsSrc = cms.InputTag("flashggIdentifiedElectrons"),
                  )
        )
    variables.extend( ["leadEleMatch    := leadingPhoton.hasUserCand('eleMatch')",
                       "subleadEleMatch := subLeadingPhoton.hasUserCand('eleMatch')"
                       ] )