1 |
#!/usr/bin/env python
|
2 |
import sys
|
3 |
import os
|
4 |
import re
|
5 |
from array import *
|
6 |
from decimal import *
|
7 |
from optparse import OptionParser
|
8 |
from OSUT3Analysis.Configuration.configurationOptions import *
|
9 |
from OSUT3Analysis.Configuration.processingUtilities import *
|
10 |
|
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()
|
21 |
|
22 |
|
23 |
|
24 |
##set default plotting options
|
25 |
line_width = 2
|
26 |
|
27 |
|
28 |
parser = OptionParser()
|
29 |
parser = set_commandline_arguments(parser)
|
30 |
|
31 |
(options, args) = parser.parse_args()
|
32 |
|
33 |
if options.localConfig:
|
34 |
sys.path.append(os.getcwd())
|
35 |
exec("from " + options.localConfig.rstrip('.py') + " import *")
|
36 |
|
37 |
outputFileName = "simple_plot.root"
|
38 |
if options.outputFileName:
|
39 |
outputFileName = options.outputFileName
|
40 |
|
41 |
|
42 |
condor_dir = set_condor_output_dir(options)
|
43 |
|
44 |
|
45 |
if options.normalizeToData and options.normalizeToUnitArea:
|
46 |
print "Conflicting normalizations requsted, will normalize to unit area"
|
47 |
options.normalizeToData = False
|
48 |
if options.normalizeToData and options.noStack:
|
49 |
print "You have asked to scale non-stacked backgrounds to data. This is a very strange request. Will normalize to unit area instead"
|
50 |
options.normalizeToData = False
|
51 |
options.normalizeToUnitArea = True
|
52 |
|
53 |
|
54 |
outputFile = TFile(outputFileName, "RECREATE")
|
55 |
|
56 |
|
57 |
datasets_needed = []
|
58 |
for histogram in input_histograms:
|
59 |
if histogram['dataset'] not in datasets_needed:
|
60 |
datasets_needed.append(histogram['dataset'])
|
61 |
|
62 |
weight = intLumi / 10000.0
|
63 |
for dataset in datasets_needed:
|
64 |
dataset_file = "%s/%s.root" % (condor_dir,dataset)
|
65 |
if types[dataset] != "data":
|
66 |
os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", weight))
|
67 |
else:
|
68 |
os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", 1.0))
|
69 |
|
70 |
|
71 |
Legend = TLegend(0.70,0.65,0.9,0.9)
|
72 |
Legend.SetBorderSize(0)
|
73 |
Legend.SetFillColor(0)
|
74 |
Legend.SetFillStyle(0)
|
75 |
|
76 |
|
77 |
|
78 |
finalMax = 0
|
79 |
|
80 |
Histograms = []
|
81 |
for histogram in input_histograms:
|
82 |
|
83 |
fileName = condor_dir + "/" + histogram['dataset'] + ".root"
|
84 |
if not os.path.exists(fileName):
|
85 |
continue
|
86 |
inputFile = TFile(fileName)
|
87 |
if inputFile.IsZombie() or not inputFile.GetNkeys():
|
88 |
continue
|
89 |
|
90 |
print "OSUAnalysis/"+histogram['channel']+"/"+histogram['name']
|
91 |
Histogram = inputFile.Get("OSUAnalysis/"+histogram['channel']+"/"+histogram['name']).Clone()
|
92 |
Histogram.SetDirectory(0)
|
93 |
inputFile.Close()
|
94 |
|
95 |
|
96 |
Histogram.SetTitle("")
|
97 |
Histogram.SetMarkerColor(histogram['color'])
|
98 |
Histogram.SetLineColor(histogram['color'])
|
99 |
Histogram.SetLineWidth(line_width)
|
100 |
Histogram.SetFillStyle(0)
|
101 |
if(options.normalizeToUnitArea and Histogram.Integral() > 0):
|
102 |
Histogram.Scale(1./Histogram.Integral())
|
103 |
|
104 |
currentMax = Histogram.GetMaximum()
|
105 |
if currentMax > finalMax:
|
106 |
finalMax = currentMax
|
107 |
|
108 |
Legend.AddEntry(Histogram,histogram['legend_entry'],"L")
|
109 |
Histograms.append(Histogram)
|
110 |
|
111 |
|
112 |
Canvas = TCanvas("plot")
|
113 |
|
114 |
counter = 0
|
115 |
for Histogram in Histograms:
|
116 |
if counter is 0:
|
117 |
Histogram.SetMaximum(1.1*finalMax)
|
118 |
Histogram.Draw()
|
119 |
|
120 |
else:
|
121 |
Histogram.Draw("SAME")
|
122 |
counter = counter+1
|
123 |
|
124 |
|
125 |
Legend.Draw()
|
126 |
if options.normalizeToUnitArea:
|
127 |
NormLabel = TPaveLabel(0.1,0.75,0.35,0.85,"Scaled to unit area","NDC")
|
128 |
NormLabel.SetBorderSize(0)
|
129 |
NormLabel.SetFillColor(0)
|
130 |
NormLabel.SetFillStyle(0)
|
131 |
NormLabel.Draw()
|
132 |
|
133 |
outputFile.cd()
|
134 |
Canvas.Write()
|
135 |
|
136 |
|
137 |
|
138 |
for dataset in datasets_needed:
|
139 |
dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset)
|
140 |
os.remove(dataset_file)
|
141 |
|
142 |
outputFile.Close()
|