1 |
lantonel |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
import sys
|
3 |
|
|
import os
|
4 |
|
|
import re
|
5 |
lantonel |
1.3 |
from optparse import OptionParser
|
6 |
lantonel |
1.1 |
from array import *
|
7 |
|
|
from decimal import *
|
8 |
lantonel |
1.2 |
|
9 |
lantonel |
1.1 |
from OSUT3Analysis.Configuration.configurationOptions import *
|
10 |
|
|
from OSUT3Analysis.Configuration.processingUtilities import *
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
##set default plotting options
|
14 |
|
|
line_width = 2
|
15 |
lantonel |
1.2 |
plotting_options = ""
|
16 |
|
|
|
17 |
lantonel |
1.3 |
parser = OptionParser()
|
18 |
lantonel |
1.2 |
parser = set_commandline_arguments(parser)
|
19 |
|
|
|
20 |
lantonel |
1.11 |
parser.remove_option("-c")
|
21 |
|
|
parser.remove_option("-t")
|
22 |
|
|
parser.remove_option("-n")
|
23 |
|
|
parser.remove_option("-e")
|
24 |
|
|
parser.remove_option("-r")
|
25 |
|
|
parser.remove_option("-d")
|
26 |
|
|
parser.remove_option("--2D")
|
27 |
|
|
|
28 |
lantonel |
1.3 |
|
29 |
lantonel |
1.4 |
parser.add_option("--hist", action="store_true", dest="plot_hist", default=False,
|
30 |
lantonel |
1.2 |
help="plot as hollow histograms instead of error bar crosses")
|
31 |
lantonel |
1.4 |
parser.add_option("--line-width", dest="line_width",
|
32 |
lantonel |
1.2 |
help="set line width (default is 2)")
|
33 |
wulsin |
1.10 |
parser.add_option("--pdf", action="store_true", dest="plot_savePdf", default=False,
|
34 |
|
|
help="save plot as pdf in addition")
|
35 |
lantonel |
1.2 |
|
36 |
lantonel |
1.1 |
|
37 |
lantonel |
1.3 |
(arguments, args) = parser.parse_args()
|
38 |
lantonel |
1.1 |
|
39 |
lantonel |
1.2 |
if arguments.localConfig:
|
40 |
lantonel |
1.9 |
sys.path.insert(0,os.getcwd())
|
41 |
lantonel |
1.2 |
exec("from " + arguments.localConfig.rstrip('.py') + " import *")
|
42 |
lantonel |
1.11 |
|
43 |
lantonel |
1.1 |
|
44 |
|
|
outputFileName = "simple_plot.root"
|
45 |
lantonel |
1.2 |
if arguments.outputFileName:
|
46 |
|
|
outputFileName = arguments.outputFileName
|
47 |
lantonel |
1.1 |
|
48 |
|
|
|
49 |
lantonel |
1.2 |
if arguments.plot_hist:
|
50 |
|
|
plotting_options = plotting_options + "HIST"
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
from ROOT import TFile, gROOT, gStyle, gDirectory, TStyle, THStack, TH1F, TCanvas, TString, TLegend, TArrow, THStack, TIter, TKey, TPaveLabel
|
54 |
|
|
sys.argv = []
|
55 |
|
|
gROOT.SetBatch()
|
56 |
|
|
gStyle.SetOptStat(0)
|
57 |
|
|
gStyle.SetCanvasBorderMode(0)
|
58 |
|
|
gStyle.SetPadBorderMode(0)
|
59 |
|
|
gStyle.SetPadColor(0)
|
60 |
|
|
gStyle.SetCanvasColor(0)
|
61 |
|
|
gStyle.SetTextFont(42)
|
62 |
|
|
gROOT.ForceStyle()
|
63 |
lantonel |
1.1 |
|
64 |
|
|
|
65 |
|
|
outputFile = TFile(outputFileName, "RECREATE")
|
66 |
|
|
|
67 |
|
|
datasets_needed = []
|
68 |
|
|
for histogram in input_histograms:
|
69 |
|
|
if histogram['dataset'] not in datasets_needed:
|
70 |
|
|
datasets_needed.append(histogram['dataset'])
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
Legend = TLegend(0.70,0.65,0.9,0.9)
|
74 |
|
|
Legend.SetBorderSize(0)
|
75 |
|
|
Legend.SetFillColor(0)
|
76 |
|
|
Legend.SetFillStyle(0)
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
finalMax = 0
|
81 |
|
|
|
82 |
|
|
Histograms = []
|
83 |
|
|
for histogram in input_histograms:
|
84 |
|
|
|
85 |
lantonel |
1.11 |
fileName = "condor/" + histogram['condor_dir'] + "/" + histogram['dataset'] + ".root"
|
86 |
lantonel |
1.1 |
if not os.path.exists(fileName):
|
87 |
|
|
continue
|
88 |
|
|
inputFile = TFile(fileName)
|
89 |
|
|
if inputFile.IsZombie() or not inputFile.GetNkeys():
|
90 |
|
|
continue
|
91 |
|
|
|
92 |
|
|
Histogram = inputFile.Get("OSUAnalysis/"+histogram['channel']+"/"+histogram['name']).Clone()
|
93 |
|
|
Histogram.SetDirectory(0)
|
94 |
|
|
inputFile.Close()
|
95 |
|
|
|
96 |
|
|
|
97 |
lantonel |
1.11 |
fullTitle = Histogram.GetTitle()
|
98 |
|
|
splitTitle = fullTitle.split(":")
|
99 |
|
|
# print splitTitle
|
100 |
|
|
Histogram.SetTitle(splitTitle[1].lstrip(" "))
|
101 |
|
|
|
102 |
lantonel |
1.1 |
Histogram.SetMarkerColor(histogram['color'])
|
103 |
|
|
Histogram.SetLineColor(histogram['color'])
|
104 |
|
|
Histogram.SetLineWidth(line_width)
|
105 |
|
|
Histogram.SetFillStyle(0)
|
106 |
lantonel |
1.2 |
if(arguments.normalizeToUnitArea and Histogram.Integral() > 0):
|
107 |
lantonel |
1.1 |
Histogram.Scale(1./Histogram.Integral())
|
108 |
lantonel |
1.11 |
if arguments.rebinFactor:
|
109 |
|
|
RebinFactor = int(arguments.rebinFactor)
|
110 |
|
|
if Histogram.GetNbinsX() >= RebinFactor*10:
|
111 |
|
|
Histogram.Rebin(RebinFactor)
|
112 |
|
|
|
113 |
lantonel |
1.1 |
|
114 |
|
|
currentMax = Histogram.GetMaximum()
|
115 |
|
|
if currentMax > finalMax:
|
116 |
|
|
finalMax = currentMax
|
117 |
|
|
|
118 |
|
|
Legend.AddEntry(Histogram,histogram['legend_entry'],"L")
|
119 |
|
|
Histograms.append(Histogram)
|
120 |
|
|
|
121 |
|
|
|
122 |
lantonel |
1.11 |
Canvas = TCanvas(outputFileName.rstrip('.root'))
|
123 |
lantonel |
1.1 |
|
124 |
|
|
counter = 0
|
125 |
|
|
for Histogram in Histograms:
|
126 |
|
|
if counter is 0:
|
127 |
|
|
Histogram.SetMaximum(1.1*finalMax)
|
128 |
lantonel |
1.8 |
Histogram.SetMinimum(0.0001)
|
129 |
lantonel |
1.2 |
Histogram.Draw(plotting_options)
|
130 |
lantonel |
1.1 |
|
131 |
|
|
else:
|
132 |
lantonel |
1.2 |
Histogram.Draw(plotting_options+" SAME")
|
133 |
lantonel |
1.1 |
counter = counter+1
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
Legend.Draw()
|
137 |
lantonel |
1.2 |
if arguments.normalizeToUnitArea:
|
138 |
lantonel |
1.1 |
NormLabel = TPaveLabel(0.1,0.75,0.35,0.85,"Scaled to unit area","NDC")
|
139 |
|
|
NormLabel.SetBorderSize(0)
|
140 |
|
|
NormLabel.SetFillColor(0)
|
141 |
|
|
NormLabel.SetFillStyle(0)
|
142 |
|
|
NormLabel.Draw()
|
143 |
|
|
|
144 |
|
|
outputFile.cd()
|
145 |
|
|
Canvas.Write()
|
146 |
wulsin |
1.10 |
|
147 |
|
|
if arguments.plot_savePdf:
|
148 |
|
|
pdfFileName = outputFileName.replace(".root", ".pdf")
|
149 |
|
|
Canvas.SaveAs(pdfFileName)
|
150 |
|
|
print "Saved file: " + pdfFileName
|
151 |
lantonel |
1.1 |
|
152 |
|
|
|
153 |
|
|
outputFile.Close()
|
154 |
wulsin |
1.10 |
print "Saved plot in file: " + outputFileName
|