ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/myutils/Ratio.py
Revision: 1.1
Committed: Wed Jan 16 16:35:41 2013 UTC (12 years, 3 months ago) by peller
Content type: text/x-python
Branch: MAIN
Log Message:
reorganized the whole repository. Macros im myutils, config files in subdirectories. Config file split in parts. Path config file restructured. Moved all path options to the path config. Changed the code accordingly.

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 = 1000.000,restrict=True):
28     from ROOT import gROOT
29     theHist, theReference = renewHist(hist,reference,min,max)
30     ROOT.gSystem.Load('./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     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     theRatio.SetYTitle("Data/MC")
55     return theRatio, refError
56