def nuisance_plot(input_file_, orien_, sticker_, oname_): pars = get_parameters_from_file(input_file_) #adjust_parameters(pars) N = len(pars) g68 = TGraph(2 * N + 7) g95 = TGraph(2 * N + 7) gPR = TGraphAsymmErrors(N) for i in range(0, N): x = pars[i].value y = i + 1.5 xerr = pars[i].error yerr = 0. if orien_ == 'h': x, y = y, x xerr, yerr = yerr, xerr gPR.SetPoint(i, x, y) gPR.SetPointEXlow(i, xerr) gPR.SetPointEYlow(i, yerr) gPR.SetPointEXhigh(i, xerr) gPR.SetPointEYhigh(i, yerr) for a in range(0, N + 3): if orien_ == 'h': g68.SetPoint(a, a, -1) g95.SetPoint(a, a, -2) g68.SetPoint(a + 1 + N + 2, N + 2 - a, 1) g95.SetPoint(a + 1 + N + 2, N + 2 - a, 2) else: g68.SetPoint(a, -1, a) g95.SetPoint(a, -2, a) g68.SetPoint(a + 1 + N + 2, 1, N + 2 - a) g95.SetPoint(a + 1 + N + 2, 2, N + 2 - a) gPR.SetLineStyle(1) gPR.SetLineWidth(1) gPR.SetLineColor(1) gPR.SetMarkerStyle(21) gPR.SetMarkerSize(1.25) g68.SetFillColor(416) g95.SetFillColor(400) if orien_ == 'h': text_TL = TPaveText(0.100, 0.925, 0.440, 0.995, 'NDC') text_TR = TPaveText(0.587, 0.925, 0.999, 0.993, 'NDC') else: text_TL = TPaveText(0.370, 0.945, 0.590, 0.995, 'NDC') text_TR = TPaveText(0.600, 0.945, 0.995, 0.993, 'NDC') text_TL.AddText(label_TL) text_TL.SetFillColor(0) text_TL.SetTextAlign(12) text_TL.SetTextSize(0.06) text_TL.SetTextFont(42) text_TR.AddText(sticker_) text_TR.SetFillColor(0) text_TR.SetTextAlign(32) text_TR.SetTextSize(0.05) text_TR.SetTextFont(42) if orien_ == 'h': c = TCanvas('c', 'c', 1000, 700) c.SetTopMargin(0.08) c.SetRightMargin(0.02) c.SetBottomMargin(0.16) c.SetLeftMargin(0.11) else: c = TCanvas('c', 'c', 700, 1000) c.SetTopMargin(0.06) c.SetRightMargin(0.02) c.SetBottomMargin(0.12) c.SetLeftMargin(0.35 * 700 / 650) c.SetTickx() c.SetTicky() c.Update() g95.Draw('AF') g68.Draw('F') gPR.Draw('P') text_TL.Draw('same') text_TR.Draw('same') ax_1 = g95.GetHistogram().GetYaxis() ax_2 = g95.GetHistogram().GetXaxis() if orien_ == 'h': ax_1, ax_2 = ax_2, ax_1 ax_1.Set(N + 2, 0, N + 2) ax_1.SetNdivisions(-414) for i in range(0, N): ax_1.SetBinLabel(i + 2, pars[i].name) g95.SetTitle('') ax_2.SetTitle('post-fit nuisance parameters values') #ax_2.SetTitle('deviation in units of #sigma') ax_1.SetTitleSize(0.050) ax_2.SetTitleSize(0.050) ax_1.SetTitleOffset(1.4) ax_2.SetTitleOffset(1.0) ax_1.SetLabelSize(0.05) #ax_2.SetLabelSize(0.05) ax_1.SetRangeUser(0, N + 2) ax_2.SetRangeUser(-2.4, 2.4) g95.GetHistogram().Draw('axis,same') c.SaveAs(oname_ + '.pdf') c.Close()
statBox.SetBorderSize(0) # statBox.SetY2NDC(0.89) # statBox.SetY1NDC(0.71) # statBox.SetX2NDC(0.49) # statBox.SetX1NDC(0.11) statBox.SetX1NDC(0.11) statBox.SetX2NDC(0.49) statBox.SetY1NDC(0.69) statBox.SetY2NDC(0.89) # txt1 = TPaveText(x_0,gPad.GetUymin()+0.1,x_0+30,gPad.GetUymin()+1.50) txt1 = TPaveText(0.65, 100, 0.75, 120) txt1.AddText(str(lineFit.Eval(1 - (t_m / t_f)))) print(lineFit.Eval(1 - (t_m / t_f))) txt1.SetFillColor(0) txt1.SetTextFont(44) txt1.SetTextSize(26) # statBox.SetTextFont(44) # statBox.SetTextSize(26) statBox.Draw() gPad.Update() txt1.Draw() gPad.Update() DrawScatYLine( tgr2, ";(t_{m+f} #minus t_{m})/t_{f} / event;Times FSQ is called / event", "../images/mainFitEnhanced/fine/FvsFSQCalls", 1 - (t_m / t_f)) # Tested #DrawScat(DefineScat(pValueCutLoFloat, tPerEvent), ";p-value low cut;CPU time / event [s]","../images/mainFitEnhanced/coarse/time") # tracks_.append(tracks.GetEntries())
filler = 1 else: filler = difference / all_value h_acp.SetBinContent(bins + 1, math.fabs(1 - filler)) c1 = TCanvas() tl = TLegend(.15, .785, .45, .9) tl.SetBorderSize(0) tl.SetFillColor(0) tl.SetTextSize(16) tl.SetTextFont(63) tl.AddEntry(h_all, 'All events', 'l') tl.AddEntry(h_hit, 'Coincidence', 'l') tit = TPaveText(.5, .785, .7, .9, 'brNDC') tit.SetTextSize(20) tit.SetTextFont(63) tit.SetBorderSize(0) tit.SetFillColor(0) tit.AddText('300 mm gap') c1.SetTickx() c1.SetTicky() h_all.Draw() h_hit.Draw('same') tl.Draw('same') tit.Draw('same') h_acp.SetMarkerStyle(8) c2 = TCanvas() h_acp.Draw()
def DrawOverlap(fileVec, histVec, titleVec, legendtext, pngname, logstatus=[0, 0], xRange=[-99999, 99999, 1]): gStyle.SetOptTitle(0) gStyle.SetOptStat(0) gStyle.SetTitleOffset(1.1, "Y") gStyle.SetTitleOffset(0.9, "X") gStyle.SetLineWidth(3) gStyle.SetFrameLineWidth(3) i = 0 histList_ = [] histList = [] histList1 = [] maximum = [] ## Legend leg = TLegend(0.4, 0.70, 0.939, 0.89) #,NULL,"brNDC"); legendtitle = legendtext[-1] leg.SetHeader(legendtitle) leg.SetBorderSize(0) leg.SetNColumns(2) leg.SetLineColor(1) leg.SetLineStyle(1) leg.SetLineWidth(1) leg.SetFillColor(0) leg.SetFillStyle(0) leg.SetTextFont(22) leg.SetTextSize(0.045) c = TCanvas("c1", "c1", 0, 0, 500, 500) #c.SetBottomMargin(0.15) #c.SetLeftMargin(0.15) #c.SetLogy(0) #c.SetLogx(0) c1_2 = TPad("c1_2", "newpad", 0.04, 0.05, 1, 0.994) c1_2.Draw() print("you have provided " + str(len(fileVec)) + " files and " + str(len(histVec)) + " histograms to make a overlapping plot") print "opening rootfiles" c.cd() #c1_2.SetBottomMargin(0.13) c1_2.SetLogy(logstatus[1]) c1_2.SetLogx(logstatus[0]) c1_2.cd() ii = 0 inputfile = {} print str(fileVec[(len(fileVec) - 1)]) for ifile_ in range(len(fileVec)): print("opening file " + fileVec[ifile_]) inputfile[ifile_] = TFile(fileVec[ifile_]) print "fetching histograms" for ihisto_ in range(len(histVec)): print("printing histo " + str(histVec[ihisto_])) histo = inputfile[ifile_].Get(histVec[ihisto_]) #status_ = type(histo) is TGraphAsymmErrors histList.append(histo) # for ratio plot as they should nt be normalize histList1.append(histo) print histList[ii].Integral() #histList[ii].Rebin(xRange[2]) type_obj = type(histList[ii]) if (type_obj is TH1D) or (type_obj is TH1F) or ( type_obj is TH1) or (type_obj is TH1I): histList[ii].Rebin(1) histList[ii].Scale(1.0 / histList[ii].Integral()) maximum.append(histList[ii].GetMaximum()) maximum.sort() ii = ii + 1 print histList for ih in range(len(histList)): tt = type(histList[ih]) # print "graph_status =" ,(tt is TGraphAsymmErrors) # print "hist status =", (tt is TH1D) or (tt is TH1F) if ih == 0: if (tt is TGraphAsymmErrors) | (tt is TGraph): histList[ih].Draw("A3P") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("HIST") if ih > 0: #histList[ih].SetLineWidth(2) if (tt is TGraphAsymmErrors) | (tt is TGraph): histList[ih].Draw("3P same") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("HISTsame") if (tt is TGraphAsymmErrors) | (tt is TGraph): # histList[ih].SetMaximum(0.06) # histList[ih].SetMinimum(0.02) # histList[ih].SetMaximum(maximum+0.3) histList[ih].SetMinimum(0.02) histList[ih].SetMarkerColor(colors[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetLineWidth(3) histList[ih].SetLineStyle(linestyle[ih]) histList[ih].SetMarkerStyle(markerStyle[ih]) histList[ih].SetMarkerSize(1) leg.AddEntry(histList[ih], legendtext[ih], "P") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].SetLineStyle(linestyle[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetLineWidth(3) histList[ih].SetMaximum(maximum[0] + 0.3) histList[ih].SetMinimum(0) leg.AddEntry(histList[ih], legendtext[ih], "L") histList[ih].GetYaxis().SetTitle(titleVec[1]) histList[ih].GetYaxis().SetTitleSize(0.045) histList[ih].GetYaxis().SetTitleOffset(1.1000998) histList[ih].GetYaxis().SetTitleFont(22) histList[ih].GetYaxis().SetLabelFont(22) histList[ih].GetYaxis().SetLabelSize(.045) histList[ih].GetXaxis().SetRangeUser(xRange[0], xRange[1]) histList[ih].GetXaxis().SetLabelSize(0.0000) histList[ih].GetXaxis().SetTitle(titleVec[0]) histList[ih].GetXaxis().SetLabelSize(0.052) histList[ih].GetXaxis().SetTitleSize(0.052) histList[ih].GetXaxis().SetTitleOffset(1.04) histList[ih].GetXaxis().SetTitleFont(22) histList[ih].GetXaxis().SetTickLength(0.07) histList[ih].GetXaxis().SetLabelFont(22) histList[ih].GetYaxis().SetLabelFont(22) # histList[ih].GetXaxis().SetNdivisions(508) # i = i + 1 pt = TPaveText(0.0877181, 0.9, 0.9580537, 0.96, "brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(22) pt.SetTextSize(0.046) text = pt.AddText(0.05, 0.5, "CMS Preliminary") #text = pt.AddText(0.5,0.5,"12.9 fb^{-1} (13 TeV)") # text = pt.AddText(0.8,0.5," (13 TeV)") # text = pt.AddText(0.65,0.5," AK8") pt.Draw() # t2a = TPaveText(0.0877181,0.81,0.9580537,0.89,"brNDC") # t2a.SetBorderSize(0) # t2a.SetFillStyle(0) # t2a.SetTextSize(0.040) # t2a.SetTextAlign(12) # t2a.SetTextFont(62) # histolabel1= str(fileVec[(len(fileVec)-1)]) # text1 = t2a.AddText(0.06,0.5,"CMS Internal") # t2a.Draw() leg.Draw() # # c.cd() outputdirname = 'HGCAL/' histname = outputdirname + pngname c.SaveAs(histname + '.png') c.SaveAs(histname + '.pdf')
def make_histos(signal, com, cutflows, stage): N2s = [] N1s = [] N2mN1s = [] nTots = [] nTotErrs = [] nEnds = [] nEndErrs = [] paveTitle = '?' paveTitle2 = '' for cutflow in glob(cutflows): N2 = cutflow.split('_')[7] N1 = cutflow.split('_')[8] with open(cutflow, 'r') as f: for line in f: if line.split()[0] == 'entry' and line.split()[1] == 'point': nTot = line.split()[2] nTotErr = line.split()[3] elif line.split()[0] == 'dR-Lep1-Lep2-smaller-2': nEnd = line.split()[1] nEndErr = line.split()[2] N2s.append(float(N2)) N1s.append(float(N1)) N2mN1s.append(float(N2) - float(N1)) nTots.append(float(nTot)) nTotErrs.append(float(nTotErr)) nEnds.append(float(nEnd)) nEndErrs.append(float(nEndErr)) if signal == 'N2N1' and com == '13': N2bins = [90., 110., 130., 150., 170., 190., 210., 230., 250.] N2mN1bins = [6.5, 8.5, 12.5, 17.5, 25., 35., 45.] elif signal == 'N2C1' and com == '13': N2bins = [ 87.5, 112.5, 137.5, 162.5, 187.5, 212.5, 237.5, 262.5, 287.5, 312.5 ] N2mN1bins = [6.5, 8.5, 12.5, 17.5, 25., 35., 45.] elif signal == 'N2C1' and com == '14': N2bins = [75., 125., 175., 225., 275., 325., 375., 425.] N2mN1bins = [2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5] N2bina = array('d', sorted(set(N2bins))) N2mN1bina = array('d', sorted(set(N2mN1bins))) # Histogram h = TH2D('', '', len(N2bina) - 1, N2bina, len(N2mN1bina) - 1, N2mN1bina) for idx in range(0, len(N2s)): N2 = N2s[idx] N1 = N1s[idx] N2mN1 = N2mN1s[idx] nTot = nTots[idx] nTotErr = nTotErrs[idx] nEnd = nEnds[idx] nEndErr = nEndErrs[idx] #print 'Foo01', N2, N2mN1, nEnd if stage == 'nTot': paveTitle = 'Total events' h.Fill(N2, N2mN1, nTot) elif stage == 'nEnd': paveTitle = 'Events in SR' h.Fill(N2, N2mN1, nEnd) elif stage == 'Acc': paveTitle = 'Acceptance' paveTitle2 = '(*1000)' try: h.Fill(N2, N2mN1, 1000. * nEnd / nTot) except ZeroDivisionError: pass # Style gStyle.SetOptStat(0) gStyle.SetPaintTextFormat('.2f') h.GetXaxis().SetTitle('N2') h.GetYaxis().SetTitle('dM') set_palette() # Pave Text t1 = TPaveText(.1, .906, .2, 1., 'NDC') t1.SetTextSize(.039) t1.SetFillColor(0) t1.SetFillStyle(0) t1.SetLineWidth(0) t1.SetTextAlign(12) t1.AddText('CMS') t2 = TPaveText(.13, .9, .9, 1., 'NDC') t2.SetTextSize(.033) t2.SetFillColor(0) t2.SetFillStyle(0) t2.SetLineWidth(0) t2.SetTextAlign(12) t2.SetTextFont(42) t2.AddText('Phase-2 Simulation Preliminary {} {} at {}TeV {}'.format( signal, paveTitle, com, paveTitle2)) # Plot c = TCanvas() #c.SetLogy() h.Draw('colz|text') t1.Draw('same') t2.Draw('same') c.Print('{}_{}_{}TeV.pdf'.format(stage, signal, com)) c.Print('{}_{}_{}TeV.png'.format(stage, signal, com))
def draw_fit(self, save_name, flag_plot_message=None, shade_regions=False): #Draw self.histo_to_fit.GetXaxis().SetTitle("Invariant Mass L_{c}^{+}(GeV/c^{2})") self.histo_to_fit.SetStats(0) c1 = TCanvas('c1', 'The Fit Canvas', 700, 700) c1.cd() gStyle.SetOptStat(0) gStyle.SetCanvasColor(0) gStyle.SetFrameFillColor(0) c1.cd() self.histo_to_fit.GetXaxis().SetRangeUser(self.fit_range_low, self.fit_range_up) # Adjust y-range for good readability histo_min = self.histo_to_fit.GetMinimum() * 0.9 histo_max = self.histo_to_fit.GetMaximum() + (self.histo_to_fit.GetMaximum() - histo_min) self.histo_to_fit.GetYaxis().SetRangeUser(histo_min, histo_max) self.histo_to_fit.SetMarkerStyle(20) self.histo_to_fit.SetMarkerSize(1) #histo.SetMinimum(0.) self.histo_to_fit.Draw("PE") self.bkg_tot_fit_func.Draw("same") self.tot_fit_func.Draw("same") c1.Update() # Shading sideband area sideband_fill_left = None sideband_fill_right = None sig_fill = None bkg_fill = None if shade_regions: sideband_fill_left = self.bkg_tot_fit_func.Clone("bkg_fit_fill_left") sideband_fill_left.SetRange(self.mean_fit - 9 * self.sigma_fit, self.mean_fit - self.nsigma_sideband * self.sigma_fit) sideband_fill_left.SetLineWidth(0) sideband_fill_left.SetFillColor(self.bkg_tot_fit_func.GetLineColor()) sideband_fill_left.SetFillStyle(3001) sideband_fill_left.Draw("same fc") sideband_fill_right = self.bkg_tot_fit_func.Clone("bkg_fit_fill_right") sideband_fill_right.SetRange(self.mean_fit + self.nsigma_sideband * self.sigma_fit, self.mean_fit + 9 * self.sigma_fit) sideband_fill_right.SetLineWidth(0) sideband_fill_right.SetFillColor(self.bkg_tot_fit_func.GetLineColor()) sideband_fill_right.SetFillStyle(3001) sideband_fill_right.Draw("same fc") # Shading bakground in signal region bkg_fill = self.bkg_tot_fit_func.Clone("bkg_fit_under_sig_fill") bkg_fill.SetRange(self.mean_fit - self.nsigma_sig * self.sigma_fit, self.mean_fit + self.nsigma_sig * self.sigma_fit) bkg_fill.SetLineWidth(0) bkg_fill.SetFillColor(kRed + 2) bkg_fill.SetFillStyle(3001) bkg_fill.Draw("same fc") # Shading signal above background n_points = 100 dx = (2 * self.nsigma_sig * self.sigma_fit) / n_points sig_fill = TGraph(2 * n_points) sig_fill.SetFillColor(kGreen + 2) sig_fill.SetFillStyle(3001) range_low = self.mean_fit - self.nsigma_sig * self.sigma_fit range_up = self.mean_fit + self.nsigma_sig * self.sigma_fit for ip in range(n_points): sig_fill.SetPoint(ip, range_low + ip * dx, self.tot_fit_func.Eval(range_low + ip * dx)) sig_fill.SetPoint(n_points + ip, range_up - ip * dx, self.bkg_tot_fit_func.Eval(range_up - ip * dx)) sig_fill.Draw("f") #write info. pinfos = TPaveText(0.12, 0.7, 0.47, 0.89, "NDC") pinfos.SetBorderSize(0) pinfos.SetFillStyle(0) pinfos.SetTextAlign(11) pinfos.SetTextSize(0.03) pinfom = TPaveText(0.5, 0.7, 1., .89, "NDC") pinfom.SetTextAlign(11) pinfom.SetBorderSize(0) pinfom.SetFillStyle(0) pinfom.SetTextColor(kBlue) pinfom.SetTextSize(0.03) chisquare_ndf = self.tot_fit_func.GetNDF() chisquare_ndf = self.tot_fit_func.GetChisquare() / chisquare_ndf if chisquare_ndf > 0. \ else 0. pinfom.AddText("#chi^{2}/NDF = %f" % (chisquare_ndf)) pinfom.AddText("%s = %.3f #pm %.3f" % (self.sig_fit_func.GetParName(1),\ self.sig_fit_func.GetParameter(1), self.sig_fit_func.GetParError(1))) pinfom.AddText("%s = %.3f #pm %.3f" % (self.sig_fit_func.GetParName(2),\ self.sig_fit_func.GetParameter(2), self.sig_fit_func.GetParError(2))) pinfom.Draw() flag_info = None if flag_plot_message is not None: flag_info = TPaveText(0.5, 0.5, 1., 0.68, "NDC") flag_info.SetBorderSize(0) flag_info.SetFillStyle(0) flag_info.SetTextAlign(11) flag_info.SetTextSize(0.03) for t in flag_plot_message: text = flag_info.AddText(t) text.SetTextColor(kRed + 2) flag_info.Draw() sig_text = pinfos.AddText("S = %.0f #pm %.0f " % (self.yield_sig, self.yield_sig_err)) sig_text.SetTextColor(kGreen + 2) bkg_text = pinfos.AddText("B (%.0f#sigma) = %.0f #pm %.0f" % \ (self.nsigma_sig, self.yield_bkg, self.yield_bkg_err)) bkg_text.SetTextColor(kRed + 2) sig_over_back = self.yield_sig / self.yield_bkg if self.yield_bkg > 0. else 0. pinfos.AddText("S/B (%.0f#sigma) = %.4f " % (self.nsigma_sig, sig_over_back)) pinfos.AddText("Signif (%.0f#sigma) = %.1f #pm %.1f " %\ (self.nsigma_sig, self.significance, self.errsignificance)) pinfos.Draw() c1.Update() c1.SaveAs(save_name) c1.Close()
def DrawOverlap(fileVec, histVec, titleVec, legendtext, pngname, logstatus=[0, 0], xRange=[-99999, 99999, 1]): gStyle.SetOptTitle(0) gStyle.SetOptStat(0) gStyle.SetTitleOffset(1.1, "Y") #gStyle.SetTitleOffset(1.9,"X"); gStyle.SetLineWidth(3) gStyle.SetFrameLineWidth(3) i = 0 histList_ = [] histList = [] histList1 = [] maximum = [] ## Legend leg = TLegend(0.1, 0.70, 0.89, 0.89) #,NULL,"brNDC"); leg.SetBorderSize(0) leg.SetNColumns(2) leg.SetLineColor(1) leg.SetLineStyle(1) leg.SetLineWidth(1) leg.SetFillColor(0) leg.SetFillStyle(0) leg.SetTextFont(42) leg.SetTextSize(0.04) c = TCanvas("c1", "c1", 0, 0, 500, 500) c.SetBottomMargin(0.15) c.SetLogy(logstatus[1]) c.SetLogx(logstatus[0]) print("you have provided " + str(len(fileVec)) + " files and " + str(len(histVec)) + " histograms to make a overlapping plot") print "opening rootfiles" c.cd() ii = 0 inputfile = {} print str(fileVec[(len(fileVec) - 1)]) for ifile_ in range(len(fileVec)): print("opening file " + fileVec[ifile_]) inputfile[ifile_] = TFile(fileVec[ifile_]) print "fetching histograms" for ihisto_ in range(len(histVec)): print("printing histo " + str(histVec[ihisto_])) histo = inputfile[ifile_].Get(histVec[ihisto_]) #status_ = type(histo) is TGraphAsymmErrors histList.append(histo) # for ratio plot as they should nt be normalize histList1.append(histo) #print histList[ii].Integral() #histList[ii].Rebin(xRange[2]) #histList[ii].Scale(1.0/histList[ii].Integral()) maximum.append(histList[ii].GetMaximum()) maximum.sort() ii = ii + 1 print histList for ih in range(len(histList)): tt = type(histList[ih]) if logstatus[1] is 1: #histList[ih].SetMaximum(100) #1.4 for log #histList[ih].SetMinimum(0.1) #1.4 for log histList[ih].SetMaximum(10) histList[ih].SetMinimum(0.001) if logstatus[1] is 0: histList[ih].SetMaximum(1.4) #1.4 for log histList[ih].SetMinimum(0.001) #1.4 for log # print "graph_status =" ,(tt is TGraphAsymmErrors) # print "hist status =", (tt is TH1D) or (tt is TH1F) if ih == 0: if tt is TGraphAsymmErrors: histList[ih].Draw("APL") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw() ## removed hist if ih > 0: #histList[ih].SetLineWidth(2) if tt is TGraphAsymmErrors: histList[ih].Draw("PL same") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("same") ## removed hist if tt is TGraphAsymmErrors: histList[ih].SetMaximum(100) histList[ih].SetMarkerColor(colors[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetLineWidth(2) histList[ih].SetMarkerStyle(markerStyle[ih]) histList[ih].SetMarkerSize(1) leg.AddEntry(histList[ih], legendtext[ih], "PL") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].SetLineStyle(linestyle[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetLineWidth(3) leg.AddEntry(histList[ih], legendtext[ih], "L") histList[ih].GetYaxis().SetTitle(titleVec[1]) histList[ih].GetYaxis().SetTitleSize(0.052) histList[ih].GetYaxis().SetTitleOffset(0.98) histList[ih].GetYaxis().SetTitleFont(42) histList[ih].GetYaxis().SetLabelFont(42) histList[ih].GetYaxis().SetLabelSize(.052) histList[ih].GetXaxis().SetRangeUser(xRange[0], xRange[1]) # histList[ih].GetXaxis().SetLabelSize(0.0000); histList[ih].GetXaxis().SetTitle(titleVec[0]) histList[ih].GetXaxis().SetLabelSize(0.052) histList[ih].GetXaxis().SetTitleSize(0.052) #histList[ih].GetXaxis().SetTitleOffset(1.14) histList[ih].GetXaxis().SetTitleFont(42) histList[ih].GetXaxis().SetLabelFont(42) histList[ih].GetYaxis().SetLabelFont(42) histList[ih].GetXaxis().SetNdivisions(507) #histList[ih].GetXaxis().SetMoreLogLabels(); #histList[ih].GetXaxis().SetNoExponent(); #histList[ih].GetTGaxis().SetMaxDigits(3); i = i + 1 pt = TPaveText(0.01, 0.92, 0.95, 0.96, "brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(42) pt.SetTextSize(0.046) #text = pt.AddText(0.12,0.35,"CMS Internal 36 fb^{-1} (2016) ") text = pt.AddText(0.12, 0.35, "CMS Internal 41.5 fb^{-1} (2017) ") #text = pt.AddText(0.12,0.35,"CMS Internal 59.6 fb^{-1} (2018) ") #text = pt.AddText(0.6,0.5,"41.5 fb^{-1} (2017) ") pt.Draw() leg.Draw() outputdirname = 'plots_limit/limitcomp//' histname = outputdirname + pngname c.SaveAs(histname + '.png') c.SaveAs(histname + '.pdf') outputname = 'cp -r ' + outputdirname + '/*' + ' /afs/cern.ch/work/k/khurana/public/AnalysisStuff/monoH/LimitModelPlots/plots_limit/limitcomp/'
def plotMet(self): if hasattr(self, "TagPt35") or hasattr(self, "TagPt35ForNctrl"): if self._fout and self._canvas: sample = self.TagPt35ForNctrl["sample"] if hasattr( self, "TagPt35ForNctrl") else self.TagPt35["sample"] condorDir = self.TagPt35ForNctrl["condorDir"] if hasattr( self, "TagPt35ForNctrl") else self.TagPt35["condorDir"] name = self.TagPt35ForNctrl["name"] if hasattr( self, "TagPt35ForNctrl") else self.TagPt35["name"] hist = self._Flavor + " Plots/" + self._flavor + "MetNoMuMinusOnePt" metMinusOne = getHist(sample, condorDir, name + "Plotter", hist) hist = self._Flavor + " Plots/" + self._flavor + "MetNoMuMinusOneUpPt" metMinusOneUp = getHist(sample, condorDir, name + "Plotter", hist) metMinusOne.Rebin(self._rebinFactor) metMinusOneUp.Rebin(self._rebinFactor) pt = TPaveText(0.398496, 0.839147, 0.798246, 0.886951, "brNDC") pt.SetBorderSize(0) pt.SetFillStyle(0) pt.SetTextFont(42) pt.SetTextSize(0.0387597) pt.AddText(str(self._plotLabel)) cmsLabel = TPaveText(0.134085, 0.937984, 0.418546, 0.984496, "brNDC") cmsLabel.SetBorderSize(0) cmsLabel.SetFillStyle(0) cmsLabel.SetTextFont(62) cmsLabel.SetTextSize(0.0387597) cmsLabel.AddText("CMS Preliminary") lumiLabel = TPaveText(0.66416, 0.937339, 0.962406, 0.992894, "brNDC") lumiLabel.SetBorderSize(0) lumiLabel.SetFillStyle(0) lumiLabel.SetTextFont(42) lumiLabel.SetTextSize(0.0387597) lumiLabel.AddText(str(self._luminosityLabel)) leg = TLegend(0.414787, 0.726098, 0.606516, 0.829457) leg.SetBorderSize(0) leg.SetTextSize(0.0388601) leg.SetTextFont(42) leg.SetLineColor(1) leg.SetLineStyle(1) leg.SetLineWidth(1) leg.SetFillColor(0) leg.SetFillStyle(0) leg.AddEntry( metMinusOne, "nominal (#mu = " + str(round(metMinusOne.GetMean(), 1)) + " #pm " + str(round(metMinusOne.GetMeanError(), 1)) + ")", "p") leg.AddEntry( metMinusOneUp, "scaled down (#mu = " + str(round(metMinusOneUp.GetMean(), 1)) + " #pm " + str(round(metMinusOneUp.GetMeanError(), 1)) + ")", "p") setStyle(metMinusOne, 600) setAxisStyle( metMinusOne, "E_{T}^{miss, no #mu} " + ("excluding selected " + self._flavor if self._flavor != "muon" else "") + " [GeV]") setStyle(metMinusOneUp, 632) setAxisStyle( metMinusOneUp, "E_{T}^{miss, no #mu} " + ("excluding selected " + self._flavor if self._flavor != "muon" else "") + " [GeV]") self._canvas.cd() metMinusOneUp.Draw() metMinusOne.Draw("same") pt.Draw("same") cmsLabel.Draw("same") lumiLabel.Draw("same") leg.Draw("same") self._fout.cd() self._canvas.Write("metMinusOneComparison") else: print("A TFile and TCanvas must be added. Not making plots...") else: print( "Neither TagPt35 nor TagPt35ForNctrl defined. Not plotting MET..." )
def main(): from optparse import OptionParser parser = OptionParser() parser.add_option("-i", "--inputfile", dest="inputfile") (options, args) = parser.parse_args() from ROOT import TFile, TCanvas, TPaveText, TLegend import configurations as config from Styles import formatCL infile = TFile(options.inputfile, "READ") oldfile = TFile(config.MI_old_file, "READ") store = [] alphabet = "abcdefghijklmnopqrstuvwxyz" for iNmin, Nmin in enumerate(config.inclusive_multiplicities): c = TCanvas("UpperLimits_Inclusive_Mul%d" % Nmin, "N >= %d" % Nmin, 500, 500) store.append(c) gCL95 = infile.Get("CL95_N%dup" % Nmin) formatCL(gCL95, "CL95") gCL95.SetTitle("") gCL95.Draw("AL") gCLA = infile.Get("CLA_N%dup" % Nmin) formatCL(gCLA, "CLA") gCLA.SetTitle("") gCLA.Draw("L") label_11 = TPaveText(0.7116935,0.2076271,0.9193548,0.2605932,"brNDC") label_11.AddText(config.MI_new_label) label_11.SetTextSize(0.03813559); label_11.SetTextFont(42) label_11.SetFillColor(0) label_11.Draw("plain") store.append(label_11) if Nmin <= config.MI_old_Nmin: gCL95_ = oldfile.Get("CL95_N%dup" % Nmin) formatCL(gCL95_, "CL95", 2) gCL95_.SetLineStyle(9) gCL95_.SetTitle("") gCL95_.Draw("L") gCLA_ = oldfile.Get("CLA_N%dup" % Nmin) formatCL(gCLA_, "CLA", 2) gCLA_.SetTitle("") gCLA_.Draw("L") label_10 = TPaveText(0.6995968,0.4364407,0.9314516,0.4809322,"brNDC") label_10.AddText(config.MI_old_label) label_10.SetTextSize(0.03813559); label_10.SetTextFont(42) label_10.SetFillColor(0) label_10.Draw("plain") gCLA_.SetLineStyle(10) store.append(label_10) gCL95.GetXaxis().SetRangeUser(config.low_bin[0], config.MI_maxST + 100) gCL95.GetYaxis().SetRangeUser(1e-3, 15.0) cmslabel = TPaveText(0.3991935,0.7775424,0.8306452,0.9237288,"brNDC") cmslabel.AddText(config.cmsTitle) cmslabel.AddText(config.cmsSubtitle) cmslabel.SetFillColor(0) cmslabel.Draw("plain") store.append(cmslabel) legend = TLegend(0.4274194,0.5614407,0.7983871,0.7605932) legend.SetTextSize(0.04237288) legend.SetTextFont(42) legend.SetHeader("N #geq %d" % Nmin) legend.AddEntry(gCL95, "Observed #sigma^{95}", "l") legend.AddEntry(gCLA, "Expected #sigma^{95}_{exp.}", "l") legend.SetFillColor(0) legend.SetLineColor(0) legend.Draw("plain") store.append(legend) label = TPaveText(0.8891129,0.8644068,0.9435484,0.9258475,"brNDC") label.SetFillColor(0) label.SetTextSize(0.0529661); label.AddText("%s)" % alphabet[iNmin]) label.Draw("plain") store.append(label) c.SetLogy(1) c.Print("UpperLimits_Inclusive_Mul%d.pdf" % Nmin) c.Update() raw_input("Press Enter to continue...")
def limit_canvas(limits_, signal_, oname_): m = [mp.mass for mp in limits_] exp = [mp.exp for mp in limits_] exp68up = [mp.exp68up for mp in limits_] exp68dn = [mp.exp68dn for mp in limits_] exp95up = [mp.exp95up for mp in limits_] exp95dn = [mp.exp95dn for mp in limits_] obs = [mp.obs for mp in limits_] N = len(limits_) gExp = TGraph() g68 = TGraph(2*N) g95 = TGraph(2*N) gObs = TGraph() gTH = get_theory_XsecBR_graph(signal_) for a in range(0,N): gExp.SetPoint(a,m[a],exp[a]) gObs.SetPoint(a,m[a],obs[a]) g68.SetPoint(a,m[a],exp68dn[a]) g95.SetPoint(a,m[a],exp95dn[a]) g68.SetPoint(N+a,m[N-a-1],exp68up[N-a-1]) g95.SetPoint(N+a,m[N-a-1],exp95up[N-a-1]) trans = 0 up = 0 if signal_ == 'n': trans = 0.770776 up = 3 if signal_ == 'w': trans = 0.836432 up = 10 if signal_ == 'r': trans = 0.899902 up = 4 gExp.SetLineStyle(2) gExp.SetLineWidth(4) gExp.SetLineColor(TColor.GetColor('#112288')) #gExp.Print() g68.SetLineStyle(1) g68.SetLineWidth(0) g68.SetLineColor(kBlack) g68.SetFillColor(TColor.GetColor('#4488dd')) g95.SetLineStyle(1) g95.SetLineWidth(0) g95.SetLineColor(kBlack) g95.SetFillColor(TColor.GetColor('#99bbff')) gObs.SetLineStyle(1) gObs.SetLineWidth(4) gObs.SetLineColor(kBlack) gObs.SetMarkerStyle(21) gObs.SetMarkerSize(0.8) gTH.SetLineStyle(7) gTH.SetLineWidth(4) gTH.SetMarkerSize(0) gTH.SetMarkerColor(kRed+1) gTH.SetLineColor(kRed+1) leg = TLegend(0.58,0.633,0.969,0.908) leg.SetFillColor(0) leg.SetBorderSize(0) leg.AddEntry(gExp,'Expected (95% CL)','l') leg.AddEntry(gObs,'Observed (95% CL)','l') leg.AddEntry(gTH,signal_dict[signal_][1],'l') leg.AddEntry(g68,'#pm1#sigma Expected','f') leg.AddEntry(g95,'#pm2#sigma Expected','f') text_TL = TPaveText(0.18,0.830,0.44,0.900,'NDC') text_TL.AddText(label_TL) text_TL.SetFillColor(0) text_TL.SetTextAlign(12) text_TL.SetTextSize(0.06) text_TL.SetTextFont(42) text_TR = TPaveText(0.586,0.923,0.999,0.997,'NDC') text_TR.AddText(label_TR) text_TR.SetFillColor(0) text_TR.SetTextAlign(32) text_TR.SetTextSize(0.055) text_TR.SetTextFont(42) c = TCanvas('c','c',950,750) c.SetTopMargin(0.08) c.SetRightMargin(0.02) c.SetBottomMargin(0.135) c.SetLeftMargin(0.11) #c.SetGrid() c.SetLogy() #hr = c.DrawFrame(0.401,0.001,3.999,1000) #hr = c.DrawFrame(0.401,0.001,4.199,1000) hr = c.DrawFrame(0.401,0.001,5.199,1000) gExp.Sort() gTH.Print() g95.Draw('f') g95.Print() g68.Draw('f') gTH.Draw('L') gExp.Draw('L') #Don't draw observed for blind analysis # gObs.Sort() # gObs.Draw('L') hr.GetXaxis().SetTitle('M_{'+signal_dict[signal_][0]+'} [TeV]') hr.GetYaxis().SetTitle('Upper limit on #sigma_{'+signal_dict[signal_][0]+'} #times B('+signal_dict[signal_][0]+' #rightarrow t#bar{t}) [pb]') #hr.GetYaxis().SetTitle('\\mathrm{Upper~limit~on~}\\sigma_{'+signal_dict[signal_][0]+'}\\times\\mathscr{B}('+signal_dict[signal_][0]+' \\rightarrow t\\bar{t}) [pb]') hr.GetXaxis().SetTitleSize(0.055) hr.GetYaxis().SetTitleSize(0.055) hr.GetXaxis().SetTitleFont(42) hr.GetYaxis().SetTitleFont(42) hr.GetXaxis().SetTitleOffset(1.00) hr.GetYaxis().SetTitleOffset(0.98) hr.GetXaxis().SetLabelSize(0.045) hr.GetYaxis().SetLabelSize(0.045) name = TString(oname_) if name.Contains("com"): tl = TLine(trans, 1e-3, trans, up) tl.SetLineStyle(ROOT.kDashed) tl.SetLineColor(kGray+1) tl.SetLineWidth(3) tl.Draw() c.Update() text_TL.Draw('same') text_TR.Draw('same') leg.Draw() c.SaveAs(oname_+'.pdf') c.Close()
def printSystematic(self): fakeRate3, fakeRate3Error, ratio3, ratio3Error = self.printFakeRateRatio( 3) fakeRate4, fakeRate4Error, ratio4, ratio4Error = self.printFakeRateRatio( 4) fakeRate5, fakeRate5Error, ratio5, ratio5Error = self.printFakeRateRatio( 5) fakeRate6, fakeRate6Error, ratio6, ratio6Error = self.printFakeRateRatio( 6) print("systematic uncertainty: " + str((abs(ratio5 - 1.0) + ratio5Error) * 100.0) + "%") basicFakeRate = TH1D("basicFakeRate", ";number of hits", 400, 2.5, 6.5) zToMuMuFakeRate = TH1D("zToMuMuFakeRate", ";number of hits", 400, 2.5, 6.5) ratio = TH1D("ratio", ";number of hits", 400, 2.5, 6.5) basicFakeRate.SetBinContent(basicFakeRate.FindBin(3.0), fakeRate3[0]) basicFakeRate.SetBinError(basicFakeRate.FindBin(3.0), fakeRate3Error[0]) basicFakeRate.SetBinContent(basicFakeRate.FindBin(4.0), fakeRate4[0]) basicFakeRate.SetBinError(basicFakeRate.FindBin(4.0), fakeRate4Error[0]) basicFakeRate.SetBinContent(basicFakeRate.FindBin(5.0), fakeRate5[0]) basicFakeRate.SetBinError(basicFakeRate.FindBin(5.0), fakeRate5Error[0]) basicFakeRate.SetBinContent(basicFakeRate.FindBin(6.0), fakeRate6[0]) basicFakeRate.SetBinError(basicFakeRate.FindBin(6.0), fakeRate6Error[0]) zToMuMuFakeRate.SetBinContent(zToMuMuFakeRate.FindBin(3.0), fakeRate3[1]) zToMuMuFakeRate.SetBinError(zToMuMuFakeRate.FindBin(3.0), fakeRate3Error[1]) zToMuMuFakeRate.SetBinContent(zToMuMuFakeRate.FindBin(4.0), fakeRate4[1]) zToMuMuFakeRate.SetBinError(zToMuMuFakeRate.FindBin(4.0), fakeRate4Error[1]) zToMuMuFakeRate.SetBinContent(zToMuMuFakeRate.FindBin(5.0), fakeRate5[1]) zToMuMuFakeRate.SetBinError(zToMuMuFakeRate.FindBin(5.0), fakeRate5Error[1]) zToMuMuFakeRate.SetBinContent(zToMuMuFakeRate.FindBin(6.0), fakeRate6[1]) zToMuMuFakeRate.SetBinError(zToMuMuFakeRate.FindBin(6.0), fakeRate6Error[1]) ratio.SetBinContent(ratio.FindBin(3.0), ratio3) ratio.SetBinError(ratio.FindBin(3.0), ratio3Error) ratio.SetBinContent(ratio.FindBin(4.0), ratio4) ratio.SetBinError(ratio.FindBin(4.0), ratio4Error) ratio.SetBinContent(ratio.FindBin(5.0), ratio5) ratio.SetBinError(ratio.FindBin(5.0), ratio5Error) ratio.SetBinContent(ratio.FindBin(6.0), ratio6) ratio.SetBinError(ratio.FindBin(6.0), ratio6Error) cmsLabel = TPaveText(0.134085, 0.937984, 0.418546, 0.984496, "brNDC") cmsLabel.SetBorderSize(0) cmsLabel.SetFillStyle(0) cmsLabel.SetTextFont(62) cmsLabel.SetTextSize(0.0387597) cmsLabel.AddText("CMS Preliminary") lumiLabel = TPaveText(0.66416, 0.937339, 0.962406, 0.992894, "brNDC") lumiLabel.SetBorderSize(0) lumiLabel.SetFillStyle(0) lumiLabel.SetTextFont(42) lumiLabel.SetTextSize(0.0387597) lumiLabel.AddText(str(self._luminosityLabel)) leg = TLegend(0.7550251, 0.7759067, 0.9459799, 0.8795337) leg.SetBorderSize(0) leg.SetTextSize(0.0388601) leg.SetTextFont(42) leg.SetLineColor(1) leg.SetLineStyle(1) leg.SetLineWidth(1) leg.SetFillColor(0) leg.SetFillStyle(0) leg.AddEntry(zToMuMuFakeRate, "Z#rightarrow#mu#mu", "p") leg.AddEntry(basicFakeRate, "basic", "p") setStyle(basicFakeRate, 632) setStyle(zToMuMuFakeRate, 600) setAxisStyle(basicFakeRate, yTitle="P_{fake}") setAxisStyle(zToMuMuFakeRate, yTitle="P_{fake}") self._canvas.cd() self._canvas.SetLogy() zToMuMuFakeRate.Draw() basicFakeRate.Draw("same") leg.Draw("same") cmsLabel.Draw("same") lumiLabel.Draw("same") self._fout.cd() self._canvas.Write("fakeRate") line = TLine(2.5, 1.0, 6.5, 1.0) line.SetLineStyle(2) line.SetLineWidth(2) line.SetLineColor(1) setStyle(ratio) setAxisStyle( ratio, yTitle=("P_{fake}^{Z#rightarrow#mu#mu} / P_{fake}^{basic}" if not self._plotDiff else "P_{fake}^{Z#rightarrow#mu#mu} - P_{fake}^{basic}")) self._canvas.cd() self._canvas.SetLogy(False) ratio.Draw() line.Draw("same") cmsLabel.Draw("same") lumiLabel.Draw("same") self._fout.cd() self._canvas.Write("fakeRateRatio")
def Measure_Integral(AllRuns, Title, RootName): FNumber=len(AllRuns) xIntegral=array("d",xrange(0,FNumber)) yIntegral=array("d",xrange(0,FNumber)) yIntegralErrUp=array("d",xrange(0,FNumber)) yIntegralErrDown=array("d",xrange(0,FNumber)) xIntegral_RMS=array("d",xrange(0,FNumber)) yIntegral_RMS=array("d",xrange(0,FNumber)) yIntegral_RMSErrUp=array("d",xrange(0,FNumber)) yIntegral_RMSErrDown=array("d",xrange(0,FNumber)) xRatio=array("d",xrange(0,FNumber)) yRatio=array("d",xrange(0,FNumber)) xSingleEv=array("d",xrange(0,40)) ySingleEv=array("d",xrange(0,40)) OutFile=TFile(RootName,"RECREATE") num=-1 iAmp=0 for Fname in AllRuns: num+=1 iAmp+=1 f = open(Fname) data = getData(f) M=TH1F(Fname,Fname,600,0,120000) x = array("d", xrange(0,1001)) y = array("d", xrange(0,1001)) for event in xrange(0,995): pedSum=0 sigSum=0 Signal=0 Pedestal=0 for BX in xrange(0, 40): adcValue=data[event][link][BX][linkChannel] if BX < 15 : pedSum += adcValue if BX > 19 and BX < 25: sigSum += adcValue xSingleEv[BX]=BX ySingleEv[BX]=adcValue scanvas = MakeCanvas("mm","nn",800,800) GrSingleEv=TGraph(len(xSingleEv),xSingleEv,ySingleEv) OutFile.WriteObject(GrSingleEv,"singleEv_"+str(iAmp)+"_"+str(event)) SFit=TF1("fit", "gaus", 19,23) SFit.SetParameter(0, 4000) SFit.SetParameter(1, 20.9) SFit.SetParLimits(1, 20, 22) SFit.SetParameter(2, 1.5) GrSingleEv.Draw("AC*") GrSingleEv.Fit("fit","R0") SFit.Draw("same") FitParam=SFit.GetParameters() print "Gaus fit param 1, 2, 3= " , round(FitParam[0],4), round(FitParam[1],4), round(FitParam[2],4) scanvas.SaveAs("PLOT/singleEv_"+str(iAmp)+"_"+str(event)+".pdf") Pedestal=pedSum/15. y[event]= sigSum- Pedestal*5 M.Fill(y[event]) histMean= M.GetMean() histRMS= M.GetStdDev() highVal = histMean + 4 * histRMS lowVal = histMean - 4 * histRMS highValAx = histMean + 6 * histRMS lowValAx = histMean - 6 * histRMS canvas = MakeCanvas("asdf","asdf",800,800) canvas.Update() MyGr= TGraph(len(x), x,y) mfit=TF1("fit", "gaus", lowVal,highVal) M.Fit(mfit, "R0","") FitParam=mfit.GetParameters() # FitParErr=mfit.GetParError() integral= round(FitParam[1],4) integral_RMS= round(FitParam[2],4) integralErr= round(mfit.GetParError(1),4) integral_RMSErr= round(mfit.GetParError(2),4) print "iAmp=", iAmp, " integral= ", integral, " integral_RMS=", integral_RMS M.SetMarkerStyle(22) M.GetXaxis().SetRangeUser(lowValAx,highValAx) M.SetTitle(Title+" = "+str(iAmp)) M.Draw("pe") mfit.Draw("same") fitInfo =TPaveText(.20,0.7,.60,0.9, "NDC"); fitInfo.SetBorderSize( 0 ); fitInfo.SetFillStyle( 0 ); fitInfo.SetTextAlign( 12 ); fitInfo.SetTextSize ( 0.03 ); fitInfo.SetTextColor( 1 ); fitInfo.SetTextFont ( 62 ); fitInfo.AddText("Mean of Fit=" + str(round(FitParam[1],1))) fitInfo.AddText("RMS of Fit =" + str(round(FitParam[2],1))) fitInfo.Draw() canvas.SaveAs("HistoSingleRun_"+str(iAmp)+"_"+Title+RootName+".pdf") xIntegral[num]=iAmp yIntegral[num]=integral yIntegralErrUp[num]=integral+integralErr yIntegralErrDown[num]=integral-integralErr xIntegral_RMS[num]=iAmp yIntegral_RMS[num]=integral_RMS yIntegral_RMSErrUp[num]=integral_RMS+integral_RMSErr yIntegral_RMSErrDown[num]=integral_RMS-integral_RMSErr xRatio[num]=iAmp yRatio[num]=integral_RMS/integral # xIntegral.append(iAmp) # yIntegral.append(integral) # xIntegral_RMS.append(iAmp) # yIntegral_RMS.append(integral_RMS) Graph_Integral= TGraph(len(xIntegral), xIntegral,yIntegral) Graph_IntegralErUp= TGraph(len(xIntegral), xIntegral,yIntegralErrUp) Graph_IntegralErDown= TGraph(len(xIntegral), xIntegral,yIntegralErrDown) canvas_Integral = MakeCanvas("can1","can1",800,800) # canvas_Integral.SetLogy() Graph_Integral.SetTitle("Pulse Integral Stability") Graph_Integral.SetMarkerStyle(22) Graph_Integral.SetMarkerColor(3) Graph_Integral.SetMarkerSize(2) Graph_Integral.GetXaxis().SetTitle("Day") Graph_Integral.GetYaxis().SetRangeUser(80000,85000) Graph_Integral.Draw() # Graph_IntegralErUp.Draw("same") # Graph_IntegralErDown.Draw("same") canvas_Integral.SaveAs("Integral_"+Title+RootName+".pdf") Graph_Integral_RMS= TGraph(len(xIntegral_RMS), xIntegral_RMS,yIntegral_RMS) Graph_Integral_RMSErUp= TGraph(len(xIntegral_RMS), xIntegral_RMS,yIntegral_RMSErrUp) Graph_Integral_RMSErDown= TGraph(len(xIntegral_RMS), xIntegral_RMS,yIntegral_RMSErrDown) canvas_Integral_RMS = MakeCanvas("can2","can2",800,800) Graph_Integral_RMS.SetTitle("Pulse Integral RMS vs. Pulse "+Title) Graph_Integral_RMS.SetMarkerStyle(23) Graph_Integral_RMS.SetMarkerColor(2) Graph_Integral_RMS.SetMarkerSize(2) Graph_Integral.GetXaxis().SetTitle("Day") Graph_Integral_RMS.Draw() # Graph_Integral_RMSErUp.Draw("same") # Graph_Integral_RMSErDown.Draw("same") canvas_Integral_RMS.SaveAs("Integral_RMS_"+Title+RootName+".pdf") Graph_Ratio= TGraph(len(xRatio), xRatio,yRatio) canvas_Ratio = MakeCanvas("can2","can2",800,800) Graph_Ratio.SetTitle("Ratio of Pulse Integral RMS and Pulse Integral "+Title) Graph_Ratio.SetMarkerStyle(21) Graph_Ratio.SetMarkerColor(8) Graph_Ratio.SetMarkerSize(2) Graph_Integral.GetXaxis().SetTitle("Day") Graph_Ratio.Draw() canvas_Ratio.SaveAs("Ratio_"+Title+RootName+".pdf") # OutFile=TFile(RootName,"RECREATE") OutFile.WriteObject(Graph_Integral,"Graph_Integral") OutFile.WriteObject(Graph_Integral_RMS,"Graph_Integral_RMS") OutFile.WriteObject(Graph_Ratio,"Graph_Ratio") OutFile.Close()
def main(): import configurations as config import csv from ModelParser import ModelKey, GroupXsecLimit from ROOT import gStyle from Styles import marker gStyle.SetPadTopMargin(0.05) gStyle.SetPadRightMargin(0.05) from optparse import OptionParser parser = OptionParser() parser.add_option("-i", "--inputfile", dest="inputfile") (options, args) = parser.parse_args() models = [] with open(config.bh_list, 'rb') as f: reader = csv.reader(f) for r in reader: models.append(ModelKey(r[0])) from ROOT import TFile, TMultiGraph, TGraph, TLegend, TCanvas infile_xsec = TFile(config.bh_xsec, "READ") infile_CL = TFile(options.inputfile, "READ") from OptimizationTools import Bisection from Styles import formatXsecCL, formatExcludedMass store = [] mg = TMultiGraph() legend1 = TLegend(0.3241611,0.49,0.746644,0.69) legend1.SetHeader("Observed Cross Section Limits") legend1.SetTextSize(0.037) legend1.SetTextFont(42) legend1.SetFillColor(0) legend1.SetLineColor(0) legend2 = TLegend(0.3241611,0.68,0.746644,0.88) legend2.SetHeader("Theoretical Cross Section") legend2.SetTextSize(0.037) legend2.SetTextFont(42) legend2.SetFillColor(0) legend2.SetLineColor(0) legend3 = TLegend(0.3241611,0.8806993,0.886644,0.9273427) legend3.SetHeader("String Ball (BlackMax)") legend3.SetTextSize(0.037) legend3.SetTextFont(42) legend3.SetFillColor(0) legend3.SetLineColor(0) iColor = 0 iStyle = 2 #for key, group in ModelLimitGroup(models).items(): for key, group in GroupXsecLimit(models).items(): if not "SB" in key: continue name = ModelKey(key).name gXsec = infile_xsec.Get(key) formatXsecCL(gXsec, iColor, iStyle) mg.Add(gXsec, "c") legend2.AddEntry(gXsec, config.model_description[name], "l") gCL95 = infile_CL.Get("%s-CL95" % key) formatXsecCL(gCL95, iColor, 1) mg.Add(gCL95, "pl") legend1.AddEntry(gCL95, config.model_description[name], "pl") iColor += 1 iStyle += 2 c = TCanvas("SB_BM", "SB_BM", 500, 500) c.SetLogy() mg.Draw("A") mg.GetXaxis().SetTitle("M^{ min} (TeV)") mg.GetXaxis().SetRangeUser(3.9,7.1) mg.GetYaxis().SetRangeUser(1e-4,50) mg.GetYaxis().SetTitle("#sigma (pb)") mg.GetYaxis().SetTitleOffset(1.05) mg.GetYaxis().SetTitleSize(0.045) mg.GetYaxis().SetLabelSize(0.045) mg.GetXaxis().SetTitleSize(0.045) mg.GetXaxis().SetLabelSize(0.045) legend1.Draw("plain") legend2.Draw("plain") legend3.Draw("plain") c.Update() from ROOT import TPaveText cmslabel = TPaveText(0.45,0.96,0.60,0.99,"brNDC") cmslabel.AddText(config.cmsTitle) cmslabel.SetTextSize(0.041) #cmslabel.AddText(config.cmsSubtitle) cmslabel.SetFillColor(0) cmslabel.Draw("plain") raw_input("Press Enter to continue...")
def Measure_Integral(Fname1, Fname2, Title, XaxisT, low, high, freq, RootName): FNumber = int((high - low) / freq) print "************* -> initiating The ", Fname1, " and number of files exist= ", FNumber # xIntegral=[] # yIntegral=[] # xIntegral_RMS=[] # yIntegral_RMS=[] # LINK=[15] LINK = [15, 16, 17, 18, 19.20] # LINKkChannel=[0,1,2,3,4,5] LINKkChannel = [4] for linkChannel in LINKkChannel: for link in LINK: xIntegral = array("d", xrange(0, FNumber)) yIntegral = array("d", xrange(0, FNumber)) yIntegralErrUp = array("d", xrange(0, FNumber)) yIntegralErrDown = array("d", xrange(0, FNumber)) xIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMSErrUp = array("d", xrange(0, FNumber)) yIntegral_RMSErrDown = array("d", xrange(0, FNumber)) xRatio = array("d", xrange(0, FNumber)) yRatio = array("d", xrange(0, FNumber)) num = -1 for iAmp in range(low, high, freq): num += 1 Fname = Fname1 + str(iAmp) + Fname2 print "************* -> initiating The ", Fname, " and number of files exist= ", FNumber print "--------------------> Now is doing .... ", low, " ____ ", Fname f = open(Fname) # data = getData(f) tdc = getTDCValues(f) M = TH1F(Fname, Fname, 200, 0, 100) x = array("d", xrange(0, 1001)) y = array("d", xrange(0, 1001)) for event in xrange(0, 995): tdcValue = 0 for BX in xrange(0, 40): if (iAmp <= 10 and BX == 20 and tdc[event][link][BX][linkChannel] != 31.5): tdcValue = tdc[event][link][BX][linkChannel] if (iAmp > 10 and BX == 21 and tdc[event][link][BX][linkChannel] != 31.5): tdcValue = tdc[event][link][BX][linkChannel] y[event] = tdcValue M.Fill(y[event]) histMean = M.GetMean() histRMS = M.GetStdDev() highVal = histMean + 4 * histRMS lowVal = histMean - 4 * histRMS highValAx = histMean + 6 * histRMS lowValAx = histMean - 6 * histRMS canvas = MakeCanvas("can", "can", 800, 800) canvas.Update() MyGr = TGraph(len(x), x, y) mfit = TF1("fit", "gaus", lowVal, highVal) M.Fit(mfit, "R0", "") FitParam = mfit.GetParameters() # FitParErr=mfit.GetParError() integral = histMean if FitParam[1] < 1.5 * histMean: integral = round(FitParam[1], 4) integral_RMS = histRMS if round(FitParam[2], 4) < 2 * histRMS: integral_RMS = round(FitParam[2], 4) integralErr = round(mfit.GetParError(1), 4) integral_RMSErr = round(mfit.GetParError(2), 4) print "iAmp=", iAmp, " integral= ", integral, " integral_RMS=", integral_RMS M.SetMarkerStyle(22) M.GetXaxis().SetRangeUser(0, 30) M.SetTitle("TDC v.s. Delay Setting (ns)") M.Draw("pe") mfit.Draw("same") fitInfo = TPaveText(.20, 0.7, .60, 0.9, "NDC") fitInfo.SetBorderSize(0) fitInfo.SetFillStyle(0) fitInfo.SetTextAlign(12) fitInfo.SetTextSize(0.03) fitInfo.SetTextColor(1) fitInfo.SetTextFont(62) fitInfo.AddText("Mean of Fit=" + str(round(FitParam[1], 1))) fitInfo.AddText("RMS of Fit =" + str(round(FitParam[2], 1))) fitInfo.AddText("Delay Setting =" + str(iAmp)) fitInfo.AddText("link =" + str(link) + " channel=" + str(linkChannel)) fitInfo.Draw() canvas.SaveAs("outHistoSingleRun_" + RootName + str(iAmp) + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf") XVAL = low + num * freq xIntegral[num] = XVAL yIntegral[num] = integral yIntegralErrUp[num] = integral + integralErr yIntegralErrDown[num] = integral - integralErr xIntegral_RMS[num] = XVAL yIntegral_RMS[num] = integral_RMS yIntegral_RMSErrUp[num] = integral_RMS + integral_RMSErr yIntegral_RMSErrDown[num] = integral_RMS - integral_RMSErr print "iAmp, integral= ", iAmp, " ", integral, " XVAL= ", XVAL # xRatio[num]=XVAL # yRatio[num]=integral_RMS/integral # xIntegral.append(iAmp) # yIntegral.append(integral) # xIntegral_RMS.append(iAmp) # yIntegral_RMS.append(integral_RMS) Graph_TDC = TGraph(len(xIntegral), xIntegral, yIntegral) Graph_TDCErUp = TGraph(len(xIntegral), xIntegral, yIntegralErrUp) Graph_TDCErDown = TGraph(len(xIntegral), xIntegral, yIntegralErrDown) canvas_TDC = MakeCanvas("can1", "can1", 800, 800) Graph_TDC.SetTitle("") Graph_TDC.SetMarkerStyle(22) Graph_TDC.SetMarkerColor(3) Graph_TDC.SetMarkerSize(2) Graph_TDC.GetXaxis().SetTitle(XaxisT) Graph_TDC.GetYaxis().SetRangeUser(0, 30) Graph_TDC.GetYaxis().SetTitle("TDC [ns]") Graph_TDC.Draw() Graph_TDCErUp.Draw("same") Graph_TDCErDown.Draw("same") canvas_TDC.SaveAs("outHisto_" + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf") Graph_TDC_RMS = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMS) Graph_TDC_RMSErUp = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMSErrUp) Graph_TDC_RMSErDown = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMSErrDown) canvas_TDC_RMS = MakeCanvas("can2", "can2", 800, 800) Graph_TDC_RMS.SetTitle("TDC RMS vs. Pulse " + Title) Graph_TDC_RMS.SetMarkerStyle(23) Graph_TDC_RMS.SetMarkerColor(2) Graph_TDC_RMS.SetMarkerSize(2) Graph_TDC_RMS.GetXaxis().SetTitle(XaxisT) Graph_TDC_RMS.GetYaxis().SetRangeUser(0, 2) Graph_TDC_RMS.Draw() Graph_TDC_RMSErUp.Draw("same") Graph_TDC_RMSErDown.Draw("same") canvas_TDC_RMS.SaveAs("outHistoRMS_" + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf") OutFile = TFile( "outFile_" + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".root", "RECREATE") OutFile.WriteObject(Graph_TDC, "Graph_TDC") OutFile.WriteObject(Graph_TDC_RMS, "Graph_TDC_RMS") OutFile.Close()
def Measure_Integral(Fname1, Fname2, Title, XaxisT, low, high, freq, RootName): FNumber = int((high - low) / freq) LINK = [3] # LINK=[15,16,17,18,19] LINKkChannel = [0, 1, 2, 3, 4, 5] # LINKkChannel=[0] for linkChannel in LINKkChannel: for link in LINK: xIntegral = array("d", xrange(0, FNumber)) yIntegral = array("d", xrange(0, FNumber)) yIntegralErrUp = array("d", xrange(0, FNumber)) yIntegralErrDown = array("d", xrange(0, FNumber)) xIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMSErrUp = array("d", xrange(0, FNumber)) yIntegral_RMSErrDown = array("d", xrange(0, FNumber)) xRatio = array("d", xrange(0, FNumber)) yRatio = array("d", xrange(0, FNumber)) xSingleEv = array("d", xrange(0, 40)) ySingleEv = array("d", xrange(0, 40)) num = -1 for iAmp in range(low, high, freq): num += 1 Fname = Fname1 + str(iAmp) + Fname2 f = open(Fname) data = getData(f) M = TH1F(Fname, Fname, 200, 0.4, 1.4) HistoSergey = TH1F(Fname, Fname, 200, -10, 200) M.SetDefaultSumw2() x = array("d", xrange(0, 1001)) y = array("d", xrange(0, 1001)) for event in xrange(0, 9): for BX in xrange(0, 40): xSingleEv[BX] = BX ySingleEv[BX] = data[event][link][BX][linkChannel] if BX < 16: HistoSergey.Fill(ySingleEv[BX]) if ySingleEv[BX] <= 0: ySingleEv[BX] = 0.1 if ySingleEv[BX] < 0.1: print "--->", ySingleEv[BX] scanvas = MakeCanvas("mm", "nn", 800, 800) scanvas.SetLogy() GrSingleEv = TGraph(len(xSingleEv), xSingleEv, ySingleEv) # SFit=TF1("fit", "gaus", 19,23) # SFit.SetParameter(0, 250) # SFit.SetParameter(1, 20.9) # SFit.SetParLimits(1, 20, 22) # SFit.SetParameter(2, 1) GrSingleEv.GetXaxis().SetRangeUser(0, 40) GrSingleEv.GetYaxis().SetRangeUser(0.05, 100000) GrSingleEv.Draw("AC*") # GrSingleEv.Fit("fit","R0") # SFit.Draw("same") # FitParam=SFit.GetParameters() # print "Gaus fit param 1, 2, 3= " , round(FitParam[0],4), round(FitParam[1],4), round(FitParam[2],4) fitInfo = TPaveText(.20, 0.7, .60, 0.9, "NDC") fitInfo.SetBorderSize(0) fitInfo.SetFillStyle(0) fitInfo.SetTextAlign(12) fitInfo.SetTextSize(0.03) fitInfo.SetTextColor(1) fitInfo.SetTextFont(62) fitInfo.AddText("eventNumber_" + str(event) + "_link" + str(link) + "_ch_" + str(linkChannel)) fitInfo.Draw() scanvas.SaveAs("PLOT/singleEv_" + str(iAmp) + "_" + str(event) + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf") sergeycanvas = MakeCanvas("mm", "nn", 800, 800) HistoSergey.Draw() sergeycanvas.SaveAs("SergeyHisto" + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf")
def main(): from optparse import OptionParser parser = OptionParser() parser.add_option("-i", "--inputfile", dest="inputfile") parser.add_option("-N", "--multiplicity", dest="N", type="int", default=3) parser.add_option("-x", "--exclusive", action="store_true",\ dest="isExclusive", default=False) parser.add_option("-l", "--label", dest="label", type="string", default="") (options, args) = parser.parse_args() N = options.N isExclusive = options.isExclusive label_text = options.label if isExclusive and not (N == 2 or N == 3): parser.error("Exclusive plot only for N =2 or 3") import configurations as config from ROOT import TFile, TCanvas, THStack, TLegend, TPaveText, TH1F, gStyle from ModelParser import ModelKey gStyle.SetPadTopMargin(0.05) gStyle.SetPadRightMargin(0.05) gStyle.SetOptStat(0000000) suffix = "" if not isExclusive: suffix = "up" sm_files = [] for model in config.sm_models: f = TFile("%s/%s.root" % (config.sm_dir, model), "READ") sm_files.append(f) bh_weights = [] bh_files = [] from BHXsec import BHXsec xsec = BHXsec() for model in config.bh_showcase: f = TFile("%s/%s.root" % (config.bh_dir, model), "READ") bh_files.append(f) h = f.Get("plotsNoCut/ST") nEvents = h.GetEntries() bh_weights.append( xsec.get(model) / nEvents * config.integrated_luminosity) c = TCanvas("ST_Mul%d%s" % (N, suffix), "ST_Mul%d%s" % (N, suffix), 500, 500) hs = THStack() hs1 = THStack() infile = TFile(options.inputfile, "READ") hBkg = infile.Get("Background_N%d%s" % (N, suffix)) gBkg = infile.Get("BackgroundGraph_N%d%s" % (N, suffix)) hData = infile.Get("Data_N%d%s" % (N, suffix)) hBkg = infile.Get("Background_N%d%s" % (N, suffix)) hBkg.SetMarkerSize(0) hBkg_ = hBkg.Clone("BkgLine") hBkg.SetFillColor(33) hBkg.SetLineColor(33) hBkg_.SetLineWidth(3) hBkg_.SetLineColor(862) hs.Add(hBkg, "e3") hData_N2 = infile.Get("Data_N2") hBkg_N2 = infile.Get("Background_N2") ratio_data = infile.Get("Data_N%d%s" % (N, suffix)) ratio_data.Sumw2() ratio_data.Divide(hData_N2, hBkg_N2) ref_N2 = infile.Get("ReferenceTemplateN2_0") ref_N3 = infile.Get("ReferenceTemplateN3_0") ratio_fits = infile.Get("ReferenceTemplateN2_0") ratio_fits.Sumw2() ratio_fits.Divide(ref_N2, ref_N3) legend = TLegend(0.3026613, 0.6919492, 0.6094355, 0.8816102) legend.SetTextSize(0.041) #was 0.02966102 legend.SetTextFont(42) legend.SetFillColor(0) legend.SetLineColor(0) if isExclusive: legend.SetHeader("Multiplicity, N = %d" % N) else: legend.SetHeader("Multiplicity, N #geq %d" % N) legend.AddEntry(ratio_data, "Data/Background", "p") legend.AddEntry(ratio_fits, "Fit-0 (N=2)/Fit-0 (N=3)", "l") legend_sm = TLegend(0.6271774, 0.6769492, 0.8308065, 0.8171186) legend_sm.SetTextSize(0.041) legend_sm.SetTextFont(42) legend_sm.SetFillColor(0) legend_sm.SetLineColor(0) for i, f in enumerate(bh_files): h = f.Get("plotsN%d%s/ST" % (N, suffix)) h.Rebin(config.rebin) h.Scale(bh_weights[i]) # Add background for ibin in range(h.GetNbinsX()): h.SetBinContent(ibin+1,\ h.GetBinContent(ibin+1)\ + hBkg.GetBinContent(ibin+1)) h.SetLineWidth(2) h.SetLineStyle(i + 2) hs.Add(h, "hist") model = ModelKey(config.bh_showcase[i]) bh_legend = "M_{D} = %.1f TeV, M_{BH}^{ min} = %.1f TeV, n = %d" % (\ model.parameter["MD"], model.parameter["M"], model.parameter["n"]) #legend.AddEntry(h, bh_legend, "l") if isExclusive: for i, f in enumerate(sm_files): h = f.Get("plotsN%d%s/ST" % (N, suffix)) h.Rebin(config.rebin) h.Scale(config.integrated_luminosity) h.SetFillColor(config.sm_colors[i]) h.SetLineColor(config.sm_colors[i]) hs1.Add(h, "hist") #legend_sm.AddEntry(h, config.sm_models[i], "f") #hs.Add(hData, "e") #TH1F *ratio_data ratio_fits.SetLineColor(4) ratio_fits.SetMarkerStyle(0) ratio_fits.SetLineWidth(2) #hs1.SetMinimum(1e-1) ratio_fits.Draw("linee1") ratio_data.Draw("same") #hs.Draw("samenostack") #c.SetLogy(1) ratio_fits.GetXaxis().SetTitle("S_{T} (GeV)") ratio_fits.GetYaxis().SetTitle("Arbitrary Units") ratio_fits.GetYaxis().SetTitleOffset(1.1) ratio_fits.GetYaxis().SetTitleSize(0.045) ratio_fits.GetYaxis().SetLabelSize(0.045) ratio_fits.GetXaxis().SetTitleSize(0.045) ratio_fits.GetXaxis().SetLabelSize(0.045) ratio_fits.GetXaxis().Draw() ibin = 0 if isExclusive: ratio_fits.GetXaxis().SetRangeUser(config.fit_range[0], config.fit_range[1] + 330) ibin = hData.FindBin(config.fit_range[0]) else: ratio_fits.GetXaxis().SetRangeUser(config.norm_range[0], config.norm_range[1] + 330) ibin = hData.FindBin(config.norm_range[0]) from Styles import formatUncertainty formatUncertainty(gBkg) #gBkg.Draw("LX") #hData.GetXaxis().SetNdivisions(510) #hData.Draw("esame") ratio_fits.SetTitle("") ratio_fits.SetMinimum(0) ratio_fits.SetMaximum(3) legend.Draw("plain") #if isExclusive: # legend_sm.Draw("plain") if isExclusive: cmslabel = TPaveText(0.45, 0.90, 0.60, 0.93, "brNDC") else: cmslabel = TPaveText(0.45, 0.90, 0.60, 0.93, "brNDC") cmslabel.AddText(config.cmsTitle) #cmslabel.AddText(config.cmsSubtitle) cmslabel.SetFillColor(0) cmslabel.SetTextSize(0.041) cmslabel.Draw("plain") label = TPaveText(0.8891129, 0.8644068, 0.9435484, 0.9258475, "brNDC") label.SetFillColor(0) label.SetTextSize(0.0529661) label.AddText(label_text) label.Draw("plain") if isExclusive: c.Print("ST_Residuals_Mul%d.pdf" % N) c.Print("ST_Residuals_Mul%d.png" % N) else: c.Print("ST_Mul%dup.pdf" % N) c.Print("ST_Mul%dup.png" % N) c.Update() raw_input("Press Enter to continue...")
from ROOT import gROOT c1 = TCanvas('c1', 'ROOT FilDir description', 700, 900) c1.Range(1, 1, 19, 24.5) title = TPaveLabel(4, 23, 16, 24.2, 'ROOT File/Directory/Key description') title.SetFillColor(16) title.Draw() keycolor = 42 dircolor = 21 objcolor = 46 file = TPaveText(2, 19, 6, 22) file.SetFillColor(39) file.Draw() file.SetTextSize(0.04) file.AddText('TFile') file.AddText('Header') arrow = TArrow(6, 20.5, 17, 20.5, 0.02, '|>') arrow.SetFillStyle(1001) arrow.SetLineWidth(2) arrow.Draw() free = TPaveText(8, 20, 11, 21) free.SetFillColor(18) free.Draw() free.AddText('First:Last') free2 = TPaveText(12, 20, 15, 21) free2.SetFillColor(18) free2.Draw() free2.AddText('First:Last') tfree = TText(6.2, 21.2, 'fFree = TList of free blocks')
def main(): from optparse import OptionParser parser = OptionParser() parser.add_option("-i", "--inputfile", dest="inputfile") parser.add_option("-N", "--multiplicity", dest="N", type="int", default=3) parser.add_option("-x", "--exclusive", action="store_true",\ dest="isExclusive", default=False) parser.add_option("-l", "--label", dest="label", type="string", default="") (options, args) = parser.parse_args() N = options.N isExclusive = options.isExclusive label_text = options.label if isExclusive and not (N == 2 or N == 3): parser.error("Exclusive plot only for N =2 or 3") import configurations as config from ROOT import TFile, TCanvas, THStack, TLegend, TPaveText, gStyle from ModelParser import ModelKey gStyle.SetPadTopMargin(0.05) gStyle.SetPadRightMargin(0.05) suffix = "" if not isExclusive: suffix = "up" sm_files = [] for model in config.sm_models: f = TFile("%s/%s.root" % (config.sm_dir, model), "READ") sm_files.append(f) bh_weights = [] bh_files = [] from BHXsec import BHXsec xsec = BHXsec() for model in config.bh_showcase: f = TFile("%s/%s.root" % (config.bh_dir, model), "READ") bh_files.append(f) h = f.Get("plotsNoCut/ST") nEvents = h.GetEntries() bh_weights.append( xsec.get(model) / nEvents * config.integrated_luminosity) c = TCanvas("ST_Mul%d%s" % (N, suffix), "ST_Mul%d%s" % (N, suffix), 500, 500) hs = THStack() infile = TFile(options.inputfile, "READ") hBkg = infile.Get("Background_N%d%s" % (N, suffix)) gBkg = infile.Get("BackgroundGraph_N%d%s" % (N, suffix)) hData = infile.Get("Data_N%d%s" % (N, suffix)) hBkg = infile.Get("Background_N%d%s" % (N, suffix)) hBkg.SetMarkerSize(0) hBkg_ = hBkg.Clone("BkgLine") hBkg.SetFillColor(33) hBkg.SetLineColor(33) hBkg_.SetLineWidth(3) hBkg_.SetLineColor(862) hs.Add(hBkg, "e3") legend = TLegend(0.3326613, 0.6419492, 0.9294355, 0.9216102) legend.SetTextSize(0.02966102) legend.SetTextFont(42) legend.SetFillColor(0) legend.SetLineColor(0) if isExclusive: legend.SetHeader("N = %d" % N) else: legend.SetHeader("N #geq %d" % N) legend.AddEntry(hData, "Data", "p") legend.AddEntry(hBkg_, "Background", "l") legend.AddEntry(hBkg, "Uncertainty", "f") legend_sm = TLegend(0.6471774, 0.7669492, 0.8508065, 0.8771186) legend_sm.SetTextSize(0.02966102) legend_sm.SetTextFont(42) legend_sm.SetFillColor(0) legend_sm.SetLineColor(0) for i, f in enumerate(bh_files): h = f.Get("plotsN%d%s/ST" % (N, suffix)) h.Rebin(config.rebin) h.Scale(bh_weights[i]) # Add background for ibin in range(h.GetNbinsX()): h.SetBinContent(ibin+1,\ h.GetBinContent(ibin+1)\ + hBkg.GetBinContent(ibin+1)) h.SetLineWidth(2) h.SetLineStyle(i + 2) hs.Add(h, "hist") model = ModelKey(config.bh_showcase[i]) bh_legend = "M_{D} = %.1f TeV, M_{BH}^{ min} = %.1f TeV, n = %d" % (\ model.parameter["MD"], model.parameter["M"], model.parameter["n"]) legend.AddEntry(h, bh_legend, "l") # if isExclusive: for i, f in enumerate(sm_files): h = f.Get("plotsN%d%s/ST" % (N, suffix)) h.Rebin(config.rebin) h.Scale(config.integrated_luminosity) h.SetFillColor(config.sm_colors[i]) h.SetLineColor(config.sm_colors[i]) hs.Add(h, "hist") legend_sm.AddEntry(h, config.sm_models[i], "f") #hs.Add(hData, "e") hs.Draw("nostack") c.SetLogy(1) hs.GetXaxis().SetTitle("S_{T} (GeV)") hs.GetYaxis().SetTitle(hData.GetYaxis().GetTitle()) hs.GetYaxis().SetTitleOffset(1.2) ibin = 0 if isExclusive: hs.GetXaxis().SetRangeUser(config.fit_range[0], config.maxST) ibin = hData.FindBin(config.fit_range[0]) else: hs.GetXaxis().SetRangeUser(config.norm_range[0], config.maxST) ibin = hData.FindBin(config.norm_range[0]) from Styles import formatUncertainty formatUncertainty(gBkg) gBkg.Draw("LX") hData.Draw("esame") hs.SetMinimum(5e-2) if isExclusive: hs.SetMaximum(hData.GetBinContent(ibin) * 20) else: #hs.SetMaximum(4e4) hs.SetMaximum(hData.GetBinContent(ibin) * 20) legend.Draw("plain") if isExclusive: legend_sm.Draw("plain") if isExclusive: cmslabel = TPaveText(0.5544355, 0.5127119, 0.8991935, 0.6292373, "brNDC") else: cmslabel = TPaveText(0.1955645, 0.1631356, 0.5403226, 0.279661, "brNDC") cmslabel.AddText(config.cmsTitle) cmslabel.AddText(config.cmsSubtitle) cmslabel.SetFillColor(0) cmslabel.Draw("plain") label = TPaveText(0.8891129, 0.8644068, 0.9435484, 0.9258475, "brNDC") label.SetFillColor(0) label.SetTextSize(0.0529661) label.AddText(label_text) label.Draw("plain") c.Update() raw_input("Press Enter to continue...")
tbig.SetTextAlign( 22 ) tbig.SetTextSize( 0.03 ) tbig.Draw() tbig.DrawText( 2.6, 7, 'fBEGIN' ) tbig.DrawText( 20., 7, 'fEND' ) arrow.DrawArrow( 2.6, 7, 2.6, 8.4, 0.01, '|>' ) arrow.DrawArrow( 20, 7, 20, 8.4, 0.01, '|>' ) #file header header = TPaveText( 0.5, .2, 9.4, 6.5 ) header.SetFillColor( 44 ) header.Draw() fh = header.AddText( 'File Header' ) fh.SetTextAlign( 22 ) fh.SetTextSize( 0.04 ) header.SetTextSize( 0.027 ) header.SetTextAlign( 12 ) header.AddText( ' ' ) header.AddLine( 0, 0, 0, 0 ) header.AddText( '"root": Root File Identifier' ) header.AddText( 'fVersion: File version identifier' ) header.AddText( 'fBEGIN: Pointer to first data record' ) header.AddText( 'fEND: Pointer to first free word at EOF' ) header.AddText( 'fSeekFree: Pointer to FREE data record' ) header.AddText( 'fNbytesFree: Number of bytes in FREE' ) header.AddText( 'fNfree: Number of free data records' ) header.AddText( 'fNbytesName: Number of bytes in name/title' ) header.AddText( 'fUnits: Number of bytes for pointers' ) header.AddText( 'fCompress: Compression level' ) #logical record header
def compareDatasets(trigger, leg, datasets, lineColors, legendLabels, axisTitle, canvas, dataLumi, metHLTFilters, outputSuffix = None): inputFiles = [TFile.Open("triggerEfficiency_" + x + ".root") for x in datasets] efficiencies = [x.Get(trigger + "_" + leg) for x in inputFiles] for iEff in range(len(efficiencies)): SetStyle(efficiencies[iEff]) efficiencies[iEff].SetLineColor(lineColors[iEff]) efficiencies[iEff].SetMarkerColor(lineColors[iEff]) oneLine = TLine(xlo, 1.0, xhi, 1.0) oneLine.SetLineWidth(3) oneLine.SetLineStyle(2) backgroundHist = TH1D("backgroundHist", "backgroundHist", 1, xlo, xhi) backgroundHist.GetYaxis().SetTitle("Trigger Efficiency") backgroundHist.GetYaxis().SetRangeUser(ylo, yhi) backgroundHist.GetXaxis().SetTitle(axisTitle) SetStyle(backgroundHist) canvas.cd() backgroundHist.Draw() for eff in efficiencies: eff.Draw("CP same") #oneLine.Draw("same") pt_cmsPrelim = TPaveText(0.132832, 0.859453, 0.486216, 0.906716, "brNDC") pt_cmsPrelim.SetBorderSize(0) pt_cmsPrelim.SetFillStyle(0) pt_cmsPrelim.SetTextFont(62) pt_cmsPrelim.SetTextSize(0.0374065) if dataLumi > 0: pt_cmsPrelim.AddText("CMS Preliminary") else: pt_cmsPrelim.AddText("CMS Simulation") pt_cmsPrelim.Draw("same") if dataLumi > 0: pt_lumi = TPaveText(0.744361, 0.92928, 0.860902, 0.977667, "brNDC") pt_lumi.SetBorderSize(0) pt_lumi.SetFillStyle(0) pt_lumi.SetTextFont(42) pt_lumi.SetTextSize(0.0374065) pt_lumi.AddText("{:.2f}".format(dataLumi / 1000.0) + " fb^{-1}, 13 TeV") pt_lumi.Draw("same") pt_leg = TPaveText(0.160401, 0.768657, 0.342105, 0.863184, "brNDC") pt_leg.SetBorderSize(0) pt_leg.SetFillStyle(0) pt_leg.SetTextFont(42) pt_leg.SetTextSize(0.025) pt_leg.SetTextAlign(12) if leg == "METLeg": legLabel = "" for filt in metHLTFilters[:-1]: legLabel = legLabel + filt + ", " legLabel = legLabel + metHLTFilters[-1] pt_leg.AddText(legLabel) if leg == "TrackLeg": pt_leg.AddText(trigger + "*") legLabel = "" for filt in metHLTFilters[:-1]: legLabel = legLabel + filt + ", " legLabel = legLabel + metHLTFilters[-1] + " applied" pt_leg.AddText(legLabel) if leg == "METPath": if trigger == "GrandOr": pt_leg.AddText("OR of Signal Paths") else: if len(trigger) > 25 and len(trigger.split("_")) > 2: firstLine = trigger.split("_")[0] + "_" + trigger.split("_")[1] + "_" pt_leg.AddText(firstLine) secondLine = "" for line in trigger.split("_")[2:-1]: secondLine += line + "_" secondLine += trigger.split("_")[-1] + "*" pt_leg.AddText(secondLine) else: pt_leg.AddText(trigger + "*") pt_leg.Draw("same") legendLabel = trigger legend = TLegend(0.65, 0.75, 0.93, 0.88) legend.SetBorderSize(0) legend.SetFillColor(0) legend.SetFillStyle(0) legend.SetTextFont(42) if leg == 'METLeg': legend.SetHeader('MET Leg') elif leg == 'TrackLeg': legend.SetHeader('Track Leg') for iEff in range(len(efficiencies)): legend.AddEntry(efficiencies[iEff], legendLabels[iEff], 'P') legend.Draw("same") if outputSuffix is not None: canvas.SaveAs('compareDatasets_' + trigger + '_' + leg + '_' + outputSuffix + '.pdf') else: canvas.SaveAs('compareDatasets_' + trigger + '_' + leg + '_.pdf') for inputFile in inputFiles: inputFile.Close() return
ratioHistogram = currentHistogram.Clone() ratioHistogram.Divide(baselineHistogram) ratios.append(ratioHistogram) for histogram in histograms: legend.AddEntry(histogram, histogram.GetName(), "LEFP") histogram.Draw("E0 same") baselineHistogram.Draw("E0 same") pt1 = TPaveText(0.1174497, 0.8621291, 0.5469799, 0.9075044, "brNDC") pt1.SetBorderSize(0) pt1.SetFillStyle(0) pt1.SetTextFont(62) pt1.SetTextSize(0.0374065) pt1.SetTextAlign(32) pt1.AddText("CMS Phase II Simulation") pt1.Draw("same") pt2 = TPaveText(0.639087, 0.8572587, 0.9286733, 0.9042985, "brNDC") pt2.SetBorderSize(0) pt2.SetFillStyle(0) pt2.SetTextFont(42) pt2.SetTextSize(0.0374065) pt2.SetTextAlign(32) pt2.AddText("14 TeV, PU = 140") pt2.Draw("same") pt3 = TPaveText(0.5035663, 0.7875101, 0.9400856, 0.8572587, "brNDC")
def compare(trigger, leg, data, mc, axisTitle, canvas, dataLumi, metHLTFilters): dataFile = TFile.Open("triggerEfficiency_" + data + ".root", "read") mcFile = TFile.Open("triggerEfficiency_" + mc + ".root", "read") dataEff = dataFile.Get(trigger + "_" + leg) mcEff = mcFile.Get(trigger + "_" + leg) SetStyle(dataEff) SetStyle(mcEff) mcEff.SetLineColor(600) mcEff.SetMarkerColor(600) oneLine = TLine(xlo, 1.0, xhi, 1.0) oneLine.SetLineWidth(3) oneLine.SetLineStyle(2) backgroundHist = TH1D("backgroundHist", "backgroundHist", 1, xlo, xhi) backgroundHist.GetYaxis().SetTitle("Trigger Efficiency") backgroundHist.GetYaxis().SetRangeUser(ylo, yhi) backgroundHist.GetXaxis().SetTitle(axisTitle) SetStyle(backgroundHist) canvas.cd() backgroundHist.Draw() dataEff.Draw("CP same") mcEff.Draw("CP same") #oneLine.Draw("same") pt_cmsPrelim = TPaveText(0.132832, 0.859453, 0.486216, 0.906716, "brNDC") pt_cmsPrelim.SetBorderSize(0) pt_cmsPrelim.SetFillStyle(0) pt_cmsPrelim.SetTextFont(62) pt_cmsPrelim.SetTextSize(0.0374065) pt_cmsPrelim.AddText("CMS Preliminary") pt_cmsPrelim.Draw("same") pt_lumi = TPaveText(0.744361, 0.92928, 0.860902, 0.977667, "brNDC") pt_lumi.SetBorderSize(0) pt_lumi.SetFillStyle(0) pt_lumi.SetTextFont(42) pt_lumi.SetTextSize(0.0374065) pt_lumi.AddText("{:.2f}".format(dataLumi / 1000.0) + " fb^{-1}, 13 TeV") pt_lumi.Draw("same") pt_leg = TPaveText(0.160401, 0.768657, 0.342105, 0.863184, "brNDC") pt_leg.SetBorderSize(0) pt_leg.SetFillStyle(0) pt_leg.SetTextFont(42) pt_leg.SetTextSize(0.025) pt_leg.SetTextAlign(12) if leg == "METLeg": legLabel = "" for filt in metHLTFilters[:-1]: legLabel = legLabel + filt + ", " legLabel = legLabel + metHLTFilters[-1] pt_leg.AddText(legLabel) if leg == "TrackLeg": pt_leg.AddText(trigger + "*") legLabel = "" for filt in metHLTFilters[:-1]: legLabel = legLabel + filt + ", " legLabel = legLabel + metHLTFilters[-1] + " applied" pt_leg.AddText(legLabel) if leg == "METPath": if trigger == "GrandOr": pt_leg.AddText("OR of Signal Paths") else: if len(trigger) > 25 and len(trigger.split("_")) > 2: firstLine = trigger.split("_")[0] + "_" + trigger.split("_")[1] + "_" pt_leg.AddText(firstLine) secondLine = "" for line in trigger.split("_")[2:-1]: secondLine += line + "_" secondLine += trigger.split("_")[-1] + "*" pt_leg.AddText(secondLine) else: pt_leg.AddText(trigger + "*") pt_leg.Draw("same") dataLabel = '2015 data' if '2016BC' in data: dataLabel = '2016 B+C data' if '2016DEFGH' in data: dataLabel = '2016 D-H data' if '2017' in data: dataLabel = '2017 data' if '2018' in data: dataLabel = '2018 data' legendLabel = trigger legend = TLegend(0.65, 0.75, 0.93, 0.88) legend.SetBorderSize(0) legend.SetFillColor(0) legend.SetFillStyle(0) legend.SetTextFont(42) if leg == 'METLeg': legend.SetHeader('MET Leg') elif leg == 'TrackLeg': legend.SetHeader('Track Leg') legend.AddEntry(dataEff, dataLabel, 'P') legend.AddEntry(mcEff, 'W #rightarrow l#nu MC', 'P') legend.Draw("same") outputDirectory = 'plots_compare' if 'BC' in data: outputDirectory = 'plots_compareBC' if 'DEFGH' in data: outputDirectory = 'plots_compareDEFGH' if not os.path.exists(outputDirectory): os.mkdir(outputDirectory) canvas.SaveAs(outputDirectory + '/' + trigger + '_' + leg + '.pdf') mcFile.Close() dataFile.Close() return
h.Fill(200., 10., 1.72) h.Fill(200., 15., 1.77) h.Fill(200., 20., 1.63) h.Fill(200., 30., 1.71) h.Fill(200., 40., 1.82) # Style gStyle.SetOptStat(0) gStyle.SetPaintTextFormat('.2f') h.GetXaxis().SetTitle('N2') h.GetYaxis().SetTitle('dM') set_palette() # Pave Text t1 = TPaveText(.1, .906, .2, 1., 'NDC') t1.SetTextSize(.039) t1.SetFillColor(0) t1.SetFillStyle(0) t1.SetLineWidth(0) t1.SetTextAlign(12) t1.AddText('CMS') t2 = TPaveText(.13, .9, .9, 1., 'NDC') t2.SetTextSize(.033) t2.SetFillColor(0) t2.SetFillStyle(0) t2.SetLineWidth(0) t2.SetTextAlign(12) t2.SetTextFont(42) t2.AddText('Phase-2 Simulation Preliminary (N2C1+N2N1)/N2C1 Events in SR') # Plot
def plotEfficiency(self, doFit = False): if hasattr(self, "Denominator") and hasattr(self, "Numerator"): if self._rebinFactor != 1: self.Denominator["hist"].Rebin(self._rebinFactor) self.Numerator["hist"].Rebin(self._rebinFactor) for ibin in range(-1, self.Numerator["hist"].GetNbinsX()+1): if self.Numerator["hist"].GetBinContent(ibin+1) > self.Denominator["hist"].GetBinContent(ibin+1): print('Fixing bad bin:', (ibin+1)) self.Numerator["hist"].SetBinContent(ibin+1, self.Denominator["hist"].GetBinContent(ibin+1)) self.Numerator["hist"].SetBinError(ibin+1, self.Denominator["hist"].GetBinError(ibin+1)) efficiencyGraph = TGraphAsymmErrors(self.Numerator["hist"], self.Denominator["hist"], "cp") pt_cmsPrelim = TPaveText(0.132832, 0.859453, 0.486216, 0.906716, "brNDC") pt_cmsPrelim.SetBorderSize(0) pt_cmsPrelim.SetFillStyle(0) pt_cmsPrelim.SetTextFont(62) pt_cmsPrelim.SetTextSize(0.0374065) pt_cmsPrelim.AddText("CMS Preliminary") pt_lumi = TPaveText(0.744361, 0.92928, 0.860902, 0.977667, "brNDC") pt_lumi.SetBorderSize(0) pt_lumi.SetFillStyle(0) pt_lumi.SetTextFont(42) pt_lumi.SetTextSize(0.0374065) pt_lumi.AddText(self._luminosityLabel) pt_leg = TPaveText(0.160401, 0.768657, 0.342105, 0.863184, "brNDC") pt_leg.SetBorderSize(0) pt_leg.SetFillStyle(0) pt_leg.SetTextFont(42) pt_leg.SetTextSize(0.0349127) pt_leg.SetTextAlign(12) if self._leg == "METLeg": legLabel = "" for filt in self._metHLTFilters[:-1]: legLabel = legLabel + filt + ", " legLabel = legLabel + self._metHLTFilters[-1] pt_leg.AddText(legLabel) pt_leg.AddText(self._datasetLabel) if self._leg == "TrackLeg": pt_leg.AddText(self._path + "*") pt_leg.AddText(self._datasetLabel) legLabel = "" for filt in self._metHLTFilters[:-1]: legLabel = legLabel + filt + ", " legLabel = legLabel + self._metHLTFilters[-1] + " applied" pt_leg.AddText(legLabel) if self._leg == "METPath": if self._path == "GrandOr": pt_leg.AddText("OR of Signal Paths") else: pt_leg.AddText(self._path + "*") pt_leg.AddText(self._datasetLabel) lumiLabel = TPaveText(0.66416, 0.937339, 0.962406, 0.992894, "brNDC") lumiLabel.SetBorderSize(0) lumiLabel.SetFillStyle(0) lumiLabel.SetTextFont(42) lumiLabel.SetTextSize(0.0387597) lumiLabel.AddText(str (self._luminosityLabel)) oneLine = TLine(xlo, 1.0, xhi, 1.0) oneLine.SetLineWidth(3) oneLine.SetLineStyle(2) backgroundHist = TH1D("backgroundHist", "backgroundHist", 1, xlo, xhi) backgroundHist.GetYaxis().SetTitle("Trigger Efficiency") backgroundHist.GetYaxis().SetRangeUser(ylo, yhi) if self._leg == "METLeg" or self._leg == "METPath": backgroundHist.GetXaxis().SetTitle(self._metLegAxisTitle) elif self._leg == "TrackLeg": backgroundHist.GetXaxis().SetTitle(self._trackLegAxisTitle) SetStyle(backgroundHist) SetStyle(efficiencyGraph) self._canvas.cd() backgroundHist.Draw() efficiencyGraph.Draw("P") pt_cmsPrelim.Draw("same") pt_lumi.Draw("same") pt_leg.Draw("same") oneLine.Draw("same") if doFit: (fitFunc, fitText) = self.PlotFit(efficiencyGraph) fitFunc.Draw("same") fitText.Draw("same") if not os.path.exists('plots_' + self.Denominator["sample"]): os.mkdir('plots_' + self.Denominator["sample"]) if self._leg == "METPath": self._canvas.SaveAs('plots_' + self.Denominator["sample"] + '/' + self._path + "_Efficiency.pdf") else: self._canvas.SaveAs('plots_' + self.Denominator["sample"] + '/' + self._path + "_" + self._leg + ".pdf") self._fout.cd() if self._tgraphSuffix is not None: efficiencyGraph.Write(self._path + "_" + self._leg + "_" + self._tgraphSuffix) if doFit: fitFunc.Write(self._path + "_" + self._leg + "_" + self._tgraphSuffix + "_fitResult") else: efficiencyGraph.Write(self._path + "_" + self._leg) if doFit: fitFunc.Write(self._path + "_" + self._leg + "_fitResult") else: print("Denominator and Numerator must be defined for path ", self._path, ", leg ", self._leg) return 0.0
def Measure_Integral(AllRuns, Title, RootName, WID): FNumber = len(AllRuns) xIntegral = array("d", xrange(0, FNumber)) yIntegral = array("d", xrange(0, FNumber)) yIntegralErrUp = array("d", xrange(0, FNumber)) yIntegralErrDown = array("d", xrange(0, FNumber)) xIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMSErrUp = array("d", xrange(0, FNumber)) yIntegral_RMSErrDown = array("d", xrange(0, FNumber)) xRatio = array("d", xrange(0, FNumber)) yRatio = array("d", xrange(0, FNumber)) xSingleEv = array("d", xrange(0, 40)) ySingleEv = array("d", xrange(0, 40)) OutFile = TFile(RootName, "RECREATE") num = -1 iAmp = 0 for Fname in AllRuns: num += 1 iAmp += 1 f = open(Fname) # data = getData(f) tdc = getTDCValues(f) M = TH1F(Fname, Fname, 200, 0, 100) x = array("d", xrange(0, 1001)) y = array("d", xrange(0, 1001)) for event in xrange(0, 995): pedSum = 0 sigSum = 0 Signal = 0 Pedestal = 0 for BX in xrange(0, 40): # print "[event][link][BX][linkChannel] = ", event," " ,link," " , BX ," " ,linkChannel, "---->data[event][link][BX][linkChannel]", tdc[event][link][BX][linkChannel] # print BX # print event # print "data=", data[event][link][BX][linkChannel] # print "TDC=", tdc[event][link][BX][linkChannel] # print "\n" # print "@@@@@@@@-------> [event] ", event tdcValue = tdc[event][link][BX][linkChannel] # print "@@@@@@@@-------> [event] ", event if (WID[num] < 10 and BX == 20 and tdc[event][link][BX][linkChannel] != 31.5): sigSum += tdcValue if (WID[num] > 10 and BX == 21 and tdc[event][link][BX][linkChannel] != 31.5): sigSum += tdcValue # print "[event][link][BX][linkChannel] = ", event," " ,link," " , BX ," " ,linkChannel, "---->data[event][link][BX][linkChannel]", tdc[event][link][BX][linkChannel] # if BX > 19 and BX < 25: sigSum += adcValue # if BX > 18 and BX < 26: print "[event][link][BX][linkChannel] = ", event," " ,link," " , BX ," " ,linkChannel, "---->data[event][link][BX][linkChannel]", data[event][link][BX][linkChannel] # print "---------------------> sigSum= ",sigSum y[event] = sigSum M.Fill(y[event]) histMean = M.GetMean() histRMS = M.GetStdDev() highVal = histMean + 4 * histRMS lowVal = histMean - 4 * histRMS highValAx = histMean + 6 * histRMS lowValAx = histMean - 6 * histRMS canvas = MakeCanvas("asdf", "asdf", 800, 800) canvas.Update() MyGr = TGraph(len(x), x, y) mfit = TF1("fit", "gaus", lowVal, highVal) M.Fit(mfit, "R0", "") FitParam = mfit.GetParameters() # FitParErr=mfit.GetParError() integral = histMean if FitParam[1] < 1.5 * histMean: integral = round(FitParam[1], 4) integral_RMS = histRMS if round(FitParam[2], 4) < 2 * histRMS: integral_RMS = round(FitParam[2], 4) integralErr = round(mfit.GetParError(1), 4) integral_RMSErr = round(mfit.GetParError(2), 4) print "iAmp=", iAmp, " integral= ", integral, " integral_RMS=", integral_RMS M.SetMarkerStyle(22) M.GetXaxis().SetRangeUser(lowValAx, highValAx) # M.GetXaxis().SetRangeUser(lowValAx,highValAx) M.SetTitle(Title + " = " + str(iAmp)) M.Draw("pe") mfit.Draw("same") fitInfo = TPaveText(.20, 0.7, .60, 0.9, "NDC") fitInfo.SetBorderSize(0) fitInfo.SetFillStyle(0) fitInfo.SetTextAlign(12) fitInfo.SetTextSize(0.03) fitInfo.SetTextColor(1) fitInfo.SetTextFont(62) fitInfo.AddText("Mean of Fit=" + str(round(FitParam[1], 1))) fitInfo.AddText("RMS of Fit =" + str(round(FitParam[2], 1))) fitInfo.Draw() canvas.SaveAs("HistoSingleRun_" + str(iAmp) + "_" + Title + "_TDC.pdf") XVAL = iAmp xIntegral[num] = XVAL yIntegral[num] = integral yIntegralErrUp[num] = integral + integralErr yIntegralErrDown[num] = integral - integralErr xIntegral_RMS[num] = XVAL yIntegral_RMS[num] = integral_RMS yIntegral_RMSErrUp[num] = integral_RMS + integral_RMSErr yIntegral_RMSErrDown[num] = integral_RMS - integral_RMSErr print "iAmp, integral= ", iAmp, " ", integral, " XVAL= ", XVAL xRatio[num] = XVAL yRatio[num] = integral_RMS / integral # xIntegral.append(iAmp) # yIntegral.append(integral) # xIntegral_RMS.append(iAmp) # yIntegral_RMS.append(integral_RMS) Graph_Integral = TGraph(len(xIntegral), xIntegral, yIntegral) Graph_IntegralErUp = TGraph(len(xIntegral), xIntegral, yIntegralErrUp) Graph_IntegralErDown = TGraph(len(xIntegral), xIntegral, yIntegralErrDown) canvas_Integral = MakeCanvas("can1", "can1", 800, 800) # canvas_Integral.SetLogy() Graph_Integral.SetTitle("TDC Stability") Graph_Integral.SetMarkerStyle(22) Graph_Integral.SetMarkerColor(3) Graph_Integral.SetMarkerSize(2) Graph_Integral.GetXaxis().SetTitle("Day") Graph_Integral.GetYaxis().SetRangeUser(0, 40) print "%%%%%%%% Graph_Integral.GetMaximum()= ", TMath.MaxElement( len(xIntegral_RMS), Graph_Integral.GetY()) # Graph_Integral.SetMaximum(1.5) Graph_Integral.Draw() # Graph_IntegralErUp.Draw("same") # Graph_IntegralErDown.Draw("same") canvas_Integral.SaveAs("Integral_" + Title + "_TDC.pdf") Graph_Integral_RMS = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMS) Graph_Integral_RMSErUp = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMSErrUp) Graph_Integral_RMSErDown = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMSErrDown) canvas_Integral_RMS = MakeCanvas("can2", "can2", 800, 800) Graph_Integral_RMS.SetTitle("TDC RMS vs. Pulse " + Title) Graph_Integral_RMS.SetMarkerStyle(23) Graph_Integral_RMS.SetMarkerColor(2) Graph_Integral_RMS.SetMarkerSize(2) Graph_Integral_RMS.GetXaxis().SetTitle("Day") Graph_Integral_RMS.GetYaxis().SetRangeUser( TMath.MinElement(len(xIntegral_RMS), Graph_Integral_RMS.GetY()) / 2, TMath.MaxElement(len(xIntegral_RMS), Graph_Integral_RMS.GetY()) * 1.5) Graph_Integral_RMS.Draw() # Graph_Integral_RMSErUp.Draw("same") # Graph_Integral_RMSErDown.Draw("same") canvas_Integral_RMS.SaveAs("Integral_RMS_" + Title + "_TDC.pdf") Graph_Ratio = TGraph(len(xRatio), xRatio, yRatio) canvas_Ratio = MakeCanvas("can2", "can2", 800, 800) Graph_Ratio.SetTitle("Ratio of TDC RMS and TDC " + Title) Graph_Ratio.SetMarkerStyle(21) Graph_Ratio.SetMarkerColor(4) Graph_Ratio.SetMarkerSize(2) Graph_Ratio.GetXaxis().SetTitle("Day") Graph_Ratio.GetYaxis().SetRangeUser( TMath.MinElement(len(xIntegral_RMS), Graph_Ratio.GetY()) / 2, TMath.MaxElement(len(xIntegral_RMS), Graph_Ratio.GetY()) * 1.5) Graph_Ratio.Draw() canvas_Ratio.SaveAs("Ratio_" + Title + "_TDC.pdf") OutFile = TFile(RootName, "RECREATE") OutFile.WriteObject(Graph_Integral, "Graph_Integral") OutFile.WriteObject(Graph_Integral_RMS, "Graph_Integral_RMS") OutFile.WriteObject(Graph_Ratio, "Graph_Ratio") OutFile.Close()
def makePlots(): # gROOT.SetStyle('Plain') # white background # gStyle.SetOptStat(222211) ROOT.gROOT.ProcessLine('.L ../tdrstyle.C') ROOT.gROOT.Reset() ROOT.gROOT.ProcessLine('setTDRStyle()') #Set CMS TDR style inputFile = TFile(output_name + '.root', 'READ') histos_SR1 = dict() histos_SR2 = dict() histos_LSB = dict() histos_RSB = dict() histos_MC = dict() keys = [ 'photon_pt', 'photon_eta', 'dimuon_pt', 'dimuon_rapidity', 'chib_pt' ] for key in keys: histos_SR1[key] = inputFile.Get(key + '_SR1') histos_SR2[key] = inputFile.Get(key + '_SR2') histos_LSB[key] = inputFile.Get(key + '_LSB') histos_RSB[key] = inputFile.Get(key + '_RSB') histos_MC[key] = inputFile.Get(key + '_MC') titles = dict( photon_pt='photon E_{T};E_{T}(#gamma) [GeV];Entries / 100 MeV', photon_eta='photon_eta;#eta(#gamma);Entries / 0.05', dimuon_pt='#Upsilon p_{T};p_{T}(#Upsilon) [GeV];Entries / GeV', dimuon_rapidity='#Upsilon rapidity(#Upsilon);y(#Upsilon);Entries / 0.1', chib_pt='#chi_{b} p_{T};p_{T}(#chi_{b}) [GeV];Entries / GeV', ) titles_chib = dict( photon_pt='photon E_{T};E_{T}(#gamma) [GeV];A.U.', photon_eta='photon_eta;#eta(#gamma);A.U.', dimuon_pt='#Upsilon p_{T};p_{T}(#Upsilon) [GeV];A.U.', dimuon_rapidity='#Upsilon rapidity(#Upsilon);y(#Upsilon);A.U.', chib_pt='#chi_{b} p_{T};p_{T}(#chi_{b}) [GeV];A.U.', ) logY = dict( photon_pt=0, photon_eta=0, dimuon_pt=0, dimuon_rapidity=0, chib_pt=0, ) maxY = dict( photon_pt=750, photon_eta=350, dimuon_pt=800, dimuon_rapidity=400, chib_pt=800, ) integralData1 = histos_SR1[keys[0]].Integral() integralData2 = histos_SR2[keys[0]].Integral() integralData = integralData1 + integralData2 for histo in histos_LSB.values() + histos_RSB.values() + histos_MC.values( ): if (histo.Integral() != 0): histo.Scale(1. / histo.Integral()) histo.Rebin(3) for histo in histos_SR1.values() + histos_SR2.values(): histo.Rebin(3) fBG = 0.48 #0.28 fLSB = 0.5 histos_BG = dict() for key in keys: histos_BG[key] = histos_RSB[key].Clone() histos_BG[key].SetNameTitle(key + '_BG', 'bgd from side-bands') histos_BG[key].Scale(1 - fLSB) histos_BG[key].Add(histos_LSB[key], fLSB) histos_Signal1 = dict() histos_Signal2 = dict() histos_Signal = dict() histos_SR = dict() for key in keys: histos_Signal1[key] = histos_SR1[key].Clone() histos_Signal1[key].SetNameTitle(key + '_signal1', 'Signal1') histos_Signal1[key].Add(histos_BG[key], -1 * integralData1 * fBG) histos_Signal2[key] = histos_SR2[key].Clone() histos_Signal2[key].SetNameTitle(key + '_signal2', 'Signal2') histos_Signal2[key].Add(histos_BG[key], -1 * integralData2 * fBG) histos_Signal[key] = histos_Signal1[key].Clone() histos_Signal[key].Add(histos_Signal2[key]) histos_Signal[key].SetNameTitle(key + '_signal', 'data bkg-subtracted') histos_SR[key] = histos_SR1[key].Clone() histos_SR[key].Add(histos_SR2[key]) histos_SR[key].SetNameTitle(key + '_SR', 'data') for histo in histos_Signal.values() + histos_BG.values(): if (histo.Integral() != 0): histo.Scale(1. / histo.Integral()) # Normalize SR to their original value, MC to be comparable with signal background-subtracted and background such that Signal+background = SR for histo in histos_MC.values(): histo.Scale(integralData * (1 - fBG)) for histo in histos_BG.values(): histo.Scale(integralData * fBG) for histo in histos_LSB.values(): histo.Scale(integralData * fBG * fLSB) for histo in histos_RSB.values(): histo.Scale(integralData * fBG * (1 - fLSB)) chi2Prob = dict() kolmogorovProb = dict() h_ratio = dict() for key in histos_Signal.keys(): h_ratio[key] = histos_SR[key].Clone() histo_sum_MC_BG = histos_MC[key].Clone() histo_sum_MC_BG.Add(histos_BG[key]) h_ratio[key].Divide(histo_sum_MC_BG) h_ratio[key].SetNameTitle(key + '_ratio', titles[key]) h_ratio[key].SetMarkerStyle(20) h_ratio[key].SetMarkerSize(1) h_ratio[key].GetYaxis().SetLabelSize(0.18) h_ratio[key].GetYaxis().SetTitle('DATA/MC') h_ratio[key].GetYaxis().SetTitleSize(0.22) h_ratio[key].GetYaxis().SetTitleOffset(0.2) h_ratio[key].GetYaxis().SetNdivisions(005) h_ratio[key].GetXaxis().SetLabelSize(0.16) h_ratio[key].GetXaxis().SetTitleSize(0.16) h_ratio[key].SetMaximum(1.5) h_ratio[key].SetMinimum(0.667) chi2Prob[key] = histos_SR[key].Chi2Test( histo_sum_MC_BG) #, 'UW')#, 'NORM') kolmogorovProb[key] = histos_SR[key].KolmogorovTest(histo_sum_MC_BG) for histo in histos_SR.values(): histo.SetLineColor(ROOT.kBlack) histo.SetLineWidth(2) histo.SetMarkerColor(ROOT.kBlack) histo.SetMarkerStyle(20) for histo in histos_SR1.values() + histos_Signal1.values(): histo.SetLineColor(ROOT.kBlue) histo.SetLineWidth(2) histo.SetMarkerColor(ROOT.kBlue) histo.SetMarkerStyle(22) for histo in histos_SR2.values() + histos_Signal2.values(): histo.SetLineColor(ROOT.kRed) histo.SetLineWidth(2) histo.SetMarkerColor(ROOT.kRed) histo.SetMarkerStyle(23) for histo in histos_Signal.values(): histo.SetLineColor(ROOT.kBlack) histo.SetLineWidth(2) # histo.SetMarkerColor(ROOT.kBlack) # histo.SetMarkerStyle(21) for histo in histos_BG.values(): histo.SetLineColor(ROOT.kRed) histo.SetLineWidth(2) histo.SetFillColor(ROOT.kRed) # histo.SetMarkerColor(ROOT.kRed) # histo.SetMarkerStyle(22) # for histo in histos_RSB.values(): # histo.SetLineColor(ROOT.kViolet) # histo.SetLineWidth(2) for histo in histos_MC.values(): histo.SetLineColor(ROOT.kBlue) histo.SetLineWidth(2) histo.SetFillColor(ROOT.kBlue) # histo.SetMarkerColor(ROOT.kBlue) # histo.SetMarkerStyle(20) outputFile = TFile(output_name + '_plots.root', 'RECREATE') for histo in histos_Signal.values() + histos_MC.values( ) + histos_BG.values() + histos_SR.values(): histo.Write() outputFile.Close() canvas = TCanvas("canvas", "canvas") canvas.Print(outputFile_name + "[") #apre file .ps for key in keys: pad1 = TPad("pad1", "The pad 80% of the height", 0.0, 0.2, 1.0, 1.0) pad1.cd() pad1.SetLogy(logY[key]) hs = THStack('hs', titles[key]) #hs.Add(histos_SR[key]) #hs.Add(histos_Signal[key]) hs.Add(histos_BG[key]) hs.Add(histos_MC[key]) #hs.Add(histos_LSB[key]) #hs.Add(histos_RSB[key]) #maxHisto = max(hs.GetMaximum(), histos_SR[key].GetMaximum()) hs.SetMaximum(maxY[key]) #maxHisto) hs.Draw('HIST') histos_SR[key].Draw('same') leg = pad1.BuildLegend(.65, .93, .95, .7) leg.SetFillStyle(0) leg.SetBorderSize(0) leg.Draw("SAME") pad2 = TPad("pad2", "The pad 20% of the height", 0.0, 0.01, 1.0, 0.2) pad2.cd() h_ratio[key].Draw() xmin = h_ratio[key].GetBinLowEdge(1) xmax = h_ratio[key].GetBinLowEdge( h_ratio[key].GetNbinsX()) + h_ratio[key].GetBinWidth( h_ratio[key].GetNbinsX()) line0 = TLine(xmin, 1, xmax, 1) line0.SetLineColor(ROOT.kBlue) line0.SetLineWidth(2) line0.Draw('same') canvas.cd() pad1.Draw() pad2.Draw() canvas.Update() canvas.Print(outputFile_name) canvas.Print('plots/' + key + '_' + mc_ptSpectrum + '.png') canvas.Print('plots/' + key + '_' + mc_ptSpectrum + '.pdf') canvas.Print('plots/' + key + '_' + mc_ptSpectrum + '.root') # Make comparisison between chib1 and chib2 histos_SR1[key].Scale(1. / histos_SR1[key].Integral()) histos_SR2[key].Scale(1. / histos_SR2[key].Integral()) histos_Signal1[key].Scale(1. / histos_Signal1[key].Integral()) histos_Signal2[key].Scale(1. / histos_Signal2[key].Integral()) # histos_SR1[key].Rebin(3) # histos_SR2[key].Rebin(3) # histos_Signal1[key].Rebin(3) # histos_Signal2[key].Rebin(3) hsc = THStack('hsc', titles_chib[key]) hsc.Add(histos_Signal1[key]) hsc.Add(histos_Signal2[key]) #hsc.SetMaximum(maxY[key]) hsc.Draw('nostack') legc = canvas.BuildLegend(.65, .93, .95, .7) legc.SetFillStyle(0) legc.SetBorderSize(0) legc.Draw("SAME") print 'kolmogorov prob SR ' + key + ' ' + str( histos_SR1[key].KolmogorovTest(histos_SR2[key])) print 'kolmogorov prob Signal ' + key + ' ' + str( histos_Signal1[key].KolmogorovTest(histos_Signal2[key])) cfr = 2 if key not in ['dimuon_pt', 'chib_pt'] else 5 kolmogorovProb_chi = round( histos_Signal1[key].KolmogorovTest(histos_Signal2[key]), cfr) pvtxt = TPaveText(.2, .0, 0.5, 0.1, "NDC") pvtxt.SetFillStyle(0) pvtxt.SetBorderSize(0) pvtxt.SetTextSize(0.04) pvtxt.AddText('Kolmogorov prob = ' + str(kolmogorovProb_chi)) pvtxt.Draw() canvas.Update() canvas.Print(outputFile_name) canvas.Print('plots/' + key + '_' + mc_ptSpectrum + '_comparison' + '.png') canvas.Print('plots/' + key + '_' + mc_ptSpectrum + '_comparison' + '.pdf') canvas.Print('plots/' + key + '_' + mc_ptSpectrum + '_comparison' + '.root') canvas.Clear() canvas.Print(outputFile_name + "]") #chiude file .ps for key in keys: print '\n' print key + ' Kolmogorov probability: ' + str(chi2Prob[key]) print key + ' chiSqure probability: ' + str(kolmogorovProb[key]) #print 'Kolmogorov probability with sidebands: '+str(histos_MC['dimuon_pt'].KolmogorovTest(histos_LSB['dimuon_pt'])) # inputFile.Close()
def main(): cc.cd() cc.SetBorderMode(0) cc.SetFixedAspectRatio(1) cc.FeedbackMode(1) gStyle.SetOptStat(0) gStyle.SetGridStyle(0) gStyle.SetGridColor(18) nbinsX = 0 for ix in range(len(SECTORSPERREGION)): nbinsX += SECTORSPERREGION[ix] hh = TH2D('hh', ';Strip;Sector', STRIPSPERSECTOR, 0, STRIPSPERSECTOR, nbinsX, 0, nbinsX) setupHists([hh]) hh.Draw('COLZ') gPad.SetLogz() gPad.SetLeftMargin(0.09) gPad.SetRightMargin(0.11) tt2 = TPaveText(240, 43, 500, 45) ttime = TPaveText(100, -5.5, 412, -3) setupPaveTexts([tt2, ttime]) tt2.SetTextSize(0.03) lll = TLine() lll.SetLineColor(15) y1 = SECTORSPERREGION[0] y2 = SECTORSPERREGION[0] + SECTORSPERREGION[1] lll.DrawLine(0, y1, STRIPSPERSECTOR, y1) lll.DrawLine(0, y2, STRIPSPERSECTOR, y2) tt = TText() tt.SetTextColor(1) tt.SetTextAngle(90) tt.SetTextSize(0.04) tt.DrawText(532, 22, 'Hz') tt.SetTextSize(0.06) tt.SetTextAngle(0) tt.SetTextColor(1) tt.DrawTextNDC(0.1, 0.93, 'SVT Scalers') tt.SetTextSize(0.03) tt.DrawText(-42, 4, 'R1') tt.DrawText(-42, 16, 'R2') tt.DrawText(-42, 32, 'R3') cc.cd() for xx in [ttime, tt2]: xx.Draw() cc.cd() gPad.SetEditable(0) while True: iy = 0 for ch in SVT.chans: loadPV(ch) ch = ch.vals data = ch['PVVAL'] time2 = ch['PVTIMEVAL'] if time2 > 10: print 'More than 10 seconds since message: ' + ch['PVNAME'] for ii in range(512): data[ii] = 0 if iy < SECTORSPERREGION[0]: region = 1 sector = iy elif iy < SECTORSPERREGION[0] + SECTORSPERREGION[1]: region = 2 sector = iy - SECTORSPERREGION[0] else: region = 3 sector = iy - SECTORSPERREGION[0] - SECTORSPERREGION[1] if data == None or len(data) != STRIPSPERSECTOR: print 'Error Reading ' + ch['PVNAME'] continue for ix in range(STRIPSPERSECTOR): hh.SetBinContent(ix, iy + 1, data[ix]) iy += 1 for xx in [ttime, tt2]: xx.Clear() [r1, r2, r3] = calcRates(SVT.chans) tt2.AddText('Sums: R1 / R2 / R3 = %.2E / %.2E / %.2E Hz' % (r1, r2, r3)) ttime.AddText(makeTime()) if not gPad: sys.exit() cc.Modified() cc.Update() time.sleep(POLLPERIOD)
ldot.DrawLine(.9, .775, .99, .775) ldot.DrawLine(.9, .275, .99, .275) ldot.DrawLine(.55, .05, .55, 0) ldot.DrawLine(.9, .05, .75, 0) pname = TText(.46, .21, 'fEventOffset') pname.SetTextFont(72) pname.SetTextSize(0.018) pname.Draw() pname.DrawText(.44, .11, 'fBuffer') pname.DrawText(.42, .01, 'fZipBuffer') pname.DrawText(.26, .81, 'fLeaves = TObjArray of TLeaf') pname.DrawText(.24, .40, 'fBasketEvent') pname.DrawText(.22, .31, 'fBaskets = TObjArray of TBasket') pname.DrawText(.20, 1.0, 'fBranches = TObjArray of TBranch') ntleaf = TPaveText(0.30, .42, .62, .7) ntleaf.SetTextSize(0.014) ntleaf.SetFillColor(leafcolor) ntleaf.SetTextAlign(12) ntleaf.AddText('fLen: number of fixed elements') ntleaf.AddText('fLenType: number of bytes of data type') ntleaf.AddText('fOffset: relative to Leaf0-fAddress') ntleaf.AddText('fNbytesIO: number of bytes used for I/O') ntleaf.AddText('fIsPointer: True if pointer') ntleaf.AddText('fIsRange: True if leaf has a range') ntleaf.AddText('fIsUnsigned: True if unsigned') ntleaf.AddText('*fLeafCount: points to Leaf counter') ntleaf.AddText(' ') ntleaf.AddLine(0, 0, 0, 0) ntleaf.AddText('fName = Leaf name') ntleaf.AddText('fTitle = Leaf type (see Type codes)') ntleaf.Draw()
def main(): from optparse import OptionParser parser = OptionParser() parser.add_option("-i", "--inputfile", dest="inputfile") parser.add_option("-N", "--multiplicity", dest="N", type="int", default=3) parser.add_option("-x", "--exclusive", action="store_true",\ dest="isExclusive", default=False) parser.add_option("-l", "--label", dest="label", type="string", default="") (options, args) = parser.parse_args() N = options.N isExclusive = options.isExclusive label_text = options.label if isExclusive and not (N == 2 or N == 3): parser.error("Exclusive plot only for N =2 or 3") import configurations as config from ROOT import TFile, TCanvas, THStack, TLegend, TPaveText, gStyle from ModelParser import ModelKey gStyle.SetPadTopMargin(0.05) gStyle.SetPadRightMargin(0.05) gStyle.SetErrorX(0.) suffix = "" if not isExclusive: suffix = "up" sm_files = [] for model in config.sm_models: f = TFile("%s/%s.root" % (config.sm_dir, model), "READ") sm_files.append(f) bh_weights = [] bh_files = [] from BHXsec import BHXsec xsec = BHXsec() for model in config.bh_showcase: f = TFile("%s/%s.root" % (config.bh_dir, model), "READ") bh_files.append(f) h = f.Get("plotsNoCut/ST") nEvents= h.GetEntries() bh_weights.append(xsec.get(model) / nEvents * config.integrated_luminosity) c = TCanvas("ST_Mul%d%s" % (N, suffix), "ST_Mul%d%s" % (N, suffix), 500, 500) hs = THStack() hs1 = THStack() infile = TFile(options.inputfile, "READ") hBkg = infile.Get("Background_N%d%s" % (N, suffix)) gBkg = infile.Get("BackgroundGraph_N%d%s" % (N, suffix)) hData = infile.Get("Data_N%d%s" % (N, suffix)) hBkg = infile.Get("Background_N%d%s" % (N, suffix)) hBkg.SetMarkerSize(0) hBkg_ = hBkg.Clone("BkgLine") hBkg.SetFillColor(33) hBkg.SetLineColor(33) hBkg_.SetLineWidth(3) hBkg_.SetLineColor(862) hs.Add(hBkg, "e3") #legend = TLegend(0.2826613,0.4819492,0.6094355,0.9416102) # - only for N >= 2 and 3 legend = TLegend(0.3026613,0.5519492,0.6094355,0.9416102) # was 0.4919... legend.SetTextSize(0.041); #was 0.02966102 legend.SetTextFont(42); legend.SetFillColor(0) legend.SetLineColor(0) if isExclusive: legend.SetHeader("Multiplicity N = %d" % N) else: legend.SetHeader("Multiplicity N #geq %d" % N) legend.AddEntry(hData, "Data", "lep") legend.AddEntry(hBkg_, "Background", "l") legend.AddEntry(hBkg, "Uncertainty", "f") legend_sm = TLegend(0.6271774,0.7369492,0.8308065,0.8771186) legend_sm.SetTextSize(0.041); legend_sm.SetTextFont(42); legend_sm.SetFillColor(0) legend_sm.SetLineColor(0) for i, f in enumerate(bh_files): h = f.Get("plotsN%d%s/ST" % (N, suffix)) h.Rebin(config.rebin) h.Scale(bh_weights[i]) # Add background for ibin in range(h.GetNbinsX()): h.SetBinContent(ibin+1,\ h.GetBinContent(ibin+1)\ + hBkg.GetBinContent(ibin+1)) h.SetLineWidth(3) #h.SetLineColor(i+2) h.SetLineStyle(i+2) if i == 0: h.SetLineColor(814) if i == 1: h.SetLineStyle(5) h.SetLineColor(899) if i == 2: h.SetLineStyle(9) h.SetLineColor(4) if i == 3: h.SetLineStyle(3) h.SetLineColor(614) hs.Add(h, "hist") model = ModelKey(config.bh_showcase[i]) bh_legend = "M_{D} = %.1f TeV, M_{BH}^{ min} = %.1f TeV, n = %d" % (\ model.parameter["MD"], model.parameter["M"], model.parameter["n"]) if i == 3: bh_legend = "M_{D} = 3.0 TeV, M_{QBH}^{ min} = 4.0 TeV, n = 4" legend.AddEntry(h, bh_legend, "l") # qbh_legend = "M_{D} = 4.0 TeV, M_{QBH}^{ min} = 5.0 TeV, n = 5" # legend.AddEntry(h, qbh_legend, "l") if isExclusive: for i, f in enumerate(sm_files): h = f.Get("plotsN%d%s/ST" % (N, suffix)) h.Rebin(config.rebin) h.Scale(config.integrated_luminosity) h.SetFillColor(config.sm_colors[i]) h.SetLineColor(config.sm_colors[i]) hs1.Add(h, "hist") legend_sm.AddEntry(h, config.sm_models[i], "f") #hs.Add(hData, "e") hs.Draw("nostack") hs1.Draw("same") c.SetLogy(1) hs.GetXaxis().SetTitle("S_{T} (GeV)") hs.GetYaxis().SetTitle(hData.GetYaxis().GetTitle()) hs.GetYaxis().SetTitleOffset(1.25) hs.GetYaxis().SetTitleSize(0.04) hs.GetYaxis().SetLabelSize(0.04) hs.GetXaxis().SetTitleSize(0.04) hs.GetXaxis().SetLabelSize(0.04) ibin = 0 #if isExclusive: # hs.GetXaxis().SetRangeUser(config.fit_range[0], config.maxST) # ibin = hData.FindBin(config.fit_range[0]) #else: # hs.GetXaxis().SetRangeUser(config.norm_range[0], config.maxST) # ibin = hData.FindBin(config.norm_range[0]) if isExclusive: hs.GetXaxis().SetRangeUser(1800, config.maxST) ibin = hData.FindBin(1800) else: hs.GetXaxis().SetRangeUser(config.norm_range[0], config.maxST) ibin = hData.FindBin(config.norm_range[0]) from Styles import formatUncertainty formatUncertainty(gBkg) gBkg.Draw("LX") hData.Draw("sameex0") hs.SetMinimum(5e-1) if isExclusive: hs.SetMaximum(hData.GetBinContent(ibin) * 40) else: #hs.SetMaximum(4e4) hs.SetMaximum(hData.GetBinContent(ibin) * 20) # or 1e7 for N>=3 and use 4 models legend.Draw("plain") if isExclusive: legend_sm.Draw("plain") if isExclusive: cmslabel =TPaveText(0.45,0.96,0.60,0.99,"brNDC"); else: cmslabel = TPaveText(0.45,0.96,0.60,0.99,"brNDC") cmslabel.AddText(config.cmsTitle) #cmslabel.AddText(config.cmsSubtitle) cmslabel.SetFillColor(0) cmslabel.SetTextSize(0.041) cmslabel.Draw("plain") label = TPaveText(0.8891129,0.8644068,0.9435484,0.9258475,"brNDC") label.SetFillColor(0) label.SetTextSize(0.0529661); label.AddText(label_text); label.Draw("plain") #block1 =TPaveText(0.333,0.84,0.354,0.86,"brNDC"); # for N>=2 and >=3 only block1 =TPaveText(0.351,0.85,0.37,0.87,"brNDC"); block1.SetFillColor(0) block1.Draw("plain") #block2 =TPaveText(0.295,0.84,0.315,0.86,"brNDC"); # for N>=2 and >=3 only block2 =TPaveText(0.314,0.85,0.332,0.87,"brNDC"); block2.SetFillColor(0) block2.Draw("plain") if isExclusive: c.Print("ST_Mul%d.pdf" % N) c.Print("ST_Mul%d.png" % N) else: c.Print("ST_Mul%dup.pdf" % N) c.Print("ST_Mul%dup.png" % N) c.Update() raw_input("Press Enter to continue...")
def DrawOverlap(histList, titleVec, legendtext, pngname, logstatus=[0, 0], xRange=[-99999, 99999, 1], cat='2b'): gStyle.SetOptTitle(0) gStyle.SetOptStat(0) gStyle.SetTitleOffset(1.1, "Y") #gStyle.SetTitleOffset(1.9,"X"); gStyle.SetLineWidth(3) gStyle.SetFrameLineWidth(3) gStyle.SetTickLength(0.0, "x") i = 0 # histList_=[] # histList=[] # histList1=[] # maximum=[] ## Legend leg = TLegend(0.2, 0.80, 0.89, 0.89) #,NULL,"brNDC"); leg.SetBorderSize(0) leg.SetNColumns(3) # leg.SetLineColor(1) leg.SetLineStyle(1) leg.SetLineWidth(1) # leg.SetFillColor(0) leg.SetFillStyle(0) leg.SetTextFont(42) leg.SetTextSize(0.05) c = TCanvas("c1", "c1", 0, 0, 500, 500) c.SetBottomMargin(0.15) c.SetLeftMargin(0.15) c.SetLogy(logstatus[1]) c.SetLogx(logstatus[0]) # print ("you have provided "+str(len(fileVec))+" files and "+str(len(histVec))+" histograms to make a overlapping plot" ) # print "opening rootfiles" c.cd() print "provided hists", histList for ih in range(len(histList)): tt = type(histList[ih]) if logstatus[1] is 1: histList[ih].SetMaximum(1.5) #1.4 for log histList[ih].SetMinimum(0.1) #1.4 for log if logstatus[1] is 0: maxi = histList[ih].GetMaximum() histList[ih].SetMaximum(maxi * 2) #1.4 for log histList[ih].SetMinimum(0) #1.4 for log # print "graph_status =" ,(tt is TGraphAsymmErrors) # print "hist status =", (tt is TH1D) or (tt is TH1F) if ih == 0: if tt is TGraphAsymmErrors: histList[ih].Draw("APL") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("PE2 ") if ih > 0: #histList[ih].SetLineWidth(2) if tt is TGraphAsymmErrors: histList[ih].Draw("PL same") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("PE0 same") if tt is TGraphAsymmErrors: histList[ih].SetMaximum(100) histList[ih].SetMarkerColor(colors[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetLineWidth(0) histList[ih].SetMarkerStyle(markerStyle[ih]) histList[ih].SetMarkerSize(1) leg.AddEntry(histList[ih], legendtext[ih], "PL") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): print "setting style for hist" print "color code", colors[ih] # histList[ih].SetLineStyle(linestyle[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetMarkerColor(colors[ih]) histList[ih].SetFillColor(colors[ih]) histList[ih].SetMarkerStyle(20) histList[ih].SetMarkerSize(1.0) histList[ih].SetLineWidth(1) #invert legend between first and second if ih == 0: leg.AddEntry(histList[ih + 1], legendtext[ih + 1], "PEL") #"f") if ih == 1: leg.AddEntry(histList[ih - 1], legendtext[ih - 1], 'f') #"PEL") histList[ih].GetYaxis().SetTitle(titleVec[1]) histList[ih].GetYaxis().SetTitleSize(0.052) histList[ih].GetYaxis().SetTitleOffset(1.4) histList[ih].GetYaxis().SetTitleFont(42) histList[ih].GetYaxis().SetLabelFont(42) histList[ih].GetYaxis().SetLabelSize(.052) histList[ih].GetXaxis().SetRangeUser(xRange[0], xRange[1]) # histList[ih].GetXaxis().SetLabelSize(0.0000); histList[ih].GetXaxis().SetTitle(titleVec[0]) histList[ih].GetXaxis().SetLabelSize(0.052) histList[ih].GetXaxis().SetTitleSize(0.052) #histList[ih].GetXaxis().SetTitleOffset(1.14) histList[ih].GetXaxis().SetTitleFont(42) histList[ih].GetXaxis().SetLabelFont(42) histList[ih].GetYaxis().SetLabelFont(42) histList[ih].GetXaxis().SetNdivisions(507) #histList[ih].GetXaxis().SetMoreLogLabels(); #histList[ih].GetXaxis().SetNoExponent(); #histList[ih].GetTGaxis().SetMaxDigits(3); # histList[ih].GetXaxis().SetTickSize(0.00) i = i + 1 pt = TPaveText(0.01, 0.92, 0.95, 0.96, "brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(42) pt.SetTextSize(0.046) #text = pt.AddText(0.12,0.35,"CMS Internal 36 fb^{-1} (2016) ") text = pt.AddText(0.12, 0.35, "CMS Internal 41.5 fb^{-1} (2017) ") #text = pt.AddText(0.12,0.35,"CMS Internal 59.6 fb^{-1} (2018) ") #text = pt.AddText(0.6,0.5,"41.5 fb^{-1} (2017) ") cattxt = TLatex(0.20, 0.75, cat + ' ' + "category") cattxt.SetTextSize(0.06) cattxt.SetTextAlign(12) cattxt.SetNDC(1) cattxt.SetTextFont(42) pt.Draw() cattxt.Draw() leg.Draw() outputdirname = 'TFplots/' histname = outputdirname + pngname c.SaveAs(histname + '.png') c.SaveAs(histname + '.pdf')