Esempio n. 1
0
    def Get(self, path):
        fakes = self.fakes.Get(path)
        wz = self.wz.Get(path)
        zz = self.zz.Get(path)

        bkg_error = wz.Clone()
        bkg_error.SetTitle("Bkg. Unc.")
        bkg_error.Reset()
        for bin_err, bin_wz, bin_zz, bin_fake in zipBins(bkg_error, wz, zz, fakes): #range(1, bkg_error.GetNbinsX() + 1):
            bin_err.error = quad(
                bin_fake.error,
                bin_fake.content*self.fake_error,
                bin_wz.content*self.wz_error,
                bin_zz.content*self.zz_error
            )
            bin_err.content = (
                bin_fake.content(bin) +
                bin_wz.content(bin) +
                bin_zz.content(bin)
            )
        bkg_error.SetMarkerSize(0)
        bkg_error.SetFillColor(1)
        bkg_error.SetFillStyle(3013)
        bkg_error.legendstyle = 'f'
        return bkg_error
 def add_error(histo, sys_error):
     clone = histo.Clone()
     for hbin in zipBins(clone):
         hbin.error = quad(
             hbin.error, 
             hbin.content * sys_error
         ) 
     return clone
def HistToTGRaphErrors(h):
    'Transforms a TH1/ rootpy.THist into a TGRaphErrors with same values and errors'
    x, y, ex, ey = (array.array('d',[]), array.array('d',[]), array.array('d',[]), array.array('d',[]) )
    for ibin in zipBins(h):
        x.append( ibin.center )
        y.append( ibin.content )
        ex.append( ibin.width / 2. )
        ey.append( ibin.error )
    gr = ROOT.TGraphErrors(len(x),x,y,ex,ey)
    gr.SetTitle( h.GetTitle() )
    gr.SetMarkerColor( h.GetMarkerColor() )
    gr.SetMarkerStyle( h.GetMarkerStyle() )
    #gr.SetFillColor( h.GetFillColor() )
    return gr
def HistToTGRaphErrors(h):
    'Transforms a TH1/ rootpy.THist into a TGRaphErrors with same values and errors'
    x, y, ex, ey = (array.array('d', []), array.array('d', []),
                    array.array('d', []), array.array('d', []))
    for ibin in zipBins(h):
        x.append(ibin.center)
        y.append(ibin.content)
        ex.append(ibin.width / 2.)
        ey.append(ibin.error)
    gr = ROOT.TGraphErrors(len(x), x, y, ex, ey)
    gr.SetTitle(h.GetTitle())
    gr.SetMarkerColor(h.GetMarkerColor())
    gr.SetMarkerStyle(h.GetMarkerStyle())
    #gr.SetFillColor( h.GetFillColor() )
    return gr
Esempio n. 5
0
    def make_closure_plots(self, var, testDir, refDir, rebin=1, xaxis=''):
        '''helper function to make comparison between data and data (closure test for fakerates etc.)'''
        self.canvas.cd()
        data_view = self.rebin_view(self.data, rebin)
        test_view = views.StyleView( views.TitleView( views.SubdirectoryView( data_view, testDir), 'Weighted data' ), fillcolor=ROOT.EColor.kRed, drawstyle='hist' )#.Get(var)
        refData   = views.SubdirectoryView( data_view, refDir).Get(var)

        testSampleName = '_'.join(testDir.split('/')[1:]).replace('IsoFailed','fail').replace('_weight','w')
        refSampleName  = refDir.split('/')[1].replace('IsoFailed','fail').replace('_weight','w')
        #testData.SetTitle(testSampleName)
        refData.SetTitle(refSampleName)

        diboson_views   = [ InflateErrorView( views.SubdirectoryView(self.rebin_view(self.get_view(pattern), rebin), refDir), 0.16 ) for pattern in ['WZ*'] ] #, 'ZZ*', 'WW*'] ]
        to_stack_views  = diboson_views + [test_view] #+ 
        stack_hist      = views.StackView( *to_stack_views ).Get(var)
        refData.drawstyle  = "ep"
        stack_hist.drawstyle = "HIST same" # same" #"HISTe same "
         
        hmax = max( [max([(b.content+b.error) for b in zipBins(refData)]),stack_hist.GetMaximum()] )
        refData.GetYaxis().SetRangeUser(0,hmax*1.3)
        refData.GetXaxis().SetTitle(xaxis)

        tgTest = HistStackToTGRaphErrors( stack_hist )
        tgTest.SetFillStyle(3013)
        tgTest.GetXaxis().SetTitle(xaxis)
        tgTest.GetYaxis().SetRangeUser(0,hmax*1.3)
        self.keep.append(tgTest)

        refData.SetMarkerStyle(20)
        refData.SetMarkerSize(1)
        self.keep.append(refData)
        self.keep.append(stack_hist)
        refData.Draw()
        stack_hist.Draw('same')
        stack_hist.GetXaxis().SetTitle(xaxis)
        stack_hist.GetYaxis().SetRangeUser(0,hmax*1.3)
        refData.Draw('same')
        tgTest.Draw('2 same')
        #stack_hist.Draw()
        #self.canvas.SetLogy()
        
        legend = self.add_legend([refData], leftside=False, entries=len(to_stack_views) +1)
        legend.AddEntry(stack_hist,'f')
        legend.Draw()
        self.add_cms_blurb(self.sqrts)
Esempio n. 6
0
    def Get(self, path):
        fakes = self.fakes.Get(path)
        wz = self.wz.Get(path)
        zz = self.zz.Get(path)

        bkg_error = wz.Clone()
        bkg_error.SetTitle("Bkg. Unc.")
        bkg_error.Reset()
        for bin_err, bin_wz, bin_zz, bin_fake in zipBins(
                bkg_error, wz, zz,
                fakes):  #range(1, bkg_error.GetNbinsX() + 1):
            bin_err.error = quad(bin_fake.error,
                                 bin_fake.content * self.fake_error,
                                 bin_wz.content * self.wz_error,
                                 bin_zz.content * self.zz_error)
            bin_err.content = (bin_fake.content(bin) + bin_wz.content(bin) +
                               bin_zz.content(bin))
        bkg_error.SetMarkerSize(0)
        bkg_error.SetFillColor(1)
        bkg_error.SetFillStyle(3013)
        bkg_error.legendstyle = 'f'
        return bkg_error
Esempio n. 7
0
 def apply_view(self, object):
     object = object.Clone()
     for hbin in zipBins(object):
         hbin.error *= self.inflation
     return object
Esempio n. 8
0
    def make_closure_plots(self, var, testDir, refDir, rebin=1, xaxis=''):
        '''helper function to make comparison between data and data (closure test for fakerates etc.)'''
        self.canvas.cd()
        data_view = self.rebin_view(self.data, rebin)
        test_view = views.StyleView(views.TitleView(
            views.SubdirectoryView(data_view, testDir), 'Weighted data'),
                                    fillcolor=ROOT.EColor.kRed,
                                    drawstyle='hist')  #.Get(var)
        refData = views.SubdirectoryView(data_view, refDir).Get(var)

        testSampleName = '_'.join(testDir.split('/')[1:]).replace(
            'IsoFailed', 'fail').replace('_weight', 'w')
        refSampleName = refDir.split('/')[1].replace('IsoFailed',
                                                     'fail').replace(
                                                         '_weight', 'w')
        #testData.SetTitle(testSampleName)
        refData.SetTitle(refSampleName)

        diboson_views = [
            InflateErrorView(
                views.SubdirectoryView(
                    self.rebin_view(self.get_view(pattern), rebin), refDir),
                0.16) for pattern in ['WZ*']
        ]  #, 'ZZ*', 'WW*'] ]
        to_stack_views = diboson_views + [test_view]  #+
        stack_hist = views.StackView(*to_stack_views).Get(var)
        refData.drawstyle = "ep"
        stack_hist.drawstyle = "HIST same"  # same" #"HISTe same "

        hmax = max([
            max([(b.content + b.error) for b in zipBins(refData)]),
            stack_hist.GetMaximum()
        ])
        refData.GetYaxis().SetRangeUser(0, hmax * 1.3)
        refData.GetXaxis().SetTitle(xaxis)

        tgTest = HistStackToTGRaphErrors(stack_hist)
        tgTest.SetFillStyle(3013)
        tgTest.GetXaxis().SetTitle(xaxis)
        tgTest.GetYaxis().SetRangeUser(0, hmax * 1.3)
        self.keep.append(tgTest)

        refData.SetMarkerStyle(20)
        refData.SetMarkerSize(1)
        self.keep.append(refData)
        self.keep.append(stack_hist)
        refData.Draw()
        stack_hist.Draw('same')
        stack_hist.GetXaxis().SetTitle(xaxis)
        stack_hist.GetYaxis().SetRangeUser(0, hmax * 1.3)
        refData.Draw('same')
        tgTest.Draw('2 same')
        #stack_hist.Draw()
        #self.canvas.SetLogy()

        legend = self.add_legend([refData],
                                 leftside=False,
                                 entries=len(to_stack_views) + 1)
        legend.AddEntry(stack_hist, 'f')
        legend.Draw()
        self.add_cms_blurb(self.sqrts)
 def apply_view(self, object):
     object = object.Clone()
     for hbin in zipBins(object):
         hbin.error *= self.inflation 
     return object