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