ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/myutils/Ratio.py
Revision: 1.3
Committed: Fri Jul 19 09:53:44 2013 UTC (11 years, 9 months ago) by nmohr
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +2 -0 lines
Error occurred while calculating annotation data.
Log Message:
For git migration

File Contents

# Content
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 = 1000.000,restrict=True):
28 from ROOT import gROOT
29 theHist, theReference = renewHist(hist,reference,min,max)
30 ROOT.gSystem.Load('./myutils/Ratio_C.so')
31 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 #theRatio.SetMinimum(0.35)
40 #theRatio.SetMaximum(1.8)
41 else:
42 theRatio.SetMinimum(int(theRatio.GetMinimum()))
43 theRatio.SetMaximum(int(theRatio.GetMaximum()*1.5))
44 #theRatio.GetYaxis().SetNdivisions(104)
45 theRatio.GetYaxis().SetNdivisions(505)
46 theRatio.GetYaxis().SetTitle("Ratio")
47 theRatio.GetYaxis().SetTitleSize(ROOT.gStyle.GetTitleSize()*2.2)
48 theRatio.GetYaxis().SetTitleOffset(0.6)
49 theRatio.GetYaxis().SetLabelSize(ROOT.gStyle.GetLabelSize() * 2.2)
50 theRatio.GetXaxis().SetTitleSize(ROOT.gStyle.GetTitleSize()*2.2)
51 theRatio.GetXaxis().SetLabelSize(ROOT.gStyle.GetLabelSize() * 2.2)
52 theRatio.GetYaxis().SetTitleOffset(0.4)
53 theRatio.GetYaxis().CenterTitle(ROOT.kTRUE)
54 theRatio.GetYaxis().SetDrawOption("M")
55 theRatio.SetXTitle(yTitle)
56 theRatio.SetYTitle("Data/MC")
57 return theRatio, refError
58