Ejemplo n.º 1
0
def drawAndPrint(var, altname=''):
    if len(altname) < 1:
        altname = var
    data.Draw(var + '>>' + altname + '(30)', var + ' != -9999.99', 'PE')
    h = gDirectory.Get(altname)
    h.SetMarkerStyle(20)
    if (altname[-5:] == '_bias') and (altname[0] == 'n'):
        print altname, 'mean:', h.GetMean()
    if (altname[-5:] == '_pull') and (opts.fitPull):
        fitfunc = 'gaus(0)/sqrt(TMath::TwoPi())/[2]'
        gfit = TF1('gfit', fitfunc,
                   h.GetXaxis().GetXmin(),
                   h.GetXaxis().GetXmax())
        gfit.SetParameters(1.0, h.GetMean(), h.GetRMS())
        gfit.FixParameter(0, 1.0)
        data.UnbinnedFit('gfit', var, '', 'E')
        gfit2 = TF1('gfit2', fitfunc,
                    h.GetXaxis().GetXmin(),
                    h.GetXaxis().GetXmax())
        gfit2.SetParameter(0, 1.0)
        gfit2.FixParameter(1, gfit.GetParameter(1))
        gfit2.FixParameter(2, gfit.GetParameter(2))
        h.Fit('gfit2', 'LN0Q')
        gfit.FixParameter(0, gfit2.GetParameter(0))
        L = TLatex()
        L.SetNDC()
        L.SetTextSize(0.04)
        L.SetTextAlign(12)
        h.Draw('PE')
        gfit.Draw('same')
        L.DrawLatex(0.12, 0.85, "<x>: %4.3f #pm %4.3f" % \
                    (gfit.GetParameter(1), gfit.GetParError(1)))
        L.DrawLatex(0.12, 0.8, "#sigma_{x}: %4.3f #pm %4.3f" % \
                    (gfit.GetParameter(2), gfit.GetParError(2)))
    c.Modified()
    sums = ''
    errs = ''
    errstr = ''
    trues = ''
    if ((altname[:4] == 'nsig') or (altname[:5] == 'nbkgd')) and \
           (altname[-4:] != '_err') and (altname[-5:] != '_pull') and \
           (altname[-5:] != '_bais'):
        mean = h.GetMean()
        rms = h.GetRMS()
        errstr = '%s mean: %5.3f rms: %5.3f fractional err: %6.4f' % (
            altname, mean, rms, rms / mean)
        #print errstr
        #if (var == altname):
        sums = altname + '+'
        errs = (altname + '_err*') * 2
        errs = errs[:-1] + '+'
        trues = altname + '_true+'
    c.Update()
    c.Print(opts.plotdir + '/' + altname + '.png')
    c.Print(opts.plotdir + '/' + altname + '.pdf')
    return errstr, sums, errs, trues
Ejemplo n.º 2
0
def DoCompareLimitPlots(Channel, tauIsolation, leptonIsolation, LTCut,lowY, highY):
    print "\n\n*********************" , Channel
    for cut0 in FitType:
        Hist = ['hist0', 'hist1', 'hist2', 'hist3']

        canvas = TCanvas()
        gStyle.SetOptStat(0)
        gStyle.SetOptStat(0);
        gStyle.SetOptTitle(0);
        canvas.SetFillColor(0)
        canvas.SetGridx()
        canvas.SetGridy()

        HistBG = TH1F("BG", "", 10, 0, 10)
        HistBG.GetXaxis().SetRangeUser(0, 4)
        HistBG.GetXaxis().SetLabelSize(.05)
        HistBG.GetXaxis().SetTitle("LT(=Pt_{l1} + Pt_{l2}) [GeV]")
        HistBG.GetXaxis().SetTitleOffset(1.4)
        HistBG.GetYaxis().SetRangeUser(lowY, highY)
        HistBG.GetYaxis().SetTitle("Expected Limit")
        for i in range(len(LTCut)):
            HistBG.GetXaxis().SetBinLabel(i + 1, str(LTCut[i]))
        HistBG.Draw()

        InFile = ROOT.TFile.Open("OutFile_" +cut0+Channel+".root", "READ")
        for j in range(len(leptonIsolation)):
            Hist[j] = InFile.Get(str(leptonIsolation[j]))
            Hist[j].SetMarkerStyle(20)
            Hist[j].SetMarkerSize(1.3)
            Hist[j].SetLineWidth(2)
            Hist[j].SetLineColor(j + 6)
            Hist[j].Draw("Plsame")

        l = TLegend(0.70, 0.70, 0.9, 0.9, "", "brNDC")
        l.SetBorderSize(0)
        l.SetFillColor(0)
        l.SetTextSize(.03)
        for k in range(len(leptonIsolation)):
            lgnd = "Isolation < " + str(leptonIsolation[k])
            l.AddEntry(Hist[k], lgnd, "lpf")
        l.Draw()

        #Text in Histogram
        t = TLatex()
        t.SetNDC()
        t.SetTextFont(62)
        t.SetTextAlign(12)
        t.SetTextSize(0.035)
        t.DrawLatex(0.1, .92, "CMS Preliminary 2012")
        t.DrawLatex(0.35, .92, "#sqrt{s} = 8 TeV, L = 19.8 fb^{-1}")
        t.SetTextColor(2)
        t.DrawLatex(0.65, .92, " LL"+Channel)
        t.DrawLatex(0.75, .92, cut0+"Mass")


        canvas.SaveAs("finalCompare_"+cut0 + Channel + "_NewSystematic.pdf")
Ejemplo n.º 3
0
def GetTLatex(t, x, y, s = 0.04):
  t = TLatex(-20, 50, t);
  t.SetNDC();
  t.SetTextAlign(12);
  t.SetX(x);
  t.SetY(y);
  t.SetTextFont(42);
  t.SetTextSize(s);
  t.Draw()
  return t
Ejemplo n.º 4
0
def drawText(x, y, t, isNDC=False):
    text = TLatex()
    text.SetTextColor(1)
    text.SetTextFont(42)
    text.SetTextAlign(23)
    text.SetTextSize(0.04)
    if isNDC: text.DrawLatexNDC(x, y, t)
    else: text.DrawLatex(x, y, t)
    text.Draw()
    return text
Ejemplo n.º 5
0
def setupTextOnPlot(plotText, t_textSize, t_alignment, t_x,  t_start, t_gap):

    l_plotText = PythonUtils.makeListFromString(plotText, '?')
    t = TLatex()
    t.SetNDC()
    t.SetTextSize(float(t_textSize))
    t.SetTextAlign(int(t_alignment))
    for item in l_plotText:
        t.DrawLatex(float(t_x), float(t_start), item)
        t_start = float(t_start) - float(t_gap)
Ejemplo n.º 6
0
 def DrawTextCMSmode(self):
     texpre = TLatex(0, 0, self.texcmsMode)
     texpre.SetNDC()
     texpre.SetTextAlign(12)
     texpre.SetX(self.texcmsModeX)
     texpre.SetY(self.texcmsModeY)
     texpre.SetTextFont(52)
     texpre.SetTextSize(self.texcmsModeS)
     texpre.SetTextSizePixels(22)
     return texpre
Ejemplo n.º 7
0
def drawlabel(xposition, yposition, text):
    latex = TLatex()
    latex.SetNDC()
    latex.SetTextSize(0.035)
    latex.SetTextColor(1)
    latex.SetTextFont(42)
    latex.SetTextAlign(33)
    #latex.SetTextAlign(11)
    #latex.DrawLatex(%f, %f, "%s" %(float(xposition),float(yposition),text))
    latex.DrawLatex(float(xposition), float(yposition), text)
Ejemplo n.º 8
0
def makeLabel(label_text):

    label = TLatex(0.65, 0.62, label_text)
    label.SetNDC()
    label.SetTextAlign(21)
    label.SetTextFont(42)
    label.SetTextColor(ROOT.kBlack)
    label.SetTextSize(0.04)
    label.SetTextAngle(0)
    return label
Ejemplo n.º 9
0
 def _draw_title(self):
     """Draws a title on the plot.
     """
     title = TLatex()
     title.SetTextColor(self.PLOT_TITLE_TEXT_COLOR)
     title.SetTextFont(self.PLOT_TITLE_TEXT_FONT)
     title.SetNDC()
     title.SetTextSize(self.PLOT_TITLE_TEXT_SIZE)
     title.SetTextAlign(22)
     title.DrawLatex(self.PLOT_TITLE_X, self.PLOT_TITLE_Y, self._title)
Ejemplo n.º 10
0
def drawRegion(channel, left=False):
    region = {
        "OSmumu": "#mu^{+}#mu^{-} / #mu^{-}#mu^{+}",
        "OSee": "e^{+}e^{-} / e^{-}e^{+}",
        "OSemu": "e^{+}#mu^{-} / e^{-}#mu^{+}",
        "SSmumu": "#mu^{+}#mu^{+} / #mu^{-}#mu^{-}",
        "SSee": "e^{+}e^{+} / e^{-}e^{-}",
        "SSemu": "e^{+}#mu^{+} / e^{-}#mu^{-}",
        "WZCR": "W(lv)Z(ll)",
        "VgCR": "V#gamma",
        "SSmue": "#mu^{+}e^{+} / #mu^{-}e^{-}"
    }
    text = ""
    if channel in region:
        text = region[channel]
    else:
        # leptons
        #if 'ee' in channel: text += "2e"
        #elif 'mumu' in channel: text += "2#mu"
        if 'OSmumu' in channel: text += "#mu^{#pm}#mu^{#mp}"
        elif 'OSee' in channel: text += "e^{+}e^{-}"
        elif 'OSemu' in channel: text += "e^{+}#mu^{-}"
        elif 'SSmumu' in channel: text += "#mu^{+}#mu^{+} / #mu^{-}#mu^{-}"
        elif 'SSee' in channel: text += "e^{+}e^{+} / e^{-}e^{-}"
        elif 'SSemu' in channel: text += "e^{+}#mu^{+} / e^{-}#mu^{-}"
        elif (('me' in channel) or ('em' in channel)): text += "1e 1#mu"
        elif 'e' in channel: text += "1e"
        elif 'm' in channel: text += "1#mu"
        elif 'll' in channel: text += "2l"
        elif 'l' in channel: text += "1l"
        elif 'nn' in channel: text += "0l"
        if 'Top' in channel: text += "top"
        # b-tag
        if 'bb' in channel: text += ", 2 b-tag"
        elif 'b' in channel: text += ", 1 b-tag"
        # purity
        if 'lp' in channel: text += ", low purity"
        elif 'hp' in channel: text += ", high purity"
        # region
        if 'TR' in channel: text += ", top control region"
        elif 'Inc' in channel: text += ", inclusive region"
        elif 'SB' in channel: text += ", sidebands region"
        elif 'SR' in channel: text += ", signal region"
        elif 'NR' in channel: text += ", inclusive region"
        elif 'MC' in channel: text += ", simulation"

    latex = TLatex()
    latex.SetNDC()
    latex.SetTextFont(72)  #52
    latex.SetTextSize(0.035)
    if left: latex.DrawLatex(0.15, 0.75, text)
    else:
        latex.SetTextAlign(22)
        latex.DrawLatex(0.5, 0.85, text)
    pass
Ejemplo n.º 11
0
def draw2d(hist, xtitle, ytitle, number=False, nxbins=0, nybins=0):
    """Draw 2D histogram."""
    tsize = 0.045
    lines = []
    xmin, xmax = hist.GetXaxis().GetXmin(), hist.GetXaxis().GetXmax()
    ymin, ymax = hist.GetYaxis().GetXmin(), hist.GetYaxis().GetXmax()
    canvas = TCanvas('canvas', 'canvas', 100, 100, 900, 800)
    canvas.SetMargin(0.11, 0.16, 0.10, 0.02)  # LRBT
    canvas.SetLogz()
    hist.GetXaxis().SetTitle(xtitle)
    hist.GetYaxis().SetTitle(ytitle)
    hist.GetZaxis().SetTitle("Events")
    hist.GetXaxis().SetTitleSize(tsize)
    hist.GetYaxis().SetTitleSize(tsize)
    hist.GetZaxis().SetTitleSize(tsize)
    hist.GetXaxis().SetLabelSize(0.9 * tsize)
    hist.GetYaxis().SetLabelSize(0.9 * tsize)
    hist.GetZaxis().SetLabelSize(0.9 * tsize)
    hist.GetXaxis().SetTitleOffset(1.04)
    hist.GetYaxis().SetTitleOffset(1.14)
    hist.GetZaxis().SetTitleOffset(1.08)
    hist.Draw('COLZ')
    if number:
        latex = TLatex()
        latex.SetTextSize(0.8 * tsize)
        latex.SetTextAlign(22)
        latex.SetTextFont(62)
        latex.SetTextColor(kRed)
        for ix in range(1, hist.GetXaxis().GetNbins() + 1):
            x = hist.GetXaxis().GetBinCenter(ix)
            for iy in range(1, hist.GetYaxis().GetNbins() + 1):
                y = hist.GetYaxis().GetBinCenter(iy)
                latex.DrawLatex(x, y, str(Unroll.GetBin(x, y)))
    if nxbins > 0:  # divide with nlines
        for i in range(1, nxbins):
            x = xmin + (xmax - xmin) * i / nxbins
            line = TLine(x, ymin, x, ymax)
            line.SetLineColor(kRed)
            line.SetLineStyle(kDashed)
            line.SetLineWidth(1)
            line.Draw()
            lines.append(line)
    if nybins > 0:  # divide with nlines
        for i in range(1, nybins):
            y = ymin + (ymax - ymin) * i / nybins
            line = TLine(xmin, y, xmax, y)
            line.SetLineColor(kRed)
            line.SetLineStyle(kDashed)
            line.SetLineWidth(2)
            line.Draw()
            lines.append(line)
    canvas.RedrawAxis()
    canvas.SaveAs(hist.GetName() + ".png")
    #canvas.SaveAs(hist.GetName()+".pdf")
    canvas.Close()
Ejemplo n.º 12
0
 def draw_cms(self, textsize=0.0375):
     """Write CMS name and data information."""
     if self._above:
         y = 0.92
         align = (31, 11)
     else:
         y = 0.88
         align = (33, 13)
     text = TLatex()
     text.SetNDC()
     text.SetTextFont(62)
     text.SetTextSize(textsize)
     text.SetTextAlign(align[0])
     if not self._simulation:
         if self.fill <= 4720:
             theyear = 2015
         elif self.fill < 5600:
             theyear = 2016
         elif self.fill < 6500:
             theyear = 2017
         else:
             theyear = 2018
         if self.fill <= 4647 and self.fill >= 4634:
             theenergy = '5.02 TeV'
         elif self.fill < 5563 and self.fill >= 5505:
             theenergy = 'Pbp, 8.16 TeV'
         elif self.fill <= 5575 and self.fill >= 5563:
             theenergy = 'pPb, 8.16 TeV'
         else:
             theenergy = '13 TeV'
         thetext = 'Fill {} ({}, {})'.format(self.fill, theyear, theenergy)
         text.DrawLatex(0.88, y, thetext)
     text.SetTextAlign(align[1])
     if self.workinprogress and self._simulation:
         thetext = '#bf{#scale[0.75]{#it{Simulation, Work in Progress}}}'
     elif self.workinprogress and not self._simulation:
         thetext = '#bf{#scale[0.75]{#it{Work in Progress}}}'
     elif not self.workinprogress and self._simulation:
         thetext = 'CMS #bf{#scale[0.75]{#it{Simulation Preliminary}}}'
     else:
         thetext = 'CMS #bf{#scale[0.75]{#it{Preliminary}}}'
     text.DrawLatex(0.15, y, thetext)
Ejemplo n.º 13
0
def drawRegion(channel, left=False):

    latex = TLatex()
    latex.SetNDC()
    latex.SetTextFont(72)  #52
    latex.SetTextSize(0.035)
    if left: latex.DrawLatex(0.15, 0.75, channel)
    else:
        latex.SetTextAlign(22)
        latex.DrawLatex(0.5, 0.85, channel)
    pass
Ejemplo n.º 14
0
    def SetCanvas(self):
        self.canvas = None
        self.plot = None
        self.ratio = None
        c = TCanvas('c', 'c', 10, 10, 1600, 1200)
        if self.doRatio:
            c.Divide(1, 2)
            plot = c.GetPad(1)
            ratio = c.GetPad(2)
        else:
            plot = c.GetPad(0)
        #if self.doRatio:
        plot.SetPad(self.hpadx0, self.hpady0, self.hpadx1, self.hpady1)
        plot.SetMargin(self.hpadMleft, self.hpadMright, self.hpadMbottom,
                       self.hpadMtop)
        #else: plot = c.GetPad(0)

        if self.doRatio:
            ratio.SetPad(self.rpadx0, self.rpady0, self.rpadx1, self.rpady1)
            ratio.SetMargin(self.rpadMleft, self.rpadMright, self.rpadMbottom,
                            self.rpadMtop)
        else:
            #ratio.SetPad(0,0,0,0)
            plot.SetPad(0, 0, 1, 1)

        # Draw the text
        texcms = self.DrawTextCMS()
        texmod = self.DrawTextCMSmode()
        texlum = self.DrawTextLumi()
        self.Tex.append(texcms)
        self.Tex.append(texmod)
        self.Tex.append(texlum)
        if hasattr(self, 'texch') and self.texch != '':
            tch = TLatex(-20, 50, self.texch)
            tch.SetNDC()
            tch.SetTextAlign(12)
            tch.SetX(self.texchX)
            tch.SetY(self.texchY)
            tch.SetTextFont(42)
            tch.SetTextSize(self.texchS)
            self.Tex.append(tch)
        for r in self.Tex:
            r.Draw()

        TGaxis.SetMaxDigits(3)
        if self.doSetLogY: plot.SetLogy()

        # Legend
        self.legend = self.SetLegend()
        self.legendRatio = self.SetLegendRatio()

        self.canvas = c
        self.plot = plot
        if self.doRatio: self.ratio = ratio
Ejemplo n.º 15
0
def drawEnPu(pileup=None, lumi=None):
    latex = TLatex()
    latex.SetNDC()
    latex.SetTextSize(0.046)
    latex.SetTextColor(1)
    latex.SetTextFont(42)
    latex.SetTextAlign(31)
    tex = '(13 TeV)'
    if pileup: tex += ', {0} PU'.format(pileup)
    if lumi: tex = '{0} '.format(lumi) + tex
    latex.DrawLatex(0.95, 0.93, tex)
Ejemplo n.º 16
0
def make_ratio(nom, up, down, channel):
    ratio1 = up.Clone("ratio")
    #ratio1.Sumw2()
    ratio1.SetStats(0)
    ratio1.Add(nom, -1)
    ratio1.Divide(nom)
    ratio1.Scale(100)
    ratio1.SetTitle("")
    y = ratio1.GetYaxis()
    y.SetTitle("#frac{Syst-Nom.}{Nom.} [%]")
    y.SetNdivisions(505)
    y.SetTitleOffset(2.3)
    y.SetTitleSize(15)
    x = ratio1.GetXaxis()
    x.SetTitle("event level descriminator")
    x.SetTitleOffset(6.2)
    ratio1.SetLineColor(632)
    ratio1.SetFillColor(632)
    ratio1.SetMarkerColor(632)
    ratio1.SetMarkerStyle(0)
    ratio1.Draw("hist")
    ratio2 = down.Clone("ratio")
    #ratio2.Sumw2()
    ratio2.Add(nom, -1)
    ratio2.Divide(nom)
    ratio2.Scale(100)
    ratio2.SetLineColor(857)
    ratio2.SetFillColor(857)
    ratio2.SetMarkerColor(857)
    ratio2.SetMarkerStyle(0)
    ratio2.Draw("same hist")
    line = TF1("fa1", "0", -1000, 1000)
    line.SetLineColor(1)
    line.Draw("same")
    ymax = abs(ratio1.GetMaximum())
    ymin = abs(ratio2.GetMaximum())
    Range = [ymax, ymin]
    maxv = max(Range)
    if maxv < 0.8:
        offset = 0.2
    else:
        offset = 0.8
    ratio1.SetMinimum(-maxv - offset)
    ratio1.SetMaximum(maxv + offset)
    ratio2.SetMinimum(-maxv - offset)
    ratio2.SetMaximum(maxv + offset)
    channel_label = TLatex()
    channel_label.SetNDC()
    channel_label.SetTextAlign(12)
    channel_label.SetTextFont(63)
    channel_label.SetTextSizePixels(15)
    channel_label.DrawLatex(0.45, 0.89, channel)
    channel_label.Draw("same")
    return ratio1, ratio2, line, channel_label
Ejemplo n.º 17
0
def settitle(title='DEFAULT'):
    if title == 'DEFAULT':
        title = '{0:.1f} fb^{{-1}} (13 TeV)'.format(lumi / 1000.)
    xpos = 1. - ROOT.gPad.GetRightMargin()
    ypos = 1. - ROOT.gPad.GetTopMargin()
    lxtitle = TLatex(0., 0., 'Z')
    lxtitle.SetNDC(True)
    lxtitle.SetTextFont(43)
    lxtitle.SetTextSize(30)
    lxtitle.SetTextAlign(31)
    lxtitle.DrawLatex(xpos, ypos + 0.02, title)
Ejemplo n.º 18
0
def drawEnYear(pileup=None, year=None):
    latex = TLatex()
    latex.SetNDC()
    latex.SetTextSize(0.046)
    latex.SetTextColor(1)
    latex.SetTextFont(42)
    latex.SetTextAlign(31)
    tex = '13 TeV'
    if pileup: tex += ', {0} PU'.format(pileup)
    if year: tex = tex + ' ({0})'.format(year)
    latex.DrawLatex(0.95, 0.93, tex)
Ejemplo n.º 19
0
def drawCMS(samples, LUMI, text, onTop=False, left_marg_CMS=0.15,data_obs=[]):
    latex = TLatex()
    latex.SetNDC()
    latex.SetTextSize(0.04)
    latex.SetTextColor(1)
    latex.SetTextFont(42)
    latex.SetTextAlign(33)
    if (type(LUMI) is float or type(LUMI) is int) and float(LUMI) > 0: latex.DrawLatex(0.95, 0.985, "%.1f fb^{-1}  (13 TeV)" % (float(LUMI)/1000.))
    elif type(LUMI) is str: latex.DrawLatex(0.95, 0.985, "%s fb^{-1}  (13 TeV)" % LUMI)
    if not onTop: latex.SetTextAlign(11)
    latex.SetTextFont(62)
    latex.SetTextSize(0.05 if len(text)>0 else 0.06)
    if not onTop:
        latex.DrawLatex(left_marg_CMS, 0.8 if len(text)>0 else 0.84, "CMS")
    else:
        latex.DrawLatex(0.20, 0.9, "CMS")#DCMS
    latex.SetTextSize(0.045)
    latex.SetTextFont(52)
    if not onTop:
        latex.DrawLatex(left_marg_CMS, 0.89, text)#0.7
    else:
        #latex.DrawLatex(0.40, 0.98, text)
        latex.DrawLatex(0.35, 0.89, text)#DCMS
    dat = ""
    if len(data_obs)>0:
        print samples[data_obs[0]]['files'][0]
        if "SingleMuon" in (samples[data_obs[0]]['files'][0]):
            dat = "SingleLepton dataset"
        elif "SingleElectron" in (samples[data_obs[0]]['files'][0]):
            dat = "SingleLepton dataset"
        elif "DisplacedJet" in (samples[data_obs[0]]['files'][0]):
            dat = "DisplacedJet dataset"
        elif "MET" in (samples[data_obs[0]]['files'][0]):
            dat = "MET dataset"
        print "dat: ", dat
        latex2 = TLatex()
        latex2.SetNDC()
        latex2.SetTextFont(72) #52
        latex2.SetTextSize(0.04)
        latex2.SetTextAlign(10)
        latex2.DrawLatex(0.45, 0.95, dat)
Ejemplo n.º 20
0
def drawCMSHeader(pad, lumi_text, extra_text, flav_text):

    pad.cd()

    top_margin = pad.GetTopMargin()
    header_offset = top_margin * 0.2

    left_margin = pad.GetLeftMargin() * 1.33

    header = TLatex(left_margin, 0.8, 'CMS')
    header.SetNDC()
    header.SetTextAngle(0)
    header.SetTextColor(ROOT.kBlack)
    header.SetTextFont(61)
    header.SetTextAlign(11)
    cmsLabelSize = top_margin * 1.3
    header.SetTextSize(cmsLabelSize)
    cms_x_position = header.GetXsize()
    header.DrawLatex(left_margin, 0.78, 'CMS')

    extra_text_size = cmsLabelSize * 0.76
    header.SetTextFont(52)
    header.SetTextSize(extra_text_size)
    #    header.DrawLatex( left_margin + 1.2 * cms_x_position, 1 - top_margin + header_offset, extra_text )
    header.DrawLatex(left_margin, 0.67, extra_text)

    lumi_text_size = top_margin * 0.7
    header.SetTextFont(42)
    header.SetTextAlign(31)
    header.SetTextSize(lumi_text_size)
    right_margin = pad.GetRightMargin()
    header.DrawLatex(1. - right_margin, 1. - top_margin + header_offset,
                     lumi_text)

    flav_text_size = top_margin * 0.75
    header.SetTextFont(42)
    header.SetTextAlign(31)
    header.SetTextSize(flav_text_size)
    right_margin = pad.GetRightMargin()
    header.DrawLatex(0.7 - right_margin, 1. - top_margin + header_offset,
                     flav_text)
Ejemplo n.º 21
0
def drawCMS(lumi, text, onTop=False):
    latex = TLatex()
    latex.SetNDC()
    latex.SetTextSize(0.04)
    latex.SetTextColor(1)
    latex.SetTextFont(42)
    latex.SetTextAlign(33)
    if (type(lumi) is float or type(lumi) is int) and float(lumi) > 0:
        latex.DrawLatex(0.95, 0.985,
                        "%.1f fb^{-1}  (13 TeV)" % (float(lumi) / 1000.))
    elif type(lumi) is str:
        latex.DrawLatex(0.95, 0.985, "%s fb^{-1}  (13 TeV)" % lumi)
    if not onTop: latex.SetTextAlign(11)
    latex.SetTextFont(62)
    latex.SetTextSize(0.05 if len(text) > 0 else 0.06)
    if not onTop: latex.DrawLatex(0.15, 0.87 if len(text) > 0 else 0.84, "CMS")
    else: latex.DrawLatex(0.20, 0.99, "CMS")
    latex.SetTextSize(0.04)
    latex.SetTextFont(52)
    if not onTop: latex.DrawLatex(0.15, 0.83, text)
    else: latex.DrawLatex(0.40, 0.98, text)
Ejemplo n.º 22
0
def doubleGaus(hist, units, color, xLeft, yLow, same, fitInput, title):

    can = TCanvas(title, title)
    can.cd()
    hist.Draw()

    #min = hist.GetMean() - 1 * hist.GetRMS()
    #max = hist.GetMean() + 1 * hist.GetRMS()
    min = -0.5
    max = 0.5
    #print "Fitting from",min,"to",max
    FZ01 = TF1(
        "FZ01",
        "[0]*exp(-0.5*((x-[1])/[2])**2)+[3]*exp(-0.5*((x-[4])/[5])**2)", min,
        max)
    FZ01.SetParameter(0, fitInput[0])
    FZ01.SetParameter(1, fitInput[1])
    FZ01.SetParameter(2, fitInput[2])
    FZ01.SetParameter(3, fitInput[3])
    FZ01.SetParameter(4, fitInput[4])
    FZ01.SetParameter(5, fitInput[5])

    FZ01.SetLineColor(color)
    FZ01.SetLineWidth(1)
    hist.Fit("FZ01", "ORQ", "same")

    FZ01.Draw("same")
    hist.Draw("same")

    text = "#mu="
    text += str(int(1000 * FZ01.GetParameter(1)))

    print 1000 * FZ01.GetParameter(1)
    print 1000 * FZ01.GetParameter(2)
    print 1000 * FZ01.GetParameter(4)
    print 1000 * FZ01.GetParameter(5)

    #text += str(round(FZ01.GetParameter(1),4))
    text += " " + units + ", #sigma="
    text += str(int(1000 * FZ01.GetParameter(2)))
    #text += str(round(FZ01.GetParameter(2),4))
    text += " " + units

    m_l = TLatex()
    m_l.SetTextSize(0.04)
    m_l.SetTextAlign(12)
    m_l.SetNDC()
    m_l.DrawLatex(xLeft, yLow, text)

    if writeOut:
        can.SaveAs(title + ".png")

    return m_l, can, FZ01, hist
Ejemplo n.º 23
0
def drawCMS_simple(LUMI, text, ERA="",onTop=False, left_marg_CMS=0.20,left_marg_LUMI=0.95):
    latex = TLatex()
    latex.SetNDC()
    latex.SetTextSize(0.04)
    latex.SetTextColor(1)
    latex.SetTextFont(42)
    latex.SetTextAlign(33)
    era_str = ""
    if ERA!="":
        era_str = ", "+ERA
    if (type(LUMI) is float or type(LUMI) is int) and float(LUMI) > 0:
        latex.DrawLatex(left_marg_LUMI, 0.985, ("%.1f fb^{-1}  (13 TeV%s)") % (float(LUMI)/1000.,era_str) )
    elif type(LUMI) is str:
        latex.DrawLatex(left_marg_LUMI, 0.985, ("%s fb^{-1}  (13 TeV%s)" % (LUMI,era_str)) )
    if not onTop: latex.SetTextAlign(11)
    latex.SetTextFont(62)
    latex.SetTextSize(0.05 if len(text)>0 else 0.06)
    latex.DrawLatex(left_marg_CMS, 0.98, "CMS")
    latex.SetTextSize(0.045)
    latex.SetTextFont(52)
    latex.DrawLatex(left_marg_CMS+0.2, 0.98, text)
Ejemplo n.º 24
0
def drawRegion(channel, left=False):
    #if not channel.startswith('X'): return False
    text = getChannel(channel)

    latex = TLatex()
    latex.SetNDC()
    latex.SetTextFont(72)  #52
    latex.SetTextSize(0.04)
    if left: latex.DrawLatex(0.15, 0.79, text)
    else:
        latex.SetTextAlign(22)
        latex.DrawLatex(0.5, 0.85, text)
Ejemplo n.º 25
0
 def DrawTextLumi(self):
   if not hasattr(self, 'lumi'): self.lumi = 0
   t = self.texlumi if not '%' in self.texlumi else (self.texlumi%self.lumi if not self.doinvfb else self.texlumi%(self.lumi/1000.))
   tlum = TLatex(-20., 50., t)
   tlum.SetNDC()
   tlum.SetTextAlign(12)
   tlum.SetTextFont(42)
   tlum.SetX(self.texlumiX)
   tlum.SetY(self.texlumiY)
   tlum.SetTextSize(self.texlumiS)
   tlum.SetTextSizePixels(22)
   return tlum
Ejemplo n.º 26
0
def drawRegion(channel, left=False):
    #if not channel.startswith('X'): return False
    #text = getChannel(channel)
    
    region = {"SR" : "1 + 2 b-tag categories", "SR1" : "1 b-tag category", "SR2" : "2 b-tag category", "ZCR" : "Z region", "ZeeCR" : "2e region", "ZeebCR" : "2e, 1 b-tag region",\
 "ZeebbCR" : "2e, 2 b-tag region", "ZmmCR" : "2#mu region", "ZmmbCR" : "2#mu, 1 b-tag region", "ZmmbbCR" : "2#mu, 2 b-tag region", "WCR" : "W region", "WeCR" : "1e region", "WebC\
R" : "1e, 1 b-tag region", "WebbCR" : "1e, 2 b-tag region", "WmCR" : "1#mu region", "WmbCR" : "1#mu, 1 b-tag region", "WmbbCR" : "1#mu, 2 b-tag region", "TCR" : "1#mu, 1e region"\
, "TbCR" : "1#mu, 1e, 1 b-tag region", "TbbCR" : "1#mu, 1e, 2 b-tag region", "CR" : "Control regions", "ZmmInc" : "2#mu selection", "ZeeInc" : "2e selection", "WmInc" : "1#mu sel\
ection", "WeInc" : "1e selection", "TInc" : "1#mu, 1e selection", "XVh" : "0l, 1l, 2l channel", "XZh" : "0l, 2l channel", "XWh" : "1l channel", "XZhnn" : "0l channel", "XZhll" : \
"2l channel", "XZhee" : "2e channel", "XZhmm" : "2#mu channel", "XWhen" : "1e channel", "XWhmn" : "1#mu channel"}

    text = ""
    if channel in region:
        text = region[channel]
    elif channel.startswith('X'):
        # leptons                                                                                                                                                                  
        if 'ee' in channel: text += "2e"
        elif 'e' in channel: text += "1e,1#tau"
        if 'mm' in channel: text += "2#mu"
        elif 'm' in channel: text += "1l,1#tau"#"1#mu,1#tau"                                                                                                                       
        if 'll' in channel: text += "2l"
        elif 'l' in channel: text += "1l"
        if 'nn' in channel: text += "0l"
        if 't' in channel: text += "2#tau"



        # b-tag                                                                                                                                                                    
        if 'bb' in channel: text += ", 2 b-tag"
        elif 'b' in channel: text += ", 1 b-tag"
        if 'qq' in channel: text += ", HP"
        elif 'q' in channel: text += ", LP"

        #if 'TR' in channel: text += ", top control region"
        #elif 'Inc' in channel: text += ", inclusive region"
        #elif 'SB' in channel: text += ", sidebands region"
        #elif 'SR' in channel:
        if "Wwind" in channel: text += ", W mass"
        elif "Zwind" in channel: text += ", Z mass"
        elif "Hwind" in channel: text += ", H mass"
        text += " region"
        #elif 'MC' in channel: text += ", simulation"
    else:
        return False

    latex = TLatex()
    latex.SetNDC()
    latex.SetTextFont(72) #52
    latex.SetTextSize(0.04)
    if left: latex.DrawLatex(0.15, 0.75, text)
    else:
        latex.SetTextAlign(22)
        latex.DrawLatex(0.5, 0.85, text)
Ejemplo n.º 27
0
def drawCMS(lumi, text, onTop=False, year='', suppressCMS=False):
    latex = TLatex()
    latex.SetNDC()
    latex.SetTextSize(0.045)
    latex.SetTextColor(1)
    latex.SetTextFont(42)
    latex.SetTextAlign(33)
    if (type(lumi) is float or type(lumi) is int):
        if float(lumi) > 0:
            latex.DrawLatex(0.95, 0.99,
                            "%.1f fb^{-1}  (13 TeV)" % (float(lumi) / 1000.))
        if year != '':
            if year == "run2": year = "RunII"
            latex.DrawLatex(0.24, 0.99, year)
        elif float(lumi) > 0:
            if lumi == 35920.:
                year = '2016'
            elif lumi == 41530.:
                year = '2017'
            elif lumi == 59740.:
                year = '2018'
            elif lumi == 137190.:
                year = 'RunII'
            latex.DrawLatex(0.24, 0.99, year)
        else:
            latex.DrawLatex(0.95, 0.99, "(13 TeV)")
    elif type(lumi) is str:
        latex.DrawLatex(0.95, 0.985, "%s  (13 TeV)" % lumi)
    if not onTop: latex.SetTextAlign(11)
    latex.SetTextFont(62)
    latex.SetTextSize(0.05 if len(text) > 0 else 0.06)
    if not suppressCMS:
        if not onTop:
            latex.DrawLatex(0.15, 0.88 if len(text) > 0 else 0.85, "CMS")
        else:
            latex.DrawLatex(0.24, 0.9925, "CMS")
    latex.SetTextSize(0.04)
    latex.SetTextFont(52)
    if not onTop: latex.DrawLatex(0.15, 0.84, text)
    else: latex.DrawLatex(0.45, 0.98, text)
Ejemplo n.º 28
0
 def setchannel(self, title='e/#mu+jets, ' + njetstr):
     #def setchannel(self, title = 'e/#mu+jets, %s jets' %njets[0]):
     #def setchannel(self, title = 'e/#mu+jets, #geq%s jets' %njets[0]):
     #def setchannel(self, title = 'e/#mu+jets, #geq%s jets in SB' %njets[0]):
     #def setchannel(self, title = 'l+jets'):
     xpos = 1. - ROOT.gPad.GetRightMargin()
     ypos = 1. - ROOT.gPad.GetTopMargin()
     lxtitle = TLatex(0., 0., 'Z')
     lxtitle.SetNDC(True)
     lxtitle.SetTextFont(63)
     lxtitle.SetTextSize(25)
     lxtitle.SetTextAlign(13)
     lxtitle.DrawLatex(0.35, ypos - 0.03, title)
Ejemplo n.º 29
0
def drawCMS(lumi, year, text, onTop=False):
    latex = TLatex()
    latex.SetNDC()
    latex.SetTextSize(0.045)
    latex.SetTextColor(1)
    latex.SetTextFont(42)
    latex.SetTextAlign(33)
    if year=='combined':
        year='RunII'
    if (type(lumi) is float or type(lumi) is int):
        if float(lumi) > 0: latex.DrawLatex(0.95, 0.99, "%s, %.1f fb^{-1}  (13 TeV)" % (year,float(lumi)/1000.))
        else: latex.DrawLatex(0.95, 0.99, "(13 TeV)")
    elif type(lumi) is str: latex.DrawLatex(0.95, 0.985, "%s, %s  (13 TeV)" % (year,lumi))
    if not onTop: latex.SetTextAlign(11)
    latex.SetTextFont(62)
    latex.SetTextSize(0.05 if len(text)>0 else 0.06)
    if not onTop: latex.DrawLatex(0.15, 0.88 if len(text)>0 else 0.85, "CMS")
    else: latex.DrawLatex(0.24, 0.9925, "CMS")
    latex.SetTextSize(0.04)
    latex.SetTextFont(52)
    if not onTop: latex.DrawLatex(0.15, 0.84, text)
    else: latex.DrawLatex(0.45, 0.98, text)
Ejemplo n.º 30
0
def drawCMS(lumi, text, onTop=False):
    latex = TLatex()
    latex.SetNDC()
    latex.SetTextSize(0.05)
    latex.SetTextColor(1)
    latex.SetTextFont(42)
    latex.SetTextAlign(33)
    if float(lumi) > 0:
        latex.DrawLatex(0.95, 0.98,
                        "%.2f fb^{-1}  (13 TeV)" % (float(lumi) / 1000.))
    if not onTop: latex.SetTextAlign(11)
    latex.SetTextFont(62)
    latex.SetTextSize(0.055)
    if not onTop: latex.DrawLatex(0.2, 0.83, "CMS")
    else: latex.DrawLatex(0.2, 0.98, "CMS")
    latex.SetTextSize(0.055)
    latex.SetTextFont(52)
    if not onTop: latex.DrawLatex(0.33, 0.83, text)
    else: latex.DrawLatex(0.33, 0.98, text)  # 0.40 preliminary; 0.33 private
    latex.SetTextSize(0.04)
    latex.SetTextFont(62)
    latex.SetTextAlign(13)