25 |
|
|
26 |
|
|
27 |
|
|
28 |
< |
|
28 |
> |
#### deal with conflicting arguments |
29 |
|
if arguments.normalizeToData and arguments.normalizeToUnitArea: |
30 |
|
print "Conflicting normalizations requsted, will normalize to unit area" |
31 |
|
arguments.normalizeToData = False |
33 |
|
print "You have asked to scale non-stacked backgrounds to data. This is a very strange request. Will normalize to unit area instead" |
34 |
|
arguments.normalizeToData = False |
35 |
|
arguments.normalizeToUnitArea = True |
36 |
+ |
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 |
|
|
40 |
|
from ROOT import TFile, gROOT, gStyle, gDirectory, TStyle, THStack, TH1F, TCanvas, TString, TLegend, TArrow, THStack, TIter, TKey, TPaveLabel, gPad |
41 |
|
|
147 |
|
inputFile = TFile(dataset_file) |
148 |
|
Histogram = inputFile.Get(rootDirectory+"/"+channel+"/"+histogramName).Clone() |
149 |
|
Histogram.SetDirectory(0) |
150 |
< |
Num = int(arguments.Rebin) |
151 |
< |
if arguments.Rebin and Histogram.GetNbinsX() >= Num*10: |
152 |
< |
Histogram.Rebin( Num ) |
150 |
< |
# if (Histogram.GetName () == "muonD0Beamspot" or Histogram.GetName () == "electronD0Beamspot"): |
151 |
< |
# Histogram.Rebin (8) |
152 |
< |
# Histogram.GetXaxis ().SetRangeUser (-0.04, 0.04) |
153 |
< |
# if (Histogram.GetName () == "muonAbsD0Beamspot" or Histogram.GetName () == "electronAbsD0Beamspot"): |
154 |
< |
# Histogram.Rebin (4) |
155 |
< |
# Histogram.GetXaxis ().SetRangeUser (0.0, 0.04) |
156 |
< |
# if (Histogram.GetName () == "electronMuonInvMass"): |
157 |
< |
# Histogram.GetXaxis ().SetRangeUser (0, 120) |
150 |
> |
RebinFactor = int(arguments.rebinFactor) |
151 |
> |
if arguments.rebinFactor and Histogram.GetNbinsX() >= RebinFactor*10: |
152 |
> |
Histogram.Rebin(RebinFactor) |
153 |
|
inputFile.Close() |
154 |
|
xAxisLabel = Histogram.GetXaxis().GetTitle() |
155 |
|
histoTitle = Histogram.GetTitle() |
244 |
|
outputFile.cd(rootDirectory+"/"+channel) |
245 |
|
|
246 |
|
makeRatioPlots = arguments.makeRatioPlots |
247 |
+ |
makeDiffPlots = arguments.makeDiffPlots |
248 |
+ |
|
249 |
|
if numBgMCSamples is 0 or numDataSamples is not 1: |
250 |
|
makeRatioPlots = False |
251 |
< |
if makeRatioPlots: |
251 |
> |
makeDiffPlots = False |
252 |
> |
if makeRatioPlots or makeDiffPlots: |
253 |
|
Canvas.SetFillStyle(0) |
254 |
|
Canvas.Divide(1,2) |
255 |
|
Canvas.cd(1) |
260 |
|
gPad.Draw() |
261 |
|
Canvas.cd(2) |
262 |
|
gPad.SetPad(0.01,0.01,0.99,0.25) |
263 |
< |
#gPad.SetMargin(l,r,b,t) |
263 |
> |
#format: gPad.SetMargin(l,r,b,t) |
264 |
|
gPad.SetMargin(0.1,0.05,0.4,0.02) |
265 |
|
gPad.SetFillStyle(0) |
266 |
|
gPad.SetGridy(1) |
276 |
|
Stack.GetXaxis().SetTitle(xAxisLabel) |
277 |
|
Stack.SetMaximum(1.1*finalMax) |
278 |
|
Stack.SetMinimum(0.0001) |
279 |
< |
if makeRatioPlots: |
279 |
> |
if makeRatioPlots or makeDiffPlots: |
280 |
|
Stack.GetHistogram().GetXaxis().SetLabelSize(0) |
281 |
|
else: |
282 |
|
BgMCHistograms[0].SetTitle(histoTitle) |
319 |
|
if(numSignalSamples is not 0): |
320 |
|
SignalMCLegend.Draw() |
321 |
|
|
322 |
< |
LumiLabel.Draw() |
322 |
> |
if not arguments.normalizeToUnitArea or numDataSamples > 0: |
323 |
> |
LumiLabel.Draw() |
324 |
|
if arguments.normalizeToData and numBgMCSamples > 0 and numDataSamples > 0: |
325 |
|
NormLabel = TPaveLabel(0.1,0.75,0.35,0.85,"MC scaled to data","NDC") |
326 |
|
NormLabel.SetBorderSize(0) |
335 |
|
NormLabel.Draw() |
336 |
|
|
337 |
|
|
338 |
< |
if makeRatioPlots: |
338 |
> |
if makeRatioPlots or makeDiffPlots: |
339 |
|
Canvas.cd(2) |
340 |
|
BgSum = Stack.GetStack().Last() |
341 |
< |
Ratio = DataHistograms[0].Clone() |
342 |
< |
Ratio.Add(BgSum,-1) |
343 |
< |
if not arguments.makeDiffPlots: |
344 |
< |
Ratio.Divide(BgSum) |
345 |
< |
|
346 |
< |
Ratio.SetTitle("") |
347 |
< |
Ratio.GetXaxis().SetTitle(xAxisLabel) |
348 |
< |
Ratio.GetYaxis().SetTitle("#frac{Data-MC}{MC}") |
349 |
< |
Ratio.GetYaxis().CenterTitle() |
350 |
< |
Ratio.GetYaxis().SetTitleSize(0.1) |
351 |
< |
Ratio.GetYaxis().SetTitleOffset(0.3) |
352 |
< |
Ratio.GetXaxis().SetTitleSize(0.15) |
353 |
< |
Ratio.GetYaxis().SetLabelSize(0.1) |
354 |
< |
Ratio.GetXaxis().SetLabelSize(0.15) |
355 |
< |
Ratio.GetYaxis().SetRangeUser(-1,1) |
356 |
< |
Ratio.GetYaxis().SetNdivisions(205) |
357 |
< |
Ratio.Draw() |
341 |
> |
Comparison = DataHistograms[0].Clone() |
342 |
> |
Comparison.Add(BgSum,-1) |
343 |
> |
if not makeDiffPlots: |
344 |
> |
Comparison.Divide(BgSum) |
345 |
> |
Comparison.SetTitle("") |
346 |
> |
Comparison.GetXaxis().SetTitle(xAxisLabel) |
347 |
> |
if makeRatioPlots: |
348 |
> |
Comparison.GetYaxis().SetTitle("#frac{Data-MC}{MC}") |
349 |
> |
elif makeDiffPlots: |
350 |
> |
Comparison.GetYaxis().SetTitle("Data-MC") |
351 |
> |
Comparison.GetYaxis().CenterTitle() |
352 |
> |
Comparison.GetYaxis().SetTitleSize(0.1) |
353 |
> |
Comparison.GetYaxis().SetTitleOffset(0.35) |
354 |
> |
Comparison.GetXaxis().SetTitleSize(0.15) |
355 |
> |
Comparison.GetYaxis().SetLabelSize(0.1) |
356 |
> |
Comparison.GetXaxis().SetLabelSize(0.15) |
357 |
> |
if makeRatioPlots: |
358 |
> |
Comparison.GetYaxis().SetRangeUser(-1,1) |
359 |
> |
elif makeDiffPlots: |
360 |
> |
YMax = Comparison.GetMaximum() |
361 |
> |
YMin = Comparison.GetMinimum() |
362 |
> |
if YMax <= 0 and YMin <= 0: |
363 |
> |
Comparison.GetYaxis().SetRangeUser(-1.2*YMin,0) |
364 |
> |
elif YMax >= 0 and YMin >= 0: |
365 |
> |
Comparison.GetYaxis().SetRangeUser(0,1.2*YMax) |
366 |
> |
else: #axis crosses y=0 |
367 |
> |
if abs(YMax) > abs(YMin): |
368 |
> |
Comparison.GetYaxis().SetRangeUser(-1.2*YMax,1.2*YMax) |
369 |
> |
else: |
370 |
> |
Comparison.GetYaxis().SetRangeUser(-1.2*YMin,1.2*YMin) |
371 |
> |
|
372 |
> |
Comparison.GetYaxis().SetNdivisions(205) |
373 |
> |
Comparison.Draw() |
374 |
|
|
375 |
|
Canvas.Write() |
376 |
|
|
414 |
|
inputFile = TFile(dataset_file) |
415 |
|
Histogram = inputFile.Get(rootDirectory+"/"+channel+"/"+histogramName).Clone() |
416 |
|
Histogram.SetDirectory(0) |
417 |
+ |
RebinFactor = int(arguments.rebinFactor) |
418 |
+ |
if arguments.rebinFactor and Histogram.GetNbinsX() >= RebinFactor*10 and Histogram.GetNbinsY() >= RebinFactor*10: |
419 |
+ |
Histogram.Rebin2D(RebinFactor) |
420 |
|
inputFile.Close() |
421 |
|
xAxisLabel = Histogram.GetXaxis().GetTitle() |
422 |
|
yAxisLabel = Histogram.GetYaxis().GetTitle() |
484 |
|
BgMCLegend.Draw() |
485 |
|
if(numSignalSamples is not 0): |
486 |
|
SignalMCLegend.Draw() |
487 |
< |
|
488 |
< |
LumiLabel.Draw() |
487 |
> |
if not arguments.normalizeToUnitArea or numDataSamples > 0: |
488 |
> |
LumiLabel.Draw() |
489 |
|
|
490 |
|
Canvas.Write() |
491 |
|
|