ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makeSinglePlot.py
(Generate patch)

Comparing UserCode/OSUT3Analysis/Configuration/scripts/makeSinglePlot.py (file contents):
Revision 1.1 by lantonel, Fri Mar 8 14:18:42 2013 UTC vs.
Revision 1.12 by wulsin, Sun Jul 28 16:32:06 2013 UTC

# Line 2 | Line 2
2   import sys
3   import os
4   import re
5 + from optparse import OptionParser
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()
21
22
12  
13   ##set default plotting options
14   line_width = 2
15 <
15 > plotting_options = ""
16  
17   parser = OptionParser()
18   parser = set_commandline_arguments(parser)
19  
20 < (options, args) = parser.parse_args()
20 > parser.remove_option("-c")
21 > parser.remove_option("-n")
22 > parser.remove_option("-e")
23 > parser.remove_option("-r")
24 > parser.remove_option("-d")
25 > parser.remove_option("--2D")
26 >
27 >
28 > parser.add_option("--hist", action="store_true", dest="plot_hist", default=False,
29 >                  help="plot as hollow histograms instead of error bar crosses")
30 > parser.add_option("--line-width", dest="line_width",
31 >                  help="set line width (default is 2)")
32 > parser.add_option("--pdf", action="store_true", dest="plot_savePdf", default=False,
33 >                  help="save plot as pdf in addition")
34 >    
35 >
36 > (arguments, args) = parser.parse_args()
37 >
38 > if arguments.localConfig:
39 >    sys.path.insert(0,os.getcwd())
40 >    exec("from " + arguments.localConfig.rstrip('.py') + " import *")
41  
33 if options.localConfig:
34    sys.path.append(os.getcwd())
35    exec("from " + options.localConfig.rstrip('.py') + " import *")
42  
43   outputFileName = "simple_plot.root"
44 < if options.outputFileName:
45 <        outputFileName = options.outputFileName
44 > if arguments.outputFileName:
45 >        outputFileName = arguments.outputFileName
46          
47  
48 < condor_dir = set_condor_output_dir(options)
48 > if arguments.plot_hist:
49 >    plotting_options = plotting_options + "HIST"
50  
51  
52 < if options.normalizeToData and options.normalizeToUnitArea:
53 <    print "Conflicting normalizations requsted, will normalize to unit area"
54 <    options.normalizeToData = False
55 < if options.normalizeToData and options.noStack:
56 <    print "You have asked to scale non-stacked backgrounds to data.  This is a very strange request.  Will normalize to unit area instead"
57 <    options.normalizeToData = False
58 <    options.normalizeToUnitArea = True
52 > from ROOT import TFile, gROOT, gStyle, gDirectory, TStyle, THStack, TH1F, TCanvas, TString, TLegend, TArrow, THStack, TIter, TKey, TPaveLabel
53 > sys.argv = []
54 > gROOT.SetBatch()
55 > gStyle.SetOptStat(0)
56 > gStyle.SetCanvasBorderMode(0)
57 > gStyle.SetPadBorderMode(0)
58 > gStyle.SetPadColor(0)
59 > gStyle.SetCanvasColor(0)
60 > gStyle.SetTextFont(42)
61 > gROOT.ForceStyle()
62  
63  
64   outputFile = TFile(outputFileName, "RECREATE")
65  
56
66   datasets_needed = []
67   for histogram in input_histograms:
68      if histogram['dataset'] not in datasets_needed:
69          datasets_needed.append(histogram['dataset'])
70  
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
71  
72   Legend = TLegend(0.70,0.65,0.9,0.9)
73   Legend.SetBorderSize(0)
# Line 80 | Line 81 | finalMax = 0
81   Histograms = []
82   for histogram in input_histograms:
83  
84 <    fileName = condor_dir + "/" + histogram['dataset'] + ".root"
84 >    fileName = "condor/" + histogram['condor_dir'] + "/" + histogram['dataset'] + ".root"
85      if not os.path.exists(fileName):
86          continue
87      inputFile = TFile(fileName)
88      if inputFile.IsZombie() or not inputFile.GetNkeys():
89          continue
90      
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("")
96 >    fullTitle = Histogram.GetTitle()
97 >    splitTitle = fullTitle.split(":")
98 > #    print splitTitle
99 >    Histogram.SetTitle(splitTitle[1].lstrip(" "))
100 >
101      Histogram.SetMarkerColor(histogram['color'])
102      Histogram.SetLineColor(histogram['color'])
103      Histogram.SetLineWidth(line_width)
104      Histogram.SetFillStyle(0)
105 <    if(options.normalizeToUnitArea and Histogram.Integral() > 0):
105 >    if(arguments.normalizeToUnitArea and Histogram.Integral() > 0):
106          Histogram.Scale(1./Histogram.Integral())
107 +    if arguments.rebinFactor:
108 +        RebinFactor = int(arguments.rebinFactor)
109 +        if Histogram.GetNbinsX() >= RebinFactor*10:
110 +            Histogram.Rebin(RebinFactor)
111 +
112  
113      currentMax = Histogram.GetMaximum()
114      if currentMax > finalMax:
# Line 109 | Line 118 | for histogram in input_histograms:
118      Histograms.append(Histogram)
119  
120  
121 < Canvas = TCanvas("plot")
121 > Canvas = TCanvas(outputFileName.rstrip('.root'))
122  
123   counter = 0
124   for Histogram in Histograms:
125      if counter is 0:
126          Histogram.SetMaximum(1.1*finalMax)
127 <        Histogram.Draw()
127 >        Histogram.SetMinimum(0.0001)
128 >        Histogram.Draw(plotting_options)
129          
130      else:
131 <        Histogram.Draw("SAME")
131 >        Histogram.Draw(plotting_options+" SAME")
132      counter = counter+1
133  
134  
135   Legend.Draw()
136 < if options.normalizeToUnitArea:
136 > if arguments.normalizeToUnitArea:
137      NormLabel = TPaveLabel(0.1,0.75,0.35,0.85,"Scaled to unit area","NDC")
138      NormLabel.SetBorderSize(0)
139      NormLabel.SetFillColor(0)
# Line 132 | Line 142 | if options.normalizeToUnitArea:
142  
143   outputFile.cd()
144   Canvas.Write()
135        
145  
146 + if arguments.plot_savePdf:
147 +    pdfFileName = outputFileName.replace(".root", ".pdf")  
148 +    Canvas.SaveAs(pdfFileName)
149 +    print "Saved file:  " + pdfFileName  
150  
138 for dataset in datasets_needed:
139    dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset)
140    os.remove(dataset_file)
151  
152   outputFile.Close()        
153 + print "Saved plot in file: " + outputFileName  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines