import FWCore.ParameterSet.Config as cms
from Configuration.Generator.Pythia8CommonSettings_cfi import *
from Configuration.Generator.Pythia8CUEP8M1Settings_cfi import *
from Configuration.Generator.Pythia8PowhegEmissionVetoSettings_cfi import *

generator = cms.EDFilter("Pythia8HadronizerFilter",
                         maxEventsToPrint = cms.untracked.int32(1),
                         pythiaPylistVerbosity = cms.untracked.int32(1),
                         filterEfficiency = cms.untracked.double(1.0),
                         pythiaHepMCVerbosity = cms.untracked.bool(False),
                         comEnergy = cms.double(13000.),
                         PythiaParameters = cms.PSet(
        pythia8CommonSettingsBlock,
        pythia8CUEP8M1SettingsBlock,
        pythia8PowhegEmissionVetoSettingsBlock,
        processParameters = cms.vstring(
            'POWHEG:nFinal = 3',   ## Number of final state particles
                                   ## (BEFORE THE DECAYS) in the LHE
                                   ## other than emitted extra parton
          ),
        parameterSets = cms.vstring('pythia8CommonSettings',
                                    'pythia8CUEP8M1Settings',
                                    'pythia8PowhegEmissionVetoSettings',
                                    'processParameters'
                                    )
        )
                         )

ProductionFilterSequence = cms.Sequence(generator)

genParticlesForFilter = cms.EDProducer("GenParticleProducer",
  saveBarCodes = cms.untracked.bool(True),
  src = cms.InputTag("generator"),
  abortOnUnknownPDGCode = cms.untracked.bool(False)
)

genSelectorFourLep = cms.EDFilter("GenParticleSelector",
  filter = cms.bool(True),
  src = cms.InputTag('genParticlesForFilter'),
  cut = cms.string('(abs(pdgId()) == 11 || abs(pdgId()) == 13 || abs(pdgId()) == 15) && (mother().pdgId() == 23 || abs(mother().pdgId()) == 24)'),
)

selectedFourLepCandFilter = cms.EDFilter("CandViewCountFilter",
   src = cms.InputTag('genSelectorFourLep'),
   filter = cms.bool(True),
   minNumber = cms.uint32(4)
)

ProductionFilterSequence = cms.Sequence(generator * (genParticlesForFilter + genSelectorFourLep + selectedFourLepCandFilter))