--- UserCode/OSUT3Analysis/Configuration/scripts/makeSinglePlot.py 2013/03/08 14:18:42 1.1 +++ UserCode/OSUT3Analysis/Configuration/scripts/makeSinglePlot.py 2013/03/12 21:10:44 1.2 @@ -2,53 +2,71 @@ import sys import os import re +import argparse from array import * from decimal import * -from optparse import OptionParser + from OSUT3Analysis.Configuration.configurationOptions import * from OSUT3Analysis.Configuration.processingUtilities import * -from ROOT import TFile, gROOT, gStyle, gDirectory, TStyle, THStack, TH1F, TCanvas, TString, TLegend, TArrow, THStack, TIter, TKey, TPaveLabel -gROOT.SetBatch() -gStyle.SetOptStat(0) -gStyle.SetCanvasBorderMode(0) -gStyle.SetPadBorderMode(0) -gStyle.SetPadColor(0) -gStyle.SetCanvasColor(0) -gStyle.SetTextFont(42) -gROOT.ForceStyle() + ##set default plotting options line_width = 2 +plotting_options = "" - -parser = OptionParser() +parser = argparse.ArgumentParser() parser = set_commandline_arguments(parser) -(options, args) = parser.parse_args() +parser.add_argument("--hist", action="store_true", dest="plot_hist", default=False, + help="plot as hollow histograms instead of error bar crosses") +parser.add_argument("--line-width", dest="line_width", + help="set line width (default is 2)") + + + +arguments = parser.parse_args() -if options.localConfig: +parser.print_help() + +if arguments.localConfig: sys.path.append(os.getcwd()) - exec("from " + options.localConfig.rstrip('.py') + " import *") + exec("from " + arguments.localConfig.rstrip('.py') + " import *") outputFileName = "simple_plot.root" -if options.outputFileName: - outputFileName = options.outputFileName +if arguments.outputFileName: + outputFileName = arguments.outputFileName -condor_dir = set_condor_output_dir(options) +condor_dir = set_condor_output_dir(arguments) -if options.normalizeToData and options.normalizeToUnitArea: +if arguments.normalizeToData and arguments.normalizeToUnitArea: print "Conflicting normalizations requsted, will normalize to unit area" - options.normalizeToData = False -if options.normalizeToData and options.noStack: + 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" - options.normalizeToData = False - options.normalizeToUnitArea = True + 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() +gStyle.SetOptStat(0) +gStyle.SetCanvasBorderMode(0) +gStyle.SetPadBorderMode(0) +gStyle.SetPadColor(0) +gStyle.SetCanvasColor(0) +gStyle.SetTextFont(42) +gROOT.ForceStyle() outputFile = TFile(outputFileName, "RECREATE") @@ -98,7 +116,7 @@ for histogram in input_histograms: Histogram.SetLineColor(histogram['color']) Histogram.SetLineWidth(line_width) Histogram.SetFillStyle(0) - if(options.normalizeToUnitArea and Histogram.Integral() > 0): + if(arguments.normalizeToUnitArea and Histogram.Integral() > 0): Histogram.Scale(1./Histogram.Integral()) currentMax = Histogram.GetMaximum() @@ -115,15 +133,15 @@ counter = 0 for Histogram in Histograms: if counter is 0: Histogram.SetMaximum(1.1*finalMax) - Histogram.Draw() + Histogram.Draw(plotting_options) else: - Histogram.Draw("SAME") + Histogram.Draw(plotting_options+" SAME") counter = counter+1 Legend.Draw() -if options.normalizeToUnitArea: +if arguments.normalizeToUnitArea: NormLabel = TPaveLabel(0.1,0.75,0.35,0.85,"Scaled to unit area","NDC") NormLabel.SetBorderSize(0) NormLabel.SetFillColor(0)