--- UserCode/OSUT3Analysis/Configuration/scripts/makeSinglePlot.py 2013/03/13 10:41:49 1.5 +++ UserCode/OSUT3Analysis/Configuration/scripts/makeSinglePlot.py 2013/07/28 16:32:06 1.12 @@ -10,10 +10,6 @@ from OSUT3Analysis.Configuration.configu from OSUT3Analysis.Configuration.processingUtilities import * - - - - ##set default plotting options line_width = 2 plotting_options = "" @@ -21,40 +17,38 @@ plotting_options = "" parser = OptionParser() parser = set_commandline_arguments(parser) +parser.remove_option("-c") +parser.remove_option("-n") +parser.remove_option("-e") +parser.remove_option("-r") +parser.remove_option("-d") +parser.remove_option("--2D") + parser.add_option("--hist", action="store_true", dest="plot_hist", default=False, help="plot as hollow histograms instead of error bar crosses") parser.add_option("--line-width", dest="line_width", help="set line width (default is 2)") +parser.add_option("--pdf", action="store_true", dest="plot_savePdf", default=False, + help="save plot as pdf in addition") (arguments, args) = parser.parse_args() if arguments.localConfig: - sys.path.append(os.getcwd()) + sys.path.insert(0,os.getcwd()) exec("from " + arguments.localConfig.rstrip('.py') + " import *") + outputFileName = "simple_plot.root" if arguments.outputFileName: outputFileName = arguments.outputFileName -condor_dir = set_condor_output_dir(arguments) - - -if arguments.normalizeToData and arguments.normalizeToUnitArea: - print "Conflicting normalizations requsted, will normalize to unit area" - arguments.normalizeToData = False -if arguments.normalizeToData and arguments.noStack: - print "You have asked to scale non-stacked backgrounds to data. This is a very strange request. Will normalize to unit area instead" - arguments.normalizeToData = False - arguments.normalizeToUnitArea = True - if arguments.plot_hist: plotting_options = plotting_options + "HIST" - from ROOT import TFile, gROOT, gStyle, gDirectory, TStyle, THStack, TH1F, TCanvas, TString, TLegend, TArrow, THStack, TIter, TKey, TPaveLabel sys.argv = [] gROOT.SetBatch() @@ -69,20 +63,11 @@ gROOT.ForceStyle() outputFile = TFile(outputFileName, "RECREATE") - datasets_needed = [] for histogram in input_histograms: if histogram['dataset'] not in datasets_needed: datasets_needed.append(histogram['dataset']) -weight = intLumi / 10000.0 -for dataset in datasets_needed: - dataset_file = "%s/%s.root" % (condor_dir,dataset) - if types[dataset] != "data": - os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", weight)) - else: - os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", 1.0)) - Legend = TLegend(0.70,0.65,0.9,0.9) Legend.SetBorderSize(0) @@ -96,26 +81,34 @@ finalMax = 0 Histograms = [] for histogram in input_histograms: - fileName = condor_dir + "/" + histogram['dataset'] + ".root" + fileName = "condor/" + histogram['condor_dir'] + "/" + histogram['dataset'] + ".root" if not os.path.exists(fileName): continue inputFile = TFile(fileName) if inputFile.IsZombie() or not inputFile.GetNkeys(): continue - print "OSUAnalysis/"+histogram['channel']+"/"+histogram['name'] Histogram = inputFile.Get("OSUAnalysis/"+histogram['channel']+"/"+histogram['name']).Clone() Histogram.SetDirectory(0) inputFile.Close() - Histogram.SetTitle("") + fullTitle = Histogram.GetTitle() + splitTitle = fullTitle.split(":") +# print splitTitle + Histogram.SetTitle(splitTitle[1].lstrip(" ")) + Histogram.SetMarkerColor(histogram['color']) Histogram.SetLineColor(histogram['color']) Histogram.SetLineWidth(line_width) Histogram.SetFillStyle(0) if(arguments.normalizeToUnitArea and Histogram.Integral() > 0): Histogram.Scale(1./Histogram.Integral()) + if arguments.rebinFactor: + RebinFactor = int(arguments.rebinFactor) + if Histogram.GetNbinsX() >= RebinFactor*10: + Histogram.Rebin(RebinFactor) + currentMax = Histogram.GetMaximum() if currentMax > finalMax: @@ -125,13 +118,13 @@ for histogram in input_histograms: Histograms.append(Histogram) -Canvas = TCanvas("plot") +Canvas = TCanvas(outputFileName.rstrip('.root')) counter = 0 for Histogram in Histograms: if counter is 0: Histogram.SetMaximum(1.1*finalMax) - Histogram.SetMaximum(0) + Histogram.SetMinimum(0.0001) Histogram.Draw(plotting_options) else: @@ -149,11 +142,12 @@ if arguments.normalizeToUnitArea: outputFile.cd() Canvas.Write() - +if arguments.plot_savePdf: + pdfFileName = outputFileName.replace(".root", ".pdf") + Canvas.SaveAs(pdfFileName) + print "Saved file: " + pdfFileName -for dataset in datasets_needed: - dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset) - os.remove(dataset_file) outputFile.Close() +print "Saved plot in file: " + outputFileName