ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/plot_systematics.py
Revision: 1.6
Committed: Wed Jan 16 12:57:46 2013 UTC (12 years, 3 months ago) by nmohr
Content type: text/x-python
Branch: MAIN
Changes since 1.5: +2 -0 lines
Log Message:
Batch mode

File Contents

# User Rev Content
1 peller 1.1 #!/usr/bin/env python
2     import ROOT
3     from ROOT import TFile
4     from Ratio import getRatio
5 peller 1.3 import TdrStyles
6     from BetterConfigParser import BetterConfigParser
7     from optparse import OptionParser
8     import sys
9    
10 nmohr 1.6 ROOT.gROOT.SetBatch(True)
11    
12 peller 1.3 argv = sys.argv
13     parser = OptionParser()
14     parser.add_option("-C", "--config", dest="config", default=[], action="append",
15     help="configuration file")
16     (opts, args) = parser.parse_args(argv)
17     config = BetterConfigParser()
18     config.read(opts.config)
19 peller 1.1
20    
21 peller 1.3 #---------- yes, this is not in the config yet---------
22 peller 1.5 #mode = 'BDT'
23     #xMin=-1
24     #xMax=1
25     #masses = ['125']
26     #Abins = ['HighPt','LowPt','HighPtLooseBTag']
27     #channels= ['Zee','Zmm']
28     #------------------------------------------------------
29     #---------- Mjj ---------------------------------------
30     mode = 'Mjj'
31     xMin=0
32     xMax=255
33 peller 1.3 masses = ['125']
34 peller 1.5 Abins = ['highPt','lowPt','medPt']
35 peller 1.3 channels= ['Zee','Zmm']
36     #------------------------------------------------------
37    
38    
39    
40     path = samplesinfo=config.get('Directories','limits')
41     outpath = samplesinfo=config.get('Directories','plotpath')
42    
43     setup = eval(config.get('LimitGeneral','setup'))
44     Dict = eval(config.get('LimitGeneral','Dict'))
45     MCs = [Dict[s] for s in setup]
46    
47     sys_BDT= eval(config.get('LimitGeneral','sys_BDT'))
48     systematicsnaming8TeV = eval(config.get('LimitGeneral','systematicsnaming8TeV'))
49     systs=[systematicsnaming8TeV[s] for s in sys_BDT]
50 peller 1.1
51 peller 1.3 if eval(config.get('LimitGeneral','weightF_sys')): systs.append('UEPS')
52 peller 1.2
53 peller 1.3 def myText(txt="CMS Preliminary",ndcX=0,ndcY=0,size=0.8):
54     ROOT.gPad.Update()
55     text = ROOT.TLatex()
56     text.SetNDC()
57     text.SetTextColor(ROOT.kBlack)
58     text.SetTextSize(text.GetTextSize()*size)
59     text.DrawLatex(ndcX,ndcY,txt)
60     return text
61 peller 1.2
62    
63 peller 1.3 #for mass in ['110','115','120','125','130','135']:
64     for mass in masses:
65     for Abin in Abins:
66     for channel in channels:
67    
68 peller 1.5 if mode == 'BDT':
69     input = TFile.Open(path+'/vhbb_TH_BDT_M'+mass+'_'+channel+Abin+'_8TeV.root','read')
70     if mode == 'Mjj':
71     input = TFile.Open(path+'/vhbb_TH_Mjj_'+Abin+'_M'+mass+'_'+channel+'.root','read')
72 peller 1.3
73     for MC in MCs:
74     for syst in systs:
75     #['CMS_res_j','CMS_scale_j','CMS_eff_b','CMS_fake_b_8TeV','UEPS']:
76 peller 1.2 #for syst in ['CMS_vhbb_stats_']:
77    
78 peller 1.3
79     TdrStyles.tdrStyle()
80    
81     c = ROOT.TCanvas('','', 600, 600)
82     c.SetFillStyle(4000)
83     c.SetFrameFillStyle(1000)
84     c.SetFrameFillColor(0)
85     oben = ROOT.TPad('oben','oben',0,0.3 ,1.0,1.0)
86     oben.SetBottomMargin(0)
87     oben.SetFillStyle(4000)
88     oben.SetFrameFillStyle(1000)
89     oben.SetFrameFillColor(0)
90     unten = ROOT.TPad('unten','unten',0,0.0,1.0,0.3)
91     unten.SetTopMargin(0.)
92     unten.SetBottomMargin(0.35)
93     unten.SetFillStyle(4000)
94     unten.SetFrameFillStyle(1000)
95     unten.SetFrameFillColor(0)
96 peller 1.2 oben.Draw()
97     unten.Draw()
98     oben.cd()
99 peller 1.3
100 peller 1.2 ROOT.gPad.SetTicks(1,1)
101    
102    
103     Ntotal=input.Get(MC)
104     Utotal=input.Get(MC+syst+'Up')
105     #Utotal=input.Get(MC+syst+MC+'_'+channel+'Up')
106     Dtotal=input.Get(MC+syst+'Down')
107     #Dtotal=input.Get(MC+syst+MC+'_'+channel+'Down')
108 peller 1.3 l = ROOT.TLegend(0.17, 0.8, 0.37, 0.65)
109    
110     l.SetLineWidth(2)
111     l.SetBorderSize(0)
112     l.SetFillColor(0)
113     l.SetFillStyle(4000)
114     l.SetTextFont(62)
115     l.SetTextSize(0.035)
116    
117    
118 peller 1.2 l.AddEntry(Ntotal,'nominal','PL')
119     l.AddEntry(Utotal,'up','PL')
120     l.AddEntry(Dtotal,'down','PL')
121 peller 1.3 Ntotal.GetYaxis().SetRangeUser(0,1.5*Ntotal.GetBinContent(Ntotal.GetMaximumBin()))
122 peller 1.2 Ntotal.SetMarkerStyle(8)
123     Ntotal.SetLineColor(1)
124     Ntotal.SetStats(0)
125     Ntotal.SetTitle(MC +' '+syst)
126     Ntotal.Draw("P0")
127     Ntotal.Draw("same")
128     Utotal.SetLineColor(4)
129     Utotal.SetLineStyle(4)
130     Utotal.SetLineWidth(2)
131     Utotal.Draw("same hist")
132     Dtotal.SetLineColor(2)
133     Dtotal.SetLineStyle(3)
134     Dtotal.SetLineWidth(2)
135     Dtotal.Draw("same hist")
136     l.SetFillColor(0)
137     l.SetBorderSize(0)
138     l.Draw()
139    
140 peller 1.3 title=myText('Shape Systematic %s in %s'%(syst,MC),0.17,0.85)
141    
142     print 'Shape Systematic %s in %s'%(syst,MC)
143     print 'Up: \t%s'%Utotal.Integral()
144     print 'Nominal:\t%s'%Ntotal.Integral()
145     print 'Down: \t%s'%Dtotal.Integral()
146 peller 1.2
147     unten.cd()
148     ROOT.gPad.SetTicks(1,1)
149    
150 peller 1.3 ratioU, errorU = getRatio(Utotal,Ntotal,xMin,xMax)
151     ratioD, errorD = getRatio(Dtotal,Ntotal,xMin,xMax)
152    
153     ksScoreU = Ntotal.KolmogorovTest( Utotal )
154     chiScoreU = Ntotal.Chi2Test( Utotal , "WWCHI2/NDF")
155     ksScoreD = Ntotal.KolmogorovTest( Dtotal )
156     chiScoreD = Ntotal.Chi2Test( Dtotal , "WWCHI2/NDF")
157    
158    
159    
160 peller 1.2
161     ratioU.SetStats(0)
162 nmohr 1.4 ratioU.SetMinimum(0.01)
163     ratioU.SetMaximum(2.49)
164     ratioU.GetYaxis().SetNdivisions(505)
165 peller 1.3 #ratioU.GetYaxis().SetLabelSize(0.2)
166     #ratioU.GetYaxis().SetTitleSize(0.2)
167     #ratioU.GetYaxis().SetTitleOffset(0.2)
168     #ratioU.GetXaxis().SetLabelColor(10)
169 peller 1.2 ratioU.SetLineColor(4)
170     ratioU.SetLineStyle(4)
171 peller 1.3 ratioU.SetLineWidth(2)
172     ratioU.GetXaxis().SetTitle('BDT output')
173     ratioU.GetYaxis().SetTitle('Ratio')
174 peller 1.2 ratioU.Draw("hist")
175     ratioU.SetTitle("")
176     ratioD.SetStats(0)
177     ratioD.GetYaxis().SetRangeUser(0.5,1.5)
178     ratioD.GetYaxis().SetNdivisions(502,0)
179 peller 1.3 #ratioD.GetYaxis().SetLabelSize(0.2)
180     #ratioD.GetYaxis().SetTitleSize(0.2)
181     #ratioD.GetYaxis().SetTitleOffset(0.2)
182     #ratioD.GetXaxis().SetLabelColor(10)
183 peller 1.2 ratioD.SetLineColor(2)
184     ratioD.SetLineStyle(3)
185     ratioD.SetLineWidth(2)
186     ratioD.Draw("hist same")
187     ratioD.SetTitle("")
188     m_one_line = ROOT.TLine(xMin,1,xMax,1)
189     m_one_line.SetLineStyle(7)
190     m_one_line.SetLineColor(4)
191     m_one_line.Draw("Same")
192    
193    
194     #name = outpath+Abin+'_M'+mass+'_'+channel+'_'+MC+syst+'.png'
195     #c.Print(name)
196     name = outpath+Abin+'_M'+mass+'_'+channel+'_'+MC+syst+'.pdf'
197     c.Print(name)
198 peller 1.1
199    
200 peller 1.3 input.Close()