def get_met_filter_acceptance(passed_list, total, parameters): print('') print('*** start get_met_filter_acceptance') canvas = ROOT.TCanvas("c", "c", 1000, 600) canvas.SetLogy() n_bins = len(parameters['from_to']) bin_width = (parameters['from_to'][-1] - parameters['from_to'][0]) / n_bins histo = [ ROOT.TH1F('histo' + str(x), ';MET_LocHadTopo Threshold [GeV];Acceptance', n_bins, parameters['from_to'][0] - bin_width / 2., parameters['from_to'][-1] + bin_width / 2.) for x in range(len(passed_list)) ] legend = ROOT.TLegend(0.6, 0.50, 0.85, 0.85) denominator = total.Integral(0, -1) for (ii, passed) in enumerate(passed_list): utils.decorate_histogram(histo[ii], BasicConfig.colors[ii]) for threshold in parameters['from_to']: numerator = passed.Integral(passed.FindBin(threshold), -1) acceptance, error = utils.division_error_propagation( numerator, denominator) histo[ii].SetBinContent(histo[ii].FindBin(threshold), acceptance) histo[ii].SetBinError(histo[ii].FindBin(threshold), error) if ii == 0: if 'max_min' in parameters: histo[ii].SetMaximum(parameters['max_min'][0]) histo[ii].SetMinimum(parameters['max_min'][1]) histo[ii].Draw('e1') else: histo[ii].Draw('same,e1') legend.AddEntry(histo[ii], parameters['legend'][ii], 'ple') if 'reference' in parameters: ref_acceptance = parameters['reference'].Integral(0, -1) / denominator print ref_acceptance canvas.Update() tl = ROOT.TLine(canvas.GetUxmin(), ref_acceptance, canvas.GetUxmax(), ref_acceptance) tl.SetLineColor(ROOT.kGray + 1) tl.SetLineStyle(2) tl.Draw() utils.decorate_legend(legend) legend.Draw() AtlasStyle.ATLASLabel(0.19, 0.85, 'Work in Progress') AtlasStyle.myText(0.20, 0.79, ROOT.kBlack, parameters['label'], 0.035) if 'label2' in parameters: AtlasStyle.myText(0.20, 0.74, ROOT.kBlack, parameters['label2'], 0.035) utils.save_as( canvas, BasicConfig.plotdir + parameters['plot_name'] + '_' + str(date.today()))
def overlay_histograms(histograms, legends, parameters): print('') print('*** start overlay_histograms') canvas = ROOT.TCanvas("c", "c", 1000, 600) y_max = histograms[0].GetMaximum() * 2 y_min = 0.8 leg = ROOT.TLegend(0.55, 0.7, 0.86, 0.90) for ii, (histogram, legend) in enumerate(zip(histograms, legends)): print(ii) decorate_histogram(histogram, BasicConfig.colors[ii]) if 'x_max' in parameters: histogram.GetXaxis().SetRangeUser(0, parameters['x_max']) if ii == 0: if 'doNorm' not in parameters: histograms[0].SetMinimum(y_min) histograms[0].SetMaximum(histograms[0].GetMaximum() * 30) else: histograms[0].Scale(1. / histograms[0].Integral()) histograms[0].SetMaximum(histograms[0].GetMaximum() * 1.5) if 'noLogy' in parameters: histograms[0].SetMinimum(0) histogram.Draw() else: if histogram.GetMaximum() > y_max and 'doNorm' not in parameters: y_max = histogram.GetMaximum() if 'noLogy' not in parameters: histograms[0].SetMaximum(y_max * 15) histogram.Draw('same') elif 'doNorm' in parameters: histogram.Scale(1. / histogram.Integral()) if histogram.GetMaximum() > histograms[0].GetMaximum(): histograms[0].SetMaximum(histogram.GetMaximum() * 1.5) if 'noLogy' not in parameters: histograms[0].SetMaximum(histogram.GetMaximum() * 15) histogram.Draw('same') leg.AddEntry(histogram, legend, 'l') canvas.Update() canvas.SetLogy() if 'noLogy' in parameters: canvas.SetLogy(parameters['noLogy']) decorate_legend(leg) leg.Draw() AtlasStyle.ATLASLabel(0.20, 0.85, 'Work in Progress') AtlasStyle.myText(0.22, 0.80, ROOT.kBlack, parameters['label'], 0.038) if 'label2' in parameters: AtlasStyle.myText(0.25, 0.76, ROOT.kBlack, parameters['label2'], 0.038) save_as( canvas, BasicConfig.plotdir + parameters['plot_name'] + '_' + str(date.today()))
def overlay_histograms(histograms, legends, parameters): print('') print('*** start overlay_histograms') canvas = ROOT.TCanvas("c", "c", 1000, 600) y_max = histograms[0].GetMaximum() * 2 y_min = 0.8 leg = ROOT.TLegend(0.55, 0.7, 0.86, 0.90) for ii, (histogram, legend) in enumerate(zip(histograms, legends)): print(ii) decorate_histogram(histogram, BasicConfig.colors[ii]) if 'x_max' in parameters: histogram.GetXaxis().SetRangeUser(0, parameters['x_max']) if ii == 0: if 'doNorm' not in parameters: histograms[0].SetMinimum(y_min) histograms[0].SetMaximum(histograms[0].GetMaximum() * 30) else: histograms[0].Scale(1./histograms[0].Integral()) histograms[0].SetMaximum(histograms[0].GetMaximum() * 1.5) if 'noLogy' in parameters: histograms[0].SetMinimum(0) histogram.Draw() else: if histogram.GetMaximum() > y_max and 'doNorm' not in parameters: y_max = histogram.GetMaximum() if 'noLogy' not in parameters: histograms[0].SetMaximum(y_max * 15) histogram.Draw('same') elif 'doNorm' in parameters: histogram.Scale(1./histogram.Integral()) if histogram.GetMaximum() > histograms[0].GetMaximum(): histograms[0].SetMaximum(histogram.GetMaximum() * 1.5) if 'noLogy' not in parameters: histograms[0].SetMaximum(histogram.GetMaximum() * 15) histogram.Draw('same') leg.AddEntry(histogram, legend, 'l') canvas.Update() canvas.SetLogy() if 'noLogy' in parameters: canvas.SetLogy(parameters['noLogy']) decorate_legend(leg) leg.Draw() AtlasStyle.ATLASLabel(0.20, 0.85, 'Work in Progress') AtlasStyle.myText(0.22, 0.80, ROOT.kBlack, parameters['label'], 0.038) if 'label2' in parameters: AtlasStyle.myText(0.25, 0.76, ROOT.kBlack, parameters['label2'], 0.038) save_as(canvas, BasicConfig.plotdir + parameters['plot_name'] + '_' + str(date.today()))
def draw_mass_distributions_and_ratio(self, ntrk, region, h_data, h_model): canvas2 = ROOT.TCanvas('canvas2', 'canvas2', 1000, 750) # mass distributions pad1 = ROOT.TPad('pad1', 'pad1', 0, 0.3, 1, 1.0) pad2 = ROOT.TPad('pad2', 'pad2', 0, 0.05, 1, 0.3) self.prepare_pads(canvas2, pad1, pad2) pad1.cd() self.configure_data_histogram(h_data) h_data.SetMaximum(h_data.GetMaximum() * 8) self.configure_model_histogram(h_model) h_data.Draw('e') h_model.SetLineWidth(2) h_model.Draw('same,hist') h_data.Draw('same,e') # list_diff3[ipad-1].SetLineWidth(2) AtlasStyle.ATLASLabel(self.ax, self.ay, 'Work in Progress') AtlasStyle.myText(self.tx, self.ty, ROOT.kBlack, self.beam_condition, 0.038) leg = ROOT.TLegend(self.x_min, self.y_min, self.x_max, self.y_max) leg.AddEntry(h_data, str(ntrk) + '-trk vertices Region' + str(region), 'lep') leg.AddEntry(h_model, str(ntrk - 1) + '-trk vert + 1 random track', 'f') utils.decorate_legend(leg) leg.Draw() line = ROOT.TLine(self.m_cut, h_data.GetMinimum(), self.m_cut, h_data.GetMaximum() * 0.1) utils.decorate_line(line, ROOT.kGray + 1, 5) line.Draw() # Ratio plot pad2.cd() h_ratio = h_data.Clone(str(ntrk) + 'trk_ratio' + str(region)) h_ratio.Sumw2() h_ratio.Divide(h_model) self.decorate_ratio_plot(h_ratio, 0.1, 1.9) h_ratio.Draw('e2p') line2 = ROOT.TLine(self.m_cut, h_ratio.GetMinimum(), self.m_cut, h_ratio.GetMaximum()) utils.decorate_line(line2, ROOT.kGray + 1, 5) line2.Draw() directory = BasicConfig.plotdir + 'bg_est/' + str(date.today()) os.system('mkdir -p ' + directory) utils.save_as( canvas2, directory + '/pseudoFit_' + str(ntrk) + 'Trk_Region' + str(region)) canvas2.Close()
def get_met_filter_acceptance(passed_list, total, parameters): print('') print('*** start get_met_filter_acceptance') canvas = ROOT.TCanvas("c", "c", 1000, 600) canvas.SetLogy() n_bins = len(parameters['from_to']) bin_width = (parameters['from_to'][-1] - parameters['from_to'][0]) / n_bins histo = [ROOT.TH1F('histo' + str(x), ';MET_LocHadTopo Threshold [GeV];Acceptance', n_bins, parameters['from_to'][0] - bin_width / 2., parameters['from_to'][-1] + bin_width / 2.) for x in range(len(passed_list))] legend = ROOT.TLegend(0.6, 0.50, 0.85, 0.85) denominator = total.Integral(0, -1) for (ii, passed) in enumerate(passed_list): utils.decorate_histogram(histo[ii], BasicConfig.colors[ii]) for threshold in parameters['from_to']: numerator = passed.Integral(passed.FindBin(threshold), -1) acceptance, error = utils.division_error_propagation(numerator, denominator) histo[ii].SetBinContent(histo[ii].FindBin(threshold), acceptance) histo[ii].SetBinError(histo[ii].FindBin(threshold), error) if ii == 0: if 'max_min' in parameters: histo[ii].SetMaximum(parameters['max_min'][0]) histo[ii].SetMinimum(parameters['max_min'][1]) histo[ii].Draw('e1') else: histo[ii].Draw('same,e1') legend.AddEntry(histo[ii], parameters['legend'][ii], 'ple') if 'reference' in parameters: ref_acceptance = parameters['reference'].Integral(0, -1) / denominator print ref_acceptance canvas.Update() tl = ROOT.TLine(canvas.GetUxmin(), ref_acceptance, canvas.GetUxmax(), ref_acceptance) tl.SetLineColor(ROOT.kGray+1) tl.SetLineStyle(2) tl.Draw() utils.decorate_legend(legend) legend.Draw() AtlasStyle.ATLASLabel(0.19, 0.85, 'Work in Progress') AtlasStyle.myText(0.20, 0.79, ROOT.kBlack, parameters['label'], 0.035) if 'label2' in parameters: AtlasStyle.myText(0.20, 0.74, ROOT.kBlack, parameters['label2'], 0.035) utils.save_as(canvas, BasicConfig.plotdir + parameters['plot_name'] + '_' + str(date.today()))
def superpose_tocs(passed_list, total, parameters): print('') print('*** start create_toc_plot') #if len(passed_list) != len(total_list): # print('lengths of passed_list and total_list are different.') # print('aborted.') # sys.exit() canvas = ROOT.TCanvas("c", "c", 1000, 600) legend = ROOT.TLegend(0.6, 0.20, 0.85, 0.60) tgs = [] for index, passed in enumerate(passed_list): if 'rebin' in parameters: passed.Rebin(parameters['rebin']) if index == 0: # only once if passed.GetNbinsX() != total.GetNbinsX(): total.Rebin(parameters['rebin']) tg = ROOT.TGraphAsymmErrors(passed, total) utils.decorate_histogram(tg, BasicConfig.colors[index]) if index == 0: tg.SetMaximum(1.09) tg.GetXaxis().SetRangeUser(0, 400) tg.GetYaxis().SetTitle('Efficiency') if 'x_title' in parameters: tg.GetXaxis().SetTitle(parameters['x_title']) tg.Draw('AP') else: tg.Draw('P,same') legend.AddEntry(tg, parameters['legend'][index], 'pl') tgs.append(tg) # stored temporarily utils.decorate_legend(legend) legend.Draw() AtlasStyle.ATLASLabel(0.19, 0.85, 'Work in Progress') AtlasStyle.myText(0.20, 0.79, ROOT.kBlack, parameters['label'], 0.035) if 'label2' in parameters: AtlasStyle.myText(0.20, 0.74, ROOT.kBlack, parameters['label2'], 0.035) utils.save_as( canvas, BasicConfig.plotdir + parameters['plot_name'] + '_' + str(date.today()))
def draw_mass_distributions_and_ratio(self, ntrk, region, h_data, h_model): canvas2 = ROOT.TCanvas('canvas2', 'canvas2', 1000, 750) # mass distributions pad1 = ROOT.TPad('pad1', 'pad1', 0, 0.3, 1, 1.0) pad2 = ROOT.TPad('pad2', 'pad2', 0, 0.05, 1, 0.3) self.prepare_pads(canvas2, pad1, pad2) pad1.cd() self.configure_data_histogram(h_data) h_data.SetMaximum(h_data.GetMaximum() * 8) self.configure_model_histogram(h_model) h_data.Draw('e') h_model.SetLineWidth(2) h_model.Draw('same,hist') h_data.Draw('same,e') # list_diff3[ipad-1].SetLineWidth(2) AtlasStyle.ATLASLabel(self.ax, self.ay, 'Work in Progress') AtlasStyle.myText(self.tx, self.ty, ROOT.kBlack, self.beam_condition, 0.038) leg = ROOT.TLegend(self.x_min, self.y_min, self.x_max, self.y_max) leg.AddEntry(h_data, str(ntrk) + '-trk vertices Region' + str(region), 'lep') leg.AddEntry(h_model, str(ntrk-1) + '-trk vert + 1 random track', 'f') utils.decorate_legend(leg) leg.Draw() line = ROOT.TLine(self.m_cut, h_data.GetMinimum(), self.m_cut, h_data.GetMaximum() * 0.1) utils.decorate_line(line, ROOT.kGray+1, 5) line.Draw() # Ratio plot pad2.cd() h_ratio = h_data.Clone(str(ntrk) + 'trk_ratio' + str(region)) h_ratio.Sumw2() h_ratio.Divide(h_model) self.decorate_ratio_plot(h_ratio, 0.1, 1.9) h_ratio.Draw('e2p') line2 = ROOT.TLine(self.m_cut, h_ratio.GetMinimum(), self.m_cut, h_ratio.GetMaximum()) utils.decorate_line(line2, ROOT.kGray+1, 5) line2.Draw() directory = BasicConfig.plotdir + 'bg_est/' + str(date.today()) os.system('mkdir -p ' + directory) utils.save_as(canvas2, directory + '/pseudoFit_' + str(ntrk) + 'Trk_Region' + str(region)) canvas2.Close()
def superpose_tocs(passed_list, total, parameters): print('') print('*** start create_toc_plot') #if len(passed_list) != len(total_list): # print('lengths of passed_list and total_list are different.') # print('aborted.') # sys.exit() canvas = ROOT.TCanvas("c", "c", 1000, 600) legend = ROOT.TLegend(0.6, 0.20, 0.85, 0.60) tgs = [] for index, passed in enumerate(passed_list): if 'rebin' in parameters: passed.Rebin(parameters['rebin']) if index == 0: # only once if passed.GetNbinsX() != total.GetNbinsX(): total.Rebin(parameters['rebin']) tg = ROOT.TGraphAsymmErrors(passed, total) utils.decorate_histogram(tg, BasicConfig.colors[index]) if index == 0: tg.SetMaximum(1.09) tg.GetXaxis().SetRangeUser(0, 400) tg.GetYaxis().SetTitle('Efficiency') if 'x_title' in parameters: tg.GetXaxis().SetTitle(parameters['x_title']) tg.Draw('AP') else: tg.Draw('P,same') legend.AddEntry(tg, parameters['legend'][index], 'pl') tgs.append(tg) # stored temporarily utils.decorate_legend(legend) legend.Draw() AtlasStyle.ATLASLabel(0.19, 0.85, 'Work in Progress') AtlasStyle.myText(0.20, 0.79, ROOT.kBlack, parameters['label'], 0.035) if 'label2' in parameters: AtlasStyle.myText(0.20, 0.74, ROOT.kBlack, parameters['label2'], 0.035) utils.save_as(canvas, BasicConfig.plotdir + parameters['plot_name'] + '_' + str(date.today()))
def create_toc_plot(passed, total, parameters): print('') print('*** start create_toc_plot') canvas = ROOT.TCanvas("c", "c", 1000, 600) if 'rebin' in parameters: passed.Rebin(parameters['rebin']) total.Rebin(parameters['rebin']) tg = ROOT.TGraphAsymmErrors(passed, total) tg.GetXaxis().SetRangeUser(0, 400) tg.GetYaxis().SetTitle('Efficiency') if 'x_title' in parameters: tg.GetXaxis().SetTitle(parameters['x_title']) tg.Draw('AP') AtlasStyle.ATLASLabel(0.50, 0.4, 'Work in Progress') AtlasStyle.myText(0.55, 0.32, ROOT.kBlack, parameters['label'], 0.038) if 'label2' in parameters: AtlasStyle.myText(0.55, 0.24, ROOT.kBlack, parameters['label2'], 0.038) save_as(canvas, BasicConfig.plotdir + parameters['plot_name'] + '_' + str(date.today()))
def create_toc_plot(passed, total, parameters): print('') print('*** start create_toc_plot') canvas = ROOT.TCanvas("c", "c", 1000, 600) if 'rebin' in parameters: passed.Rebin(parameters['rebin']) total.Rebin(parameters['rebin']) tg = ROOT.TGraphAsymmErrors(passed, total) tg.GetXaxis().SetRangeUser(0, 400) tg.GetYaxis().SetTitle('Efficiency') if 'x_title' in parameters: tg.GetXaxis().SetTitle(parameters['x_title']) tg.Draw('AP') AtlasStyle.ATLASLabel(0.50, 0.4, 'Work in Progress') AtlasStyle.myText(0.55, 0.32, ROOT.kBlack, parameters['label'], 0.038) if 'label2' in parameters: AtlasStyle.myText(0.55, 0.24, ROOT.kBlack, parameters['label2'], 0.038) save_as( canvas, BasicConfig.plotdir + parameters['plot_name'] + '_' + str(date.today()))
def draw_atlas_details(labels=[], x_pos=0.2, y_pos=0.87, dy=0.04 * 0.9, text_size=0.035 * 0.9, sampleName="", height=1.0, isSimulation=True): if sampleName != "": sampleName = ", " + c.samples[sampleName]["Name"] text_size = text_size / height dy = dy / height if not isSimulation: AS.ATLASLabel(x_pos, y_pos, 1, 0.1, text_size, "Internal") else: AS.ATLASLabel(x_pos, y_pos, 1, 0.1, text_size, "Simulation Internal") y_pos -= dy AS.myText(x_pos, y_pos, 1, text_size, "#sqrt{s} = 13 TeV %s" % (sampleName)) y_pos -= dy for label in labels: AS.myText(x_pos, y_pos, 1, text_size, "%s" % label) y_pos -= dy
def MultipleFlatEffCurve(outputName, approachList, bins, binslong,flav = "L"): markerlist = [21, 8 , 22, 23, 29, 34] fout = ROOT.TFile(outputName, "recreate") fout.cd() Canv = ROOT.TCanvas("EffComb", "EffComb", 0, 800, 0, 800) Canv.cd() EffCurves = [] for scoreList, varList, label, scoreCutList in approachList: heff = getFixEffCurve(scoreList, varList, label, binslong, fix_eff_target=0.7, scoreCutList=scoreCutList, onlyReturnCutList=False) EffCurves.append(heff) legend = ROOT.TLegend(0.5, 0.5, 0.75, 0.75) legend_rel = ROOT.TLegend(0.5, 0.5, 0.75, 0.75) ROCs = [] mg = ROOT.TMultiGraph() for i in range(len(EffCurves)): ROC = ConvertEffToGraph(EffCurves[i],bins, False) ROC.SetLineWidth(2) ROC.SetLineColor(colorlist[i]) ROC.SetMarkerColor(colorlist[i]) ROC.SetMarkerSize(1) ROC.SetMarkerStyle(markerlist[i]) ROC.SetLineStyle(i+1) mg.Add(ROC) legend.AddEntry(ROC, approachList[i][2][1], "lp") ROCs.append(ROC) mg.Draw("AP") mg.GetXaxis().SetTitle("b-jet p_{T} [GeV]") if flav == "L": mg.GetYaxis().SetTitle("light-jet Rejection, 1/#varepsilon_{l}") if flav == "C": mg.GetYaxis().SetTitle("c-jet Rejection, 1/#varepsilon_{c}") legend.Draw("same") Atlas.ATLASLabel(0.2, 0.88,0.13, "Simulation Internal",color=1) Atlas.myText(0.2, 0.81 ,color=1, size=0.04,text="#sqrt{s}=13 TeV, t#bar{t}") Atlas.myText(0.2, 0.75 ,color=1, size=0.04,text="p_{T}>20 GeV, |#eta|<2.5") Atlas.myText(0.2, 0.69 ,color=1, size=0.04,text="Flat 70% b-tagging WP") Canv.Write() fout.Close()
def DrawCorrelation(var, labels, model, varname): f = ROOT.TFile("corr_"+varname+".root", "recreate") #b_hist = ROOT.TH1D("corr_score_b_"+varname, "corr_score_b_"+varname, 15, 0.5, 15.5) #c_hist = ROOT.TH1D("corr_score_c_"+varname, "corr_score_c_"+varname, 15, 0.5, 15.5) #l_hist = ROOT.TH1D("corr_score_l_"+varname, "corr_score_l_"+varname, 15, 0.5, 15.5)# bjet_var = var[ labels[:,0]==5] cjet_var = var[ labels[:,0]==4] ljet_var = var[ labels[:,0]==0] bjet_score = model.pred[labels[:,0]==5] cjet_score = model.pred[labels[:,0]==4] ljet_score = model.pred[labels[:,0]==0] def loop(var, score): print var.shape print score.shape itrk_list = [] corr_list = [] for itrk in range(15): var_thistrk = [] score_thistrk = [] score_thistrk = score[ var[:, itrk] !=0 ] var_thistrk = var[ var[:, itrk] !=0, itrk] #hist.SetBinContent(itrk+1, pearsonr(var_thistrk, score_thistrk)[0] ) print pearsonr(var_thistrk, score_thistrk)[0] itrk_list.append(itrk+1) corr_list.append(pearsonr(var_thistrk, score_thistrk)[0] ) return ROOT.TGraph(15, array.array('d', itrk_list), array.array('d', corr_list)) b_hist= loop(bjet_var, bjet_score) c_hist = loop(cjet_var, cjet_score) l_hist = loop(ljet_var, ljet_score) f.cd() canvas = ROOT.TCanvas(varname, varname, 800, 600) canvas.cd() b_hist.SetLineColor( colorind[0]) b_hist.SetMarkerColor( colorind[0]) b_hist.SetMarkerStyle(20) b_hist.SetMarkerSize(1) b_hist.SetLineWidth( 3) c_hist.SetLineColor( colorind[1]) c_hist.SetMarkerColor( colorind[1]) c_hist.SetLineWidth( 3) c_hist.SetMarkerStyle(21) c_hist.SetMarkerSize(1) l_hist.SetLineColor( colorind[2]) l_hist.SetMarkerColor( colorind[2]) l_hist.SetLineWidth( 3) l_hist.SetMarkerStyle(22) l_hist.SetMarkerSize(1) legend = ROOT.TLegend(0.5, 0.5, 0.75, 0.75) legend.AddEntry(b_hist, "b-jets", "lp") legend.AddEntry(c_hist, "c-jets", "lp") legend.AddEntry(l_hist, "light-jets", "lp") mg = ROOT.TMultiGraph() mg.Add(b_hist) mg.Add(c_hist) mg.Add(l_hist) mg.Draw("APL") mg.GetXaxis().SetTitle("i^{th} track in sequence") mg.GetYaxis().SetTitle("Correlation, #rho(D_{RNN}, "+varname+")") legend.Draw("same") Atlas.ATLASLabel(0.2, 0.88,0.13, "Simulation Internal",color=1) Atlas.myText(0.2, 0.81 ,color=1, size=0.04,text="#sqrt{s}=13 TeV, t#bar{t}") Atlas.myText(0.2, 0.75 ,color=1, size=0.04,text="p_{T}>20 GeV, |#eta|<2.5") canvas.Draw() canvas.Write()
pad2.Draw() pad1.cd() # drawing plots if (NPlots == 0): histo.Draw("HIST") else: histo.Draw("Same HIST") c.Update() # legend legend.AddEntry(histo,LegendEntryList[NPlots],"l") legend.Draw("Same") # ATLAS Style Setting AtlasStyle.ATLAS_LABEL(0.5, 0.85, internal = ATLAS_Internal, preliminary = ATLAS_Preliminary, color=1) AtlasStyle.myText(0.5, 0.8, 1, "#sqrt{s} = 13 TeV") # create ratio plots in pad2 if (EnableHistoCombination & EnableRatioPlots): ## save reference plot, i.e. NPlots == 0 if (NPlots == 0): refHisto = histo ## else plot ratio histos else: # change to pad2 pad2.cd() pad2.SetLogy(False) ## create and setup histoRatio histoRatio=histo.Clone()
def plot_upper_limit(sum_xsecs, uls, masses, UL_label, outputfile=None): xmin = 350 xmax = 800 ymin = 0.9 ymax = 500 pad_title = "NUHM2: m_{0}=5 TeV, A_{0}=-1.6m_{0}, tan#beta=15, #mu=150 GeV, m_{A}=1 TeV" x_title = "m_{1/2} [GeV]" y_title = "#sigma_{NUHM2} (#font[12]{pp #rightarrow #tilde{#chi}^{0}_{2}#tilde{#chi}^{#pm}_{1}, #tilde{#chi}^{0}_{2}#tilde{#chi}^{0}_{1}, #tilde{#chi}^{#pm}_{1}#tilde{#chi}^{#pm}_{1}}) [pb]" titles = pad_title + ";" + x_title + ";" + y_title # TGraph gul_obs = ROOT.TGraph() gul_exp = ROOT.TGraph() gul_exp1s = ROOT.TGraphAsymmErrors() gul_exp2s = ROOT.TGraphAsymmErrors() g_xsec = ROOT.TGraph() g_xsec_up = ROOT.TGraph() g_xsec_down = ROOT.TGraph() # Fill the TGraph n = len(uls) # n = 6, from 350 m = len(sum_xsecs) # m = 7, from 300 for i in range(0, n): # j = i + 1 # i starts from 350 but j starts from 300 # print 'm12=', uls[i]['m12'], 'mu_SIG=', uls[i]['ul_obs'], 'xsec=', sum_xsecs[j]['sum_xsec'], 'xsec*mu_SIG=', uls[i]['ul_obs'] * sum_xsecs[j]['sum_xsec'] for j in range(0, m): if uls[i]['m12'] == sum_xsecs[j]['m12']: gul_obs.SetPoint(i, uls[i]['m12'], uls[i]['ul_obs'] * sum_xsecs[j]['sum_xsec']) gul_exp.SetPoint(i, uls[i]['m12'], uls[i]['ul_exp'] * sum_xsecs[j]['sum_xsec']) eyl_1s = abs((uls[i]['ul_expm1s'] - uls[i]['ul_exp']) * sum_xsecs[j]['sum_xsec']) eyh_1s = abs((uls[i]['ul_expp1s'] - uls[i]['ul_exp']) * sum_xsecs[j]['sum_xsec']) gul_exp1s.SetPoint(i, uls[i]['m12'], uls[i]['ul_exp'] * sum_xsecs[j]['sum_xsec']) gul_exp1s.SetPointError(i, 0., 0., eyl_1s, eyh_1s) eyl_2s = abs((uls[i]['ul_expm2s'] - uls[i]['ul_exp']) * sum_xsecs[j]['sum_xsec']) eyh_2s = abs((uls[i]['ul_expp2s'] - uls[i]['ul_exp']) * sum_xsecs[j]['sum_xsec']) gul_exp2s.SetPoint(i, uls[i]['m12'], uls[i]['ul_exp'] * sum_xsecs[j]['sum_xsec']) gul_exp2s.SetPointError(i, 0., 0., eyl_2s, eyh_2s) for j in range(0, m): g_xsec.SetPoint(j, sum_xsecs[j]['m12'], sum_xsecs[j]['sum_xsec']) g_xsec_up.SetPoint(j, sum_xsecs[j]['m12'], sum_xsecs[j]['sum_xsec_up']) g_xsec_down.SetPoint(j, sum_xsecs[j]['m12'], sum_xsecs[j]['sum_xsec_down']) # Set the TGraph color_obs = ROOT.TColor.GetColor("#aa000") color_exp = ROOT.TColor.GetColor("#28373c") color_yellow = ROOT.TColor.GetColor("#ffe938") gul_obs.SetLineStyle(1) gul_exp.SetLineStyle(7) gul_exp1s.SetLineStyle(1) gul_exp2s.SetLineStyle(1) g_xsec.SetLineStyle(1) g_xsec_up.SetLineStyle(2) g_xsec_down.SetLineStyle(2) gul_obs.SetLineColor(color_obs) gul_exp.SetLineColor(color_exp) gul_exp1s.SetLineColor(ROOT.kGreen) gul_exp2s.SetLineColor(color_yellow) g_xsec.SetLineColor(ROOT.kBlue) g_xsec_up.SetLineColor(ROOT.kBlue) g_xsec_down.SetLineColor(ROOT.kBlue) gul_obs.SetLineWidth(4) gul_exp.SetLineWidth(3) gul_exp1s.SetLineWidth(2) gul_exp2s.SetLineWidth(2) g_xsec.SetLineWidth(2) g_xsec_up.SetLineWidth(2) g_xsec_down.SetLineWidth(2) gul_exp1s.SetFillStyle(1001) gul_exp2s.SetFillStyle(1001) gul_exp1s.SetFillColor(ROOT.kGreen) gul_exp2s.SetFillColor(color_yellow) leg = ROOT.TLegend(0.52, 0.65, 0.87, 0.87) leg.AddEntry( g_xsec, "pp #rightarrow #tilde{#chi}^{0}_{2}#tilde{#chi}^{#pm}_{1}, #tilde{#chi}^{0}_{2}#tilde{#chi}^{0}_{1}, #tilde{#chi}^{#pm}_{1}#tilde{#chi}^{#pm}_{1}", "l") leg.AddEntry(g_xsec_up, "Theoretical uncertainty", "l") leg.AddEntry(gul_exp, "Expected limit", "l") leg.AddEntry(gul_obs, "Observed limit", "l") leg.AddEntry(gul_exp1s, "Expected #pm 1#sigma_{exp}", "f") leg.AddEntry(gul_exp2s, "Expected #pm 2#sigma_{exp}", "f") leg.SetBorderSize(0) leg.SetTextFont(42) leg.SetTextSize(0.03) leg.SetFillColor(0) leg.SetFillStyle(0) # TGraph # g_dm = ROOT.TGraph() # x: m12, y: dm # for i in range(0, len(masses)): # g_dm.SetPoint(i, masses[i]['m12'], masses[i]['dm']) # print g_dm.Eval(350), g_dm.Eval(400), g_dm.Eval(500), g_dm.Eval(600), g_dm.Eval(700), g_dm.Eval(800) g_m12 = ROOT.TGraph() # x: dm, y: m12 for i in range(0, len(masses)): g_m12.SetPoint(i, masses[i]['dm'], masses[i]['m12']) # print g_m12.Eval(20), g_m12.Eval(25), g_m12.Eval(30), g_m12.Eval(35), g_m12.Eval(40), g_m12.Eval(45) c = ROOT.TCanvas("c", "Upper limit", 600, 800) ROOT.gStyle.SetOptStat(0) right_margin = 0.05 left_margin = 0.13 # Upper plot will be in pad1 pad1 = ROOT.TPad("pad1", "pad1", 0, 0.15, 1, 0.98) pad1.SetTopMargin(0.08) pad1.SetBottomMargin(0.15) pad1.SetRightMargin(right_margin) pad1.SetLeftMargin(left_margin) # pad1.SetFillColor(42) # pad1->SetGridy() # grid lines pad1.Draw() # lower plot will be in pad pad2 = ROOT.TPad("pad2", "pad2", 0, 0.02, 1, 0.15) pad2.SetTopMargin(0.05) pad2.SetBottomMargin(0.3) pad2.SetRightMargin(right_margin) pad2.SetLeftMargin(left_margin) # pad2.SetFillColor(16) # pad2.SetGridy() # grid lines pad2.Draw() pad1.cd() pad1.SetLogy() pad1.SetTickx() pad1.SetTicky() frame1 = pad1.DrawFrame(xmin, ymin, xmax, ymax, titles) frame1.GetXaxis().SetTitleOffset(1.15) frame1.GetXaxis().SetTitleSize(0.045) frame1.GetXaxis().SetLabelOffset(0.015) frame1.GetXaxis().SetLabelSize(0.03) frame1.GetYaxis().SetTitleOffset(1.3) frame1.GetYaxis().SetTitleSize(0.045) frame1.GetYaxis().SetLabelOffset(0.015) frame1.GetYaxis().SetLabelSize(0.03) gul_exp2s.Draw("L3") gul_exp1s.Draw("L3") gul_obs.Draw("L") gul_exp.Draw("L") g_xsec.Draw("L") g_xsec_up.Draw("L") g_xsec_down.Draw("L") leg.Draw() # AtlasStyle.ATLASLabel(0.18, 0.80, "Internal", ROOT.kBlack) AtlasStyle.myText(0.18, 0.73, "#sqrt{s} = 13 TeV, 36.1 fb^{-1}", ROOT.kBlack, 0.04) AtlasStyle.myText(0.61, 0.62, "All limits at 95% CL", ROOT.kBlack, 0.03) AtlasStyle.myText(0.61, 0.585, "ee/#mu#mu, m_{#font[12]{l}#font[12]{l}} shape fit", ROOT.kBlack, 0.03) AtlasStyle.myText( 0.61, 0.54, "#tilde{#chi}^{0}_{2} #rightarrow Z* #tilde{#chi}^{0}_{1}, #tilde{#chi}^{#pm}_{1} #rightarrow W* #tilde{#chi}^{0}_{1}", ROOT.kBlack, 0.03) if UL_label: label = ROOT.TLatex() label.SetTextFont(42) label.SetTextSize(0.024) label.SetTextColor(ROOT.kGray + 2) label.SetTextAngle(45) # label.SetNDC() for i in range(0, n): # n = len(uls) for j in range(0, m): if uls[i]['m12'] == sum_xsecs[j]['m12']: x_value = uls[i]['m12'] y_value = uls[i]['ul_obs'] * sum_xsecs[j]['sum_xsec'] label_text = '{:04.2f}'.format(y_value) if x_value == 350: x_value += 10 if x_value == 800: x_value -= 15 label.DrawLatex(x_value, y_value + 0.5, label_text) # 1 and 2 sigma bands cover the y ticks. # we need to redraw the axis to show the ticks pad1.Update() pad1.RedrawAxis() # Draw the dm axis on pad2 pad2.cd() # Draw an axis without ticks and labels. # This is used for a axis line and title only gaxis = ROOT.TGaxis(left_margin, 0.7, 1 - right_margin, 0.7, 0, 1, 0, "") gaxis.SetTitle("m_{#tilde{#chi}^{0}_{2}} - m_{#tilde{#chi}^{0}_{1}} [GeV]") gaxis.SetTitleFont(42) gaxis.SetTitleSize(0.28) gaxis.SetLabelFont(42) gaxis.SetLabelSize(0) gaxis.SetTickLength(0) gaxis.SetLineWidth(2) gaxis.Draw() # Make ticks and labels by myself l_tick_left = ROOT.TLine(left_margin, 0.7, left_margin, 0.85) l_tick_left.SetLineWidth(2) l_tick_left.Draw() l_tick_right = ROOT.TLine(1 - right_margin, 0.7, 1 - right_margin, 0.85) l_tick_right.SetLineWidth(2) l_tick_right.Draw() # Ticks # g_m12.Eval(350) = 46.057022 # g_m12.Eval(400) = 38.168159 # g_m12.Eval(500) = 28.016555 # g_m12.Eval(600) = 22.049652 # g_m12.Eval(700) = 18.192032 # g_m12.Eval(800) = 15.495697 # So the small ticks from 16 to 45 list_ticks = [] list_labels = [] for tick in [ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45 ]: tick_x_value = left_margin + (g_m12.Eval(tick) - 350.) / ( 800. - 350.) * (1 - right_margin - left_margin) if tick in [20, 25, 30, 35, 40, 45]: l_tick = ROOT.TLine(tick_x_value, 0.7, tick_x_value, 0.85) tick_label = ROOT.TLatex(tick_x_value - 0.01, 0.48, str(tick)) tick_label.SetTextFont(42) tick_label.SetTextSize(0.2) list_labels.append(tick_label) else: l_tick = ROOT.TLine(tick_x_value, 0.7, tick_x_value, 0.78) list_ticks.append(l_tick) for tick in list_ticks: tick.Draw() for tick_label in list_labels: tick_label.Draw() if outputfile is None: c.SaveAs("nuhm2_UL.pdf") else: c.SaveAs(outputfile)
def make_time_rod_evo(error_dict, rod_dict, results, doLock): c2 = TCanvas( 'c2', 'c2', 1000, 600) leg = TLegend(0.18,0.85,0.45,0.55) leg.SetLineColor(0) leg.SetFillStyle(0) leg.SetShadowColor(0) leg.SetBorderSize(0) leg.SetNColumns(2) R15 = TLine(431,0,431,60) R15.SetLineColorAlpha(kPink+10,0.4) R15.SetLineWidth(4) R16 = TLine(1820,0,1820,60) R16.SetLineColorAlpha(kMagenta+10,0.4) R16.SetLineWidth(4) R17 = TLine(3376,0,3376,60) R17.SetLineColorAlpha(kGreen-3,0.4) R17.SetLineWidth(4) TS1 = TLine(431,0,432,60) TS1.SetLineColorAlpha(kPink+10,0.5) TS1.SetLineWidth(5) TS2 = TLine(1415,0,1415,60) TS2.SetLineColorAlpha(kMagenta+3,0.5) TS2.SetLineWidth(5) leg2 = TLegend(0.18,0.45,0.35,0.55) leg2.SetLineColor(0) leg2.SetFillStyle(0) leg2.SetShadowColor(0) leg2.SetBorderSize(0) gStyle.SetLegendTextSize(0.030) leg2.AddEntry(R15, "End of 2015", 'lf') leg2.AddEntry(R16, "End of 2016", 'lf') leg2.AddEntry(R17, "End of 2017", 'lf') #leg2.AddEntry(TS2, "TS2", 'lf') for key,val in rod_dict.items(): TS1.SetY2(val*0.5) TS2.SetY2(val+1) R15.SetY2(val*0.3) R16.SetY2(val*0.5) R17.SetY2(val*0.8) times = {} times.clear() for e in error_bits: times['0x'+e] = [0] for error in results: pos_rod = error.text.find("ROD") + 4 pos_lock = error.text.find("Lock") + 15 pos_buff = error.text.find("buffer") + 17 if error.msgID == 'TRT::ROD05Module': rod = '0x'+str(error.text[pos_rod:pos_rod+6]) else: rod = str(error.text[pos_rod:pos_rod+8]) lock = str(error.text[pos_lock:pos_lock+3]) buff = str(error.text[pos_buff:pos_buff+3]) if key == rod and doLock and lock != '0xf': times[lock].append(error.sb_total_time) leg.Clear() mg = TMultiGraph() for e in error_bits: errs = [] for i,x in enumerate(times['0x'+e]): errs.append(i+0.0) errs.append(errs[-1]) #times['0x'+e].append(1800.0) times['0x'+e].append(results[-1].sb_total_time) gr = TGraph(len(times['0x'+e]), array(times['0x'+e]), array(errs)) gr.SetMarkerSize(0.7) if bin(int('0x'+e, 16))[2:].zfill(4) == '0111': leg.AddEntry(gr,'GOL 3',"lp"); elif bin(int('0x'+e, 16))[2:].zfill(4) == '1011': leg.AddEntry(gr,'GOL 2',"lp"); elif bin(int('0x'+e, 16))[2:].zfill(4) == '1101': leg.AddEntry(gr,'GOL 1',"lp"); elif bin(int('0x'+e, 16))[2:].zfill(4) == '1110': leg.AddEntry(gr,'GOL 0',"lp"); else: leg.AddEntry(gr,bin(int('0x'+e, 16))[2:].zfill(4),"lp"); mg.Add(gr,"pl"); mg.SetTitle("; Hours of stable beams; # of rocketio io lock errors"); mg.Draw("PMC PLC a"); R15.Draw() R16.Draw() R17.Draw() #TS1.Draw() #TS2.Draw() AtlasStyle.ATLAS_LABEL(0.19,.88, 1, "Internal") leg.Draw() leg2.Draw() AtlasStyle.myText(0.4, 0.88, kBlack, "ROD: " + key) leg.SetMargin(0.5) gPad.Modified() mg.GetXaxis().SetLimits(0,results[-1].sb_total_time) mg.SetMinimum(0.) mg.SetMaximum(val+1) c2.Update() c2.Print("plots/time_"+key+".pdf") c2.Clear()
def getROC( signal, background, label, cut_start=None, cut_end=None, outputName="myROC.root", Rejection="l", omission = []): ROCList = [] markerlist = [21, 8 , 22, 23] print "get roc ", label for ivar in range(len(signal)): s_sort = np.sort( signal[ivar] ) b_sort = np.sort( background[ivar] ) #c_start=(0.0 if cut_start==None else cut_start) #c_end= (1.0 if cut_end==None else cut_end) print s_sort, b_sort for i in range(s_sort.shape[0]): if s_sort[i] == float("Inf"): s_sort[i] = 100000 if s_sort[i] == float("-Inf"): s_sort[i] = -1000000 for i in range(b_sort.shape[0]): if b_sort[i] == float("Inf"): b_sort[i] = 100000 if b_sort[i] == float("-Inf"): b_sort[i] = -1000000 c_start=np.min( (s_sort[0], b_sort[0]) ) c_end= np.max( (s_sort[len(s_sort)-1], b_sort[len(b_sort)-1]) ) if c_start==-float('inf'): c_start = -2*c_end print label[ivar], "min(", s_sort[0], b_sort[0], ")=", c_start print label[ivar], "max(", s_sort[-1], b_sort[-1], ")=", c_end s_eff=[] b_rej=[] n_points = 1000 c_delta = (1.0*c_end - 1.0*c_start) / (1.0*n_points) for i in range(1000): cut = c_start + i*1.0*c_delta s_eff.append( 1.0*np.count_nonzero( s_sort > cut ) / (1.0*len(s_sort)) ) b_count = np.count_nonzero( b_sort > cut ) b_rej.append( (1.0*len(b_sort)) / (1.0 if b_count==0 else (1.0*b_count)) ) ROC = ROOT.TGraph(n_points, array.array('d', s_eff), array.array('d', b_rej)) ROC.SetName("ROC_%i" % (ivar)) ROCList.append(ROC) f = ROOT.TFile(outputName, "update") canvas = ROOT.TCanvas("ROC_Overlay", "ROC_Overlay", 800, 600) canvas.cd() mg = ROOT.TMultiGraph() legend = ROOT.TLegend(0.5, 0.5, 0.75, 0.75) for i in range(len(ROCList)): if i in omission: continue ROC = ROCList[i] ROC.SetLineWidth(3) ROC.SetLineColor(colorlist[i]) ROC.SetMarkerColor(colorlist[i]) ROC.SetMarkerSize(0) ROC.SetMarkerStyle(0) ROC.SetLineStyle(i+1) mg.Add(ROC) if omission == []: legend.AddEntry(ROC, label[i], "lp") f.WriteTObject(ROC, "ROC_"+label[i], "Overwrite") if omission!=[]: legend.AddEntry(ROCList[1], label[1], "lp") legend.AddEntry(ROCList[4], label[4], "lp") legend.AddEntry(ROCList[5], label[5], "lp") legend.AddEntry(ROCList[2], label[2], "lp") mg.Draw("AL") mg.GetXaxis().SetTitle("b-jet efficiency, #varepsilon_{b}") if Rejection == "l": mg.GetYaxis().SetTitle("light-jet rejection, 1/#varepsilon_{l}") if Rejection == "c": mg.GetYaxis().SetTitle("c-jet rejection, 1/#varepsilon_{c}") legend.Draw("same") Atlas.ATLASLabel(0.2, 0.88,0.13, "Simulation Internal",color=1) Atlas.myText(0.2, 0.81 ,color=1, size=0.04,text="#sqrt{s}=13 TeV, t#bar{t}") Atlas.myText(0.2, 0.75 ,color=1, size=0.04,text="p_{T}>20 GeV, |#eta|<2.5") #Atlas.myText(0.2, 0.69 ,color=1, size=0.04,text="Rel21") #canvas.Update() canvas.Draw() f.WriteTObject(canvas, canvas.GetName(), "Overwrite") f.Close() return (ROCList, canvas)
def plot_N_minus_one_distribution_in_SR(m12, varexp, lep_EEOS, lep_MMOS): # signal h_nuhm2 = get_N_minus_one_histogram( path + files['sigFile'], "MGPy8EG_A14N23LO_NUHM2_m12_" + str(m12) + "_weak_NoSys", varexp, lep_EEOS, lep_MMOS) h_nuhm2.SetLineColor(ROOT.kRed) h_nuhm2.SetLineWidth(2) # h_nuhm2.SetFillColor(ROOT.kRed) integral_nuhm2 = h_nuhm2.Integral() # data h_data = get_N_minus_one_histogram(path + files['dataFile'], "data", varexp, lep_EEOS, lep_MMOS) # bkg h_diboson = get_N_minus_one_histogram(path + files['dibosonFile'], "diboson_NoSys", varexp, lep_EEOS, lep_MMOS) h_fakes = get_N_minus_one_histogram(path + files['fakesFile'], "fakes_NoSys", varexp, lep_EEOS, lep_MMOS) h_other = get_N_minus_one_histogram(path + files['otherFile'], "other_NoSys", varexp, lep_EEOS, lep_MMOS) h_top = get_N_minus_one_histogram(path + files['topFile'], "top_NoSys", varexp, lep_EEOS, lep_MMOS) h_Zttjets = get_N_minus_one_histogram(path + files['ZttjetsFile'], "Zttjets_NoSys", varexp, lep_EEOS, lep_MMOS) h_data.SetLineColor(ROOT.kBlack) h_data.SetMarkerColor(ROOT.kBlack) h_data.SetMarkerStyle(ROOT.kFullCircle) h_data.SetMarkerSize(1.5) integral_data = h_data.Integral() h_diboson.SetLineColor(ROOT.kOrange + 1) h_diboson.SetFillColor(ROOT.kOrange + 1) h_diboson.SetFillStyle(1001) integral_diboson = h_diboson.Integral() h_fakes.SetLineColor(18) h_fakes.SetFillColor(18) h_fakes.SetFillStyle(1001) integral_fakes = h_fakes.Integral() h_other.SetLineColor(ROOT.kYellow - 9) h_other.SetFillColor(ROOT.kYellow - 9) h_other.SetFillStyle(1001) integral_other = h_other.Integral() h_top.SetLineColor(ROOT.kAzure + 7) h_top.SetFillColor(ROOT.kAzure + 7) h_top.SetFillStyle(1001) integral_top = h_top.Integral() h_Zttjets.SetLineColor(ROOT.kGreen + 2) h_Zttjets.SetFillColor(ROOT.kGreen + 2) h_Zttjets.SetFillStyle(1001) integral_Zttjets = h_Zttjets.Integral() hstack = ROOT.THStack() hstack.Add(h_other) hstack.Add(h_diboson) hstack.Add(h_Zttjets) hstack.Add(h_top) hstack.Add(h_fakes) h_SM = h_diboson.Clone() h_SM.Reset() h_SM.Add(h_diboson) h_SM.Add(h_fakes) h_SM.Add(h_other) h_SM.Add(h_top) h_SM.Add(h_Zttjets) h_SM.SetLineColor(ROOT.kGray + 3) h_SM.SetFillColor(ROOT.kGray + 3) h_SM.SetFillStyle(0) integral_SM = h_SM.Integral() h_SM_err = h_SM.Clone() h_SM_err.SetLineColor(ROOT.kGray + 3) h_SM_err.SetFillColor(ROOT.kGray + 3) h_SM_err.SetMarkerColor(ROOT.kGray + 3) h_SM_err.SetFillStyle(3004) # Set error of SM to stat + 20% syst for i in range(0, h_SM.GetXaxis().GetNbins() + 1): stat = h_SM.GetBinError(i) syst = h_SM.GetBinContent(i) error = math.sqrt(stat * stat + (syst * 0.2) * (syst * 0.2)) h_SM.SetBinError(i, error) # Making plot c1 = ROOT.TCanvas("c1", "", 800, 800) ROOT.gStyle.SetOptStat(0) # gStyle->SetOptFit(1111) # Upper plot will be in pad1 pad1 = ROOT.TPad("pad1", "pad1", 0, 0.35, 1, 1.0) pad1.SetBottomMargin(0.05) pad1.SetRightMargin(0.05) pad1.SetLeftMargin(0.16) # pad1->SetGridy() # grid lines pad1.Draw() # lower plot will be in pad pad2 = ROOT.TPad("pad2", "pad2", 0, 0.05, 1, 0.35) pad2.SetTopMargin(0.05) pad2.SetBottomMargin(0.3) pad2.SetRightMargin(0.05) pad2.SetLeftMargin(0.16) # pad2.SetGridy() # grid lines pad2.Draw() # # pad1: top pad # pad1.cd() # pad1 becomes the current pad # pad1.SetFrameLineWidth(2) hstack.Draw("hist") # need to draw first, otherwise cannot GetHistogram() hstack.GetHistogram().SetStats(0) # hstack.SetMinimum(0.) hstack.SetMaximum(h_SM.GetMaximum() * 2.6) hstack.GetHistogram().SetXTitle("") # suppress Xtitle if varexp == "met_Et": hstack.GetXaxis().SetRangeUser(0, 600) elif varexp == "lep1Pt" or varexp == "lep2Pt": hstack.GetXaxis().SetRangeUser(0, 60) hstack.GetXaxis().SetLabelSize(0) hstack.GetHistogram().SetYTitle(h_data.GetYaxis().GetTitle()) hstack.GetYaxis().SetLabelSize(0.04) hstack.GetYaxis().SetLabelOffset(0.015) hstack.GetYaxis().SetTitleSize(0.05) hstack.GetYaxis().SetTitleOffset(1.3) hstack.Draw("hist") # re-draw to make the changes working hstack.Draw("hist") h_SM.Draw("hist,same") h_SM_err.Draw("E2,same") h_data.Draw("E,same") h_nuhm2.Scale(10.) # multiply by 10 on the Nsig because Nsig is to small h_nuhm2.Draw("hist,same") x1, x2, dx = 0., 0., 0. if varexp == "met_Et": x1 = 200. dx = h_SM.GetXaxis().GetXmax() * 0.1 elif varexp == "nBJet20_MV2c10": x1 = 1. dx = -1 * h_SM.GetXaxis().GetXmax() * 0.1 elif varexp == "DPhiJ1Met": x1 = 2. dx = h_SM.GetXaxis().GetXmax() * 0.1 elif varexp == "minDPhiAllJetsMet": x1 = 0.5 dx = h_SM.GetXaxis().GetXmax() * 0.1 elif varexp == "mt_lep1": x1 = 70. dx = -1 * h_SM.GetXaxis().GetXmax() * 0.1 elif varexp == "MTauTau": x1 = 0. dx = -1 * h_SM.GetXaxis().GetXmax() * 0.1 x2 = 160. elif varexp == "Rll": x1 = 2. dx = -1 * h_SM.GetXaxis().GetXmax() * 0.1 elif varexp == "METOverHTLep": x1 = 5. dx = h_SM.GetXaxis().GetXmax() * 0.1 if (varexp != 'nJet30' and varexp != 'lep1Pt' and varexp != 'lep2Pt' and varexp != 'mll'): v_line_y = h_SM.GetMaximum() * 1.3 v_line1 = ROOT.TLine(x1, 0., x1, v_line_y) v_line1.SetLineWidth(3) v_line1.SetLineColor(ROOT.kBlack) v_line1.Draw() v_arrow1 = ROOT.TArrow(x1, v_line_y, x1 + dx, v_line_y, 0.03, "|>") v_arrow1.SetLineColor(ROOT.kBlack) v_arrow1.SetLineWidth(3) v_arrow1.SetFillColor(ROOT.kBlack) v_arrow1.SetFillStyle(1001) v_arrow1.Draw() v_line2, v_arror2 = None, None if varexp == "MTauTau": v_line2 = ROOT.TLine(x2, 0., x2, v_line_y) v_line2.SetLineWidth(3) v_line2.SetLineColor(ROOT.kBlack) v_line2.Draw() v_arrow2 = ROOT.TArrow(x2, v_line_y, x2 - dx, v_line_y, 0.03, "|>") v_arrow2.SetLineColor(ROOT.kBlack) v_arrow2.SetLineWidth(3) v_arrow2.SetFillColor(ROOT.kBlack) v_arrow2.SetFillStyle(1001) v_arrow2.Draw() AtlasStyle.ATLASLabel(0.2, 0.83, "Internal", ROOT.kBlack) AtlasStyle.myText(0.2, 0.78, "13 TeV, 36.1 fb^{-1}", ROOT.kBlack, 0.04) if lep_EEOS is True and lep_MMOS is False: AtlasStyle.myText(0.2, 0.75, "SRee-iMLLg ee", ROOT.kBlack, 0.02) if lep_MMOS is True and lep_EEOS is False: AtlasStyle.myText(0.2, 0.75, "SRmm-iMLLg #mu#mu", ROOT.kBlack, 0.02) if lep_EEOS is True and lep_MMOS is True: AtlasStyle.myText(0.2, 0.75, "SRee-iMLLg ee + SRmm-iMLLg #mu#mu", ROOT.kBlack, 0.02) AtlasStyle.myText(0.2, 0.72, "SusySkimHiggsino v1.9b", ROOT.kGray, 0.02) legend_nuhm2 = "NUHM2 m12={0} ({1:.2f})".format(m12, integral_nuhm2) legend_data = "Data ({0:.1f} Events)".format(integral_data) legend_SM = "SM stat #oplus 20% syst ({0:.1f})".format(integral_SM) legend_fakes = "Fake leptons ({0:.1f}%)".format(integral_fakes / integral_SM * 100) legend_top = 't#bar{t}& Single top ' + "({0:.1f}%)".format( integral_top / integral_SM * 100) legend_Zttjets = "Z(#rightarrow#tau#tau)+jets ({0:.1f}%)".format( integral_Zttjets / integral_SM * 100) legend_diboson = "Diboson ({0:.1f}%)".format(integral_diboson / integral_SM * 100) legend_other = "Others ({0:.1f}%)".format(integral_other / integral_SM * 100) legend = ROOT.TLegend(0.6, 0.5, 0.9, 0.87) legend.AddEntry(h_nuhm2, legend_nuhm2, "l") legend.AddEntry(h_data, legend_data, "pl") legend.AddEntry(h_SM_err, legend_SM, "fl") legend.AddEntry(h_fakes, legend_fakes, "f") legend.AddEntry(h_top, legend_top, "f") legend.AddEntry(h_Zttjets, legend_Zttjets, "f") legend.AddEntry(h_diboson, legend_diboson, "f") legend.AddEntry(h_other, legend_other, "f") legend.SetBorderSize(0) legend.SetTextFont(42) legend.SetTextSize(0.03) legend.SetFillColor(0) legend.SetFillStyle(0) legend.Draw() # # pad2: bottom pad # pad2.cd() # pad2 becomes the current pad pad2_X_min = h_data.GetXaxis().GetXmin() pad2_X_max = h_data.GetXaxis().GetXmax() if varexp == "met_Et": pad2_X_max = 600. elif varexp == "lep1Pt" or varexp == "lep2Pt": pad2_X_max = 60. pad2_Y_min = 0. pad2_Y_max = 2. pad2_X_title = h_data.GetXaxis().GetTitle() pad2_Y_title = "Data / SM" frame = pad2.DrawFrame(pad2_X_min, pad2_Y_min, pad2_X_max, pad2_Y_max) frame.GetXaxis().SetNdivisions(510) frame.GetYaxis().SetNdivisions(405) frame.SetLineWidth(1) frame.SetXTitle(pad2_X_title) frame.GetXaxis().SetTitleSize(25) frame.GetXaxis().SetTitleFont(47) frame.GetXaxis().SetTitleOffset(4.0) frame.GetXaxis().SetLabelFont( 43) # Absolute font size in pixel (precision 3) frame.GetXaxis().SetLabelSize(20) frame.GetXaxis().SetLabelOffset(0.05) frame.SetYTitle(pad2_Y_title) frame.GetYaxis().SetTitleSize(25) frame.GetYaxis().SetTitleFont(43) frame.GetYaxis().SetTitleOffset(2.0) frame.GetYaxis().SetLabelFont( 43) # Absolute font size in pixel (precision 3) frame.GetYaxis().SetLabelSize(20) frame.GetYaxis().SetLabelOffset(0.015) frame.Draw() line = ROOT.TLine(pad2_X_min, 1., pad2_X_max, 1.) line.SetLineColor(ROOT.kBlack) line.SetLineStyle(1) line.SetLineWidth(1) line.Draw("same") h_data_over_SM = h_data.Clone() h_data_over_SM.Divide(h_SM) h_data_over_SM.SetLineColor(ROOT.kBlack) h_data_over_SM.SetMarkerColor(ROOT.kBlack) h_data_over_SM.SetMarkerStyle(ROOT.kFullCircle) h_data_over_SM.SetMarkerSize(1.5) bin_center = [] for i in range(0, h_data_over_SM.GetXaxis().GetNbins() + 1): # remove the 0 bin content points by setting the central value to -99 if h_data_over_SM.GetBinContent(i) == 0: h_data_over_SM.SetBinContent(i, -99.) if h_data_over_SM.GetBinContent(i) > 2: bin_center.append(h_data_over_SM.GetBinCenter(i)) h_data_over_SM.Draw("E0,same") # Use E optoin, then no 0 bin content points are drawn but no error bars for those point > 2 # Use E0 option, the 0 bin content points are drawn and so do error bars # Add a small arrow for those bins with central value > 2 arrow_list = [] for x in bin_center: arrow = ROOT.TArrow(x, 1.7, x, 1.95, 0.01, "|>") # arrow.SetArrowSize(0.02) arrow.SetLineColor(ROOT.kOrange + 1) arrow.SetLineWidth(3) arrow.SetFillColor(ROOT.kOrange + 1) arrow.SetFillStyle(1001) # If draw arrow at here, then only the last arrow is drawn. # So put arrow object into a list and draw them later. if x < pad2_X_max: arrow_list.append(arrow) for arrow in arrow_list: arrow.Draw() h_SM_over_SM = h_SM.Clone() h_SM_over_SM.Divide(h_SM) h_SM_over_SM.SetLineColor(ROOT.kGray + 3) h_SM_over_SM.SetFillColor(ROOT.kGray + 3) h_SM_over_SM.SetMarkerColor(ROOT.kGray + 3) h_SM_over_SM.SetFillStyle(3004) h_SM_over_SM.Draw("E2,same") output = "NUHM2_m12_" + str(m12) + "_and_Bkg_" if varexp == 'mt_lep1+mt_lep2': output += "mt_lep1_plus_mt_lep2" else: output += varexp if lep_EEOS is True and lep_MMOS is False: output += "_EEOS" if lep_MMOS is True and lep_EEOS is False: output += "_MMOS" if lep_EEOS is True and lep_MMOS is True: output += "_SFOS" # output += "_N_minus_one_distribution_in_SR.pdf" output += "_N_minus_one_distribution_in_SR_times_10_on_Nsig.pdf" c1.SaveAs(output)
def make_minute_plots(buff_dict, lock_dict, results): hl0 = TH1F('hl0','hl0', 50, 0, 1) hl4 = TH1F('hl4','hl4', 50, 0, 1) hl8 = TH1F('hl8','hl8', 50, 0, 1) hl8.GetXaxis().SetTitle("Fraction of fill length") hl8.GetYaxis().SetTitle("Arbitrary units/ 0.02") hb0 = TH1F('hb0','h0', 50, 0, 1) hb4 = TH1F('hb4','h4', 50, 0, 1) hb8 = TH1F('hb8','h8', 50, 0, 1) hb8.GetXaxis().SetTitle("Fraction of fill length") hb8.GetYaxis().SetTitle("Arbitrary units/ 0.02") change_colors_min(hl0, hl4, hl8) change_colors_min(hb0, hb4, hb8) h0_lock_beg = [] h0_lock_end = [] h4_lock_beg = [] h4_lock_end = [] h8_lock_beg = [] h8_lock_end = [] h0_buff_beg = [] h0_buff_end = [] h4_buff_beg = [] h4_buff_end = [] h8_buff_beg = [] h8_buff_end = [] for r in lock_dict: temp0 = TH1F('htl0'+r,'htl0'+r, 80, 0, 240) temp1 = TH1F('htl1'+r,'htl1'+r, 80, 0, 240) temp2 = TH1F('htl2'+r,'htl2'+r, 96, 0, 480) temp3 = TH1F('htl3'+r,'htl3'+r, 96, 0, 480) temp4 = TH1F('htl4'+r,'htl4'+r, 180,0, 900) temp5 = TH1F('htl5'+r,'htl5'+r, 180,0, 900) temp0.SetLineWidth(0) temp0.SetFillStyle(1001) temp1.SetLineWidth(0) temp1.SetFillStyle(1001) temp2.SetLineWidth(0) temp2.SetFillStyle(1001) temp3.SetLineWidth(0) temp3.SetFillStyle(1001) temp4.SetLineWidth(0) temp4.SetFillStyle(1001) temp5.SetLineWidth(0) temp5.SetFillStyle(1001) h0_lock_beg.append(temp0) h0_lock_end.append(temp1) h0_lock_beg[-1].SetDirectory(0) h0_lock_end[-1].SetDirectory(0) h4_lock_beg.append(temp2) h4_lock_end.append(temp3) h4_lock_beg[-1].SetDirectory(0) h4_lock_end[-1].SetDirectory(0) h8_lock_beg.append(temp4) h8_lock_end.append(temp5) h8_lock_beg[-1].SetDirectory(0) h8_lock_end[-1].SetDirectory(0) for r in buff_dict: temp0 = TH1F('htb0'+r,'htb0'+r, 80, 0, 240) temp1 = TH1F('htb1'+r,'htb1'+r, 80, 0, 240) temp2 = TH1F('htb2'+r,'htb2'+r, 96, 0, 480) temp3 = TH1F('htb3'+r,'htb3'+r, 96, 0, 480) temp4 = TH1F('htb4'+r,'htb4'+r, 180,0, 900) temp5 = TH1F('htb5'+r,'htb5'+r, 180,0, 900) temp0.SetLineWidth(0) temp0.SetFillStyle(1001) temp1.SetLineWidth(0) temp1.SetFillStyle(1001) temp2.SetLineWidth(0) temp2.SetFillStyle(1001) temp3.SetLineWidth(0) temp3.SetFillStyle(1001) temp4.SetLineWidth(0) temp4.SetFillStyle(1001) temp5.SetLineWidth(0) temp5.SetFillStyle(1001) h0_buff_beg.append(temp0) h0_buff_end.append(temp1) h0_buff_beg[-1].SetDirectory(0) h0_buff_end[-1].SetDirectory(0) h4_buff_beg.append(temp2) h4_buff_end.append(temp3) h4_buff_beg[-1].SetDirectory(0) h4_buff_end[-1].SetDirectory(0) h8_buff_beg.append(temp4) h8_buff_end.append(temp5) h8_buff_beg[-1].SetDirectory(0) h8_buff_end[-1].SetDirectory(0) for error in results: pos_rod = error.text.find("ROD") + 4 pos_lock = error.text.find("Lock") + 15 pos_buff = error.text.find("buffer") + 17 if error.msgID == 'TRT::ROD05Module': rod = '0x'+str(error.text[pos_rod:pos_rod+6]) else: rod = str(error.text[pos_rod:pos_rod+8]) lock = str(error.text[pos_lock:pos_lock+3]) buff = str(error.text[pos_buff:pos_buff+3]) for i,key in enumerate(lock_dict): if key == rod and lock != '0xf' and error.sb_length > 0.5 and error.sb == 1: frac = error.sb_time_run/error.sb_length if error.sb_length < 4: hl0.Fill(frac) h0_lock_beg[i].Fill(error.sb_time_run*60) h0_lock_end[i].Fill(error.sb_length*60 - error.sb_time_run*60) elif error.sb_length < 8: hl4.Fill(frac) h4_lock_beg[i].Fill(error.sb_time_run*60) h4_lock_end[i].Fill(error.sb_length*60 - error.sb_time_run*60) else: hl8.Fill(frac) h8_lock_beg[i].Fill(error.sb_time_run*60) h8_lock_end[i].Fill(error.sb_length*60 - error.sb_time_run*60) for i,key2 in enumerate(buff_dict): if key2 == rod and buff != '0xf' and error.sb_length > 0.5 and error.sb == 1: frac = error.sb_time_run/error.sb_length if error.sb_length < 4: hb0.Fill(frac) h0_buff_beg[i].Fill(error.sb_time_run*60) h0_buff_end[i].Fill(error.sb_length*60 - error.sb_time_run*60) elif error.sb_length < 8: hb4.Fill(frac) h4_buff_beg[i].Fill(error.sb_time_run*60) h4_buff_end[i].Fill(error.sb_length*60 - error.sb_time_run*60) else: hb8.Fill(frac) h8_buff_beg[i].Fill(error.sb_time_run*60) h8_buff_end[i].Fill(error.sb_length*60 - error.sb_time_run*60) leg3 = TLegend(0.23,0.85,0.45,0.75) leg3.SetLineColor(0) leg3.SetFillStyle(0) leg3.SetShadowColor(0) leg3.SetBorderSize(0) leg3.AddEntry(hl0, "Fill Length: 0-4 hours", "lf") leg3.AddEntry(hl4, "Fill Length: 4-8 hours", "lf") leg3.AddEntry(hl8, "Fill Length: 8+ hours", "lf") c3 = TCanvas( 'c3', 'c3', 1000, 600) hl8.DrawNormalized("HIST",1) hl0.DrawNormalized("HISTSAME",1) hl4.DrawNormalized("HISTSAME",1) AtlasStyle.ATLAS_LABEL(0.24,.88, 1, "Internal") leg3.Draw() AtlasStyle.myText(0.5, 0.88, kBlack, "All RODs: lock errors") c3.Update() c3.Print("plots/frac_all_lock.pdf") c3.Clear() hb8.DrawNormalized("HIST",1) hb0.DrawNormalized("HISTSAME",1) hb4.DrawNormalized("HISTSAME",1) AtlasStyle.ATLAS_LABEL(0.24,.88, 1, "Internal") leg3.Draw() AtlasStyle.myText(0.5, 0.88, kBlack, "All RODs: buffer errors") c3.Update() c3.Print("plots/frac_all_buff.pdf") print_single_min(h0_lock_beg, h0_lock_end, "min_lock_0_4", "Lock errors, 0-4 hour fills") print_single_min(h4_lock_beg, h4_lock_end, "min_lock_4_8", "Lock errors, 4-8 hour fills") print_single_min(h8_lock_beg, h8_lock_end, "min_lock_8", "Lock errors, 8+ hour fills") print_single_min(h0_buff_beg, h0_buff_end, "min_buff_0_4", "Buffer errors, 0-4 hour fills") print_single_min(h4_buff_beg, h4_buff_end, "min_buff_4_8", "Buffer errors, 4-8 hour fills") print_single_min(h8_buff_beg, h8_buff_end, "min_buff_8", "Buffer errors, 8+ hour fills")
def getROC(signal, background, label, cut_start=None, cut_end=None, outputName="myROC.root", Rejection="l", omission=[]): ROCList = [] markerlist = [21, 8, 22, 23] print "get roc ", label for ivar in range(len(signal)): s_sort = np.sort(signal[ivar]) b_sort = np.sort(background[ivar]) #c_start=(0.0 if cut_start==None else cut_start) #c_end= (1.0 if cut_end==None else cut_end) print s_sort, b_sort for i in range(s_sort.shape[0]): if s_sort[i] == float("Inf"): s_sort[i] = 100000 if s_sort[i] == float("-Inf"): s_sort[i] = -1000000 for i in range(b_sort.shape[0]): if b_sort[i] == float("Inf"): b_sort[i] = 100000 if b_sort[i] == float("-Inf"): b_sort[i] = -1000000 c_start = np.min((s_sort[0], b_sort[0])) c_end = np.max((s_sort[len(s_sort) - 1], b_sort[len(b_sort) - 1])) if c_start == -float('inf'): c_start = -2 * c_end print label[ivar], "min(", s_sort[0], b_sort[0], ")=", c_start print label[ivar], "max(", s_sort[-1], b_sort[-1], ")=", c_end s_eff = [] b_rej = [] n_points = 1000 c_delta = (1.0 * c_end - 1.0 * c_start) / (1.0 * n_points) for i in range(1000): cut = c_start + i * 1.0 * c_delta s_eff.append(1.0 * np.count_nonzero(s_sort > cut) / (1.0 * len(s_sort))) b_count = np.count_nonzero(b_sort > cut) b_rej.append((1.0 * len(b_sort)) / (1.0 if b_count == 0 else (1.0 * b_count))) ROC = ROOT.TGraph(n_points, array.array('d', s_eff), array.array('d', b_rej)) ROC.SetName("ROC_%i" % (ivar)) ROCList.append(ROC) f = ROOT.TFile(outputName, "update") canvas = ROOT.TCanvas("ROC_Overlay", "ROC_Overlay", 800, 600) canvas.cd() mg = ROOT.TMultiGraph() legend = ROOT.TLegend(0.5, 0.5, 0.75, 0.75) for i in range(len(ROCList)): if i in omission: continue ROC = ROCList[i] ROC.SetLineWidth(3) ROC.SetLineColor(colorlist[i]) ROC.SetMarkerColor(colorlist[i]) ROC.SetMarkerSize(0) ROC.SetMarkerStyle(0) ROC.SetLineStyle(i + 1) mg.Add(ROC) if omission == []: legend.AddEntry(ROC, label[i], "lp") f.WriteTObject(ROC, "ROC_" + label[i], "Overwrite") if omission != []: legend.AddEntry(ROCList[1], label[1], "lp") legend.AddEntry(ROCList[4], label[4], "lp") legend.AddEntry(ROCList[5], label[5], "lp") legend.AddEntry(ROCList[2], label[2], "lp") mg.Draw("AL") mg.GetXaxis().SetTitle("b-jet efficiency, #varepsilon_{b}") if Rejection == "l": mg.GetYaxis().SetTitle("light-jet rejection, 1/#varepsilon_{l}") if Rejection == "c": mg.GetYaxis().SetTitle("c-jet rejection, 1/#varepsilon_{c}") legend.Draw("same") Atlas.ATLASLabel(0.2, 0.88, 0.13, "Simulation Internal", color=1) Atlas.myText(0.2, 0.81, color=1, size=0.04, text="#sqrt{s}=13 TeV, t#bar{t}") Atlas.myText(0.2, 0.75, color=1, size=0.04, text="p_{T}>20 GeV, |#eta|<2.5") #Atlas.myText(0.2, 0.69 ,color=1, size=0.04,text="Rel21") #canvas.Update() canvas.Draw() f.WriteTObject(canvas, canvas.GetName(), "Overwrite") f.Close() return (ROCList, canvas)
def draw_cross_section_limit_dM(tree, dM, flavor_of_sample='MET_TLJets'): AtlasStyle.SetAtlasStyle() entries = tree.GetEntries() current_mass = 0 upper_limits = [] mass_g = [] index = -1 point = 0 for entry in range(entries): tree.GetEntry(entry) if tree.deltaM == dM or (dM == 'large' and tree.mGluino - tree.deltaM == 100): if current_mass != tree.mGluino: print('*** {0}, {1}'.format(tree.mGluino, tree.deltaM)) upper_limits.append(TGraphErrors()) mass_g.append(int(tree.mGluino)) index += 1 point = 0 current_mass = tree.mGluino upper_limits[index].SetPoint(point, tree.ctau * 1e3, tree.xsUL) #upper_limits[index].SetPointError(point, 0, tree.xsUL*tree.effRelStatErr+tree.xsUL*tree.effRelSystErr) point += 1 print(tree.ctau, tree.xsUL) canvas = TCanvas('c', 'c', 1000, 800) canvas.SetLogx() canvas.SetLogy() h_xs = TH1F('xs', ';c#tau [mm]; Cross Section [fb]', 1000, 0.9, 310) h_xs.GetYaxis().SetRangeUser(0.1, 100) h_xs.Draw() #h_xs_line = TH1F('xs_line', ';c#tau [mm]; Cross Section [fb]', 1000, 0.9, 310) #print(mc.mass_xs_err[mass_g]['xs'] * 1e3) legend = TLegend(0.60, 0.75, 0.83, 0.90) for ii, upper_limit in enumerate(upper_limits): #upper_limit.RemovePoint(0) upper_limit.SetMarkerSize(0) upper_limit.SetFillStyle(3001) index = ii #if dM[ii] == 130: # index = 1 #elif dM[ii] == 80: # index = 2 # continue #elif dM[ii] == 50: # index = 3 #elif dM[ii] == 30: # index = 4 #print(upper_limit) upper_limit.SetFillColor(BasicConfig.colors[index+1]) upper_limit.SetLineColor(BasicConfig.colors[index+1]) upper_limit.Draw('lp,same') #upper_limit.Draw('c,same') #if dM[ii] > 100: # #legend.AddEntry(upper_limit, 'M_{#tilde{g}} = '+str(mass_g)+' GeV, #DeltaM = '+str(dM[ii])+' GeV', 'lf') # legend.AddEntry(upper_limit, '#DeltaM = '+str(dM[ii])+' GeV', 'lf') #legend.AddEntry(upper_limit, '#DeltaM = '+str(dM[ii])+' GeV', 'lf') legend.AddEntry(upper_limit, 'Mass G = ' + str(mass_g[ii]) + ' GeV', 'lf') utils.decorate_legend(legend) legend.Draw() AtlasStyle.ATLASLabel(0.19, 0.87, 'Work in Progress') AtlasStyle.myText(0.20, 0.79, kBlack, '#sqrt{s} = 13 TeV, #int L dt = 30 fb^{-1}', 0.035) #AtlasStyle.myText(0.20, 0.73, kBlack, 'Split-SUSY Model, M_{#tilde{g}} = '+str(mass_g)+' GeV', 0.032) #AtlasStyle.myText(0.20, 0.67, kBlack, 'M_{#tilde{g}} = '+str(mass_g)+' GeV', 0.035) #if dM == 'large' and tree.mGluino - tree.deltaM == 100: # print('test') utils.save_as(canvas, BasicConfig.plotdir + 'xs_limit_large_dM_' + flavor_of_sample)
def draw_cross_section_limit(tree, mass_g, flavor_of_sample='MET_TLJets'): AtlasStyle.SetAtlasStyle() entries = tree.GetEntries() current_delta_mass = 0 upper_limits = [] dM = [] index = -1 for entry in range(entries): tree.GetEntry(entry) if tree.mGluino == mass_g: if current_delta_mass != tree.deltaM: print('*** {0}, {1}'.format(tree.mGluino, tree.deltaM)) upper_limits.append(TGraphErrors()) dM.append(int(tree.deltaM)) index += 1 point = 0 current_delta_mass = tree.deltaM #if current_delta_mass < 100: # continue upper_limits[index].SetPoint(point, tree.ctau * 1e3, tree.xsUL) upper_limits[index].SetPointError( point, 0, tree.xsUL * tree.effRelStatErr + tree.xsUL * tree.effRelSystErr) point += 1 print(tree.ctau, tree.xsUL) canvas = TCanvas('c', 'c', 1000, 800) canvas.SetLogx() canvas.SetLogy() #upper_limits[0].SetMinimum(0.8) #upper_limits[0].SetMinimum(0.05) #upper_limits[0].SetMaximum(30000) #upper_limits[0].GetXaxis().SetRangeUser(0.9, 310) #upper_limits[0].GetXaxis().SetTitle('c#tau [mm]') #upper_limits[0].GetYaxis().SetTitle('Cross Section [fb]') #upper_limits[0].Draw('A3') #if mass_g == 1400: # upper_limits[1].RemovePoint(0) #upper_limits[0].RemovePoint(2) #upper_limits[1].RemovePoint(0) h_xs = TH1F('xs', ';c#tau [mm]; Cross Section [fb]', 1000, 0.9, 310) h_xs_line = TH1F('xs_line', ';c#tau [mm]; Cross Section [fb]', 1000, 0.9, 310) print(mc.mass_xs_err[mass_g]['xs'] * 1e3) for bin in range(1, 1000 + 1): h_xs.SetBinContent(bin, mc.mass_xs_err[mass_g]['xs'] * 1e3) h_xs_line.SetBinContent(bin, mc.mass_xs_err[mass_g]['xs'] * 1e3) h_xs.SetBinError( bin, mc.mass_xs_err[mass_g]['xs'] * 1e3 * mc.mass_xs_err[mass_g]['xs_err'] * 0.01) h_xs.SetMarkerSize(0) h_xs.SetFillStyle(3001) h_xs.SetFillColor(kGray + 2) #h_xs.SetMinimum(0.8) h_xs.SetMinimum(0.05) h_xs.SetMaximum(30000) #h_xs.Draw('same,e2') h_xs.Draw('e2') h_xs_line.SetLineColor(kGray + 3) h_xs_line.SetLineStyle(2) h_xs_line.Draw('same') legend = TLegend(0.60, 0.75, 0.83, 0.90) for ii, upper_limit in enumerate(upper_limits): #upper_limit.RemovePoint(0) upper_limit.SetMarkerSize(0) upper_limit.SetFillStyle(3001) index = ii if dM[ii] == 130: index = 1 elif dM[ii] == 80: index = 2 continue elif dM[ii] == 50: index = 3 elif dM[ii] == 30: index = 4 upper_limit.SetFillColor(BasicConfig.colors[index + 1]) upper_limit.SetLineColor(BasicConfig.colors[index + 1]) upper_limit.Draw('3,same') #upper_limit.Draw('c,same') #if dM[ii] > 100: # #legend.AddEntry(upper_limit, 'M_{#tilde{g}} = '+str(mass_g)+' GeV, #DeltaM = '+str(dM[ii])+' GeV', 'lf') # legend.AddEntry(upper_limit, '#DeltaM = '+str(dM[ii])+' GeV', 'lf') legend.AddEntry(upper_limit, '#DeltaM = ' + str(dM[ii]) + ' GeV', 'lf') utils.decorate_legend(legend) legend.Draw() AtlasStyle.ATLASLabel(0.19, 0.87, 'Work in Progress') AtlasStyle.myText(0.20, 0.79, kBlack, '#sqrt{s} = 13 TeV, #int L dt = 30 fb^{-1}', 0.035) AtlasStyle.myText( 0.20, 0.73, kBlack, 'Split-SUSY Model, M_{#tilde{g}} = ' + str(mass_g) + ' GeV', 0.032) #AtlasStyle.myText(0.20, 0.67, kBlack, 'M_{#tilde{g}} = '+str(mass_g)+' GeV', 0.035) utils.save_as( canvas, BasicConfig.plotdir + 'xs_limit_mGluino' + str(mass_g) + flavor_of_sample)
def draw_cross_section_limit_dM(tree, dM, flavor_of_sample='MET_TLJets'): AtlasStyle.SetAtlasStyle() entries = tree.GetEntries() current_mass = 0 upper_limits = [] mass_g = [] index = -1 point = 0 for entry in range(entries): tree.GetEntry(entry) if tree.deltaM == dM or (dM == 'large' and tree.mGluino - tree.deltaM == 100): if current_mass != tree.mGluino: print('*** {0}, {1}'.format(tree.mGluino, tree.deltaM)) upper_limits.append(TGraphErrors()) mass_g.append(int(tree.mGluino)) index += 1 point = 0 current_mass = tree.mGluino upper_limits[index].SetPoint(point, tree.ctau * 1e3, tree.xsUL) #upper_limits[index].SetPointError(point, 0, tree.xsUL*tree.effRelStatErr+tree.xsUL*tree.effRelSystErr) point += 1 print(tree.ctau, tree.xsUL) canvas = TCanvas('c', 'c', 1000, 800) canvas.SetLogx() canvas.SetLogy() h_xs = TH1F('xs', ';c#tau [mm]; Cross Section [fb]', 1000, 0.9, 310) h_xs.GetYaxis().SetRangeUser(0.1, 100) h_xs.Draw() #h_xs_line = TH1F('xs_line', ';c#tau [mm]; Cross Section [fb]', 1000, 0.9, 310) #print(mc.mass_xs_err[mass_g]['xs'] * 1e3) legend = TLegend(0.60, 0.75, 0.83, 0.90) for ii, upper_limit in enumerate(upper_limits): #upper_limit.RemovePoint(0) upper_limit.SetMarkerSize(0) upper_limit.SetFillStyle(3001) index = ii #if dM[ii] == 130: # index = 1 #elif dM[ii] == 80: # index = 2 # continue #elif dM[ii] == 50: # index = 3 #elif dM[ii] == 30: # index = 4 #print(upper_limit) upper_limit.SetFillColor(BasicConfig.colors[index + 1]) upper_limit.SetLineColor(BasicConfig.colors[index + 1]) upper_limit.Draw('lp,same') #upper_limit.Draw('c,same') #if dM[ii] > 100: # #legend.AddEntry(upper_limit, 'M_{#tilde{g}} = '+str(mass_g)+' GeV, #DeltaM = '+str(dM[ii])+' GeV', 'lf') # legend.AddEntry(upper_limit, '#DeltaM = '+str(dM[ii])+' GeV', 'lf') #legend.AddEntry(upper_limit, '#DeltaM = '+str(dM[ii])+' GeV', 'lf') legend.AddEntry(upper_limit, 'Mass G = ' + str(mass_g[ii]) + ' GeV', 'lf') utils.decorate_legend(legend) legend.Draw() AtlasStyle.ATLASLabel(0.19, 0.87, 'Work in Progress') AtlasStyle.myText(0.20, 0.79, kBlack, '#sqrt{s} = 13 TeV, #int L dt = 30 fb^{-1}', 0.035) #AtlasStyle.myText(0.20, 0.73, kBlack, 'Split-SUSY Model, M_{#tilde{g}} = '+str(mass_g)+' GeV', 0.032) #AtlasStyle.myText(0.20, 0.67, kBlack, 'M_{#tilde{g}} = '+str(mass_g)+' GeV', 0.035) #if dM == 'large' and tree.mGluino - tree.deltaM == 100: # print('test') utils.save_as( canvas, BasicConfig.plotdir + 'xs_limit_large_dM_' + flavor_of_sample)
def plot1D( Hists, SampleTypes, SampleNames ): histName = '_'.join(Hists[0].GetName().split('_')[1:] ) plotRatio = args.plotRatio ## Setup Canvas ## c0 = ROOT.TCanvas(histName) logx = False logy = False # TODO need a logXList of variables for choosing this. Get from a config file? ## #extraText=[] ## #logXList = [ "mjj", "m3j", "chi", "m12", "m13", "m23" ] # madd all two-jet mass plots have logX ## logXList = [ "chi" ] # madd all two-jet mass plots have logX ## for v in logXList: ## if v == hName: logx = True ### elif v in hName and "for_mjj" in hName : logx = True ## elif v in hName and not "__" in hName: logx = True ## if logx: hists[i].GetYaxis().SetMoreLogLabels(1) ## ## if logx: ## c0.SetLogx() ## if (plotRatio): ## pad1.SetLogx() ## pad2.SetLogx() ## else: ## c0.SetLogx(0) ## if (plotRatio): ## pad1.SetLogx(0) ## pad2.SetLogx(0) setMaximum(Hists) if plotRatio: pad1, pad2, zeroLine, oneLine = getRatioObjects(c0, logx, logy) pad1.cd() leg = configureLegend(SampleTypes, Hists, SampleNames) ### Configure draw string ### for iH, hist in enumerate(Hists): drawString = "" if iH != 0: drawString += 'same' drawString += 'hist' #drawString += 'histe' if not "data" == SampleTypes[iH]: #if args.stackBkg: # drawString += 'fe' #else: drawString += '' else: drawString += 'ep' print drawString Hists[iH].Draw( drawString ) ## Setup Ratio Plots if plotRatio: ratioHists = [] #Ratio histograms iRatioHist = SampleTypes.index(args.ratioWRT) for iHist, hist in enumerate(Hists): if iHist == iRatioHist: continue ## get relevant hists ## tmpRatioHist = Hists[iRatioHist].Clone( hist.GetName()+'_ratio' ) tmpHist = hist.Clone( 'tmp' ) ## create ratio ## if type(tmpHist) == ROOT.THStack: tmpStackHist = getCombinedStack( tmpHist ) for iStack, stackHist in enumerate(tmpHist.GetHists() ): if iStack == 0: tmpStackHist = stackHist.Clone('tmp2') else: tmpStackHist.Add( stackHist ) tmpRatioHist.Add( tmpStackHist, -1. ) tmpRatioHist.Divide( tmpStackHist ) else: tmpRatioHist.Add( tmpHist, -1. ) tmpRatioHist.Divide( tmpHist ) # flip it so excess is still positive on ratio if args.ratioWRT == 'bkg' or args.ratioWRT == 'stack': tmpRatioHist.Scale( -1.0 ) ## If ratio value is 0 then there should be no ratio drawn for iBin in range(1, tmpRatioHist.GetNbinsX()+1): if Hists[iRatioHist].GetBinContent(iBin) == 0: tmpRatioHist.SetBinContent(iBin, 0) tmpRatioHist.SetBinError(iBin, 0) configureRatioHist(tmpHist, tmpRatioHist) ratioHists.append( tmpRatioHist ) ## Draw Ratio Plots if plotRatio: pad2.cd() for iHist, ratioHist in enumerate(ratioHists): ratioHists[iHist].SetStats(0) if iHist == 0: ratioHists[iHist].DrawCopy("p") ratioHists[iHist].SetMarkerSize(0) ratioHists[iHist].DrawCopy("same e0") else: ratioHists[iHist].Draw( "same fhist" ) zeroLine.Draw("same") c0.cd() leg.Draw("same") AtlasStyle.ATLAS_LABEL(0.20,0.88, 1, "Internal") sqrtSLumiText = getSqrtSLumiText( args.lumi ) AtlasStyle.myText(0.20,0.82,1, sqrtSLumiText) if len(args.plotText)>0: AtlasStyle.myText(0.20,0.76,1, args.plotText) if any( extraTextString.split(',')[0] in histName for extraTextString in extraText ): extraTextString = [extraTextString for extraTextString in extraText if extraTextString.split(',')[0] in histName][0] if len(args.plotText)>0: AtlasStyle.myText(0.20,0.64, 1,extraTextString.split(',')[1]) else: AtlasStyle.myText(0.20,0.75, 1,extraTextString.split(',')[1]) c0.Print( args.outDir + "/" + args.outputTag + "_" + histName + args.outputVersion + ".png","png") #,"png") ## Draw y-log plots ## if plotRatio: pad1.SetLogy() pad1.cd() else: c0.SetLogy() setMaximum(Hists, True) ### Redraw using new logY maximum ### for iH, hist in enumerate(Hists): drawString = "" if iH != 0: drawString += 'same' drawString += 'histe' if not "data" == SampleTypes[iH]: drawString += 'fe' else: drawString += 'ep' Hists[iH].Draw( drawString ) c0.Print( args.outDir + "/" + args.outputTag + "_" + histName + args.outputVersion + "_logY.png","png") #,"png") ## TODO Draw log versions? if plotRatio: pad1.Delete() pad2.Delete() # c0.Delete() return
def createPlot(fname, plotType = 'discriminant', parameter_file = '', pt_range=[0,0], bdt=False, extraFiles=''): # values for the plotting of labels and stuff labelx = labelx_dnn = 0.45 labely = labely_dnn = 0.88 labelx_bdt = 0.2 labely_bdt = 0.88 legendx1 = legendx1_dnn = 0.65 legendy1 = legendy1_dnn = 0.6 legendx2 = legendx2_dnn = 0.9 legendy2 = legendy2_dnn = 0.75 xlow = 0.0 xhigh = 1.0 legendx1_bdt = 0.68 legendy1_bdt = 0.75 legendx2_bdt = 0.93 legendy2_bdt = 0.95 paramx = paramx_dnn = 0.4 paramy = paramy_dnn = 0.8 paramx_bdt = 0.2 paramy_bdt = 0.8 if bdt: labelx = labelx_bdt labely = labely_bdt legendx1 = legendx1_bdt legendx2 = legendx2_bdt legendy1 = legendy1_bdt legendy2 = legendy2_bdt paramx = paramx_bdt paramy = paramy_bdt #if plotType != 'discriminant': # legendx1 = 0.65 # legendx2 = 0.9 # legendy1 = 0.68 # legendy2 = 0.88 xtitle = 'Signal Probability' # need to get the tagger id from the file name pos = fname.find('paramID_')+8 pos_end = copy.deepcopy(pos) while fname[pos_end].isdigit(): pos_end+=1 taggerid = fname[pos:pos_end] #print fname, taggerid cv_pos = fname.find('ID',pos_end+1,len(fname))+3 cv = fname[cv_pos] print 'cv:',cv f = rt.TFile.Open(fname,mode)#'UPDATE' if plotType == 'discriminant': distrib = 'Discriminant' combined = 'Discriminant' file_flag = '_disc' else: distrib = 'Decision Function' combined = 'Decision Functions Norm' xtitle = 'Decision Function' file_flag = '_df' xlow = -1 keys = f.GetListOfKeys() has_sigdf = False has_bkgdf = False has_df = False for k in keys: if k.GetName() == 'Signal '+distrib: has_sigdf = True if k.GetName() == 'Background '+distrib: has_bkgdf = True if k.GetName() == combined: has_df = True if not has_sigdf or not has_bkgdf: print 'keys do not exist' return if has_df and mode=='UPDATE': print 'already has the df canvas' return sigdf = f.Get('Signal '+distrib).Clone() sigdf.SetDirectory(0) sigdf.SetLineColor(rt.kRed) sigdf.SetMarkerSize(1) sigdf.SetTitle(xtitle) #sigdf.Rebin(5) sigdf.GetXaxis().SetTitle(xtitle) sigdf.GetYaxis().SetTitle('Normalised Entries') #sigdf.GetXaxis().SetRangeUser(xlow,xhigh) #if sigdf.Integral() != 0.0: # sigdf.Scale(1./sigdf.Integral()) bkgdf = f.Get('Background '+distrib).Clone() bkgdf.SetDirectory(0) bkgdf.SetLineColor(rt.kBlue) bkgdf.SetTitle(xtitle) bkgdf.SetMarkerSize(1) bkgdf.GetXaxis().SetTitle(xtitle) bkgdf.GetYaxis().SetTitle('Normalised Entries') #bkgdf.GetXaxis().SetRangeUser(xlow,xhigh) #if bkgdf.Integral() != 0.0: # bkgdf.Scale(1./bkgdf.Integral()) f.Close() print type(sigdf) # now get the rest of them from the other files!!!! #tlistsig = rt.TList() #tlistbkg = rt.TList() #tlistsig.Add(sigdf) #tlistbkg.Add(bkgdf) # find extra files! if bdt: folds = 10 else: folds = 5 ef = [] for x in range(0,folds): ffff = fname[:cv_pos]+str(x)+fname[cv_pos+1:] ef.append(ffff) print ef print sigdf.Integral() for tf in ef: tmpfile = rt.TFile.Open(tf,mode) sigtmp = tmpfile.Get('Signal ' + distrib).Clone() sigtmp.SetDirectory(0) bkgtmp = tmpfile.Get('Background ' + distrib).Clone() bkgtmp.SetDirectory(0) sigdf.Add(sigtmp) bkgdf.Add(bkgtmp) tmpfile.Close() #ef.close() #sigdf2 = sigdf.Clone() #sigdf2.Reset() #sigdf2.Merge(tlistsig) #bkgdf2 = bkgdf.Clone() #bkgdf2.Reset() #bkgdf2.Merge(tlistbkg) print sigdf.Integral() if plotType != 'discriminant': sigdf.Rebin(4) bkgdf.Rebin(4) else: sigdf.Rebin(2) bkgdf.Rebin(2) if sigdf.Integral() != 0.0: sigdf.Scale(1./sigdf.Integral()) if bkgdf.Integral() != 0.0: bkgdf.Scale(1./bkgdf.Integral()) tc = rt.TCanvas(combined) tc.SetTitle(combined) legend = rt.TLegend(legendx1, legendy1, legendx2, legendy2);legend.SetFillColor(rt.kWhite) legend.SetBorderSize(0) legend.SetFillStyle(0) legend.AddEntry(sigdf, 'Signal') legend.AddEntry(bkgdf, 'Background') max_v = max(sigdf.GetMaximum(), bkgdf.GetMaximum()) sigdf.SetMaximum(max_v*1.4) bkgdf.SetMaximum(max_v*1.4) sigdf.Draw('hist') bkgdf.Draw('histsame') legend.Draw() label = rt.TLatex() label.SetTextSize(0.05) label.DrawLatexNDC(labelx,labely, '#sqrt{s}=13 TeV, '+str(pt_range[0])+'<p_{T}<'+str(pt_range[1])+' (GeV)') if fname.find('AGILE') != -1 or fname.find('DNN') != -1: param_label = gp.dnn(parameter_file) elif fname.find('BDT') != -1: param_label = gp.bdt(parameter_file) print param_label atlas.myText(paramx, paramy, 1, 0.04, param_label[taggerid]) if mode == 'UPDATE': tc.Write() else: tc.SaveAs(fname.replace('.root',file_flag+'.pdf'))
def plot_invariant_mass(lep_EEOS=False, lep_MMOS=False): path = '/raid05/atlas/data/Higgsino/SusySkimHiggsino_v1.1_SUSY16_Bkgs_tree/' data15 = 'data15_SusySkimHiggsino_v1.1_SUSY16_tree.root' data16 = 'data16_SusySkimHiggsino_v1.1_SUSY16_tree.root' h_data15 = get_histogram(path + data15, "data15", 'mll', lep_EEOS, lep_MMOS) h_data15.SetLineColor(ROOT.kAzure) h_data16A = get_histogram(path + data16, "data16A", 'mll', lep_EEOS, lep_MMOS) h_data16A.SetLineColor(ROOT.kAzure) h_data16B = get_histogram(path + data16, "data16B", 'mll', lep_EEOS, lep_MMOS) h_data16B.SetLineColor(ROOT.kAzure) h_data16C = get_histogram(path + data16, "data16C", 'mll', lep_EEOS, lep_MMOS) h_data16C.SetLineColor(ROOT.kAzure) h_data16D = get_histogram(path + data16, "data16D", 'mll', lep_EEOS, lep_MMOS) h_data16D.SetLineColor(ROOT.kAzure) h_data16E = get_histogram(path + data16, "data16E", 'mll', lep_EEOS, lep_MMOS) h_data16E.SetLineColor(ROOT.kAzure) h_data16F = get_histogram(path + data16, "data16F", 'mll', lep_EEOS, lep_MMOS) h_data16F.SetLineColor(ROOT.kAzure) h_data16G = get_histogram(path + data16, "data16G", 'mll', lep_EEOS, lep_MMOS) h_data16G.SetLineColor(ROOT.kAzure) h_data16I = get_histogram(path + data16, "data16I", 'mll', lep_EEOS, lep_MMOS) h_data16I.SetLineColor(ROOT.kAzure) h_data16K = get_histogram(path + data16, "data16K", 'mll', lep_EEOS, lep_MMOS) h_data16K.SetLineColor(ROOT.kAzure) h_data16L = get_histogram(path + data16, "data16L", 'mll', lep_EEOS, lep_MMOS) h_data16L.SetLineColor(ROOT.kAzure) h_data = h_data15.Clone() h_data.Add(h_data16A) h_data.Add(h_data16B) h_data.Add(h_data16C) h_data.Add(h_data16D) h_data.Add(h_data16E) h_data.Add(h_data16F) h_data.Add(h_data16G) h_data.Add(h_data16I) h_data.Add(h_data16K) h_data.Add(h_data16L) entries = h_data.Integral() # Making plot c1 = ROOT.TCanvas("c1", "", 800, 800) ROOT.gStyle.SetOptStat(0) ROOT.gPad.SetBottomMargin(0.15) ROOT.gPad.SetRightMargin(0.05) ROOT.gPad.SetLeftMargin(0.15) ROOT.gPad.SetLogx() ymax = 0. if lep_EEOS: ymax = 250. elif lep_MMOS: ymax = 2000. h_data.SetMinimum(0.) h_data.SetMaximum(ymax) h_data.GetXaxis().SetTitleOffset(1.5) h_data.GetYaxis().SetTitleOffset(1.8) h_data.Draw() AtlasStyle.myText(0.2, 0.83, "#sqrt{s} = 13 TeV, 36.1 fb^{-1}", ROOT.kBlack, 0.04) AtlasStyle.myText( 0.2, 0.78, "SusySkimHiggsino v1.1, Data (" + str(int(entries)) + " Events)", ROOT.kBlack, 0.03) AtlasStyle.myText( 0.2, 0.73, "Pass E^{miss}_{T} triggers, #Delta#phi(#font[62]{p}^{j1}_{T}, #font[62]{p}^{miss}_{T}) < 1.5 Control Region", ROOT.kBlack, 0.03) if lep_EEOS: AtlasStyle.myText(0.2, 0.68, "Baseline e^{#pm}e^{#mp}", ROOT.kBlack, 0.03) elif lep_MMOS: AtlasStyle.myText(0.2, 0.68, "Baseline #mu^{#pm}#mu^{#mp}", ROOT.kBlack, 0.03) output = 'invariant_mass_' if lep_EEOS: output += 'lep_EEOS.pdf' elif lep_MMOS: output += 'lep_MMOS.pdf' c1.SaveAs(output)
def DrawHistsWithSys(self, title, axisname=[], inplots=[], inlabel=[], sys=[], syslabel=[]): maxval = 1 minval = 1000 secminval = 10000 legend = ROOT.TLegend(self.legend[0], self.legend[1], self.legend[2], self.legend[3]) legend.SetFillColor(0) ## finding the right axises space for i in range(len(inplots)): if inplots[i] == None: continue doExist = False legend.AddEntry(inplots[i], inlabel[i], "LPS") thismax = inplots[i].GetMaximum() thismin = inplots[i].GetMinimum() if maxval < thismax: maxval = thismax if (minval >= thismin): minval = thismin if minval <= 1.0: minval = 1.0 ###### draw histogram Canv = ROOT.TCanvas('Canv_' + title, 'Canv_' + title, 0, 0, 800, 600) if (self.CompareData): Pad1 = ROOT.TPad('Pad1', 'Pad1', 0.0, 0.25, 1.0, 0.99, 0) Pad2 = ROOT.TPad('Pad2', 'Pad2', 0.0, 0.00, 1.0, 0.32, 0) Pad2.SetBottomMargin(0.4) Pad1.Draw() Pad2.Draw() Pad1.cd() ncolor = 0 count = 0 for i in range(len(inplots)): if inplots[i] == None: continue inplots[i].SetMarkerColor(self.colorlist[ncolor]) inplots[i].SetFillColor(self.colorlist[ncolor]) inplots[i].SetLineColor(self.colorlist[ncolor]) inplots[i].GetXaxis().SetTitle(axisname[0]) inplots[i].GetYaxis().SetTitle(axisname[1]) if (self.doRescale and not (self.doLogY)): inplots[i].GetYaxis().SetRangeUser(0, maxval * 4.5 / 3.) if (self.doRescale and self.doLogY): inplots[i].GetYaxis().SetRangeUser(minval / 100., maxval * 10.) ncolor += 1 inplots[i].SetTitle("") if count != 0: self.drawOption = "same" inplots[i].Draw("e" + self.drawOption) else: inplots[i].Draw("e") count += 1 for i in range(len(sys)): sys[i].SetFillStyle(3004) sys[i].SetFillColor(self.colorlist[ncolor]) sys[i].SetLineColor(0) sys[i].SetMarkerStyle(10) sys[i].SetMarkerSize(0) sys[i].Draw("e2 same") ncolor += 1 count += 1 legend.AddEntry(sys[i], syslabel[i], 'f') legend.Draw("same") for text in self.texts: Atlas.myText(text[0], text[1], text[2], text[3], text[4]) if self.doAtlasLabel: Atlas.ATLASLabel(self.AtlasLabelPos, 0.88, 0.13, self.studytype, color=1) #if self.doLabel and self.lumi != "0": Atlas.myText(self.AtlasLabelPos, 0.81, color=1, size=0.04, text="#sqrt{s}=" + self.sqrtS + " TeV: " + "#intLdt=20.3" + " fb^{-1}") #if self.doLabel and self.lumi == "0": # Atlas.myText(0.2, 0.81 ,color=1, size=0.04,text="#sqrt{s}="+self.sqrtS + " TeV") if self.doLogY: Canv.SetLogy() if self.doLogX: Canv.SetLogx() if self.doLogZ: Canv.SetLogz() Canv.Write() if (self.doPrintPlots): Canv.SaveAs(self.OutPlotDir + Canv.GetName() + ".png") Canv.Close() return inplots
def plot1D(Hists, SampleTypes, SampleNames): histName = '_'.join(Hists[0].GetName().split('_')[1:]) plotRatio = args.plotRatio ## Setup Canvas ## c0 = ROOT.TCanvas(histName) logx = False logy = False # TODO need a logXList of variables for choosing this. Get from a config file? ## #extraText=[] ## #logXList = [ "mjj", "m3j", "chi", "m12", "m13", "m23" ] # madd all two-jet mass plots have logX ## logXList = [ "chi" ] # madd all two-jet mass plots have logX ## for v in logXList: ## if v == hName: logx = True ### elif v in hName and "for_mjj" in hName : logx = True ## elif v in hName and not "__" in hName: logx = True ## if logx: hists[i].GetYaxis().SetMoreLogLabels(1) ## ## if logx: ## c0.SetLogx() ## if (plotRatio): ## pad1.SetLogx() ## pad2.SetLogx() ## else: ## c0.SetLogx(0) ## if (plotRatio): ## pad1.SetLogx(0) ## pad2.SetLogx(0) setMaximum(Hists) if plotRatio: pad1, pad2, zeroLine, oneLine = getRatioObjects(c0, logx, logy) pad1.cd() leg = configureLegend(SampleTypes, Hists, SampleNames) ### Configure draw string ### for iH, hist in enumerate(Hists): drawString = "" if iH != 0: drawString += 'same' drawString += 'hist' #drawString += 'histe' if not "data" == SampleTypes[iH]: #if args.stackBkg: # drawString += 'fe' #else: drawString += '' else: drawString += 'ep' print drawString Hists[iH].Draw(drawString) ## Setup Ratio Plots if plotRatio: ratioHists = [] #Ratio histograms iRatioHist = SampleTypes.index(args.ratioWRT) for iHist, hist in enumerate(Hists): if iHist == iRatioHist: continue ## get relevant hists ## tmpRatioHist = Hists[iRatioHist].Clone(hist.GetName() + '_ratio') tmpHist = hist.Clone('tmp') ## create ratio ## if type(tmpHist) == ROOT.THStack: tmpStackHist = getCombinedStack(tmpHist) for iStack, stackHist in enumerate(tmpHist.GetHists()): if iStack == 0: tmpStackHist = stackHist.Clone('tmp2') else: tmpStackHist.Add(stackHist) tmpRatioHist.Add(tmpStackHist, -1.) tmpRatioHist.Divide(tmpStackHist) else: tmpRatioHist.Add(tmpHist, -1.) tmpRatioHist.Divide(tmpHist) # flip it so excess is still positive on ratio if args.ratioWRT == 'bkg' or args.ratioWRT == 'stack': tmpRatioHist.Scale(-1.0) ## If ratio value is 0 then there should be no ratio drawn for iBin in range(1, tmpRatioHist.GetNbinsX() + 1): if Hists[iRatioHist].GetBinContent(iBin) == 0: tmpRatioHist.SetBinContent(iBin, 0) tmpRatioHist.SetBinError(iBin, 0) configureRatioHist(tmpHist, tmpRatioHist) ratioHists.append(tmpRatioHist) ## Draw Ratio Plots if plotRatio: pad2.cd() for iHist, ratioHist in enumerate(ratioHists): ratioHists[iHist].SetStats(0) if iHist == 0: ratioHists[iHist].DrawCopy("p") ratioHists[iHist].SetMarkerSize(0) ratioHists[iHist].DrawCopy("same e0") else: ratioHists[iHist].Draw("same fhist") zeroLine.Draw("same") c0.cd() leg.Draw("same") AtlasStyle.ATLAS_LABEL(0.20, 0.88, 1, "Internal") sqrtSLumiText = getSqrtSLumiText(args.lumi) AtlasStyle.myText(0.20, 0.82, 1, sqrtSLumiText) if len(args.plotText) > 0: AtlasStyle.myText(0.20, 0.76, 1, args.plotText) if any( extraTextString.split(',')[0] in histName for extraTextString in extraText): extraTextString = [ extraTextString for extraTextString in extraText if extraTextString.split(',')[0] in histName ][0] if len(args.plotText) > 0: AtlasStyle.myText(0.20, 0.64, 1, extraTextString.split(',')[1]) else: AtlasStyle.myText(0.20, 0.75, 1, extraTextString.split(',')[1]) c0.Print(args.outDir + "/" + args.outputTag + "_" + histName + args.outputVersion + ".png", "png") #,"png") ## Draw y-log plots ## if plotRatio: pad1.SetLogy() pad1.cd() else: c0.SetLogy() setMaximum(Hists, True) ### Redraw using new logY maximum ### for iH, hist in enumerate(Hists): drawString = "" if iH != 0: drawString += 'same' drawString += 'histe' if not "data" == SampleTypes[iH]: drawString += 'fe' else: drawString += 'ep' Hists[iH].Draw(drawString) c0.Print(args.outDir + "/" + args.outputTag + "_" + histName + args.outputVersion + "_logY.png", "png") #,"png") ## TODO Draw log versions? if plotRatio: pad1.Delete() pad2.Delete() # c0.Delete() return
def DrawHists(self, title, axisname=[], inplots=[], inlabel=[], instacks=[], instacklabel=[], sys=[]): maxval = 1 minval = 1000 secminval = 10000 legend = ROOT.TLegend(self.legend[0], self.legend[1], self.legend[2], self.legend[3]) legend.SetFillColor(0) doExist = True ## finding the right axises space for i in range(len(inplots)): if inplots[i] == None: continue doExist = False if ("TH2D" in inplots[i].ClassName()): continue if ("TH" not in inplots[i].ClassName()): legend.AddEntry(inplots[i], inlabel[i], "LPS") continue inplots[i] = CopyHist(inplots[i]) legend.AddEntry(inplots[i], inlabel[i], "LPS") thismax = inplots[i].GetMaximum() thismin = inplots[i].GetMinimum() if maxval < thismax: maxval = thismax if (minval >= thismin): minval = thismin inplots[i].GetYaxis().SetTitleOffset( inplots[i].GetYaxis().GetTitleOffset() * 1.1) for i in range(len(instacks)): ## scale the MC if instacks[i] == None: continue doExist = False instacks[i] = CopyHist(instacks[i]) if ((i != len(instacks) - 1) and self.CompareData): instacks[i].Scale(self.DrawScale) legend.AddEntry(instacks[i], instacklabel[i], 'f') if ((i == len(instacks) - 1) and self.CompareData): legend.AddEntry(instacks[i], instacklabel[i]) instacks[i].GetYaxis().SetTitleOffset( instacks[i].GetYaxis().GetTitleOffset() * 1.1) thismax = instacks[i].GetMaximum() thismin = instacks[i].GetMinimum() if maxval < thismax: maxval = thismax if (minval >= thismin and thismin != 0): minval = thismin if doExist: return if minval <= 1.0: minval = 1.0 ###### draw histogram Canv = ROOT.TCanvas('Canv_' + title, 'Canv_' + title, 0, 0, 800, 600) if (self.CompareData): Pad1 = ROOT.TPad('Pad1', 'Pad1', 0.0, 0.25, 1.0, 0.99, 0) Pad2 = ROOT.TPad('Pad2', 'Pad2', 0.0, 0.00, 1.0, 0.32, 0) Pad2.SetBottomMargin(0.4) Pad1.Draw() Pad2.Draw() Pad1.cd() ncolor = 0 for i in range(len(instacks)): if instacks[i] == None: ncolor += 1 continue instacks[i].SetMarkerColor(self.colorlist[ncolor]) instacks[i].SetFillColor(self.colorlist[ncolor]) instacks[i].SetFillStyle(self.FillStyle) instacks[i].SetLineColor(self.colorlist[ncolor]) instacks[i].SetLineColor(1) instacks[i].SetLineWidth(1) instacks[i].GetXaxis().SetTitle(axisname[0]) instacks[i].GetYaxis().SetTitle(axisname[1]) if (self.doRescale and not (self.doLogY)): instacks[i].GetYaxis().SetRangeUser(0, maxval * 4.5 / 3.) if (self.doRescale and self.doLogY): instacks[i].GetYaxis().SetRangeUser(minval / 100., maxval * 10.) ncolor += 1 for i in range(len(inplots)): if self.CompareData: XaxisTitle = inplots[i].GetXaxis().GetTitle() labelsize = inplots[i].GetXaxis().GetLabelSize() inplots[i].SetTitle("") inplots[i].GetXaxis().SetLabelSize(0) if i == len(inplots) - 1: if ("TH" not in inplots[i].ClassName()): inplots[i].Draw("") else: inplots[i].Draw("e") inplots[i].SetLineColor(1) inplots[i].SetMarkerColor(1) #inplots[i].SetFillColor(1) continue if i == len(inplots) - 2: if ("TH" not in inplots[i].ClassName()): inplots[i].Draw("same") else: inplots[i].Draw("e same") inplots[i].SetMarkerStyle(20) inplots[i].SetMarkerColor(2) inplots[i].SetLineColor(2) #### pay attention ## Pad2.cd() relsize = Pad2.GetAbsHNDC() / Pad1.GetAbsHNDC() size = Atlas.tsize / relsize Ratio = None if self.doDiff: Fit = None if ("TH" not in inplots[i].ClassName()): Ratio = deepcopy(inplots[len(inplots) - 1]) PreBinInt = Ratio.Integral() Fit = deepcopy(inplots[i]) else: Fit = deepcopy(inplots[len(inplots) - 1]) Ratio = deepcopy(inplots[i]) PreBinInt = Ratio.Integral() data = deepcopy(Ratio) Ratio.Add(Fit, -1) Ratio.Rebin(5) data.Rebin(5) Ratio.Divide(data) try: Fit.Rebin(5) except AttributeError: None else: Ratio = deepcopy(inplots[len(inplots) - 1]) Ratio.Divide(inplots[i]) Ratio.SetTitle("") Ratio.GetXaxis().SetLabelSize(size) Ratio.GetYaxis().SetLabelSize(size) Ratio.GetXaxis().SetTitleSize(size) Ratio.GetYaxis().SetTitleSize(size) Ratio.GetXaxis().SetTitleOffset( Ratio.GetXaxis().GetTitleOffset() * relsize * 2.9) Ratio.GetXaxis().SetLabelOffset(0.03) Ratio.GetYaxis().SetTitleOffset( Ratio.GetYaxis().GetTitleOffset() * relsize) Ratio.GetYaxis().SetTitle(self.DrawRatio) Ratio.GetXaxis().SetTitle(XaxisTitle) Ratio.GetYaxis().SetNdivisions(4) if self.doDiff: Ratio.GetYaxis().SetRangeUser(-0.2, 0.2) else: Ratio.GetYaxis().SetRangeUser(0.5, 1.5) Ratio.SetMarkerColor(1) Ratio.SetLineColor(1) Ratio.GetYaxis().SetNdivisions(5, ROOT.kFALSE) if sys == []: Ratio.Draw('e') else: Ratio.Draw('e') sys[0].SetFillStyle(3004) sys[0].SetFillColor(1) sys[0].SetMarkerStyle(10) sys[0].SetMarkerSize(0) if sys[0].GetBinError(1) != 0: sys[0].Draw("e2 same") if len(sys) > 1: sys[1].SetFillStyle(3004) sys[1].SetFillColor(2) sys[1].SetMarkerStyle(10) sys[1].SetMarkerSize(0) sys[1].SetLineColor(2) sys[1].SetLineWidth(2) sys[1].Draw("e2 same") if Ratio != None: line.Draw("same") Pad1.cd() continue if inplots[i] == None: continue inplots[i].SetMarkerColor(self.colorlist[ncolor]) #inplots[i].SetFillColor(self.colorlist[ncolor]) inplots[i].SetLineColor(self.colorlist[ncolor]) inplots[i].GetXaxis().SetTitle(axisname[0]) inplots[i].GetYaxis().SetTitle(axisname[1]) if (self.doRescale and not (self.doLogY)): inplots[i].GetYaxis().SetRangeUser(0, maxval * 4.5 / 3.) if (self.doRescale and self.doLogY): inplots[i].GetYaxis().SetRangeUser(minval / 100., maxval * 10.) ncolor += 1 count = 0 for i in range(len(inplots)): if inplots[i] == None: continue inplots[i].SetTitle("") if count != 0: self.drawOption = "same" if inplots[i].ClassName() != "TH2D": inplots[i].Draw(self.drawOption) else: inplots[i].Draw("colz") count += 1 count = 0 for i in range(len(instacks)): if instacks[i] == None: continue if "TH2" not in (instacks[i].ClassName()): #instacks[i].GetYaxis().SetMaxDigits(3) if count == 0: instacks[i].SetTitle("") if self.CompareData: instacks[i].GetXaxis().SetLabelSize(0) instacks[i].GetXaxis().SetTitle("") instacks[i].Draw("hist") count += 1 continue else: if self.CompareData: XaxisTitle = instacks[i].GetXaxis().GetTitle() labelsize = instacks[i].GetXaxis().GetLabelSize() instacks[i].SetTitle("") instacks[i].GetXaxis().SetLabelSize(0) if i == len(instacks) - 1: instacks[i].Draw("e same") instacks[i].SetLineColor(1) instacks[i].SetLineWidth(2) instacks[i].SetMarkerColor(1) instacks[i].SetFillColor(0) #### pay attention ## DataIntError = ROOT.Double(0) DataInt = instacks[i].IntegralAndError( 0, instacks[i].GetNbinsX() + 1, DataIntError) MCIntError = ROOT.Double(0) MCInt = instacks[i - 1].IntegralAndError( 0, instacks[i - 1].GetNbinsX() + 1, MCIntError) if MCInt == 0: MCInt = 1 print(" warning: no mc") if DataInt == 0: DataInt = 1 print(" warning: no data") rat = DataInt / MCInt rerr = sqrt((DataIntError / DataInt)**2 + (MCIntError / MCInt)**2) * rat #Atlas.myText(0.7, 0.45, 1, 0.04, "Data / MC = " + str(round(rat, 3)) +"#pm" + str(round(rerr,3))) count += 1 #continue if i == len(instacks) - 2: instacks[i].SetMarkerStyle(10) instacks[i].SetFillStyle(3004) instacks[i].SetMarkerSize(0.00001) instacks[i].SetFillColor(1) instacks[i].SetLineWidth(0) instacks[i].Draw("e2 same") #print instacklabel[i], len(instacklabel) Pad2.cd() relsize = Pad2.GetAbsHNDC() / Pad1.GetAbsHNDC() size = Atlas.tsize / relsize Ratio = CopyHist(instacks[len(instacks) - 1]) line = 0 if Ratio == None: continue if Ratio != None: line = ROOT.TLine( Ratio.GetXaxis().GetBinLowEdge(1), 1, Ratio.GetXaxis().GetBinUpEdge( Ratio.GetNbinsX()), 1) Ratio.Divide(instacks[i]) Ratio.SetTitle("") Ratio.GetXaxis().SetLabelSize(size) Ratio.GetYaxis().SetLabelSize(size) Ratio.GetXaxis().SetTitleSize(size) Ratio.GetYaxis().SetTitleSize(size) Ratio.GetXaxis().SetTitleOffset( Ratio.GetXaxis().GetTitleOffset() * relsize * 2.9) Ratio.GetXaxis().SetLabelOffset(0.03) Ratio.GetYaxis().SetTitleOffset( Ratio.GetYaxis().GetTitleOffset() * relsize) Ratio.GetYaxis().SetTitle(self.DrawRatio) Ratio.GetXaxis().SetTitle(XaxisTitle) Ratio.GetYaxis().SetRangeUser(0.5, 1.5) Ratio.GetYaxis().SetNdivisions(4) Ratio.SetMarkerColor(1) Ratio.SetLineColor(1) Ratio.SetLineWidth(2) Ratio.GetYaxis().SetNdivisions(5, ROOT.kFALSE) if sys == []: Ratio.Draw('e') elif len(sys) > 1: Ratio.Draw('e') sys[1].SetFillStyle(3001) sys[1].SetFillColor(30) sys[1].SetMarkerStyle(10) sys[1].SetMarkerSize(0) sys[1].SetLineColor(2) sys[1].SetLineWidth(2) sys[1].Draw("e2 same") sys[0].SetFillStyle(3004) sys[0].SetFillColor(1) sys[0].SetMarkerStyle(10) sys[0].SetLineWidth(2) sys[0].SetMarkerSize(0) if sys[0].GetBinError(1) != 0: sys[0].Draw("e2 same") Ratio.Draw('e same') else: Ratio.Draw('e') sys[0].SetFillStyle(3004) sys[0].SetFillColor(1) sys[0].SetMarkerStyle(10) sys[0].SetLineWidth(2) sys[0].SetMarkerSize(0) sys[0].Draw("e2 same") # if Ratio != None: # line.Draw("same") Pad1.cd() count += 1 continue instacks[i].Draw("hist same") else: if i == len(instacks) - 1: instacks[i].SetMarkerStyle(10) instacks[i].SetFillStyle(3020) instacks[i].Draw("e2 same") count += 1 continue instacks[i].Draw("hist same") ##### draw 2d else: instacks[i].SetTitle("") instacks[i].Draw('cont') count += 1 if ((instacks != [] and instacks[-1] != None and ("TH2" not in (instacks[-1].ClassName()))) or (inplots != [] and inplots[-1] != None and ("TH2" not in (inplots[-1].ClassName())))): legend.Draw("same") for text in self.texts: Atlas.myText(text[0], text[1], text[2], text[3], text[4]) if self.doAtlasLabel: Atlas.ATLASLabel(self.AtlasLabelPos, 0.88, self.shift, self.studytype, color=1) if self.doLabel and self.lumi != "0": Atlas.myText(self.AtlasLabelPos, 0.81, color=1, size=0.04, text="#sqrt{s}=" + self.sqrtS + " TeV " + "#intLdt=" + self.lumi + " fb^{-1}") if self.doLabel and self.lumi == "0": Atlas.myText(self.AtlasLabelPos, 0.81, color=1, size=0.04, text="#sqrt{s}=" + self.sqrtS + " TeV") if self.doLogY: Canv.SetLogy() if self.doLogX: Canv.SetLogx() if self.doLogZ: Canv.SetLogz() Canv.Write() if (self.doPrintPlots): Canv.SaveAs(self.OutPlotDir + Canv.GetName() + ".png") Canv.Close() return inplots
# # effPt = h_triggers[iT].GetXaxis().GetBinLowEdge( effBin ) leg = ROOT.TLegend(0.6, 0.4, 0.9, 0.9) leg.AddEntry( h_triggers[0], "Data "+trigger, "l") leg.AddEntry( h_triggers[2], "MC", "l") leg.AddEntry( h_triggers[4], "Biased MC", "l") h_triggers[0].Draw() h_triggers[2].Draw("same") h_triggers[4].Draw("same") AtlasStyle.ATLAS_LABEL(0.3,0.34, 1," Internal") AtlasStyle.myText(0.3,0.28,1, "#sqrt{s} = 13 TeV, 3.6 fb^{-1}") # AtlasStyle.myText(0.3,0.22,2, "99.5\% Efficient: %.0f GeV" %(effPt[0]) ) AtlasStyle.myText(0.3,0.22,2, "Data: %.0f, MC: %.0f, MCbiased: %.0f GeV" %(effPt[0], effPt[2], effPt[4]) ) leg.Draw("same") plotName = upDir+'/combinedPlots/'+histName[0]+'_Recoil_'+trigger+'.png' # plotName += h_data_triggers[iT].GetName()+'.png' c1.SaveAs(plotName); c1.Clear(); h_triggers[1].Draw() h_triggers[3].Draw("same") h_triggers[5].Draw("same")
# mc_effBin = h_mc_triggers[iT].FindFirstBinAbove(0.995) #### # # effPt = h_triggers[iT].GetXaxis().GetBinLowEdge( effBin ) leg = ROOT.TLegend(0.6, 0.4, 0.9, 0.9) leg.AddEntry(h_triggers[0], "Data " + trigger, "l") leg.AddEntry(h_triggers[2], "MC", "l") leg.AddEntry(h_triggers[4], "Biased MC", "l") h_triggers[0].Draw() h_triggers[2].Draw("same") h_triggers[4].Draw("same") AtlasStyle.ATLAS_LABEL(0.3, 0.34, 1, " Internal") AtlasStyle.myText(0.3, 0.28, 1, "#sqrt{s} = 13 TeV, 3.6 fb^{-1}") # AtlasStyle.myText(0.3,0.22,2, "99.5\% Efficient: %.0f GeV" %(effPt[0]) ) AtlasStyle.myText( 0.3, 0.22, 2, "Data: %.0f, MC: %.0f, MCbiased: %.0f GeV" % (effPt[0], effPt[2], effPt[4])) leg.Draw("same") plotName = upDir + '/combinedPlots/' + histName[ 0] + '_Recoil_' + trigger + '.png' # plotName += h_data_triggers[iT].GetName()+'.png' c1.SaveAs(plotName) c1.Clear() h_triggers[1].Draw()
def DrawCorrelation(var, labels, model, varname): f = ROOT.TFile("corr_"+varname+".root", "recreate") #b_hist = ROOT.TH1D("corr_score_b_"+varname, "corr_score_b_"+varname, 15, 0.5, 15.5) #c_hist = ROOT.TH1D("corr_score_c_"+varname, "corr_score_c_"+varname, 15, 0.5, 15.5) #l_hist = ROOT.TH1D("corr_score_l_"+varname, "corr_score_l_"+varname, 15, 0.5, 15.5)# bjet_var = var[ labels[:,0]==5] cjet_var = var[ labels[:,0]==4] ljet_var = var[ labels[:,0]==0] bjet_score = model.pred[labels[:,0]==5] cjet_score = model.pred[labels[:,0]==4] ljet_score = model.pred[labels[:,0]==0] def loop(var, score): print var.shape print score.shape itrk_list = [] corr_list = [] for itrk in range(15): var_thistrk = [] score_thistrk = [] score_thistrk = score[ var[:, itrk] !=0 ] var_thistrk = var[ var[:, itrk] !=0, itrk] #hist.SetBinContent(itrk+1, pearsonr(var_thistrk, score_thistrk)[0] ) print pearsonr(var_thistrk, score_thistrk)[0] itrk_list.append(itrk+1) corr_list.append(pearsonr(var_thistrk, score_thistrk)[0] ) return ROOT.TGraph(15, array.array('d', itrk_list), array.array('d', corr_list)) b_hist= loop(bjet_var, bjet_score) c_hist = loop(cjet_var, cjet_score) l_hist = loop(ljet_var, ljet_score) f.cd() canvas = ROOT.TCanvas(varname, varname, 800, 600) canvas.cd() b_hist.SetLineColor( colorind[0]) b_hist.SetMarkerColor( colorind[0]) b_hist.SetMarkerStyle(20) b_hist.SetMarkerSize(1) b_hist.SetLineWidth( 3) c_hist.SetLineColor( colorind[1]) c_hist.SetMarkerColor( colorind[1]) c_hist.SetLineWidth( 3) c_hist.SetMarkerStyle(21) c_hist.SetMarkerSize(1) l_hist.SetLineColor( colorind[2]) l_hist.SetMarkerColor( colorind[2]) l_hist.SetLineWidth( 3) l_hist.SetMarkerStyle(22) l_hist.SetMarkerSize(1) legend = ROOT.TLegend(0.5, 0.5, 0.75, 0.75) legend.AddEntry(b_hist, "b-jets", "lp") legend.AddEntry(c_hist, "c-jets", "lp") legend.AddEntry(l_hist, "light-jets", "lp") mg = ROOT.TMultiGraph() mg.Add(b_hist) mg.Add(c_hist) mg.Add(l_hist) mg.Draw("APL") mg.GetXaxis().SetTitle("i^{th} track in sequence") mg.GetYaxis().SetTitle("Correlation, #rho(D_{RNN}, "+varname+")") legend.Draw("same") Atlas.ATLASLabel(0.2, 0.88,0.13, "Simulation Internal",color=1) Atlas.myText(0.2, 0.81 ,color=1, size=0.04,text="#sqrt{s}=13 TeV, t#bar{t}") Atlas.myText(0.2, 0.75 ,color=1, size=0.04,text="p_{T}>20 GeV, |#eta|<2.5") #Atlas.myText(0.2, 0.69 ,color=1, size=0.04,text="Rel21") canvas.Draw() canvas.Write()
def print_single_min(vec_beg, vec_end, name, text): total_beg = vec_beg[0].Clone() c = 0 for v in vec_beg: if c != 0: total_beg.Add(vec_beg[c]) c = c + 1 norm = 1/total_beg.Integral() total_beg.Scale(norm) if 'buff' in name: legb = TLegend(0.25,0.93,0.90,0.60) legb.SetNColumns(5) else: legb = TLegend(0.60,0.80,0.90,0.60) legb.SetNColumns(2) legb.SetLineColor(0) legb.SetFillStyle(0) legb.SetShadowColor(0) legb.SetBorderSize(0) if 'buff' in name: lege = TLegend(0.25,0.93,0.90,0.60) lege.SetNColumns(5) else: lege = TLegend(0.22,0.90,0.52,0.70) lege.SetNColumns(2) lege.SetLineColor(0) lege.SetFillStyle(0) lege.SetShadowColor(0) lege.SetBorderSize(0) #vec_beg = sorted(vec_beg, key=lambda x: x.Integral(), reverse=True) stack1 = THStack("stack1","stack1") for v in vec_beg: if v.Integral() != 0: v.Scale(norm) legb.AddEntry(v, v.GetTitle()[4:], "f") stack1.Add(v) total_end = vec_end[0].Clone() c = 0 for v in vec_end: if c != 0: total_end.Add(vec_end[c]) c = c + 1 norm = 1/total_end.Integral() total_end.Scale(norm) stack2 = THStack("stack2","stack2") for v in vec_end: if v.Integral() != 0: v.Scale(norm) lege.AddEntry(v, v.GetTitle()[4:], "f") stack2.Add(v) total_beg.SetLineColor(kRed) total_beg.SetLineWidth(1) total_end.SetLineColor(kRed) total_end.SetLineWidth(1) total_beg.GetXaxis().SetTitle("Minutes after stable beams declared [min]") total_end.GetXaxis().SetTitle("Minutes before stable beams ended [min]") if '0_4' in name: total_beg.GetYaxis().SetTitle("Arbitrary units / 3 mins") total_end.GetYaxis().SetTitle("Arbitrary units / 3 mins") else: total_beg.GetYaxis().SetTitle("Arbitrary units / 5 mins") total_end.GetYaxis().SetTitle("Arbitrary units / 5 mins") c4 = TCanvas( 'c4', 'c4',1000, 1200) c4.Divide(1,2) c4.cd(1) total_beg.Draw("HIST") stack1.Draw("PFC PLC SAME HIST") total_beg.Draw("SAMEHIST") AtlasStyle.ATLAS_LABEL(0.18,.96, 1, "Internal") AtlasStyle.myText(0.40, 0.96, kBlack, text) legb.Draw() c4.cd(2) total_end.Draw("HIST") stack2.Draw("PFC PLC SAME HIST") total_end.Draw("SAMEHIST") AtlasStyle.ATLAS_LABEL(0.18,.96, 1, "Internal") AtlasStyle.myText(0.40, 0.96, kBlack, text) lege.Draw() c4.Update() c4.Print("plots/"+name+".pdf")
def main(): # METOverHT function func1 = ROOT.TF1("func1", "TMath::Max(5., 15.-2.*x)", 0, 30) func1.SetLineColor(ROOT.kRed) # 2-D histograms for NUHM2 hist_m12_350 = ROOT.TH2F("hist_m12_350", "", 300, 0., 30., 500, 0., 50) hist_m12_400 = ROOT.TH2F("hist_m12_400", "", 300, 0., 30., 500, 0., 50) hist_m12_500 = ROOT.TH2F("hist_m12_500", "", 300, 0., 30., 500, 0., 50) hist_m12_600 = ROOT.TH2F("hist_m12_600", "", 300, 0., 30., 500, 0., 50) hist_m12_700 = ROOT.TH2F("hist_m12_700", "", 300, 0., 30., 500, 0., 50) hist_m12_800 = ROOT.TH2F("hist_m12_800", "", 300, 0., 30., 500, 0., 50) get_histogram(path + files['sigFile'], "MGPy8EG_A14N23LO_NUHM2_m12_350_weak_NoSys", hist_m12_350) get_histogram(path + files['sigFile'], "MGPy8EG_A14N23LO_NUHM2_m12_400_weak_NoSys", hist_m12_400) get_histogram(path + files['sigFile'], "MGPy8EG_A14N23LO_NUHM2_m12_500_weak_NoSys", hist_m12_500) get_histogram(path + files['sigFile'], "MGPy8EG_A14N23LO_NUHM2_m12_600_weak_NoSys", hist_m12_600) get_histogram(path + files['sigFile'], "MGPy8EG_A14N23LO_NUHM2_m12_700_weak_NoSys", hist_m12_700) get_histogram(path + files['sigFile'], "MGPy8EG_A14N23LO_NUHM2_m12_800_weak_NoSys", hist_m12_800) hist_m12_350.SetMarkerStyle(ROOT.kFullCircle) hist_m12_400.SetMarkerStyle(ROOT.kFullCircle) hist_m12_500.SetMarkerStyle(ROOT.kFullCircle) hist_m12_600.SetMarkerStyle(ROOT.kFullCircle) hist_m12_700.SetMarkerStyle(ROOT.kFullCircle) hist_m12_800.SetMarkerStyle(ROOT.kFullCircle) hist_m12_350.SetMarkerColor(ROOT.kAzure) hist_m12_400.SetMarkerColor(ROOT.kMagenta) hist_m12_500.SetMarkerColor(ROOT.kRed) hist_m12_600.SetMarkerColor(ROOT.kYellow) hist_m12_700.SetMarkerColor(ROOT.kGreen) hist_m12_800.SetMarkerColor(ROOT.kCyan) hist_m12_350.SetMarkerSize(1.0) hist_m12_400.SetMarkerSize(1.0) hist_m12_500.SetMarkerSize(1.0) hist_m12_600.SetMarkerSize(1.0) hist_m12_700.SetMarkerSize(1.0) hist_m12_800.SetMarkerSize(1.0) # 2-D histograms for backgrounds hist_total_bkg = ROOT.TH2F("hist_total_bkg", "", 6, 0., 30., 10, 0., 50.) hist_diboson = ROOT.TH2F("hist_diboson", "", 6, 0., 30., 10, 0., 50.) hist_fakes = ROOT.TH2F("hist_fakes", "", 6, 0., 30., 10, 0., 50.) hist_other = ROOT.TH2F("hist_other", "", 6, 0., 30., 10, 0., 50.) hist_top = ROOT.TH2F("hist_top", "", 6, 0., 30., 10, 0., 50.) hist_Zttjets = ROOT.TH2F("hist_Zttjets", "", 6, 0., 30., 10, 0., 50.) get_histogram(path + files['dibosonFile'], "diboson_NoSys", hist_diboson) get_histogram(path + files['fakesFile'], "fakes_NoSys", hist_fakes) get_histogram(path + files['otherFile'], "other_NoSys", hist_other) get_histogram(path + files['topFile'], "top_NoSys", hist_top) get_histogram(path + files['ZttjetsFile'], "Zttjets_NoSys", hist_Zttjets) hist_total_bkg.Add(hist_diboson) hist_total_bkg.Add(hist_fakes) hist_total_bkg.Add(hist_other) hist_total_bkg.Add(hist_top) hist_total_bkg.Add(hist_Zttjets) # Making plot c1 = ROOT.TCanvas("c1", "", 800, 800) ROOT.gStyle.SetOptStat(0) ROOT.gPad.SetBottomMargin(0.15) ROOT.gPad.SetRightMargin(0.05) ROOT.gPad.SetLeftMargin(0.15) hist_total_bkg.SetLineColor(ROOT.kBlack) hist_total_bkg.SetFillColor(ROOT.kWhite) hist_total_bkg.SetFillStyle(0) #hollow hist_total_bkg.GetXaxis().SetTitle("m_{#font[12]{l}#font[12]{l}} [GeV]") hist_total_bkg.GetXaxis().SetTitleOffset(1.3) hist_total_bkg.GetXaxis().SetTitleSize(0.05) hist_total_bkg.GetYaxis().SetTitle("E_{T}^{miss}/H_{T}^{lep}") hist_total_bkg.GetYaxis().SetTitleOffset(1.3) hist_total_bkg.GetYaxis().SetTitleSize(0.05) hist_total_bkg.Draw("box") hist_m12_350.Draw("same") hist_m12_400.Draw("same") hist_m12_500.Draw("same") hist_m12_600.Draw("same") hist_m12_700.Draw("same") hist_m12_800.Draw("same") func1.Draw("same") # AtlasStyle.ATLASLabel(0.2, 0.83, "Internal", ROOT.kBlack) # AtlasStyle.myText(0.2, 0.78, "13 TeV, 36.1 fb^{-1}", ROOT.kBlack, 0.04) AtlasStyle.myText(0.2, 0.83, "13 TeV, 36.1 fb^{-1}", ROOT.kBlack, 0.04) legend_total_bkg = "Total Background" legend_m12_350 = "NUHM2 m_{1/2}=350 GeV #Delta m(#tilde{#chi}^{0}_{2}, #tilde{#chi}^{0}_{1})=46.06 GeV" legend_m12_400 = "NUHM2 m_{1/2}=400 GeV #Delta m(#tilde{#chi}^{0}_{2}, #tilde{#chi}^{0}_{1})=38.17 GeV" legend_m12_500 = "NUHM2 m_{1/2}=500 GeV #Delta m(#tilde{#chi}^{0}_{2}, #tilde{#chi}^{0}_{1})=28.02 GeV" legend_m12_600 = "NUHM2 m_{1/2}=600 GeV #Delta m(#tilde{#chi}^{0}_{2}, #tilde{#chi}^{0}_{1})=22.05 GeV" legend_m12_700 = "NUHM2 m_{1/2}=700 GeV #Delta m(#tilde{#chi}^{0}_{2}, #tilde{#chi}^{0}_{1})=18.19 GeV" legend_m12_800 = "NUHM2 m_{1/2}=800 GeV #Delta m(#tilde{#chi}^{0}_{2}, #tilde{#chi}^{0}_{1})=15.49 GeV" legend = ROOT.TLegend(0.54, 0.6, 0.94, 0.87) legend.AddEntry(hist_total_bkg, legend_total_bkg, "f") legend.AddEntry(hist_m12_350, legend_m12_350, "p") legend.AddEntry(hist_m12_400, legend_m12_400, "p") legend.AddEntry(hist_m12_500, legend_m12_500, "p") legend.AddEntry(hist_m12_600, legend_m12_600, "p") legend.AddEntry(hist_m12_700, legend_m12_700, "p") legend.AddEntry(hist_m12_800, legend_m12_800, "p") # legend.SetBorderSize(0); legend.SetTextFont(42) legend.SetTextSize(0.015) # legend.SetFillColor(0); # legend.SetFillStyle(0); legend.Draw() # output = "METOverHT_vs_mll.pdf" output2 = "METOverHT_vs_mll.png" # c1.SaveAs(output) c1.SaveAs(output2)
def combinedPlotNominal(files, normalize, ratio): files = files.split(',') dataFile = [file for file in files if ".data." in file][0] files.remove(dataFile) files.insert(0, dataFile) if any("Pythia" in file for file in files): pythiaFile = [file for file in files if "Pythia" in file][0] files.remove(pythiaFile) files.insert(1, pythiaFile) if any("Sherpa" in file for file in files): sherpaFile = [file for file in files if "Sherpa" in file][0] files.remove(sherpaFile) files.insert(2, sherpaFile) # Save output to directory of first file outDir = dataFile[:-5] + '/' if not os.path.exists(outDir): os.mkdir(outDir) if normalize: outDir += "combinedPlotNominal_normalized/" else: outDir += "combinedPlotNominal/" if not os.path.exists(outDir): os.mkdir(outDir) if not os.path.exists(outDir + '/eps'): os.mkdir(outDir + '/eps') AtlasStyle.SetAtlasStyle() gROOT.ProcessLine("gErrorIgnoreLevel = 2000") #Ignore TCanvas::Print info inFiles = [] nomDirs = [] for file in files: inFiles.append(TFile.Open(file, "READ")) keyList = [key.GetName() for key in inFiles[-1].GetListOfKeys() ] #List of top level objects dirList = [key for key in keyList if "Iteration" in key] #List of all directories nomDir = [dir for dir in dirList if "Nominal" in dir] if (not len(nomDir) == 1): print "Error, nominal directories are ", nomDir return else: nomDirs.append(inFiles[-1].Get(nomDir[0])) c1 = TCanvas() ################ Set Color Palate ####################3 # Data, Herwig, Pythia8, Sherpa colors = [kBlack, kRed, kBlue, kViolet, kCyan] markers = [20, 21, 23, 22, 33, 34] # colorMax = 240. # colorMin = 0. #20. # numInputs = len( nomDirs ) # colors = [] # if len(nomDirs) == 2: # colors = [kBlack, kRed] # else: # for iDir, nomDir in enumerate(nomDirs): # colorNum = int( colorMin+(colorMax-colorMin)*iDir/numInputs) # colors.append( gStyle.GetColorPalette( colorNum )) ##################### Plot All Nominal ################################# print "Plotting nominal hists " oneLine = TF1("zl1", "1", -10000, 10000) oneLine.SetTitle("") oneLine.SetLineWidth(1) oneLine.SetLineStyle(2) oneLine.SetLineColor(kBlack) histList = [key.GetName() for key in nomDirs[0].GetListOfKeys()] for histName in histList: if "prof_" in histName or "ptSlice" in histName: continue tmpHist = nomDirs[0].Get(histName) if not type(tmpHist) == TH1F and not type( tmpHist) == TH1D and not type( tmpHist) == TGraphErrors: #Can't draw bands if not 1D continue leg = TLegend(0.65, 0.72, 0.9, 0.93) leg.SetFillStyle(0) leg.SetTextFont(42) #! leg = TLegend(0.83, 0.15, 0.99, 0.95) if ratio: pad1 = TPad("pad1", "", 0, 0.32, 1, 1) pad2 = TPad("pad2", "", 0, 0, 1, 0.32) #! pad1 = TPad("pad1", "", 0, 0.3, 0.83, 1) #! pad2 = TPad("pad2", "", 0, 0, 0.83, 0.3) pad1.SetBottomMargin(0.01) pad2.SetTopMargin(0) pad2.SetBottomMargin(0.45) pad1.Draw() pad2.Draw() else: #! pad1 = TPad("pad1", "", 0, 0, 0.83, 1) pad1.Draw() pad1.cd() nomHists = [] drawString = "" maxVal = [] maxBinX = [] for iDir, nomDir in enumerate(nomDirs): thisFileStr = files[iDir].split('.')[2] if "all" in thisFileStr: thisFileStr = files[iDir].split('.')[1] nomHist = nomDir.Get(histName) nomHist.SetName(nomHist.GetName()) if "Beta" in histName: nomHist.Rebin(2) if "alpha" in histName: nomHist.Rebin(4) if "ptAsym" in histName: nomHist.Rebin(4) if "Eta" in histName and not type(nomHist) == TGraphErrors: nomHist.Rebin(4) if ("recoilPt" in histName): for iBin in range(1, nomHist.GetNbinsX() + 1): nomHist.SetBinContent( iBin, nomHist.GetBinContent(iBin) / nomHist.GetBinWidth(iBin)) if normalize and not type( nomHist) == TGraphErrors and nomHist.Integral() > 0.: nomHist.Scale(1. / nomHist.Integral()) if "Sherpa" in files[iDir] and "MJB" in histName: for iBin in range(31, nomHist.GetNbinsX() + 1): nomHist.SetBinContent(iBin, 0) nomHist.SetBinError(iBin, 0) nomHist.SetLineColor(colors[iDir]) nomHist.SetMarkerColor(colors[iDir]) nomHist.SetMarkerStyle(markers[iDir]) thisEntry = leg.AddEntry( nomHist, thisFileStr.replace('d', 'D').replace( 'Sherpa', 'Sherpa 2.1').replace('Herwig', 'Herwig++'), "lp") thisEntry.SetTextColor(colors[iDir]) #nomHist.SetMinimum(0.9) # if( "jetPt" in histName or "jetEnergy" in histName): # maxBinX.append(nomHist.FindLastBinAbove(0)+1) # nomHist.SetMaximum(1.5*nomHist.GetMaximum()) # nomHist.SetMinimum(0.000101) # else: nomHist.SetMaximum(1.5 * nomHist.GetMaximum()) #nomHist.SetMinimum(0.000101) if ("MJB" in histName): nomHist.SetMinimum(0.0000101) #nomHist.GetXaxis().SetRangeUser( 500, 2800 ) #!!public #nomHist.SetMaximum(1.06) #!!public #nomHist.SetMinimum(0.9701) #!!public nomHist.GetXaxis().SetRangeUser(300, 2800) nomHist.SetMaximum(1.2) nomHist.SetMinimum(0.8999) nomHist.GetXaxis().SetMoreLogLabels(True) nomHist.GetYaxis().SetTitle( "#LT p_{T}^{lead jet}/p_{T}^{recoil} #GT") nomHist.GetYaxis().SetTitleSize(0.09) nomHist.GetYaxis().SetTitleOffset(0.7) nomHist.GetYaxis().SetLabelSize(0.06) nomHist.GetYaxis().SetLabelOffset(0.01) nomHist.SetMarkerSize(.8) nomHist.SetLineWidth(1) elif ("Pt" in histName): nomHist.GetYaxis().SetTitle("AU") if ("jet0" in histName): nomHist.GetXaxis().SetRangeUser(200, 2000) else: nomHist.GetXaxis().SetRangeUser(0, 800) else: nomHist.GetYaxis().SetTitle("AU") if ("recoilPt" in histName): nomHist.GetYaxis().SetTitle("1/N dp_{T}^{recoil}/dN") nomHist.GetXaxis().SetRangeUser(300, 3000) if not type(nomHist) == TGraphErrors: #drawString = "histsamep" drawString = "psame" else: drawString = "apsame" nomHist.SetMarkerStyle(33) nomHist.SetMarkerSize(1.5) nomHist.SetLineWidth(4) nomHists.append(nomHist) maxVal.append(nomHist.GetMaximum()) maxDir = maxVal.index(max(maxVal)) nomHists[maxDir].Draw(drawString) if maxBinX: maxBinX = max(maxBinX) for iDir, nomDir in enumerate(nomDirs): nomHists[iDir].GetXaxis().SetRange(1, maxBinX) for iDir, nomDir in enumerate(nomDirs): nomHists[iDir].Draw(drawString) oneLine.Draw("same") for iDir, nomDir in enumerate(nomDirs): nomHists[iDir].Draw(drawString) nomHists[0].Draw(drawString) ## Draw data on top if ratio: pad2.cd() ratioHists = [] for iDir in range(1, len(nomDirs)): #ratioHists.append( nomHists[0].Clone() ) #ratioHists[iDir-1].Add(nomHists[iDir], -1.) #ratioHists[iDir-1].Divide(nomHists[iDir]) ratioHists.append(nomHists[iDir].Clone()) ratioHists[iDir - 1].Divide(nomHists[0]) ratioHists[iDir - 1].SetMarkerColor(colors[iDir]) ratioHists[iDir - 1].SetMarkerStyle(markers[iDir]) ratioHists[iDir - 1].SetLineColor(colors[iDir]) if iDir == 1: ratioHists[iDir - 1].SetMaximum(2) ratioHists[iDir - 1].SetMinimum(0.5) ratioHists[iDir - 1].GetXaxis().SetLabelOffset(.015) ratioHists[iDir - 1].GetXaxis().SetTitleOffset(1.3) ratioHists[iDir - 1].GetXaxis().SetLabelSize(0.13) ratioHists[iDir - 1].GetXaxis().SetTitleSize(0.16) # ratioHists[iDir-1].GetXaxis().SetTitle(nomHists[0].GetXaxis().GetTitle()); ratioHists[iDir - 1].GetXaxis().SetMoreLogLabels() ratioHists[iDir - 1].GetYaxis().SetLabelSize(0.13) ratioHists[iDir - 1].GetYaxis().SetTitleSize(0.16) ratioHists[iDir - 1].GetYaxis().SetLabelOffset(.01) ratioHists[iDir - 1].GetYaxis().SetTitleOffset(0.37) #ratioHists[iDir-1].GetYaxis().SetTitle("Significance") ratioHists[iDir - 1].GetYaxis().SetTitle(" MC / Data") ratioHists[iDir - 1].GetYaxis().SetNdivisions(7) if ("Pt" in histName): if ("jet0" in histName): ratioHists[iDir - 1].GetXaxis().SetRangeUser( 200, 2000) else: ratioHists[iDir - 1].GetXaxis().SetRangeUser( 0, 800) if ("MJB" in histName): #ratioHists[iDir-1].GetXaxis().SetRangeUser( 500, 2800 ) #!!public ratioHists[iDir - 1].GetXaxis().SetRangeUser(300, 2500) ratioHists[iDir - 1].SetMaximum(1.05) ratioHists[iDir - 1].SetMinimum(0.95) ratioHists[iDir - 1].GetXaxis().SetTitle( "p_{T}^{recoil} [GeV]") if ("recoilPt" in histName): ratioHists[iDir - 1].GetXaxis().SetRangeUser(300, 3000) ratioHists[iDir - 1].GetXaxis().SetTitle( "p_{T}^{recoil} [GeV]") # if( "jetBeta" in histName): # ratioHists[iDir-1].SetMaximum(1) # ratioHists[iDir-1].SetMinimum(-1) ratioHists[0].Draw("p") oneLine.Draw("same") for iDir in range(1, len(nomDirs)): ratioHists[iDir - 1].Draw("psame") c1.cd() leg.Draw() AtlasStyle.ATLAS_LABEL(0.2, 0.88, 1, " Preliminary") AtlasStyle.myText(0.2, 0.82, 1, "#sqrt{s} = 13 TeV, 3.3 fb^{-1}") AtlasStyle.myText(0.2, 0.76, 1, "Multijet Events") typeText = "anti-k_{t} R = 0.4" if "_LC_" in dataFile: typeText += ", LC+JES (in-situ)" else: typeText += ", EM+JES (in-situ)" AtlasStyle.myText(0.2, 0.7, 1, typeText) AtlasStyle.myText(0.2, 0.64, 1, "#left|#eta^{lead jet}#right| < 1.2") # AtlasStyle.myText(0.1,0.75,1, "m_{jj} Correction") if "MJB" in histName: pad1.SetLogx() if ratio: pad2.SetLogx() else: pad1.SetLogx(0) if ratio: pad2.SetLogx(0) #if "Pt" in histName or "alpha" in histName: pad1.SetLogy() c1.SaveAs(outDir + nomHist.GetName() + "_logy.png") c1.SaveAs(outDir + "/eps/" + nomHist.GetName() + "_logy.eps") pad1.SetLogy(0) c1.SaveAs((outDir + nomHist.GetName() + ".png")) c1.SaveAs((outDir + "/eps/" + nomHist.GetName() + ".eps")) c1.SaveAs((outDir + "/eps/" + nomHist.GetName() + ".pdf")) c1.Clear() for inFile in inFiles: inFile.Close()
def plot1D( Hists, SampleTypes ): histName = '_'.join(Hists[0].GetName().split('_')[1:] ) plotRatio = args.plotRatio ## Setup Canvas ## c0 = ROOT.TCanvas(histName) logx = False logy = False # TODO need a logXList of variables for choosing this. Get from a config file? ## #extraText=[] ## #logXList = [ "mjj", "m3j", "chi", "m12", "m13", "m23" ] # madd all two-jet mass plots have logX ## logXList = [ "chi" ] # madd all two-jet mass plots have logX ## for v in logXList: ## if v == hName: logx = True ### elif v in hName and "for_mjj" in hName : logx = True ## elif v in hName and not "__" in hName: logx = True ## if logx: hists[i].GetYaxis().SetMoreLogLabels(1) ## ## if logx: ## c0.SetLogx() ## if (plotRatio): ## pad1.SetLogx() ## pad2.SetLogx() ## else: ## c0.SetLogx(0) ## if (plotRatio): ## pad1.SetLogx(0) ## pad2.SetLogx(0) if plotRatio: pad1, pad2, zeroLine, oneLine = getRatioObjects(logx, logy) leg = configureLegend(SampleTypes, Hists) ### Configure draw string ### for iH, hist in enumerate(Hists): drawString = "" if iH != 0: drawString += 'same' drawString += 'histe' if len(args.dataType) > 0 and not "data" == SampleTypes[iH]: # not data so can make sure markers are not seen - see error bars if not "stack" == SampleTypes[iH]: Hists[iH].SetMarkerSize( 0.0 ) if not "bkg" == SampleTypes[iH]: drawString += 'fe' else: #why is this here? drawString += 'fe' else: drawString += 'ep' Hists[iH].Draw( drawString ) leg.Draw("same") AtlasStyle.ATLAS_LABEL(0.20,0.88) sqrtSLumiText = getSqrtSLumiText( args.lumi ) AtlasStyle.myText(0.20,0.82,1, sqrtSLumiText) if len(args.plotText)>0: AtlasStyle.myText(0.20,0.76,1, args.plotText) if any( extraTextString.split(',')[0] in histName for extraTextString in extraText ): extraTextString = [extraTextString for extraTextString in extraText if extraTextString.split(',')[0] in histName][0] if len(args.plotText)>0: AtlasStyle.myText(0.20,0.64, 1,extraTextString.split(',')[1]) else: AtlasStyle.myText(0.20,0.75, 1,extraTextString.split(',')[1]) c0.Print( args.plotDir + "/" + args.outputTag + "_" + histName + args.outputVersion + ".png","png") #,"png") ## TODO Draw log versions? return
c.Update() # legend legend.AddEntry(histo, LegendEntryList[NPlots], "l") legend.Draw("Same") # ATLAS Style Setting AtlasStyle.ATLAS_LABEL( 0.5, 0.85, internal=ATLAS_Internal, preliminary=ATLAS_Preliminary, color=1) AtlasStyle.myText(0.5, 0.8, 1, "#sqrt{s} = 13 TeV") # create ratio plots in pad2 if (EnableHistoCombination & EnableRatioPlots): ## save reference plot, i.e. NPlots == 0 if (NPlots == 0): refHisto = histo ## else plot ratio histos else: # change to pad2 pad2.cd() pad2.SetLogy(False) ## create and setup histoRatio
def plotNominal(file, f_plotSys, f_addGagik): outDir = file[:-5]+'/' if not os.path.exists(outDir): os.mkdir(outDir) outDir += "plotNominal/" if not os.path.exists(outDir): os.mkdir(outDir) if not os.path.exists(outDir+'/eps'): os.mkdir(outDir+'/eps') AtlasStyle.SetAtlasStyle() gROOT.ProcessLine("gErrorIgnoreLevel = 2000") #Ignore TCanvas::Print info inFile = TFile.Open(file, "READ"); keyList = [key.GetName() for key in inFile.GetListOfKeys()] #List of top level objects dirList = [key for key in keyList if "Iteration" in key] #List of all directories #nomDir = [dir for dir in dirList if "NoCorr" in dir] nomDir = [dir for dir in dirList if "Nominal" in dir] if( not len(nomDir) == 1): print "Error, nominal directories are ", nomDir return else: nomDir = inFile.Get( nomDir[0] ) c1 = TCanvas() ##################### Plot All Nominal With Systematic Bands ################################# print "Plotting nominal hists " if(f_plotSys): sysDirNameList = [dir for dir in dirList if not "Nominal" in dir] sysDirList = [] for sysDirName in sysDirNameList: sysDirList.append( inFile.Get(sysDirName) ) ## Combine systematics in types ## #sysTypes = ["MJB_a", "MJB_b", "MJB_ptt", "MJB_pta", "Flavor", "EtaIntercalibration"] sysTypes = ["ZJ", "GJ", "MJB", "Flavor", "EtaIntercalibration", "All"] if "All" in sysTypes: colorOffset = 240./(len(sysTypes)-1) else: colorOffset = 240./len(sysTypes) histList = [key.GetName() for key in nomDir.GetListOfKeys()] for histName in histList: if "prof_" in histName or "ptSlice" in histName: continue nomHist = nomDir.Get( histName ) nomHist.SetName(nomHist.GetName()) if not type(nomHist) == TH1F and not type(nomHist) == TH1D and not type(nomHist) == TGraphErrors: #Can't draw bands if not 1D continue leg = TLegend(0.83, 0.15, 0.99, 0.95) pad1 = TPad("pad1", "", 0, 0, 0.83, 1) pad1.Draw() pad1.cd() leg.AddEntry( nomHist, "Nominal", "lp" ) #nomHist.SetMinimum(0.9) if( "Pt" in histName or "Energy" in histName): nomHist.GetXaxis().SetRange(nomHist.FindFirstBinAbove(0), nomHist.FindLastBinAbove(0)+1 ) nomHist.SetMaximum(1.5*nomHist.GetMaximum()) nomHist.SetMinimum(0.0001) if( "MJB" in histName) : nomHist.GetXaxis().SetRangeUser( 300, 2500 ) nomHist.SetMaximum(1.1) nomHist.SetMinimum(0.9) nomHist.GetXaxis().SetMoreLogLabels(True) # nomHist.SetMarkerSize(.75) if( "recoilPt" in histName): nomHist.GetYaxis().SetTitle("Entries / GeV") nomHist.GetXaxis().SetRangeUser( 500, 3100 ) if( "recoilPt" in histName): for iBin in range(1, nomHist.GetNbinsX()+1): nomHist.SetBinContent(iBin, nomHist.GetBinContent(iBin)/ nomHist.GetBinWidth(iBin)) nomHist.Draw() if not type(nomHist) == TGraphErrors: nomHist.Draw("p") else: nomHist.SetMarkerStyle(33) nomHist.SetMarkerSize(1.5) nomHist.SetLineWidth(4) nomHist.Draw("ap") if(f_plotSys): ## Get list of systematic histograms ## fullHistList = [] for thisSysDir in sysDirList: fullHistList.append( thisSysDir.Get(histName) ) fullHistList[-1].SetDirectory(0) ## Add systematic bands ## sysHistList = [] for iTopSys, topSysName in enumerate(sysTypes): if topSysName == 'All': subHistList = [thisHist for thisName, thisHist in zip(sysDirNameList, fullHistList) if any(otherTopName in thisName for otherTopName in sysTypes) ] else: subHistList = [thisHist for thisName, thisHist in zip(sysDirNameList, fullHistList) if topSysName in thisName] sysHistUp, sysHistDn = plotSysRatios.getCombinedSysHist(nomHist, subHistList, topSysName) for iBin in range(1, nomHist.GetNbinsX()+1): sysHistUp.SetBinContent( iBin, nomHist.GetBinContent(iBin)*(1.+sysHistUp.GetBinContent(iBin)) ) sysHistDn.SetBinContent( iBin, nomHist.GetBinContent(iBin)*(1.+sysHistDn.GetBinContent(iBin)) ) if topSysName == 'All': color = kBlack else: color = gStyle.GetColorPalette(int(colorOffset*(iTopSys+1))) sysHistUp.SetLineColor(color) sysHistUp.SetMarkerColor(color) sysHistUp.SetMarkerSize(1.5) sysHistUp.SetMarkerStyle(34) sysHistDn.SetLineColor(color) sysHistDn.SetMarkerColor(color) sysHistDn.SetMarkerSize(1.5) sysHistDn.SetMarkerStyle(34) if( "Pt" in histName or "Energy" in histName): sysHistUp.GetXaxis().SetRange(sysHistUp.FindFirstBinAbove(0), sysHistUp.FindLastBinAbove(0)+1) sysHistDn.GetXaxis().SetRange(sysHistDn.FindFirstBinAbove(0), sysHistDn.FindLastBinAbove(0)+1) if not type(nomHist) == TGraphErrors: sysHistUp.Draw("same hist l") sysHistDn.Draw("same hist l") else: sysHistUp.SetMarkerStyle(4) sysHistUp.SetMarkerSize(1.2) sysHistUp.Draw("same l") sysHistDn.SetMarkerStyle(4) sysHistDn.SetMarkerSize(1.2) sysHistDn.Draw("same l") if( topSysName == "EtaIntercalibration"): leg.AddEntry( sysHistUp, "EIC", "lp") else: leg.AddEntry( sysHistUp, topSysName, "lp") # Save them in a list sysHistList.append( sysHistUp ) sysHistList.append( sysHistDn ) # ### Add MC for Data MJB! ### # if( "data" in file and "MJB" in histName ): # filePath = os.path.dirname( file ) # if( "initial" in file): # mcFile = glob.glob( filePath+"/*mc14*MJB_initial.root") # elif( "final" in file): # mcFile = glob.glob( filePath+"/*mc14*MJB_final.root") # if len(mcFile) == 1: # mcFile = TFile.Open(mcFile[0], "READ") # mcKeyList = [key.GetName() for key in mcFile.GetListOfKeys()] #List of top level objects # mcDirList = [key for key in mcKeyList if "Iteration" in key] #List of all directories # #mcDir = [dir for dir in dirList if "NoCorr" in dir] # mcDir = [dir for dir in dirList if "Nominal" in dir] # if len(mcDir) == 1: # mcDir = mcFile.Get( mcDir[0] ) # mcHist = mcDir.Get(histName) # mcHist.SetMarkerColor(kRed) # mcHist.SetLineColor(kRed) # mcHist.SetMarkerStyle(33) # mcHist.SetMarkerSize(1.3) # mcHist.Draw("same p") # leg.AddEntry(mcHist, "MC", "lp") # # ### Add Gagik for DoubleMJB! ### # if( f_addGagik ): # if( "DoubleMJB" in histName ): # filePath = os.path.dirname( file ) # gagikFile = TFile.Open(filePath+"/ThirdCycle.EM4.sherpa.1.v11.root", "READ") # gagikHist = gagikFile.Get("g_DoMC_fmean_vs_recoil") # gagikHist.SetMarkerColor(kRed) # gagikHist.SetLineColor(kRed) # gagikHist.SetMarkerStyle(33) # gagikHist.SetMarkerSize(1.3) # gagikHist.Draw("same p") # leg.AddEntry(gagikHist, "8 TeV", "lp") # nomHist.Draw("same p") c1.cd() leg.Draw() AtlasStyle.ATLAS_LABEL(0.2,0.88, 1," Internal") AtlasStyle.myText(0.2,0.82,1, "#sqrt{s} = 13 TeV, 3.3 fb^{-1}") if "Pt" in histName or "alpha" in histName: pad1.SetLogy() c1.SaveAs(outDir+nomHist.GetName()+"_logy.png" ) c1.SaveAs(outDir+'/eps/'+nomHist.GetName()+"_logy.eps" ) pad1.SetLogy(0) if "MJB" in histName: pad1.SetLogx() c1.SaveAs((outDir+nomHist.GetName()+".png") ) c1.SaveAs((outDir+'/eps/'+nomHist.GetName()+".eps") ) c1.Clear() inFile.Close()
def MultipleFlatEffCurve(outputName, approachList, bins, binslong, flav="L"): markerlist = [21, 8, 22, 23, 29, 34] fout = ROOT.TFile(outputName, "recreate") fout.cd() Canv = ROOT.TCanvas("EffComb", "EffComb", 0, 800, 0, 800) Canv.cd() EffCurves = [] for scoreList, varList, label, scoreCutList in approachList: heff = getFixEffCurve(scoreList, varList, label, binslong, fix_eff_target=0.7, scoreCutList=scoreCutList, onlyReturnCutList=False) EffCurves.append(heff) legend = ROOT.TLegend(0.5, 0.5, 0.75, 0.75) legend_rel = ROOT.TLegend(0.5, 0.5, 0.75, 0.75) ROCs = [] mg = ROOT.TMultiGraph() for i in range(len(EffCurves)): ROC = ConvertEffToGraph(EffCurves[i], bins, False) ROC.SetLineWidth(2) ROC.SetLineColor(colorlist[i]) ROC.SetMarkerColor(colorlist[i]) ROC.SetMarkerSize(1) ROC.SetMarkerStyle(markerlist[i]) ROC.SetLineStyle(i + 1) mg.Add(ROC) legend.AddEntry(ROC, approachList[i][2][1], "lp") ROCs.append(ROC) mg.Draw("AP") mg.GetXaxis().SetTitle("b-jet p_{T} [GeV]") if flav == "L": mg.GetYaxis().SetTitle("light-jet Rejection, 1/#varepsilon_{l}") if flav == "C": mg.GetYaxis().SetTitle("c-jet Rejection, 1/#varepsilon_{c}") legend.Draw("same") Atlas.ATLASLabel(0.2, 0.88, 0.13, "Simulation Internal", color=1) Atlas.myText(0.2, 0.81, color=1, size=0.04, text="#sqrt{s}=13 TeV, t#bar{t}") Atlas.myText(0.2, 0.75, color=1, size=0.04, text="p_{T}>20 GeV, |#eta|<2.5") Atlas.myText(0.2, 0.69, color=1, size=0.04, text="Flat 70% b-tagging WP") Canv.Write() fout.Close()
def draw_mass_distributions_and_ratio(self, ntrk, region, h_data, h_model, h_coll): #def draw_mass_distributions_and_ratio(self, ntrk, region, h_data, h_model): canvas2 = ROOT.TCanvas('canvas2', 'canvas2', 1000, 750) # mass distributions pad1 = ROOT.TPad('pad1', 'pad1', 0, 0.35, 1, 1.0) pad2 = ROOT.TPad('pad2', 'pad2', 0, 0.05, 1, 0.35) self.prepare_pads(canvas2, pad1, pad2) pad1.cd() if self.rebin > 1: # h_nocross.Rebin(rebin) #h_nolarge[region].Rebin(self.rebin) #h_large[region].Rebin(self.rebin) #h_data[region].Rebin(self.rebin) #h_data_collimated[region].Rebin(self.rebin) h_model = utils.rebin(h_model, bins_array) h_data = utils.rebin(h_data, bins_array) h_coll = utils.rebin(h_coll, bins_array) self.configure_data_histogram(h_data) h_data.SetMaximum(h_data.GetMaximum() * 8) self.configure_model_histogram(h_model) for bin in range(h_data.GetNbinsX()): if h_data.GetBinContent(bin+1) == 0: h_data.SetBinError(bin+1, 1.) h_data.Draw('e') if self.show_collimated: self.configure_model_histogram(h_coll) h_coll.SetFillStyle(3013) h_coll.SetLineWidth(0) h_coll.SetFillColor(ROOT.kAzure) h_coll.Draw('same,hist') h_model.SetLineWidth(2) h_model.Draw('same,hist') h_data.Draw('same,e') # list_diff3[ipad-1].SetLineWidth(2) AtlasStyle.ATLASLabel(self.ax, self.ay, 'Work in Progress') AtlasStyle.myText(self.tx, self.ty, ROOT.kBlack, self.beam_condition, 0.038) leg = ROOT.TLegend(self.x_min, self.y_min, self.x_max, self.y_max) leg.AddEntry(h_data, str(ntrk) + '-trk vertices Region' + str(region), 'lep') leg.AddEntry(h_model, str(ntrk-1) + '-trk vert + 1 random track', 'f') utils.decorate_legend(leg) leg.Draw() line = ROOT.TLine(self.m_cut, h_data.GetMinimum(), self.m_cut, h_data.GetMaximum() * 0.1) utils.decorate_line(line, ROOT.kGray+1, 5) line.Draw() # Ratio plot pad2.cd() h_ratio = h_data.Clone(str(ntrk) + 'trk_ratio' + str(region)) h_ratio.Sumw2() h_ratio.Divide(h_model) self.decorate_ratio_plot(h_ratio, 0.1, 1.9) h_ratio.Draw('e2p') line2 = ROOT.TLine(self.m_cut, h_ratio.GetMinimum(), self.m_cut, h_ratio.GetMaximum()) utils.decorate_line(line2, ROOT.kGray+1, 5) line2.Draw() directory = BasicConfig.plotdir + 'bg_est/' + str(date.today()) os.system('mkdir -p ' + directory) utils.save_as(canvas2, directory + '/dv_mass_fitter_' + str(ntrk) + 'Trk_Region' + str(region)) canvas2.Close()
def draw_cross_section_limit(tree, mass_g, flavor_of_sample='MET_TLJets'): AtlasStyle.SetAtlasStyle() entries = tree.GetEntries() current_delta_mass = 0 upper_limits = [] dM = [] index = -1 for entry in range(entries): tree.GetEntry(entry) if tree.mGluino == mass_g: if current_delta_mass != tree.deltaM: print('*** {0}, {1}'.format(tree.mGluino, tree.deltaM)) upper_limits.append(TGraphErrors()) dM.append(int(tree.deltaM)) index += 1 point = 0 current_delta_mass = tree.deltaM #if current_delta_mass < 100: # continue upper_limits[index].SetPoint(point, tree.ctau * 1e3, tree.xsUL) upper_limits[index].SetPointError(point, 0, tree.xsUL*tree.effRelStatErr+tree.xsUL*tree.effRelSystErr) point += 1 print(tree.ctau, tree.xsUL) canvas = TCanvas('c', 'c', 1000, 800) canvas.SetLogx() canvas.SetLogy() #upper_limits[0].SetMinimum(0.8) #upper_limits[0].SetMinimum(0.05) #upper_limits[0].SetMaximum(30000) #upper_limits[0].GetXaxis().SetRangeUser(0.9, 310) #upper_limits[0].GetXaxis().SetTitle('c#tau [mm]') #upper_limits[0].GetYaxis().SetTitle('Cross Section [fb]') #upper_limits[0].Draw('A3') #if mass_g == 1400: # upper_limits[1].RemovePoint(0) #upper_limits[0].RemovePoint(2) #upper_limits[1].RemovePoint(0) h_xs = TH1F('xs', ';c#tau [mm]; Cross Section [fb]', 1000, 0.9, 310) h_xs_line = TH1F('xs_line', ';c#tau [mm]; Cross Section [fb]', 1000, 0.9, 310) print(mc.mass_xs_err[mass_g]['xs'] * 1e3) for bin in range(1, 1000+1): h_xs.SetBinContent(bin, mc.mass_xs_err[mass_g]['xs'] * 1e3) h_xs_line.SetBinContent(bin, mc.mass_xs_err[mass_g]['xs'] * 1e3) h_xs.SetBinError(bin, mc.mass_xs_err[mass_g]['xs'] * 1e3 * mc.mass_xs_err[mass_g]['xs_err'] * 0.01) h_xs.SetMarkerSize(0) h_xs.SetFillStyle(3001) h_xs.SetFillColor(kGray+2) #h_xs.SetMinimum(0.8) h_xs.SetMinimum(0.05) h_xs.SetMaximum(30000) #h_xs.Draw('same,e2') h_xs.Draw('e2') h_xs_line.SetLineColor(kGray+3) h_xs_line.SetLineStyle(2) h_xs_line.Draw('same') legend = TLegend(0.60, 0.75, 0.83, 0.90) for ii, upper_limit in enumerate(upper_limits): #upper_limit.RemovePoint(0) upper_limit.SetMarkerSize(0) upper_limit.SetFillStyle(3001) index = ii if dM[ii] == 130: index = 1 elif dM[ii] == 80: index = 2 continue elif dM[ii] == 50: index = 3 elif dM[ii] == 30: index = 4 upper_limit.SetFillColor(BasicConfig.colors[index+1]) upper_limit.SetLineColor(BasicConfig.colors[index+1]) upper_limit.Draw('3,same') #upper_limit.Draw('c,same') #if dM[ii] > 100: # #legend.AddEntry(upper_limit, 'M_{#tilde{g}} = '+str(mass_g)+' GeV, #DeltaM = '+str(dM[ii])+' GeV', 'lf') # legend.AddEntry(upper_limit, '#DeltaM = '+str(dM[ii])+' GeV', 'lf') legend.AddEntry(upper_limit, '#DeltaM = '+str(dM[ii])+' GeV', 'lf') utils.decorate_legend(legend) legend.Draw() AtlasStyle.ATLASLabel(0.19, 0.87, 'Work in Progress') AtlasStyle.myText(0.20, 0.79, kBlack, '#sqrt{s} = 13 TeV, #int L dt = 30 fb^{-1}', 0.035) AtlasStyle.myText(0.20, 0.73, kBlack, 'Split-SUSY Model, M_{#tilde{g}} = '+str(mass_g)+' GeV', 0.032) #AtlasStyle.myText(0.20, 0.67, kBlack, 'M_{#tilde{g}} = '+str(mass_g)+' GeV', 0.035) utils.save_as(canvas, BasicConfig.plotdir + 'xs_limit_mGluino' + str(mass_g) + flavor_of_sample)
def draw_breakdown(self, mode, use_multiple_models=True): print('***********************') print('draw_breakdown') print(mode) canvas3 = ROOT.TCanvas('canvas3_' + mode['mode'], 'canvas3', 1000, 800) canvas3.SetLeftMargin(0.15) #canvas3.SetLogy() #mat = MaterialVolume.MaterialVolume() #bins = array('f', [0] + mat.region_list) #h_factor = mode['h_factor'] #if mode['mode'] == 'cross_factor': # self.h_factor = ROOT.TH1F('h_value_' + mode['mode'], ';R [mm];' + mode['y_axis'], # len(mat.region_list), bins) #h_value = ROOT.TH1F('h_value_' + mode['mode'], ';R [mm];' + mode['y_axis'], # len(mat.region_list), bins) #h_est = ROOT.TH1F('h_est_' + mode['mode'], '', len(mat.region_list), bins) h_fill = ROOT.TH1F('h_fill_' + mode['mode'], '', len(mat.region_list), bins) for ii in range(len(mat.region_list)): if ii in self.vetoed_region: h_fill.SetBinContent(ii + 1, 99999.) h_fill.SetBinError(ii + 1, 0.) h_factor.SetBinContent(ii+1, 0) h_factor.SetBinError(ii+1, 0) h_factor_large.SetBinContent(ii+1, 0) h_factor_large.SetBinError(ii+1, 0) if not mode['mode'] == 'cross_factor': self.h_obs[mode['mode']].SetBinContent(ii+1, 0) self.h_obs[mode['mode']].SetBinError(ii+1, 0) self.h_est[mode['mode']].SetBinContent(ii+1, 0) self.h_est[mode['mode']].SetBinError(ii+1, 0) self.h_est_large[mode['mode']].SetBinContent(ii+1, 0) self.h_est_large[mode['mode']].SetBinError(ii+1, 0) # 8to10 self.h_obs_8to10[mode['mode']].SetBinContent(ii+1, 0) self.h_obs_8to10[mode['mode']].SetBinError(ii+1, 0) self.h_est_8to10[mode['mode']].SetBinContent(ii+1, 0) self.h_est_8to10[mode['mode']].SetBinError(ii+1, 0) self.h_est_large_8to10[mode['mode']].SetBinContent(ii+1, 0) self.h_est_large_8to10[mode['mode']].SetBinError(ii+1, 0) else: pass #h_fill.SetBinContent(ii + 1, -99999.) #h_fill.SetBinError(ii + 1, 0.) #if mode['mode'] == 'cross_factor': #pass #self.h_factor.SetBinContent(ii + 1, self.crossfactor_list[ii]) #self.h_factor.SetBinError(ii + 1, self.error_list[ii]) #self.h_factor.Sumw2() #elif mode['mode'] == '4': ##print(ii, self.obs_list[4][ii]) #h_value.SetBinContent(ii + 1, self.obs_list[4][ii]) #h_value.SetBinError(ii + 1, ROOT.TMath.Sqrt(self.obs_list[4][ii])) ##print(ii, self.est_list[4][ii]) #h_est.SetBinContent(ii + 1, self.est_list[4][ii]) #h_est.SetBinError(ii + 1, ROOT.TMath.Sqrt(self.est_list[4][ii])) #elif mode['mode'] == '5' or mode['mode'] == '6': # h_value.SetBinContent(ii + 1, self.obs_list[5][ii]) # h_value.SetBinError(ii + 1, ROOT.TMath.Sqrt(self.obs_list[5][ii])) #else: # print('invalid mode') h_fill.SetLineWidth(0) h_fill.SetFillColor(ROOT.kPink) h_fill.SetFillStyle(3001) if mode['mode'] == 'cross_factor': #h_factor.SetMaximum(0.0105) #h_factor.SetMaximum(0.0305) #h_factor.SetMaximum(0.905) #h_factor.SetMaximum(90.5) h_factor.SetMaximum(0.004) h_factor.GetYaxis().SetTitleOffset(1.80) h_factor.SetMinimum(0) #h_factor.SetMinimum(0.00002) #h_factor.SetMinimum(0.00002) h_factor.SetLineWidth(2) h_factor.SetLineColor(ROOT.kBlack) h_factor.SetMarkerColor(ROOT.kBlack) h_factor.SetMarkerStyle(20) h_factor.Draw('e') if use_multiple_models: h_factor_large.SetLineWidth(2) h_factor_large.SetLineColor(ROOT.kBlue+1) h_factor_large.SetMarkerColor(ROOT.kBlue+1) h_factor_large.SetMarkerStyle(20) h_factor_large.Draw('e,same') output_factor = ROOT.TFile('output_factor_{}.root'.format(self.m_cut), 'recreate') h_factor.Write() h_fill.Write() else: utils.decorate_histogram(self.h_obs[mode['mode']], ROOT.kGray+3) #self.h_obs[mode['mode']].SetMaximum(self.h_obs[mode['mode']].GetMaximum() * 3.1) #self.h_obs[mode['mode']].SetMaximum(self.h_obs[mode['mode']].GetMaximum() * 200) #self.h_obs[mode['mode']].SetMinimum(2e-2) self.h_obs[mode['mode']].SetMaximum(self.h_obs[mode['mode']].GetMaximum() * 3) self.h_obs[mode['mode']].SetMinimum(0) self.h_obs[mode['mode']].Draw('e') utils.decorate_histogram(self.h_est[mode['mode']], ROOT.kGreen+2, fill_style=3002) self.h_est[mode['mode']].Add(self.h_est_large[mode['mode']]) self.h_est[mode['mode']].SetLineWidth(0) self.h_est[mode['mode']].Draw('e2,same') ## 8to10 #utils.decorate_histogram(self.h_obs_8to10[mode['mode']], ROOT.kGray+3) #self.h_obs_8to10[mode['mode']].SetMaximum(self.h_obs_8to10[mode['mode']].GetMaximum() * 200) #self.h_obs_8to10[mode['mode']].Draw('e') #utils.decorate_histogram(self.h_est_8to10[mode['mode']], ROOT.kGreen+2, fill_style=3002) self.h_est_8to10[mode['mode']].Add(self.h_est_large_8to10[mode['mode']]) #self.h_est[mode['mode']].SetLineWidth(0) #self.h_est[mode['mode']].Draw('e2,same') h_fill.Draw('same') AtlasStyle.ATLASLabel(self.ax, self.ay, 'Work in Progress') AtlasStyle.myText(self.tx, self.ty, ROOT.kBlack, self.beam_condition, 0.038) leg3 = ROOT.TLegend(self.x_min, self.y_min, self.x_max, self.y_max) if mode['mode'] == 'cross_factor': if use_multiple_models: leg3.AddEntry(h_factor, 'Crossing Factor (NoLarge)', 'lep') leg3.AddEntry(h_factor_large, 'Crossing Factor (Large)', 'lep') else: leg3.AddEntry(h_factor, 'Crossing Factor', 'lep') elif mode['mode'] == '4': leg3.AddEntry(self.h_obs[mode['mode']], 'Observed', 'lep') leg3.AddEntry(self.h_est[mode['mode']], 'Predicted', 'epf') elif mode['mode'] == '5' or mode['mode'] == 6: leg3.AddEntry(self.h_obs[mode['mode']], 'Observed (Blinded)', 'lep') leg3.AddEntry(self.h_est[mode['mode']], 'Predicted', 'epf') utils.decorate_legend(leg3) leg3.Draw() directory = BasicConfig.plotdir + 'bg_est/' + str(date.today()) utils.save_as(canvas3, directory + '/dv_mass_fitter_summary_' + mode['mode']) canvas3.Close()