--- UserCode/OSUT3Analysis/Configuration/scripts/makeComparisonPlots.py 2013/07/12 14:23:47 1.1 +++ UserCode/OSUT3Analysis/Configuration/scripts/makeComparisonPlots.py 2013/07/16 14:33:28 1.2 @@ -173,7 +173,11 @@ def ratioHistogram( dataHist, mcHist, re def groupErr(group): Data,MC = [float(sum(hist.GetBinContent(i) for i in group)) for hist in [dataHist,mcHist]] dataErr2,mcErr2 = [sum(hist.GetBinError(i)**2 for i in group) for hist in [dataHist,mcHist]] - return abs(math.sqrt( (dataErr2+mcErr2)/(Data-MC)**2 + mcErr2/MC**2 ) * (Data-MC)/MC) if Data and MC else 0 + if MC > 0 and Data > 0 and Data != MC: + return abs(math.sqrt( (dataErr2+mcErr2)/(Data-MC)**2 + mcErr2/MC**2 ) * (Data-MC)/MC) + else: + return 0 + def regroup(groups): err,iG = max( (groupErr(g),groups.index(g)) for g in groups ) @@ -264,10 +268,14 @@ def MakeOneDHist(histogramName): xAxisLabel = Histogram.GetXaxis().GetTitle() unitIndex = xAxisLabel.find("[") + yAxisLabel = "" if unitIndex is not -1: #x axis has a unit yAxisLabel = "Entries / " + str(Histogram.GetXaxis().GetBinWidth(1)) + " " + xAxisLabel[unitIndex+1:-1] else: yAxisLabel = "Entries per bin (" + str(Histogram.GetXaxis().GetBinWidth(1)) + " width)" + if arguments.normalizeToUnitArea: + yAxisLabel = yAxisLabel + " (Unit Area Norm.)" + if not arguments.makeFancy: fullTitle = Histogram.GetTitle() @@ -303,9 +311,10 @@ def MakeOneDHist(histogramName): ### scaling histograms as per user's specifications for histogram in Histograms: - if arguments.normalizeToUnitArea: + if arguments.normalizeToUnitArea and histogram.Integral() > 0: histogram.Scale(1./histogram.Integral()) + ### formatting histograms and adding to legend legendIndex = 0 for histogram in Histograms: @@ -315,9 +324,10 @@ def MakeOneDHist(histogramName): ### finding the maximum value of anything going on the canvas, so we know how to set the y-axis finalMax = 0 for histogram in Histograms: - if(histogram.GetMaximum() > finalMax): - finalMax = histogram.GetMaximum() - finalMax = 1.8*finalMax + currentMax = histogram.GetMaximum() + histogram.GetBinError(histogram.GetMaximumBin()) + if(currentMax > finalMax): + finalMax = currentMax + finalMax = 1.5*finalMax if arguments.setYMax: finalMax = float(arguments.setYMax) @@ -371,49 +381,27 @@ def MakeOneDHist(histogramName): histCounter = histCounter + 1 #legend coordinates, empirically determined :-) - x_left = 0.6761745 - x_right = 0.9328859 - x_width = x_right - x_left + + x_left = 0.1677852 + x_right = 0.9647651 + y_min = 0.6765734 y_max = 0.9 - entry_height = 0.05 Legend.SetX1NDC(x_left) - Legend.SetY1NDC(y_max-entry_height*(len(Histograms))) + Legend.SetY1NDC(y_min) Legend.SetX2NDC(x_right) Legend.SetY2NDC(y_max) Legend.Draw() # Deciding which text labels to draw and drawing them - drawLumiLabel = False - drawNormLabel = False - offsetNormLabel = False drawHeaderLabel = False - if not arguments.normalizeToUnitArea: #don't draw the lumi label if it's scaled to unit area - drawLumiLabel = True - #move the normalization label down before drawing if we drew the lumi. label - offsetNormLabel = True - if arguments.normalizeToUnitArea: - drawNormLabel = True if arguments.makeFancy: drawHeaderLabel = True - drawLumiLabel = False #now that flags are set, draw the appropriate labels - if drawLumiLabel: - LumiLabel.Draw() - - if drawNormLabel: - if offsetNormLabel: - NormLabel.SetY1NDC(topLeft_y_bottom-topLeft_y_offset) - NormLabel.SetY2NDC(topLeft_y_top-topLeft_y_offset) - else: - NormLabel.SetY1NDC(topLeft_y_bottom) - NormLabel.SetY2NDC(topLeft_y_top) - NormLabel.Draw() - if drawHeaderLabel: HeaderLabel.Draw()