def HGCAL_label(text='HGCAL Simulation', pad=None): """Add label to the current Pad.""" if pad is None: pad = ROOT.gPad.func() with preserve_current_canvas(): pad.cd() left_margin = pad.GetLeftMargin() top_margin = pad.GetTopMargin() # Offset labels by 14% of the top margin ypos = 1 - 0.86 * top_margin label_cms = ROOT.TLatex(left_margin, ypos, "CMS") label_cms.SetTextFont(61) # Helvetica bold label_cms.SetTextAlign(11) # left-bottom label_cms.SetNDC() # The text is 75% as tall as the margin it lives in. label_cms.SetTextSize(0.75 * top_margin) label_cms.Draw() keepalive(pad, label_cms) # Draw additional text if desired label_add = None if text: label_add = ROOT.TLatex(left_margin + 0.09, ypos, text) label_add.SetTextFont(52) # Helvetica italic label_add.SetTextAlign(11) # left-bottom label_add.SetNDC() # The text is 75% as tall as the margin it lives in. label_add.SetTextSize(0.60 * top_margin) label_add.Draw() keepalive(pad, label_add) pad.Modified() pad.Update() return label_cms, label_add
def toprightplotlabel(input): plottitle = ROOT.TLatex(0.74, 0.971, input) plottitle.SetTextFont(43) plottitle.SetTextSize(canvasheight * labelscale) plottitle.SetNDC() plottitle.Draw()
def topleftplotlabel(input): plottitle = ROOT.TLatex(labelmargin, 0.974, input) plottitle.SetTextFont(43) plottitle.SetTextSize(canvasheight * labelscale) plottitle.SetNDC() plottitle.Draw()
def SRlabel(input): plottitle = ROOT.TLatex(labelmargin, 0.745, input) plottitle.SetTextFont(43) plottitle.SetTextSize(canvasheight * labelscale * 1.0) plottitle.SetNDC() plottitle.Draw()
def pvalue_plot(poi, pvalues, pad=None, xtitle='X', ytitle='P_{0}', linestyle=None, linecolor=None, yrange=None, verbose=False): """ Draw a pvalue plot Parameters ---------- poi : list List of POI values tested pvalues : list List of p-values or list of lists of p-values to overlay multiple p-value curves pad : Canvas or Pad, optional (default=None) Pad to draw onto. Create new pad if None. xtitle : str, optional (default='X') The x-axis label (POI name) ytitle : str, optional (default='P_{0}') The y-axis label linestyle : str or list, optional (default=None) Line style for the p-value graph or a list of linestyles for multiple p-value graphs. linecolor : str or list, optional (default=None) Line color for the p-value graph or a list of linestyles for multiple p-value graphs. Returns ------- pad : Canvas The pad. graphs : list of Graph The p-value graphs """ if not pvalues: raise ValueError("pvalues is empty") if not poi: raise ValueError("poi is empty") # determine if pvalues is list or list of lists if not isinstance(pvalues[0], (list, tuple)): pvalues = [pvalues] if linecolor is not None: if not isinstance(linecolor, list): linecolor = [linecolor] linecolor = cycle(linecolor) if linestyle is not None: if not isinstance(linestyle, list): linestyle = [linestyle] linestyle = cycle(linestyle) with preserve_current_canvas(): if pad is None: pad = Canvas() pad.cd() pad.SetLogy() # create the axis min_poi, max_poi = min(poi), max(poi) haxis = Hist(1000, min_poi, max_poi) xaxis = haxis.xaxis yaxis = haxis.yaxis xaxis.SetRangeUser(min_poi, max_poi) haxis.Draw('AXIS') min_pvalue = float('inf') graphs = [] for ipv, pv in enumerate(pvalues): graph = Graph(len(poi), linestyle='dashed', drawstyle='L', linewidth=2) for idx, (point, pvalue) in enumerate(zip(poi, pv)): graph.SetPoint(idx, point, pvalue) if linestyle is not None: graph.linestyle = linestyle.next() if linecolor is not None: graph.linecolor = linecolor.next() graphs.append(graph) curr_min_pvalue = min(pv) if curr_min_pvalue < min_pvalue: min_pvalue = curr_min_pvalue if verbose: for graph in graphs: log.info(['{0:1.1f}'.format(xval) for xval in list(graph.x())]) log.info(['{0:0.3f}'.format(yval) for yval in list(graph.y())]) # automatically handles axis limits axes, bounds = draw(graphs, pad=pad, same=True, logy=True, xtitle=xtitle, ytitle=ytitle, xaxis=xaxis, yaxis=yaxis, ypadding=(0.2, 0.1), logy_crop_value=1E-300) if yrange is not None: xaxis, yaxis = axes yaxis.SetLimits(*yrange) yaxis.SetRangeUser(*yrange) min_pvalue = yrange[0] # draw sigma levels up to minimum of pvalues line = Line() line.SetLineStyle(2) line.SetLineColor(2) latex = ROOT.TLatex() latex.SetNDC(False) latex.SetTextSize(20) latex.SetTextColor(2) sigma = 0 while True: pvalue = gaussian_cdf_c(sigma) if pvalue < min_pvalue: break keepalive( pad, latex.DrawLatex(max_poi, pvalue, " {0}#sigma".format(sigma))) keepalive(pad, line.DrawLine(min_poi, pvalue, max_poi, pvalue)) sigma += 1 pad.RedrawAxis() pad.Update() return pad, graphs
else: expr = expr.format( var_info['name'], h.name, (var_info['bins'], var_info['range'][0], var_info['range'][1])) print expr tree.Draw(expr, cut, var_info['style']) h = asrootpy(ROOT.gPad.GetPrimitive(h.name)) h.xaxis.title = get_label(var_info) h.yaxis.title = 'Number of Events' if h.integral() != 0: h /= h.integral() h.SetLineWidth(2) h.yaxis.SetRangeUser(0, 0.5) if 'binlabels' in var_info.keys(): for ib, lab in enumerate(var_info['binlabels']): h.xaxis.SetBinLabel(ib + 1, lab) c = Canvas() # c.SetLogy() c.SetTopMargin(0.08) h.Draw('HIST') label = ROOT.TLatex( c.GetLeftMargin() + 0.05, 1 - c.GetTopMargin() + 0.02, '{0}H #rightarrow #tau#tau (m_{{H}} = {1} GeV) - Hist Integral = {2}'.format( get_dir_mode(d), get_dir_mass(d), h.Integral())) label.SetNDC() label.SetTextSize(20) label.Draw('same') c.SaveAs('./plots/{0}_mass{1}_mode{2}.png'.format( key, get_dir_mass(d), get_dir_mode(d)))