ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makeSinglePlot.py
Revision: 1.11
Committed: Thu Apr 11 12:34:33 2013 UTC (12 years ago) by lantonel
Content type: text/x-python
Branch: MAIN
CVS Tags: V02-03-02, V02-03-01, V02-03-00, V02-02-00, V02-01-01, V02-01-00, V01-01-00, V01-00-01, V01-00-00, V02-00-00, V00-00-01, V00-01-00
Changes since 1.10: +21 -29 lines
Log Message:
added some options, took out reweighting, and require user to specify condor dir in config file

File Contents

# Content
1 #!/usr/bin/env python
2 import sys
3 import os
4 import re
5 from optparse import OptionParser
6 from array import *
7 from decimal import *
8
9 from OSUT3Analysis.Configuration.configurationOptions import *
10 from OSUT3Analysis.Configuration.processingUtilities import *
11
12
13 ##set default plotting options
14 line_width = 2
15 plotting_options = ""
16
17 parser = OptionParser()
18 parser = set_commandline_arguments(parser)
19
20 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
29 parser.add_option("--hist", action="store_true", dest="plot_hist", default=False,
30 help="plot as hollow histograms instead of error bar crosses")
31 parser.add_option("--line-width", dest="line_width",
32 help="set line width (default is 2)")
33 parser.add_option("--pdf", action="store_true", dest="plot_savePdf", default=False,
34 help="save plot as pdf in addition")
35
36
37 (arguments, args) = parser.parse_args()
38
39 if arguments.localConfig:
40 sys.path.insert(0,os.getcwd())
41 exec("from " + arguments.localConfig.rstrip('.py') + " import *")
42
43
44 outputFileName = "simple_plot.root"
45 if arguments.outputFileName:
46 outputFileName = arguments.outputFileName
47
48
49 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
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 fileName = "condor/" + histogram['condor_dir'] + "/" + histogram['dataset'] + ".root"
86 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 fullTitle = Histogram.GetTitle()
98 splitTitle = fullTitle.split(":")
99 # print splitTitle
100 Histogram.SetTitle(splitTitle[1].lstrip(" "))
101
102 Histogram.SetMarkerColor(histogram['color'])
103 Histogram.SetLineColor(histogram['color'])
104 Histogram.SetLineWidth(line_width)
105 Histogram.SetFillStyle(0)
106 if(arguments.normalizeToUnitArea and Histogram.Integral() > 0):
107 Histogram.Scale(1./Histogram.Integral())
108 if arguments.rebinFactor:
109 RebinFactor = int(arguments.rebinFactor)
110 if Histogram.GetNbinsX() >= RebinFactor*10:
111 Histogram.Rebin(RebinFactor)
112
113
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 Canvas = TCanvas(outputFileName.rstrip('.root'))
123
124 counter = 0
125 for Histogram in Histograms:
126 if counter is 0:
127 Histogram.SetMaximum(1.1*finalMax)
128 Histogram.SetMinimum(0.0001)
129 Histogram.Draw(plotting_options)
130
131 else:
132 Histogram.Draw(plotting_options+" SAME")
133 counter = counter+1
134
135
136 Legend.Draw()
137 if arguments.normalizeToUnitArea:
138 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
147 if arguments.plot_savePdf:
148 pdfFileName = outputFileName.replace(".root", ".pdf")
149 Canvas.SaveAs(pdfFileName)
150 print "Saved file: " + pdfFileName
151
152
153 outputFile.Close()
154 print "Saved plot in file: " + outputFileName