ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/Ratio.py
Revision: 1.2
Committed: Thu Oct 4 13:02:23 2012 UTC (12 years, 7 months ago) by nmohr
Content type: text/x-python
Branch: MAIN
CVS Tags: hcpPreApp, hcpPreAppFreeze
Changes since 1.1: +3 -8 lines
Log Message:
Plotting style

File Contents

# User Rev Content
1 peller 1.1 import ROOT
2     def renewHist(hist,reference,min,max):
3     theHist = hist.Clone()
4     theReference = reference.Clone()
5     theHist.SetLineWidth(1)
6     theHist.SetMarkerSize(1)
7     return theHist, theReference
8     nBins = int((max-min)/hist.GetBinWidth(1))
9     theHist = ROOT.TH1F('hist%s' %(hist.GetName()), 'hist%s' %(hist.GetName()), nBins, min, max)
10     theHist.SetDefaultSumw2(ROOT.kTRUE)
11     theReference = ROOT.TH1F('reference%s' %(hist.GetName()), 'reference%s' %(hist.GetName()), nBins, min, max)
12     theReference.SetDefaultSumw2(ROOT.kTRUE)
13     for i in range(0,hist.GetNbinsX()+1):
14     weAreAt = hist.GetBinCenter(i)
15     if hist.GetBinLowEdge(i) < min: continue
16     if hist.GetBinLowEdge(i)+hist.GetBinWidth(i) > max: continue
17     theHist.SetBinContent(theHist.FindBin(weAreAt),hist.GetBinContent(i))
18     theHist.SetBinError(theHist.FindBin(weAreAt),hist.GetBinError(i))
19     for i in range(0,reference.GetNbinsX()+1):
20     weAreAt = reference.GetBinCenter(i)
21     if reference.GetBinLowEdge(i) < min: continue
22     if reference.GetBinLowEdge(i)+reference.GetBinWidth(i) > max: continue
23     theReference.SetBinContent(theReference.FindBin(weAreAt),reference.GetBinContent(i))
24     theReference.SetBinError(theReference.FindBin(weAreAt),reference.GetBinError(i))
25     return theHist, theReference
26    
27     def getRatio(hist,reference,min,max,yTitle="",maxUncertainty = 0.2,restrict=True):
28     from ROOT import gROOT
29     theHist, theReference = renewHist(hist,reference,min,max)
30 nmohr 1.2 ROOT.gSystem.Load('./Ratio_C.so')
31 peller 1.1 from ROOT import coolRatio
32     thePlotter = coolRatio()
33     theRatio = thePlotter.make_rebinned_ratios(theHist,theReference,maxUncertainty,False,0)
34     refError = thePlotter.make_rebinned_ratios(theHist,theReference,maxUncertainty,False,1)
35     theRatio.GetXaxis().SetRangeUser(min,max)
36     if restrict:
37     theRatio.SetMinimum(0.01)
38     theRatio.SetMaximum(2.49)
39     else:
40     theRatio.SetMinimum(int(theRatio.GetMinimum()))
41     theRatio.SetMaximum(int(theRatio.GetMaximum()*1.5))
42     #theRatio.GetYaxis().SetNdivisions(104)
43     theRatio.GetYaxis().SetNdivisions(505)
44     theRatio.GetYaxis().SetTitle("Ratio")
45     theRatio.GetYaxis().SetTitleSize(ROOT.gStyle.GetTitleSize()*2.2)
46     theRatio.GetYaxis().SetTitleOffset(0.6)
47     theRatio.GetYaxis().SetLabelSize(ROOT.gStyle.GetLabelSize() * 2.2)
48     theRatio.GetXaxis().SetTitleSize(ROOT.gStyle.GetTitleSize()*2.2)
49     theRatio.GetXaxis().SetLabelSize(ROOT.gStyle.GetLabelSize() * 2.2)
50     theRatio.GetYaxis().SetTitleOffset(0.4)
51     theRatio.GetYaxis().CenterTitle(ROOT.kTRUE)
52     theRatio.GetYaxis().SetDrawOption("M")
53     theRatio.SetXTitle(yTitle)
54 nmohr 1.2 theRatio.SetYTitle("Data/MC")
55     return theRatio, refError
56 peller 1.1