Ejemplo n.º 1
0
	leg.AddEntry(g[3],'Expected \\pm 2\\sigma','F')
	leg.Draw('same')
	leg2.Draw('same')
	cmsStamp(lumi=18510,coords=(0.5,0.87),preliminary=False)
	name=str(MH)+'_'+str(MX)+option
	os.chdir(plotDir)
	c.SaveAs(name+'.eps')
	os.system('epstopdf '+name+'.eps')
	os.system('rm '+name+'.eps')
	os.chdir('../../')

option=sys.argv[3]
limDir=sys.argv[1]+'/limits'+option+'/'
files = [f for f in os.listdir(limDir)]
plotDir=sys.argv[1]+'/plots/'
setupTdrStyle()

CTAUS={(1500,500):17.3,(1000,150):5.9,(350,150):17.8, \
	  (700,150):8.1, (700,500):27.9, (1000,500):22.7, (1500,150):4.5}
MH = [1500, 1000, 700, 350]
THS = [0.00067, 0.0144, 0.139, 9.97]
THERRS = [0.38, 0.24, 0.2, 0.16]
MX = [150, 500]

for i,H in enumerate(MH):
	TH=THS[i]
	THERR=THERRS[i]
	for X in MX:
		if X>H : continue
		print H,X
		CTAU = CTAUS[(H,X)]	
Ejemplo n.º 2
0
def plotABCDscan(analysis,org,plotter,n,blind=True,onlyB=False):

	setupTdrStyle()


	plotter.pdfFileName = plotter.pdfFileName.replace(analysis.name+'.pdf','Scans_'+analysis.name+'.pdf')
	plotter.canvas.Clear()
	plotter.printCanvas("[")
	text1 = plotter.printTimeStamp()
	plotter.flushPage()

	# get all the counts
	counts = [[0]*len(analysis.scan) for sample in org.samples]
	for step in org.steps : 
		for plotName in sorted(step.keys()) :
			if 'ABCDEFGHcounts' not in plotName: continue
			i = eval(plotName[:plotName.find('ABCDEFGH')])
			for j in range(len(org.samples)): counts[j][i] = getCounts(step[plotName][j])

	# pick points to scan
	scans=[]
	for cut in analysis.scanPrompt: scans.append((cut,cut,None))

	# constant names
	cutNames = ['(NPrompt1,PromptFrac1)','(NPrompt2,PromptFrac2)','DiscVtx']
	histNames = ['observed','FG/B','EG/C','DG/A','BE/A','CF/A','EF/D','BCD/A^{2}']

	# plot scans
	for scan in scans:
		plotter.canvas=r.TCanvas("c","c",600,600)
		plotter.canvas.Divide(1,2)
		plotter.canvas.cd(1).SetPad(0.01,0.30+0.0,0.99,0.99)
		plotter.canvas.cd(1).SetTopMargin(0.07)
		plotter.canvas.cd(1).SetBottomMargin(0.)
		plotter.canvas.cd(2).SetPad(0.01,0.01,0.99,0.30)
		plotter.canvas.cd(2).SetTopMargin(0.)
		plotter.canvas.cd(2).SetBottomMargin(0.35)
		plotter.canvas.cd(1)
		r.gPad.SetLogy()
		#r.gPad.SetTicky(0)
	
		title=''
		#title='max Prompt Tracks = %s, max Prompt Energy Fraction = %s'%(scan[0][0],scan[0][1])
		xtitle = 'Vertex/cluster discriminant'
		ytitle = 'Number of events'

		indices = [i for i,cuts in enumerate(analysis.scan) if len(listdiff(cuts,scan))<=1]
		labels = [string(cuts[scan.index(None)]) for i,cuts in enumerate(analysis.scan) if i in indices]
		# first make a plot of signal efficiency
		sigSamples = [sample for sample in org.samples if 'H' in sample['name']]		
	 	sigeff = [r.TH1F('','',len(indices),0,1) for sample in sigSamples]
		for j,sample in enumerate(sigSamples):
			i = org.indexOfSampleWithName(sample['name'])
			norm = sample['xs']*org.lumi
			for k,idx in enumerate(indices):
				sigeff[j].SetBinContent(k+1,100*counts[i][idx][0][0]/float(2*norm))
				sigeff[j].SetBinError(k+1,100*counts[i][idx][0][1]/float(norm))
				sigeff[j].GetXaxis().SetBinLabel(k+1,labels[k])

		# Data/QCD plots with signal efficiency on the same plot
		for j,sample in enumerate(org.samples):
			if 'H' in sample['name'] : continue

			histos = [r.TH1F(name,title,len(indices),0,1) for name in histNames]
			histob = r.TH1F('predicted bkg.',title,len(indices),0,1)
			histob0 = r.TH1F('predicted bkg.',title,len(indices),0,1)
			histoz = r.TH1F('','',len(indices),0,1)

			for h in histos: h.GetXaxis().SetNdivisions(len(indices)*100+10,False)
			histoz.GetXaxis().SetNdivisions(len(indices)*100+10,False)

			for k,idx in enumerate(indices):
				b,berr = getBkg(counts[j][idx],None)
				histob.SetBinContent(k+1,b)
				histob.SetBinError(k+1,berr)
				histob0.SetBinContent(k+1,b)
				histob0.SetBinError(k+1,0.00001)
				N=int(counts[j][idx][0][0])
				if N==0: 
					histoz.SetBinContent(k+1,-1e5)
					continue
				p=pvalue(b,berr,N,1e4)
				z=r.RooStats.PValueToSignificance(p)
				histoz.SetBinContent(k+1,z)
				histoz.SetBinError(k+1,0.)

			if onlyB:
				legend = r.TLegend(0.5, 0.65, 0.93, 0.83)
			else:
				legend = r.TLegend(0.7, 0.55, 0.93, 0.93)
			for i in reversed(range(n)):
				if blind and 'Data' in sample['name'] and i==0: continue
				for k,idx in enumerate(indices):
					histos[i].SetBinContent(k+1,counts[j][idx][i][0])
					histos[i].SetBinError(k+1,counts[j][idx][i][1])
					histos[i].GetXaxis().SetBinLabel(k+1,labels[k])
					histoz.GetXaxis().SetBinLabel(k+1,labels[k])
					histob.GetXaxis().SetBinLabel(k+1,'')
					histob0.GetXaxis().SetBinLabel(k+1,'')
					
				histos[i].GetXaxis().SetTitle(xtitle)
				histos[i].GetYaxis().SetTitle(ytitle)
				histos[i].SetStats(False)
				histob.SetStats(False)
				histos[i].GetYaxis().SetTitleOffset(1.25)
				histos[i].GetYaxis().SetTitleSize(0.066)
				histos[i].GetYaxis().SetLabelSize(0.062)
				histoz.GetXaxis().SetTitle(xtitle)
				histoz.SetTitle('')
				histoz.SetStats(0)
				histoz.SetMarkerStyle(8)
				histob.SetMarkerSize(0)
				histob0.SetMarkerSize(0)
				histos[i].SetMarkerStyle(25 if i!=0 else 8)
				if i==(n-1):histos[i].SetMarkerStyle(21)
				histos[i].SetMarkerColor(i+1)
				histos[i].SetFillColor(0)
				histos[i].SetLabelSize(0.07)
				if onlyB: 
					if i==0:
						legend.AddEntry(histos[i],'Observed background')
				else:
					legend.AddEntry(histos[i],histNames[i])
				option='EX0' if i==(n-1) else 'EX0same'
				histos[i].Draw(option)
			if onlyB:
				legend.AddEntry(histob,'Predicted background')
				histob.SetFillColor(r.kBlue)
				histob0.SetFillColor(r.kWhite)
				histob.SetFillStyle(3001)
				histob0.SetLineWidth(3)
				histob.SetLineWidth(3)
				histob0.SetLineColor(r.kBlue)
				histob.SetLineColor(r.kBlue)
				histos[0].SetLineWidth(2)
				histos[0].Draw('EX0')
				histob.Draw("E2same")
				histob0.Draw("Lsame")
				histos[0].Draw('EX0same')
			histos_tmp=tuple([histos[i] for i in range(n)])
			plotter.setRanges(histos_tmp,*plotter.getExtremes(1,histos_tmp,[False]*n))
			
			if onlyB:
				cmsStamp(lumi=18500,coords=(0.71,0.84),preliminary=False)
				#cmsStamp(lumi=None,coords=(0.78,0.88))
			else:
				cmsStamp(lumi=org.lumi,coords=(0.45,0.88),simulation=True)
				#cmsStamp(lumi=None,coords=(0.45,0.85))
			
			pad = r.TPad("pad2","",0,0,1,1)
			pad.SetFillStyle(4000)
			pad.SetFrameFillStyle(0)
			pad.SetLogy(0)
			pad.Draw()
			pad.cd()
			for i,sample in enumerate(sigSamples):
				option='histY+' + ('same' if i>0 else '')
				sigeff[i].SetLineWidth(1)
				sigeff[i].SetStats(False)
				sigeff[i].SetLabelSize(0.06)
				sigeff[i].SetLineColor(i+2)
				sigeff[i].SetLineStyle(2)
				sigeff[i].GetYaxis().SetRangeUser(0,45)
				sigeff[i].GetYaxis().SetTitle('efficiency [%]')
				sigeff[i].Draw(option)
				legend.AddEntry(sigeff[i],sample['name'].split('.')[0])
			
			legend.SetFillColor(0)
			legend.SetBorderSize(0)
			legend.Draw("same")

			plotter.canvas.cd(2)
			r.gPad.SetGridy()
			histoz.GetYaxis().SetNdivisions(505,True)
			histoz.GetYaxis().SetTitleOffset(0.5)
			histoz.GetYaxis().SetTitleSize(0.16)
			histoz.GetXaxis().SetTitleOffset(1.0)
			histoz.GetXaxis().SetTitleSize(0.16)
			histoz.GetYaxis().SetLabelSize(0.14)
			histoz.GetYaxis().SetLabelOffset(0.015)
			histoz.GetYaxis().SetTickLength(1.3*histoz.GetYaxis().GetTickLength())
			histoz.GetXaxis().SetTickLength(2.*histoz.GetXaxis().GetTickLength())
			histoz.GetXaxis().SetLabelSize(0.19)
			histoz.GetXaxis().SetLabelOffset(0.02)
			histoz.GetYaxis().SetTitle('Significance ')
			#histoz.GetYaxis().CenterTitle()
			histoz.GetYaxis().SetRangeUser(-2.99,2.99)
			histoz.Draw('P')
			plotter.printCanvas()
			#plotter.canvas.Clear()

	plotter.printCanvas("]")
	print plotter.pdfFileName, "has been written."