Exemple #1
0
  def Draw(self, doSetLogy = False):
    self.SetCanvas()
    self.plot.cd()
    gPad.SetTickx();
    gPad.SetTicky();
    if not os.path.isdir(self.GetOutPath()): os.makedirs(self.GetOutPath())

    dmax = []; dmin = []
    for h in self.histos: 
      dmax.append(h[0].GetMaximum())
      dmin.append(h[0].GetMinimum())
      legsymbol = h[1] if h[1] != '' and h[1] != 0 else h[2]
      if   'hist' in legsymbol: legsymbol = 'l'
      elif 'e2'   in legsymbol: legsymbol = 'f'
      if h[1] != 0 and h[1] != '': h[0].Draw('same,'+h[1])
      # Draw errors
      if h[2] != 0 and h[2] != '': h[0].Draw('same,'+h[2])
      # Legend
      if h[3] != 0 and h[3] != '': self.legend.AddEntry(h[0], h[3], legsymbol)
    self.SetAxisPlot(self.histos[0][0])
    dmax = max(dmax)
    dmin = min(dmin)
    if self.legend.GetNRows() > 0: self.legend.Draw()

    # Set maximum and minimum
    if isinstance(self.PlotMaximum, float): self.histos[0][0].SetMaximum(self.PlotMaximum)
    else: self.histos[0][0].SetMaximum(dmax*self.PlotMaxScale)
    if isinstance(self.PlotMinimum, float): self.histos[0][0].SetMinimum(self.PlotMinimum)
    self.plot.SetLogy(doSetLogy)

    if self.doRatio: 
      if self.autoRatio:
        hratio = self.histos[0][0].Clone("hratio")
        self.SetAxisRatio(hratio)
        if len(self.binLabels) > 0: 
          for i in range(len(self.binLabels)):
            hratio.GetXaxis().SetBinLabel(i+1,self.binLabels[i])
        nbins = hratio.GetNbinsX()
        for h in self.histos[1:]: 
          htemp    = h[0].Clone(h[0].GetName()+'ratio')
          htempRat = hratio.Clone(h[0].GetName()+'hratio')
          htempRat.Divide(htemp)
          self.AddRatioHisto(htempRat, h[1], h[2])
      self.ratio.cd()
      if len(self.ratioh) >= 1:
        self.SetAxisRatio(self.ratioh[0][0])
        self.ratioh[0][0].SetMaximum(self.PlotRatioMax)
        self.ratioh[0][0].SetMinimum(self.PlotRatioMin)
        for h in self.ratioh: 
          h[0].SetFillStyle(0)
          h[0].Draw(h[1] + ',same')
          if h[2] != 0 and h[2] != '': 
            hrat = h[0].Clone()
            hrat.SetFillStyle(3244)
            hrat.Draw('same,'+h[2])
        
    # Save
    gPad.SetTickx();
    gPad.SetTicky();
    self.Save()
Exemple #2
0
def gPadSet():
    gPad.SetTickx(1)
    gPad.SetTicky(1)
    gPad.SetLeftMargin(0.12)
    gPad.SetRightMargin(1.4)
    gPad.SetBottomMargin(0.10)
    gPad.SetFrameLineWidth(2)
    gPad.RedrawAxis()
Exemple #3
0
gPad.SetLeftMargin(0.15)
gr.Draw( 'AP' )

func1 = TF1('fun1', 'x', 0., 100.)
func1.SetLineColor(4)
func1.SetLineStyle(2)
func1.Draw('same')
####


c1.cd(2)
gPad.SetPad(small, small, 1.-small, 0.3-small)
gPad.SetTopMargin(small)
gPad.SetLeftMargin(0.15)
gPad.SetBottomMargin(0.3)
gPad.SetTickx()

gr1 = TGraph( n, energyVec, deltaE_f )
gr1.SetLineColor( 1 )
gr1.SetLineWidth( 1 )
gr1.SetMarkerStyle( 20 )
gr1.SetMarkerSize( makerSize )
gr1.SetMarkerColor( 2 )
gr1.SetTitle( '' )
textsize = labelSize/(gPad.GetWh()*gPad.GetAbsHNDC())
gr1.GetXaxis().SetTitle( 'E_{particle} (GeV)' )
gr1.GetYaxis().SetTitle( '#DeltaE/E_{particle}' )
gr1.GetXaxis().SetTitleOffset(1.2)
gr1.GetYaxis().SetTitleOffset(0.6)
gr1.GetYaxis().SetTitleSize(textsize)
gr1.GetXaxis().SetLabelSize(textsize)
Exemple #4
0
    def DrawStack(self, xtit='', ytit=''):
        ''' Draws a stack plot '''
        # Set the canvas and pads
        if xtit != '': self.axisXtit = xtit
        if ytit != '': self.axisYtit = ytit
        self.SetCanvas()

        # Stack processes and draw stack and data
        self.plot.cd()
        gPad.SetTickx()
        gPad.SetTicky()
        if not os.path.isdir(self.GetOutPath()): os.makedirs(self.GetOutPath())
        self.hStack.Draw('hist')
        if hasattr(self, 'MCstatUnc'): self.MCstatUnc.Draw("e2,same")
        if hasattr(self, 'MCunc'): self.MCunc.Draw("e2,same")

        # Extra histograms
        for h in self.overlapHistos:
            h.Draw("hist,same")

        # Errors in data
        if hasattr(self, 'hData'):
            self.hData.SetBinErrorOption(TH1.kPoisson)
            self.hData.Sumw2(False)
            self.hData.Draw('psameE0X0')  #self.data.GetDrawStyle())

        # Set Maximum
        datamax = self.hData.GetMaximum() if hasattr(self, 'hData') else -999
        bkgmax = self.TotMC.GetMaximum() if hasattr(
            self, 'TotMC') else self.hStack.GetStack().Last().GetMaximum()
        dmax = max(datamax, bkgmax)

        if isinstance(self.PlotMaximum, float):
            self.hStack.SetMaximum(self.PlotMaximum)
        else:
            self.hStack.SetMaximum(dmax * self.PlotMaxScale)
        if isinstance(self.PlotMinimum, float):
            self.hStack.SetMinimum(self.PlotMinimum)

        # Set titles...
        TGaxis.SetMaxDigits(3)
        self.SetAxisPlot(self.hStack)
        if self.doRatio:
            self.SetAxisRatio(self.hRatio)
            self.SetAxisRatio(self.hRatioUnc)
            self.SetAxisRatio(self.hRatioStatUnc)

        # Legend
        if hasattr(self, 'processes'):
            self.hleg = []
            leg = self.SetLegend()
            for pr in self.processes:
                h = self.TotMC.Clone('leg%s' % pr)
                h.SetFillStyle(1000)
                h.SetLineColor(0)
                h.SetLineWidth(0)
                h.SetFillColor(self.colors[pr])
                self.hleg.append(h)
                leg.AddEntry(self.hleg[-1], pr, 'f')
            for h in self.overlapHistos:
                leg.AddEntry(h, h.GetName(), 'l')
            if hasattr(self, 'hData'): leg.AddEntry(self.hData, 'data', 'pe')
            leg.Draw()

        # Ratio
        if self.doRatio:
            self.ratio.cd()
            legr = self.SetLegendRatio()
            if hasattr(self, 'hRatioStatUnc'):
                self.hRatioStatUnc.Draw('e2same')
                self.hRatioStatUnc.SetLineWidth(0)
                self.hRatioStatUnc.SetMaximum(self.PlotRatioMax)
                self.hRatioStatUnc.SetMinimum(self.PlotRatioMin)
                legr.AddEntry(self.hRatioStatUnc, 'Stat', 'f')
            if hasattr(self, 'hRatioUnc'):
                self.hRatioUnc.Draw('e2same')
                self.hRatioUnc.SetLineWidth(0)
                self.hRatioUnc.SetMinimum(self.PlotRatioMin)
                self.hRatioUnc.SetMaximum(self.PlotRatioMax)
                legr.AddEntry(self.hRatioUnc, 'Stat #oplus Syst', 'f')
            if hasattr(self, 'hRatio'):
                self.hRatio.Draw('pE0X0,same')
                self.hRatio.SetMaximum(self.PlotRatioMax)
                self.hRatio.SetMinimum(self.PlotRatioMin)
            for h in self.extraRatio:
                h.Draw("hist, same")
            legr.Draw()
        else:
            for r in self.Tex:
                r.Draw()

        if len(self.binLabels) > 0:
            for i in range(len(self.binLabels)):
                if self.doRatio:
                    if hasattr(self, 'hRatio'):
                        self.hRatio.GetXaxis().SetBinLabel(
                            i + 1, self.binLabels[i])
                    if hasattr(self, 'hRatioUnc'):
                        self.hRatioUnc.GetXaxis().SetBinLabel(
                            i + 1, self.binLabels[i])
                    if hasattr(self, 'hRatioStatUnc'):
                        self.hRatioStatUnc.GetXaxis().SetBinLabel(
                            i + 1, self.binLabels[i])
                else:
                    self.hStack.GetXaxis().SetBinLabel(i + 1,
                                                       self.binLabels[i])

        self.Save()
Exemple #5
0
def main():
    gStyle.SetOptStat(0)
    zplist = [600, 600, 1200, 1200, 2000, 2000]
    a0list = [300, 400, 300, 500, 300, 600]
    c1 = TCanvas('c1', 'c1', 3)
    gPad.SetTickx()
    gPad.SetTicky()
    c1.SetLeftMargin(0.12)
    h_frame = TH1F('frame', '', 60, 0, 1200)
    h_frame.SetXTitle('P^{miss}_{T} (GeV)')
    h_frame.SetYTitle('Arbitrary units')
    h_frame.SetMaximum(0.3)

    h_higgsPt = TH1F('h_higgsPt', 'h_higgsPt', 60, 0, 1200)
    h_higgsPtList = []
    rootfilelist = []
    for i in range(6):
        fName = 'rootFile/higgsPt_MZp' + str(zplist[i]) + '_MA0' + str(
            a0list[i]) + '.root'
        rootfile = TFile(fName)
        rootfilelist.append(rootfile)

    colorList = [61, 95, 65, 91, 69, 87]
    for i in range(6):
        hist = rootfilelist[i].Get('h_higgsPt')
        hist.SetName('h_higgsPt_MZp' + str(zplist[i]) + '_MA0' +
                     str(a0list[i]))
        h_higgsPtList.append(hist)
        h_higgsPtList[i].SetLineWidth(2)
        h_higgsPtList[i].SetLineColor(colorList[i])

    info_bar = TLatex(0, 0.305, 'CMS')
    info_bar_3 = TLatex(700, 0.15, '#font[42]{tan#beta=1.0}')
    info_bar_2 = TLatex(1200, 0.305, '35.9 fb^{-1} (13 TeV)')
    info_bar.SetTextSize(0.03)
    info_bar_2.SetTextSize(0.03)
    info_bar_3.SetTextSize(0.04)
    info_bar_2.SetTextAlign(31)
    leg = TLegend(0.32, 0.57, 0.87, 0.87)
    leg.SetBorderSize(0)
    for j in range(3):
        i = 2 * j
        text = 'M_{Z\'} = ' + str(zplist[i]) + ' GeV, M_{A} = ' + str(
            a0list[i]) + ' GeV'
        leg.AddEntry(h_higgsPtList[i], text)

    for j in range(3):
        i = 2 * j + 1
        text = 'M_{Z\'} = ' + str(zplist[i]) + ' GeV, M_{A} = ' + str(
            a0list[i]) + ' GeV'
        leg.AddEntry(h_higgsPtList[i], text)

    h_frame.Draw('hist')
    for i in range(6):
        h_higgsPtList[i].DrawNormalized('histsame')
    leg.Draw()
    info_bar.Draw()
    info_bar_2.Draw()
    info_bar_3.Draw()
    c1.Print('Zp2HDM_higgsPt_new.pdf')
    '''
Exemple #6
0
def drawHistsWithRatio(hists, name, **kwargs):
    """Draw histograms with ratios."""

    title = kwargs.get('title', "")
    xtitle = kwargs.get('xtitle', "")
    ytitle = kwargs.get('ytitle', "")
    rtitle = kwargs.get('rtitle', "Ratio")
    xmin = kwargs.get('xmin', hists[0].GetXaxis().GetXmin())
    xmax = kwargs.get('xmax', hists[0].GetXaxis().GetXmax())
    ymin = kwargs.get('ymin', None)
    ymax = kwargs.get('ymax', None)
    rmin = kwargs.get('rmin', 0.45)
    rmax = kwargs.get('rmax', 1.55)
    logx = kwargs.get('logx', False)
    logy = kwargs.get('logy', False)
    denom = kwargs.get('denom', 1) - 1  # denominator for ratio
    textsize = kwargs.get('textsize', 0.045)
    texts = kwargs.get('text', [])
    #textheight = kwargs.get('textheight',   1.09                 )
    #ctext      = kwargs.get('ctext',        [ ]                  ) # corner text
    #cposition  = kwargs.get('cposition',    'topleft'            ).lower() # cornertext
    #ctextsize  = kwargs.get('ctextsize',    1.4*legendtextsize   )
    colors = kwargs.get('colors', linecolors)
    if not isinstance(texts, list) or isinstance(texts, tuple):
        texts = [texts]
    if ymax == None:
        ymax = 1.12 * max(h.GetMaximum() for h in hists)

    # MAIN plot
    canvas = TCanvas('canvas', 'canvas', 100, 100, 800, 800)
    canvas.SetFillColor(0)
    canvas.SetBorderMode(0)
    canvas.SetFrameBorderMode(0)
    canvas.Divide(2)
    canvas.SetMargin(0.0, 0.0, 0.0, 0.0)
    canvas.cd(1)
    gPad.SetPad('pad1', 'pad1', 0, 0.33, 1, 1)
    gPad.SetMargin(0.12, 0.04, 0.02, 0.08)
    gPad.SetFillColor(0)
    gPad.SetBorderMode(0)
    gPad.SetTickx(0)
    gPad.SetTicky(0)
    gPad.SetGrid()
    gPad.Draw()
    canvas.cd(2)
    gPad.SetPad('pad2', 'pad2', 0, 0, 1, 0.33)
    gPad.SetMargin(0.12, 0.04, 0.30, 0.03)
    gPad.SetFillColor(0)
    gPad.SetFillStyle(4000)
    gPad.SetFrameFillStyle(0)
    gPad.SetBorderMode(0)
    gPad.Draw()

    # MAIN plot
    canvas.cd(1)
    for i, hist in enumerate(hists):
        color = colors[i % len(colors)]
        hist.SetLineColor(color)
        hist.SetLineWidth(2)
        hist.Draw('HIST SAME')
    frame = hists[0]
    frame.GetYaxis().SetTitleSize(0.060)
    frame.GetXaxis().SetTitleSize(0)
    frame.GetXaxis().SetLabelSize(0)
    frame.GetYaxis().SetLabelSize(0.052)
    frame.GetXaxis().SetLabelOffset(0.010)
    frame.GetXaxis().SetTitleOffset(0.98)
    frame.GetYaxis().SetTitleOffset(1.05)
    frame.GetXaxis().SetNdivisions(508)
    frame.GetYaxis().SetTitle(ytitle)
    frame.GetXaxis().SetTitle(xtitle)
    if logx:
        gPad.Update()
        gPad.SetLogx()
    if logy:
        gPad.Update()
        gPad.SetLogy()
    if ymin: frame.SetMinimum(ymin)
    if ymax: frame.SetMaximum(ymax)

    width = 0.25
    height = 1.1 * textsize * len([l for l in texts + hists if l])
    x1, y1 = 0.65, 0.88
    x2, y2 = x1 + width, y1 - height
    legend = TLegend(x1, y1, x2, y2)
    legend.SetTextSize(textsize)
    legend.SetBorderSize(0)
    legend.SetFillStyle(0)
    legend.SetFillColor(0)
    legend.SetMargin(0.05 / width)
    if title:
        legend.SetTextFont(62)
        legend.SetHeader(title)
    legend.SetTextFont(42)
    for hist in hists:
        legend.AddEntry(hist, hist.GetTitle(), 'l')
    for text in texts:
        legend.AddEntry(0, text, '')
    legend.Draw()

    gPad.SetTicks(1, 1)
    gPad.Modified()
    frame.Draw('AXIS SAME')
    CMS_style.CMS_lumi(gPad, 13, 0)

    # RATIO plot
    canvas.cd(2)
    ratios = []
    for i, hist in enumerate(hists):
        if i == denom: continue
        ratio = hist.Clone(hist.GetName() + "_ratio")
        ratio.Divide(hists[denom])
        ratio.Draw('HIST SAME')
        ratios.append(ratio)
    frame_ratio = ratios[0]
    frame_ratio.GetYaxis().SetRangeUser(rmin, rmax)
    frame_ratio.GetYaxis().CenterTitle()
    frame_ratio.GetYaxis().SetTitleSize(0.13)
    frame_ratio.GetXaxis().SetTitleSize(0.13)
    frame_ratio.GetXaxis().SetLabelSize(0.12)
    frame_ratio.GetYaxis().SetLabelSize(0.11)
    frame_ratio.GetXaxis().SetLabelOffset(0.012)
    frame_ratio.GetXaxis().SetTitleOffset(1.02)
    frame_ratio.GetYaxis().SetTitleOffset(0.48)
    frame_ratio.GetXaxis().SetNdivisions(508)
    frame_ratio.GetYaxis().CenterTitle(True)
    frame_ratio.GetYaxis().SetTitle(rtitle)
    frame_ratio.GetXaxis().SetTitle(xtitle)
    frame_ratio.GetYaxis().SetNdivisions(505)
    if logx:
        gPad.Update()
        gPad.SetLogx()
    line = TLine(xmin, 1., xmax, 1.)
    line.SetLineColor(hists[denom].GetLineColor())
    line.SetLineWidth(hists[denom].GetLineWidth())
    line.SetLineStyle(1)
    line.Draw('SAME')
    gPad.SetTicks(1, 1)
    gPad.Update()
    gPad.SetGrid()
    gPad.Modified()
    frame_ratio.Draw('SAME AXIS')

    canvas.SaveAs(name + ".png")
    canvas.SaveAs(name + ".pdf")
    canvas.Close()
Exemple #7
0
def make_canvas(name,xtitle,mass,rat1,rat2,rat4,rat5,rat6,zoom):
  if zoom:
    can = TCanvas(name+"_zoom")
    #rat1.GetYaxis().SetLimits(0.8,1.05)
  else:
    can = TCanvas(name)
    #rat1.GetYaxis().SetLimits(0.,1.05)
  gStyle.SetOptStat(0)
  if mass == "5":
    m1 = "5"
    m2 = "5.5"
  if mass == "6":
    m1 = "5"
    m2 = "7"
  if mass == "50":
    m1 = "50"
    m2 = "55"
  if mass == "60":
    m1 = "50"
    m2 = "70"
  rat1.SetTitle("DSA ID Efficiency: iDM(m1,m2) = (%s,%s) GeV"%(m1,m2))
  rat1.GetXaxis().SetTitle(xtitle)
  rat1.GetYaxis().SetTitle("Efficiency")
  rat1.SetMaximum(1.05)
  rat1.SetLineColor(kBlack)
  rat1.SetMarkerColor(kBlack)
  rat1.SetMarkerStyle(8)
  rat1.Draw()
  rat2.SetLineColor(kRed)
  rat2.SetMarkerColor(kRed)
  rat2.SetMarkerStyle(8)
  rat2.Draw("Same")
  rat4.SetLineColor(kBlue)
  rat4.SetMarkerColor(kBlue)
  rat4.SetMarkerStyle(8)
  rat4.Draw("Same")
  rat5.SetLineColor(kGreen)
  rat5.SetMarkerColor(kGreen)
  rat5.SetMarkerStyle(8)
  rat5.Draw("Same")
#  rat6.SetLineColor(kOrange)
#  rat6.SetMarkerColor(kOrange)
#  rat6.SetMarkerStyle(8)
#  rat6.Draw("Same")
  leg = TLegend(.125,.15,.325,.25)
  leg.AddEntry(rat1,"p_{T} resolution < 1","l")
  leg.AddEntry(rat2,"+ Planes > 1","l")
  leg.AddEntry(rat4,"+ #chi^{2} <2.5","l")
  leg.AddEntry(rat5,"+ Hits >12 (18 if CSC=0)","l")
  leg.SetBorderSize(0)
  leg.SetFillStyle(0)
#  leg.AddEntry(rat6,"+ |#eta| <2.4","l")
  leg.Draw("Same")
  gPad.SetTickx()
  gPad.SetTicky()
  can.Modified()
  can.Update()
  if zoom:
    rat1.SetMinimum(0.8)
  else:
    rat1.SetMinimum(0.)
  return (can,leg)
Exemple #8
0
for pt in pts_to_test:
    for variable in variables_to_test:
        for plot in plots:

            plot_name = plot['name'] + "_" + variable + "_" + pt
            canvas = TCanvas(plot_name, "", 0, 0, 700, 800)

            canvas.Divide(1, 2)

            canvas.cd(1)
            gPad.SetLogy()
            gPad.SetPad(0, 0.25, 1, 1)
            gPad.SetMargin(0.15, 0.05, 0.0, 0.07)
            gPad.SetFillStyle(0)
            gPad.SetTickx(1)
            gPad.SetTicky(1)
            gPad.Update()
            gPad.Draw()

            canvas.cd(2)
            gPad.SetPad(0, 0, 1, 0.25)
            gPad.SetMargin(0.15, 0.05, 0.4, 0.0)
            gPad.SetFillStyle(0)
            gPad.SetTickx(1)
            gPad.SetTicky(1)
            gPad.Update()
            gPad.Draw()

            canvas.cd(1)
Exemple #9
0
def compareUpperLimits(labels, masses, filelabels, **kwargs):
    print color("compareUpperLimits()", color="magenta", prepend=">>>\n>>> ")

    # SIGNAL strength & mass
    extralabel = kwargs.get('extralabel', "")
    plotlabel = kwargs.get('plotlabel', "")

    # LOOP over LABELS
    for label in labels:
        print color("plotUpperLimits - %s" % (label),
                    color="grey",
                    prepend="\n>>> ")

        ymax = -99999
        ymin = 99999
        medians = []

        for filelabel, title in filelabels:
            N = len(masses)
            median = TGraph(N)  # median line
            median.SetTitle(title)
            medians.append(median)
            for i, mass in enumerate(masses):
                filename = getOutputFilename(label, mass, extralabel=filelabel)
                limits = getLimits(filename)
                median.SetPoint(i, mass, limits[2])  # median
                if limits[2] > ymax: ymax = limits[2]
                if limits[2] < ymin: ymin = limits[2]

        median0 = medians[0]
        doLog = ymin and ymax / ymin > 6
        ymax = ymax * 1.40
        xtitle = "m_{X} [GeV]"
        ytitle = "95% upper limit on #sigma#timesBR(X #rightarrow #tau#tau) [pb]"
        if "bbA" in filelabels[0][0]:
            xtitle = "m_{A} [GeV]"
            ytitle = "95% upper limit on #sigma#timesBR(A #rightarrow #tau#tau) [pb]"

        W, H = 800, 800
        T, B = 0.10 * H, 0.16 * H
        L, R = 0.12 * W, 0.04 * W

        # MAIN plot
        canvas = TCanvas("canvas", "canvas", 100, 100, W, H)
        canvas.Divide(2)
        canvas.cd(1)
        gPad.SetPad("pad1", "pad1", 0, 0.37, 1, 1, 0, -1, 0)
        gPad.SetTopMargin(T / H)
        gPad.SetBottomMargin(0.01)
        gPad.SetLeftMargin(L / W)
        gPad.SetRightMargin(R / W)
        gPad.SetTickx(0)
        gPad.SetTicky(0)
        gPad.SetGrid()
        if doLog:
            ymin = 10**(floor(log(ymin, 10)))
            ymax = 10**(ceil(log(ymax, 10)))
            gPad.SetLogy()
        else:
            ymin *= 0 if ymin > 0 else 1.20

        width = 0.25
        height = 0.05 + len(medians) * 0.05
        #x1 = 0.16; x2 = x1 + width # Left
        x2 = 0.70
        x1 = x2 - width  # Right
        x2 = x1 + width
        y1 = 0.86
        y2 = y1 - height
        legend = TLegend(x1, y1, x2, y2)

        frame = gPad.DrawFrame(min(masses), ymin, max(masses), ymax)
        frame.GetYaxis().CenterTitle()
        frame.GetYaxis().SetTitleSize(0.055)
        frame.GetXaxis().SetTitleSize(0.058)
        frame.GetXaxis().SetLabelSize(0.050 * 0)
        frame.GetYaxis().SetLabelSize(0.053)
        frame.GetXaxis().SetLabelOffset(0.012)
        frame.GetXaxis().SetTitleOffset(1.02)
        frame.GetYaxis().SetTitleOffset(1.08)
        frame.GetXaxis().SetNdivisions(508)
        frame.GetYaxis().CenterTitle(True)
        frame.GetYaxis().SetTitle(ytitle)
        frame.GetXaxis().SetTitle(xtitle)

        option = 'L'
        for i, median in enumerate(medians):
            median.SetLineColor(colors[i % len(colors)])
            median.SetLineStyle(styles[i % len(styles)])
            median.SetLineWidth(2 if styles[i % len(styles)] != kDotted else 3)
            median.Draw('L')
            legend.AddEntry(median, median.GetTitle(), 'L')
            if i == 0: option += ' SAME'

        CMS_lumi.CMS_lumi(gPad, 13, 0)
        gPad.SetTicks(1, 1)
        gPad.Modified()
        frame.Draw('sameaxis')

        legend.SetFillStyle(0)
        legend.SetBorderSize(0)
        legend.SetTextSize(0.041)
        legend.SetTextFont(62)
        legend.SetHeader("%s" % (label_dict[label + extralabel]))
        legend.SetTextFont(42)
        legend.Draw()

        # RATIO plot
        canvas.cd(2)
        gPad.SetPad("pad2", "pad2", 0, 0, 1, 0.36, 0, -1, 0)
        gPad.SetTopMargin(0.05)
        gPad.SetBottomMargin(0.24)
        gPad.SetLeftMargin(L / W)
        gPad.SetRightMargin(R / W)

        frame_ratio = gPad.DrawFrame(min(masses), 0.36, max(masses), 1.20)
        frame_ratio.GetYaxis().CenterTitle()
        frame_ratio.GetYaxis().SetTitleSize(0.055 * 1.79)
        frame_ratio.GetXaxis().SetTitleSize(0.058 * 1.79)
        frame_ratio.GetXaxis().SetLabelSize(0.052 * 1.79)
        frame_ratio.GetYaxis().SetLabelSize(0.050 * 1.79)
        frame_ratio.GetXaxis().SetLabelOffset(0.012)
        frame_ratio.GetXaxis().SetTitleOffset(1.00)
        frame_ratio.GetYaxis().SetTitleOffset(0.63)
        frame_ratio.GetXaxis().SetNdivisions(508)
        frame_ratio.GetYaxis().CenterTitle(True)
        frame_ratio.GetYaxis().SetTitle("ratio")
        frame_ratio.GetXaxis().SetTitle(xtitle)
        frame_ratio.GetYaxis().SetNdivisions(5)

        option = 'L'
        ratios = []
        for i, median in enumerate(medians):
            ratio = makeRatioTGraphs(median, median0)
            ratio.SetLineColor(median.GetLineColor())
            ratio.SetLineStyle(median.GetLineStyle())
            ratio.SetLineWidth(median.GetLineWidth())
            ratio.Draw('L')
            ratios.append(ratio)
            if i == 1: option += ' SAME'

        gPad.SetTicks(1, 1)
        gPad.Modified()
        frame_ratio.Draw('sameaxis')

        print " "
        canvas.SaveAs("%s/upperLimit-%s%s_compare.png" %
                      (PLOTS_DIR, label, plotlabel))
        canvas.SaveAs("%s/upperLimit-%s%s_compare.pdf" %
                      (PLOTS_DIR, label, plotlabel))
        canvas.Close()
Exemple #10
0
def checkDataPoissonErrors():
    '''Check on behaviour of Poisson errors in histograms.'''

    N = 100
    hist0 = TH1D("data0", "default", N, 0, N)
    hist1 = TH1D("data1", "TH1.kPoisson", N, 0, N)
    hist2 = TH1D("data2", "#chi^{2} quantile", N, 0, N)

    for i in xrange(0, N + 2):
        y = max(0, i - 1)
        hist0.SetBinContent(i, y)
        hist1.SetBinContent(i, y)
        hist2.SetBinContent(i, y)

    # GET data Possoin errors
    graph1 = getDataPoissonErrors(hist1,
                                  drawZeroBins=True,
                                  centerBin=False,
                                  kPoisson=True)
    graph2 = getDataPoissonErrors(hist2,
                                  drawZeroBins=True,
                                  centerBin=False,
                                  kPoisson=False)

    # FILL table
    table = []
    table.append(
        "%22s  %14s  %14s  %14s" %
        (" ", "default".center(14), "kPoisson".center(14), "chi^2".center(14)))
    table.append("%4s %7s  %7s   %6s %6s   %6s %6s   %6s %6s" %
                 ("bin", "content", "sqrt(N)", "errLow", "errUp", "errLow",
                  "errUp", "errLow", "errUp"))
    for i in xrange(1, N + 1):
        y = hist0.GetBinContent(i)
        table.append(
            "%4d %5d    %7.2f   %6.2f %6.2f   %6.2f %6.2f   %6.2f %6.2f" %
            (i, y, sqrt(y), hist0.GetBinErrorLow(i), hist0.GetBinErrorUp(i),
             graph1.GetErrorYlow(i - 1), graph1.GetErrorYhigh(i - 1),
             graph2.GetErrorYlow(i - 1), graph2.GetErrorYhigh(i - 1)))

    # PRINT table
    for line in table:
        print ">>> " + line
    print ">>> "

    # GRAPHS
    function = TF1("function1", "sqrt(x)", 0, N)
    function.SetTitle("#sqrt{N}")
    graphElow1, graphEup1 = makeErrorGraph(graph1)
    graphElow2, graphEup2 = makeErrorGraph(graph2)
    graphElow1.SetTitle("TH1.kPoisson low")
    graphEup1.SetTitle("TH1.kPoisson high")
    graphElow2.SetTitle("N-F^{-1}_{#chi^{2}}(1-#alpha,2N)/2")
    graphEup2.SetTitle("F^{-1}_{#chi^{2}}(#alpha,2(N-1))/2-N")
    graphs = [function, graphElow1, graphEup1, graphElow2, graphEup2]

    # DRAW settings
    W, H = 800, 800
    T, B = 0.04 * H, 0.14 * H
    L, R = 0.12 * W, 0.04 * W
    xmin, xmax = -N * 0.01, N * 1.01
    ymax = function.GetMaximum() * 1.16
    width = 0.25
    legendTextSize = 0.045
    height = 0.062 * (1 + len(graphs))
    x2 = 0.86
    x1 = x2 - width
    y1 = 0.20
    y2 = y1 + height

    # CANVAS
    canvas = TCanvas("canvas", "canvas", 100, 100, W, H)
    canvas.Divide(2)
    canvas.cd(1)
    gPad.SetPad("pad1", "pad1", 0, 0.37, 1, 1, 0, -1, 0)
    gPad.SetTopMargin(T / H)
    gPad.SetBottomMargin(0.01)
    gPad.SetLeftMargin(L / W)
    gPad.SetRightMargin(R / W)
    gPad.SetTickx(0)
    gPad.SetTicky(0)
    gPad.SetGrid()

    # FRAME
    frame = gPad.DrawFrame(xmin, 0, xmax, ymax)
    frame.GetYaxis().SetTitleSize(0.055)
    frame.GetXaxis().SetTitleSize(0.058)
    frame.GetXaxis().SetLabelSize(0.050 * 0)
    frame.GetYaxis().SetLabelSize(0.053)
    frame.GetXaxis().SetLabelOffset(0.012)
    frame.GetXaxis().SetTitleOffset(1.02)
    frame.GetYaxis().SetTitleOffset(1.08)
    frame.GetXaxis().SetNdivisions(505)
    frame.GetXaxis().SetTitle("number of events")
    frame.GetYaxis().SetTitle("error on number of events")
    legend = TLegend(x1, y1, x2, y2)

    # DRAW
    colors = [kRed, kBlue, kViolet, kYellow, kGreen]
    for i, graph in enumerate(graphs):
        style = kSolid
        width = 2
        if i < 3: width = 3
        if i > 2: style = kDashed
        graph.SetLineColor(colors[i % len(colors)])
        graph.SetLineStyle(style)
        graph.SetLineWidth(width)
        graph.Draw('L SAME')
        legend.AddEntry(graph, graph.GetTitle(), 'L')
    #CMS_lumi.CMS_lumi(gPad,13,0)
    gPad.SetTicks(1, 1)
    gPad.Modified()
    frame.Draw('SAME AXIS')

    # LEGEND
    legend.SetFillStyle(0)
    legend.SetBorderSize(0)
    legend.SetTextSize(legendTextSize)
    legend.SetTextFont(62)
    legend.SetHeader("method")
    legend.SetTextFont(42)
    legend.Draw()

    # CHI2 TEXT
    text1 = "#splitline{#alpha = (1-0.6827)/2}{upper #chi^{2} CDF F_{#chi^{2}}}"
    text = TLatex()
    text.SetNDC()
    text.SetTextFont(42)
    text.SetTextSize(legendTextSize)
    text.SetTextAlign(13)  # centered: 22
    xoffset = (legend.GetX2() - legend.GetX1()) * legend.GetMargin() * 1.04
    text.DrawLatexNDC(legend.GetX1() + xoffset, legend.GetY1() - 0.012, text1)

    # RATIO plot
    canvas.cd(2)
    gPad.SetPad("pad2", "pad2", 0, 0, 1, 0.36, 0, -1, 0)
    gPad.SetTopMargin(0.05)
    gPad.SetBottomMargin(0.24)
    gPad.SetLeftMargin(L / W)
    gPad.SetRightMargin(R / W)

    # FRAME ratio
    frame_ratio = gPad.DrawFrame(xmin, 0.50, xmax, 1.50)
    frame_ratio.GetYaxis().CenterTitle()
    frame_ratio.GetYaxis().SetTitleSize(0.055 * 1.79)
    frame_ratio.GetXaxis().SetTitleSize(0.058 * 1.79)
    frame_ratio.GetXaxis().SetLabelSize(0.052 * 1.79)
    frame_ratio.GetYaxis().SetLabelSize(0.050 * 1.79)
    frame_ratio.GetXaxis().SetLabelOffset(0.012)
    frame_ratio.GetXaxis().SetTitleOffset(1.00)
    frame_ratio.GetYaxis().SetTitleOffset(0.63)
    frame_ratio.GetXaxis().SetNdivisions(508)
    frame_ratio.GetYaxis().CenterTitle(True)
    frame_ratio.GetYaxis().SetTitle("ratio")
    frame_ratio.GetXaxis().SetTitle("number of events N")
    frame_ratio.GetYaxis().SetNdivisions(5)

    # DRAW ratio
    ratios = []
    graphf = makeGraphFromTF1(function, N)
    for i, graph in enumerate(graphs):
        if isinstance(graph, TF1): graph = makeGraphFromTF1(graph, N)
        ratio = makeRatioTGraphs(graph, graphf)
        ratio.SetLineColor(graph.GetLineColor())
        ratio.SetLineStyle(graph.GetLineStyle())
        ratio.SetLineWidth(graph.GetLineWidth())
        ratio.Draw('L SAME')
        ratios.append(ratio)
    gPad.SetTicks(1, 1)
    gPad.Modified()
    frame_ratio.Draw('sameaxis')

    # SAVE
    canvas.SaveAs("PoissonError.png")
    canvas.Close()
Exemple #11
0
def main():
    gStyle.SetOptStat(0)
    zplist = [600,600,1200,1200,2000,2000]
    a0list = [300,400,300,500,300,600]
    c1 = TCanvas('c1','c1',3)
    gPad.SetTickx()
    gPad.SetTicky()
    c1.SetLeftMargin(0.12)
    h_frame = TH1F('frame','',60,0,1200)
    h_frame.SetXTitle('P^{miss}_{T} (GeV)')
    h_frame.SetYTitle('Arbitrary units')
    h_frame.SetMaximum(0.3)

    h_higgsPt = TH1F('h_higgsPt','h_higgsPt',60,0,1200)
    h_higgsPtList = []
    rootfilelist = []
    for i in range(6):
        fName = 'higgsPt_MZp'+str(zplist[i])+'_MA0'+str(a0list[i])+'.root'
        rootfile = TFile(fName)
        rootfilelist.append(rootfile)
    
    colorList = [61,95,65,91,69,87] 
    for i in range(6):
        hist = rootfilelist[i].Get('h_higgsPt')
        hist.SetName('h_higgsPt_MZp'+str(zplist[i])+'_MA0'+str(a0list[i]))
        h_higgsPtList.append(hist)
        h_higgsPtList[i].SetLineWidth(2)
        h_higgsPtList[i].SetLineColor(colorList[i])
    
    info_bar = TLatex(0,0.305,'CMS')
    info_bar_3 = TLatex(700,0.15,'#font[42]{tan#beta=1.0}')
    info_bar_2 = TLatex(1200,0.305,'35.9 fb^{-1} (13 TeV)')
    info_bar.SetTextSize(0.03)
    info_bar_2.SetTextSize(0.03)
    info_bar_3.SetTextSize(0.04)
    info_bar_2.SetTextAlign(31)
    leg = TLegend(0.32,0.57,0.87,0.87)
    leg.SetBorderSize(0)
    for j in range(3):
        i = 2*j
        text = 'M_{Z\'} = '+str(zplist[i])+' GeV, M_{A} = '+str(a0list[i])+' GeV'
        leg.AddEntry(h_higgsPtList[i],text)
    
    for j in range(3):
        i = 2*j+1
        text = 'M_{Z\'} = '+str(zplist[i])+' GeV, M_{A} = '+str(a0list[i])+' GeV'
        leg.AddEntry(h_higgsPtList[i],text)
    
    h_frame.Draw('hist')
    for i in range(6): h_higgsPtList[i].DrawNormalized('histsame')
    leg.Draw()
    info_bar.Draw()
    info_bar_2.Draw()
    info_bar_3.Draw()
    c1.Print('Zp2HDM_higgsPt.pdf')
    
    ## Baryonic
    histName_bar = ['missPt_MZp1000_MDM500','missPt_MZp1000_MDM100','missPt_MZp1000_MDM1','missPt_MZp500_MDM1','missPt_MZp100_MDM1','missPt_MZp10_MDM1']
    legtext_bar = ["M_{Z'}=1000 GeV,M_{#chi}=500 GeV","M_{Z'}=1000 GeV,M_{#chi}=100 GeV","M_{Z'}=1000 GeV,M_{#chi}=1 GeV","M_{Z'}=500 GeV,M_{#chi}=1 GeV",\
        "M_{Z'}=100 GeV,M_{#chi}=1 GeV","M_{Z'}=10 GeV,M_{#chi}=1 GeV"]
    h_frame.SetMaximum(0.25)
    h_frame.SetAxisRange(0., 750.,"X")
    leg.Clear() 
    info_bar = TLatex(0,0.255,'CMS')
    info_bar_2 = TLatex(750,0.255,'35.9 fb^{-1} (13 TeV)')
    info_bar.SetTextSize(0.03)
    info_bar_2.SetTextSize(0.03)
    info_bar_2.SetTextAlign(31)

    kOrange = 800
    colorList = [kOrange-4,kOrange-1,kOrange+3,70,65,55]
    h_higgsPt_BarList = []
    f = TFile('BaryonicZp_missPt.root')
    for i in range(6): 
        hist = TH1F()
        hist = f.Get(histName_bar[i])
        h_higgsPt_BarList.append(hist)
    
    for i in range(6):
        #h_higgsPt_BarList[i].SetLineColor(93-6*i)
        h_higgsPt_BarList[i].SetLineColor(colorList[i])
        leg.AddEntry(h_higgsPt_BarList[i],legtext_bar[i])

    h_frame.Draw('hist')
    for i in range(5,-1,-1):h_higgsPt_BarList[i].DrawNormalized('histsame')
    leg.Draw()
    info_bar.Draw()
    info_bar_2.Draw()
    c1.Print('Baryonic_higgsPt.pdf')
    f.Close()
    
    '''
def define_weights(filepythia, its):
    ftamu = TFile("theory/input_RAA_TAMU_Bs_B.root")
    grTAMURAABs = ftamu.Get("RAA_TAMU_Bs")

    ffonllcent = TFile(
        "fonll/DfromB_FONLLcentPythia8_FFee_yDcut_sqrts5500.root")
    hfonllB = ffonllcent.Get("hfonllB")
    hfonllB.SetLineColor(kBlue)
    hfonllB.SetLineWidth(2)
    hfonllB.Scale(1. / hfonllB.Integral())

    hfonllBTAMU = hfonllB.Clone("hfonllBTAMU")
    for i in range(hfonllB.GetNbinsX()):
        hfonllBTAMU.SetBinContent(
            i,
            hfonllB.GetBinContent(i) *
            grTAMURAABs.Eval(hfonllB.GetBinCenter(i)))
    hfonllBTAMU.SetLineColor(kRed + 1)
    hfonllBTAMU.SetLineWidth(2)

    hflat = hfonllB.Clone("flat")
    for i in range(hflat.GetNbinsX()):
        hflat.SetBinContent(i, 0.001)
    hflat.SetLineColor(kRed + 1)
    hflat.SetLineWidth(2)
    hflat.SetLineStyle(2)

    fpythia = TFile(filepythia)
    hgen = fpythia.Get("h_gen_pr")
    hpythia = hgen.Clone("hpythia")
    hpythia.SetLineColor(kBlack)
    hpythia.Scale(1. / hpythia.Integral())
    hpythia.SetLineWidth(2)
    hpythia.SetTitle(";#it{p}_{T} (GeV/#it{c});d#it{N}/d#it{p}_{T} (a.u.)")

    c = TCanvas("c", "c", 450, 400)
    c.cd()
    hpythia.Draw("hist")
    gStyle.SetOptStat(0)
    hpythia.GetXaxis().SetRangeUser(0, 24)
    hpythia.GetYaxis().SetRangeUser(0.00001, 0.1)
    gPad.SetLogy()
    gPad.SetTickx()
    gPad.SetTicky()
    hfonllB.Draw("same hist")
    hfonllBTAMU.Draw("same hist")
    #hflat.Draw("same hist")

    leg = TLegend(.6, .69, .75, .85)
    leg.SetBorderSize(0)
    leg.SetFillColor(0)
    leg.SetFillStyle(0)
    leg.SetTextFont(42)
    leg.SetTextSize(0.034)
    leg.AddEntry(hpythia, "Pythia", "l")
    leg.AddEntry(hfonllB, "FONLL", "l")
    leg.AddEntry(hfonllBTAMU, "FONLL x TAMU", "l")
    #leg.AddEntry(hflat, "Flat", "l")
    leg.Draw()

    c.SaveAs("tempfig_" + its + "/MCpTshape_dNdpT_" + its + ".eps")

    hpythia_weight = hpythia.Clone("hpythia_weight")
    hfonllB_weight = hfonllB.Clone("hfonllB_weight")
    hfonllBTAMU_weight = hfonllBTAMU.Clone("hfonllBTAMU_weight")
    hflat_weight = hflat.Clone("hflat_weight")

    hpythia_weight.SetTitle(";#it{p}_{T} (GeV/#it{c});#it{p}_{T} weights")
    hpythia_weight.SetLineStyle(9)
    hflat_weight.SetLineStyle(2)

    hpythia_weight.Divide(hpythia_weight, hpythia, 1, 1, "B")
    hfonllB_weight.Divide(hfonllB_weight, hpythia, 1, 1, "B")
    hfonllBTAMU_weight.Divide(hfonllBTAMU_weight, hpythia, 1, 1, "B")
    hflat_weight.Divide(hflat_weight, hpythia, 1, 1, "B")

    cw = TCanvas("cw", "cw", 450, 400)
    cw.cd()
    hpythia_weight.Draw("hist")
    gStyle.SetOptStat(0)
    hpythia_weight.GetXaxis().SetRangeUser(0, 23.95)
    hpythia_weight.GetYaxis().SetRangeUser(0.1, 10)
    gPad.SetLogy()
    gPad.SetTickx()
    gPad.SetTicky()
    hfonllB_weight.Draw("same hist")
    hfonllBTAMU_weight.Draw("same hist")
    #hflat_weight.Draw("same hist")
    leg.Draw()

    cw.SaveAs("tempfig_" + its + "/MCpTshape_weights_" + its + ".eps")

    hreco = fpythia.Get("h_sel_pr")
    hgen = fpythia.Get("h_gen_pr")
    hreco.SetLineWidth(2)
    hgen.SetLineWidth(2)

    hgenpythia = hgen.Clone("hgenpythia")
    hgenfonll = hgen.Clone("hgenfonll")
    hgenfonlltamu = hgen.Clone("hgenfonlltamu")
    hgenflat = hgen.Clone("hgenflat")

    hrecopythia = hreco.Clone("hrecopythia")
    hrecofonll = hreco.Clone("hrecofonll")
    hrecofonlltamu = hreco.Clone("hrecofonlltamu")
    hrecoflat = hreco.Clone("hrecoflat")

    hgenpythia.SetLineColor(kBlack)
    hgenfonll.SetLineColor(kBlue)
    hgenfonlltamu.SetLineColor(kRed + 1)
    hgenflat.SetLineColor(kOrange + 1)
    hrecopythia.SetLineColor(kBlack)
    hrecofonll.SetLineColor(kBlue)
    hrecofonlltamu.SetLineColor(kRed + 1)
    hrecoflat.SetLineColor(kOrange + 1)

    hgenpythia.Multiply(hgenpythia, hpythia_weight, 1, 1, "B")
    hgenfonll.Multiply(hgenfonll, hfonllB_weight, 1, 1, "B")
    hgenfonlltamu.Multiply(hgenfonlltamu, hfonllBTAMU_weight, 1, 1, "B")
    hgenflat.Multiply(hgenflat, hflat_weight, 1, 1, "B")

    hrecopythia.Multiply(hrecopythia, hpythia_weight, 1, 1, "B")
    hrecofonll.Multiply(hrecofonll, hfonllB_weight, 1, 1, "B")
    hrecofonlltamu.Multiply(hrecofonlltamu, hfonllBTAMU_weight, 1, 1, "B")
    hrecoflat.Multiply(hrecoflat, hflat_weight, 1, 1, "B")

    arr_ptbins = [2, 4, 8, 12, 16, 24]  #[0.5 + i*0.25 for i in range(20)]
    heff_cent = TH1F("heff_cent", ";#it{p}_{T} (GeV/#it{c});efficiency ratio",
                     len(arr_ptbins) - 1, array("d", arr_ptbins))
    heff_pythia = TH1F("heff_pythia",
                       ";#it{p}_{T} (GeV/#it{c});efficiency ratio",
                       len(arr_ptbins) - 1, array("d", arr_ptbins))
    heff_fonll = TH1F("heff_fonll",
                      ";#it{p}_{T} (GeV/#it{c});efficiency ratio",
                      len(arr_ptbins) - 1, array("d", arr_ptbins))
    heff_fonlltamu = TH1F("heff_fonlltamu",
                          ";#it{p}_{T} (GeV/#it{c});efficiency ratio",
                          len(arr_ptbins) - 1, array("d", arr_ptbins))
    heff_flat = TH1F("heff_flat", ";#it{p}_{T} (GeV/#it{c});efficiency ratio",
                     len(arr_ptbins) - 1, array("d", arr_ptbins))
    arr_ptbins2 = [0, 2, 4, 8, 12, 16, 24]
    href = TH1F("href", ";#it{p}_{T} (GeV/#it{c});efficiency ratio",
                len(arr_ptbins2) - 1, array("d", arr_ptbins2))

    for i in range(len(arr_ptbins) - 1):
        binmin = arr_ptbins[i]
        binmax = arr_ptbins[i + 1]
        eff_cent = hrecopythia.Integral(hrecopythia.FindBin(binmin), hrecopythia.FindBin(binmax-0.001)) / \
                   hgenpythia.Integral(hgenpythia.FindBin(binmin), hgenpythia.FindBin(binmax-0.001))
        eff_pythia = hrecopythia.Integral(hrecopythia.FindBin(binmin), hrecopythia.FindBin(binmax-0.001)) / \
                    hgenpythia.Integral(hgenpythia.FindBin(binmin), hgenpythia.FindBin(binmax-0.001))
        eff_fonll = hrecofonll.Integral(hrecofonll.FindBin(binmin), hrecofonll.FindBin(binmax-0.001)) / \
                    hgenfonll.Integral(hgenfonll.FindBin(binmin), hgenfonll.FindBin(binmax-0.001))
        eff_fonlltamu = hrecofonlltamu.Integral(hrecofonlltamu.FindBin(binmin), hrecofonlltamu.FindBin(binmax-0.001)) / \
                        hgenfonlltamu.Integral(hgenfonlltamu.FindBin(binmin), hgenfonlltamu.FindBin(binmax-0.001))
        eff_flat = hrecoflat.Integral(hrecoflat.FindBin(binmin), hrecoflat.FindBin(binmax-0.001)) / \
                   hgenflat.Integral(hgenflat.FindBin(binmin), hgenflat.FindBin(binmax-0.001))
        heff_cent.SetBinContent(i + 1, eff_cent)
        heff_pythia.SetBinContent(i + 1, eff_pythia)
        heff_fonll.SetBinContent(i + 1, eff_fonll)
        heff_fonlltamu.SetBinContent(i + 1, eff_fonlltamu)
        heff_flat.SetBinContent(i + 1, eff_flat)
        heff_cent.SetBinError(i + 1, 0.0001)
        heff_pythia.SetBinError(i + 1, 0.0001)
        heff_fonll.SetBinError(i + 1, 0.0001)
        heff_fonlltamu.SetBinError(i + 1, 0.0001)
        heff_flat.SetBinError(i + 1, 0.0001)

    heff_pythia.Divide(heff_pythia, heff_cent, 1, 1, "B")
    heff_fonll.Divide(heff_fonll, heff_cent, 1, 1, "B")
    heff_fonlltamu.Divide(heff_fonlltamu, heff_cent, 1, 1, "B")
    heff_flat.Divide(heff_flat, heff_cent, 1, 1, "B")

    for i in range(len(arr_ptbins) - 1):
        heff_pythia.SetBinError(i, 0.0001)

    heff_pythia.SetLineColor(kBlack)
    heff_fonll.SetLineColor(kBlue)
    heff_fonlltamu.SetLineColor(kRed + 1)
    heff_flat.SetLineColor(kOrange + 1)
    heff_pythia.SetMarkerColor(kBlack)
    heff_fonll.SetMarkerColor(kBlue)
    heff_fonlltamu.SetMarkerColor(kRed + 1)
    heff_flat.SetMarkerColor(kOrange + 1)
    heff_pythia.SetLineWidth(2)
    heff_fonll.SetLineWidth(2)
    heff_fonlltamu.SetLineWidth(2)
    heff_flat.SetLineWidth(2)
    heff_flat.SetLineStyle(2)
    heff_pythia.SetMarkerStyle(20)
    heff_fonll.SetMarkerStyle(20)
    heff_fonlltamu.SetMarkerStyle(20)
    heff_flat.SetMarkerStyle(20)

    ce = TCanvas("ce", "ce", 450, 400)
    ce.cd()
    href.Draw()
    gStyle.SetOptStat(0)
    href.GetXaxis().SetRangeUser(0, 23.95)
    href.GetYaxis().SetRangeUser(0.8, 1.2)
    gPad.SetTickx()
    gPad.SetTicky()
    heff_pythia.Draw("same ep")
    heff_fonll.Draw("same ep")
    heff_fonlltamu.Draw("same ep")
    #heff_flat.Draw("same ep")
    leg.Draw()

    ce.SaveAs("tempfig_" + its + "/MCpTshape_efficiency_ratio_" + its + ".eps")
Exemple #13
0
def main():
    gStyle.SetOptStat(0)
    c1 = TCanvas('c1', 'c1', 3)
    gPad.SetTickx()
    gPad.SetTicky()
    c1.SetLeftMargin(0.12)
    h_frame = TH1F('frame', '', 50, 0, 1000)
    h_frame.SetXTitle('P^{miss}_{T} (GeV)')
    h_frame.SetYTitle('Arbitrary units')
    h_frame.SetMaximum(0.4)

    h_higgsPt = TH1F('h_higgsPt', 'h_higgsPt', 50, 0, 1000)
    h_higgsPtList = []
    for i in range(6):
        h_higgsPtList.append(TH1F(histName_zp2HDM[i], '', 50, 0, 1000))
        h_higgsPtList[i].SetLineWidth(2)
    h_higgsPt_BarList = []
    for i in range(6):
        h_higgsPt_BarList.append(TH1F(histName_bar[i], '', 40, 0, 800))
        h_higgsPt_BarList[i].SetLineWidth(2)
    ## test code
    '''
    ivVectList = getPtList(hApath)
    for fourV in ivVectList:
        h_higgsPt.Fill(fourV.pt)
    '''

    ## loop all combination
    leg = TLegend(0.32, 0.57, 0.87, 0.87)
    leg.SetBorderSize(0)
    for i in range(3):
        ivVectList = getPtList(hApathList[i])
        h_higgsPtList[i].SetLineColor(87 + 4 * i)
        leg.AddEntry(h_higgsPtList[i], legtext[i])
        for fourV in ivVectList:
            h_higgsPtList[i].Fill(fourV.pt)

    for i in range(3):
        ivVectList = getPtList(hApathList_5[i])
        h_higgsPtList[i + 3].SetLineColor(61 + 4 * i)
        leg.AddEntry(h_higgsPtList[i + 3], legtext_5[i])
        for fourV in ivVectList:
            h_higgsPtList[i + 3].Fill(fourV.pt)

    h_frame.Draw('hist')
    #h_higgsPt.Draw('histsame')
    for i in range(6):
        h_higgsPtList[i].DrawNormalized('histsame')
    leg.Draw()
    c1.Print('Zp2HDM_higgsPt.pdf')

    colorList = [95, 91, 87, 61, 65, 69]
    #colorList = [61,95,65,91,69,87]
    ## Baryonic
    info_bar = TLatex(0, 0.255, 'CMS')
    info_bar_2 = TLatex(750, 0.255, '35.9 fb^{-1} (13 TeV)')
    info_bar.SetTextSize(0.03)
    info_bar_2.SetTextSize(0.03)
    info_bar_2.SetTextAlign(31)
    h_frame.SetMaximum(0.25)
    h_frame.SetAxisRange(0., 750., "X")
    leg.Clear()
    for i in range(6):
        ivVectList = getPtList('BaryonicFile/' + hApath_barList[i])
        h_higgsPt_BarList[i].SetLineColor(colorList[i])
        #h_higgsPt_BarList[i].SetLineColor(90-6*i)
        leg.AddEntry(h_higgsPt_BarList[i], legtext_bar[i])
        for fourV in ivVectList:
            h_higgsPt_BarList[i].Fill(fourV.pt)

    h_frame.Draw('hist')
    for i in range(5, -1, -1):
        h_higgsPt_BarList[i].DrawNormalized('histsame')
    leg.Draw()
    info_bar.Draw()
    info_bar_2.Draw()
    c1.Print('Baryonic_higgsPt.pdf')
    f = TFile('rootFile/Zp2HDM_missPt.root', 'recreate')
    for i in range(6):
        h_higgsPtList[i].SetLineColor(1)
        h_higgsPtList[i].Write()

    f.Close()

    f = TFile('rootFile/BaryonicZp_missPt.root', 'recreate')
    for i in range(6):
        h_higgsPt_BarList[i].SetLineColor(1)
        h_higgsPt_BarList[i].Write()

    f.Close()
Exemple #14
0
    def DrawStack(self, xtit='', ytit=''):
        ''' Draws a stack plot '''
        # Set the canvas and pads
        if xtit != '': self.axisXtit = xtit
        if ytit != '': self.axisYtit = ytit
        self.SetCanvas()

        # Stack processes and draw stack and data
        self.plot.cd()
        gPad.SetTickx()
        gPad.SetTicky()
        if not os.path.isdir(self.GetOutPath()): os.makedirs(self.GetOutPath())
        self.hStack.Draw('hist')
        x0, x1 = self.rangeX
        if x0 < x1: self.hStack.GetXaxis().SetRangeUser(x0, x1)
        if hasattr(self, 'MCstatUnc') and self.MCstatUnc != None:
            self.MCstatUnc.Draw("e2,same")
        if hasattr(self, 'MCnormUnc') and self.MCnormUnc != None:
            self.MCnormUnc.Draw("e2,same")
        if hasattr(self, 'MCunc') and self.MCunc != None:
            self.MCunc.Draw("e2,same")

        # Extra histograms
        for h in self.overlapHistos:
            h.Draw("hist,same")

        # Errors in data
        if hasattr(self, 'hData'):
            if not isinstance(self.hData, TGraphAsymmErrors):
                self.hData.SetBinErrorOption(TH1.kPoisson)
                self.hData.Sumw2(False)
            self.hData.Draw('psameE0X0')  #self.data.GetDrawStyle())

        # Set Maximum
        datamax = self.hData.GetMaximum() if hasattr(self, 'hData') else -999
        bkgmax = self.TotMC.GetMaximum() if hasattr(
            self, 'TotMC') else self.hStack.GetStack().Last().GetMaximum()
        dmax = max(datamax, bkgmax)

        if isinstance(self.PlotMaximum, float):
            self.hStack.SetMaximum(self.PlotMaximum)
        else:
            self.hStack.SetMaximum(dmax * self.PlotMaxScale)
        if isinstance(self.PlotMinimum, float):
            self.hStack.SetMinimum(self.PlotMinimum)

        # Set titles...
        TGaxis.SetMaxDigits(3)
        self.SetAxisPlot(self.hStack)
        if self.doRatio:
            self.SetAxisRatio(self.hRatio)
            self.SetAxisRatio(self.hRatioUnc)
            if hasattr(self, 'hRatioStatUnc') and self.hRatioStatUnc != None:
                self.SetAxisRatio(self.hRatioStatUnc)
            if hasattr(self, 'hRatioNormUnc') and self.hRatioNormUnc != None:
                self.SetAxisRatio(self.hRatioNormUnc)

        # Legend
        if hasattr(self, 'processes'):
            self.hleg = []
            leg = self.SetLegend()
            for pr in self.processes:
                htot = self.TotMC if hasattr(
                    self, 'TotMC') else self.hStack.GetStack().Last()
                h = htot.Clone('leg%s' % pr)
                h.SetFillStyle(1000)
                h.SetLineColor(0)
                h.SetLineWidth(0)
                h.SetFillColor(self.colors[pr])
                self.hleg.append(h)
                leg.AddEntry(
                    self.hleg[-1], pr if not pr in self.legnames.keys() else
                    self.legnames[pr], 'f')
            for h in self.overlapHistos:
                leg.AddEntry(h, h.GetName(), 'l')
            if hasattr(self, 'hData'): leg.AddEntry(self.hData, 'data', 'pe')
            leg.Draw()

        if self.doZoom:
            self.mini.cd()
            gPad.SetTickx()
            gPad.SetTicky()
            #if not os.path.isdir(self.GetOutPath()): os.makedirs(self.GetOutPath())
            self.hStack2 = self.hStack.Clone("hStack2")
            self.hStack2.Draw('hist')
            if hasattr(self, 'MCstatUnc') and self.MCstatUnc != None:
                self.MCstatUnc.Draw("e2,same")
            if hasattr(self, 'MCnormUnc') and self.MCnormUnc != None:
                self.MCnormUnc.Draw("e2,same")
            if hasattr(self, 'MCunc') and self.MCunc != None:
                self.MCunc.Draw("e2,same")

            self.hStack2.GetYaxis().SetTitle("")
            # Extra histograms
            for h in self.overlapHistos:
                h.Draw("hist,same")

        # Errors in data
            if hasattr(self, 'hData'):
                self.hData.SetBinErrorOption(TH1.kPoisson)
                self.hData.Sumw2(False)
                self.hData.Draw('psameE0X0')  #self.data.GetDrawStyle())
            self.hStack2.GetXaxis().SetRangeUser(16, 20)  #XLIMITS
            self.hStack2.GetYaxis().SetLabelSize(0.075)
            self.hStack2.GetXaxis().SetLabelSize(0.075)
            self.hStack2.GetXaxis().SetNdivisions(4)
            # Set Maximum
            datamax = self.hData.GetMaximum() if hasattr(self,
                                                         'hData') else -999
            bkgmax = self.TotMC.GetMaximum() if hasattr(
                self,
                'TotMC') else self.hStack2.GetStack().Last().GetMaximum()
            dmax = max(datamax, bkgmax)

            #if isinstance(self.PlotMaximum, float): self.hStack2.SetMaximum(self.PlotMaximum)
            self.hStack2.SetMaximum(dmax - dmax * 0.9)
            self.hStack2.SetMinimum(10)
            # Set titles...
            #TGaxis.SetMaxDigits(2)
            #self.SetAxisPlot(self.hStack)
            #self.mini.Draw()

        # Ratio
        if self.doRatio:
            self.ratio.cd()
            legr = self.SetLegendRatio()
            x0, x1 = self.rangeX
            if hasattr(self, 'hRatioStatUnc') and self.hRatioStatUnc != None:
                if x0 < x1: self.hRatioStatUnc.GetXaxis().SetRangeUser(x0, x1)
                self.hRatioStatUnc.Draw('e2same')
                self.hRatioStatUnc.SetLineWidth(0)
                self.hRatioStatUnc.SetMaximum(self.PlotRatioMax)
                self.hRatioStatUnc.SetMinimum(self.PlotRatioMin)
                legr.AddEntry(self.hRatioStatUnc, 'Stat', 'f')
            if hasattr(self, 'hRatioNormUnc') and self.hRatioNormUnc != None:
                if x0 < x1: self.hRatioNormUnc.GetXaxis().SetRangeUser(x0, x1)
                self.hRatioNormUnc.Draw('e2same')
                self.hRatioNormUnc.SetLineWidth(0)
                self.hRatioNormUnc.SetMaximum(self.PlotRatioMax)
                self.hRatioNormUnc.SetMinimum(self.PlotRatioMin)
                legr.AddEntry(self.hRatioNormUnc, 'Bkg norm', 'f')
            if hasattr(self, 'hRatioUnc') and self.hRatioUnc != None:
                if x0 < x1: self.hRatioUnc.GetXaxis().SetRangeUser(x0, x1)
                self.hRatioUnc.Draw('e2same')
                self.hRatioUnc.SetLineWidth(0)
                self.hRatioUnc.SetMinimum(self.PlotRatioMin)
                self.hRatioUnc.SetMaximum(self.PlotRatioMax)
                legr.AddEntry(self.hRatioUnc, 'Tot unc',
                              'f')  #'Stat #oplus Syst', 'f')
            if hasattr(self, 'hRatio'):
                if x0 < x1: self.hRatio.GetXaxis().SetRangeUser(x0, x1)
                self.hRatio.Draw('pE0X0,same')
                self.hRatio.SetMaximum(self.PlotRatioMax)
                self.hRatio.SetMinimum(self.PlotRatioMin)
            for h in self.extraRatio:
                h.Draw("hist, same")
            legr.Draw()
        else:
            for r in self.Tex:
                r.Draw()
            for l in self.Line:
                l.Draw()

        if len(self.binLabels) > 0:
            for i in range(len(self.binLabels)):
                if self.doRatio:
                    if hasattr(self, 'hRatio'):
                        self.hRatio.GetXaxis().SetBinLabel(
                            i + 1, self.binLabels[i])
                    if hasattr(self, 'hRatioUnc'):
                        self.hRatioUnc.GetXaxis().SetBinLabel(
                            i + 1, self.binLabels[i])
                    if hasattr(self, 'hRatioStatUnc'):
                        self.hRatioStatUnc.GetXaxis().SetBinLabel(
                            i + 1, self.binLabels[i])
                    if hasattr(self, 'hRatioNormUnc'):
                        self.hRatioNormUnc.GetXaxis().SetBinLabel(
                            i + 1, self.binLabels[i])
                else:
                    self.hStack.GetXaxis().SetBinLabel(i + 1,
                                                       self.binLabels[i])

        self.Save()