Esempio n. 1
0
def vbfgHfake(sample, rname):
    """
    VBF + photon had->photon fake control sample.
    """

    selector = vbfgBase(sample, rname)

    filename, suffix = selconf['hadronTFactorSource']

    hadproxyTightWeight = su.getFromFile(filename, 'tfactTight', 'tfactTight' + suffix)
    hadproxyLooseWeight = su.getFromFile(filename, 'tfactLoose', 'tfactLoose' + suffix)
    hadproxyPurityUpWeight = su.getFromFile(filename, 'tfactNomPurityUp', 'tfactNomPurityUp' + suffix)
    hadproxyPurityDownWeight = su.getFromFile(filename, 'tfactNomPurityDown', 'tfactNomPurityDown' + suffix)

    modHfake(selector)

    weight = selector.findOperator('hadProxyWeight')

    weight.addVariation('proxyDefUp', hadproxyTightWeight)
    weight.addVariation('proxyDefDown', hadproxyLooseWeight)
    weight.addVariation('purityUp', hadproxyPurityUpWeight)
    weight.addVariation('purityDown', hadproxyPurityDownWeight)

    photonSel = selector.findOperator('PhotonSelection')

    # Need to keep the cuts looser than nominal to accommodate proxyDefUp & Down
    # Proper cut applied at plotconfig as variations
    setupPhotonSelection(photonSel, changes = ['!CHIso', '+CHIso11', '-NHIso', '+NHIsoLoose', '-PhIso', '+PhIsoLoose'])
    setupPhotonSelection(photonSel, veto = True)

    return selector
Esempio n. 2
0
def addIDSFWeight(sample, selector):
    x, y, variables, (pvSF, pvUnc) = selconf['photonSF']

    if type(x) is str and type(y) is str:
        filename, histname = x, y
        logger.info('Adding photon ID scale factor from ' + filename)

        idsf = ROOT.IDSFWeight(ROOT.cPhotons, 'photonSF')
        idsf.addFactor(su.getFromFile(filename, histname, newname='photonSF'))
        variables_compiled = tuple(
            map(lambda s: getattr(ROOT.IDSFWeight, s), variables))
        idsf.setVariable(*variables_compiled)
        selector.addOperator(idsf)

    else:
        sf, unc = x, y
        logger.info('Adding numeric photon ID scale factor')

        idsf = ROOT.ConstantWeight(sf, 'photonSF')
        idsf.setUncertaintyUp(unc)
        idsf.setUncertaintyDown(unc)
        selector.addOperator(idsf)

    pvsf = ROOT.ConstantWeight(pvSF, 'pixelVetoSF')
    pvsf.setUncertaintyUp(pvUnc)
    pvsf.setUncertaintyDown(pvUnc)
    selector.addOperator(pvsf)
Esempio n. 3
0
def modEfake(selector, selections=[]):
    """Append PhotonPtWeight with eproxyWeight and set up the photon selections."""

    nom = selconf['electronTFactor']
    unc = selconf['electronTFactorUnc']

    if type(nom) is str:
        # nom = file.root/obj
        filename = nom[:nom.find('.root') + 5]
        objname = nom[nom.find('.root') + 6:]
        logger.info('Adding electron fake rate from %s/%s', filename, objname)

        eproxyWeight = su.getFromFile(filename, objname)
        weight = ROOT.PhotonPtWeight(eproxyWeight, 'egfakerate')
        selector.addOperator(weight)

        if unc:
            if type(unc) is bool:
                weight.useErrors(
                    True)  # use errors of eleproxyWeight as syst. variation
            else:
                up = su.getFromFile(filename, unc + 'Up')
                weight.addVariation('egfakerateUp', up)
                down = su.getFromFile(filename, unc + 'Down')
                weight.addVariation('egfakerateDown', down)

    elif type(nom) is float:
        frate = nom
        logger.info('Adding numeric electron fake rate %f +- %f', frate, unc)

        weight = ROOT.ConstantWeight(frate, 'egfakerate')
        weight.setUncertaintyUp(unc)
        weight.setUncertaintyDown(unc)
        selector.addOperator(weight)

    else:
        logger.info('Adding electron fake rate from TF1 ' + nom.GetTitle())

        # type is TF1
        weight = ROOT.PhotonPtWeight(nom, 'egfakerate')
        selector.addOperator(weight)

    photonSel = selector.findOperator('PhotonSelection')

    setupPhotonSelection(photonSel,
                         changes=selections + ['-EVeto', '-ChargedPFVeto'])
    setupPhotonSelection(photonSel, veto=True)
Esempio n. 4
0
def hfakeVtx(sample, rname):
    """
    Candidate-like but with inverted CHIso and vertex-adjusted proxy weighting.
    """

    selector = monophotonBase(sample, rname)

    filename, suffix = selconf['hadronTFactorSource']

    hadproxyTightWeight = su.getFromFile(filename, 'tfactTight',
                                         'tfactTight' + suffix)
    hadproxyLooseWeight = su.getFromFile(filename, 'tfactLoose',
                                         'tfactLoose' + suffix)
    hadproxyPurityUpWeight = su.getFromFile(filename, 'tfactNomPurityUp',
                                            'tfactNomPurityUp' + suffix)
    hadproxyPurityDownWeight = su.getFromFile(filename, 'tfactNomPurityDown',
                                              'tfactNomPurityDown' + suffix)

    isoTFactor = su.getFromFile(filename, 'tfactNom', 'tfactNom' + suffix)
    noIsoTFactor = su.getFromFile(datadir + '/hadronTFactorNoICH.root',
                                  'tfactNom')
    isoVertexScore = su.getFromFile(datadir + '/vertex_scores.root', 'iso')
    noIsoVertexScore = su.getFromFile(datadir + '/vertex_scores.root', 'noIso')
    rcProb = su.getFromFile(datadir + '/randomcone.root', 'chIso')

    vtxWeight = ROOT.VtxAdjustedJetProxyWeight(isoTFactor, isoVertexScore,
                                               noIsoTFactor, noIsoVertexScore)

    vtxWeight.setRCProb(rcProb, 1.163)
    vtxWeight.addVariation('proxyDefUp', hadproxyTightWeight)
    vtxWeight.addVariation('proxyDefDown', hadproxyLooseWeight)
    vtxWeight.addVariation('purityUp', hadproxyPurityUpWeight)
    vtxWeight.addVariation('purityDown', hadproxyPurityDownWeight)

    selector.addOperator(vtxWeight)

    photonSel = selector.findOperator('PhotonSelection')

    # Need to keep the cuts looser than nominal to accommodate proxyDefUp & Down
    # Proper cut applied at plotconfig as variations
    setupPhotonSelection(photonSel,
                         changes=[
                             '!CHIsoMax', '+CHIsoMax11', '-NHIso',
                             '+NHIsoLoose', '-PhIso', '+PhIsoLoose'
                         ])
    setupPhotonSelection(photonSel, veto=True)

    return selector
Esempio n. 5
0
def addElectronIDSFWeight(sample, selector):
    logger.info('Adding electron ID scale factor (ICHEP)')

    electronTightSF = su.getFromFile(
        datadir + '/egamma_electron_tight_SF_2016.root', 'EGamma_SF2D',
        'electronTightSF')  # x: sc eta, y: pt
    electronTrackSF = su.getFromFile(
        datadir + '/egamma_electron_reco_SF_2016.root', 'EGamma_SF2D',
        'electronTrackSF')  # x: sc eta, y: npv

    idsf = ROOT.IDSFWeight(ROOT.cElectrons, 'ElectronSF')
    idsf.addFactor(electronTightSF)
    idsf.setVariable(ROOT.IDSFWeight.kEta, ROOT.IDSFWeight.kPt)
    selector.addOperator(idsf)

    track = ROOT.IDSFWeight(ROOT.cElectrons, 'ElectronTrackSF')
    track.addFactor(electronTrackSF)
    track.setVariable(ROOT.IDSFWeight.kEta, ROOT.IDSFWeight.kNpv)
    selector.addOperator(track)
Esempio n. 6
0
def gghee(sample, rname):
    """
    GGH + double electron.
    """

    selector = gghlBase(sample, rname, ROOT.lElectron)
    selector.findOperator('LeptonSelection').setN(2, 0)

    dielMass = ROOT.Mass()
    dielMass.setPrefix('diel')
    dielMass.setMin(60.)
    dielMass.setMax(120.)
    dielMass.setCollection1(ROOT.cElectrons)
    dielMass.setCollection2(ROOT.cElectrons)
    dielMass.setIgnoreDecision(True)
    selector.addOperator(dielMass)

    dielSign = ROOT.OppositeSign()
    dielSign.setPrefix('diel')
    dielSign.setCollection1(ROOT.cElectrons)
    dielSign.setCollection2(ROOT.cElectrons)
    dielSign.setIgnoreDecision(True)
    selector.addOperator(dielSign)

    if not sample.data:
        electronLooseSF = su.getFromFile(
            datadir + '/egamma_electron_loose_SF_2016.root', 'EGamma_SF2D',
            'electronLooseSF')  # x: sc eta, y: pt
        electronTrackSF = su.getFromFile(
            datadir + '/egamma_electron_reco_SF_2016.root', 'EGamma_SF2D',
            'electronTrackSF')  # x: sc eta, y: npv

        idsf = selector.findOperator('ElectronSF')
        idsf.addFactor(electronLooseSF)
        idsf.setNParticles(2)

        track = selector.findOperator('ElectronTrackSF')
        track.addFactor(electronTrackSF)
        track.setNParticles(2)

    return selector
Esempio n. 7
0
def addMuonIDSFWeight(sample, selector):
    logger.info('Adding muon ID scale factor (ICHEP)')

    muonTightSF = su.getFromFile(datadir + '/muo_muon_idsf_2016.root',
                                 'Tight_ScaleFactor',
                                 'muonTightSF')  # x: abs eta, y: pt
    muonTrackSF = su.getFromFile(
        datadir + '/muonpog_muon_tracking_SF_ichep.root',
        'htrack2',
        'muonTrackSF',
    )  # x: npv

    idsf = ROOT.IDSFWeight(ROOT.cMuons, 'MuonSF')
    idsf.addFactor(muonTightSF)
    idsf.setVariable(ROOT.IDSFWeight.kAbsEta, ROOT.IDSFWeight.kPt)
    selector.addOperator(idsf)

    track = ROOT.IDSFWeight(ROOT.cMuons, 'MuonTrackSF')
    track.addFactor(muonTrackSF)
    track.setVariable(ROOT.IDSFWeight.kNpv)
    selector.addOperator(track)
Esempio n. 8
0
def gghmm(sample, rname):
    """
    GGH + single muon.
    """

    selector = gghlBase(sample, rname, ROOT.lMuon)
    selector.findOperator('LeptonSelection').setN(0, 2)

    dimuMass = ROOT.Mass()
    dimuMass.setPrefix('dimu')
    dimuMass.setMin(60.)
    dimuMass.setMax(120.)
    dimuMass.setCollection1(ROOT.cMuons)
    dimuMass.setCollection2(ROOT.cMuons)
    dimuMass.setIgnoreDecision(True)
    selector.addOperator(dimuMass)

    dimuSign = ROOT.OppositeSign()
    dimuSign.setPrefix('dimu')
    dimuSign.setCollection1(ROOT.cMuons)
    dimuSign.setCollection2(ROOT.cMuons)
    dimuSign.setIgnoreDecision(True)
    selector.addOperator(dimuSign)

    if not sample.data:
        muonLooseSF = su.getFromFile(datadir + '/muo_muon_idsf_2016.root',
                                     'Loose_ScaleFactor')  # x: abs eta, y: pt
        muonTrackSF = su.getFromFile(datadir +
                                     '/muonpog_muon_tracking_SF_ichep.root',
                                     'htrack2')  # x: npv

        idsf = selector.findOperator('MuonSF')
        idsf.addFactor(muonLooseSF)
        idsf.setNParticles(2)

        track = selector.findOperator('MuonTrackSF')
        track.addFactor(muonTrackSF)
        track.setNParticles(2)

    return selector
Esempio n. 9
0
def addQCDKfactor(sample, sname, selector):
    corr = su.getFromFile(datadir + '/kfactor.root',
                          sname,
                          newname=sname + '_kfactor')
    if not corr:
        raise RuntimeError('kfactor not found for ' + sample.name)

    qcd = ROOT.PhotonPtWeight(corr, 'QCDCorrection')
    if 'gj-' in sname:
        qcd.setPhotonType(ROOT.PhotonPtWeight.kPostShower)
    else:
        qcd.setPhotonType(ROOT.PhotonPtWeight.kParton)

    for variation in [
            'renUp', 'renDown', 'facUp', 'facDown', 'scaleUp', 'scaleDown'
    ]:
        vcorr = su.getFromFile(datadir + '/kfactor.root',
                               sname + '_' + variation)
        if vcorr:
            logger.info('applying qcd var %s %s', variation, sample.name)
            qcd.addVariation('qcd' + variation, vcorr)

    selector.addOperator(qcd)
Esempio n. 10
0
def addMuonVetoSFWeight(sample, selector):
    logger.info('Adding muon veto scale factor (ICHEP)')

    # made using misc/SFmerge.py
    muonVetoSF = su.getFromFile(datadir + '/muo_muon_idsf_2016.root',
                                'LooseVeto_ScaleFactor',
                                'muonVetoSF')  # x: abs eta, y: pt

    idsf = ROOT.IDSFWeight(ROOT.nCollections, 'MuonVetoSF')
    failingMuons = selector.findOperator('LeptonSelection').getFailingMuons()
    idsf.addCustomCollection(failingMuons)
    idsf.addFactor(muonVetoSF)
    idsf.setVariable(ROOT.IDSFWeight.kAbsEta, ROOT.IDSFWeight.kPt)
    selector.addOperator(idsf)
Esempio n. 11
0
def modHfake(selector):
    """Append PhotonPtWeight with hadProxyWeight and set up the photon selections."""

    filename, suffix = selconf['hadronTFactorSource']

    hadproxyWeight = su.getFromFile(filename, 'tfactNom', 'tfactNom' + suffix)

    weight = ROOT.PhotonPtWeight(hadproxyWeight, 'hadProxyWeight')
    weight.setPhotonType(ROOT.PhotonPtWeight.kReco)
    selector.addOperator(weight)

    photonSel = selector.findOperator('PhotonSelection')

    setupPhotonSelection(photonSel, changes=selconf['hadronProxyDef'])
    setupPhotonSelection(photonSel, veto=True)
Esempio n. 12
0
def addElectronVetoSFWeight(sample, selector):
    logger.info('Adding electron veto scale factor (ICHEP)')

    # made using misc/SFmerge.py
    electronVetoSF = su.getFromFile(
        datadir + '/egamma_electron_veto_SF_2016.root', 'EGamma_VetoSF2D',
        'electronVetoSF')  # x: sc eta, y: pt

    idsf = ROOT.IDSFWeight(ROOT.nCollections, 'ElectronVetoSF')
    failingElectrons = selector.findOperator(
        'LeptonSelection').getFailingElectrons()
    idsf.addCustomCollection(failingElectrons)
    idsf.addFactor(electronVetoSF)
    idsf.setVariable(ROOT.IDSFWeight.kEta, ROOT.IDSFWeight.kPt)
    selector.addOperator(idsf)
Esempio n. 13
0
def addEWKKfactor(sample, sname, selector):
    corrFile = selconf['ewkCorrSource']
    print corrFile

    if sname.startswith('znng'):
        logger.info('applying ewk %s', sample.name)

        corr = su.getFromFile(datadir + '/' + corrFile,
                              sname,
                              newname=sname + '_ewkcorr')
        ewk = ROOT.PhotonPtWeight(corr, 'EWKNLOCorrection')
        ewk.setPhotonType(ROOT.PhotonPtWeight.kParton)

        for variation in [
                'straightUp', 'straightDown', 'twistedUp', 'twistedDown',
                'gammaUp', 'gammaDown'
        ]:
            vcorr = su.getFromFile(datadir + '/' + corrFile,
                                   sname + '_' + variation)
            if vcorr:
                logger.info('applying ewk var %s %s', variation, sample.name)
                ewk.addVariation('ewk' + variation, vcorr)

        selector.addOperator(ewk)

    elif sample.name.startswith('wnlg'):
        logger.info('applying ewk %s', sample.name)

        suffix = '_p'
        corrp = su.getFromFile(datadir + '/' + corrFile,
                               sname + suffix,
                               newname=sname + suffix + '_ewkcorr')
        suffix = '_m'
        corrm = su.getFromFile(datadir + '/' + corrFile,
                               sname + suffix,
                               newname=sname + suffix + '_ewkcorr')

        ewk = ROOT.PhotonPtWeightSigned(corrp, corrm, 'EWKNLOCorrection')

        for variation in [
                'straightUp', 'straightDown', 'twistedUp', 'twistedDown',
                'gammaUp', 'gammaDown'
        ]:
            vcorrp = su.getFromFile(datadir + '/' + corrFile,
                                    sname + '_p_' + variation)
            vcorrm = su.getFromFile(datadir + '/' + corrFile,
                                    sname + '_m_' + variation)
            ewk.addVariation('ewk' + variation, vcorrp, vcorrm)

        selector.addOperator(ewk)