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

Comparing UserCode/OSUT3Analysis/Configuration/scripts/makeComparisonPlots.py (file contents):
Revision 1.1 by lantonel, Fri Jul 12 14:23:47 2013 UTC vs.
Revision 1.2 by lantonel, Tue Jul 16 14:33:28 2013 UTC

# Line 173 | Line 173 | def ratioHistogram( dataHist, mcHist, re
173      def groupErr(group):
174          Data,MC = [float(sum(hist.GetBinContent(i) for i in group)) for hist in [dataHist,mcHist]]
175          dataErr2,mcErr2 = [sum(hist.GetBinError(i)**2 for i in group) for hist in [dataHist,mcHist]]
176 <        return abs(math.sqrt( (dataErr2+mcErr2)/(Data-MC)**2 + mcErr2/MC**2 ) * (Data-MC)/MC) if Data and MC else 0
176 >        if MC > 0 and Data > 0 and Data != MC:
177 >            return abs(math.sqrt( (dataErr2+mcErr2)/(Data-MC)**2 + mcErr2/MC**2 ) * (Data-MC)/MC)
178 >        else:
179 >            return 0
180 >        
181  
182      def regroup(groups):
183          err,iG = max( (groupErr(g),groups.index(g)) for g in groups )
# Line 264 | Line 268 | def MakeOneDHist(histogramName):
268  
269          xAxisLabel = Histogram.GetXaxis().GetTitle()
270          unitIndex = xAxisLabel.find("[")
271 +        yAxisLabel = ""
272          if unitIndex is not -1: #x axis has a unit
273              yAxisLabel = "Entries / " + str(Histogram.GetXaxis().GetBinWidth(1)) + " " + xAxisLabel[unitIndex+1:-1]
274          else:
275              yAxisLabel = "Entries per bin (" + str(Histogram.GetXaxis().GetBinWidth(1)) + " width)"
276 +        if arguments.normalizeToUnitArea:
277 +            yAxisLabel = yAxisLabel + " (Unit Area Norm.)"
278 +
279          
280          if not arguments.makeFancy:
281              fullTitle = Histogram.GetTitle()
# Line 303 | Line 311 | def MakeOneDHist(histogramName):
311  
312      ### scaling histograms as per user's specifications
313      for histogram in Histograms:
314 <        if arguments.normalizeToUnitArea:
314 >        if arguments.normalizeToUnitArea and histogram.Integral() > 0:
315              histogram.Scale(1./histogram.Integral())
316  
317 +
318      ### formatting histograms and adding to legend
319      legendIndex = 0
320      for histogram in Histograms:
# Line 315 | Line 324 | def MakeOneDHist(histogramName):
324      ### finding the maximum value of anything going on the canvas, so we know how to set the y-axis
325      finalMax = 0
326      for histogram in Histograms:
327 <        if(histogram.GetMaximum() > finalMax):
328 <            finalMax = histogram.GetMaximum()
329 <    finalMax = 1.8*finalMax
327 >        currentMax = histogram.GetMaximum() + histogram.GetBinError(histogram.GetMaximumBin())
328 >        if(currentMax > finalMax):
329 >            finalMax = currentMax
330 >    finalMax = 1.5*finalMax
331      if arguments.setYMax:  
332          finalMax = float(arguments.setYMax)
333  
# Line 371 | Line 381 | def MakeOneDHist(histogramName):
381          histCounter = histCounter + 1
382  
383      #legend coordinates, empirically determined :-)
384 <    x_left = 0.6761745
385 <    x_right = 0.9328859
386 <    x_width = x_right - x_left
384 >
385 >    x_left = 0.1677852
386 >    x_right = 0.9647651
387 >    y_min = 0.6765734
388      y_max = 0.9
378    entry_height = 0.05
389  
390      Legend.SetX1NDC(x_left)
391 <    Legend.SetY1NDC(y_max-entry_height*(len(Histograms)))
391 >    Legend.SetY1NDC(y_min)
392      Legend.SetX2NDC(x_right)
393      Legend.SetY2NDC(y_max)
394      Legend.Draw()
395  
396  
397      # Deciding which text labels to draw and drawing them
388    drawLumiLabel = False
389    drawNormLabel = False
390    offsetNormLabel = False
398      drawHeaderLabel = False
399  
393    if not arguments.normalizeToUnitArea: #don't draw the lumi label if it's scaled to unit area
394        drawLumiLabel = True
395        #move the normalization label down before drawing if we drew the lumi. label
396        offsetNormLabel = True
397    if arguments.normalizeToUnitArea:
398        drawNormLabel = True
400      if arguments.makeFancy:
401          drawHeaderLabel = True
401        drawLumiLabel = False
402  
403      #now that flags are set, draw the appropriate labels
404  
405    if drawLumiLabel:
406        LumiLabel.Draw()
407
408    if drawNormLabel:
409        if offsetNormLabel:
410            NormLabel.SetY1NDC(topLeft_y_bottom-topLeft_y_offset)
411            NormLabel.SetY2NDC(topLeft_y_top-topLeft_y_offset)
412        else:
413            NormLabel.SetY1NDC(topLeft_y_bottom)
414            NormLabel.SetY2NDC(topLeft_y_top)
415        NormLabel.Draw()
416
405      if drawHeaderLabel:
406          HeaderLabel.Draw()
407  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines