예제 #1
0
def routine(chan, var):
    hs_b, hs_a = [], []
    htitle = None
    numbers = defaultdict(dict)

    # before
    chandir = getattr(beforef, 'ch' + chan)
    for it, sigtag in enumerate(sigTAGS):
        h = getattr(getattr(chandir.sig, sigtag), var)  # Hist
        if htitle is None: htitle = h.title
        h.title = sigtag + ' w/ mu iso'
        h.drawstyle = 'hist'
        h.color = sigCOLORS[it]
        h.linewidth = 2
        h.legendstyle = 'L'
        hs_b.append(h)
        numbers[sigtag]['before'] = h.integral()

    # after
    chandir = getattr(afterf, 'ch' + chan)
    for it, sigtag in enumerate(sigTAGS):
        h = getattr(getattr(chandir.sig, sigtag), var)  # Hist
        h.title = 'w/o mu iso'
        h.drawstyle = 'hist'
        h.color = sigCOLORS[it]
        h.linewidth = 2
        h.linestyle = 'dashed'
        h.legendstyle = 'L'
        hs_a.append(h)
        numbers[sigtag]['after'] = h.integral()

    print('>', chan, var)
    df = pd.DataFrame(numbers).T
    df['incr %'] = (df['after'] - df['before']) / df['before'] * 100
    print(df[['before', 'after', 'incr %']])
    draw(hs_b + hs_a, logy=True)

    legend = Legend(len(hs_b),
                    pad=canvas,
                    margin=0.25,
                    leftmargin=0.3,
                    topmargin=0.02,
                    entrysep=0.01,
                    entryheight=0.02,
                    textsize=10)
    legend.SetNColumns(2)
    for _b, _a in zip(hs_b, hs_a):
        legend.AddEntry(_b)
        legend.AddEntry(_a)
    legend.Draw()

    title = TitleAsLatex('[{}] '.format(chan.replace('mu', '#mu')) + htitle)
    title.Draw()
    draw_labels('59.74 fb^{-1} (13 TeV)',
                cms_position='left',
                extra_text='work-in-progress')

    canvas.SaveAs('{}/ch{}_{}.pdf'.format(outdir, chan, var))
    canvas.Clear()
예제 #2
0
        canvas = Canvas(canvasConfigs.get('width', 500), canvasConfigs.get('height', 500))

        canvas.SetRightMargin(canvasConfigs.get('rightmargin', 0.1))
        canvas.SetBottomMargin(canvasConfigs.get('bottommargin', 0.2))
        canvas.SetLeftMargin(canvasConfigs.get('leftmargin', 0.2))

        if canvasConfigs.get('logy', False) == True:
          canvas.set_logy()

        # create a legend (an entry for each group)
        legendConfigs = copy.copy(plots_config.get('legend', {}))
        legendConfigs.update(plots_path.get('legend', {}))
        legend_numColumns = legendConfigs.get('numcolumns', 1)
        if "numcolumns" in legendConfigs: del legendConfigs['numcolumns']
        legend = Legend(len(h), **legendConfigs)
        legend.SetNColumns(legend_numColumns)

        # scale the histograms before doing anything else
        for hgroup in h:
          if groups.get(hgroup.group).get('do not scale me', False):
            logger.info("Skipping %s for scaling" % hgroup.group)
            continue
          for hist in hgroup:
            # scale the histograms, look up weights by did
            did = get_did(hist)
            weight = weights.get(did)
            if weight is None:
              raise KeyError("Could not find the weights for did=%s" % did)
            scaleFactor = 1.0
            if weight.get('num events') == 0:
              raise ValueError("did=%s has num events == 0" % did)