ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makePlots.py
Revision: 1.34
Committed: Tue Apr 30 09:34:47 2013 UTC (12 years ago) by jbrinson
Content type: text/x-python
Branch: MAIN
CVS Tags: V02-01-00, V01-01-00, V01-00-00, V02-00-00, V00-01-00
Changes since 1.33: +4 -6 lines
Log Message:
Fixed bug in adding yields to legends

File Contents

# User Rev Content
1 lantonel 1.1 #!/usr/bin/env python
2     import sys
3     import os
4 ahart 1.6 import re
5 lantonel 1.31 from math import *
6 lantonel 1.1 from array import *
7 lantonel 1.3 from decimal import *
8 lantonel 1.17 from optparse import OptionParser
9 lantonel 1.2 from OSUT3Analysis.Configuration.configurationOptions import *
10 lantonel 1.7 from OSUT3Analysis.Configuration.processingUtilities import *
11 lantonel 1.1
12 lantonel 1.17 parser = OptionParser()
13 lantonel 1.7 parser = set_commandline_arguments(parser)
14 lantonel 1.17 (arguments, args) = parser.parse_args()
15 lantonel 1.1
16 lantonel 1.16 if arguments.localConfig:
17 lantonel 1.1 sys.path.append(os.getcwd())
18 lantonel 1.16 exec("from " + arguments.localConfig.rstrip('.py') + " import *")
19 lantonel 1.1
20 lantonel 1.15
21     outputFileName = "stacked_histograms.root"
22 lantonel 1.16 if arguments.outputFileName:
23     outputFileName = arguments.outputFileName
24 lantonel 1.15
25 lantonel 1.16 condor_dir = set_condor_output_dir(arguments)
26 lantonel 1.1
27    
28 lantonel 1.15
29 lantonel 1.25 #### deal with conflicting arguments
30 lantonel 1.16 if arguments.normalizeToData and arguments.normalizeToUnitArea:
31 lantonel 1.13 print "Conflicting normalizations requsted, will normalize to unit area"
32 lantonel 1.16 arguments.normalizeToData = False
33     if arguments.normalizeToData and arguments.noStack:
34 lantonel 1.14 print "You have asked to scale non-stacked backgrounds to data. This is a very strange request. Will normalize to unit area instead"
35 lantonel 1.16 arguments.normalizeToData = False
36     arguments.normalizeToUnitArea = True
37 lantonel 1.25 if arguments.makeRatioPlots and arguments.makeDiffPlots:
38     print "You have requested both ratio and difference plots. Will make just ratio plots instead"
39     arguments.makeRatioPlots = False
40 lantonel 1.13
41 lantonel 1.32 from ROOT import TFile, gROOT, gStyle, gDirectory, TStyle, THStack, TH1F, TCanvas, TString, TLegend, TLegendEntry, TArrow, THStack, TIter, TKey, TPaveLabel, gPad
42 lantonel 1.1
43     gROOT.SetBatch()
44     gStyle.SetOptStat(0)
45     gStyle.SetCanvasBorderMode(0)
46     gStyle.SetPadBorderMode(0)
47     gStyle.SetPadColor(0)
48     gStyle.SetCanvasColor(0)
49     gStyle.SetTextFont(42)
50 lantonel 1.3 gROOT.ForceStyle()
51 lantonel 1.15 outputFile = TFile(condor_dir + "/" + outputFileName, "RECREATE")
52 lantonel 1.1
53     channels = []
54     processed_datasets = []
55    
56     #### check which input datasets have valid output files
57     for sample in datasets:
58     fileName = condor_dir + "/" + sample + ".root"
59     if not os.path.exists(fileName):
60     continue
61     testFile = TFile(fileName)
62 lantonel 1.14 if testFile.IsZombie() or not testFile.GetNkeys():
63     continue
64     processed_datasets.append(sample)
65 lantonel 1.1
66     if len(processed_datasets) is 0:
67     sys.exit("No datasets have been processed")
68    
69     #### open first input file and re-make its directory structure in the output file
70     testFile = TFile(condor_dir + "/" + processed_datasets[0] + ".root")
71     testFile.cd()
72     for key in testFile.GetListOfKeys():
73     if (key.GetClassName() != "TDirectoryFile"):
74     continue
75     outputFile.cd()
76     outputFile.mkdir(key.GetName())
77     rootDirectory = key.GetName()
78    
79     testFile.cd(key.GetName())
80     for key2 in gDirectory.GetListOfKeys():
81     if (key2.GetClassName() != "TDirectoryFile"):
82     continue
83     outputFile.cd(key.GetName())
84     gDirectory.mkdir(key2.GetName())
85     channels.append(key2.GetName())
86    
87    
88 lantonel 1.31 ## weight = intLumi / 10000.0
89     ## for dataset in processed_datasets:
90     ## dataset_file = "%s/%s.root" % (condor_dir,dataset)
91     ## fin = TFile (dataset_file)
92     ## flags = fin.Get ("flags")
93     ## noWeights = flags and flags.GetBinContent (1)
94     ## fin.Close ()
95    
96     ## if types[dataset] != "data" and not noWeights:
97     ## os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", weight))
98     ## else:
99     ## os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", 1.0))
100 lantonel 1.1
101 lantonel 1.33
102 lantonel 1.1 for channel in channels: # loop over final states, which each have their own directory
103    
104     testFile.cd(rootDirectory+"/"+channel)
105 lantonel 1.3
106 lantonel 1.10 for key in gDirectory.GetListOfKeys(): # loop over histograms in the current directory
107     histogramName = key.GetName()
108 lantonel 1.1
109 lantonel 1.10 if re.match ('TH1', key.GetClassName()): # plot a 1-D histogram
110    
111     numBgMCSamples = 0
112     numDataSamples = 0
113     numSignalSamples = 0
114 lantonel 1.1
115 lantonel 1.10 Stack = THStack("stack",histogramName)
116 lantonel 1.1
117 lantonel 1.10 if(intLumi < 1000.):
118     LumiText = "L_{int} = " + str(intLumi) + " pb^{-1}"
119     else:
120     getcontext().prec = 2
121     LumiInFb = intLumi/1000.
122     LumiText = "L_{int} = " + str(LumiInFb) + " fb^{-1}"
123    
124     LumiLabel = TPaveLabel(0.1,0.8,0.34,0.9,LumiText,"NDC")
125     LumiLabel.SetBorderSize(0)
126     LumiLabel.SetFillColor(0)
127     LumiLabel.SetFillStyle(0)
128 lantonel 1.32
129     BgMCLegend = TLegend()
130     BgTitle = BgMCLegend.AddEntry(0, "Data & Bkgd. MC", "H")
131     BgTitle.SetTextAlign(21)
132     BgTitle.SetTextFont(62)
133 lantonel 1.10 BgMCLegend.SetBorderSize(0)
134     BgMCLegend.SetFillColor(0)
135     BgMCLegend.SetFillStyle(0)
136 lantonel 1.32 SignalMCLegend = TLegend()
137     SignalTitle = SignalMCLegend.AddEntry(0, "Signal MC", "H")
138     SignalTitle.SetTextAlign(21)
139     SignalTitle.SetTextFont(62)
140 lantonel 1.10 SignalMCLegend.SetBorderSize(0)
141     SignalMCLegend.SetFillColor(0)
142     SignalMCLegend.SetFillStyle(0)
143    
144     outputFile.cd(rootDirectory+"/"+channel)
145     Canvas = TCanvas(histogramName)
146     BgMCHistograms = []
147 lantonel 1.32 BgMCLegendEntries = []
148 lantonel 1.10 SignalMCHistograms = []
149 lantonel 1.32 SignalMCLegendEntries = []
150 lantonel 1.10 DataHistograms = []
151 lantonel 1.32 DataLegendEntries = []
152    
153 lantonel 1.10
154     backgroundIntegral = 0
155     dataIntegral = 0
156     scaleFactor = 1
157    
158     for sample in processed_datasets: # loop over different samples as listed in configurationOptions.py
159 ahart 1.28 dataset_file = "%s/%s.root" % (condor_dir,sample)
160 lantonel 1.10 inputFile = TFile(dataset_file)
161     Histogram = inputFile.Get(rootDirectory+"/"+channel+"/"+histogramName).Clone()
162     Histogram.SetDirectory(0)
163 lantonel 1.27 if arguments.rebinFactor:
164     RebinFactor = int(arguments.rebinFactor)
165     if Histogram.GetNbinsX() >= RebinFactor*10:
166     Histogram.Rebin(RebinFactor)
167 lantonel 1.10 inputFile.Close()
168     xAxisLabel = Histogram.GetXaxis().GetTitle()
169     histoTitle = Histogram.GetTitle()
170 wulsin 1.29
171 jbrinson 1.34 legLabel = labels[sample]
172 wulsin 1.29 if (arguments.printYields):
173     yieldHist = Histogram.Integral()
174     legLabel = legLabel + " (%.1f)" % yieldHist
175    
176 lantonel 1.10 if( types[sample] == "bgMC"):
177    
178     numBgMCSamples += 1
179 lantonel 1.32 backgroundIntegral += Histogram.Integral()
180 wulsin 1.29
181 lantonel 1.32 Histogram.SetLineStyle(1)
182 lantonel 1.16 if(arguments.noStack):
183 lantonel 1.14 Histogram.SetFillStyle(0)
184     Histogram.SetLineColor(colors[sample])
185     Histogram.SetLineWidth(2)
186     else:
187     Histogram.SetFillStyle(1001)
188     Histogram.SetFillColor(colors[sample])
189     Histogram.SetLineColor(1)
190     Histogram.SetLineWidth(1)
191 lantonel 1.31
192 jbrinson 1.34 BgMCLegendEntries.append(legLabel)
193 lantonel 1.10 BgMCHistograms.append(Histogram)
194 lantonel 1.31
195 lantonel 1.10
196     elif( types[sample] == "signalMC"):
197    
198     numSignalSamples += 1
199 lantonel 1.11
200 lantonel 1.10 Histogram.SetFillStyle(0)
201     Histogram.SetLineColor(colors[sample])
202     Histogram.SetLineStyle(1)
203     Histogram.SetLineWidth(2)
204 lantonel 1.16 if(arguments.normalizeToUnitArea and Histogram.Integral() > 0):
205 lantonel 1.11 Histogram.Scale(1./Histogram.Integral())
206 lantonel 1.32
207 jbrinson 1.34 SignalMCLegendEntries.append(legLabel)
208 lantonel 1.10 SignalMCHistograms.append(Histogram)
209    
210     elif( types[sample] == "data"):
211    
212     numDataSamples += 1
213 lantonel 1.32 dataIntegral += Histogram.Integral()
214    
215 lantonel 1.10 Histogram.SetFillStyle(0)
216     Histogram.SetLineColor(colors[sample])
217     Histogram.SetLineStyle(1)
218     Histogram.SetLineWidth(2)
219 lantonel 1.16 if(arguments.normalizeToUnitArea and Histogram.Integral() > 0):
220 lantonel 1.11 Histogram.Scale(1./Histogram.Integral())
221 lantonel 1.32
222 jbrinson 1.34 DataLegendEntries.append(legLabel)
223 lantonel 1.10 DataHistograms.append(Histogram)
224    
225     if dataIntegral > 0 and backgroundIntegral > 0:
226     scaleFactor = dataIntegral/backgroundIntegral
227     for bgMCHist in BgMCHistograms:
228 lantonel 1.16 if arguments.normalizeToData:
229 lantonel 1.10 bgMCHist.Scale(scaleFactor)
230 lantonel 1.16 if arguments.normalizeToUnitArea and not arguments.noStack and backgroundIntegral > 0:
231 lantonel 1.11 bgMCHist.Scale(1./backgroundIntegral)
232 lantonel 1.16 elif arguments.normalizeToUnitArea and arguments.noStack and bgMCHist.Integral() > 0:
233 lantonel 1.14 bgMCHist.Scale(1./bgMCHist.Integral())
234 lantonel 1.16 if not arguments.noStack:
235 lantonel 1.14 Stack.Add(bgMCHist)
236 lantonel 1.3
237 lantonel 1.14
238    
239 lantonel 1.15
240    
241 lantonel 1.32 ### formatting data histograms and adding to legend
242     counter = 0
243     for Histogram in DataHistograms:
244     BgMCLegend.AddEntry(Histogram,DataLegendEntries[counter],"LEP").SetTextFont (42)
245     counter = counter+1
246    
247 lantonel 1.31
248 lantonel 1.32 ### creating the histogram to represent the statistical errors on the stack
249 lantonel 1.33 if numBgMCSamples is not 0 and not arguments.noStack:
250 lantonel 1.31 ErrorHisto = BgMCHistograms[0].Clone("errors")
251     ErrorHisto.SetFillStyle(3001)
252     ErrorHisto.SetFillColor(13)
253     ErrorHisto.SetLineWidth(0)
254 lantonel 1.32 BgMCLegend.AddEntry(ErrorHisto,"Stat. Errors","F").SetTextFont (42)
255 lantonel 1.31 for Histogram in BgMCHistograms:
256     if Histogram is not BgMCHistograms[0]:
257     ErrorHisto.Add(Histogram)
258    
259 lantonel 1.32
260     ### formatting bgMC histograms and adding to legend
261     counter = numBgMCSamples-1
262     for Histogram in reversed(BgMCHistograms):
263     if(arguments.noStack):
264     BgMCLegend.AddEntry(Histogram,BgMCLegendEntries[counter],"L").SetTextFont (42)
265     else:
266     BgMCLegend.AddEntry(Histogram,BgMCLegendEntries[counter],"F").SetTextFont (42)
267     counter = counter-1
268    
269     ### formatting signalMC histograms and adding to legend
270     counter = 0
271     for Histogram in SignalMCHistograms:
272     SignalMCLegend.AddEntry(Histogram,SignalMCLegendEntries[counter],"L").SetTextFont (42)
273     counter = counter+1
274    
275    
276    
277 lantonel 1.33 ### finding the maximum value of anything going on the canvas, and know how to set the y-axis
278     finalMax = 0
279     if numBgMCSamples is not 0 and not arguments.noStack:
280     finalMax = ErrorHisto.GetMaximum() + ErrorHisto.GetBinError(ErrorHisto.GetMaximumBin())
281     else:
282     for bgMCHist in BgMCHistograms:
283     if(bgMCHist.GetMaximum() > finalMax):
284     finalMax = bgMCHist.GetMaximum()
285     for signalMCHist in SignalMCHistograms:
286     if(signalMCHist.GetMaximum() > finalMax):
287     finalMax = signalMCHist.GetMaximum()
288     for dataHist in DataHistograms:
289     if(dataHist.GetMaximum() > finalMax):
290     finalMax = dataHist.GetMaximum() + dataHist.GetBinError(dataHist.GetMaximumBin())
291     finalMax = 1.1*finalMax
292    
293    
294 lantonel 1.32 ### Drawing histograms to canvas
295    
296    
297 lantonel 1.10 outputFile.cd(rootDirectory+"/"+channel)
298 lantonel 1.3
299 lantonel 1.16 makeRatioPlots = arguments.makeRatioPlots
300 lantonel 1.25 makeDiffPlots = arguments.makeDiffPlots
301    
302 lantonel 1.15 if numBgMCSamples is 0 or numDataSamples is not 1:
303     makeRatioPlots = False
304 lantonel 1.25 makeDiffPlots = False
305     if makeRatioPlots or makeDiffPlots:
306 lantonel 1.15 Canvas.SetFillStyle(0)
307     Canvas.Divide(1,2)
308     Canvas.cd(1)
309     gPad.SetPad(0.01,0.25,0.99,0.99)
310     gPad.SetMargin(0.1,0.05,0.02,0.07)
311     gPad.SetFillStyle(0)
312     gPad.Update()
313     gPad.Draw()
314     Canvas.cd(2)
315     gPad.SetPad(0.01,0.01,0.99,0.25)
316 lantonel 1.25 #format: gPad.SetMargin(l,r,b,t)
317 lantonel 1.15 gPad.SetMargin(0.1,0.05,0.4,0.02)
318     gPad.SetFillStyle(0)
319     gPad.SetGridy(1)
320     gPad.Update()
321     gPad.Draw()
322    
323     Canvas.cd(1)
324    
325 lantonel 1.31 if numBgMCSamples is not 0:
326 ahart 1.28
327 lantonel 1.16 if not arguments.noStack:
328 lantonel 1.14 Stack.SetTitle(histoTitle)
329     Stack.Draw("HIST")
330     Stack.GetXaxis().SetTitle(xAxisLabel)
331 lantonel 1.33 Stack.SetMaximum(finalMax)
332 lantonel 1.20 Stack.SetMinimum(0.0001)
333 lantonel 1.25 if makeRatioPlots or makeDiffPlots:
334 lantonel 1.15 Stack.GetHistogram().GetXaxis().SetLabelSize(0)
335 lantonel 1.31 #draw shaded error bands
336 lantonel 1.32 ErrorHisto.Draw("A E2 SAME")
337 lantonel 1.31
338    
339 lantonel 1.14 else:
340     BgMCHistograms[0].SetTitle(histoTitle)
341     BgMCHistograms[0].Draw("HIST")
342     BgMCHistograms[0].GetXaxis().SetTitle(xAxisLabel)
343 lantonel 1.33 BgMCHistograms[0].SetMaximum(finalMax)
344 lantonel 1.20 BgMCHistograms[0].SetMinimum(0.0001)
345 lantonel 1.14 for bgMCHist in BgMCHistograms:
346 lantonel 1.32 bgMCHist.Draw("A HIST SAME")
347 lantonel 1.10 for signalMCHist in SignalMCHistograms:
348 lantonel 1.32 signalMCHist.Draw("A HIST SAME")
349 lantonel 1.10 for dataHist in DataHistograms:
350 lantonel 1.32 dataHist.Draw("A E SAME")
351 lantonel 1.10
352 lantonel 1.31 elif numSignalSamples is not 0:
353 lantonel 1.10 SignalMCHistograms[0].SetTitle(histoTitle)
354     SignalMCHistograms[0].Draw("HIST")
355     SignalMCHistograms[0].GetXaxis().SetTitle(xAxisLabel)
356 lantonel 1.33 SignalMCHistograms[0].SetMaximum(finalMax)
357 lantonel 1.20 SignalMCHistograms[0].SetMinimum(0.0001)
358 lantonel 1.10 for signalMCHist in SignalMCHistograms:
359     if(signalMCHist is not SignalMCHistograms[0]):
360 lantonel 1.32 signalMCHist.Draw("A HIST SAME")
361 lantonel 1.10 for dataHist in DataHistograms:
362 lantonel 1.32 dataHist.Draw("A E SAME")
363 lantonel 1.1
364 lantonel 1.10 elif(numDataSamples is not 0):
365     DataHistograms[0].SetTitle(histoTitle)
366     DataHistograms[0].Draw("E")
367     DataHistograms[0].GetXaxis().SetTitle(xAxisLabel)
368 lantonel 1.33 DataHistograms[0].SetMaximum(finalMax)
369 lantonel 1.20 DataHistograms[0].SetMinimum(0.0001)
370 lantonel 1.10 for dataHist in DataHistograms:
371     if(dataHist is not DataHistograms[0]):
372 lantonel 1.32 dataHist.Draw("A E SAME")
373 lantonel 1.3
374 lantonel 1.10
375     if(numBgMCSamples is not 0 or numDataSamples is not 0):
376 lantonel 1.32 BgMCLegend.SetX1NDC(0.75)
377     if numBgMCSamples is 0:
378     BgMCLegend.SetY1NDC(0.9-0.05*(1+numDataSamples))
379     else:
380     BgMCLegend.SetY1NDC(0.9-0.05*(2+numBgMCSamples+numDataSamples))
381     BgMCLegend.SetX2NDC(0.9)
382     BgMCLegend.SetY2NDC(0.9)
383 lantonel 1.10 BgMCLegend.Draw()
384 lantonel 1.32 if(numSignalSamples is not 0):
385     SignalMCLegend.SetX1NDC(0.6)
386     SignalMCLegend.SetY1NDC(0.9-0.05*(1+numSignalSamples))
387     SignalMCLegend.SetX2NDC(0.75)
388     SignalMCLegend.SetY2NDC(0.9)
389     SignalMCLegend.Draw()
390     elif numSignalSamples is not 0:
391     SignalMCLegend.SetX1NDC(0.75)
392     SignalMCLegend.SetY1NDC(0.9-0.05*(1+numSignalSamples))
393     SignalMCLegend.SetX2NDC(0.9)
394     SignalMCLegend.SetY2NDC(0.9)
395 lantonel 1.10 SignalMCLegend.Draw()
396    
397 lantonel 1.25 if not arguments.normalizeToUnitArea or numDataSamples > 0:
398     LumiLabel.Draw()
399 lantonel 1.16 if arguments.normalizeToData and numBgMCSamples > 0 and numDataSamples > 0:
400 lantonel 1.32 if numSignalSamples is 0:
401     NormLabel = TPaveLabel(0.6,0.85,0.75,0.9,"MC scaled to data","NDC")
402     else:
403     NormLabel = TPaveLabel(0.45,0.85,0.6,0.9,"MC scaled to data","NDC")
404 lantonel 1.10 NormLabel.SetBorderSize(0)
405     NormLabel.SetFillColor(0)
406     NormLabel.SetFillStyle(0)
407     NormLabel.Draw()
408 lantonel 1.16 elif arguments.normalizeToUnitArea:
409 lantonel 1.32 if (numBgMCSamples is not 0 or numDataSamples is not 0) and numSignalSamples is 0:
410     NormLabel = TPaveLabel(0.6,0.85,0.75,0.9,"Scaled to unit area","NDC")
411     else:
412     NormLabel = TPaveLabel(0.45,0.85,0.6,0.9,"Scaled to unit area","NDC")
413 lantonel 1.13 NormLabel.SetBorderSize(0)
414     NormLabel.SetFillColor(0)
415     NormLabel.SetFillStyle(0)
416     NormLabel.Draw()
417 lantonel 1.15
418    
419 lantonel 1.25 if makeRatioPlots or makeDiffPlots:
420 lantonel 1.15 Canvas.cd(2)
421     BgSum = Stack.GetStack().Last()
422 lantonel 1.25 Comparison = DataHistograms[0].Clone()
423     Comparison.Add(BgSum,-1)
424     if not makeDiffPlots:
425     Comparison.Divide(BgSum)
426     Comparison.SetTitle("")
427     Comparison.GetXaxis().SetTitle(xAxisLabel)
428     if makeRatioPlots:
429     Comparison.GetYaxis().SetTitle("#frac{Data-MC}{MC}")
430     elif makeDiffPlots:
431     Comparison.GetYaxis().SetTitle("Data-MC")
432     Comparison.GetYaxis().CenterTitle()
433     Comparison.GetYaxis().SetTitleSize(0.1)
434     Comparison.GetYaxis().SetTitleOffset(0.35)
435     Comparison.GetXaxis().SetTitleSize(0.15)
436     Comparison.GetYaxis().SetLabelSize(0.1)
437     Comparison.GetXaxis().SetLabelSize(0.15)
438     if makeRatioPlots:
439 lantonel 1.33 Comparison.GetYaxis().SetRangeUser(-1.15,1.15)
440 lantonel 1.25 elif makeDiffPlots:
441     YMax = Comparison.GetMaximum()
442     YMin = Comparison.GetMinimum()
443     if YMax <= 0 and YMin <= 0:
444     Comparison.GetYaxis().SetRangeUser(-1.2*YMin,0)
445     elif YMax >= 0 and YMin >= 0:
446     Comparison.GetYaxis().SetRangeUser(0,1.2*YMax)
447     else: #axis crosses y=0
448     if abs(YMax) > abs(YMin):
449     Comparison.GetYaxis().SetRangeUser(-1.2*YMax,1.2*YMax)
450     else:
451     Comparison.GetYaxis().SetRangeUser(-1.2*YMin,1.2*YMin)
452    
453     Comparison.GetYaxis().SetNdivisions(205)
454     Comparison.Draw()
455 lantonel 1.10 Canvas.Write()
456 lantonel 1.1
457 lantonel 1.26 if re.match ('TH2', key.GetClassName()) and arguments.draw2DPlots: # plot a 2-D histogram
458 lantonel 1.4
459 lantonel 1.10 numBgMCSamples = 0
460     numDataSamples = 0
461     numSignalSamples = 0
462    
463     if(intLumi < 1000.):
464     LumiText = "L_{int} = " + str(intLumi) + " pb^{-1}"
465     else:
466     getcontext().prec = 2
467     LumiInFb = intLumi/1000.
468     LumiText = "L_{int} = " + str(LumiInFb) + " fb^{-1}"
469    
470     LumiLabel = TPaveLabel(0.1,0.8,0.34,0.9,LumiText,"NDC")
471     LumiLabel.SetBorderSize(0)
472     LumiLabel.SetFillColor(0)
473     LumiLabel.SetFillStyle(0)
474    
475 ahart 1.30 BgMCLegend = TLegend(0.76,0.65,0.99,0.9)
476     BgMCLegend.AddEntry (0, "Data & Bkgd. MC", "H").SetTextFont (62)
477 lantonel 1.10 BgMCLegend.SetBorderSize(0)
478     BgMCLegend.SetFillColor(0)
479     BgMCLegend.SetFillStyle(0)
480 ahart 1.30 SignalMCLegend = TLegend(0.76,0.135,0.99,0.377)
481     SignalMCLegend.AddEntry (0, "Signal MC", "H").SetTextFont (62)
482 lantonel 1.10 SignalMCLegend.SetBorderSize(0)
483     SignalMCLegend.SetFillColor(0)
484     SignalMCLegend.SetFillStyle(0)
485    
486     outputFile.cd(rootDirectory+"/"+channel)
487     Canvas = TCanvas(histogramName)
488     Canvas.SetRightMargin(0.2413793);
489     BgMCHistograms = []
490     SignalMCHistograms = []
491     DataHistograms = []
492    
493     for sample in processed_datasets: # loop over different samples as listed in configurationOptions.py
494 ahart 1.28 dataset_file = "%s/%s.root" % (condor_dir,sample)
495 lantonel 1.10 inputFile = TFile(dataset_file)
496     Histogram = inputFile.Get(rootDirectory+"/"+channel+"/"+histogramName).Clone()
497     Histogram.SetDirectory(0)
498 lantonel 1.25 RebinFactor = int(arguments.rebinFactor)
499     if arguments.rebinFactor and Histogram.GetNbinsX() >= RebinFactor*10 and Histogram.GetNbinsY() >= RebinFactor*10:
500     Histogram.Rebin2D(RebinFactor)
501 lantonel 1.10 inputFile.Close()
502     xAxisLabel = Histogram.GetXaxis().GetTitle()
503     yAxisLabel = Histogram.GetYaxis().GetTitle()
504     histoTitle = Histogram.GetTitle()
505    
506     if( types[sample] == "bgMC"):
507 lantonel 1.4
508 lantonel 1.10 numBgMCSamples += 1
509     Histogram.SetMarkerColor(colors[sample])
510     Histogram.SetFillColor(colors[sample])
511 ahart 1.30 BgMCLegend.AddEntry(Histogram,labels[sample],"F").SetTextFont (42)
512 lantonel 1.10 BgMCHistograms.append(Histogram)
513    
514     elif( types[sample] == "signalMC"):
515 lantonel 1.3
516 lantonel 1.10 numSignalSamples += 1
517     Histogram.SetMarkerColor(colors[sample])
518     Histogram.SetFillColor(colors[sample])
519 ahart 1.30 SignalMCLegend.AddEntry(Histogram,labels[sample],"F").SetTextFont (42)
520 lantonel 1.10 SignalMCHistograms.append(Histogram)
521    
522     elif( types[sample] == "data"):
523    
524     numDataSamples += 1
525     Histogram.SetMarkerColor(colors[sample])
526 wulsin 1.29 Histogram.SetFillColor(colors[sample])
527 ahart 1.30 BgMCLegend.AddEntry(Histogram,labels[sample],"F").SetTextFont (42)
528 lantonel 1.10 DataHistograms.append(Histogram)
529    
530    
531     outputFile.cd(rootDirectory+"/"+channel)
532    
533     if(numBgMCSamples is not 0):
534     BgMCHistograms[0].SetTitle(histoTitle)
535     BgMCHistograms[0].GetXaxis().SetTitle(xAxisLabel)
536     BgMCHistograms[0].GetYaxis().SetTitle(yAxisLabel)
537     BgMCHistograms[0].Draw()
538     for signalMCHist in SignalMCHistograms:
539     signalMCHist.Draw("SAME")
540     for dataHist in DataHistograms:
541     dataHist.Draw("SAME")
542 lantonel 1.3
543 lantonel 1.10 elif(numSignalSamples is not 0):
544     SignalMCHistograms[0].SetTitle(histoTitle)
545     SignalMCHistograms[0].Draw()
546     SignalMCHistograms[0].GetXaxis().SetTitle(xAxisLabel)
547     SignalMCHistograms[0].GetYaxis().SetTitle(yAxisLabel)
548     for signalMCHist in SignalMCHistograms:
549     if(signalMCHist is not SignalMCHistograms[0]):
550     signalMCHist.Draw("SAME")
551     for dataHist in DataHistograms:
552     dataHist.Draw("SAME")
553    
554     elif(numDataSamples is not 0):
555     DataHistograms[0].SetTitle(histoTitle)
556     DataHistograms[0].GetXaxis().SetTitle(xAxisLabel)
557     DataHistograms[0].GetYaxis().SetTitle(yAxisLabel)
558     DataHistograms[0].Draw()
559     for dataHist in DataHistograms:
560     if(dataHist is not DataHistograms[0]):
561     dataHist.Draw("SAME")
562 lantonel 1.3
563 lantonel 1.8
564 lantonel 1.10 if(numBgMCSamples is not 0 or numDataSamples is not 0):
565     BgMCLegend.Draw()
566     if(numSignalSamples is not 0):
567     SignalMCLegend.Draw()
568 lantonel 1.25 if not arguments.normalizeToUnitArea or numDataSamples > 0:
569     LumiLabel.Draw()
570 lantonel 1.4
571 lantonel 1.10 Canvas.Write()
572    
573 lantonel 1.4
574 ahart 1.28 #for dataset in processed_datasets:
575     # dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset)
576     # os.remove(dataset_file)
577 lantonel 1.1
578     outputFile.Close()