Exemple #1
0
    def _drawHists(self, h1, h2, h1name):
        '''Compare 2 histograms'''

        h1.SetMarkerColor(1)
        h1.SetMarkerStyle(21)
        h1.SetLineColor(1)
        h1.SetMarkerSize(0.8)

        h2.SetFillColor(16)
        h2.SetFillStyle(1001)
        h2.SetMarkerColor(1)
        h2.SetMarkerStyle(4)
        h2.SetLineColor(1)
        h2.SetMarkerSize(0.8)

        title1 = self.title1
        title2 = self.title2
        if title1 is None:
            title1 = self.info1.name
        if title2 is None:
            title2 = self.info2.name
        # import pdb; pdb.set_trace()
        if not self.hcomp:
            self.hcomp = HistComparator(h1name, h1, h2, title1, title2)
        else:
            self.hcomp.set(h1name, h1, h2, title1, title2)
        self.hcomp.draw()
        print 'Draw', h1name, 'done'
        pngname = '/'.join([self.outdir, h1name + '.png'])
        print pngname
        self.hcomp.can.SaveAs(pngname)
        return True
Exemple #2
0
def draw(var1,
         cut,
         t1,
         t2,
         w1='1',
         w2='1',
         name1=None,
         name2=None,
         normalize=False,
         nbins=20,
         xmin=0,
         xmax=200,
         var2=None):
    if var2 is None:
        var2 = var1
    print 'tree1',
    print '\t var   : ', var1
    print '\t weight:', w1
    print 'tree2',
    print '\t var   : ', var2
    print '\t weight:', w2
    print 'cut', cut
    global legend
    h1 = TH1F(hname(), '', nbins, xmin, xmax)
    h1.Sumw2()
    t1.Project(h1.GetName(), var1, '({cut})*({w1})'.format(cut=cut, w1=w1), '')
    h2 = h1.Clone(hname())
    h2.Sumw2()
    t2.Project(h2.GetName(), var2, '({cut})*({w2})'.format(cut=cut, w2=w2), '')
    if normalize:
        h1.Scale(1. / h1.Integral())
        h2.Scale(1. / h2.Integral())
    else:
        pass
        # h2.Scale(h1.Integral()/h2.Integral())
    sBlue.markerStyle = 25
    sBlue.formatHisto(h2)
    sBlack.formatHisto(h1)
    h2.SetFillStyle(1001)
    h2.SetFillColor(5)
    h1.SetMarkerSize(0.8)
    h2.SetMarkerSize(0.8)
    h1.SetStats(0)
    h2.SetStats(0)
    if name1 is None: name1 = t1.GetTitle()
    if name2 is None: name2 = t2.GetTitle()
    h1.SetTitle(name1)
    h2.SetTitle(name2)
    legend = TLegend(0.55, 0.7, 0.88, 0.88)
    legend.SetFillColor(0)
    legend.AddEntry(h1, name1, 'lp')
    legend.AddEntry(h2, name2, 'lpf')

    print 'number of selected rows:', t1.GetSelectedRows(), t2.GetSelectedRows(
    )

    comparator = HistComparator(var1, h1, h2)
    return comparator