def hists_to_graph_asymm_err(hlow, hcent, hhigh): 'convert three histograms into one TGraphAsymmError' if hlow.GetNbinsX() == hcent.GetNbinsX() == hhigh.GetNbinsX(): binsx = [] binsy = [] errx = [] erryl = [] erryh = [] for binl, binm, binh in zipBins(hlow, hcent, hhigh): binsx.append( binm.center ) binsy.append( binm.content) errx.append( binm.width/2. ) erryl.append( binm.content - binl.content) erryh.append( binh.content - binm.content) return ROOT.TGraphAsymmErrors(len(binsx), array('f',binsx), array('f',binsy), array('f',errx), array('f',errx), array('f',erryl), array('f',erryh) ) else: raise BinError("The tree input histograms don't have the same binning")
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 apply_error_from_sysHist(self, hlow, hcent, hhigh): if hlow.GetNbinsX() == hcent.GetNbinsX() == hhigh.GetNbinsX(): for binl, binm, binh in zipBins(hlow, hcent, hhigh): binm.error = max(abs(binm.content - binl.content), abs(binm.content - binh.content)) else: raise BinError( "The tree input histograms don't have the same binning")
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 ['VH*'] ] #, '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 hists_to_graph_asymm_err(hlow, hcent, hhigh): 'convert three histograms into one TGraphAsymmError' if hlow.GetNbinsX() == hcent.GetNbinsX() == hhigh.GetNbinsX(): binsx = [] binsy = [] errx = [] erryl = [] erryh = [] for binl, binm, binh in zipBins(hlow, hcent, hhigh): binsx.append(binm.center) binsy.append(binm.content) errx.append(binm.width / 2.) erryl.append(binm.content - binl.content) erryh.append(binh.content - binm.content) return ROOT.TGraphAsymmErrors(len(binsx), array('f', binsx), array('f', binsy), array('f', errx), array('f', errx), array('f', erryl), array('f', erryh)) else: raise BinError( "The tree input histograms don't have the same binning")
def apply_error_from_sysHist(self, hlow, hcent, hhigh): if hlow.GetNbinsX() == hcent.GetNbinsX() == hhigh.GetNbinsX(): for binl, binm, binh in zipBins(hlow, hcent, hhigh): binm.error = max( abs(binm.content-binl.content), abs(binm.content-binh.content) ) else: raise BinError("The tree input histograms don't have the same binning")