Exemplo n.º 1
0
	def __init__(self, name, file):
		self.name = name
		self.file = ROOT.TFile(file)
		#self.tree = ROOT.TFile(file).Get('closureTree')
		self.tree = self.file.Get('closureTree')
		#self.mm = cat('MUON-MUON')
		#self.em = cat('MUON-ELECTRON')
		#self.ee = cat('ELECTRON-ELECTRON')
		#self.cats = [self.mm, self.em, self.ee]
		#self.histos = {}
		self.regions = []
		self.color = lib.getColor(name)
		self.loaded = False
		if name in ['doublemu', 'doubleel']:
			self.isdata = True
		else:
			self.isdata = False
Exemplo n.º 2
0
def make1dPlot_plot(dataType, pad_plot, hists, title_hist, leg):
	#
	# producing the plot without ratio plot
	#
	# this function takes the following parameters:
	# dataType....type of the lepton ('mu', 'el')
	# pad_plot....pad to be plotted
	# hists.......list of histograms to be plotted
	# title_hist..histogram where we take the axis labels from
	# leg.........legend to be drawn


	pad_plot.cd()

	# get maximum

	max = hists[0][0].GetMaximum()
	for i in range(1,len(hists)):
		if max < hists[i][0].GetStack().Last().GetMaximum():
			max = hists[i][0].GetStack().Last().GetMaximum()

	# set standard plot stype

	hists[0][0] = helper.set1dPlotStyle(dataType, hists[0][0], helper.getColor(hists[0][1]), '', title_hist)

	# draw and set maximum

	hists[0][0].Draw("p x0 e")
	hists[0][0].SetMinimum(0.001)
	hists[0][0].SetMaximum(1.5*max)
	for i in range(1,len(hists)):
		hists[i][0].Draw("hist same")
		hists[i][0].SetMinimum(0.001)
		hists[i][0].SetMaximum(1.5*max)
	
	hists[0][0].Draw("p x0 e same")

	# draw legend

	leg.Draw()
Exemplo n.º 3
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)
Exemplo n.º 4
0
def PlotCompare(dataType, outputDir, mcsets, histname, leg, cutoff = -1, precise = False):
	#
	# plot a set of histograms defined by histname and comparing mc samples
	# NOTE: ALL SAMPLES MUST CONTAIN THE EXACT SAME LIST OF HISTOGRAMS, OTHERWISE THIS FUNCTION WILL NOT WORK
	#
	# this function takes the following parameters:
	# dataType....type of the lepton ('mu', 'el')
	# outputDir...basic output directory
	# mcsets......list of mc samples [mcsample1, mcsample2, ..]
	# leg.........legend to be plotted
	# cutoff......cutoff for the histogram name (see function getSaveName() in lib.py)
	# precise.....True if only the histogram with the name matching histname exactly shall be plotted

	# define canvas and pads

	canv = helper.makeCanvas(900, 675)
	pad_plot = helper.makePad('plot')
	pad_ratio = helper.makePad('ratio')
	pad_ratio.cd()

	# iterate over all histograms in root files
	# it does not matter which sample we iterate on, as all samples contain the same list of histograms

	for hist in mcsets[0].hists:

		# get index of histogram

		i = mcsets[0].hists.index(hist)
		pad_plot.cd()

		# if precise is True, we only plot the histogram with the name matching histname exactly
		# else, we plot all histograms which have histname in their name (useful for several versions or bins of a histogram)

		if precise     and not histname == hist.GetName(): continue
		if not precise and not histname in hist.GetName(): continue

		# pre- and postpends

		prepend = ''
		postpend = '_compare'
		if '_Loose_' in hist.GetName(): prepend = 'Loose_'
		if '_Tight_' in hist.GetName(): prepend = 'Tight_'

		# draw first histogram

		hist.Draw('hist')
		hist.SetFillStyle(0)
		hist.Scale(1.0/hist.Integral())
		max = hist.GetMaximum()

		for j in range(1,len(mcsets)):	
			mcsets[j].hists[i].Draw('hist same')
			mcsets[j].hists[i].SetFillStyle(0)
			mcsets[j].hists[i].SetLineStyle(2)
			mcsets[j].hists[i].Scale(1.0/mcsets[j].hists[i].Integral())
			if max < mcsets[j].hists[i].GetMaximum(): max = mcsets[j].hists[i].GetMaximum()

		# do some cosmetics

		hist.SetMinimum(0.0001)
		hist.SetMaximum(1.5 * max)
		hist = helper.set1dPlotStyle(dataType, hist, helper.getColor(mcsets[0].GetName()), '', hist, '1/Integral')

		# draw legend

		leg.Draw()

		# draw ratio plot

		pad_ratio.cd()
		hist_ratio = copy.deepcopy(hist)
		hist_ratio.Divide(copy.deepcopy(mcsets[1].hists[i]))
		hist_ratio.Draw("p e1")
		hist_ratio = helper.setRatioStyle(dataType, hist_ratio, hist)
		line = helper.makeLine(hist_ratio.GetXaxis().GetXmin(), 1.00, hist_ratio.GetXaxis().GetXmax(), 1.00)
		line.Draw()

		# make plot

		helper.saveCanvas(canv, pad_plot, outputDir + "compare/", prepend + helper.getSaveName(hist, cutoff) + postpend)