ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/plot_systematics.py
Revision: 1.9
Committed: Fri Jul 19 10:13:50 2013 UTC (11 years, 9 months ago) by nmohr
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +6 -3 lines
Log Message:
For git migration

File Contents

# Content
1 #!/usr/bin/env python
2 import ROOT
3 ROOT.gROOT.SetBatch(True)
4 from ROOT import TFile
5 from optparse import OptionParser
6 import sys
7 from myutils import BetterConfigParser, TdrStyles, getRatio
8
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']
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 path = config.get('Directories','limits')
37 outpath = config.get('Directories','plotpath')
38
39 setup = eval(config.get('LimitGeneral','setup'))
40 Dict = eval(config.get('LimitGeneral','Dict'))
41 MCs = [Dict[s] for s in setup]
42
43 sys_BDT= eval(config.get('LimitGeneral','sys_BDT'))
44 systematicsnaming = eval(config.get('LimitGeneral','systematicsnaming'))
45 systs=[systematicsnaming[s] for s in sys_BDT]
46
47 if eval(config.get('LimitGeneral','weightF_sys')): systs.append('UEPS')
48
49 def myText(txt="CMS Preliminary",ndcX=0,ndcY=0,size=0.8):
50 ROOT.gPad.Update()
51 text = ROOT.TLatex()
52 text.SetNDC()
53 text.SetTextColor(ROOT.kBlack)
54 text.SetTextSize(text.GetTextSize()*size)
55 text.DrawLatex(ndcX,ndcY,txt)
56 return text
57
58
59 #for mass in ['110','115','120','125','130','135']:
60 for mass in masses:
61 for Abin in Abins:
62 for channel in channels:
63
64 if mode == 'BDT':
65 input = TFile.Open(path+'/vhbb_TH_BDT_M'+mass+'_'+channel+Abin+'_8TeV.root','read')
66 if mode == 'Mjj':
67 input = TFile.Open(path+'/vhbb_TH_Mjj_'+Abin+'_M'+mass+'_'+channel+'.root','read')
68
69 for MC in MCs:
70 print MC
71 for syst in systs:
72 print syst
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 input.cd(channel+Abin+'_8TeV')
102 Ntotal=ROOT.gDirectory.Get(MC)
103 Utotal=ROOT.gDirectory.Get(MC+syst+'Up')
104 #Utotal=input.Get(MC+syst+MC+'_'+channel+'Up')
105 Dtotal=ROOT.gDirectory.Get(MC+syst+'Down')
106 #Dtotal=input.Get(MC+syst+MC+'_'+channel+'Down')
107 l = ROOT.TLegend(0.17, 0.8, 0.37, 0.65)
108
109 l.SetLineWidth(2)
110 l.SetBorderSize(0)
111 l.SetFillColor(0)
112 l.SetFillStyle(4000)
113 l.SetTextFont(62)
114 l.SetTextSize(0.035)
115
116
117 l.AddEntry(Ntotal,'nominal','PL')
118 l.AddEntry(Utotal,'up','PL')
119 l.AddEntry(Dtotal,'down','PL')
120 Ntotal.GetYaxis().SetRangeUser(0,1.5*Ntotal.GetBinContent(Ntotal.GetMaximumBin()))
121 Ntotal.SetMarkerStyle(8)
122 Ntotal.SetLineColor(1)
123 Ntotal.SetStats(0)
124 Ntotal.SetTitle(MC +' '+syst)
125 Ntotal.Draw("P0")
126 Ntotal.Draw("same")
127 Utotal.SetLineColor(4)
128 Utotal.SetLineStyle(4)
129 Utotal.SetLineWidth(2)
130 Utotal.Draw("same hist")
131 Dtotal.SetLineColor(2)
132 Dtotal.SetLineStyle(3)
133 Dtotal.SetLineWidth(2)
134 Dtotal.Draw("same hist")
135 l.SetFillColor(0)
136 l.SetBorderSize(0)
137 l.Draw()
138
139 title=myText('Shape Systematic %s in %s'%(syst,MC),0.17,0.85)
140
141 print 'Shape Systematic %s in %s'%(syst,MC)
142 print 'Up: \t%s'%Utotal.Integral()
143 print 'Nominal:\t%s'%Ntotal.Integral()
144 print 'Down: \t%s'%Dtotal.Integral()
145
146 unten.cd()
147 ROOT.gPad.SetTicks(1,1)
148
149 ratioU, errorU = getRatio(Utotal,Ntotal,xMin,xMax)
150 ratioD, errorD = getRatio(Dtotal,Ntotal,xMin,xMax)
151
152 ksScoreU = Ntotal.KolmogorovTest( Utotal )
153 chiScoreU = Ntotal.Chi2Test( Utotal , "WWCHI2/NDF")
154 ksScoreD = Ntotal.KolmogorovTest( Dtotal )
155 chiScoreD = Ntotal.Chi2Test( Dtotal , "WWCHI2/NDF")
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 fitRatioU = ratioU.Fit("pol2","S")
174 fitRatioU.Draw("SAME")
175 ratioU.SetTitle("")
176 ratioD.SetStats(0)
177 ratioD.GetYaxis().SetRangeUser(0.5,1.5)
178 ratioD.GetYaxis().SetNdivisions(502,0)
179 #ratioD.GetYaxis().SetLabelSize(0.2)
180 #ratioD.GetYaxis().SetTitleSize(0.2)
181 #ratioD.GetYaxis().SetTitleOffset(0.2)
182 #ratioD.GetXaxis().SetLabelColor(10)
183 ratioD.SetLineColor(2)
184 ratioD.SetLineStyle(3)
185 ratioD.SetLineWidth(2)
186 ratioD.Draw("hist same")
187 fitRatioD = ratioD.Fit("pol2","S")
188 fitRatioD.Draw("SAME")
189 ratioD.SetTitle("")
190 m_one_line = ROOT.TLine(xMin,1,xMax,1)
191 m_one_line.SetLineStyle(7)
192 m_one_line.SetLineColor(4)
193 m_one_line.Draw("Same")
194
195
196 #name = outpath+Abin+'_M'+mass+'_'+channel+'_'+MC+syst+'.png'
197 #c.Print(name)
198 name = outpath+'systPlot_'+Abin+'_M'+mass+'_'+channel+'_'+MC+syst+'.pdf'
199 c.Print(name)
200
201
202 input.Close()