Example #1
0
def kinematicDistributions(region):
	ROOT.gROOT.SetBatch()
	for var in samples[0].regions[0].mm.histos['nom'].keys():
		print 'at variable:', var
		for t in ['tt', 'tl', 'll']:
			print 'at type:', t
			for sys in ['nom', 'jesup', 'jesdn', 'jer', 'bup', 'bdn']:
				print 'at systematic:', sys
				legend = lib.makeLegend(0.6, 0.6, 0.8, 0.87)
				legend.SetTextSize(0.04)
				mcstack = ROOT.THStack('mcstack', 'mcstack')
				mcint = 0.
				for sample in samples:
					if  incQCD == False:
						if 'qcd' in sample.name: continue
					if sample == totals or sample.isdata: continue
					#
					reg = SRs.index(region)
					print sample.name
					sample.regions[reg].mm.histos[sys][var][t].SetFillColor(sample.color)
					mcint += sample.regions[reg].mm.histos[sys][var][t].Integral()
					mcstack.Add(sample.regions[reg].mm.histos[sys][var][t])
					legend.AddEntry(sample.regions[reg].mm.histos[sys][var][t], sample.name, 'f')

				legend.AddEntry(doublemu.regions[reg].mm.histos[sys][var][t], doublemu.name, 'pe')
				func = helper.canvasWithRatio(mcstack, doublemu.regions[reg].mm.histos[sys][var][t], legend)
				c = func[0] #don't ask me why this is necessary
				print c.ls()
				c.Update()
				c.FindObject('ratio').GetXaxis().SetTitle(helper.getLatexVariable(var))
				c.FindObject('mcstack').SetTitle(helper.getLatexType(t))
				c.Draw()
				helper.saveAll(c, 'figs/'+var+'_'+doublemu.regions[reg].name+'_'+sys+'_'+t)
	return
Example #2
0
def isoplots(region):
	ROOT.gROOT.SetBatch()
	reg = SRs.index(region)
	for key in samples[0].regions[reg].histos.keys():
		if not key in ['muiso', 'muisoT', 'muisoL', 'muisoTL', 'muisoTLT', 'muisoTLL', 'muip', 'muipTL',  
		               'eliso', 'elisoT', 'elisoL', 'elisoTL', 'elisoTLT', 'elisoTLL', 'elip', 'elipTL' ]: continue
		if 'mu' in key:
			mulegend = lib.makeLegend(0.4, 0.6, 0.6, 0.87)
			mulegend.SetTextSize(0.04)
			mumcstack = ROOT.THStack('mumcstack', 'mumcstack')
			mumcint = 0.
		if 'el' in key:
			ellegend = lib.makeLegend(0.6, 0.6, 0.8, 0.8)
			ellegend.SetTextSize(0.04)
			elmcstack = ROOT.THStack('elmcstack', 'elmcstack')
			elmcint = 0.
		for sample in samples:
			if sample == totals or sample.isdata: continue
			#muons 
			if 'mu' in key:
				sample.regions[reg].histos[key].SetFillColor(sample.color)
				mumcint += sample.regions[reg].histos[key].Integral()
				mumcstack.Add(sample.regions[reg].histos[key])
				mulegend.AddEntry(sample.regions[reg].histos[key], sample.name, 'f')
			#electrons 
			if 'el' in key:
				sample.regions[reg].histos[key].SetFillColor(sample.color)
				elmcint += sample.regions[reg].histos[key].Integral()
				elmcstack.Add(sample.regions[reg].histos[key])
				ellegend.AddEntry(sample.regions[reg].histos[key], sample.name, 'f')
		
		if 'mu' in key:
			mulegend.AddEntry(doublemu.regions[reg].histos[key], doublemu.name, 'pe')
			mufunc = helper.canvasWithRatio(mumcstack, doublemu.regions[reg].histos[key], mulegend)
			cmu = mufunc[0] #don't ask me why this is necessary
			cmu.Update()
			cmu.Draw()
			helper.saveAll(cmu, 'figs/'+key+'_sideband_'+samples[0].regions[reg].name)
	 
		if 'el' in key:
			ellegend.AddEntry(doubleel.regions[reg].histos[key], doubleel.name, 'pe')
			elfunc = helper.canvasWithRatio(elmcstack, doubleel.regions[reg].histos[key], ellegend)
			cel = elfunc[0] #don't ask me why this is necessary
			cel.Update()
			cel.Draw()
			helper.saveAll(cel, 'figs/'+key+'_sideband_'+samples[0].regions[reg].name)
	return
Example #3
0
	wjets.Rescale(scalefactors[0][1])
	dyjets50.Rescale(scalefactors[0][1])
	dyjets10.Rescale(scalefactors[0][1])
	lower = scalefactors[1]
	upper = scalefactors[2]

if module == 'plots_1d' or module == 'all':
	helper.PrintScale(canv, outputDir, [qcd_samples[0], wjets, dyjets50, dyjets10], lower, upper)




# produce 1d Plots

if module == 'plots_1d' or module == 'all':
	leg = helper.makeLegend(0.6, 0.5, 0.85, 0.85)
	leg.AddEntry(data_samples[0].hists[0], helper.getLegendName(data_samples[0].GetName()), 'pe')
	leg.AddEntry(wjets          .hists[0], helper.getLegendName(wjets          .GetName()), 'f' )
	leg.AddEntry(dyjets10       .hists[0], helper.getLegendName(dyjets10       .GetName()), 'f' )
	leg.AddEntry(qcd_samples[0] .hists[0], helper.getLegendName(qcd_samples[0] .GetName()), 'f' )
	if dataType == 'el': leg.AddEntry(qcdbc20.hists[0], helper.getLegendName(qcdbc20.GetName()), 'f')
	Plot.Plot1d(dataType, outputDir, data_samples, mc_samples, plot1dHists, leg, True)



# produce 2d Plots

if module == 'plots_2d' or module == 'all':
	Plot.Plot2d(dataType, outputDir, data_samples, mc_samples, plot2dHists)

Example #4
0
def make1dFRPlot(dataType, canv, pad_plot, pad_ratio, outputDir, hists, title_hist, file_name, usemarkers = False, ratio_title = '', ratio_max = 1.99, ratio_min = 0.0):
	#
	# produces all 1d fake rate plots (this function, among others, wants to be improved)
	# NOTE: when calling this function make sure that the first histogram in hists is the total data, and the second is the total bg (important for ratio)
	#
	# this function takes the following paramters:
	# dataType..........type of the lepton ('mu', 'el')
	# canv..............canvas to be plotted
	# pad_plot..........pad of the plot to be plotted
	# pad_ratio.........pad of the ratio to be plotted
	# outputDir.........basic output directory
	# hists.............list of histograms to be plotted to be plotted on top of each other
	# title_hist........histogram to get the X axis title from
	# file_name.........name of the output file
	# usemarkers........True if we want to plot both data and mc with markers (e.g. comparing different ewk subtraction methods), False then mc is plotted as a colored rectangle
	# ratio_title.......Y axis title of the ratio plot
	# ratio_max.........maximum Y range of the ratio plot
	# ratio_min.........minimum Y range of the ratio plot


	# define pads, draw options (we use markers for mc if 

	pad_plot.cd()
	
	if usemarkers:
		markersize_mc = 1.4
		drawoption_data = "p e1"
		drawoption_mc = "p e1 same"
		legendoption_mc = "pe"
	else:
		markersize_mc = 0
		drawoption_data = "p e1 x0"
		drawoption_mc = "e2 same"
		legendoption_mc = "f"

	# draw histograms

	hists[0][0].Draw(drawoption_data)
	hists[0][0].SetMarkerSize(1.4)
	for i in range(1,len(hists)):
		hists[i][0].SetMarkerSize(markersize_mc)
		hists[i][0].Draw(drawoption_mc)
	hists[0][0].Draw(drawoption_data + " same")

	# set plot style
	
	for i in range(len(hists)):
		hists[i][0] = helper.setFRPlotStyle(dataType, hists[i][0], helper.getColor(hists[i][1]))
		if i+1 == len(hists): 
			hists[i][0] = helper.setFRPlotStyle(dataType, hists[i][0], helper.getColor(hists[i][1]), 'FR as function of ' + helper.getXTitle(dataType, title_hist), title_hist)

	# define legend, fill and draw it

	leg1 = helper.makeLegend(0.22, 0.4, 0.47, 0.65)
	#if dataType == 'el': leg1 = helper.makeLegend(0.62, 0.08, 0.87, 0.33)
	#else               : leg1 = helper.makeLegend(0.22, 0.6, 0.47, 0.85)

	leg1.AddEntry(hists[0][0], helper.getLegendName(hists[0][1]), 'pe')
	for i in range(1,len(hists)):
		leg1.AddEntry(hists[i][0], helper.getLegendName(hists[i][1]), legendoption_mc)

	leg1.Draw()


	# create RATIO PLOT

	pad_ratio.cd()
	data_bg_ratio = copy.deepcopy(hists[0][0])
	data_bg_ratio.Divide(hists[1][0])
	data_bg_ratio.Draw("p e")
	data_bg_ratio = helper.setRatioStyle(dataType, data_bg_ratio, title_hist, ratio_title, ratio_max, ratio_min)
	line = helper.makeLine(data_bg_ratio.GetXaxis().GetXmin(), 1.00, data_bg_ratio.GetXaxis().GetXmax(), 1.00)
	line.Draw()

	# produce plot
	
	helper.saveCanvas(canv, pad_plot, outputDir + "fakerates_1d/", file_name)