def makeEffPlot(fs, sp, quantity, region):
    if sp is None:
        hDen = HG.getAddedSignalHistograms(
            FILES[fs], fs,
            '{}-Den-{}'.format(quantity,
                               region))['{}-Den-{}'.format(quantity, region)]
        hNum = HG.getAddedSignalHistograms(
            FILES[fs], fs,
            '{}-Eff-{}'.format(quantity,
                               region))['{}-Eff-{}'.format(quantity, region)]
        prettyFS = '2#mu' if '2Mu' in fs else '4#mu'
        lumi = 'H#rightarrow2X#rightarrow{}, all samples combined{}{}'.format(
            prettyFS, ' + trigger' if ARGS.TRIGGER else '',
            ' wrt acc.' if region == 'Acc' else '')
    else:
        hDen = HG.getHistogram(FILES[fs], (fs, sp),
                               '{}-Den-{}'.format(quantity, region)).Clone()
        hNum = HG.getHistogram(FILES[fs], (fs, sp),
                               '{}-Eff-{}'.format(quantity, region)).Clone()
        prettyFS = '2#mu' if '2Mu' in fs else '4#mu'
        lumi = 'H#rightarrow2X#rightarrow{} ({} GeV, {} GeV, {} mm){}{}'.format(
            prettyFS, sp[0], sp[1], sp[2],
            ' + trigger' if ARGS.TRIGGER else '',
            ' wrt acc.' if region == 'Acc' else '')

    spstr = '{:4d} {:3d} {:4d}'.format(
        *sp) if sp is not None else '{:4s} {:3s} {:4s}'.format('', '', '')
    hNumInt = hNum.Integral(0, hNum.GetNbinsX() + 1)
    hDenInt = hDen.Integral(0, hDen.GetNbinsX() + 1)
    print '\033[m{:19s} {:5s} {:3s} {:13s} {:6.0f} {:6.0f} {:6.2%}\033[m'.format(
        ARGS.TAG, quantity, region, spstr, hNumInt, hDenInt, hNumInt / hDenInt)
def makeEffPlot(fs, sp):
    if sp is None:
        hNum = HG.getAddedSignalHistograms(FILES[fs], fs, 'Lxy-Num')['Lxy-Num']
        hDen = HG.getAddedSignalHistograms(FILES[fs], fs, 'Lxy-Den')['Lxy-Den']
    else:
        hNum = HG.getHistogram(FILES[fs], (fs, sp), 'Lxy-Num').Clone()
        hDen = HG.getHistogram(FILES[fs], (fs, sp), 'Lxy-Den').Clone()

        hNumInt = hNum.Integral(hNum.GetXaxis().FindBin(65.),
                                hNum.GetNbinsX() + 1)
        hDenInt = hDen.Integral(hDen.GetXaxis().FindBin(65.),
                                hDen.GetNbinsX() + 1)

        #if sp == (sp[0], sp[1], SIGNALS[sp[0]][sp[1]][0]): return
        print '{:5s} {:4d} {:3d} {:4d} ::: {:5.0f} {:5.0f} {:7.2%}'.format(
            fs, sp[0], sp[1], sp[2], hNumInt, hDenInt,
            hNumInt / hDenInt if hDenInt != 0. else 0.)

        return

    hNum.Rebin(2)
    hDen.Rebin(2)

    g = R.TGraphAsymmErrors(hNum, hDen, 'cp')

    p = Plotter.Plot(g, '', '', 'p')

    prettyFS = '2#mu' if '2Mu' in fs else '4#mu'
    if sp is not None:
        lumi = 'H#rightarrow2X#rightarrow{} ({} GeV, {} GeV, {} mm)'.format(
            prettyFS, *sp)
    else:
        lumi = 'H#rightarrow2X#rightarrow{}, all samples combined'.format(
            prettyFS)
    c = Plotter.Canvas(lumi=lumi, cWidth=600 if ARGS.SQUARE else 800)

    c.addMainPlot(p)
    p.setColor(R.kBlue, which='LM')

    c.firstPlot.SetMinimum(0.)
    c.firstPlot.SetMaximum(1.)
    c.firstPlot.setTitles(X='', copy=hNum)
    c.firstPlot.setTitles(
        Y='Efficiency for pairing criteria to select correct dimuons')

    if ARGS.SQUARE:
        c.firstPlot.scaleTitleOffsets(1.1, 'X')
    c.cleanup('pdfs/PC_Lxy_{}_{}.pdf'.format(
        fs, 'Global' if sp is None else SPStr(sp)),
              mode='LUMI')
def makeLxyPlot():
    hkeys = ['Lxy_{}'.format(tag) for tag in TAGS]
    HISTS = HG.getAddedSignalHistograms(FILES['Signal'], '2Mu2J', hkeys)

    for key in hkeys:
        HISTS[key].Rebin(10)

    g = {}
    for tag in TAGS:
        g[tag] = R.TGraphAsymmErrors(HISTS['Lxy_{}'.format(tag)], HISTS['Lxy_1'], 'cp')

    p = {tag:Plotter.Plot(g[tag], TAGS[tag]['leg'], 'lp', 'p') for tag in TAGS}

    c = Plotter.Canvas()
    for tag in ('1', '34', '23', '12'):
        c.addMainPlot(p[tag])
        p[tag].setColor(TAGS[tag]['col'])

    c.makeLegend(lWidth=0.2, pos='bl')

    c.firstPlot.setTitles(X='', Y='', copy=HISTS[hkeys[0]])
    c.firstPlot.SetMinimum(0.8)
    c.firstPlot.SetMaximum(1.01)

    c.cleanup('Lxy_deltaR.pdf')
Пример #4
0
def makeLxyResVSLxyPlot(recoType):
    key = recoType + '-LxyResVSgenLxy'
    HISTS = HG.getAddedSignalHistograms(FILE, fs, (key,))

    upperEdge = 35
    xPoints = map(lambda z: float(z)+0.5, range(upperEdge))
    xError = [0.5] * len(xPoints)

    yPoints = []
    yError = []
    for ibin in xrange(1,upperEdge+1):
        h = HISTS[key].ProjectionY('h'+str(ibin), ibin, ibin)
        #lims = .01
        lims = 5. if recoType == 'DSA' else .05
        if recoType == 'PAT' and ibin > 10:
            lims = lims/5.
        func = R.TF1('f', 'gaus', -lims, lims)
        h.Fit('f', 'R')
        yPoints.append(func.GetParameter(2))
        yError.append(func.GetParError(2))

    g = R.TGraphErrors(len(xPoints), np.array(xPoints), np.array(yPoints), np.array(xError), np.array(yError))
    p = Plotter.Plot(g, '', '', 'pe')
    p.setTitles(X='gen L_{xy} [cm]', Y='Fitted #sigma L_{xy} Res. [cm]')

    canvas = Plotter.Canvas(lumi=fs)
    canvas.addMainPlot(p)
    if recoType == 'PAT':
        canvas.firstPlot.SetMaximum(0.020)
        canvas.firstPlot.SetMinimum(0.000)
    canvas.cleanup('pdfs/ResVSLxy_{}.pdf'.format(recoType))
Пример #5
0
def makeSignalPlot(hkey):
    HISTS = HG.getAddedSignalHistograms(FILES['2Mu2J'], '2Mu2J', hkey)
    h = HISTS[hkey]
    p = Plotter.Plot(h, '', '', 'hist')
    canvas = Plotter.Canvas(lumi='Signal: H#rightarrow2X#rightarrow2#mu + *',
                            logy=True if hkey != 'nDTHits' else False)
    canvas.addMainPlot(p)
    p.SetLineColor(R.kBlue)
    canvas.firstPlot.SetMinimum(0.9)
    pave = canvas.makeStatsBox(p, color=R.kBlue)
    if hkey in ('nHits', 'LxySig'):
        Plotter.MOVE_OBJECT(pave, Y=-.3)
    canvas.mainPad.Update()
    if canvas.logy:
        line = R.TLine(
            CONFIG[hkey]['val'], canvas.firstPlot.GetMinimum(),
            CONFIG[hkey]['val'],
            10.**(R.TMath.Log10(canvas.firstPlot.GetMaximum()) * 1.06))
    else:
        line = R.TLine(CONFIG[hkey]['val'], canvas.firstPlot.GetMinimum(),
                       CONFIG[hkey]['val'],
                       canvas.firstPlot.GetMaximum() * 1.05)
    line.Draw()
    line.SetLineStyle(2)
    print '\033[31m{:6s} {:8s} {:5.0f} {:5.0f} {:7.2%}\033[m'.format(
        'Signal', hkey, *fractionCut(hkey, canvas.firstPlot.plot))
    RT.addBinWidth(canvas.firstPlot)
    canvas.cleanup('pdfs/NM1D_{}_2Mu2J.pdf'.format(hkey))
def makeLxyPlot():
    hkeys = ['Lxy_{}'.format(tag) for tag in TAGS]
    HISTS = HG.getAddedSignalHistograms(FILES['Signal'], '2Mu2J', hkeys)

    for key in hkeys:
        HISTS[key].Rebin(20)

    print HISTS['Lxy_before'].Integral(HISTS['Lxy_before'].GetXaxis().FindBin(100.), HISTS['Lxy_before'].GetNbinsX()+1), \
          HISTS['Lxy_after' ].Integral(HISTS['Lxy_after' ].GetXaxis().FindBin(100.), HISTS['Lxy_after' ].GetNbinsX()+1)

    g = {}
    g['plot'] = R.TGraphAsymmErrors(HISTS['Lxy_after'], HISTS['Lxy_before'], 'cp')

    p = {}
    p['plot'] = Plotter.Plot(g['plot'], '', '', 'p')

    #p = {tag:Plotter.Plot(g[tag], TAGS[tag]['leg'], 'lp', 'hist p') for tag in TAGS}

    c = Plotter.Canvas()
    c.addMainPlot(p['plot'])
    p['plot'].setColor(R.kBlue)

    c.firstPlot.setTitles(X='', Y='', copy=HISTS[hkeys[0]])
    c.firstPlot.SetMinimum(0.95)
    c.firstPlot.SetMaximum(1.01)

    c.firstPlot.GetXaxis().SetRangeUser(0., 400.)

    c.cleanup('Lxy_globalDeltaR.pdf')
def makeDSASignal2DPlots():
    for quantity in ('pT', 'eta', 'trkChi2'):

        hkey = 'DSA-12-' + quantity
        HISTS = HG.getAddedSignalHistograms(FILES[fs], fs, (hkey, ))
        if 'trkChi2' not in hkey: HISTS[hkey].Rebin2D(10, 10)
        for sp in SIGNALPOINTS:
            HISTS[sp] = HG.getHistogram(FILES[fs], (fs, sp), hkey).Clone()
            if 'trkChi2' not in hkey: HISTS[sp].Rebin2D(10, 10)

        opt = 'colz'
        #opt = 'scat=0.2'
        PLOTS = {hkey: Plotter.Plot(HISTS[hkey], '', '', opt)}
        for sp in SIGNALPOINTS:
            PLOTS[sp] = Plotter.Plot(HISTS[sp], '', '', opt)

        for sp in [
                hkey,
        ] + SIGNALPOINTS:
            canvas = Plotter.Canvas(lumi=fs + lumiExtra.get(CUTSTRING) if
                                    type(sp) != tuple else SPLumiStr(fs, *sp))
            canvas.addMainPlot(PLOTS[sp])
            canvas.mainPad.SetLogz()

            if quantity == 'trkChi2':
                canvas.firstPlot.GetXaxis().SetRangeUser(0., 10.)
                canvas.firstPlot.GetYaxis().SetRangeUser(0., 10.)

            canvas.scaleMargins(1.75, edges='R')
            canvas.scaleMargins(0.8, edges='L')
            canvas.cleanup('pdfs/ZEP_2D_{}_{}_{}_{}.pdf'.format(
                quantity, CUTSTRING, fs,
                'Global' if type(sp) != tuple else SPStr(sp)))
Пример #8
0
def makeTestPlot():
    hkey = 'DSA-deltaPhi'
    HISTS = HG.getAddedSignalHistograms(FILES['2Mu2J'], '2Mu2J',
                                        ('deltaPhi', ))
    DATAHISTS, DataPConfig = HG.getDataHistograms(FILES['Data'], hkey)

    HISTS[hkey] = HISTS['deltaPhi']

    pS = Plotter.Plot(HISTS[hkey], 'H#rightarrow2X#rightarrow2#mu signal', 'l',
                      'hist')
    pD = Plotter.Plot(DATAHISTS[hkey]['data'], *DataPConfig[hkey]['data'])

    canvas = Plotter.Canvas(lumi='2#mu signal + 10% of 2016 data', logy=True)

    canvas.addMainPlot(pS)
    canvas.addMainPlot(pD)

    pS.setColor(R.kBlue, which='L')

    canvas.makeLegend(lWidth=.25)
    canvas.legend.resizeHeight()
    canvas.legend.moveLegend(X=-.1)

    canvas.firstPlot.SetMinimum(0.5)
    canvas.firstPlot.SetMaximum(50000.)
    canvas.firstPlot.setTitles(Y='Long-Lived Candidates')

    line = R.TLine(R.TMath.Pi() / 2., 0.5, R.TMath.Pi() / 2., 50000.)
    line.Draw()
    line.SetLineStyle(2)

    RT.addBinWidth(canvas.firstPlot)
    canvas.cleanup('deltaPhi.pdf')
def makeEffPlot(fs, sp):
    if sp is None:
        hNum = HG.getAddedSignalHistograms(FILES[fs], fs,
                                           ['nRec' + MUON for MUON in MUONS])
        hDen = HG.getAddedSignalHistograms(FILES[fs], fs,
                                           ['nGen' + MUON for MUON in MUONS])
        prettyFS = '2#mu' if '2Mu' in fs else '4#mu'
        lumi = 'H#rightarrow2X#rightarrow{}, all samples combined{}'.format(
            prettyFS, ' + trigger' if ARGS.TRIGGER else '')
    else:
        hNum, hDen = {}, {}
        for MUON in MUONS:
            hNum['nRec' + MUON] = HG.getHistogram(FILES[fs], (fs, sp),
                                                  'nRec' + MUON).Clone()
            hDen['nGen' + MUON] = HG.getHistogram(FILES[fs], (fs, sp),
                                                  'nGen' + MUON).Clone()
        prettyFS = '2#mu' if '2Mu' in fs else '4#mu'
        lumi = 'H#rightarrow2X#rightarrow{} ({} GeV, {} GeV, {} mm){}'.format(
            prettyFS, sp[0], sp[1], sp[2],
            ' + trigger' if ARGS.TRIGGER else '')

    c = Plotter.Canvas(lumi=lumi, cWidth=600 if ARGS.SQUARE else 800)
    pretty = {'DSA': {'col': R.kBlue}, 'RSA': {'col': R.kRed}}
    g, p = {}, {}
    for MUON in MUONS:
        hNum['nRec' + MUON].Rebin(10)
        hDen['nGen' + MUON].Rebin(10)
        g[MUON] = R.TGraphAsymmErrors(hNum['nRec' + MUON], hDen['nGen' + MUON],
                                      'cp')
        p[MUON] = Plotter.Plot(g[MUON], MUON, 'l', 'p')
        c.addMainPlot(p[MUON])
        p[MUON].setColor(pretty[MUON]['col'], which='LM')

    c.makeLegend(lWidth=0.125, pos='bl')
    c.legend.resizeHeight()

    c.firstPlot.SetMinimum(0.)
    c.firstPlot.SetMaximum(1.)
    c.firstPlot.setTitles(X='', Y='', copy=hNum['nRecDSA'])
    if ARGS.SQUARE:
        c.firstPlot.scaleTitleOffsets(1.1, 'X')

    c.cleanup('pdfs/REFF_Lxy{}_{}_{}.pdf'.format(
        '_Trig' if ARGS.TRIGGER else '', fs,
        'Global' if sp is None else SPStr(sp)),
              mode='LUMI')
def makeLxyResVSLxyPlot(recoType):
    key = recoType + '-LxyResVSGEN-Lxy'
    HISTS = HG.getAddedSignalHistograms(FILES[fs], fs, (key, ))

    config = {
        'PAT': (35, 1),
        'HYB': (70, 2),
        'DSA': (350, 10),
    }

    upperEdge = config[recoType][0]
    step = config[recoType][1]
    xPoints = map(lambda z: float(z) + float(step) / 2.,
                  range(0, upperEdge, step))
    xError = [float(step) / 2.] * len(xPoints)

    yPoints = []
    yError = []
    for ibin in xrange(1, upperEdge + 1):
        if (ibin + step / 2) % step != 0: continue
        binRange = (ibin - int(step / 2. - 1), ibin + int(step / 2.))
        h = HISTS[key].ProjectionY('h' + str(ibin), *binRange)
        #lims = .01
        #lims = 5. if recoType == 'DSA' else .05
        lims = {'DSA': 15., 'PAT': .05, 'HYB': 5.}
        lims = lims[recoType]
        if recoType == 'PAT' and ibin > 10:
            lims = lims / 5.
        func = R.TF1('f', 'gaus', -lims, lims)
        h.Fit('f', 'Rq')
        yPoints.append(func.GetParameter(2))
        yError.append(func.GetParError(2))

    g = R.TGraphErrors(len(xPoints), np.array(xPoints), np.array(yPoints),
                       np.array(xError), np.array(yError))
    p = Plotter.Plot(g, '', '', 'pe')
    p.setTitles(X='gen L_{xy} [cm]', Y='Fitted #sigma L_{xy} Res. [cm]')

    canvas = Plotter.Canvas(lumi=fs + lumiExtra.get(CUTSTRING) +
                            ' ({})'.format(recoType))
    canvas.addMainPlot(p)
    canvas.firstPlot.SetMinimum(0.)
    if recoType == 'PAT':
        canvas.firstPlot.SetMaximum(0.02)
    if recoType == 'HYB':
        canvas.firstPlot.SetMaximum(5.)
    if recoType == 'DSA':
        canvas.firstPlot.SetMaximum(10.)
    canvas.cleanup('pdfs/ZEP_ResVSLxy_{}_{}_{}.pdf'.format(
        recoType, CUTSTRING, fs))
Пример #11
0
def makeRepEffectPlots(sp=None):

    lumi = 'H#rightarrow2X#rightarrow2#mu'
    if sp is None:
        lumi += ', all samples combined'
    else:
        lumi += ' ({} GeV, {} GeV, {} mm)'.format(*sp)

    hkeys = ('Lxy-before', 'Lxy-after')
    if sp is None:
        HISTS = HG.getAddedSignalHistograms(FILES['Signal'], '2Mu2J', hkeys)
    else:
        HISTS = {}
        for key in hkeys:
            HISTS[key] = HG.getHistogram(FILES['Signal'], ('2Mu2J', sp),
                                         key).Clone()

    nPass = HISTS['Lxy-after'].Integral(
        HISTS['Lxy-after'].GetXaxis().FindBin(65.),
        HISTS['Lxy-after'].GetNbinsX() + 1)
    nTot = HISTS['Lxy-before'].Integral(
        HISTS['Lxy-before'].GetXaxis().FindBin(65.),
        HISTS['Lxy-before'].GetNbinsX() + 1)
    print nPass / nTot

    for key in hkeys:
        HISTS[key].Rebin(2)
    g = R.TGraphAsymmErrors(HISTS['Lxy-after'], HISTS['Lxy-before'], 'cp')
    p = Plotter.Plot(g, '', '', 'p')

    canvas = Plotter.Canvas(lumi=lumi, cWidth=600 if ARGS.SQUARE else 800)
    canvas.addMainPlot(p)
    p.setColor(R.kBlue)

    canvas.firstPlot.setTitles(X='generated L_{xy} [cm]',
                               Y='Dimuons after / before association')

    canvas.firstPlot.SetMaximum(1.)
    canvas.firstPlot.SetMinimum(0.)

    if ARGS.SQUARE:
        canvas.firstPlot.scaleTitleOffsets(1.1, 'X')
    canvas.cleanup('pdfs/REPEFF_Signal_{}.pdf'.format(
        'Global' if sp is None else SPStr(sp)),
                   mode='LUMI')
Пример #12
0
def makePercentReplacedPlot():
    keylist = ['PAT-genLxy', 'DSA-genLxy']
    HISTS = HG.getAddedSignalHistograms(FILE, fs, keylist)
    for key, h in HISTS.iteritems():
        pass
        #h.Rebin(5)
    g = R.TGraphAsymmErrors(HISTS[keylist[0]], HISTS[keylist[1]], 'cp')
    p = Plotter.Plot(g, '', '', 'p')

    p.setTitles(Y='% replaced selected DSA dimuons', X='gen L_{xy} [cm]')
    #RT.addBinWidth(p)

    canvas = Plotter.Canvas(lumi=fs)
    #canvas = Plotter.Canvas(lumi=fs, logy=True)
    canvas.addMainPlot(p)
    canvas.firstPlot.SetMinimum(0.)
    #canvas.firstPlot.SetMinimum(0.0001)
    canvas.firstPlot.SetMaximum(1.)
    canvas.cleanup('pdfs/percentReplacedVSgenLxy_{}.pdf'.format(fs))
def makeResPlot(fs, sp):
    if sp is None:
        h = HG.getAddedSignalHistograms(FILES[fs], fs,
                                        ['pTRes-' + MUON for MUON in MUONS])
        prettyFS = '2#mu' if '2Mu' in fs else '4#mu'
        lumi = 'H#rightarrow2X#rightarrow{}, all samples combined{}'.format(
            prettyFS, ' + trigger' if ARGS.TRIGGER else '')
    else:
        h = {}
        for MUON in MUONS:
            h['pTRes-' + MUON] = HG.getHistogram(FILES[fs], (fs, sp),
                                                 'pTRes-' + MUON).Clone()
        prettyFS = '2#mu' if '2Mu' in fs else '4#mu'
        lumi = 'H#rightarrow2X#rightarrow{} ({} GeV, {} GeV, {} mm){}'.format(
            prettyFS, sp[0], sp[1], sp[2],
            ' + trigger' if ARGS.TRIGGER else '')

    c = Plotter.Canvas(lumi=lumi, cWidth=600 if ARGS.SQUARE else 800)
    pretty = {'DSA': {'col': R.kBlue}, 'RSA': {'col': R.kRed}}
    p = {}
    for MUON in MUONS:
        h['pTRes-' + MUON].Scale(
            1. /
            h['pTRes-' + MUON].Integral(0, h['pTRes-' + MUON].GetNbinsX() + 1))
        #h['pTRes-'+MUON].Rebin(10)
        p[MUON] = Plotter.Plot(h['pTRes-' + MUON], MUON, 'l', 'hist')
        c.addMainPlot(p[MUON])
        p[MUON].setColor(pretty[MUON]['col'], which='LM')

    c.makeLegend(lWidth=0.125, pos='tr')
    c.legend.resizeHeight()

    c.setMaximum()
    c.firstPlot.setTitles(X='', Y='', copy=h['pTRes-DSA'])
    RT.addBinWidth(c.firstPlot)
    if ARGS.SQUARE:
        c.firstPlot.scaleTitleOffsets(1.1, 'X')
        c.firstPlot.scaleTitleOffsets(1.3, 'Y')

    c.cleanup('pdfs/PTRES{}_{}_{}.pdf'.format(
        '_Trig' if ARGS.TRIGGER else '', fs,
        'Global' if sp is None else SPStr(sp)),
              mode='LUMI')
Пример #14
0
def makeLxyPlot():
    hkeys = ['Lxy_{}'.format(tag) for tag in TAGS]
    HISTS = HG.getAddedSignalHistograms(FILES['Signal'], '2Mu2J', hkeys)

    for key in hkeys:
        HISTS[key].Rebin(10)

    for tag in TAGS:
        zz = 'Lxy_{}'.format(tag)
        print zz, HISTS[zz].Integral(
            HISTS[zz].GetXaxis().FindBin(100.),
            HISTS[zz].GetNbinsX() + 1), HISTS['Lxy_00'].Integral(
                HISTS['Lxy_00'].GetXaxis().FindBin(100.),
                HISTS['Lxy_00'].GetNbinsX() + 1)

    g = {}
    for tag in TAGS:
        #g[tag] = R.TGraphAsymmErrors(HISTS['Lxy_{}'.format(tag)], HISTS['Lxy_00'], 'cp')
        g[tag] = HISTS['Lxy_{}'.format(tag)].Clone()
        g[tag].Divide(HISTS['Lxy_00'])

    #p = {tag:Plotter.Plot(g[tag], TAGS[tag]['leg'], 'lp', 'p') for tag in TAGS}
    p = {
        tag: Plotter.Plot(g[tag], TAGS[tag]['leg'], 'lp', 'hist p')
        for tag in TAGS
    }

    c = Plotter.Canvas()
    for tag in ('00', '05', '10', '15'):
        c.addMainPlot(p[tag])
        p[tag].setColor(TAGS[tag]['col'])

    c.makeLegend(lWidth=0.2, pos='bl')

    c.firstPlot.setTitles(X='', Y='', copy=HISTS[hkeys[0]])
    c.firstPlot.SetMinimum(0.8)
    c.firstPlot.SetMaximum(1.01)

    c.firstPlot.GetXaxis().SetRangeUser(0., 400.)

    c.cleanup('Lxy_deltaR_PD.pdf')
Пример #15
0
def makePlot(mtype, vtype, quantity, which):
    hkey = '{}_{}_{}'.format(mtype, vtype, quantity)
    if which == 'Signal':
        HISTS = HG.getAddedSignalHistograms(FILES['Signal'], '2Mu2J', hkey)
        h = HISTS[hkey]
    elif which == 'Data':
        HISTS, PConfig = HG.getDataHistograms(FILES['Data'],
                                              hkey,
                                              addFlows=False)
        h = HISTS[hkey]['data']
    p = Plotter.Plot(h, '', '', 'hist')
    c = Plotter.Canvas()
    c.addMainPlot(p)
    p.setColor(R.kBlue)
    if hkey == 'Prox_PD_deltaR' or hkey == 'Prox_PP_deltaR':
        s = 0
        print hkey, which
        for ibin in xrange(1, p.GetNbinsX() + 1):
            s += p.GetBinContent(ibin)
            print p.GetXaxis().GetBinLowEdge(ibin), p.GetBinContent(ibin), s
    s = c.makeStatsBox(p, R.kBlue)
    c.cleanup(hkey + '_' + which + '.pdf')
def makeSignal2DPlots():
    for quantity in ('normChi2', 'nTrkLay', 'nPxlHit', 'highPurity',
                     'isGlobal', 'isMedium', 'hitsBeforeVtx',
                     'missingHitsAfterVtx'):
        if quantity == 'nTrkLay':
            R.gStyle.SetPaintTextFormat('.1f')
        else:
            R.gStyle.SetPaintTextFormat('g')

        hkey = 'PAT-12-' + quantity
        HISTS = HG.getAddedSignalHistograms(FILES[fs], fs, (hkey, ))
        for sp in SIGNALPOINTS:
            HISTS[sp] = HG.getHistogram(FILES[fs], (fs, sp), hkey).Clone()

        if quantity != 'normChi2':
            opt = 'colz text'
        else:
            opt = 'colz'
        PLOTS = {hkey: Plotter.Plot(HISTS[hkey], '', '', opt)}
        for sp in SIGNALPOINTS:
            PLOTS[sp] = Plotter.Plot(HISTS[sp], '', '', opt)

        for sp in [
                hkey,
        ] + SIGNALPOINTS:
            canvas = Plotter.Canvas(lumi=fs + lumiExtra.get(CUTSTRING) if
                                    type(sp) != tuple else SPLumiStr(fs, *sp))
            canvas.addMainPlot(PLOTS[sp])
            canvas.firstPlot.SetMarkerColor(R.kWhite)

            if quantity == 'normChi2':
                canvas.firstPlot.GetXaxis().SetRangeUser(0., 10.)
                canvas.firstPlot.GetYaxis().SetRangeUser(0., 10.)

            canvas.scaleMargins(1.75, edges='R')
            canvas.scaleMargins(0.8, edges='L')
            canvas.cleanup('pdfs/ZEP_2D_{}_{}_{}_{}.pdf'.format(
                quantity, CUTSTRING, fs,
                'Global' if type(sp) != tuple else SPStr(sp)))
def makeIntegratedSEQSignal(hkey='SEQ'):
    HISTS = HG.getAddedSignalHistograms(FILES['2Mu2J'], '2Mu2J', hkey)

    h = HISTS[hkey]
    p = Plotter.Plot(h, '', '', 'hist')

    canvas = Plotter.Canvas(lumi='2Mu2J', cWidth=1600)
    canvas.addMainPlot(p)

    p.SetLineColor(R.kBlue)

    setBinLabels(canvas)

    canvas.firstPlot.setTitles(X='Cut', Y='Normalized Counts')
    canvas.firstPlot.SetMaximum(3.e5 if 'DSA' not in hkey else 1.e5)
    canvas.firstPlot.SetMinimum(0.)

    canvas.scaleMargins(.5, 'L')
    canvas.firstPlot.scaleTitleOffsets(.5, 'Y')
    R.TGaxis.SetExponentOffset(0., 0.02, "y")

    canvas.cleanup('pdfs/NM1_{}{}{}_2Mu2J.pdf'.format(hkey, BUMPSTRING,
                                                      IDPHISTRING))
def makeIntegratedNM1Signal(hkey='NM1'):

    #HISTS, INDIV = HG.getAddedSignalHistograms(FILES['2Mu2J'], '2Mu2J', 'NM1', getIndividuals=True)

    #totalBin1 = sum([INDIV['NM1'][ref].GetBinContent(1) for ref in SIGNALPOINTS])
    #for ibin in range(1, len(CUTS)+2):
    #    totalBin = sum([INDIV['NM1'][ref].GetBinContent(ibin) for ref in SIGNALPOINTS])
    #    scaleFactor = totalBin1/totalBin
    #    for ref in SIGNALPOINTS:
    #        INDIV['NM1'][ref].SetBinContent(ibin, INDIV['NM1'][ref].GetBinContent(ibin)/totalBin*scaleFactor)

    HISTS = HG.getAddedSignalHistograms(FILES['2Mu2J'], '2Mu2J', hkey)
    totalBin1 = HISTS[hkey].GetBinContent(1)
    for ibin in range(1, len(CUTS) + 2):
        totalBin = HISTS[hkey].GetBinContent(ibin)
        scaleFactor = totalBin1 / totalBin
        HISTS[hkey].SetBinContent(ibin, scaleFactor)

    h = HISTS[hkey]
    p = Plotter.Plot(h, '', '', 'hist')

    canvas = Plotter.Canvas(lumi='2Mu2J', cWidth=1600)
    canvas.addMainPlot(p)

    p.SetLineColor(R.kBlue)

    setBinLabels(canvas)

    canvas.firstPlot.setTitles(X='Cut', Y='n#minus1 Eff.')
    canvas.firstPlot.SetMaximum(1.2)
    canvas.firstPlot.SetMinimum(0.)

    canvas.scaleMargins(.5, 'L')
    canvas.firstPlot.scaleTitleOffsets(.5, 'Y')

    canvas.cleanup('pdfs/NM1_{}{}{}_2Mu2J.pdf'.format(hkey, BUMPSTRING,
                                                      IDPHISTRING))
Пример #19
0
        func.Draw("same")
        raw_input()

        h = HG.getHistogram(FILE, (fs, sp), 'DSA-LxyRes')
        func = R.TF1('f', 'gaus', -15., 15.)
        h.Fit('f', 'R')
        h.Draw()
        func.Draw("same")
        raw_input()

# stripped copy of the function in makePATPlots for looking at individual fits
if False:
    recoType = 'PAT'

    key = recoType + '-LxyResVSgenLxy'
    HISTS = HG.getAddedSignalHistograms(FILE, fs, (key, ))

    upperEdge = 35
    for ibin in xrange(1, upperEdge + 1):
        h = HISTS[key].ProjectionY('h' + str(ibin), ibin, ibin)
        #lims = .01
        lims = 5. if recoType == 'DSA' else .05
        if recoType == 'PAT' and ibin > 10:
            lims = lims / 5.
        func = R.TF1('f', 'gaus', -lims, lims)
        h.Fit('f', 'R')
        print ibin
        h.Draw()
        func.Draw("same")
        raw_input()
def makeResPlots(metric, quantity, sp=None):
    PRETTY = {
        'pTRes_hits_less': {
            'mnice': 'p_{T} res.',
            'qnice': 'N(hits)',
            'leg': 'N(hits) #leq 12',
            'col': R.kRed
        },
        'pTRes_hits_more': {
            'mnice': 'p_{T} res.',
            'qnice': 'N(hits)',
            'leg': 'N(hits) > 12',
            'col': R.kBlue
        },
        'pTRes_fpte_less': {
            'mnice': 'p_{T} res.',
            'qnice': '#sigma_{p_{T}}/p_{T}',
            'leg': '#sigma_{p_{T}}/p_{T} < 1',
            'col': R.kBlue
        },
        'pTRes_fpte_more': {
            'mnice': 'p_{T} res.',
            'qnice': '#sigma_{p_{T}}/p_{T}',
            'leg': '#sigma_{p_{T}}/p_{T} #geq 1',
            'col': R.kRed
        },
        'qdiff_hits_less': {
            'mnice': 'charge diff.',
            'qnice': 'N(hits)',
            'leg': 'N(hits) #leq 12',
            'col': R.kRed
        },
        'qdiff_hits_more': {
            'mnice': 'charge diff.',
            'qnice': 'N(hits)',
            'leg': 'N(hits) > 12',
            'col': R.kBlue
        },
        'qdiff_fpte_less': {
            'mnice': 'charge diff.',
            'qnice': '#sigma_{p_{T}}/p_{T}',
            'leg': '#sigma_{p_{T}}/p_{T} < 1',
            'col': R.kBlue
        },
        'qdiff_fpte_more': {
            'mnice': 'charge diff.',
            'qnice': '#sigma_{p_{T}}/p_{T}',
            'leg': '#sigma_{p_{T}}/p_{T} #geq 1',
            'col': R.kRed
        },
    }
    witches = ('less', 'more') if quantity == 'fpte' else ('more', 'less')
    hkeys = ['{}_{}_{}'.format(metric, quantity, which) for which in witches]

    if sp is None:
        HISTS = HG.getAddedSignalHistograms(FILES['Signal'], '2Mu2J', hkeys)
    else:
        HISTS = {}
        for key in hkeys:
            HISTS[key] = HG.getHistogram(FILES['Signal'], ('2Mu2J', sp),
                                         key).Clone()

    PLOTS = {}
    for key in hkeys:
        HISTS[key].Scale(1. /
                         HISTS[key].Integral(0, HISTS[key].GetNbinsX() + 1))
        #RT.addFlows(HISTS[key])
        PLOTS[key] = Plotter.Plot(HISTS[key], PRETTY[key]['leg'], 'l', 'hist')

    #canvas = Plotter.Canvas(lumi='{} by {}'.format(PRETTY[hkeys[0]]['mnice'], PRETTY[hkeys[0]]['qnice']))
    lumi = 'H#rightarrow2X#rightarrow2#mu'
    if sp is None:
        lumi += ', all samples combined'
    else:
        lumi += ' ({} GeV, {} GeV, {} mm)'.format(*sp)
    canvas = Plotter.Canvas(lumi=lumi, cWidth=600 if ARGS.SQUARE else 800)

    for key in hkeys:
        canvas.addMainPlot(PLOTS[key])
        PLOTS[key].setColor(PRETTY[key]['col'], which='L')

    canvas.firstPlot.SetMinimum(0.)
    canvas.setMaximum()
    if metric == 'qdiff':
        canvas.firstPlot.SetMaximum(1.)

    canvas.firstPlot.setTitles(Y='Density')
    if 'qdiff' in hkeys[0]:
        canvas.firstPlot.SetNdivisions(3)

    canvas.makeLegend(lWidth=0.27, pos='tr')
    canvas.legend.resizeHeight()

    RT.addBinWidth(canvas.firstPlot)

    if ARGS.SQUARE:
        canvas.firstPlot.scaleTitleOffsets(1.1, 'X')
        if metric == 'pTRes':
            canvas.firstPlot.scaleTitleOffsets(1.3, 'Y')
    canvas.cleanup('pdfs/QCUTRES_Sig_{}_{}_{}.pdf'.format(
        metric, quantity, 'Global' if sp is None else SPStr(sp)),
                   mode='LUMI')
PP.PARSER.add_argument('--thesis', dest='THESIS', action='store_true')
ARGS = PP.PARSER.parse_args()

##################################
#### Get histograms and scale ####
##################################

FILES = {
    'DataNom' : R.TFile.Open('roots/MyDataPileupHistogram.root'),
    'DataLow' : R.TFile.Open('roots/MyDataPileupHistogram_Low.root'),
    'DataHigh': R.TFile.Open('roots/MyDataPileupHistogram_High.root'),
    'Signal'  : R.TFile.Open('roots/pileup_HTo2XTo2Mu2J.root'),
}

HISTS, INDIV = HG.getAddedSignalHistograms(FILES['Signal'], '2Mu2J', 'pileup', True)
HISTS, INDIV = HISTS['pileup'], INDIV['pileup']

KEYS = ('Nom', 'Low', 'High')

DATA = {key:FILES['Data'+key].Get('pileup').Clone() for key in KEYS}

for key in DATA:
    DATA[key].Scale(1./DATA[key].Integral())

for sp in INDIV:
    INDIV[sp].Scale(1./INDIV[sp].Integral())

HISTS.Scale(1./HISTS.Integral())

# saves the weight for a printing pass afterwards
Пример #22
0
def makeResPlots(metric, quantity):
    PRETTY = {
        'pTRes_hits_less': {
            'mnice': 'p_{T} res.',
            'qnice': 'N(hits)',
            'leg': 'N(hits) #leq 12',
            'col': R.kRed
        },
        'pTRes_hits_more': {
            'mnice': 'p_{T} res.',
            'qnice': 'N(hits)',
            'leg': 'N(hits) > 12',
            'col': R.kBlue
        },
        'pTRes_fpte_less': {
            'mnice': 'p_{T} res.',
            'qnice': '#sigma_{p_{T}}/p_{T}',
            'leg': '#sigma_{p_{T}}/p_{T} < 1',
            'col': R.kBlue
        },
        'pTRes_fpte_more': {
            'mnice': 'p_{T} res.',
            'qnice': '#sigma_{p_{T}}/p_{T}',
            'leg': '#sigma_{p_{T}}/p_{T} #geq 1',
            'col': R.kRed
        },
        'qdiff_hits_less': {
            'mnice': 'charge diff.',
            'qnice': 'N(hits)',
            'leg': 'N(hits) #leq 12',
            'col': R.kRed
        },
        'qdiff_hits_more': {
            'mnice': 'charge diff.',
            'qnice': 'N(hits)',
            'leg': 'N(hits) > 12',
            'col': R.kBlue
        },
        'qdiff_fpte_less': {
            'mnice': 'charge diff.',
            'qnice': '#sigma_{p_{T}}/p_{T}',
            'leg': '#sigma_{p_{T}}/p_{T} < 1',
            'col': R.kBlue
        },
        'qdiff_fpte_more': {
            'mnice': 'charge diff.',
            'qnice': '#sigma_{p_{T}}/p_{T}',
            'leg': '#sigma_{p_{T}}/p_{T} #geq 1',
            'col': R.kRed
        },
    }
    witches = ('less', 'more')
    hkeys = ['{}_{}_{}'.format(metric, quantity, which) for which in witches]

    HISTS = HG.getAddedSignalHistograms(FILES['Signal'], '2Mu2J', hkeys)

    PLOTS = {}
    for key in hkeys:
        HISTS[key].Scale(1. /
                         HISTS[key].Integral(0, HISTS[key].GetNbinsX() + 1))
        RT.addFlows(HISTS[key])
        PLOTS[key] = Plotter.Plot(HISTS[key], PRETTY[key]['leg'], 'l', 'hist')

    canvas = Plotter.Canvas(lumi='{} by {}'.format(PRETTY[hkeys[0]]['mnice'],
                                                   PRETTY[hkeys[0]]['qnice']))

    for key in hkeys:
        canvas.addMainPlot(PLOTS[key])
        PLOTS[key].setColor(PRETTY[key]['col'], which='L')

    canvas.firstPlot.SetMinimum(0.)
    canvas.firstPlot.SetMaximum(0.08 if metric == 'pTRes' else 1.)

    canvas.firstPlot.setTitles(Y='Density')
    if 'qdiff' in hkeys[0]:
        canvas.firstPlot.SetNdivisions(3)

    canvas.makeLegend(lWidth=0.27, pos='tr')

    RT.addBinWidth(canvas.firstPlot)
    canvas.cleanup('Res_Sig_{}_{}.pdf'.format(metric, quantity))
Пример #23
0
                 h.GetBinContent(2, 1) + h.GetBinContent(2, 2)) * 100.
    print '{:4d} {:3d} {:4d}'.format(*sp),
    print '{:5.0f} {:5.0f} {:.2%}'.format(
        h.GetBinContent(1, 1) + h.GetBinContent(1, 2) + h.GetBinContent(2, 1) +
        h.GetBinContent(2, 2), h.GetBinContent(2, 2),
        h.GetBinContent(2, 2) /
        (h.GetBinContent(1, 1) + h.GetBinContent(1, 2) +
         h.GetBinContent(2, 1) + h.GetBinContent(2, 2)))

makeSummaryPlot(DATA, '2Mu2J', ('med', ), ';;% both medium',
                {'med': '% both medium'}, {'med': R.kRed}, {
                    'min': 0.,
                    'max': 100.
                }, 'MED.pdf')

HISTS = HG.getAddedSignalHistograms(f, '2Mu2J', 'PAT-normChi2VSisMedium')
p = {}
p['not'] = Plotter.Plot(
    HISTS['PAT-normChi2VSisMedium'].ProjectionY('not', 1, 1), 'not medium',
    'lp', 'hist')
p['med'] = Plotter.Plot(
    HISTS['PAT-normChi2VSisMedium'].ProjectionY('med', 2, 2), 'medium', 'lp',
    'hist')
canvas = Plotter.Canvas(logy=True)
canvas.addMainPlot(p['med'])
canvas.addMainPlot(p['not'])
p['not'].setColor(R.kRed, which='LM')
p['med'].setColor(R.kBlue, which='LM')
p['not'].Scale(1. / p['not'].Integral(0, p['not'].GetNbinsX() + 1))
p['med'].Scale(1. / p['med'].Integral(0, p['med'].GetNbinsX() + 1))
canvas.makeLegend(lWidth=.2)
def makeSignalPlot(key):
    h = HG.getAddedSignalHistograms(FILES['2Mu2J'], '2Mu2J', key)
    h = h[key]

    p = Plotter.Plot(h, '', '', 'hist')

    RT.addBinWidth(p)

    c = Plotter.Canvas(lumi='H#rightarrow2X#rightarrow2#mu, {}'.format(
        CUTS[key]['lumi']),
                       cWidth=600 if key != 'deltaPhi' else 800,
                       logy=CUTS[key]['logy'])
    c.addMainPlot(p)
    c.firstPlot.setColor(R.kBlue)
    c.firstPlot.scaleTitleOffsets(1.1, 'Y')

    if key == 'deltaPhi':
        axis = c.firstPlot.GetXaxis()
        labeldict = {
            1: '0',
            25: '#pi/4',
            50: '#pi/2',
            75: '3#pi/4',
            100: '#pi'
        }
        for i in xrange(1, 101):
            val = labeldict.get(i)
            if val is None: val = ''
            axis.SetBinLabel(i, val)
        axis.SetNdivisions(216, False)
        axis.SetLabelSize(.06)
        axis.SetTickLength(0.03)
        axis.SetTickSize(0.03)
        axis.LabelsOption('h')

        c.mainPad.Update()
        ymin = c.mainPad.GetUymin()
        ymax = c.mainPad.GetUymax()
        if c.logy:
            ymax = 10.**ymax

        xB = R.TGaxis(0., ymin,
                      R.TMath.Pi() - .07, ymin, 0., R.TMath.Pi(), 216, "+B",
                      .03)
        xB.SetLabelSize(0)
        xB.Draw('same')

        xT = R.TGaxis(0., ymax,
                      R.TMath.Pi() - .07, ymax, 0., R.TMath.Pi(), 216, "-B",
                      .03)
        xT.SetLabelSize(0)
        xT.Draw('same')

    if key == 'pT':
        c.firstPlot.GetXaxis().SetRangeUser(0., 600.)

    eff = getEff(p, key)
    c.drawText('{:.1%} efficient'.format(eff),
               align='tr',
               pos=(1. - c.margins['r'] - .03, 1. - c.margins['t'] - .03))

    c.mainPad.Update()
    ymax = c.mainPad.GetUymax()
    line = R.TLine(CUTS[key]['val'], 0., CUTS[key]['val'],
                   ymax if not c.logy else 10.**ymax)
    line.SetLineStyle(2)
    line.Draw()

    if key == 'trkChi2': c.firstPlot.GetXaxis().SetTitle('trk. #chi^{2}/dof')

    c.cleanup('pdfs/NM1_2Mu2J_{}.pdf'.format(key), mode='LUMI')
Пример #25
0
import ROOT as R
import DisplacedDimuons.Analysis.HistogramGetter as HG
import DisplacedDimuons.Analysis.Plotter as Plotter

FILES = {'_PATOnly':0, '_NoRep':0, '':0}
HISTS = {}
for key in FILES:
    FILES[key] = R.TFile.Open('roots/ZephyrPlots_Trig_Combined_BS9{}_2Mu2J.root'.format(key))
    HISTS[key] = HG.getAddedSignalHistograms(FILES[key], '2Mu2J', ('GEN-Lxy', 'GEN-Lxy-PAT', 'GEN-Lxy-HYB', 'GEN-Lxy-DSA'))

# relative signal match eff
h = {}
h['PAT'] = HISTS['_PATOnly']['GEN-Lxy'].Clone()
h['HYB'] = HISTS[''        ]['GEN-Lxy'].Clone()
h['DSA'] = HISTS['_NoRep'  ]['GEN-Lxy'].Clone()
for key in h:
    h[key].Rebin(5)

h['PAT'].Divide(h['DSA'])
h['HYB'].Divide(h['DSA'])

h.pop('DSA')

p = {}
config = {'PAT' : ('DSA-DSA or PAT-PAT only', R.kRed), 'HYB' : ('DSA-DSA, PAT-PAT, or DSA-PAT', R.kBlue)}
for key in h:
    p[key] = Plotter.Plot(h[key], config[key][0], 'lp', 'p')

canvas = Plotter.Canvas(lumi='2Mu2J')
for key in ('PAT', 'HYB'):
    canvas.addMainPlot(p[key])
Пример #26
0
#fOld = R.TFile.Open('roots/ZephyrPlots_Trig_Combined_NS_NH_FPTE_HLT_REP_PQ1_PT_PC_LXYE_MASS_CHI2_DSAPROXMATCH_HTo2XTo2Mu2J.root')
#fNew = R.TFile.Open('roots/ZephyrPlots_Trig_Combined_NS_NH_FPTE_HLT_REP_PQ1_PT_PC_LXYE_MASS_CHI2_DPT_HTo2XTo2Mu2J.root')

fOld = R.TFile.Open(
    'roots/ZephyrPlots_Trig_Combined_NS_NH_FPTE_HLT_REP_PT_PC_LXYE_MASS_CHI2_VTX_COSA_SFPTE_HTo2XTo2Mu2J.root'
)
fNew = R.TFile.Open(
    'roots/ZephyrPlots_Trig_Combined_NS_NH_FPTE_HLT_REP_PT_PC_LXYE_MASS_CHI2_VTX_COSA_SFPTE_PROXTHRESH_HTo2XTo2Mu2J.root'
)


def deleteHistogram(HIST):
    R.gROOT.ProcessLine('delete gROOT->FindObject("' + HIST.GetName() + '")')


hOld = HG.getAddedSignalHistograms(fOld, '2Mu2J', 'GEN-Lxy-DSA')
g = hOld['GEN-Lxy-DSA'].Clone()
g.SetName('new')
deleteHistogram(hOld['GEN-Lxy-DSA'])

HybOld = HG.getAddedSignalHistograms(fOld, '2Mu2J', 'GEN-Lxy-HYB')
g.Add(HybOld['GEN-Lxy-HYB'])
deleteHistogram(HybOld['GEN-Lxy-HYB'])

hNew = HG.getAddedSignalHistograms(fNew, '2Mu2J', 'GEN-Lxy-DSA')
h = hNew['GEN-Lxy-DSA'].Clone()
h.SetName('old')
deleteHistogram(hNew['GEN-Lxy-DSA'])

HybNew = HG.getAddedSignalHistograms(fNew, '2Mu2J', 'GEN-Lxy-HYB')
h.Add(HybNew['GEN-Lxy-HYB'])
import ROOT as R
import DisplacedDimuons.Analysis.HistogramGetter as HG
import DisplacedDimuons.Analysis.Plotter as Plotter

f = R.TFile.Open('roots/HPPlots_Trig_Combined_NS_NH_FPTE_HLT_REP_PT_PC_LXYE_MASS_2Mu2J.root')
h = HG.getAddedSignalHistograms(f, '2Mu2J', ('pT', 'GM-pT', 'pT-HP', 'GM-pT-HP'))

for key in ('', 'GM-'):
    h[key+'pT-HP'].Rebin(5)
    h[key+'pT'   ].Rebin(5)
    g = R.TGraphAsymmErrors(h[key+'pT-HP'], h[key+'pT'], 'cp')
    p = Plotter.Plot(g, '', '', 'pe')
    c = Plotter.Canvas()
    c.addMainPlot(p)
    p.setTitles(X='pre-refit PAT muon p_{T} [GeV]', Y='High purity fraction')
    p.setColor(R.kBlue, which='LM')
    c.cleanup('pdfs/HP_2Mu2J_'+key+'HPFrac.pdf')

f = R.TFile.Open('roots/HPPlots_Combined_NS_NH_FPTE_HLT_REP_PT_PC_LXYE_MASS_MC.root')
h, pc = HG.getBackgroundHistograms(f, ('pT', 'pT-HP'), stack=False, rebin=5)

for key in ('stack', 'DY50toInf'):
    g = R.TGraphAsymmErrors(h['pT-HP'][key], h['pT'][key], 'cp')
    p = Plotter.Plot(g, '', '', 'pe')
    c = Plotter.Canvas(lumi=key.title() if key == 'stack' else key)
    c.addMainPlot(p)
    p.setTitles(X='pre-refit PAT muon p_{T} [GeV]', Y='High purity fraction')
    p.setColor(R.kBlue, which='LM')
    c.cleanup('pdfs/HP_MC_'+key+'_HPFrac.pdf')
def makeSinglePlots():
    quantities = {
        'DSA': [],
        'PAT': [],
        'HYB': [],
        'HYB-DSA': [],
        'HYB-PAT': []
    }
    dimQuantities = [
        'Lxy', 'LxySig', 'LxyErr', 'vtxChi2', 'LxyRes', 'LxyPull', 'mind0Sig',
        'mass', 'deltaPhi', 'deltaR', 'cosAlpha', 'cosAlpha-O', 'DCA',
        'pTOverM', 'minNHits', 'qsum'
    ]
    for recoType in quantities:
        if 'HYB-' in recoType: continue
        quantities[recoType].extend(dimQuantities)

    quantities['HYB-DSA'].extend(
        ['pT', 'eta', 'phi', 'd0', 'FPTE', 'd0Sig', 'trkChi2', 'nStations'])
    quantities['HYB-PAT'].extend(
        ['pT', 'eta', 'phi', 'd0', 'relTrkIso', 'd0Sig', 'trkChi2'])

    quantities['REF-DSA'] = ['FPTE']
    quantities[''] = ['nDimuon', 'nDSA', 'nDSA12', 'nDSA12-pT', 'nDSA-DT']

    for recoType in ('DSA', 'PAT'):
        quantities[recoType].extend(quantities['HYB-' + recoType])

    for recoType in quantities:
        for quantity in quantities[recoType]:
            key = recoType + '-' + quantity
            if key[0] == '-' or recoType == 'DSAPlus':
                key = quantity
                recoType = 'DSAPlus'
            HISTS = HG.getAddedSignalHistograms(FILES[fs], fs, (key, ))

            LXYZOOMED = LXYZOOMEDFULL and recoType == 'DSA'

            p = Plotter.Plot(HISTS[key], key, 'l', 'hist')
            canvas = Plotter.Canvas(
                lumi=fs + lumiExtra.get(CUTSTRING) + ' ({})'.format(recoType),
                logy=True if quantity in ('vtxChi2', 'relTrkIso', 'deltaPhi',
                                          'trkChi2', 'nDimuon', 'nDSA',
                                          'nDSA12', 'nDSA12-pT', 'nDSA-DT',
                                          'd0', 'DCA') else False)

            if key == 'REF-DSA-FPTE':
                canvas.mainPad.SetLogx()

            canvas.addMainPlot(p, addS=True)
            p.setColor(R.kBlue, which='L')
            nbox = canvas.makeStatsBox(p.plot, color=R.kBlue)

            if quantity == 'LxyPull':
                func = R.TF1('f', 'gaus', -4., 4.)
                HISTS[key].Fit('f', 'R')
                fplot = Plotter.Plot(func, 'Fit', 'l', '')
                fplot.SetLineColor(R.kRed)
                canvas.addMainPlot(fplot)
                canvas.setFitBoxStyle(p.plot, lWidth=0.275, pos='tl')
                sbox = p.plot.FindObject('stats')
                sbox.SetTextColor(R.kRed)

            if not canvas.logy:
                canvas.firstPlot.SetMinimum(0.)

            if 'vtxChi2' in key:
                canvas.firstPlot.GetXaxis().SetRangeUser(0., 50.)
                canvas.firstPlot.SetMaximum(40000.)
                canvas.firstPlot.SetMinimum(1.)
            if 'mind0Sig' in key:
                canvas.firstPlot.SetMaximum(200. if recoType ==
                                            'PAT' else 900.)
            if 'LxySig' in key:
                canvas.firstPlot.SetMaximum(200. if recoType == 'PAT' else (
                    1200. if recoType == 'DSA' else 2700.))
            if 'relTrkIso' in key:
                canvas.firstPlot.SetMaximum(2000.)

            if 'Lxy' == quantity and LXYZOOMED:
                canvas.firstPlot.GetXaxis().SetRangeUser(0., 50.)

            RT.addBinWidth(canvas.firstPlot)
            canvas.cleanup('pdfs/ZEP_{}_{}_{}_{}.pdf'.format(
                quantity +
                ('Zoomed' if quantity == 'Lxy' and LXYZOOMED else ''),
                recoType, CUTSTRING, fs))
Пример #29
0
import ROOT as R
import DisplacedDimuons.Analysis.HistogramGetter as HG
import DisplacedDimuons.Analysis.Plotter as Plotter
import DisplacedDimuons.Common.Utilities as Utilities

FILE = R.TFile.Open(
    'roots/ZephyrPlots_Trig_Combined_NS_NH_FPTE_HLT_REP_PQ1_PT_PC_LXYE_MASS_CHI2_HTo2XTo2Mu2J.root'
)
HISTS, INDIV = HG.getAddedSignalHistograms(
    FILE,
    '2Mu2J', ('GEN-Lxy', 'GEN-Lxy-PAT', 'GEN-Lxy-HYB', 'GEN-Lxy-DSA'),
    getIndividuals=True)

for sp in INDIV['GEN-Lxy'].keys() + [None]:
    h = {}
    if sp is not None:
        SOURCEDICT = {key: INDIV[key][sp] for key in INDIV}
    else:
        SOURCEDICT = HISTS

    h['Tot'] = SOURCEDICT['GEN-Lxy'].Clone()
    for RTYPE in ('DSA', 'PAT', 'HYB'):
        h[RTYPE] = SOURCEDICT['GEN-Lxy-' + RTYPE].Clone()

    print '{:13s} ::: {:6.0f} ::: DSA {:6.0f} ( {:6.2%} ) ::: PAT {:6.0f} ( {:6.2%} ) ::: HYB {:6.0f} ( {:6.2%} )'.format(
        'Global - -' if sp is None else '{:4d} {:3d} {:4d}'.format(*sp),
        h['Tot'].Integral(0, h['Tot'].GetNbinsX() + 1),
        h['DSA'].Integral(0, h['DSA'].GetNbinsX() + 1),
        h['DSA'].Integral(0, h['DSA'].GetNbinsX() + 1) /
        h['Tot'].Integral(0, h['Tot'].GetNbinsX() + 1),
        h['PAT'].Integral(0, h['PAT'].GetNbinsX() + 1),