ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makeEfficiencyComparisonPlot.py
Revision: 1.1
Committed: Fri Apr 19 08:55:53 2013 UTC (12 years ago) by qpython
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, HEAD
Log Message:
first commitment, this macro can be used to do and compare efficiency plots

File Contents

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