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.5 by lantonel, Wed Mar 13 10:41:49 2013 UTC vs.
Revision 1.12 by wulsin, Sun Jul 28 16:32:06 2013 UTC

# Line 10 | Line 10 | from OSUT3Analysis.Configuration.configu
10   from OSUT3Analysis.Configuration.processingUtilities import *
11  
12  
13
14
15
16
13   ##set default plotting options
14   line_width = 2
15   plotting_options = ""
# Line 21 | Line 17 | plotting_options = ""
17   parser = OptionParser()
18   parser = set_commandline_arguments(parser)
19  
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.append(os.getcwd())
39 >    sys.path.insert(0,os.getcwd())
40      exec("from " + arguments.localConfig.rstrip('.py') + " import *")
41  
42 +
43   outputFileName = "simple_plot.root"
44   if arguments.outputFileName:
45          outputFileName = arguments.outputFileName
46          
47  
42 condor_dir = set_condor_output_dir(arguments)
43
44
45 if arguments.normalizeToData and arguments.normalizeToUnitArea:
46    print "Conflicting normalizations requsted, will normalize to unit area"
47    arguments.normalizeToData = False
48 if arguments.normalizeToData and arguments.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    arguments.normalizeToData = False
51    arguments.normalizeToUnitArea = True
52
48   if arguments.plot_hist:
49      plotting_options = plotting_options + "HIST"
50  
51  
57
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()
# Line 69 | Line 63 | gROOT.ForceStyle()
63  
64   outputFile = TFile(outputFileName, "RECREATE")
65  
72
66   datasets_needed = []
67   for histogram in input_histograms:
68      if histogram['dataset'] not in datasets_needed:
69          datasets_needed.append(histogram['dataset'])
70  
78 weight = intLumi / 10000.0
79 for dataset in datasets_needed:
80    dataset_file = "%s/%s.root" % (condor_dir,dataset)
81    if types[dataset] != "data":
82        os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", weight))
83    else:
84        os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", 1.0))
85
71  
72   Legend = TLegend(0.70,0.65,0.9,0.9)
73   Legend.SetBorderSize(0)
# Line 96 | 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      
106    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(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 125 | 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.SetMaximum(0)
127 >        Histogram.SetMinimum(0.0001)
128          Histogram.Draw(plotting_options)
129          
130      else:
# Line 149 | Line 142 | if arguments.normalizeToUnitArea:
142  
143   outputFile.cd()
144   Canvas.Write()
152        
145  
146 + if arguments.plot_savePdf:
147 +    pdfFileName = outputFileName.replace(".root", ".pdf")  
148 +    Canvas.SaveAs(pdfFileName)
149 +    print "Saved file:  " + pdfFileName  
150  
155 for dataset in datasets_needed:
156    dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset)
157    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