def _build_signal(self): self.signals = [ Sample('VBFH', convert_color(ROOT.kRed +1, 'mpl'), 'VBF'), Sample('ggH', convert_color(ROOT.kRed - 1, 'mpl'), 'ggH'), Sample('VH', convert_color(ROOT.kRed - 3, 'mpl'), 'VH', ['WH', 'ZH']), Sample('ttH', convert_color(ROOT.kRed - 5, 'mpl'), 'ttH'), ] for s in self.signals: self.sample_dict[s.name] = s
def _build_background(self): """ """ Ztt = Sample('Ztt', convert_color(ROOT.kAzure + 1, 'mpl'), 'Z#rightarrow#tau#tau', sub_samples=['Ztt', 'ZttEWK']) Fake = Sample('Fake', 'yellow', 'Fake' if self.channel == 'hadhad' else 'Fakes') Zll = Sample('Zll', convert_color(ROOT.kCyan - 10, 'mpl'), 'Z#rightarrowll', sub_samples=None if self.channel=='hadhad' else ['Zll', 'ZllEWK']) Top = Sample('Top', convert_color(ROOT.kOrange + 1, 'mpl'), 'Top') if self.channel == 'leplep': Others = Sample('Others', convert_color(ROOT.kViolet + 1, 'mpl'), 'Others', sub_samples=['VV', 'ggHWW', 'VBFHWW']) self.background_keys = ['Ztt', 'ZttEWK', 'Fake', 'Top', 'Zll', 'ZllEWK', 'VV', 'ggHWW', 'VBFHWW'] elif self.channel == 'lephad': Others = Sample('Others', convert_color(ROOT.kViolet + 1, 'mpl'), 'Others', sub_samples=['VV', 'W', 'WEWK']) self.background_keys = ['Ztt', 'ZttEWK', 'Fake', 'Top', 'Zll', 'ZllEWK', 'VV', 'W', 'WEWK'] elif self.channel == 'hadhad': Others = Sample('Others', convert_color(ROOT.kViolet + 1, 'mpl'), 'Others', sub_samples=['VV', 'W']) self.background_keys = ['Ztt', 'ZttEWK', 'Fake', 'VV', 'Top', 'Zll', 'W'] else: raise ValueError('Wrong channel') self.backgrounds = [Ztt, Fake, Zll, Top, Others] for b in self.backgrounds: self.sample_dict[b.name] = b
def draw_contours(hist, n_contours=3, contours=None, linecolors=None, linestyles=None, linewidths=None, labelcontours=True, labelcolors=None, labelsizes=None, labelformats=None, same=False, min_points=5): if contours is None: contours = np.linspace(hist.min(), hist.max(), n_contours + 1, endpoint=False)[1:] hist = hist.Clone() hist.SetContour(len(contours), np.asarray(contours, dtype=float)) graphs = [] levels = [] with invisible_canvas() as c: hist.Draw('CONT LIST') c.Update() conts = asrootpy(ROOT.gROOT.GetListOfSpecials().FindObject('contours')) for i, cont in enumerate(conts): for curve in cont: if len(curve) < min_points: continue graphs.append(curve.Clone()) levels.append(contours[i]) if not same: axes = hist.Clone() axes.Draw('AXIS') if linecolors is None: linecolors = ['black'] elif not isinstance(linecolors, list): linecolors = [linecolors] if linestyles is None: linestyles = linestyles_text2root.keys() elif not isinstance(linestyles, list): linestyles = [linestyles] if linewidths is None: linewidths = [1] elif not isinstance(linewidths, list): linewidths = [linewidths] if labelsizes is not None: if not isinstance(labelsizes, list): labelsizes = [labelsizes] labelsizes = cycle(labelsizes) if labelcolors is not None: if not isinstance(labelcolors, list): labelcolors = [labelcolors] labelcolors = cycle(labelcolors) if labelformats is None: labelformats = ['%0.2g'] elif not isinstance(labelformats, list): labelformats = [labelformats] linecolors = cycle(linecolors) linestyles = cycle(linestyles) linewidths = cycle(linewidths) labelformats = cycle(labelformats) label = ROOT.TLatex() xmin, xmax = hist.bounds(axis=0) ymin, ymax = hist.bounds(axis=1) stepx = (xmax - xmin) / 100 stepy = (ymax - ymin) / 100 for level, graph in zip(levels, graphs): graph.linecolor = linecolors.next() graph.linewidth = linewidths.next() graph.linestyle = linestyles.next() graph.Draw('C') if labelcontours: if labelsizes is not None: label.SetTextSize(labelsizes.next()) if labelcolors is not None: label.SetTextColor(convert_color(labelcolors.next(), 'ROOT')) point_idx = len(graph) / 2 point = graph[point_idx] padx, pady = 0, 0 if len(graph) > 5: # use derivative to get text angle x1, y1 = graph[point_idx - 2] x2, y2 = graph[point_idx + 2] dx = (x2 - x1) / stepx dy = (y2 - y1) / stepy if dx == 0: label.SetTextAngle(0) label.SetTextAlign(12) else: padx = copysign(1, -dy) * stepx pady = copysign(1, dx) * stepy if pady < 0: align = 23 else: align = 21 angle = atan(dy / dx) * 180 / pi label.SetTextAngle(angle) label.SetTextAlign(align) else: label.SetTextAngle(0) label.SetTextAlign(21) label.DrawLatex(point[0] + padx, point[1] + pady, (labelformats.next()) % level)
def make_plot(raw_data, binning, title_text, outfn): h = Hist(*binning, drawstyle='hist e1', color=sigCOLORS[0], linewidth=2, title=';Percent difference[%];Events') for sample, value in raw_data.items(): h.Fill(value['variation'], value['count']) hc = asrootpy(h.GetCumulative()) hc.linecolor = 'gold' hc.fillcolor = 'lightyellow' hc.fillstyle = 'solid' hc.scale(h.max(include_error=True) / hc.max()) xmin_, xmax_, ymin_, ymax_ = get_limits([h, hc]) draw([hc, h], ylimits=(0, ymax_)) x95, x99 = None, None cumsum = 0 for i in range(1, h.GetNbinsX() + 1): cumsum += h.GetBinContent(i) if x95 is None and cumsum / h.Integral() > 0.95: x95 = h.GetXaxis().GetBinUpEdge(i) if x99 is None and cumsum / h.Integral() > 0.99: x99 = h.GetXaxis().GetBinUpEdge(i) title = TitleAsLatex(title_text) title.Draw() # print(title_text, ROOT.gPad.GetUymax(), hc.max()) # draw a second axis on the right. ROOT.gPad.SetTicks( 1, 0 ) # Draw top ticks but not right ticks (https://root.cern.ch/root/roottalk/roottalk99/2908.html) low, high = 0, ROOT.gPad.GetUymax() / hc.max() raxis = ROOT.TGaxis(ROOT.gPad.GetUxmax(), ROOT.gPad.GetUymin(), ROOT.gPad.GetUxmax(), ROOT.gPad.GetUymax(), low, high, 510, "+L") raxis.SetLabelSize(0.03) raxis.SetLabelFont(42) raxis.SetLabelColor(convert_color('gold', 'root')) raxis.Draw() frame = canvas.FindObject('TFrame') lo, hi = frame.GetY1(), frame.GetY2() l95 = ROOT.TLine(x95, lo, x95, hi) l95.SetLineStyle(2) l95.SetLineColor(convert_color(sigCOLORS[1], 'root')) l95.SetLineWidth(2) l95.Draw() l99 = ROOT.TLine(x99, lo, x99, hi) l99.SetLineStyle(3) l99.SetLineColor(convert_color(sigCOLORS[2], 'root')) l99.Draw() leg = Legend(3, margin=0.25, leftmargin=0.45, topmargin=0.02, entrysep=0.01, entryheight=0.02, textsize=10) leg.AddEntry(hc, label='cumulative (norm.)', style='LF') leg.AddEntry(l95, label='95% @ {}'.format(x95), style='L') leg.AddEntry(l99, label='99% @ {}'.format(x99), style='L') leg.Draw() canvas.SaveAs(outfn) canvas.clear()
numbers[channel][sample][cutCount] = int(words[1]) for channel in numbers: if channel not in histos: histos[channel] = {} for sample in numbers[channel]: histos[channel][sample] = ROOT.TH1F("hCutFlow%s%s"%(sample,channel), "Cut flow summary %s"%channel, cutCountMax, 0, cutCountMax) for nCut, n in numbers[channel][sample].iteritems(): histos[channel][sample].SetBinContent(nCut, float(n)) histos[channel][sample].GetXaxis().SetBinLabel(nCut, cutNames[nCut]) if args.stacks: histos[channel][sample].SetLineWidth(4) if not sampleInfo[sample]['isData'] and sampleInfo[sample]['isSignal']: histos[channel][sample].SetFillColorAlpha(convert_color(sampleInfo[sample]['color'], 'root'), 0.2) histos[channel][sample].SetLineColor(convert_color(sampleInfo[sample]['color'], 'root')) elif not sampleInfo[sample]['isData'] and not sampleInfo[sample]['isSignal']: histos[channel][sample].SetFillStyle(1001) histos[channel][sample].SetFillColor(convert_color(sampleInfo[sample]['color'], 'root')) histos[channel][sample].SetLineColor(ROOT.EColor.kBlack) else: histos[channel][sample].SetMarkerStyle(4) histos[channel][sample].SetMarkerColor(convert_color(sampleInfo[sample]['color'], 'root')) histos[channel][sample].SetMarkerSize(2) histos[channel][sample].SetLineColor(convert_color(sampleInfo[sample]['color'], 'root')) if channel == "eeee": evType = "4e" elif channel == "eemm": evType = "2e2\\mu" elif channel == "mmmm":