2 |
|
import sys |
3 |
|
import os |
4 |
|
import re |
5 |
+ |
import argparse |
6 |
|
from array import * |
7 |
|
from decimal import * |
8 |
< |
from optparse import OptionParser |
8 |
> |
|
9 |
|
from OSUT3Analysis.Configuration.configurationOptions import * |
10 |
|
from OSUT3Analysis.Configuration.processingUtilities import * |
11 |
|
|
11 |
– |
from ROOT import TFile, gROOT, gStyle, gDirectory, TStyle, THStack, TH1F, TCanvas, TString, TLegend, TArrow, THStack, TIter, TKey, TPaveLabel |
12 |
|
|
13 |
< |
gROOT.SetBatch() |
14 |
< |
gStyle.SetOptStat(0) |
15 |
< |
gStyle.SetCanvasBorderMode(0) |
16 |
< |
gStyle.SetPadBorderMode(0) |
17 |
< |
gStyle.SetPadColor(0) |
18 |
< |
gStyle.SetCanvasColor(0) |
19 |
< |
gStyle.SetTextFont(42) |
20 |
< |
gROOT.ForceStyle() |
13 |
> |
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
##set default plotting options |
18 |
|
line_width = 2 |
19 |
+ |
plotting_options = "" |
20 |
|
|
21 |
< |
|
28 |
< |
parser = OptionParser() |
21 |
> |
parser = argparse.ArgumentParser() |
22 |
|
parser = set_commandline_arguments(parser) |
23 |
|
|
24 |
< |
(options, args) = parser.parse_args() |
24 |
> |
parser.add_argument("--hist", action="store_true", dest="plot_hist", default=False, |
25 |
> |
help="plot as hollow histograms instead of error bar crosses") |
26 |
> |
parser.add_argument("--line-width", dest="line_width", |
27 |
> |
help="set line width (default is 2)") |
28 |
> |
|
29 |
> |
|
30 |
> |
|
31 |
> |
arguments = parser.parse_args() |
32 |
|
|
33 |
< |
if options.localConfig: |
33 |
> |
parser.print_help() |
34 |
> |
|
35 |
> |
if arguments.localConfig: |
36 |
|
sys.path.append(os.getcwd()) |
37 |
< |
exec("from " + options.localConfig.rstrip('.py') + " import *") |
37 |
> |
exec("from " + arguments.localConfig.rstrip('.py') + " import *") |
38 |
|
|
39 |
|
outputFileName = "simple_plot.root" |
40 |
< |
if options.outputFileName: |
41 |
< |
outputFileName = options.outputFileName |
40 |
> |
if arguments.outputFileName: |
41 |
> |
outputFileName = arguments.outputFileName |
42 |
|
|
43 |
|
|
44 |
< |
condor_dir = set_condor_output_dir(options) |
44 |
> |
condor_dir = set_condor_output_dir(arguments) |
45 |
|
|
46 |
|
|
47 |
< |
if options.normalizeToData and options.normalizeToUnitArea: |
47 |
> |
if arguments.normalizeToData and arguments.normalizeToUnitArea: |
48 |
|
print "Conflicting normalizations requsted, will normalize to unit area" |
49 |
< |
options.normalizeToData = False |
50 |
< |
if options.normalizeToData and options.noStack: |
49 |
> |
arguments.normalizeToData = False |
50 |
> |
if arguments.normalizeToData and arguments.noStack: |
51 |
|
print "You have asked to scale non-stacked backgrounds to data. This is a very strange request. Will normalize to unit area instead" |
52 |
< |
options.normalizeToData = False |
53 |
< |
options.normalizeToUnitArea = True |
52 |
> |
arguments.normalizeToData = False |
53 |
> |
arguments.normalizeToUnitArea = True |
54 |
> |
|
55 |
> |
if arguments.plot_hist: |
56 |
> |
plotting_options = plotting_options + "HIST" |
57 |
> |
|
58 |
> |
|
59 |
> |
|
60 |
> |
from ROOT import TFile, gROOT, gStyle, gDirectory, TStyle, THStack, TH1F, TCanvas, TString, TLegend, TArrow, THStack, TIter, TKey, TPaveLabel |
61 |
> |
sys.argv = [] |
62 |
> |
gROOT.SetBatch() |
63 |
> |
gStyle.SetOptStat(0) |
64 |
> |
gStyle.SetCanvasBorderMode(0) |
65 |
> |
gStyle.SetPadBorderMode(0) |
66 |
> |
gStyle.SetPadColor(0) |
67 |
> |
gStyle.SetCanvasColor(0) |
68 |
> |
gStyle.SetTextFont(42) |
69 |
> |
gROOT.ForceStyle() |
70 |
|
|
71 |
|
|
72 |
|
outputFile = TFile(outputFileName, "RECREATE") |
116 |
|
Histogram.SetLineColor(histogram['color']) |
117 |
|
Histogram.SetLineWidth(line_width) |
118 |
|
Histogram.SetFillStyle(0) |
119 |
< |
if(options.normalizeToUnitArea and Histogram.Integral() > 0): |
119 |
> |
if(arguments.normalizeToUnitArea and Histogram.Integral() > 0): |
120 |
|
Histogram.Scale(1./Histogram.Integral()) |
121 |
|
|
122 |
|
currentMax = Histogram.GetMaximum() |
133 |
|
for Histogram in Histograms: |
134 |
|
if counter is 0: |
135 |
|
Histogram.SetMaximum(1.1*finalMax) |
136 |
< |
Histogram.Draw() |
136 |
> |
Histogram.Draw(plotting_options) |
137 |
|
|
138 |
|
else: |
139 |
< |
Histogram.Draw("SAME") |
139 |
> |
Histogram.Draw(plotting_options+" SAME") |
140 |
|
counter = counter+1 |
141 |
|
|
142 |
|
|
143 |
|
Legend.Draw() |
144 |
< |
if options.normalizeToUnitArea: |
144 |
> |
if arguments.normalizeToUnitArea: |
145 |
|
NormLabel = TPaveLabel(0.1,0.75,0.35,0.85,"Scaled to unit area","NDC") |
146 |
|
NormLabel.SetBorderSize(0) |
147 |
|
NormLabel.SetFillColor(0) |