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