ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makePlots.py
Revision: 1.32
Committed: Fri Apr 19 09:54:38 2013 UTC (12 years ago) by lantonel
Content type: text/x-python
Branch: MAIN
Changes since 1.31: +86 -31 lines
Log Message:
legends now scale with number of entries, and the sample order in legend matches the order in the stack

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     for channel in channels: # loop over final states, which each have their own directory
102    
103     testFile.cd(rootDirectory+"/"+channel)
104 lantonel 1.3
105 lantonel 1.10 for key in gDirectory.GetListOfKeys(): # loop over histograms in the current directory
106     histogramName = key.GetName()
107 lantonel 1.1
108 lantonel 1.10 if re.match ('TH1', key.GetClassName()): # plot a 1-D histogram
109    
110     numBgMCSamples = 0
111     numDataSamples = 0
112     numSignalSamples = 0
113 lantonel 1.1
114 lantonel 1.10 Stack = THStack("stack",histogramName)
115 lantonel 1.1
116 lantonel 1.10 if(intLumi < 1000.):
117     LumiText = "L_{int} = " + str(intLumi) + " pb^{-1}"
118     else:
119     getcontext().prec = 2
120     LumiInFb = intLumi/1000.
121     LumiText = "L_{int} = " + str(LumiInFb) + " fb^{-1}"
122    
123     LumiLabel = TPaveLabel(0.1,0.8,0.34,0.9,LumiText,"NDC")
124     LumiLabel.SetBorderSize(0)
125     LumiLabel.SetFillColor(0)
126     LumiLabel.SetFillStyle(0)
127 lantonel 1.32
128     BgMCLegend = TLegend()
129     BgTitle = BgMCLegend.AddEntry(0, "Data & Bkgd. MC", "H")
130     BgTitle.SetTextAlign(21)
131     BgTitle.SetTextFont(62)
132 lantonel 1.10 BgMCLegend.SetBorderSize(0)
133     BgMCLegend.SetFillColor(0)
134     BgMCLegend.SetFillStyle(0)
135 lantonel 1.32 SignalMCLegend = TLegend()
136     SignalTitle = SignalMCLegend.AddEntry(0, "Signal MC", "H")
137     SignalTitle.SetTextAlign(21)
138     SignalTitle.SetTextFont(62)
139 lantonel 1.10 SignalMCLegend.SetBorderSize(0)
140     SignalMCLegend.SetFillColor(0)
141     SignalMCLegend.SetFillStyle(0)
142    
143     outputFile.cd(rootDirectory+"/"+channel)
144     Canvas = TCanvas(histogramName)
145     BgMCHistograms = []
146 lantonel 1.32 BgMCLegendEntries = []
147 lantonel 1.10 SignalMCHistograms = []
148 lantonel 1.32 SignalMCLegendEntries = []
149 lantonel 1.10 DataHistograms = []
150 lantonel 1.32 DataLegendEntries = []
151    
152 lantonel 1.10
153     backgroundIntegral = 0
154     dataIntegral = 0
155     scaleFactor = 1
156    
157     for sample in processed_datasets: # loop over different samples as listed in configurationOptions.py
158 ahart 1.28 dataset_file = "%s/%s.root" % (condor_dir,sample)
159 lantonel 1.10 inputFile = TFile(dataset_file)
160     Histogram = inputFile.Get(rootDirectory+"/"+channel+"/"+histogramName).Clone()
161     Histogram.SetDirectory(0)
162 lantonel 1.27 if arguments.rebinFactor:
163     RebinFactor = int(arguments.rebinFactor)
164     if Histogram.GetNbinsX() >= RebinFactor*10:
165     Histogram.Rebin(RebinFactor)
166 lantonel 1.10 inputFile.Close()
167     xAxisLabel = Histogram.GetXaxis().GetTitle()
168     histoTitle = Histogram.GetTitle()
169 wulsin 1.29
170 lantonel 1.32
171 wulsin 1.29 if (arguments.printYields):
172     yieldHist = Histogram.Integral()
173     legLabel = legLabel + " (%.1f)" % yieldHist
174    
175 lantonel 1.10 if( types[sample] == "bgMC"):
176    
177     numBgMCSamples += 1
178 lantonel 1.32 backgroundIntegral += Histogram.Integral()
179 wulsin 1.29
180 lantonel 1.32 Histogram.SetLineStyle(1)
181 lantonel 1.16 if(arguments.noStack):
182 lantonel 1.14 Histogram.SetFillStyle(0)
183     Histogram.SetLineColor(colors[sample])
184     Histogram.SetLineWidth(2)
185     else:
186     Histogram.SetFillStyle(1001)
187     Histogram.SetFillColor(colors[sample])
188     Histogram.SetLineColor(1)
189     Histogram.SetLineWidth(1)
190 lantonel 1.31
191 lantonel 1.32 BgMCLegendEntries.append(labels[sample])
192 lantonel 1.10 BgMCHistograms.append(Histogram)
193 lantonel 1.31
194 lantonel 1.10
195     elif( types[sample] == "signalMC"):
196    
197     numSignalSamples += 1
198 lantonel 1.11
199 lantonel 1.10 Histogram.SetFillStyle(0)
200     Histogram.SetLineColor(colors[sample])
201     Histogram.SetLineStyle(1)
202     Histogram.SetLineWidth(2)
203 lantonel 1.16 if(arguments.normalizeToUnitArea and Histogram.Integral() > 0):
204 lantonel 1.11 Histogram.Scale(1./Histogram.Integral())
205 lantonel 1.32
206     SignalMCLegendEntries.append(labels[sample])
207 lantonel 1.10 SignalMCHistograms.append(Histogram)
208    
209     elif( types[sample] == "data"):
210    
211     numDataSamples += 1
212 lantonel 1.32 dataIntegral += Histogram.Integral()
213    
214 lantonel 1.10 Histogram.SetFillStyle(0)
215     Histogram.SetLineColor(colors[sample])
216     Histogram.SetLineStyle(1)
217     Histogram.SetLineWidth(2)
218 lantonel 1.16 if(arguments.normalizeToUnitArea and Histogram.Integral() > 0):
219 lantonel 1.11 Histogram.Scale(1./Histogram.Integral())
220 lantonel 1.32
221     DataLegendEntries.append(labels[sample])
222 lantonel 1.10 DataHistograms.append(Histogram)
223    
224     if dataIntegral > 0 and backgroundIntegral > 0:
225     scaleFactor = dataIntegral/backgroundIntegral
226     for bgMCHist in BgMCHistograms:
227 lantonel 1.16 if arguments.normalizeToData:
228 lantonel 1.10 bgMCHist.Scale(scaleFactor)
229 lantonel 1.16 if arguments.normalizeToUnitArea and not arguments.noStack and backgroundIntegral > 0:
230 lantonel 1.11 bgMCHist.Scale(1./backgroundIntegral)
231 lantonel 1.16 elif arguments.normalizeToUnitArea and arguments.noStack and bgMCHist.Integral() > 0:
232 lantonel 1.14 bgMCHist.Scale(1./bgMCHist.Integral())
233 lantonel 1.16 if not arguments.noStack:
234 lantonel 1.14 Stack.Add(bgMCHist)
235 lantonel 1.3
236 lantonel 1.14
237     finalMax = 0
238 lantonel 1.16 if not arguments.noStack:
239 lantonel 1.14 finalMax = Stack.GetMaximum()
240     else:
241     for bgMCHist in BgMCHistograms:
242     if(bgMCHist.GetMaximum() > finalMax):
243     finalMax = bgMCHist.GetMaximum()
244 lantonel 1.10 for signalMCHist in SignalMCHistograms:
245     if(signalMCHist.GetMaximum() > finalMax):
246     finalMax = signalMCHist.GetMaximum()
247     for dataHist in DataHistograms:
248     if(dataHist.GetMaximum() > finalMax):
249     finalMax = dataHist.GetMaximum()
250 lantonel 1.4
251 lantonel 1.14
252    
253 lantonel 1.10 if len(DataHistograms) is 1:
254     dataIntegral += DataHistograms[0].Integral()
255 lantonel 1.15
256    
257 lantonel 1.32 ### formatting data histograms and adding to legend
258     counter = 0
259     for Histogram in DataHistograms:
260     BgMCLegend.AddEntry(Histogram,DataLegendEntries[counter],"LEP").SetTextFont (42)
261     counter = counter+1
262    
263 lantonel 1.31
264 lantonel 1.32 ### creating the histogram to represent the statistical errors on the stack
265 lantonel 1.31 if numBgMCSamples is not 0:
266     ErrorHisto = BgMCHistograms[0].Clone("errors")
267     ErrorHisto.SetFillStyle(3001)
268     ErrorHisto.SetFillColor(13)
269     ErrorHisto.SetLineWidth(0)
270 lantonel 1.32 BgMCLegend.AddEntry(ErrorHisto,"Stat. Errors","F").SetTextFont (42)
271 lantonel 1.31 for Histogram in BgMCHistograms:
272     if Histogram is not BgMCHistograms[0]:
273     ErrorHisto.Add(Histogram)
274    
275 lantonel 1.32
276     ### formatting bgMC histograms and adding to legend
277     counter = numBgMCSamples-1
278     for Histogram in reversed(BgMCHistograms):
279     if(arguments.noStack):
280     BgMCLegend.AddEntry(Histogram,BgMCLegendEntries[counter],"L").SetTextFont (42)
281     else:
282     BgMCLegend.AddEntry(Histogram,BgMCLegendEntries[counter],"F").SetTextFont (42)
283     counter = counter-1
284    
285     ### formatting signalMC histograms and adding to legend
286     counter = 0
287     for Histogram in SignalMCHistograms:
288     SignalMCLegend.AddEntry(Histogram,SignalMCLegendEntries[counter],"L").SetTextFont (42)
289     counter = counter+1
290    
291    
292    
293     ### Drawing histograms to canvas
294    
295    
296 lantonel 1.10 outputFile.cd(rootDirectory+"/"+channel)
297 lantonel 1.3
298 lantonel 1.16 makeRatioPlots = arguments.makeRatioPlots
299 lantonel 1.25 makeDiffPlots = arguments.makeDiffPlots
300    
301 lantonel 1.15 if numBgMCSamples is 0 or numDataSamples is not 1:
302     makeRatioPlots = False
303 lantonel 1.25 makeDiffPlots = False
304     if makeRatioPlots or makeDiffPlots:
305 lantonel 1.15 Canvas.SetFillStyle(0)
306     Canvas.Divide(1,2)
307     Canvas.cd(1)
308     gPad.SetPad(0.01,0.25,0.99,0.99)
309     gPad.SetMargin(0.1,0.05,0.02,0.07)
310     gPad.SetFillStyle(0)
311     gPad.Update()
312     gPad.Draw()
313     Canvas.cd(2)
314     gPad.SetPad(0.01,0.01,0.99,0.25)
315 lantonel 1.25 #format: gPad.SetMargin(l,r,b,t)
316 lantonel 1.15 gPad.SetMargin(0.1,0.05,0.4,0.02)
317     gPad.SetFillStyle(0)
318     gPad.SetGridy(1)
319     gPad.Update()
320     gPad.Draw()
321    
322     Canvas.cd(1)
323    
324 lantonel 1.31 if numBgMCSamples is not 0:
325 ahart 1.28
326 lantonel 1.16 if not arguments.noStack:
327 lantonel 1.14 Stack.SetTitle(histoTitle)
328     Stack.Draw("HIST")
329     Stack.GetXaxis().SetTitle(xAxisLabel)
330     Stack.SetMaximum(1.1*finalMax)
331 lantonel 1.20 Stack.SetMinimum(0.0001)
332 lantonel 1.25 if makeRatioPlots or makeDiffPlots:
333 lantonel 1.15 Stack.GetHistogram().GetXaxis().SetLabelSize(0)
334 lantonel 1.31 #draw shaded error bands
335 lantonel 1.32 ErrorHisto.Draw("A E2 SAME")
336 lantonel 1.31
337    
338 lantonel 1.14 else:
339     BgMCHistograms[0].SetTitle(histoTitle)
340     BgMCHistograms[0].Draw("HIST")
341     BgMCHistograms[0].GetXaxis().SetTitle(xAxisLabel)
342     BgMCHistograms[0].SetMaximum(1.1*finalMax)
343 lantonel 1.20 BgMCHistograms[0].SetMinimum(0.0001)
344 lantonel 1.14 for bgMCHist in BgMCHistograms:
345 lantonel 1.32 bgMCHist.Draw("A HIST SAME")
346 lantonel 1.10 for signalMCHist in SignalMCHistograms:
347 lantonel 1.32 signalMCHist.Draw("A HIST SAME")
348 lantonel 1.10 for dataHist in DataHistograms:
349 lantonel 1.32 dataHist.Draw("A E SAME")
350 lantonel 1.10
351 lantonel 1.31 elif numSignalSamples is not 0:
352 lantonel 1.10 SignalMCHistograms[0].SetTitle(histoTitle)
353     SignalMCHistograms[0].Draw("HIST")
354     SignalMCHistograms[0].GetXaxis().SetTitle(xAxisLabel)
355     SignalMCHistograms[0].SetMaximum(1.1*finalMax)
356 lantonel 1.20 SignalMCHistograms[0].SetMinimum(0.0001)
357 lantonel 1.10 for signalMCHist in SignalMCHistograms:
358     if(signalMCHist is not SignalMCHistograms[0]):
359 lantonel 1.32 signalMCHist.Draw("A HIST SAME")
360 lantonel 1.10 for dataHist in DataHistograms:
361 lantonel 1.32 dataHist.Draw("A E SAME")
362 lantonel 1.1
363 lantonel 1.10 elif(numDataSamples is not 0):
364     DataHistograms[0].SetTitle(histoTitle)
365     DataHistograms[0].Draw("E")
366     DataHistograms[0].GetXaxis().SetTitle(xAxisLabel)
367     DataHistograms[0].SetMaximum(1.1*finalMax)
368 lantonel 1.20 DataHistograms[0].SetMinimum(0.0001)
369 lantonel 1.10 for dataHist in DataHistograms:
370     if(dataHist is not DataHistograms[0]):
371 lantonel 1.32 dataHist.Draw("A E SAME")
372 lantonel 1.3
373 lantonel 1.10
374     if(numBgMCSamples is not 0 or numDataSamples is not 0):
375 lantonel 1.32 BgMCLegend.SetX1NDC(0.75)
376     if numBgMCSamples is 0:
377     BgMCLegend.SetY1NDC(0.9-0.05*(1+numDataSamples))
378     else:
379     BgMCLegend.SetY1NDC(0.9-0.05*(2+numBgMCSamples+numDataSamples))
380     BgMCLegend.SetX2NDC(0.9)
381     BgMCLegend.SetY2NDC(0.9)
382 lantonel 1.10 BgMCLegend.Draw()
383 lantonel 1.32 if(numSignalSamples is not 0):
384     SignalMCLegend.SetX1NDC(0.6)
385     SignalMCLegend.SetY1NDC(0.9-0.05*(1+numSignalSamples))
386     SignalMCLegend.SetX2NDC(0.75)
387     SignalMCLegend.SetY2NDC(0.9)
388     SignalMCLegend.Draw()
389     elif numSignalSamples is not 0:
390     SignalMCLegend.SetX1NDC(0.75)
391     SignalMCLegend.SetY1NDC(0.9-0.05*(1+numSignalSamples))
392     SignalMCLegend.SetX2NDC(0.9)
393     SignalMCLegend.SetY2NDC(0.9)
394 lantonel 1.10 SignalMCLegend.Draw()
395    
396 lantonel 1.25 if not arguments.normalizeToUnitArea or numDataSamples > 0:
397     LumiLabel.Draw()
398 lantonel 1.16 if arguments.normalizeToData and numBgMCSamples > 0 and numDataSamples > 0:
399 lantonel 1.32 if numSignalSamples is 0:
400     NormLabel = TPaveLabel(0.6,0.85,0.75,0.9,"MC scaled to data","NDC")
401     else:
402     NormLabel = TPaveLabel(0.45,0.85,0.6,0.9,"MC scaled to data","NDC")
403 lantonel 1.10 NormLabel.SetBorderSize(0)
404     NormLabel.SetFillColor(0)
405     NormLabel.SetFillStyle(0)
406     NormLabel.Draw()
407 lantonel 1.16 elif arguments.normalizeToUnitArea:
408 lantonel 1.32 if (numBgMCSamples is not 0 or numDataSamples is not 0) and numSignalSamples is 0:
409     NormLabel = TPaveLabel(0.6,0.85,0.75,0.9,"Scaled to unit area","NDC")
410     else:
411     NormLabel = TPaveLabel(0.45,0.85,0.6,0.9,"Scaled to unit area","NDC")
412 lantonel 1.13 NormLabel.SetBorderSize(0)
413     NormLabel.SetFillColor(0)
414     NormLabel.SetFillStyle(0)
415     NormLabel.Draw()
416 lantonel 1.15
417    
418 lantonel 1.25 if makeRatioPlots or makeDiffPlots:
419 lantonel 1.15 Canvas.cd(2)
420     BgSum = Stack.GetStack().Last()
421 lantonel 1.25 Comparison = DataHistograms[0].Clone()
422     Comparison.Add(BgSum,-1)
423     if not makeDiffPlots:
424     Comparison.Divide(BgSum)
425     Comparison.SetTitle("")
426     Comparison.GetXaxis().SetTitle(xAxisLabel)
427     if makeRatioPlots:
428     Comparison.GetYaxis().SetTitle("#frac{Data-MC}{MC}")
429     elif makeDiffPlots:
430     Comparison.GetYaxis().SetTitle("Data-MC")
431     Comparison.GetYaxis().CenterTitle()
432     Comparison.GetYaxis().SetTitleSize(0.1)
433     Comparison.GetYaxis().SetTitleOffset(0.35)
434     Comparison.GetXaxis().SetTitleSize(0.15)
435     Comparison.GetYaxis().SetLabelSize(0.1)
436     Comparison.GetXaxis().SetLabelSize(0.15)
437     if makeRatioPlots:
438     Comparison.GetYaxis().SetRangeUser(-1,1)
439     elif makeDiffPlots:
440     YMax = Comparison.GetMaximum()
441     YMin = Comparison.GetMinimum()
442     if YMax <= 0 and YMin <= 0:
443     Comparison.GetYaxis().SetRangeUser(-1.2*YMin,0)
444     elif YMax >= 0 and YMin >= 0:
445     Comparison.GetYaxis().SetRangeUser(0,1.2*YMax)
446     else: #axis crosses y=0
447     if abs(YMax) > abs(YMin):
448     Comparison.GetYaxis().SetRangeUser(-1.2*YMax,1.2*YMax)
449     else:
450     Comparison.GetYaxis().SetRangeUser(-1.2*YMin,1.2*YMin)
451    
452     Comparison.GetYaxis().SetNdivisions(205)
453     Comparison.Draw()
454 lantonel 1.4
455 lantonel 1.10 Canvas.Write()
456 lantonel 1.1
457 lantonel 1.4
458 lantonel 1.26 if re.match ('TH2', key.GetClassName()) and arguments.draw2DPlots: # plot a 2-D histogram
459 lantonel 1.4
460 lantonel 1.10 numBgMCSamples = 0
461     numDataSamples = 0
462     numSignalSamples = 0
463    
464     if(intLumi < 1000.):
465     LumiText = "L_{int} = " + str(intLumi) + " pb^{-1}"
466     else:
467     getcontext().prec = 2
468     LumiInFb = intLumi/1000.
469     LumiText = "L_{int} = " + str(LumiInFb) + " fb^{-1}"
470    
471     LumiLabel = TPaveLabel(0.1,0.8,0.34,0.9,LumiText,"NDC")
472     LumiLabel.SetBorderSize(0)
473     LumiLabel.SetFillColor(0)
474     LumiLabel.SetFillStyle(0)
475    
476 ahart 1.30 BgMCLegend = TLegend(0.76,0.65,0.99,0.9)
477     BgMCLegend.AddEntry (0, "Data & Bkgd. MC", "H").SetTextFont (62)
478 lantonel 1.10 BgMCLegend.SetBorderSize(0)
479     BgMCLegend.SetFillColor(0)
480     BgMCLegend.SetFillStyle(0)
481 ahart 1.30 SignalMCLegend = TLegend(0.76,0.135,0.99,0.377)
482     SignalMCLegend.AddEntry (0, "Signal MC", "H").SetTextFont (62)
483 lantonel 1.10 SignalMCLegend.SetBorderSize(0)
484     SignalMCLegend.SetFillColor(0)
485     SignalMCLegend.SetFillStyle(0)
486    
487     outputFile.cd(rootDirectory+"/"+channel)
488     Canvas = TCanvas(histogramName)
489     Canvas.SetRightMargin(0.2413793);
490     BgMCHistograms = []
491     SignalMCHistograms = []
492     DataHistograms = []
493    
494     for sample in processed_datasets: # loop over different samples as listed in configurationOptions.py
495 ahart 1.28 dataset_file = "%s/%s.root" % (condor_dir,sample)
496 lantonel 1.10 inputFile = TFile(dataset_file)
497     Histogram = inputFile.Get(rootDirectory+"/"+channel+"/"+histogramName).Clone()
498     Histogram.SetDirectory(0)
499 lantonel 1.25 RebinFactor = int(arguments.rebinFactor)
500     if arguments.rebinFactor and Histogram.GetNbinsX() >= RebinFactor*10 and Histogram.GetNbinsY() >= RebinFactor*10:
501     Histogram.Rebin2D(RebinFactor)
502 lantonel 1.10 inputFile.Close()
503     xAxisLabel = Histogram.GetXaxis().GetTitle()
504     yAxisLabel = Histogram.GetYaxis().GetTitle()
505     histoTitle = Histogram.GetTitle()
506    
507     if( types[sample] == "bgMC"):
508 lantonel 1.4
509 lantonel 1.10 numBgMCSamples += 1
510     Histogram.SetMarkerColor(colors[sample])
511     Histogram.SetFillColor(colors[sample])
512 ahart 1.30 BgMCLegend.AddEntry(Histogram,labels[sample],"F").SetTextFont (42)
513 lantonel 1.10 BgMCHistograms.append(Histogram)
514    
515     elif( types[sample] == "signalMC"):
516 lantonel 1.3
517 lantonel 1.10 numSignalSamples += 1
518     Histogram.SetMarkerColor(colors[sample])
519     Histogram.SetFillColor(colors[sample])
520 ahart 1.30 SignalMCLegend.AddEntry(Histogram,labels[sample],"F").SetTextFont (42)
521 lantonel 1.10 SignalMCHistograms.append(Histogram)
522    
523     elif( types[sample] == "data"):
524    
525     numDataSamples += 1
526     Histogram.SetMarkerColor(colors[sample])
527 wulsin 1.29 Histogram.SetFillColor(colors[sample])
528 ahart 1.30 BgMCLegend.AddEntry(Histogram,labels[sample],"F").SetTextFont (42)
529 lantonel 1.10 DataHistograms.append(Histogram)
530    
531    
532     outputFile.cd(rootDirectory+"/"+channel)
533    
534     if(numBgMCSamples is not 0):
535     BgMCHistograms[0].SetTitle(histoTitle)
536     BgMCHistograms[0].GetXaxis().SetTitle(xAxisLabel)
537     BgMCHistograms[0].GetYaxis().SetTitle(yAxisLabel)
538     BgMCHistograms[0].Draw()
539     for signalMCHist in SignalMCHistograms:
540     signalMCHist.Draw("SAME")
541     for dataHist in DataHistograms:
542     dataHist.Draw("SAME")
543 lantonel 1.3
544 lantonel 1.10 elif(numSignalSamples is not 0):
545     SignalMCHistograms[0].SetTitle(histoTitle)
546     SignalMCHistograms[0].Draw()
547     SignalMCHistograms[0].GetXaxis().SetTitle(xAxisLabel)
548     SignalMCHistograms[0].GetYaxis().SetTitle(yAxisLabel)
549     for signalMCHist in SignalMCHistograms:
550     if(signalMCHist is not SignalMCHistograms[0]):
551     signalMCHist.Draw("SAME")
552     for dataHist in DataHistograms:
553     dataHist.Draw("SAME")
554    
555     elif(numDataSamples is not 0):
556     DataHistograms[0].SetTitle(histoTitle)
557     DataHistograms[0].GetXaxis().SetTitle(xAxisLabel)
558     DataHistograms[0].GetYaxis().SetTitle(yAxisLabel)
559     DataHistograms[0].Draw()
560     for dataHist in DataHistograms:
561     if(dataHist is not DataHistograms[0]):
562     dataHist.Draw("SAME")
563 lantonel 1.3
564 lantonel 1.8
565 lantonel 1.10 if(numBgMCSamples is not 0 or numDataSamples is not 0):
566     BgMCLegend.Draw()
567     if(numSignalSamples is not 0):
568     SignalMCLegend.Draw()
569 lantonel 1.25 if not arguments.normalizeToUnitArea or numDataSamples > 0:
570     LumiLabel.Draw()
571 lantonel 1.4
572 lantonel 1.10 Canvas.Write()
573    
574 lantonel 1.4
575 lantonel 1.1
576 ahart 1.28 #for dataset in processed_datasets:
577     # dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset)
578     # os.remove(dataset_file)
579 lantonel 1.1
580     outputFile.Close()