4 |
|
import re |
5 |
|
from array import * |
6 |
|
from decimal import * |
7 |
< |
from optparse import OptionParser |
7 |
> |
import argparse |
8 |
|
from OSUT3Analysis.Configuration.configurationOptions import * |
9 |
|
from OSUT3Analysis.Configuration.processingUtilities import * |
10 |
|
|
11 |
< |
parser = OptionParser() |
11 |
> |
parser = argparse.ArgumentParser() |
12 |
|
parser = set_commandline_arguments(parser) |
13 |
|
|
14 |
< |
(options, args) = parser.parse_args() |
14 |
> |
arguments = parser.parse_args() |
15 |
|
|
16 |
< |
if options.localConfig: |
16 |
> |
if arguments.localConfig: |
17 |
|
sys.path.append(os.getcwd()) |
18 |
< |
exec("from " + options.localConfig.rstrip('.py') + " import *") |
18 |
> |
exec("from " + arguments.localConfig.rstrip('.py') + " import *") |
19 |
|
|
20 |
|
|
21 |
|
outputFileName = "stacked_histograms.root" |
22 |
< |
if options.outputFileName: |
23 |
< |
outputFileName = options.outputFileName |
22 |
> |
if arguments.outputFileName: |
23 |
> |
outputFileName = arguments.outputFileName |
24 |
|
|
25 |
< |
condor_dir = set_condor_output_dir(options) |
25 |
> |
condor_dir = set_condor_output_dir(arguments) |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
< |
if options.normalizeToData and options.normalizeToUnitArea: |
30 |
> |
if arguments.normalizeToData and arguments.normalizeToUnitArea: |
31 |
|
print "Conflicting normalizations requsted, will normalize to unit area" |
32 |
< |
options.normalizeToData = False |
33 |
< |
if options.normalizeToData and options.noStack: |
32 |
> |
arguments.normalizeToData = False |
33 |
> |
if arguments.normalizeToData and arguments.noStack: |
34 |
|
print "You have asked to scale non-stacked backgrounds to data. This is a very strange request. Will normalize to unit area instead" |
35 |
< |
options.normalizeToData = False |
36 |
< |
options.normalizeToUnitArea = True |
35 |
> |
arguments.normalizeToData = False |
36 |
> |
arguments.normalizeToUnitArea = True |
37 |
|
|
38 |
|
from ROOT import TFile, gROOT, gStyle, gDirectory, TStyle, THStack, TH1F, TCanvas, TString, TLegend, TArrow, THStack, TIter, TKey, TPaveLabel, gPad |
39 |
|
|
149 |
|
|
150 |
|
numBgMCSamples += 1 |
151 |
|
|
152 |
< |
if(options.noStack): |
152 |
> |
if(arguments.noStack): |
153 |
|
Histogram.SetFillStyle(0) |
154 |
|
Histogram.SetLineColor(colors[sample]) |
155 |
|
Histogram.SetLineWidth(2) |
174 |
|
Histogram.SetLineColor(colors[sample]) |
175 |
|
Histogram.SetLineStyle(1) |
176 |
|
Histogram.SetLineWidth(2) |
177 |
< |
if(options.normalizeToUnitArea and Histogram.Integral() > 0): |
177 |
> |
if(arguments.normalizeToUnitArea and Histogram.Integral() > 0): |
178 |
|
Histogram.Scale(1./Histogram.Integral()) |
179 |
|
SignalMCLegend.AddEntry(Histogram,labels[sample],"L") |
180 |
|
SignalMCHistograms.append(Histogram) |
187 |
|
Histogram.SetLineColor(colors[sample]) |
188 |
|
Histogram.SetLineStyle(1) |
189 |
|
Histogram.SetLineWidth(2) |
190 |
< |
if(options.normalizeToUnitArea and Histogram.Integral() > 0): |
190 |
> |
if(arguments.normalizeToUnitArea and Histogram.Integral() > 0): |
191 |
|
Histogram.Scale(1./Histogram.Integral()) |
192 |
|
|
193 |
|
dataIntegral += Histogram.Integral() |
198 |
|
if dataIntegral > 0 and backgroundIntegral > 0: |
199 |
|
scaleFactor = dataIntegral/backgroundIntegral |
200 |
|
for bgMCHist in BgMCHistograms: |
201 |
< |
if options.normalizeToData: |
201 |
> |
if arguments.normalizeToData: |
202 |
|
bgMCHist.Scale(scaleFactor) |
203 |
< |
if options.normalizeToUnitArea and not options.noStack and backgroundIntegral > 0: |
203 |
> |
if arguments.normalizeToUnitArea and not arguments.noStack and backgroundIntegral > 0: |
204 |
|
bgMCHist.Scale(1./backgroundIntegral) |
205 |
< |
elif options.normalizeToUnitArea and options.noStack and bgMCHist.Integral() > 0: |
205 |
> |
elif arguments.normalizeToUnitArea and arguments.noStack and bgMCHist.Integral() > 0: |
206 |
|
bgMCHist.Scale(1./bgMCHist.Integral()) |
207 |
< |
if not options.noStack: |
207 |
> |
if not arguments.noStack: |
208 |
|
Stack.Add(bgMCHist) |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
finalMax = 0 |
213 |
< |
if not options.noStack: |
213 |
> |
if not arguments.noStack: |
214 |
|
finalMax = Stack.GetMaximum() |
215 |
|
else: |
216 |
|
for bgMCHist in BgMCHistograms: |
234 |
|
|
235 |
|
outputFile.cd(rootDirectory+"/"+channel) |
236 |
|
|
237 |
< |
makeRatioPlots = options.makeRatioPlots |
237 |
> |
makeRatioPlots = arguments.makeRatioPlots |
238 |
|
if numBgMCSamples is 0 or numDataSamples is not 1: |
239 |
|
makeRatioPlots = False |
240 |
|
if makeRatioPlots: |
258 |
|
Canvas.cd(1) |
259 |
|
|
260 |
|
if(numBgMCSamples is not 0): |
261 |
< |
if not options.noStack: |
261 |
> |
if not arguments.noStack: |
262 |
|
Stack.SetTitle(histoTitle) |
263 |
|
Stack.Draw("HIST") |
264 |
|
Stack.GetXaxis().SetTitle(xAxisLabel) |
304 |
|
SignalMCLegend.Draw() |
305 |
|
|
306 |
|
LumiLabel.Draw() |
307 |
< |
if options.normalizeToData and numBgMCSamples > 0 and numDataSamples > 0: |
307 |
> |
if arguments.normalizeToData and numBgMCSamples > 0 and numDataSamples > 0: |
308 |
|
NormLabel = TPaveLabel(0.1,0.75,0.35,0.85,"MC scaled to data","NDC") |
309 |
|
NormLabel.SetBorderSize(0) |
310 |
|
NormLabel.SetFillColor(0) |
311 |
|
NormLabel.SetFillStyle(0) |
312 |
|
NormLabel.Draw() |
313 |
< |
elif options.normalizeToUnitArea: |
313 |
> |
elif arguments.normalizeToUnitArea: |
314 |
|
NormLabel = TPaveLabel(0.1,0.75,0.35,0.85,"Scaled to unit area","NDC") |
315 |
|
NormLabel.SetBorderSize(0) |
316 |
|
NormLabel.SetFillColor(0) |