def make_bottom_hist(cnv_wrp, kws): if not bottom_plot_canv_ok(cnv_wrp): return cnv_wrp par = dict(settings.defaults_BottomPlot) par.update(outer_kws) par.update(kws) cnv_wrp._par_mk_pull_plot_func = par rnds = cnv_wrp._renderers mcee_rnd, data_rnd = bottom_plot_get_div_hists(rnds) y_title = par['y_title'] or ('#frac{Data-MC}{#sigma}' if data_rnd.is_data else '#frac{Sig-bkg}{bkg}') # produce pull histogram mc_histo = mcee_rnd.histo data_hist = data_rnd.histo # NO CLONE HERE! sigma_histo = mcee_rnd.histo.Clone() data_hist.SetBinErrorOption(ROOT.TH1.kPoisson) mc_histo.SetBinErrorOption(ROOT.TH1.kPoisson) for i in xrange(mc_histo.GetNbinsX() + 2): sigma_histo.SetBinError(i, 0.) # pm stands for plusminus pm = 1. if data_hist.GetBinContent(i) > mc_histo.GetBinContent( i) else -1. mc_sig_stat = mc_histo.GetBinErrorUp( i) if pm > 0 else mc_histo.GetBinErrorLow(i) data_sig_stat = data_hist.GetBinErrorLow( i) if pm > 0 else data_hist.GetBinErrorUp(i) if not data_hist.GetBinContent(i): data_sig_stat = 1.8 if not mc_histo.GetBinContent(i): mc_sig_stat = 1.8 mc_sig_syst = 0. if mcee_rnd.histo_sys_err: mc_sys_hist = mcee_rnd.histo_sys_err mc_sig_syst = mc_sys_hist.GetBinError(i) + pm * abs( mc_histo.GetBinContent(i) - mc_sys_hist.GetBinContent(i)) sqr_quad = sqrt(mc_sig_stat**2 + data_sig_stat**2 + mc_sig_syst**2) or 1e-10 sigma_histo.SetBinContent(i, sqr_quad) div_hist = data_hist.Clone() # NOW CLONING! div_hist.Add(mc_histo, -1) div_hist.Divide(sigma_histo) div_hist.SetYTitle(y_title) cnv_wrp.bottom_hist = div_hist settings.set_bottom_plot_general_style(cnv_wrp.bottom_hist) settings.set_bottom_plot_pull_style(div_hist) _bottom_plot_y_bounds(cnv_wrp, cnv_wrp.bottom_hist, par) par['draw_opt'] = 'hist'
def make_bottom_hist(cnv_wrp, kws): if not bottom_plot_canv_ok(cnv_wrp): return cnv_wrp par = dict(settings.defaults_BottomPlot) par.update(outer_kws) par.update(kws) cnv_wrp._par_mk_pull_plot_func = par rnds = cnv_wrp._renderers mcee_rnd, data_rnd = bottom_plot_get_div_hists(rnds) y_title = par['y_title'] or ( '#frac{Data-MC}{#sigma}' if data_rnd.is_data else '#frac{Sig-bkg}{bkg}') # produce pull histogram mc_histo = mcee_rnd.histo data_hist = data_rnd.histo # NO CLONE HERE! sigma_histo = mcee_rnd.histo.Clone() data_hist.SetBinErrorOption(ROOT.TH1.kPoisson) mc_histo.SetBinErrorOption(ROOT.TH1.kPoisson) for i in xrange(mc_histo.GetNbinsX()+2): sigma_histo.SetBinError(i, 0.) # pm stands for plusminus pm = 1. if data_hist.GetBinContent(i) > mc_histo.GetBinContent(i) else -1. mc_sig_stat = mc_histo.GetBinErrorUp(i) if pm > 0 else mc_histo.GetBinErrorLow(i) data_sig_stat = data_hist.GetBinErrorLow(i) if pm > 0 else data_hist.GetBinErrorUp(i) if not data_hist.GetBinContent(i): data_sig_stat = 1.8 if not mc_histo.GetBinContent(i): mc_sig_stat = 1.8 mc_sig_syst = 0. if mcee_rnd.histo_sys_err: mc_sys_hist = mcee_rnd.histo_sys_err mc_sig_syst = mc_sys_hist.GetBinError(i) + pm*abs( mc_histo.GetBinContent(i) - mc_sys_hist.GetBinContent(i)) sqr_quad = sqrt(mc_sig_stat**2+data_sig_stat**2+mc_sig_syst**2) or 1e-10 sigma_histo.SetBinContent(i, sqr_quad) div_hist = data_hist.Clone() # NOW CLONING! div_hist.Add(mc_histo, -1) div_hist.Divide(sigma_histo) div_hist.SetYTitle(y_title) cnv_wrp.bottom_hist = div_hist settings.set_bottom_plot_general_style(cnv_wrp.bottom_hist) settings.set_bottom_plot_pull_style(div_hist) _bottom_plot_y_bounds(cnv_wrp, cnv_wrp.bottom_hist, par) par['draw_opt'] = 'hist'
def _bottom_plot_fix_bkg_err_values(wrp, histo): # errors are not plottet, if the bin center is out of the y bounds. # this function fixes it. y_min, y_max = wrp.y_min_max for i in xrange(1, histo.GetNbinsX() + 1): val = histo.GetBinContent(i) new_val = 0 if val <= y_min: new_val = y_min * 0.99 elif val >= y_max: new_val = y_max * 0.99 if new_val: new_err = histo.GetBinError(i) - abs(new_val - val) new_err = max(new_err, 0) # may not be negative histo.SetBinContent(i, new_val) histo.SetBinError(i, new_err) settings.set_bottom_plot_general_style(histo) histo.GetYaxis().SetRangeUser(y_min, y_max)
def make_bottom_hist(cnv_wrp, kws): if not bottom_plot_canv_ok(cnv_wrp): return cnv_wrp par = dict(settings.defaults_BottomPlot) par.update(outer_kws) par.update(kws) cnv_wrp._par_mk_ratio_plot_func = par rnds = cnv_wrp._renderers div_wrp = op.div(bottom_plot_get_div_hists(rnds)) div_wrp.histo.SetYTitle(par['y_title'] or ( '#frac{Data}{MC}' if rnds[1].is_data else 'Ratio')) cnv_wrp.bottom_hist = div_wrp.histo settings.set_bottom_plot_general_style(cnv_wrp.bottom_hist) settings.set_bottom_plot_ratio_style(cnv_wrp.bottom_hist) _bottom_plot_y_bounds(cnv_wrp, cnv_wrp.bottom_hist, par)
def make_bottom_hist(cnv_wrp, kws): if not bottom_plot_canv_ok(cnv_wrp): return cnv_wrp par = dict(settings.defaults_BottomPlot) par.update(outer_kws) par.update(kws) cnv_wrp._par_mk_ratio_plot_func = par rnds = cnv_wrp._renderers div_wrp = op.div(bottom_plot_get_div_hists(rnds)) div_wrp.histo.SetYTitle( par['y_title'] or ('#frac{Data}{MC}' if rnds[1].is_data else 'Ratio')) cnv_wrp.bottom_hist = div_wrp.histo settings.set_bottom_plot_general_style(cnv_wrp.bottom_hist) settings.set_bottom_plot_ratio_style(cnv_wrp.bottom_hist) _bottom_plot_y_bounds(cnv_wrp, cnv_wrp.bottom_hist, par)