Ejemplo n.º 1
0
    log.warning(
        'AOD is not supported for doPhoID, please consider using miniAOD')
if varOptions.isAOD and varOptions.doTrigger:
    log.warning(
        'AOD is not supported for doTrigger, please consider using miniAOD')
if not varOptions.isAOD and varOptions.doRECO:
    log.warning(
        'miniAOD is not supported for doRECO, please consider using AOD')

from EgammaAnalysis.TnPTreeProducer.cmssw_version import isReleaseAbove
if varOptions.era not in [
        '2016', '2017', '2018', 'UL2016preVFP', 'UL2016postVFP', 'UL2017',
        'UL2018'
]:
    log.error('%s is not a valid era' % varOptions.era)
if ('UL' in varOptions.era) != (isReleaseAbove(10, 6)):
    log.error(
        'Inconsistent release for era %s. Use CMSSW_10_6_X for UL and CMSSW_10_2_X for rereco'
        % varOptions.era)

if varOptions.includeSUSY: log.info('Including variables for SUSY')
if varOptions.doEleID: log.info('Producing electron SF tree')
if varOptions.doPhoID: log.info('Producing photon SF tree')
if varOptions.doTrigger:
    log.info('Producing HLT (trigger ele) efficiency tree')
if varOptions.doRECO: log.info('Producing RECO SF tree')

###################################################################
## Define TnP inputs
###################################################################
def setIDs(process, options):

    switchOnVIDElectronIdProducer(
        process, DataFormat.AOD if options['useAOD'] else DataFormat.MiniAOD)

    # define which IDs we want to produce
    my_id_modules = [
        'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff',
        'RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV60_cff',
        'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff',
        'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V1_cff',
        'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V1_cff',
        'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V1_cff',
        'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff',
        'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff',
        'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Fall17_94X_V2_cff'
    ]

    ### add only miniAOD supported IDs
    if not options['useAOD']:
        my_id_modules.append(
            'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronHLTPreselecition_Summer16_V1_cff'
        )
        my_id_modules.append(
            'EgammaAnalysis.TnPTreeProducer.Identification.cutBasedDoubleElectronHLTPreselecition_Summer16_V1_cff'
        )

    for idmod in my_id_modules:
        setupAllVIDIdsInModule(process, idmod, setupVIDElectronSelection)

    process.egmGsfElectronIDs.physicsObjectSrc = cms.InputTag(
        options['ELECTRON_COLL'])
    process.electronMVAValueMapProducer.src = cms.InputTag(
        options['ELECTRON_COLL'])

    if not isReleaseAbove(10, 6):  # only for CMSSW_10_2
        process.electronRegressionValueMapProducer.srcMiniAOD = cms.InputTag(
            options['ELECTRON_COLL'])

    #
    # One tag module --> cut based tight 94X V2
    #
    process.tagEleCutBasedTight = cms.EDProducer(
        'GsfElectronSelectorByValueMap'
        if options['useAOD'] else 'PatElectronSelectorByValueMap',
        input=cms.InputTag("goodElectrons"),
        cut=cms.string(options['ELECTRON_TAG_CUTS']),
        selection=cms.InputTag(
            "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-tight"),
        id_cut=cms.bool(True))

    #
    # Add many probe modules, use the PatElectronNm1Selector in case we want to check the effect of one cut
    #
    def addNewProbeModule(sequence, name, inputTag, cutNamesToMask=None):
        if cutNamesToMask:
            temp = cms.EDProducer(
                'PatElectronNm1Selector',
                input=cms.InputTag("goodElectrons"),
                cut=cms.string(options['ELECTRON_CUTS']),
                selection=cms.InputTag(inputTag),
                cutNamesToMask=cutNamesToMask,
            )
        else:
            temp = cms.EDProducer(
                'GsfElectronSelectorByValueMap'
                if options['useAOD'] else 'PatElectronSelectorByValueMap',
                input=cms.InputTag("goodElectrons"),
                cut=cms.string(options['ELECTRON_CUTS']),
                selection=cms.InputTag(inputTag),
                id_cut=cms.bool(True))
        setattr(process, 'probeEle%s' % name, temp)
        sequence += temp

    probeSequence = cms.Sequence()
    if not options['useAOD']:
        addNewProbeModule(
            probeSequence, 'HLTsafe',
            'egmGsfElectronIDs:cutBasedElectronHLTPreselection-Summer16-V1')
        addNewProbeModule(
            probeSequence, 'DoubleEleHLTsafe',
            'egmGsfElectronIDs:cutBasedDoubleElectronHLTPreselection-Summer16-V1'
        )

    for wp in ['Veto', 'Loose', 'Medium', 'Tight']:
        addNewProbeModule(
            probeSequence, 'CutBased%s80X' % wp,
            'egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-%s' %
            wp.lower())
        addNewProbeModule(
            probeSequence, 'CutBased%s94X' % wp,
            'egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V1-%s' %
            wp.lower())
        addNewProbeModule(
            probeSequence, 'CutBased%s94XV2' % wp,
            'egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-%s' %
            wp.lower())

    for wp in ['wp80', 'wp90']:
        addNewProbeModule(
            probeSequence, 'MVA80X%s' % wp,
            'egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-%s' % wp)

    for wp in ['wp80', 'wp90', 'wpLoose']:
        addNewProbeModule(probeSequence, 'MVA94X%snoiso' % wp,
                          'egmGsfElectronIDs:mvaEleID-Fall17-noIso-V1-%s' % wp)
        addNewProbeModule(probeSequence, 'MVA94X%siso' % wp,
                          'egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-%s' % wp)
        addNewProbeModule(probeSequence, 'MVA94X%snoisoV2' % wp,
                          'egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-%s' % wp)
        addNewProbeModule(probeSequence, 'MVA94X%sisoV2' % wp,
                          'egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-%s' % wp)

    addNewProbeModule(probeSequence, 'MVA94XwpHZZisoV2',
                      'egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wpHZZ')

    #
    # For cut based 94X V2, also check partial cuts
    #
    allCuts = [
        "MinPt", "GsfEleSCEtaMultiRange", "GsfEleDEtaInSeed", "GsfEleDPhiIn",
        "GsfEleFull5x5SigmaIEtaIEta", "GsfEleHadronicOverEMEnergyScaled",
        "GsfEleEInverseMinusPInverse", "GsfEleRelPFIsoScaled",
        "GsfEleConversionVeto", "GsfEleMissingHits"
    ]

    for cut in allCuts:
        otherCuts = cms.vstring([i + 'Cut_0' for i in allCuts if i != cut])
        for wp in ['Veto', 'Loose', 'Medium', 'Tight']:
            addNewProbeModule(
                probeSequence,
                'CutBased%s94XV2%sCut' % (wp, cut),
                'egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V2-%s' %
                wp.lower(),
                cutNamesToMask=otherCuts)

    #
    # Optional: SUSY variables (broken?)
    #
    if options['addSUSY']:
        from EgammaAnalysis.TnPTreeProducer.electronsExtrasSUSY_cff import workingPoints
        for wp in workingPoints:
            addNewProbeModule(probeSequence, wp, 'susyEleVarHelper:pass' + wp)

    return probeSequence
def setIDs(process, options):

    switchOnVIDPhotonIdProducer(
        process, DataFormat.AOD if options['useAOD'] else DataFormat.MiniAOD)

    # define which IDs we want to produce
    my_id_modules = [
        'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff',
        'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff',
        'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V1_cff',
        'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V2_cff',
        'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Fall17_94X_V2_cff'
    ]

    if not isReleaseAbove(10, 6):  # (photon mva 94X_V1 broken in CMSSW_10_6_X)
        my_id_modules += [
            'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Fall17_94X_V1_cff'
        ]
    else:  # (only needed in CMSSW_10_6_X
        process.load(
            "RecoEgamma.PhotonIdentification.photonIDValueMapProducer_cff")

    for idmod in my_id_modules:
        setupAllVIDIdsInModule(process, idmod, setupVIDPhotonSelection)

    process.egmPhotonIDs.physicsObjectSrc = cms.InputTag(
        options['PHOTON_COLL'])
    process.photonIDValueMapProducer.srcMiniAOD = cms.InputTag(
        options['PHOTON_COLL'])
    process.photonMVAValueMapProducer.srcMiniAOD = cms.InputTag(
        options['PHOTON_COLL'])

    #    process.photonMVAValueMapProducer.src        = cms.InputTag(options['PHOTON_COLL'])

    #
    # Add many probe modules, use the PatPhotonNm1Selector in case we want to check the effect of one cut
    #
    def addNewProbeModule(sequence, name, inputTag, cutNamesToMask=None):
        if cutNamesToMask:
            temp = cms.EDProducer(
                'PatPhotonNm1Selector',
                input=cms.InputTag("goodPhotons"),
                cut=cms.string(options['PHOTON_CUTS']),
                selection=cms.InputTag(inputTag),
                cutNamesToMask=cutNamesToMask,
            )
        else:
            temp = cms.EDProducer(
                'PhotonSelectorByValueMap'
                if options['useAOD'] else 'PatPhotonSelectorByValueMap',
                input=cms.InputTag("goodPhotons"),
                cut=cms.string(options['PHOTON_CUTS']),
                selection=cms.InputTag(inputTag),
                id_cut=cms.bool(True))
        setattr(process, 'probePho%s' % name, temp)
        sequence += temp

    probeSequence = cms.Sequence()
    for wp in ['Loose', 'Medium', 'Tight']:
        addNewProbeModule(
            probeSequence, 'CutBased%s80X' % wp,
            'egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-%s' % wp.lower())
        addNewProbeModule(
            probeSequence, 'CutBased%s94X' % wp,
            'egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V1-%s' % wp.lower())
        addNewProbeModule(
            probeSequence, 'CutBased%s94XV2' % wp,
            'egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-%s' % wp.lower())

    for wp in ['wp80', 'wp90']:
        addNewProbeModule(probeSequence, 'MVA80X%s' % wp,
                          'egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-%s' % wp)
        addNewProbeModule(probeSequence, 'MVA94XV2%s' % wp,
                          'egmPhotonIDs:mvaPhoID-RunIIFall17-v2-%s' % wp)
        if not isReleaseAbove(10, 6):
            addNewProbeModule(probeSequence, 'MVA94X%s' % wp,
                              'egmPhotonIDs:mvaPhoID-RunIIFall17-v1-%s' % wp)

    #
    # For cut based 94X V2, also check partial cuts
    #
    if isReleaseAbove(10, 6):  # (name change of cuts)
        allCuts = [
            "MinPtCut_0", "PhoSCEtaMultiRangeCut_0",
            "PhoSingleTowerHadOverEmCut_0", "PhoFull5x5SigmaIEtaIEtaCut_0",
            "PhoGenericRhoPtScaledCut_0", "PhoGenericRhoPtScaledCut_1",
            "PhoGenericRhoPtScaledCut_2"
        ]
    else:
        allCuts = [
            "MinPtCut_0", "PhoSCEtaMultiRangeCut_0",
            "PhoSingleTowerHadOverEmCut_0", "PhoFull5x5SigmaIEtaIEtaCut_0",
            "PhoAnyPFIsoWithEACut_0", "PhoAnyPFIsoWithEAAndQuadScalingCut_0",
            "PhoAnyPFIsoWithEACut_1"
        ]

    for cut in allCuts:
        otherCuts = cms.vstring([i for i in allCuts if i != cut])
        cutName = cut.replace('_', '').replace(
            '0', '')  # special case for the PhoAnyPFIsoWithEACut_1
        for wp in ['Loose', 'Medium', 'Tight']:
            addNewProbeModule(
                probeSequence,
                'CutBased%s94XV2%s' % (wp, cutName),
                'egmPhotonIDs:cutBasedPhotonID-Fall17-94X-V2-%s' % wp.lower(),
                cutNamesToMask=otherCuts)

    return probeSequence
    ph_mva80X=cms.InputTag(
        "photonMVAValueMapProducer:PhotonMVAEstimatorRun2Spring16NonTrigV1Values"
    ),
    ph_mva94X=cms.InputTag(
        "photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v1p1Values"),
    ph_mva94XV2=cms.InputTag(
        "photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v2Values"),

    # iso
    ph_chIso=cms.string("chargedHadronIso"),
    ph_neuIso=cms.string("neutralHadronIso"),
    ph_phoIso=cms.string("photonIso"),
    ph_chWorIso=cms.string("chargedHadronWorstVtxIso"),
)

if not isReleaseAbove(10, 6):  # old way of accessing these in CMSSW_10_2
    PhoProbeVariablesToStore.ph_sieip = cms.InputTag(
        "photonIDValueMapProducer:phoFull5x5SigmaIEtaIPhi")
    PhoProbeVariablesToStore.ph_ESsigma = cms.InputTag(
        "photonIDValueMapProducer:phoESEffSigmaRR")
    PhoProbeVariablesToStore.ph_chIso = cms.InputTag(
        "photonIDValueMapProducer:phoChargedIsolation")
    PhoProbeVariablesToStore.ph_neuIso = cms.InputTag(
        "photonIDValueMapProducer:phoNeutralHadronIsolation")
    PhoProbeVariablesToStore.ph_phoIso = cms.InputTag(
        "photonIDValueMapProducer:phoPhotonIsolation")
    PhoProbeVariablesToStore.ph_chWorIso = cms.InputTag(
        "photonIDValueMapProducer:phoWorstChargedIsolation")

TagVariablesToStore = cms.PSet(
    Ele_eta=cms.string("eta"),
            p.join()
    else:
        p = Process(target=submit,
                    args=(config, requestName, sample, era, getLumiMask(era),
                          extraParam))
        p.start()
        p.join()


#
# List of samples to submit, with eras
# Here the default data/MC for UL and rereco are given (taken based on the release environment)
# If you would switch to AOD, don't forget to add 'isAOD=True' to the defaultArgs!
#
from EgammaAnalysis.TnPTreeProducer.cmssw_version import isReleaseAbove
if isReleaseAbove(10, 6):
    era = 'UL2016preVFP'
    submitWrapper(
        'Run2016B',
        '/SingleElectron/Run2016B-21Feb2020_ver2_UL2016_HIPM-v1/MINIAOD', era)
    submitWrapper('Run2016C',
                  '/SingleElectron/Run2016C-21Feb2020_UL2016_HIPM-v1/MINIAOD',
                  era)
    submitWrapper('Run2016D',
                  '/SingleElectron/Run2016D-21Feb2020_UL2016_HIPM-v1/MINIAOD',
                  era)
    submitWrapper('Run2016E',
                  '/SingleElectron/Run2016E-21Feb2020_UL2016_HIPM-v1/MINIAOD',
                  era)
    submitWrapper('Run2016F',
                  '/SingleElectron/Run2016F-21Feb2020_UL2016_HIPM-v1/MINIAOD',