if runOnData:
    process.calibratedAK4PFJetsCHSForPFMVAMEt = cms.EDProducer(
        "PFJetCorrectionProducer",
        src=cms.InputTag("ak4PFJetsCHS"),
        correctors=cms.vstring("ak4PFCHSL1FastL2L3Residual"),
    )
else:
    process.calibratedAK4PFJetsCHSForPFMVAMEt = cms.EDProducer(
        "PFJetCorrectionProducer", src=cms.InputTag("ak4PFJetsCHS"), correctors=cms.vstring("ak4PFCHSL1FastL2L3")
    )

from RecoJets.JetProducers.PileupJetID_cfi import pileupJetId

process.puJetIdForPFMVAMEt = cms.EDProducer("PileupJetIdProducer", **pileupJetId.parameters_())
process.puJetIdForPFMVAMEt.vertexes = cms.InputTag("offlineSlimmedPrimaryVertices")
process.puJetIdForPFMVAMEt.jets = cms.InputTag("calibratedAK4PFJetsCHSForPFMVAMEt")

process.mvaMetSequence = cms.Sequence(
    process.leptonPreSelectionSequence
    + process.chs
    + process.ak4PFJetsCHS
    + process.calibratedAK4PFJetsCHSForPFMVAMEt
    + process.puJetIdForPFMVAMEt
    + process.mvaMETDiTau
    + process.mvaMETTauMu
    + process.mvaMETTauEle
    + process.mvaMETMuEle
    + process.mvaMETMuMu
    + process.mvaMETEleEle
  process.load("JetMETCorrections.Configuration.DefaultJEC_cff")

  if runOnData:
    process.calibratedAK4PFJetsCHSForPFMVAMEt = cms.EDProducer("PFJetCorrectionProducer",
                                                               src = cms.InputTag("ak4PFJetsCHS"),
                                                               correctors = cms.vstring('ak4PFCHSL1FastL2L3Residual')
                                                             )
  else:
    process.calibratedAK4PFJetsCHSForPFMVAMEt = cms.EDProducer("PFJetCorrectionProducer",
                                                               src = cms.InputTag("ak4PFJetsCHS"),
                                                               correctors = cms.vstring('ak4PFCHSL1FastL2L3')
                                                             )

  from RecoJets.JetProducers.PileupJetID_cfi import pileupJetId
  process.puJetIdForPFMVAMEt = cms.EDProducer("PileupJetIdProducer",
                                              **pileupJetId.parameters_())
  process.puJetIdForPFMVAMEt.vertexes = cms.InputTag("offlineSlimmedPrimaryVertices")
  process.puJetIdForPFMVAMEt.jets = cms.InputTag("calibratedAK4PFJetsCHSForPFMVAMEt")

  process.mvaMetSequence  = cms.Sequence(process.leptonPreSelectionSequence +
                                         process.chs + process.ak4PFJetsCHS + process.calibratedAK4PFJetsCHSForPFMVAMEt +
                                         process.puJetIdForPFMVAMEt +
                                         process.mvaMETDiTau + process.mvaMETTauMu + process.mvaMETTauEle + process.mvaMETMuEle + 
                                         process.mvaMETMuMu + process.mvaMETEleEle)


# END Pairwise MVA MET ==============================================================

########### HBHE

    process.load("JetMETCorrections.Configuration.DefaultJEC_cff")

    if runOnData:
        process.calibratedAK4PFJetsCHSForPFMVAMEt = cms.EDProducer(
            "PFJetCorrectionProducer",
            src=cms.InputTag("ak4PFJetsCHS"),
            correctors=cms.vstring('ak4PFCHSL1FastL2L3Residual'))
    else:
        process.calibratedAK4PFJetsCHSForPFMVAMEt = cms.EDProducer(
            "PFJetCorrectionProducer",
            src=cms.InputTag("ak4PFJetsCHS"),
            correctors=cms.vstring('ak4PFCHSL1FastL2L3'))

    from RecoJets.JetProducers.PileupJetID_cfi import pileupJetId
    process.puJetIdForPFMVAMEt = cms.EDProducer("PileupJetIdProducer",
                                                **pileupJetId.parameters_())
    process.puJetIdForPFMVAMEt.vertexes = cms.InputTag(
        "offlineSlimmedPrimaryVertices")
    process.puJetIdForPFMVAMEt.jets = cms.InputTag(
        "calibratedAK4PFJetsCHSForPFMVAMEt")

    process.mvaMetSequence = cms.Sequence(
        process.leptonPreSelectionSequence + process.chs +
        process.ak4PFJetsCHS + process.calibratedAK4PFJetsCHSForPFMVAMEt +
        process.puJetIdForPFMVAMEt + process.mvaMETDiTau +
        process.mvaMETTauMu + process.mvaMETTauEle + process.mvaMETMuEle +
        process.mvaMETMuMu + process.mvaMETEleEle)

# END Pairwise MVA MET ==============================================================

########### HBHE