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 mll_C1_test(): path = "/afs/cern.ch/work/y/yushen/private/Higgsino/SimpleAnalysis/Results/" f_original = path + "20170619/user.chris.100k.CC.filtered.TestJob.root" f_C1_at_middle = path + "20170620/user.chris.C1.middle.TestJob.root" f_no_C1 = path + "20170619/user.chris.10k.CC.no.x1.filtered.TestJob.root" f1 = ROOT.TFile(f_original) f2 = ROOT.TFile(f_C1_at_middle) f3 = ROOT.TFile(f_no_C1) t1 = f1.Get("EwkHiggsino2016__ntuple") h1 = ROOT.TH1F("h1", "mll", 100, 0, 50) t1.Project("h1", "mll", "mll>0") h1.SetDirectory(ROOT.gROOT) t2 = f2.Get("EwkHiggsino2016__ntuple") h2 = ROOT.TH1F("h2", "mll", 100, 0, 50) t2.Project("h2", "mll", "mll>0") h2.SetDirectory(ROOT.gROOT) t3 = f3.Get("EwkHiggsino2016__ntuple") h3 = ROOT.TH1F("h3", "mll", 100, 0, 50) t3.Project("h3", "mll", "mll>0") h3.SetDirectory(ROOT.gROOT) h1.Scale(1 / h1.Integral()) h2.Scale(1 / h2.Integral()) h3.Scale(1 / h3.Integral()) h1.SetLineColor(ROOT.kBlack) h2.SetLineColor(ROOT.kRed) h3.SetLineColor(ROOT.kBlue) c1 = ROOT.TCanvas("c1", "c1", 800, 800) ROOT.gPad.SetLogy() h1.SetStats(0) # no stats box h1.SetXTitle("M_{ll} [GeV]") h1.SetMaximum(h1.GetMaximum() * 20) h1.Draw() h2.Draw("same") h3.Draw("same") legend = ROOT.TLegend(0.5, 0.6, 0.9, 0.8) legend.AddEntry(h1, "NUHM2, 100k, Original", "l") legend.AddEntry(h2, "NUHM2, 10k, C1 at middle", "l") legend.AddEntry(h3, "NUHM2, 10k, No C1", "l") legend.SetBorderSize(0) legend.SetTextFont(42) legend.SetTextSize(0.02) legend.SetFillColor(0) legend.SetFillStyle(0) legend.Draw() AtlasStyle.ATLASLabel(0.15, 0.85, "internal", ROOT.kBlack) c1.SaveAs("mll_C1_test.pdf")
def fit_plot(file, n2_n1): f = ROOT.TFile(file) t = f.Get("MGPy8EG_A14N23LO_SM_Higgsino_" + n2_n1 + "_2LMET50_MadSpin_NoSys") h = ROOT.TH1F("h_" + n2_n1, "truthMll", 100, 0, 100) t.Project("h_" + n2_n1, "truthMll", "truthMll>0") n2 = float((n2_n1.split("_"))[0]) n1 = float((n2_n1.split("_"))[1]) dm = n2 - n1 print n2, n1, dm fit_func = ROOT.TF1("fit_func", funcMllDistr, 0, dm, 3) fit_func.SetParameters(1., n1, -1. * n2) area_fit_func = fit_func.Integral(0., dm) fit_func.SetParameter(0, 1. / area_fit_func) # normalize fit_func fit_func.FixParameter(1, n1) fit_func.FixParameter(2, -1. * n2) fit_func.SetLineColor(ROOT.kRed) fit_func.SetLineStyle(2) canvas = ROOT.TCanvas("c", "", 800, 600) canvas.SetLeftMargin(0.12) logY = True if logY: ROOT.gPad.SetLogy() ROOT.gStyle.SetOptFit(1111) h.SetXTitle("m_{ll} [GeV]") h.SetYTitle("Events / 1GeV") h.GetYaxis().SetTitleOffset(1.2) h.SetLineColor(ROOT.kBlue) h.Draw("hist") h.Fit(fit_func, "R0") h.Fit(fit_func, "R0") h.Fit(fit_func, "R+") fit_func.Draw("same") AtlasStyle.ATLASLabel(0.15, 0.85, "internal", ROOT.kBlack) legend = ROOT.TLegend(0.5, 0.4, 0.9, 0.5) legend.AddEntry(h, "Higgsino_" + n2_n1, "l") # legend.AddEntry(fit_func, "Theoretical Higgsino_" + n2_n1 + "(fix N2 and N1)", "l") legend.AddEntry(fit_func, "Theoretical Higgsino_" + n2_n1, "l") legend.SetBorderSize(0) legend.SetTextFont(42) legend.SetTextSize(0.03) legend.SetFillColor(0) legend.SetFillStyle(0) legend.Draw() output = "fit_Higgsino_common_ntuple_v1.8b_" + n2_n1 + ".pdf" canvas.SaveAs(output)
def compare_two_curves(file1, file2, var, normalize): canvas = ROOT.TCanvas("c", "", 800, 600) if var not in [ "h_NJets", "h_NJet30", "h_NJet25", "h_Nbjets", "h_NLepts_baseline", "h_NLepts_signal" ]: ROOT.gPad.SetLogy() f1 = ROOT.TFile(file1) var_in_f1 = f1.Get(var) integral1 = var_in_f1.Integral() if normalize is True: var_in_f1.Scale(1 / integral1) f2 = ROOT.TFile(file2) var_in_f2 = f2.Get(var) integral2 = var_in_f2.Integral() if normalize is True: var_in_f2.Scale(1 / integral2) y_maximum = max(var_in_f1.GetMaximum(), var_in_f2.GetMaximum()) var_in_f1.SetStats(0) var_in_f1.SetLineColor(ROOT.kBlue) if normalize is True: var_in_f1.SetYTitle("Normalized event counts") else: var_in_f1.SetYTitle("Event counts") var_in_f1.SetMaximum(y_maximum * 1.2) if var is "h_mll": var_in_f1.GetXaxis().SetRangeUser(0, 300) var_in_f1.Draw("hist") var_in_f2.SetLineColor(ROOT.kRed) var_in_f2.Draw("hist,same") legend = ROOT.TLegend(0.6, 0.7, 0.9, 0.8) legend.AddEntry(var_in_f1, "NUHM2_m12_600", "l") legend.AddEntry(var_in_f2, "Higgsino_190_150", "l") legend.SetBorderSize(0) legend.SetTextFont(42) legend.SetTextSize(0.03) legend.SetFillColor(0) legend.SetFillStyle(0) legend.Draw() AtlasStyle.ATLASLabel(0.15, 0.85, "internal", ROOT.kBlack) # if normalize is not True: # AtlasStyle.myText(0.3, 0.85, ROOT.kBlack, "36.1fb^{-1}") #AtlasStyle.myText(0.6, 0.4, ROOT.kBlack, "#sqrt{s}=13TeV") output = var + ".pdf" canvas.SaveAs(output)
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 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 draw_distributions_and_ratio(h_data, h_model, parameters): 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) prepare_pads(canvas2, pad1, pad2) pad1.cd() decorate_histogram(h_data, ROOT.kGray + 3) h_data.Sumw2() h_data.Scale(1. / h_data.GetEntries()) h_data.SetMaximum(h_data.GetMaximum() * 10) h_data.Draw('e') #h_model.SetLineWidth(2) decorate_histogram(h_model, ROOT.kRed + 1) h_model.Sumw2() h_model.Scale(1. / h_model.GetEntries()) h_model.Draw('same,e') # list_diff3[ipad-1].SetLineWidth(2) AtlasStyle.ATLASLabel(0.2, 0.85, 'Work in Progress') #AtlasStyle.myText(0, self.ty, ROOT.kBlack, self.beam_condition, 0.038) leg = ROOT.TLegend(0.55, 0.6, 0.85, 0.85) leg.AddEntry(h_data, parameters['legend1'], 'lep') leg.AddEntry(h_model, parameters['legend2'], 'lep') decorate_legend(leg) leg.Draw() #line = ROOT.TLine(self.m_cut, h_data.GetMinimum(), self.m_cut, h_data.GetMaximum() * 0.1) #decorate_line(line, ROOT.kGray + 1, 5) #line.Draw() # Ratio plot pad2.cd() h_ratio = h_data.Clone('ratio') h_ratio.Sumw2() h_ratio.Divide(h_model) 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()) #decorate_line(line2, ROOT.kGray + 1, 5) #line2.Draw() directory = BasicConfig.plotdir + 'validation/' + str(date.today()) os.system('mkdir -p ' + directory) save_as(canvas2, directory + '/' + parameters['file_name']) 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 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 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()
def mll_components(): ''' show the mll components ''' f1 = ROOT.TFile( "/afs/cern.ch/work/y/yushen/private/Higgsino/SimpleAnalysis/Results/20170619/user.chris.100k.CC.filtered.TestJob.root" ) t1 = f1.Get("EwkHiggsino2016__ntuple") h1 = ROOT.TH1F("h1", "mll", 100, 0, 50) h2 = ROOT.TH1F("h2", "mll is2LChannel", 100, 0, 50) h3 = ROOT.TH1F("h3", "mll !is2LChannel", 100, 0, 50) h4 = ROOT.TH1F("h4", "mll isSameSign", 100, 0, 50) h5 = ROOT.TH1F("h5", "mll !isSameSign", 100, 0, 50) h6 = ROOT.TH1F("h6", "mll is2LChannel&&isSameSign", 100, 0, 50) h7 = ROOT.TH1F("h7", "mll is2LChannel&&!isSameSign", 100, 0, 50) h8 = ROOT.TH1F("h8", "mll !is2LChannel&&isSameSign", 100, 0, 50) h9 = ROOT.TH1F("h9", "mll !is2LChannel&&!isSameSign", 100, 0, 50) t1.Project("h1", "mll", "mll>0") t1.Project("h2", "mll", "mll>0&&is2LChannel") t1.Project("h3", "mll", "mll>0&&!is2LChannel") t1.Project("h4", "mll", "mll>0&&isSameSign") t1.Project("h5", "mll", "mll>0&&!isSameSign") t1.Project("h6", "mll", "mll>0&&is2LChannel&&isSameSign") t1.Project("h7", "mll", "mll>0&&is2LChannel&&!isSameSign") t1.Project("h8", "mll", "mll>0&&!is2LChannel&&isSameSign") t1.Project("h9", "mll", "mll>0&&!is2LChannel&&!isSameSign") h1.SetLineColor(ROOT.kBlack) h2.SetLineColor(ROOT.kRed) h3.SetLineColor(ROOT.kGreen) h3.SetFillColor(ROOT.kGreen) h3.SetFillStyle(1001) # solid h4.SetLineColor(ROOT.kBlue) h4.SetFillColor(ROOT.kBlue) h4.SetFillStyle(0) # hollow h5.SetLineColor(ROOT.kYellow) h6.SetLineColor(ROOT.kMagenta) h6.SetFillColor(ROOT.kMagenta) h6.SetFillStyle(1001) # solid h7.SetLineColor(ROOT.kCyan) h8.SetLineColor(ROOT.kOrange) h8.SetFillColor(ROOT.kYellow) h8.SetFillStyle(1001) # solid h9.SetLineColor(ROOT.kAzure) h9.SetFillColor(ROOT.kAzure) h9.SetFillStyle(0) c1 = ROOT.TCanvas("c1", "c1", 800, 800) ROOT.gPad.SetLogy() h1.GetXaxis().SetRangeUser(0, 50) h1.SetStats(0) # no stats box h1.SetXTitle("M_{ll} [GeV]") h1.Draw() h2.Draw("same") h3.Draw("same") h4.Draw("same") h5.Draw("same") h6.Draw("same") h7.Draw("same") h8.Draw("same") h9.Draw("same") legend = ROOT.TLegend(0.5, 0.6, 0.9, 0.8) legend.AddEntry(h1, "All", "l") legend.AddEntry(h2, "is2L", "l") legend.AddEntry(h3, "!is2L", "l") legend.AddEntry(h4, "isSS", "l") legend.AddEntry(h5, "!is2L", "l") legend.AddEntry(h6, "is2L && isSS", "l") legend.AddEntry(h7, "is2L && !isSS", "l") legend.AddEntry(h8, "!is2L && isSS", "l") legend.AddEntry(h9, "!is2L && !isSS", "l") legend.SetBorderSize(0) legend.SetTextFont(42) legend.SetTextSize(0.02) legend.SetFillColor(0) legend.SetFillStyle(0) legend.Draw() AtlasStyle.ATLASLabel(0.15, 0.85, "internal", ROOT.kBlack) c1.SaveAs("mll_components.pdf")
def main(): path_higgsino = "/Users/ytshen/Documents/Working/OU/HEP/my_codes/Higgsino/data/truth3_Results/20170817/" n2_n1 = "190_150" f_higgsino_N2N1 = "user.yushen.SM_N2N1_" + n2_n1 + "_2LMET50.root" f_higgsino_C1C1 = "user.yushen.SM_C1C1_" + n2_n1 + "_2LMET50.root" f_higgsino_N2C1p = "user.yushen.SM_N2C1p_" + n2_n1 + "_2LMET50.root" f_higgsino_N2C1m = "user.yushen.SM_N2C1m_" + n2_n1 + "_2LMET50.root" n2 = int(n2_n1[:n2_n1.find("_")]) n1 = int(n2_n1[n2_n1.find("_") + 1:]) higgsino_dm = n2 - n1 path_nuhm2 = "/Users/ytshen/Documents/Working/OU/HEP/my_codes/Higgsino/data/truth3_Results/20170817/" m12 = 600 f_nuhm2_N2N1 = "user.yushen.run_" + str(m12) + "_N2N1.TestJob.root" f_nuhm2_C1C1 = "user.yushen.run_" + str(m12) + "_C1C1.TestJob.root" f_nuhm2_N2C1p = "user.yushen.run_" + str(m12) + "_N2C1p.TestJob.root" f_nuhm2_N2C1m = "user.yushen.run_" + str(m12) + "_N2C1m.TestJob.root" nuhm2_dm = 0 if m12 == 300: nuhm2_dm = 55 elif m12 == 350: nuhm2_dm = 46 elif m12 == 400: nuhm2_dm = 38 elif m12 == 500: nuhm2_dm = 28 elif m12 == 600: nuhm2_dm = 22 elif m12 == 700: nuhm2_dm = 18 elif m12 == 800: nuhm2_dm = 15 file1 = path_higgsino + f_higgsino_N2N1 file2 = path_higgsino + f_higgsino_C1C1 file3 = path_higgsino + f_higgsino_N2C1p file4 = path_higgsino + f_higgsino_N2C1m file5 = path_nuhm2 + f_nuhm2_N2N1 file6 = path_nuhm2 + f_nuhm2_C1C1 file7 = path_nuhm2 + f_nuhm2_N2C1p file8 = path_nuhm2 + f_nuhm2_N2C1m var = "mll" h_higgsino = get_histogram(file1, file2, file3, file4) h_higgsino.SetLineColor(ROOT.kBlack) h_nuhm2 = get_histogram(file5, file6, file7, file8) h_nuhm2.SetLineColor(ROOT.kBlue) # Use a Gaussian to fit the core and an exponential function to fit the tail # Firstly, fit core and tail separately to get the parameters, # then use the parameters as initial parameters for combined fit. # Fitting histogram (with predefined function): fit_higgsino_core = ROOT.TF1("fit_higgsino_core", "gaus", 0, higgsino_dm) fit_higgsino_core.SetLineColor(ROOT.kRed - 8) fit_higgsino_core.SetLineWidth(3) # fit_higgsino_core = ROOT.TF1("fit_higgsino_core", funcMllDistr, 0, higgsino_dm, 3) # need to provide number of parameters as the last argument # fit_higgsino_core.SetParameters(1, n1, -1.*n2) # n1 and n2 should be opposite sign # fit_higgsino_core.FixParameter(1, n1) # fit_higgsino_core.FixParameter(2, -1.*n2) h_higgsino.Fit(fit_higgsino_core, "R0") h_higgsino.Fit(fit_higgsino_core, "R0") h_higgsino.Fit(fit_higgsino_core, "R0+") higgsino_core_parameters = fit_higgsino_core.GetParameters() fit_higgsino_tail = ROOT.TF1("fit_higgsino_tail", "expo", higgsino_dm, h_higgsino.GetXaxis().GetXmax()) fit_higgsino_tail.SetLineColor(ROOT.kRed - 8) fit_higgsino_tail.SetLineWidth(3) h_higgsino.Fit(fit_higgsino_tail, "R0") h_higgsino.Fit(fit_higgsino_tail, "R0") h_higgsino.Fit(fit_higgsino_tail, "R0+") higgsino_tail_parameters = fit_higgsino_tail.GetParameters() # print "Fit higgsino total:" fit_higgsino_total = ROOT.TF1("fit_higgsino_total", "gaus(0)+expo(3)", h_higgsino.GetXaxis().GetXmin(), h_higgsino.GetXaxis().GetXmax()) fit_higgsino_total.SetLineColor(ROOT.kRed - 8) fit_higgsino_total.SetLineWidth(3) fit_higgsino_total.SetParameters(higgsino_core_parameters[0], higgsino_core_parameters[1], higgsino_core_parameters[2], higgsino_tail_parameters[0], higgsino_tail_parameters[1]) h_higgsino.Fit(fit_higgsino_total, "R0") h_higgsino.Fit(fit_higgsino_total, "R0") h_higgsino.Fit(fit_higgsino_total, "R+") # Fitting histogram (with predefined function): fit_nuhm2_core = ROOT.TF1("fit_nuhm2_core", "gaus", 0, nuhm2_dm) fit_nuhm2_core.SetLineColor(ROOT.kGreen - 7) fit_nuhm2_core.SetLineWidth(3) h_nuhm2.Fit(fit_nuhm2_core, "R0") h_nuhm2.Fit(fit_nuhm2_core, "R0") h_nuhm2.Fit(fit_nuhm2_core, "R0+") nuhm2_core_parameters = fit_nuhm2_core.GetParameters() fit_nuhm2_tail = ROOT.TF1("fit_nuhm2_tail", "expo", nuhm2_dm, h_nuhm2.GetXaxis().GetXmax()) fit_nuhm2_tail.SetLineColor(ROOT.kGreen - 7) fit_nuhm2_tail.SetLineWidth(3) h_nuhm2.Fit(fit_nuhm2_tail, "R0") h_nuhm2.Fit(fit_nuhm2_tail, "R0") h_nuhm2.Fit(fit_nuhm2_tail, "R0+") nuhm2_tail_parameters = fit_nuhm2_tail.GetParameters() # print "Fit NUHM2 total" fit_nuhm2_total = ROOT.TF1("fit_nuhm2_total", "gaus(0)+expo(3)", h_nuhm2.GetXaxis().GetXmin(), h_nuhm2.GetXaxis().GetXmax()) fit_nuhm2_total.SetLineColor(ROOT.kGreen - 7) fit_nuhm2_total.SetLineWidth(3) fit_nuhm2_total.SetParameters(nuhm2_core_parameters[0], nuhm2_core_parameters[1], nuhm2_core_parameters[2], nuhm2_tail_parameters[0], nuhm2_tail_parameters[1]) h_nuhm2.Fit(fit_nuhm2_total, "R0") h_nuhm2.Fit(fit_nuhm2_total, "R0") h_nuhm2.Fit(fit_nuhm2_total, "R+") # Make plot canvas = ROOT.TCanvas("c", "", 800, 600) canvas.SetLeftMargin(0.12) # ROOT.gStyle.SetOptFit(1111) # show fitting results in stats box logY = True if logY: ROOT.gPad.SetLogy() h_higgsino.SetStats(0) # no stats box h_nuhm2.SetStats(0) # no stats box max_value = max(h_higgsino.GetMaximum(), h_nuhm2.GetMaximum()) * 10 h_higgsino.SetMinimum(0.0001) h_higgsino.SetMaximum(max_value) h_higgsino.Draw() h_nuhm2.Draw("same") legend = ROOT.TLegend(0.5, 0.7, 0.9, 0.8) legend.AddEntry(h_higgsino, "Higgsino" + n2_n1, "l") legend.AddEntry(h_nuhm2, "NUHM2 m12=" + str(m12), "l") # legend.AddEntry(fit_higgsino_total, "fitting Higgsino", "l") # legend.AddEntry(fit_nuhm2_total, "fitting NUHM2", "l") legend.SetBorderSize(0) legend.SetTextFont(42) legend.SetTextSize(0.02) legend.SetFillColor(0) legend.SetFillStyle(0) legend.Draw() AtlasStyle.ATLASLabel(0.15, 0.85, "internal", ROOT.kBlack) output = "fit_" + var + "_" + str(m12) + ".pdf" canvas.SaveAs(output)
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()
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 mll_no_Hadronic_Tau(): path = "/afs/cern.ch/work/y/yushen/private/Higgsino/SimpleAnalysis/Results/" f_Higgsino_N1N2 = path + "20170619/user.yushen.SM_N2N1_170_150_2LMET50.root" f_Higgsino_N2C1p = path + "20170619/user.yushen.SM_N2C1p_170_150_2LMET50.root" f_Higgsino_N2C1m = path + "20170619/user.yushen.SM_N2C1m_170_150_2LMET50.root" f_NUHM2_no_HadTau = path + "20170621/user.chris.10k.no.HadTau.TestJob.root" f_NUHM2_no_HadTau_simplified = path + "20170621/user.chris.10k.simplified.no.HadTau.TestJob.root" f1 = ROOT.TFile(f_Higgsino_N1N2) t1 = f1.Get("EwkHiggsino2016__ntuple") h1 = ROOT.TH1F("h1", "mll", 100, 0, 50) t1.Project("h1", "mll", "mll>0") integral1 = h1.Integral() h1.Scale(1 / integral1) h1.SetDirectory(ROOT.gROOT) f2 = ROOT.TFile(f_Higgsino_N2C1p) t2 = f2.Get("EwkHiggsino2016__ntuple") h2 = ROOT.TH1F("h2", "mll", 100, 0, 50) t2.Project("h2", "mll", "mll>0") integral2 = h2.Integral() h2.Scale(1 / integral2) h2.SetDirectory(ROOT.gROOT) f3 = ROOT.TFile(f_Higgsino_N2C1m) t3 = f3.Get("EwkHiggsino2016__ntuple") h3 = ROOT.TH1F("h3", "mll", 100, 0, 50) t3.Project("h3", "mll", "mll>0") integral3 = h3.Integral() h3.Scale(1 / integral3) h3.SetDirectory(ROOT.gROOT) f4 = ROOT.TFile(f_NUHM2_no_HadTau) t4 = f4.Get("EwkHiggsino2016__ntuple") h4 = ROOT.TH1F("h4", "mll", 100, 0, 50) t4.Project("h4", "mll", "mll>0") integral4 = h4.Integral() h4.Scale(1 / integral4) h4.SetDirectory(ROOT.gROOT) f5 = ROOT.TFile(f_NUHM2_no_HadTau_simplified) t5 = f5.Get("EwkHiggsino2016__ntuple") h5 = ROOT.TH1F("h5", "mll", 100, 0, 50) t5.Project("h5", "mll", "mll>0") integral5 = h5.Integral() h5.Scale(1 / integral5) h5.SetDirectory(ROOT.gROOT) ROOT.gROOT.cd() h1.SetLineColor(ROOT.kOrange) h1.SetFillColor(ROOT.kOrange) h1.SetFillStyle(1001) # Solid h2.SetLineColor(ROOT.kOrange - 3) h2.SetFillColor(ROOT.kOrange - 3) h2.SetFillStyle(1001) # Solid h3.SetLineColor(ROOT.kOrange - 6) h3.SetFillColor(ROOT.kOrange - 6) h3.SetFillStyle(1001) # Solid hs = ROOT.THStack() h1.Scale(integral1 / (integral1 + integral2 + integral3)) h2.Scale(integral2 / (integral1 + integral2 + integral3)) h3.Scale(integral3 / (integral1 + integral2 + integral3)) hs.Add(h1) hs.Add(h2) hs.Add(h3) canvas = ROOT.TCanvas("c", "", 800, 600) canvas.SetLeftMargin(0.12) ROOT.gPad.SetLogy() hs.Draw("hist") y_stack = h1.GetMaximum() + h2.GetMaximum() + h3.GetMaximum() y_maximum = max(y_stack, h4.GetMaximum()) hs.GetHistogram().SetStats(0) hs.SetTitle("M_{ll}") hs.GetHistogram().SetXTitle("M_{ll} [GeV]") hs.GetHistogram().SetYTitle("Normalized event counts") hs.SetMaximum(y_maximum * 2) hs.Draw() # re-draw to make the y axis range setting working h4.SetLineColor(ROOT.kBlue) h4.Draw("hist,same") h5.SetLineColor(ROOT.kRed) h5.Draw("hist,same") legend = ROOT.TLegend(0.5, 0.6, 0.9, 0.8) legend.AddEntry(h1, "Higgsino_N2N1_170_150", "f") legend.AddEntry(h2, "Higgsino_N2C1p_170_150", "f") legend.AddEntry(h3, "Higgsino_N2C1m_170_150", "f") legend.AddEntry(h4, "NUHM2_m12_600 no hadronic Tau", "l") legend.AddEntry(h5, "NUHM2_m12_600 no hadronic Tau, simplified", "l") legend.SetBorderSize(0) legend.SetTextFont(42) legend.SetTextSize(0.02) legend.SetFillColor(0) legend.SetFillStyle(0) legend.Draw() AtlasStyle.ATLASLabel(0.15, 0.85, "internal", ROOT.kBlack) canvas.SaveAs("mll_no_Hadronic_Tau.pdf")
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 mll_shape(): f_Higgsino_N2N1 = "../../../SimpleAnalysis/Results/20170628/user.yushen.SM_N2N1_170_150_2LMET50.root" f_Higgsino_N2C1p = "../../../SimpleAnalysis/Results/20170628/user.yushen.SM_N2C1p_170_150_2LMET50.root" f_Higgsino_N2C1m = "../../../SimpleAnalysis/Results/20170628/user.yushen.SM_N2C1m_170_150_2LMET50.root" f_NUHM2_100k_CC_filtered = "../../../SimpleAnalysis/Results/20170628/user.chris.100k.CC.filtered.TestJob.root" f_NUHM2_10k_n2_decay_no_jet = "../../../SimpleAnalysis/Results/20170628/user.chris.10k.n2.decay.no.jet.TestJob.root" f_NUHM2_10k_n2_decay_with_jet = "../../../SimpleAnalysis/Results/20170628/user.chris.10k.n2.decay.with.jet.TestJob.root" file1 = f_Higgsino_N2N1 file2 = f_Higgsino_N2C1p file3 = f_Higgsino_N2C1m file4 = f_NUHM2_100k_CC_filtered file5 = f_NUHM2_10k_n2_decay_no_jet file6 = f_NUHM2_10k_n2_decay_with_jet canvas = ROOT.TCanvas("c", "", 800, 600) canvas.SetLeftMargin(0.12) ROOT.gPad.SetLogy() var = "mll" nbins, xmin, xmax = 100, 0, 50 cut = "mll>0" normalize = True f1 = ROOT.TFile(file1) t1 = f1.Get("EwkHiggsino2016__ntuple") h1 = ROOT.TH1F("h1_" + var, var, nbins, xmin, xmax) t1.Project("h1_" + var, var, cut) integral1 = h1.Integral() # print integral1 if normalize is True: h1.Scale(1 / integral1) h1.SetDirectory(ROOT.gROOT) f2 = ROOT.TFile(file2) t2 = f2.Get("EwkHiggsino2016__ntuple") h2 = ROOT.TH1F("h2_" + var, var, nbins, xmin, xmax) t2.Project("h2_" + var, var, cut) integral2 = h2.Integral() # print integral2 if normalize is True: h2.Scale(1 / integral2) h2.SetDirectory(ROOT.gROOT) f3 = ROOT.TFile(file3) t3 = f3.Get("EwkHiggsino2016__ntuple") h3 = ROOT.TH1F("h3_" + var, var, nbins, xmin, xmax) t3.Project("h3_" + var, var, cut) integral3 = h3.Integral() # print integral3 if normalize is True: h3.Scale(1 / integral3) h3.SetDirectory(ROOT.gROOT) f4 = ROOT.TFile(file4) t4 = f4.Get("EwkHiggsino2016__ntuple") h4 = ROOT.TH1F("h4_" + var, var, nbins, xmin, xmax) t4.Project("h4_" + var, var, cut) integral4 = h4.Integral() # print integral4 if normalize is True: h4.Scale(1 / integral4) h4.SetDirectory(ROOT.gROOT) f5 = ROOT.TFile(file5) t5 = f5.Get("EwkHiggsino2016__ntuple") h5 = ROOT.TH1F("h5_" + var, var, nbins, xmin, xmax) t5.Project("h5_" + var, var, cut) integral5 = h5.Integral() # print integral5 if normalize is True: h5.Scale(1 / integral5) h5.SetDirectory(ROOT.gROOT) f6 = ROOT.TFile(file6) t6 = f6.Get("EwkHiggsino2016__ntuple") h6 = ROOT.TH1F("h6_" + var, var, nbins, xmin, xmax) t6.Project("h6_" + var, var, cut) integral6 = h6.Integral() # print integral6 if normalize is True: h6.Scale(1 / integral6) h6.SetDirectory(ROOT.gROOT) ROOT.gROOT.cd() h1.SetLineColor(ROOT.kOrange) h1.SetFillColor(ROOT.kOrange) h1.SetFillStyle(1001) # Solid h2.SetLineColor(ROOT.kOrange - 3) h2.SetFillColor(ROOT.kOrange - 3) h2.SetFillStyle(1001) # Solid h3.SetLineColor(ROOT.kOrange - 6) h3.SetFillColor(ROOT.kOrange - 6) h3.SetFillStyle(1001) # Solid hs = ROOT.THStack() h1.Scale(integral1 / (integral1 + integral2 + integral3)) h2.Scale(integral2 / (integral1 + integral2 + integral3)) h3.Scale(integral3 / (integral1 + integral2 + integral3)) hs.Add(h1) hs.Add(h2) hs.Add(h3) hs.Draw("hist") y_stack = h1.GetMaximum() + h2.GetMaximum() + h3.GetMaximum() y_maximum = max(y_stack, h4.GetMaximum()) hs.GetHistogram().SetStats(0) hs.SetTitle(var) hs.GetHistogram().SetXTitle(var + " [GeV]") hs.GetHistogram().SetYTitle("Normalized event counts") hs.SetMaximum(y_maximum * 20) hs.GetHistogram().GetYaxis().SetTitleOffset(1.5) hs.Draw() # re-draw to make the y axis range setting working h4.SetLineColor(ROOT.kBlue) h4.Draw("hist,same") h5.SetLineColor(ROOT.kRed) h5.Draw("hist,same") h6.SetLineColor(ROOT.kGreen) h6.Draw("hist,same") legend = ROOT.TLegend(0.4, 0.6, 0.9, 0.8) legend.AddEntry(h1, "Higgsino_N2N1_170_150", "f") legend.AddEntry(h2, "Higgsino_N2C1p_170_150", "f") legend.AddEntry(h3, "Higgsino_N2C1m_170_150", "f") legend.AddEntry(h4, "NUHM2_m12_600 (100k, C+C(+j), filtered)", "l") legend.AddEntry(h5, "NUHM2_m12_600 (10k, n2>l+l-n1, no jet, filtered)", "l") legend.AddEntry(h6, "NUHM2_m12_600 (10k, n2>l+l-n1, with jet, filtered)", "l") legend.SetBorderSize(0) legend.SetTextFont(42) legend.SetTextSize(0.02) legend.SetFillColor(0) legend.SetFillStyle(0) legend.Draw() AtlasStyle.ATLASLabel(0.15, 0.85, "internal", ROOT.kBlack) output = var + ".pdf" canvas.SaveAs(output)
def compare_pythia_madgraph_madspin(): f_Higgsino_N2C1p = "../../../SimpleAnalysis/Results/20170628/user.yushen.SM_N2C1p_170_150_2LMET50.root" f_Higgsino_N2C1m = "../../../SimpleAnalysis/Results/20170628/user.yushen.SM_N2C1m_170_150_2LMET50.root" f_NUHM2_100k_CC_filtered = "../../../SimpleAnalysis/Results/20170628/user.chris.100k.CC.filtered.TestJob.root" f_NUHM2_10k_n2_decay_no_jet = "../../../SimpleAnalysis/Results/20170628/user.chris.10k.n2.decay.no.jet.TestJob.root" f_MadSpin_N2C1p = "../../../SimpleAnalysis/Results/20170629/user.Judita.10k.N2C1p.TestJob.root" f_MadSpin_N2C1m = "../../../SimpleAnalysis/Results/20170629/user.Judita.10k.N2C1m.TestJob.root" file1 = f_Higgsino_N2C1p file2 = f_Higgsino_N2C1m file3 = f_NUHM2_100k_CC_filtered file4 = f_NUHM2_10k_n2_decay_no_jet file5 = f_MadSpin_N2C1p file6 = f_MadSpin_N2C1m canvas = ROOT.TCanvas("c", "", 800, 600) canvas.SetLeftMargin(0.12) ROOT.gPad.SetLogy() var = "mll" nbins, xmin, xmax = 100, 0, 50 cut = "mll>0" normalize = True f1 = ROOT.TFile(file1) t1 = f1.Get("EwkHiggsino2016__ntuple") h1 = ROOT.TH1F("h1_" + var, var, nbins, xmin, xmax) t1.Project("h1_" + var, var, cut) # integral1 = h1.Integral() # print integral1 # if normalize is True: # h1.Scale(1/integral1) h1.SetDirectory(ROOT.gROOT) f2 = ROOT.TFile(file2) t2 = f2.Get("EwkHiggsino2016__ntuple") h2 = ROOT.TH1F("h2_" + var, var, nbins, xmin, xmax) t2.Project("h2_" + var, var, cut) # integral2 = h2.Integral() # print integral2 # if normalize is True: # h2.Scale(1/integral2) h2.SetDirectory(ROOT.gROOT) f3 = ROOT.TFile(file3) t3 = f3.Get("EwkHiggsino2016__ntuple") h3 = ROOT.TH1F("h3_" + var, var, nbins, xmin, xmax) t3.Project("h3_" + var, var, cut) integral3 = h3.Integral() # print integral3 if normalize is True: h3.Scale(1 / integral3) h3.SetDirectory(ROOT.gROOT) f4 = ROOT.TFile(file4) t4 = f4.Get("EwkHiggsino2016__ntuple") h4 = ROOT.TH1F("h4_" + var, var, nbins, xmin, xmax) t4.Project("h4_" + var, var, cut) integral4 = h4.Integral() # print integral4 if normalize is True: h4.Scale(1 / integral4) h4.SetDirectory(ROOT.gROOT) f5 = ROOT.TFile(file5) t5 = f5.Get("EwkHiggsino2016__ntuple") h5 = ROOT.TH1F("h5_" + var, var, nbins, xmin, xmax) t5.Project("h5_" + var, var, cut) # integral5 = h5.Integral() # print integral5 # if normalize is True: # h5.Scale(1/integral5) h5.SetDirectory(ROOT.gROOT) f6 = ROOT.TFile(file6) t6 = f6.Get("EwkHiggsino2016__ntuple") h6 = ROOT.TH1F("h6_" + var, var, nbins, xmin, xmax) t6.Project("h6_" + var, var, cut) # integral6 = h6.Integral() # print integral6 # if normalize is True: # h6.Scale(1/integral6) h6.SetDirectory(ROOT.gROOT) ROOT.gROOT.cd() h12 = h1.Clone() h12.Add(h2) integral12 = h12.Integral() h12.Scale(1 / integral12) h56 = h5.Clone() h56.Add(h6) integral56 = h56.Integral() h56.Scale(1 / integral56) y_maximum = max(h12.GetMaximum(), h56.GetMaximum()) h12.SetStats(0) h12.SetTitle(var) h12.SetXTitle(var + " [GeV]") h12.SetYTitle("Normalized event counts") h12.SetMaximum(y_maximum * 20) h12.SetMinimum(0.0003) h12.GetYaxis().SetTitleOffset(1.5) h12.SetLineColor(ROOT.kOrange) h12.SetFillColor(ROOT.kOrange) h12.SetFillStyle(1001) # Solid h12.Draw() h3.SetLineColor(ROOT.kBlue) h3.SetFillColor(ROOT.kBlue) h3.SetFillStyle(0) h3.Draw("hist,same") h4.SetLineColor(ROOT.kRed) h4.SetFillColor(ROOT.kRed) h4.SetFillStyle(0) h4.Draw("hist,same") h56.SetLineColor(ROOT.kGreen) h56.SetFillColor(ROOT.kGreen) h56.SetFillStyle(0) h56.Draw("hist,same") legend = ROOT.TLegend(0.5, 0.6, 0.9, 0.8) legend.AddEntry(h12, "Higgsino_N2C1p/m_170_150", "f") legend.AddEntry(h3, "NUHM2_m12_600 (Pythia)", "l") legend.AddEntry(h4, "NUHM2_m12_600 (N2C1p/m, MadGraph)", "l") legend.AddEntry(h56, "NUHM2_m12_600 (N2C1p/m, MadSpin)", "l") legend.SetBorderSize(0) legend.SetTextFont(42) legend.SetTextSize(0.02) legend.SetFillColor(0) legend.SetFillStyle(0) legend.Draw() AtlasStyle.ATLASLabel(0.15, 0.85, "internal", ROOT.kBlack) output = var + ".pdf" canvas.SaveAs(output)
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
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 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 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_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)