Beispiel #1
0
def print_METCR_info(sample):
	'''
	Takes a sample, and prints a table w/ the # of events passing each cut
	'''

	h_cosmic_CR = get1DHisto(f,sample+"_METCosmicCR_cutflow_wght")
	h_fake_CR   = get1DHisto(f,sample+"_METFakeCR_cutflow_wght")
	h_heavy_CR  = get1DHisto(f,sample+"_METHeavyCR_cutflow_wght")
	h_muon_VR   = get1DHisto(f,sample+"_METVR_cutflow_wght")

	
	text_file = open("Plots/Cutflows/CRMET_"+sample+".txt", "w")

	# cut strings
	cut_strings = ["No DVs", "Mat 3 Track", "2 Track DVs", "3 Track LM", "3 Track HV"]

	# want the last five bins???
	text_file.write( "Selection: Cosmic  Fake  HeavyFlavor  Nominal \n" )
	for i, cut_string in enumerate(cut_strings):

		nbins = h_cosmic_CR.GetNbinsX()
		bin = nbins-4+i
		#print (bin, cut_string)
		n_cosmic  = h_cosmic_CR.GetBinContent(bin)
		n_fake    = h_fake_CR  .GetBinContent(bin)
		n_heavy   = h_heavy_CR .GetBinContent(bin)
		n_nominal = h_muon_VR  .GetBinContent(bin)


		text_file.write( "%s: 	%0.1f 	%0.1f 	%0.1f 	%0.1f \n"%(cut_string, n_cosmic, n_fake, n_heavy, n_nominal) )

	text_file.close()

	return 
def compare1D(dist1, dist2):

    hist1 = get1DHisto(f, dist1)
    hist2 = get1DHisto(f, dist2)

    # setup canvas
    canvas = ROOT.TCanvas("", "", 800, 900)
    canvas.Draw()
    canvas.cd()

    if "ntrks" not in dist1 or "Stop" not in dist1:
        hist1.Rebin(2)
        hist2.Rebin(2)

    # draw histos
    logy = 0
    if "d0" in dist1:
        logy = 1

    maximum = max(hist1.GetMaximum(), hist2.GetMaximum())
    hist1.SetMaximum(1.45 * maximum)
    hist1.SetMinimum(0.)
    if logy:
        hist1.SetMaximum(15 * maximum)
        hist1.SetMinimum(0.1)

    clean1D(hist1)
    clean1D(hist2)

    hist1.SetLineWidth(3)
    hist2.SetLineWidth(3)
    hist1.SetLineColor(ROOT.kRed + 1)
    hist2.SetLineColor(ROOT.kAzure + 1)
    hist1.SetMarkerColor(ROOT.kRed + 1)
    hist2.SetMarkerColor(ROOT.kAzure + 1)

    hist1.Draw("hist")
    hist2.Draw("hist same")

    legend = ROOT.TLegend(0.17, 0.82, 0.84, 0.90)
    legend.SetBorderSize(0)
    legend.SetFillColor(0)
    legend.SetTextSize(0.035)
    legend.AddEntry(hist1, getlabel(hist1), "l")
    legend.AddEntry(hist2, getlabel(hist2), "l")
    legend.Draw()

    canvas.SetLogy(logy)
    canvas.Print("Plots/Compare/" + dist1 + ".png")
    canvas.Close()
    canvas.SetLogy(0)
    return
Beispiel #3
0
def print_SRMU_efficiency(sample):
	'''
	Takes a sample, and prints a table w/ the # of events passing each cut
	As well as the overall efficiency & relative efficiency of each cut
	'''

	h_sample = get1DHisto(f,sample+"_MuonSR_cutflow_wght")
	text_file = open("Plots/Cutflows/SRMU_"+sample+".txt", "w")


	for bin in range(1,h_sample.GetXaxis().GetNbins()+1):

		nevts = h_sample.GetBinContent(bin)

		if nevts == 0: rel_eff = 0
		elif bin == 1: rel_eff = nevts/nevts
		else         : rel_eff = nevts/h_sample.GetBinContent(bin-1)

		tot_eff = nevts/h_sample.GetBinContent(1)

		text_file.write( "%s: 	%0.1f 	%0.2f 	%0.2f \n"%(MUcutString(bin), nevts, rel_eff, tot_eff) )

	text_file.close()

	return 
Beispiel #4
0
def compare1D(dist1, dist2, dist3, dist4):

	#print("")
	#print(dist1)
	#print(dist2)
	#print(dist3)
	#print(dist4)

	hist1 = get1DHisto(f,dist1)
	hist2 = get1DHisto(f,dist2)
	hist3 = get1DHisto(f,dist3)
	hist4 = get1DHisto(f,dist4)

	# setup canvas	
	canvas = ROOT.TCanvas("", "", 800, 900)
	canvas.Draw()
	canvas.cd()

	if rebin(hist1): 
		hist1.Rebin(2)
		hist2.Rebin(2)
		hist3.Rebin(2)
		hist4.Rebin(2)

	#scaling for now
	hist1.Scale(1.0/hist1.Integral(0,-1))
	hist2.Scale(1.0/hist2.Integral(0,-1))
	hist3.Scale(1.0/hist3.Integral(0,-1))
	hist4.Scale(1.0/hist4.Integral(0,-1))

	# draw histos 
	logy = get_logy(hist1)
	
	maximum = max(hist1.GetMaximum(),hist2.GetMaximum(),hist3.GetMaximum(),hist4.GetMaximum())
	hist1.SetMaximum(1.5*maximum)
	hist1.SetMinimum(0.)
	if logy : # since scaling
		hist1.SetMaximum(100)
		hist1.SetMinimum(0.001)
	
	clean1D(hist1, ROOT.kBlue+1)
	clean1D(hist2, ROOT.kViolet+1) 
	clean1D(hist3, ROOT.kRed+1) 
	clean1D(hist4, ROOT.kOrange+1) 

	hist1.Draw("hist")
	hist2.Draw("hist same")
	hist3.Draw("hist same")
	hist4.Draw("hist same")

	legend = ROOT.TLegend(0.17, 0.72, 0.84, 0.90)
	legend.SetBorderSize(0)
	legend.SetFillColor(0)
	legend.SetTextSize(0.035)
	legend.AddEntry(hist1  ,getlabel(hist1),"l") 
	legend.AddEntry(hist2  ,getlabel(hist2),"l")   
	legend.AddEntry(hist3  ,getlabel(hist3),"l")   
	legend.AddEntry(hist4  ,getlabel(hist4),"l")   
	legend.Draw()

	canvas.SetLogy(logy)
	canvas.Print("Plots/Tracks/"+dist1+".png")
	canvas.Close()
	canvas.SetLogy(0)
	return
Beispiel #5
0
def plot_SR_efficiency():
	'''
	makes a 2D plot of MET efficiency as a function of mass and lifetime
	'''

	canvas = ROOT.TCanvas("c1", "c1", 800, 800)
	canvas.SetTopMargin(0.05)
	canvas.SetBottomMargin(0.13)
	canvas.SetLeftMargin(0.17)
	canvas.SetRightMargin(0.2)

	# old
	#mstops = ["1600", "1400", "1200", "1000", "800"]
	#taus   = ["0p01", "0p1", "1", "10"]
	# june 2018 samples
	mstops = ["1100", "1400", "1700"]
	taus = ["0p1", "1"]

	xbins = [0.05, 0.5, 5]
	nxbins = len(xbins)-1
	ybins = [950,1250,1550,1850]
	nybins = len(ybins)-1

	h_SRMET_eff = ROOT.TH2F("h_SRMET_eff",";#tau [ns];m_{#tilde{t}} [GeV];Signal Effiency",nxbins,array('d',xbins),nybins,array('d',ybins))
	h_SRMET_evt = ROOT.TH2F("h_SRMET_evt",";#tau [ns];m_{#tilde{t}} [GeV];Signal Events"  ,nxbins,array('d',xbins),nybins,array('d',ybins))

	h_SRMU_eff = ROOT.TH2F("h_SRMU_eff",";#tau [ns];m_{#tilde{t}} [GeV];Signal Effiency",nxbins,array('d',xbins),nybins,array('d',ybins))
	h_SRMU_evt = ROOT.TH2F("h_SRMU_evt",";#tau [ns];m_{#tilde{t}} [GeV];Signal Events"  ,nxbins,array('d',xbins),nybins,array('d',ybins))


	for mstop in mstops:
		for tau in taus:

			sample = "Stop_"+mstop+"_"+tau+"ns"
			h_met_sample = get1DHisto(f,sample+"_METSR_cutflow_wght")

			# last bin requires muon - link 
			# 2nd to last bin doesn't require link
			met_num = 0
			met_den = 1
			if (h_met_sample!=-1):
				met_num = h_met_sample.GetBinContent(h_met_sample.GetXaxis().GetNbins()-1)
				met_den = h_met_sample.GetBinContent(1)

			h_SRMET_evt.Fill(lifetime(tau),mass(mstop),met_num)
			h_SRMET_eff.Fill(lifetime(tau),mass(mstop),met_num/met_den)

			#print num,den,eff

			h_mu_sample = get1DHisto(f,sample+"_MuonSR_cutflow_wght")

			mu_num = 0
			mu_den = 1
			if (h_mu_sample!=-1):
				mu_num = h_mu_sample.GetBinContent(h_mu_sample.GetXaxis().GetNbins()-1)
				mu_den = h_mu_sample.GetBinContent(1)
	 
			h_SRMU_evt.Fill(lifetime(tau),mass(mstop),mu_num)
			h_SRMU_eff.Fill(lifetime(tau),mass(mstop),mu_num/mu_den)




	# Now print histos
	canvas.SetLogx(1)
	canvas.SetLogz(1)
	h_SRMET_evt.GetXaxis().SetTitleOffset(1.3)
	h_SRMET_evt.GetYaxis().SetTitleOffset(1.6)
	h_SRMET_evt.GetZaxis().SetTitleOffset(1.4)
	h_SRMET_evt.Draw("COLZ")
	h_SRMET_evt.Draw("TEXT same")
	canvas.Print("Plots/Cutflows/2D_SRMET_Events.png")

	canvas.SetLogz(0)
	h_SRMET_eff.GetXaxis().SetTitleOffset(1.3)
	h_SRMET_eff.GetYaxis().SetTitleOffset(1.6)
	h_SRMET_eff.GetZaxis().SetTitleOffset(1.5)
	h_SRMET_eff.Draw("COLZ")
	h_SRMET_eff.Draw("TEXT same")
	canvas.Print("Plots/Cutflows/2D_SRMET_Efficiency.png")
	canvas.SetLogx(0)


	canvas.SetLogx(1)
	canvas.SetLogz(1)
	h_SRMU_evt.GetXaxis().SetTitleOffset(1.3)
	h_SRMU_evt.GetYaxis().SetTitleOffset(1.6)
	h_SRMU_evt.GetZaxis().SetTitleOffset(1.4)
	h_SRMU_evt.Draw("COLZ")
	h_SRMU_evt.Draw("TEXT same")
	canvas.Print("Plots/Cutflows/2D_SRMU_Events.png")

	canvas.SetLogz(0)
	h_SRMU_eff.GetXaxis().SetTitleOffset(1.3)
	h_SRMU_eff.GetYaxis().SetTitleOffset(1.6)
	h_SRMU_eff.GetZaxis().SetTitleOffset(1.5)
	h_SRMU_eff.Draw("COLZ")
	h_SRMU_eff.Draw("TEXT same")
	canvas.Print("Plots/Cutflows/2D_SRMU_Efficiency.png")
	canvas.SetLogx(0)


	return 
def efficiency(numerator_name, denominator_name, label1="", label2=""):

    numerator = get1DHisto(f, numerator_name)
    denominator = get1DHisto(f, denominator_name)

    # setup canvas
    canvas = ROOT.TCanvas("", "", 800, 900)
    canvas.Draw()

    # Upper plot will be in pad1
    pad1 = ROOT.TPad("pad1", "pad1", 0, 0.35, 1, 1.0)
    pad1.SetBottomMargin(0.02)
    # Upper and lower plot are joined
    pad1.SetTicks()
    # Ticks
    pad1.Draw()
    # Draw the upper pad: pad1
    pad1.cd()
    # pad1 becomes the current pad
    pad1.SetLogy(get_logy(numerator))

    # lower plot will be in pad
    canvas.cd()
    # Go back to the main canvas before defining pad2
    pad2 = ROOT.TPad("pad2", "pad2", 0, 0.05, 1, 0.35)
    pad2.SetTopMargin(0.02)
    pad2.SetBottomMargin(0.2)
    pad2.SetTicks()  # Ticks
    pad2.Draw()
    pad2.cd()
    #pad2.SetLogy(logy)

    # Draw top half
    pad1.cd()
    clean1D(numerator)
    clean1D(denominator)
    if "eta" in numerator_name:
        numerator.GetXaxis().SetRangeUser(-2.5, 2.5)
        denominator.GetXaxis().SetRangeUser(-2.5, 2.5)
    if rebin_eff(numerator):
        numerator.Rebin(rebin_eff(numerator))
        denominator.Rebin(rebin_eff(denominator))

    numerator.SetLineWidth(3)
    denominator.SetLineWidth(3)
    #numerator  .SetFillStyle(1)
    #denominator.SetFillStyle(1)
    #numerator  .SetFillColor(ROOT.kBlack)
    #denominator.SetFillColor(ROOT.kAzure+1)
    numerator.SetLineColor(ROOT.kAzure + 1)
    denominator.SetLineColor(ROOT.kRed + 1)

    maxim = max(denominator.GetMaximum(), numerator.GetMaximum())
    denominator.SetMaximum(1.4 * maxim)
    if get_logy(denominator):
        denominator.SetMaximum(50 * maxim)

    denominator.GetXaxis().SetLabelSize(0)
    denominator.Draw("hist")
    numerator.Draw("hist same")

    y = 0.75
    legend = ROOT.TLegend(0.2, y, 0.93, 0.91)
    legend.SetBorderSize(0)
    legend.SetFillColor(0)
    legend.SetTextSize(0.05)
    legend.AddEntry(numerator, label1, "l")
    legend.AddEntry(denominator, label2, "l")
    legend.Draw()

    # Draw bottom half
    pad2.cd()  #pad2 becomes the current pad

    # scale and draw
    signal_eff = numerator.Clone()
    signal_eff.Divide(numerator, denominator, 1, 1, "B")
    signal_eff.GetYaxis().SetRangeUser(0, 1.1)
    ratio(signal_eff)

    signal_eff.Draw()

    #text =  ROOT.TLatex(0.11,0.92,getlabel(hist));
    #text.SetNDC();
    #text.SetTextFont(43);
    #text.SetTextSize(35);
    #text.Draw();

    canvas.Print("Plots/SigEff/" + numerator_name + ".png")

    canvas.SetLogz(0)
    canvas.Close()

    return
Beispiel #7
0
def comparison(dist, scale=0):

    # 1 - 1100 0.1 ns
    # 2 - 1400 0.1 ns
    # 3 - 1400 1 ns
    hist1 = get1DHisto(f, "RHad_1300_0p01ns_" + dist)
    hist2 = get1DHisto(f, "RHad_1100_0p1ns_" + dist)
    hist3 = get1DHisto(f, "RHad_1100_1ns_" + dist)
    #hist4 = get1DHisto(f,"Stop_1400_1ns_"+dist)

    # setup canvas
    canvas = ROOT.TCanvas("", "", 800, 900)
    canvas.Draw()
    canvas.cd()

    if (rebin(dist)):
        hist1.Rebin(rebin(dist))
        hist2.Rebin(rebin(dist))
        hist3.Rebin(rebin(dist))
        #hist4.Rebin(rebin(dist))

    if scale:
        hist1.Scale(1.0 / hist1.Integral(0, -1))
        hist2.Scale(1.0 / hist2.Integral(0, -1))
        hist3.Scale(1.0 / hist3.Integral(0, -1))
        #hist4.Scale(1.0/hist4.Integral(0,-1))

    # draw histos
    maximum = max(hist1.GetMaximum(), hist2.GetMaximum(), hist3.GetMaximum())
    #maximum = max(hist1.GetMaximum(),hist2.GetMaximum(),hist3.GetMaximum(),hist4.GetMaximum())
    if get_logy(dist):
        hist1.SetMaximum(100 * maximum)
        #if "Muon" in file_name: hist1.SetMinimum(0.01)
        #if "MET"  in file_name: hist2.SetMinimum(0.1)
    else:
        hist1.SetMaximum(1.45 * maximum)
        hist1.SetMinimum(0.)

    hist1 = signal(hist1)
    hist2 = signal(hist2)
    hist3 = signal(hist3)
    #hist4 = signal(hist4)

    #if "all_mu" in dist: hist1.GetYaxis().SetTitle("Muons [au]")
    #if "DVs_dv" in dist: hist1.GetYaxis().SetTitle("DVs")
    #if "PassPre_dv" in dist: hist1.GetYaxis().SetTitle("Preselected DVs [au]")
    #if "PassPreNtrkMass_dv" in dist: hist1.GetYaxis().SetTitle("Fully selected DVs [au]")
    #if "LHTMET" in dist: hist1.GetYaxis().SetTitle("events [au]")

    hist1.Draw("hist")
    hist2.Draw("hist same")
    hist3.Draw("hist same")
    #hist4.Draw("hist same")

    y = 0.71
    legend = ROOT.TLegend(0.20, y, 0.93, 0.91)
    legend.SetBorderSize(0)
    legend.SetFillColor(0)
    legend.SetTextSize(0.045)
    legend.AddEntry(hist1, signalLabel(hist1), "l")
    legend.AddEntry(hist2, signalLabel(hist2), "l")
    legend.AddEntry(hist3, signalLabel(hist3), "l")
    #legend.AddEntry(hist4  ,signalLabel(hist4),"l")
    legend.Draw()

    canvas.SetLogy(get_logy(dist))
    canvas.Print("Plots/SignalDists/Compare_" + dist + ".png")
    canvas.SetLogy(0)
    canvas.Close()

    return