ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/plot_systematics.py
Revision: 1.5
Committed: Wed Jan 16 09:56:54 2013 UTC (12 years, 4 months ago) by peller
Content type: text/x-python
Branch: MAIN
Changes since 1.4: +16 -5 lines
Log Message:
removing obsolete files step*

File Contents

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