def writeTitleTexts(lumi): # Texts for # 1) "CMS Preliminary" # 2) "sqrt(s) = 7" # 3) integrated luminosity tex = TLatex() tex.SetNDC() tex.SetTextFont(43) tex.SetTextSize(27) tex.SetLineWidth(2) tex.DrawLatex(0.62, 0.96, "CMS Preliminary") tex2 = TLatex() tex2.SetNDC() tex2.SetTextFont(43) tex2.SetTextSize(27) tex2.SetLineWidth(2) tex2.DrawLatex(0.2, 0.96, "#sqrt{s} = 7 TeV") mystring = '%.1f' % float(lumi) tex = TLatex() tex.SetNDC() tex.SetTextFont(43) tex.SetTextSize(27) tex.SetLineWidth(2) tex.DrawLatex(0.43, 0.96, mystring + " fb^{-1}") return 0
data_hist.SetLineColor(1) data_hist.SetLineWidth(2) leg = TLegend(0.77, 0.7, 0.97, 0.99) leg.AddEntry(data_hist, "Data", "lep") leg.AddEntry(Diboson_hist, "Diboson") leg.AddEntry(Triboson_hist, "Triboson") leg.AddEntry(Z_jets_hist, "Z+jets") leg.AddEntry(Top_hist, "Top") leg.AddEntry(W_jets_hist, "W+jets") leg.AddEntry(sig_hist, "signal", "lep") tex1 = TLatex(0.54, 0.75, "#int Ldt = 36.5 fb^{-1}") tex1.SetNDC() tex1.SetTextFont(42) tex1.SetLineWidth(2) tex2 = TLatex(0.54, 0.85, "#sqrt{s} = 13 TeV") tex2.SetNDC() tex2.SetTextFont(42) tex2.SetLineWidth(2) tex3 = TLatex(0.54, 0.93, "ATLAS Internal") tex3.SetNDC() tex3.SetTextFont(42) tex3.SetLineWidth(2) cc = TCanvas(var, var, 800, 750) # cc.SetLogy() pad1 = TPad("p1", "p1", 0, 0.25, 1, 1, 0, 0) pad1.SetMargin(0.15, 0.03, 0, 0.01) pad2 = TPad("p2", "p2", 0, 0, 1, 0.25, 0, 0) pad2.SetMargin(0.15, 0.03, 0.3, 0.01)
def cal_fraction(year, outputdir, eORb, pt_down, pt_up, fit_type, fdata, ftrue, ffake): sieie_cut = 0 if eORb == "barrel": sieie_cut = 0.01015 if eORb == "endcap": sieie_cut = 0.0272 lumi = 0 if year == "2016": lumi = 35.92 if year == "2017": lumi = 41.50 if year == "2018": lumi = 59.74 histname = "hist_" + eORb + "_" + str(pt_down) + "to" + str(pt_up) hdata = fdata.Get(histname) htrue = ftrue.Get(histname) hfake = ffake.Get(histname) c1 = TCanvas(histname, histname, 1000, 700) htrue.Scale(lumi) if fit_type == 'closureTEST': hdata.Scale(lumi) hfake.Scale(lumi) for i in range(hdata.GetNbinsX() + 2): if hdata.GetBinContent(i) < 0: hdata.SetBinContent(i, 0) if htrue.GetBinContent(i) < 0: htrue.SetBinContent(i, 0) if hfake.GetBinContent(i) < 0: hfake.SetBinContent(i, 0) mc = TObjArray(2) mc.Add(htrue) mc.Add(hfake) fit = TFractionFitter(hdata, mc) fit.Constrain(1, 0.0, 1.0) status = fit.Fit() val0, err0, val1, err1 = ROOT.Double(0), ROOT.Double(0), ROOT.Double( 0), ROOT.Double(0) n_data_total = hdata.Integral() fit.GetResult(0, val0, err0) fit.GetResult(1, val1, err1) # get fake rate nbin = hdata.FindFixBin(sieie_cut) - 1 nbins = hdata.GetNbinsX() fake_err_in_window, fake_err_total, data_err_in_window, data_err_total = ROOT.Double( 0), ROOT.Double(0), ROOT.Double(0), ROOT.Double(0) n_hfake_in_window = hfake.IntegralAndError(1, nbin, fake_err_in_window) n_hfake_total = hfake.IntegralAndError(1, nbins, fake_err_total) sector1 = n_hfake_in_window / n_hfake_total n_hdata_in_window = hdata.IntegralAndError(1, nbin, data_err_in_window) n_hdata_total = hdata.IntegralAndError(1, nbins, data_err_total) sector2 = n_hdata_in_window / n_hdata_total fakerate = val1 * sector1 / sector2 err_sector1 = sqrt( (sector1)**2 * ((fake_err_in_window / n_hfake_in_window)**2 + (fake_err_total / n_hfake_total)**2)) err_sector2 = sqrt( (sector2)**2 * ((data_err_in_window / n_hdata_in_window)**2 + (data_err_total / n_hdata_total)**2)) tmp = val1 * sector1 tmp_err = sqrt( (val1 * sector1)**2 * ((err_sector1 / sector1)**2 + (err1 / val1)**2)) fakerate_err = sqrt( (tmp / sector2)**2 * ((tmp_err / tmp)**2 + (err_sector2 / sector2)**2)) result = fit.GetPlot() hdata.Draw("p e") hdata.GetYaxis().SetTitle("Events/bin") hdata.GetYaxis().SetTitleOffset(1.45) hdata.GetXaxis().SetTitle("#sigma_{i#etai#eta}") hdata.SetStats(0) hdata.SetLineColor(1) hdata.SetMarkerStyle(20) result.Draw("HIST same") result.SetLineColor(8) result.SetLineWidth(2) result.SetStats(0) htrue.SetLineColor(2) htrue.SetLineWidth(2) htrue.SetStats(0) htrue.DrawNormalized("HIST e same", val0 * n_data_total) hfake.SetLineColor(4) hfake.SetLineWidth(2) hfake.SetStats(0) hfake.DrawNormalized("HIST e same", val1 * n_data_total) maximum = 1.3 * hdata.GetMaximum() hdata.SetMaximum(maximum) leg = TLegend(0.53, 0.48, 0.88, 0.88, "brNDC") leg.SetFillStyle(0) leg.SetLineColor(0) leg.SetFillColor(10) leg.SetBorderSize(0) leg.SetHeader( str(pt_down) + "GeV<p_{T}^{#gamma}<" + str(pt_up) + "GeV", "c") leg.AddEntry(hdata, "Data", "LPE") leg.AddEntry(result, "Template prediction", "LPE") leg.AddEntry(htrue, "True template from W#gamma", "LPE") leg.AddEntry(hfake, "Fake template from Data", "LPE") leg.Draw("same") statusStr = "fit status: " + str(int(status)) chi2 = fit.GetChisquare() ndf = fit.GetNDF() chi2ToNDF = chi2 / ndf chiInt = (100 * chi2ToNDF) strChi = "#chi^{2}/ndf = " + str(round( chiInt / 100, 3)) #+ '.' + str(round(chiInt % 100,3)) FRInt = (10000 * fakerate) FRErrInt = (10000 * fakerate_err) strFR = "fake rate = (" + str(round(FRInt / 100, 3)) + '#pm' + str( round(FRErrInt / 100, 3)) + '%)' latex = TLatex() latex.SetNDC() latex.SetTextSize(0.03) latex.SetLineWidth(1) latex.DrawLatex(0.75, 0.90, eORb) latex.DrawLatex(0.55, 0.44, statusStr) latex.DrawLatex(0.55, 0.38, strChi) latex.DrawLatex(0.55, 0.34, strFR) PNG_name = outputdir + '/' + str(year) + '_' + histname + '.png' c1.SaveAs(PNG_name) return fakerate, fakerate_err
stacked_mc[histogram_name_index].GetXaxis().SetLabelSize(0.035) stacked_mc[histogram_name_index].GetXaxis().SetLabelFont(42) stacked_mc[histogram_name_index].GetXaxis().SetTitleSize(0.035) #stacked_mc[histogram_name_index].SetTitle(histogram_descriptions[histogram_name_index]) stacked_mc[histogram_name_index].GetYaxis().SetTitleSize(0.06) stacked_mc[histogram_name_index].GetYaxis().SetLabelSize(0.05) stacked_mc[histogram_name_index].GetYaxis().SetTitleOffset(0.81) stacked_mc[histogram_name_index].GetYaxis().SetTitleFont(42) stacked_mc[histogram_name_index].GetYaxis().SetLabelFont(42) #cmslabel.Draw() text3 = TLatex(0.1969, 0.906825, "CMS") text3.SetNDC() text3.SetTextAlign(13) text3.SetTextFont(61) text3.SetTextSize(0.07475) text3.SetLineWidth(2) text3.Draw() text2 = TLatex(0.1969, 0.817125, "Preliminary") text2.SetNDC() text2.SetTextAlign(13) text2.SetTextFont(52) text2.SetTextSize(0.05681) text2.SetLineWidth(2) text2.Draw() text4 = TLatex(0.1969, 0.727425, "t#bar{t} sample") text4.SetNDC() text4.SetTextAlign(12) text4.SetTextFont(42) text4.SetTextSize(0.05681) text4.SetLineWidth(2) text4.Draw()
def train_and_apply(): np.random.seed(1) ROOT.gROOT.SetBatch() #Extract data from root file tree = uproot.open("out_all.root")["outA/Tevts"] branch_mc = [ "MC_B_P", "MC_B_eta", "MC_B_phi", "MC_B_pt", "MC_D0_P", "MC_D0_eta", "MC_D0_phi", "MC_D0_pt", "MC_Dst_P", "MC_Dst_eta", "MC_Dst_phi", "MC_Dst_pt", "MC_Est_mu", "MC_M2_miss", "MC_mu_P", "MC_mu_eta", "MC_mu_phi", "MC_mu_pt", "MC_pis_P", "MC_pis_eta", "MC_pis_phi", "MC_pis_pt", "MC_q2" ] branch_rec = [ "B_P", "B_eta", "B_phi", "B_pt", "D0_P", "D0_eta", "D0_phi", "D0_pt", "Dst_P", "Dst_eta", "Dst_phi", "Dst_pt", "Est_mu", "M2_miss", "mu_P", "mu_eta", "mu_phi", "mu_pt", "pis_P", "pis_eta", "pis_phi", "pis_pt", "q2" ] nvariable = len(branch_mc) x_train = tree.array(branch_mc[0], entrystop=options.maxevents) for i in range(1, nvariable): x_train = np.vstack( (x_train, tree.array(branch_mc[i], entrystop=options.maxevents))) x_test = tree.array(branch_rec[0], entrystop=options.maxevents) for i in range(1, nvariable): x_test = np.vstack( (x_test, tree.array(branch_rec[i], entrystop=options.maxevents))) x_train = x_train.T x_test = x_test.T x_test = array2D_float(x_test) #Different type of reconstruction variables #BN normalization gamma = 0 beta = 0.2 ar = np.array(x_train) a = K.constant(ar[:, 0]) mean = K.mean(a) var = K.var(a) x_train = K.eval(K.batch_normalization(a, mean, var, gamma, beta)) for i in range(1, nvariable): a = K.constant(ar[:, i]) mean = K.mean(a) var = K.var(a) a = K.eval(K.batch_normalization(a, mean, var, gamma, beta)) x_train = np.vstack((x_train, a)) x_train = x_train.T ar = np.array(x_test) a = K.constant(ar[:, 0]) mean = K.mean(a) var = K.var(a) x_test = K.eval(K.batch_normalization(a, mean, var, gamma, beta)) for i in range(1, nvariable): a = K.constant(ar[:, i]) mean = K.mean(a) var = K.var(a) a = K.eval(K.batch_normalization(a, mean, var, gamma, beta)) x_test = np.vstack((x_test, a)) x_test = x_test.T #Add noise, remain to be improved noise = np.random.normal(loc=0.0, scale=0.01, size=x_train.shape) x_train_noisy = x_train + noise noise = np.random.normal(loc=0.0, scale=0.01, size=x_test.shape) x_test_noisy = x_test + noise x_train = np.clip(x_train, -1., 1.) x_test = np.clip(x_test, -1., 1.) x_train_noisy = np.clip(x_train_noisy, -1., 1.) x_test_noisy = np.clip(x_test_noisy, -1., 1.) # Network parameters input_shape = (x_train.shape[1], ) batch_size = 128 latent_dim = 2 # Build the Autoencoder Model # First build the Encoder Model inputs = Input(shape=input_shape, name='encoder_input') x = inputs # Shape info needed to build Decoder Model shape = K.int_shape(x) # Generate the latent vector latent = Dense(latent_dim, name='latent_vector')(x) # Instantiate Encoder Model encoder = Model(inputs, latent, name='encoder') encoder.summary() # Build the Decoder Model latent_inputs = Input(shape=(latent_dim, ), name='decoder_input') x = Dense(shape[1])(latent_inputs) x = Reshape((shape[1], ))(x) outputs = Activation('tanh', name='decoder_output')(x) # Instantiate Decoder Model decoder = Model(latent_inputs, outputs, name='decoder') decoder.summary() # Autoencoder = Encoder + Decoder # Instantiate Autoencoder Model autoencoder = Model(inputs, decoder(encoder(inputs)), name='autoencoder') autoencoder.summary() autoencoder.compile(loss='mse', optimizer='adam') # Train the autoencoder autoencoder.fit(x_train_noisy, x_train, validation_data=(x_test_noisy, x_test), epochs=options.epochs, batch_size=batch_size) # Predict the Autoencoder output from corrupted test imformation x_decoded = autoencoder.predict(x_test_noisy) # Draw Comparision Plots c = TCanvas("c", "c", 700, 700) fPads1 = TPad("pad1", "Run2", 0.0, 0.29, 1.00, 1.00) fPads2 = TPad("pad2", "", 0.00, 0.00, 1.00, 0.29) fPads1.SetBottomMargin(0.007) fPads1.SetLeftMargin(0.10) fPads1.SetRightMargin(0.03) fPads2.SetLeftMargin(0.10) fPads2.SetRightMargin(0.03) fPads2.SetBottomMargin(0.25) fPads1.Draw() fPads2.Draw() fPads1.cd() nbin = 50 min = -1. max = 1. variable = "P^{B}" lbin = (max - min) / nbin lbin = str(float((max - min) / nbin)) xtitle = branch_rec[options.branch - 1] ytitle = "Events/" + lbin + "GeV" h_rec = TH1D("h_rec", "" + ";%s;%s" % (xtitle, ytitle), nbin, min, max) h_rec.Sumw2() h_pre = TH1D("h_pre", "" + ";%s;%s" % (xtitle, ytitle), nbin, min, max) h_pre.Sumw2() for i in range(x_test_noisy.shape[0]): h_rec.Fill(x_test_noisy[i][options.branch - 1]) h_pre.Fill(x_decoded[i][options.branch - 1]) h_rec = UnderOverFlow1D(h_rec) h_pre = UnderOverFlow1D(h_pre) maxY = TMath.Max(h_rec.GetMaximum(), h_pre.GetMaximum()) h_rec.SetLineColor(2) h_rec.SetFillStyle(0) h_rec.SetLineWidth(2) h_rec.SetLineStyle(1) h_pre.SetLineColor(3) h_pre.SetFillStyle(0) h_pre.SetLineWidth(2) h_pre.SetLineStyle(1) h_rec.SetStats(0) h_pre.SetStats(0) h_rec.GetYaxis().SetRangeUser(0, maxY * 1.1) h_rec.Draw("HIST") h_pre.Draw("same HIST") h_rec.GetYaxis().SetTitleSize(0.06) h_rec.GetYaxis().SetTitleOffset(0.78) theLeg = TLegend(0.5, 0.45, 0.95, 0.82, "", "NDC") theLeg.SetName("theLegend") theLeg.SetBorderSize(0) theLeg.SetLineColor(0) theLeg.SetFillColor(0) theLeg.SetFillStyle(0) theLeg.SetLineWidth(0) theLeg.SetLineStyle(0) theLeg.SetTextFont(42) theLeg.SetTextSize(.05) theLeg.AddEntry(h_rec, "Reconstruction", "L") theLeg.AddEntry(h_pre, "Prediction", "L") theLeg.SetY1NDC(0.9 - 0.05 * 6 - 0.005) theLeg.SetY1(theLeg.GetY1NDC()) fPads1.cd() theLeg.Draw() title = TLatex( 0.91, 0.93, "AE prediction compare with reconstruction, epochs=" + str(options.epochs)) title.SetNDC() title.SetTextSize(0.05) title.SetTextFont(42) title.SetTextAlign(31) title.SetLineWidth(2) title.Draw() fPads2.cd() h_Ratio = h_pre.Clone("h_Ratio") h_Ratio.Divide(h_rec) h_Ratio.SetLineColor(1) h_Ratio.SetLineWidth(2) h_Ratio.SetMarkerStyle(8) h_Ratio.SetMarkerSize(0.7) h_Ratio.GetYaxis().SetRangeUser(0, 2) h_Ratio.GetYaxis().SetNdivisions(504, 0) h_Ratio.GetYaxis().SetTitle("Pre/Rec") h_Ratio.GetYaxis().SetTitleOffset(0.35) h_Ratio.GetYaxis().SetTitleSize(0.13) h_Ratio.GetYaxis().SetTitleSize(0.13) h_Ratio.GetYaxis().SetLabelSize(0.11) h_Ratio.GetXaxis().SetLabelSize(0.1) h_Ratio.GetXaxis().SetTitleOffset(0.8) h_Ratio.GetXaxis().SetTitleSize(0.14) h_Ratio.SetStats(0) axis1 = TGaxis(min, 1, max, 1, 0, 0, 0, "L") axis1.SetLineColor(1) axis1.SetLineWidth(1) for i in range(1, h_Ratio.GetNbinsX() + 1, 1): D = h_rec.GetBinContent(i) eD = h_rec.GetBinError(i) if D == 0: eD = 0.92 B = h_pre.GetBinContent(i) eB = h_pre.GetBinError(i) if B < 0.1 and eB >= B: eB = 0.92 Err = 0. if B != 0.: Err = TMath.Sqrt((eD * eD) / (B * B) + (D * D * eB * eB) / (B * B * B * B)) h_Ratio.SetBinContent(i, D / B) h_Ratio.SetBinError(i, Err) if B == 0.: Err = TMath.Sqrt((eD * eD) / (eB * eB) + (D * D * eB * eB) / (eB * eB * eB * eB)) h_Ratio.SetBinContent(i, D / 0.92) h_Ratio.SetBinError(i, Err) if D == 0 and B == 0: h_Ratio.SetBinContent(i, -1) h_Ratio.SetBinError(i, 0) h_Ratio.Draw("e0") axis1.Draw() c.SaveAs(branch_rec[options.branch - 1] + "_comparision.png")
def plotUpperLimits(labels, values): # see CMS plot guidelines: https://ghm.web.cern.ch/ghm/plots/ N = len(labels) yellow = TGraph(2 * N) # yellow band green = TGraph(2 * N) # green band median = TGraph(N) # median line up2s = [] for i in range(N): # file_name = "higgsCombine"+labels[i]+"AsymptoticLimits.mH125.root" file_name = "higgsCombine.AsymptoticLimits.mH125." + labels[i] + ".root" limit = getLimits(file_name) # print'limit = ',limit # print'values[i] = ',values[i] up2s.append(limit[4]) yellow.SetPoint(i, values[i], limit[4]) # + 2 sigma green.SetPoint(i, values[i], limit[3]) # + 1 sigma median.SetPoint(i, values[i], limit[2]) # median green.SetPoint(2 * N - 1 - i, values[i], limit[1]) # - 1 sigma yellow.SetPoint(2 * N - 1 - i, values[i], limit[0]) # - 2 sigma W = 800 H = 600 T = 0.08 * H B = 0.12 * H L = 0.12 * W R = 0.04 * W c = TCanvas("c", "c", 100, 100, W, H) c.SetFillColor(0) c.SetBorderMode(0) c.SetFrameFillStyle(0) c.SetFrameBorderMode(0) c.SetLeftMargin(L / W) c.SetRightMargin(R / W) c.SetTopMargin(T / H) c.SetBottomMargin(B / H) c.SetTickx(0) c.SetTicky(0) c.SetGrid() # c.SetLogy() # gPad.SetLogy() c.cd() # ROOT.gPad.SetLogy() # c.SetLogy() frame = c.DrawFrame(1.4, 0.001, 4.1, 10) frame.GetYaxis().CenterTitle() frame.GetYaxis().SetTitleSize(0.05) frame.GetXaxis().SetTitleSize(0.05) frame.GetXaxis().SetLabelSize(0.04) frame.GetYaxis().SetLabelSize(0.04) frame.GetYaxis().SetTitleOffset(0.9) frame.GetXaxis().SetNdivisions(508) frame.GetYaxis().CenterTitle(True) # frame.GetYaxis().SetTitle("95% upper limit on #sigma / #sigma_{SM}") if (args.atlas_compare): frame.GetYaxis().SetTitle( "95% CL limits on #sigma(gg#rightarrow X)#times B(X#rightarrow HH) [pb]" ) elif (args.CMS_compare): frame.GetYaxis().SetTitle( "95% CL limit on #sigma(gg#rightarrow X#rightarrow HH) (fb)") # frame.GetYaxis().SetTitle("95% upper limit on #sigma #times BR / (#sigma #times BR)_{SM}") # frame.GetXaxis().SetTitle("background systematic uncertainty [%]") #if(args.SM_Radion): frame.GetXaxis.SetTitle("Standard Model") #else: frame.GetXaxis().SetTitle("Radion Mass (GeV)") # frame.SetMinimum(0) # frame.SetMinimum(1) # need Minimum > 0 for log scale frame.SetMinimum(1.000001) # need Minimum > 0 for log scale # frame.SetMaximum(max(up2s)*1.05) # frame.SetMaximum(max(up2s)*2) # frame.SetMaximum(1000.) if (args.atlas_compare): frame.SetMaximum(7 * 1e2) # ATLAS elif (args.CMS_compare): frame.SetMaximum(8 * 1e4) # CMS HH #frame.GetXaxis().SetLimits(min(values),max(values)) # frame.SetLogy() frame.GetXaxis().SetLimits(min(values) - 10, max(values) + 10) yellow.SetFillColor(ROOT.kOrange) yellow.SetLineColor(ROOT.kOrange) yellow.SetFillStyle(1001) yellow.Draw('F') green.SetFillColor(ROOT.kGreen + 1) green.SetLineColor(ROOT.kGreen + 1) green.SetFillStyle(1001) green.Draw('Fsame') median.SetLineColor(1) median.SetLineWidth(2) median.SetLineStyle(2) median.Draw('Lsame') CMS_lumi.CMS_lumi(c, 4, 11) ROOT.gPad.SetTicks(1, 1) frame.Draw('sameaxis') # yboost = 0.075 yboost = -0.2 x1 = 0.15 x2 = x1 + 0.24 y2 = 0.76 + yboost y1 = 0.60 + yboost legend = TLegend(x1, y1, x2, y2) legend.SetFillStyle(0) legend.SetBorderSize(0) legend.SetTextSize(0.041) legend.SetTextFont(42) legend.AddEntry(median, "AsymptoticLimits CL_{s} expected", 'L') legend.AddEntry(green, "#pm 1 std. deviation", 'f') # legend.AddEntry(green, "AsymptoticLimits CL_{s} #pm 1 std. deviation",'f') legend.AddEntry(yellow, "#pm 2 std. deviation", 'f') # legend.AddEntry("","STAT Only","") # legend.AddEntry(green, "AsymptoticLimits CL_{s} #pm 2 std. deviation",'f') legend.Draw() label = TLatex() label.SetNDC() label.SetTextAngle(0) label.SetTextColor(kBlack) label.SetTextFont(42) label.SetTextSize(0.045) label.SetLineWidth(2) label.DrawLatex(0.7, 0.7 + yboost, "STAT only") print " " # c.SaveAs("UpperLimit.png") outFile = '' if (args.CMS_compare): outFile += "CMS_Compare_" if (args.atlas_compare): outFile += "atlas_Compare_" if args.SM_Radion: outFile += "SM_" c.SaveAs(outFile + "UpperLimit.pdf") c.SaveAs(outFile + "UpperLimit.C") c.Close()
def plot(ana, histos, h_legend, minY, maxY, minX, maxX, whatX, whatY, c1=0): global stack, leg, dum # print what # gROOT.SetBatch(True) # suppress root window popping up #! better: sys.argv.append('b') gROOT.ProcessLine( "gErrorIgnoreLevel = kWarning;" ) # suppress standard output of the form: "Info in <TCanvas::Print>: ... has been created" and # "Info in <TCanvas::SaveAs>: ... has been created" #prepare the layout if c1 == 0: c1 = TCanvas('c1', '', 800, 600) c1.SetLogy() dum = histo.Clone() # dum.Reset() dum.SetMinimum(minY) dum.SetMaximum(maxY) dum.GetXaxis().SetRangeUser(minX, maxX) # last = dum.FindLastBinAbove(0,1) # last = last + 0.5 * last # dum.GetXaxis().SetRange(0,last+10) dum.GetXaxis().SetTitleSize(0.038) dum.GetYaxis().SetTitleSize(0.04) dum.GetXaxis().SetLabelSize(0.03) dum.GetYaxis().SetLabelSize(0.03) dum.GetXaxis().SetTitleOffset(1.2) dum.GetYaxis().SetTitleOffset(1.1) dum.SetXTitle(whatX) dum.SetYTitle(whatY) dum.SetTitle('') dum.SetStats(0) dum.Draw() tex = TLatex( 0.89, 0.93, "#scale[0.8]{CMSSW_7_2_3} #scale[0.6]{ #sqrt{s} = 13 TeV, #int L dt = 4 fb^{-1}, bx = 25 ns, PU = 20}" ) tex.SetNDC() tex.SetTextAlign(31) tex.SetTextFont(42) tex.SetTextSize(0.047) tex.SetLineWidth(2) tex.Draw() #CMS_lumi_v2( c1, 14, 11 ) # tex1 = TLatex(0.15,0.89,"CMSSW_7_2_3 ") # tex1.SetNDC() # tex1.SetTextAlign(13) # tex1.SetTextFont(61) # tex1.SetTextSize(0.045) # tex1.SetLineWidth(2) # tex1.Draw() # a legend # leg = TLegend(0.63,0.525,0.87,0.875) #for 33 TeV # leg = TLegend(0.65,0.65,0.9,0.9) leg = TLegend(0.6545226, 0.534965, 0.8944724, 0.8846154) #fits best leg.SetBorderSize(1) leg.SetTextFont(62) leg.SetTextSize(0.035) leg.SetLineColor(0) leg.SetLineStyle(1) leg.SetLineWidth(1) leg.SetFillColor(0) leg.SetFillStyle(1001) if ana == 'TTbar': title = ' t#bar{t}' leg.AddEntry(histo, title, 'l') elif ana == 'WJets': leg.AddEntry(histo, 'W+jets', 'l') elif ana == 'DYJets': leg.AddEntry(histo, 'DY+jets', 'l') elif ana == 'QCD': leg.AddEntry(histo, 'QCD', 'l') elif ana == 'SingleTop': leg.AddEntry(histo, 't / #bar{t}', 'l') elif ana == 'TTH': leg.AddEntry(histo, 'ttH', 'l') elif ana == 'TTW': leg.AddEntry(histo, 'ttW', 'l') elif ana == 'TTZ': leg.AddEntry(histo, 'ttZ', 'l') elif ana == 'T1tttt_1500_100': leg.AddEntry(histo, 'T1t^{4}(1500,100)', 'l') elif ana == 'T1tttt_1200_800': leg.AddEntry(histo, 'T1t^{4}(1200,800)', 'l') elif ana == 'T5tttt_1000_280': leg.AddEntry(histo, 'T5t^{4}(1000,280)', 'l') elif ana == 'T5tttt_1300_280': leg.AddEntry(histo, 'T5t^{4}(1300,280)', 'l') elif ana == 'T5tttt_1000_285': leg.AddEntry(histo, 'T5t^{4}(1000,285)', 'l') elif ana == 'T5tttt_1300_285': leg.AddEntry(histo, 'T5t^{4}(1300,285)', 'l') elif ana == 'T1ttbbWW_1300_290': leg.AddEntry(histo, 'T1t^{2}b^{2}W^{2}(1300,290)', 'l') elif ana == 'T1ttbbWW_1300_295': leg.AddEntry(histo, 'T1t^{2}b^{2}W^{2}(1300,295)', 'l') elif ana == 'T1ttbbWW_1000_715': leg.AddEntry(histo, 'T1t^{2}b^{2}W^{2}(1000,715)', 'l') elif ana == 'T1ttbbWW_1000_720': leg.AddEntry(histo, 'T1t^{2}b^{2}W^{2}(1000,720)', 'l') elif ana == 'SqGl_1300_100': leg.AddEntry(histo, 'SqGl(1300,100)', 'l') # bgrd stack if histos != 0 and h_legend != 0: stack = THStack('stack', '') N = len(histos) for i in range(N): h = histos[i][0] stack.Add(h) for i in range(N - 1, -1, -1): h = histos[i][0] t = h_legend[h] leg.AddEntry(h, t, 'f') # draw bgrds + signals # stack.Draw('samehist') stack.Draw('same') #histo.Draw('samehist') histo.Draw('same') leg.Draw("same") gPad.RedrawAxis() c1.SaveAs(dir_png_noCuts + what + ".png") c1.SaveAs(dir_pdf_noCuts + what + ".pdf") c1.SaveAs(dir_root_noCuts + what + ".root")
def doULPlot(suffix): xbins = array('d', []) xbins_env = array('d', []) ybins_exp = array('d', []) ybins_obs = array('d', []) ybins_1s = array('d', []) ybins_2s = array('d', []) ybins_th = array('d', []) for i in range(len(mass)): curFile = "higgsCombine_lim_%s%03d%s.Asymptotic.mH%03d.root" % ( options.signalmodel, mass[i], suffix, mass[i]) print "curFile: %s" % curFile if options.lvqqBR: sf = table_signalscale[mass[i]] * xsDict_lvj[mass[i]] #*0.1057*0.577; # BR(W->munu)*BR(H->bb) else: sf = table_signalscale[mass[i]] * xsDict[mass[i]] curAsymLimits = getAsymLimits(curFile) #print mass[i] #print curAsymLimits #raw_input("zixu") xbins.append(mass[i] / 1000.) #GeV->TeV xbins_env.append(mass[i] / 1000.) ybins_exp.append(curAsymLimits[3] * sf) ybins_obs.append(curAsymLimits[0] * sf) ybins_2s.append(curAsymLimits[1] * sf) ybins_1s.append(curAsymLimits[2] * sf) #ybins_th.append(sf);#/20.); #*0.25); if options.lvqqBR: ybins_th.append(xsDict_lvj[mass[i]]) #/20.); #*0.25); else: ybins_th.append(xsDict[mass[i]]) #/20.); #*0.25); for i in range(len(mass) - 1, -1, -1): curFile = "higgsCombine_lim_%s%03d%s.Asymptotic.mH%03d.root" % ( options.signalmodel, mass[i], suffix, mass[i]) print "curFile: %s" % curFile if options.lvqqBR: sf = table_signalscale[mass[i]] * xsDict_lvj[mass[i]] #*0.1057*0.577; # BR(W->munu)*BR(H->bb) else: sf = table_signalscale[mass[i]] * xsDict[mass[i]] curAsymLimits = getAsymLimits(curFile) xbins_env.append(mass[i] / 1000.) ybins_2s.append(curAsymLimits[5] * sf) ybins_1s.append(curAsymLimits[4] * sf) nPoints = len(mass) curGraph_exp = ROOT.TGraphAsymmErrors(nPoints, xbins, ybins_exp) curGraph_obs = ROOT.TGraphAsymmErrors(nPoints, xbins, ybins_obs) curGraph_th = ROOT.TGraph(nPoints, xbins, ybins_th) curGraph_1s = ROOT.TGraphAsymmErrors(nPoints * 2, xbins_env, ybins_1s) curGraph_2s = ROOT.TGraphAsymmErrors(nPoints * 2, xbins_env, ybins_2s) curGraph_obs.SetMarkerStyle(20) curGraph_obs.SetLineWidth(3) curGraph_obs.SetLineStyle(1) curGraph_obs.SetMarkerSize(1.6) curGraph_exp.SetMarkerSize(1.3) curGraph_exp.SetMarkerColor(ROOT.kBlack) curGraph_exp.SetLineStyle(2) curGraph_exp.SetLineWidth(3) curGraph_exp.SetMarkerSize(2) curGraph_exp.SetMarkerStyle(24) curGraph_exp.SetMarkerColor(ROOT.kBlack) #curGraph_th.SetLineStyle(ROOT.kDashed); curGraph_th.SetFillStyle(3344) curGraph_th.SetLineWidth(2) curGraph_th.SetMarkerSize(2) curGraph_th.SetLineColor(ROOT.kRed) curGraph_1s.SetFillColor(ROOT.kGreen) curGraph_1s.SetFillStyle(1001) curGraph_1s.SetLineStyle(ROOT.kDashed) curGraph_1s.SetLineWidth(3) curGraph_2s.SetFillColor(ROOT.kYellow) curGraph_2s.SetFillStyle(1001) curGraph_2s.SetLineStyle(ROOT.kDashed) curGraph_2s.SetLineWidth(3) oneLine = ROOT.TF1("oneLine", "1", 799, 1001) oneLine.SetLineColor(ROOT.kRed) oneLine.SetLineWidth(3) setStyle() can_SM = ROOT.TCanvas("can_SM", "can_SM", 630, 600) hrl_SM = can_SM.DrawFrame(mass[0] / 1000. - 0.01, 1e-4, mass[nPoints - 1] / 1000. + 0.01, 1e2) if options.signalmodel == "BulkGravWW": if options.lvqqBR: hrl_SM.GetYaxis().SetTitle( "#sigma_{95%} (pp #rightarrow G_{Bulk} #rightarrow WW #rightarrow l#nuqq') (pb)" ) else: hrl_SM.GetYaxis().SetTitle( "#sigma_{95%} (pp #rightarrow G_{Bulk} #rightarrow WW) (pb)") elif options.signalmodel == "WprimeWZ": if options.lvqqBR: hrl_SM.GetYaxis().SetTitle( "#sigma_{95%} (pp #rightarrow W' #rightarrow WZ #rightarrow l#nuqq') (pb)" ) else: hrl_SM.GetYaxis().SetTitle( "#sigma_{95%} (pp #rightarrow W' #rightarrow WZ) (pb)") elif options.signalmodel == "WprimeWZ-HVT-A": if options.lvqqBR: hrl_SM.GetYaxis().SetTitle( "#sigma_{95%} (pp #rightarrow W' #rightarrow WZ #rightarrow l#nuqq') (pb)" ) else: hrl_SM.GetYaxis().SetTitle( "#sigma_{95%} (pp #rightarrow W' #rightarrow WZ) (pb)") hrl_SM.GetYaxis().SetTitleOffset(1.35) hrl_SM.GetYaxis().SetTitleSize(0.045) hrl_SM.GetYaxis().SetTitleFont(42) if options.signalmodel == "BulkGravWW": hrl_SM.GetXaxis().SetTitle("M_{G_{Bulk}} (TeV)") elif options.signalmodel == "WprimeWZ": hrl_SM.GetXaxis().SetTitle("M_{W'} (TeV)") elif options.signalmodel == "WprimeWZ-HVT-A": hrl_SM.GetXaxis().SetTitle("M_{W'} (TeV)") hrl_SM.GetXaxis().SetTitleSize(0.045) hrl_SM.GetXaxis().SetTitleFont(42) hrl_SM.GetXaxis().SetNdivisions(510) hrl_SM.GetYaxis().SetNdivisions(505) can_SM.SetGridx(1) can_SM.SetGridy(1) curGraph_2s.Draw("F") curGraph_1s.Draw("Fsame") if options.keepblind == 0: curGraph_obs.Draw("PLsame") curGraph_exp.Draw("Lsame") curGraph_th.Draw("Csame") leg2 = ROOT.TLegend(0.32, 0.67, 0.9, 0.92) leg2.SetFillColor(0) leg2.SetShadowColor(0) leg2.SetTextFont(42) leg2.SetTextSize(0.035) leg2.AddEntry(curGraph_1s, "Asympt. CL_{S} Expected #pm 1 s.d.", "LF") leg2.AddEntry(curGraph_2s, "Asympt. CL_{S} Expected #pm 2 s.d.", "LF") if options.signalmodel == "BulkGravWW": if options.lvqqBR: leg2.AddEntry( curGraph_th, "#sigma_{TH} #times BR(G_{Bulk}#rightarrow WW#rightarrow l#nuqq'), #tilde{k}=0.5", "L") else: leg2.AddEntry( curGraph_th, "#sigma_{TH} #times BR(G_{Bulk}#rightarrow WW), #tilde{k}=0.5", "L") elif options.signalmodel == "WprimeWZ": if options.lvqqBR: leg2.AddEntry( curGraph_th, "#sigma_{TH} #times BR(W'_{HVT B}#rightarrow WZ#rightarrow l#nuqq')", "L") else: leg2.AddEntry(curGraph_th, "#sigma_{TH} #times BR(W'_{HVT B}#rightarrow WZ)", "L") elif options.signalmodel == "WprimeWZ-HVT-A": if options.lvqqBR: leg2.AddEntry( curGraph_th, "#sigma_{TH} #times BR(W'_{HVT A}#rightarrow WZ#rightarrow l#nuqq')", "L") else: leg2.AddEntry(curGraph_th, "#sigma_{TH} #times BR(W'_{HVT A}#rightarrow WZ)", "L") leg2.AddEntry(curGraph_obs, "Asympt. CL_{S} Observed", "LP") #ROOT.gPad.SetLogx(); #hrl_SM.GetXaxis().SetMoreLogLabels() #hrl_SM.GetXaxis().SetNoExponent() ROOT.gPad.SetLogy() can_SM.Update() can_SM.RedrawAxis() can_SM.RedrawAxis("g") can_SM.Update() leg2.Draw() line = TLine(1.1, 1e-4, 1.1, 1e0) line.SetLineWidth(2) line.SetLineColor(kBlack) line.SetLineStyle(9) line.Draw() banner = TLatex(0.95, 0.96, "%s fb^{-1} (13 TeV)" % (Lumi)) banner.SetNDC() banner.SetTextSize(0.038) banner.SetTextFont(42) banner.SetTextAlign(31) banner.SetLineWidth(2) banner.Draw() CMStext = TLatex(0.15, 0.96, "CMS") CMStext.SetNDC() CMStext.SetTextSize(0.041) CMStext.SetTextFont(61) CMStext.SetTextAlign(11) CMStext.SetLineWidth(2) CMStext.Draw() if suffix == "_el_HP": Extratext = TLatex(0.241, 0.96, "Preliminary W#rightarrow e#nu") Extratext.SetNDC() Extratext.SetTextSize(0.032) Extratext.SetTextFont(52) Extratext.SetTextAlign(11) Extratext.SetLineWidth(2) Extratext.Draw() elif suffix == "_mu_HP": Extratext = TLatex(0.241, 0.96, "Preliminary W#rightarrow #mu#nu") Extratext.SetNDC() Extratext.SetTextSize(0.032) Extratext.SetTextFont(52) Extratext.SetTextAlign(11) Extratext.SetLineWidth(2) Extratext.Draw() elif suffix == "_em_HP": Extratext = TLatex(0.241, 0.96, "Preliminary W#rightarrow l#nu") Extratext.SetNDC() Extratext.SetTextSize(0.032) Extratext.SetTextFont(52) Extratext.SetTextAlign(11) Extratext.SetLineWidth(2) Extratext.Draw() #CMS_lumi.lumi_13TeV = "%s fb^{-1}"%(Lumi) #CMS_lumi.writeExtraText = 1 #CMS_lumi.extraText = "Preliminary" #iPos = 11 #if(iPos == 0): # CMS_lumi.relPosX = 0.15 #CMS_lumi.CMS_lumi(can_SM, 4, 11) os.system("mkdir -p %s/LimitResult/" % (os.getcwd())) os.system("mkdir -p %s/LimitResult/Limit_%s_sys%s/" % (os.getcwd(), options.signalmodel, options.Sys)) can_SM.SaveAs("./LimitResult/Limit_%s_sys%s/Lim%s.png" % (options.signalmodel, options.Sys, suffix)) can_SM.SaveAs("./LimitResult/Limit_%s_sys%s/Lim%s.pdf" % (options.signalmodel, options.Sys, suffix)) #can_SM.SaveAs("./LimitResult/Limit_sys%s/Lim%s.root"%(options.Sys, suffix)); can_SM.SaveAs("./LimitResult/Limit_%s_sys%s/Lim%s.C" % (options.signalmodel, options.Sys, suffix)) ROOT.gPad.SetLogx() hrl_SM.GetXaxis().SetMoreLogLabels() hrl_SM.GetXaxis().SetNoExponent() can_SM.Update() can_SM.RedrawAxis() can_SM.RedrawAxis("g") leg2.Draw() can_SM.Update() can_SM.SaveAs("./LimitResult/Limit_%s_sys%s/Lim%s_Logx.png" % (options.signalmodel, options.Sys, suffix)) can_SM.SaveAs("./LimitResult/Limit_%s_sys%s/Lim%s_Logx.pdf" % (options.signalmodel, options.Sys, suffix)) can_SM.SaveAs("./LimitResult/Limit_%s_sys%s/Lim%s_Logx.C" % (options.signalmodel, options.Sys, suffix))
def plotUpperLimits(masses, limit, ALP_xs, name): N = len(masses) print str(N) + ' mass points' yellow = TGraph(2 * N) # yellow band green = TGraph(2 * N) # green band median = TGraph(N) # median line print 'limit = ', limit for i in range(N): print 'ALP mass: ' + str(masses[i]) + ' GeV' x_mass = masses[i] yellow.SetPoint(i, x_mass, limit[x_mass][4] * ALP_xs) # + 2 sigma green.SetPoint(i, x_mass, limit[x_mass][3] * ALP_xs) # + 1 sigma median.SetPoint(i, x_mass, limit[x_mass][2] * ALP_xs) # median green.SetPoint(2 * N - 1 - i, x_mass, limit[x_mass][1] * ALP_xs) # - 1 sigma yellow.SetPoint(2 * N - 1 - i, x_mass, limit[x_mass][0] * ALP_xs) # - 2 sigma W = 800 H = 600 T = 0.08 * H B = 0.12 * H L = 0.12 * W R = 0.04 * W c = TCanvas("c", "c", 100, 100, W, H) c.SetFillColor(0) c.SetBorderMode(0) c.SetFrameFillStyle(0) c.SetFrameBorderMode(0) c.SetLeftMargin(L / W) c.SetRightMargin(R / W) c.SetTopMargin(T / H) c.SetBottomMargin(B / H) c.SetTickx(0) c.SetTicky(0) c.SetGrid() c.cd() frame = c.DrawFrame(1.4, 0.001, 4.1, 10) frame.GetYaxis().CenterTitle() frame.GetYaxis().SetTitleSize(0.04) frame.GetXaxis().SetTitleSize(0.05) frame.GetXaxis().SetLabelSize(0.04) frame.GetYaxis().SetLabelSize(0.04) frame.GetYaxis().SetTitleOffset(1.3) frame.GetXaxis().SetNdivisions(508) frame.GetYaxis().CenterTitle(True) frame.GetXaxis().SetTitle("m_{a} [GeV]") if (args.pb): frame.GetYaxis().SetTitle( "95% CL limits on #sigma(gg#rightarrow H)#times B(X#rightarrow HH) [pb]" ) elif (args.fb): if name == 'coeff': frame.GetYaxis().SetTitle( "95% CL limits on |C_{Zh}^{eff}| [#frac{#Lambda}{1 TeV}]") frame.SetMinimum(0.01) # need Minimum > 0 for log scale frame.SetMaximum(1.) # CMS HH elif name == 'Br': #frame.GetYaxis().SetTitle("95% CL limits on #sigma(gg#rightarrow H#rightarrow Za#rightarrow 2l + 2#gamma)(fb)") frame.GetYaxis().SetTitle( "95% CL limits on Br(pp#rightarrow H#rightarrow Za#rightarrow 2l + 2#gamma)" ) frame.SetMinimum(0.000001) # need Minimum > 0 for log scale frame.SetMaximum(1.) # CMS HH else: frame.GetYaxis().SetTitle( "95% CL limits on #sigma(pp#rightarrow H#rightarrow Za#rightarrow 2l + 2#gamma)(fb)" ) frame.SetMinimum(0.1) # need Minimum > 0 for log scale frame.SetMaximum(8 * 1e4) # CMS HH frame.GetXaxis().SetLimits(0, 32) yellow.SetFillColor(ROOT.kOrange) yellow.SetLineColor(ROOT.kOrange) yellow.SetFillStyle(1001) yellow.Draw('F') green.SetFillColor(ROOT.kGreen + 1) green.SetLineColor(ROOT.kGreen + 1) green.SetFillStyle(1001) green.Draw('Fsame') median.SetLineColor(1) median.SetLineWidth(2) median.SetLineStyle(2) median.Draw('Lsame') CMS_lumi.CMS_lumi(c, 4, 11) ROOT.gPad.SetTicks(1, 1) frame.Draw('sameaxis') # yboost = 0.075 yboost = -0.2 x1 = 0.15 x2 = x1 + 0.24 y2 = 0.88 + yboost y1 = 0.80 + yboost legend = TLegend(x1, y1, x2, y2) legend.SetFillStyle(0) legend.SetBorderSize(0) legend.SetTextSize(0.035) legend.SetTextFont(42) legend.AddEntry(median, "AsymptoticLimits CL_{s} expected", 'L') legend.AddEntry(green, "#pm 1 std. deviation", 'f') # legend.AddEntry(green, "AsymptoticLimits CL_{s} #pm 1 std. deviation",'f') legend.AddEntry(yellow, "#pm 2 std. deviation", 'f') # legend.AddEntry("","STAT Only","") # legend.AddEntry(green, "AsymptoticLimits CL_{s} #pm 2 std. deviation",'f') legend.Draw() label = TLatex() label.SetNDC() label.SetTextAngle(0) label.SetTextColor(kBlack) label.SetTextFont(42) label.SetTextSize(0.045) label.SetLineWidth(2) label.DrawLatex(0.7, 0.7 + yboost, "STAT only") print " " # c.SaveAs("UpperLimit.png") outFile = "ALP_" if args.SM_Radion: outFile += "SM_" c.SaveAs(outFile + name + "_UpperLimit.pdf") c.SaveAs(outFile + name + "_UpperLimit.C") c.Close()