ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/plot_systematics.py
Revision: 1.7
Committed: Wed Jan 16 16:22:46 2013 UTC (12 years, 3 months ago) by peller
Content type: text/x-python
Branch: MAIN
CVS Tags: LHCP_PreAppFreeze, workingVersionAfterHCP
Changes since 1.6: +2 -6 lines
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

# Content
1 #!/usr/bin/env python
2 import ROOT
3 from ROOT import TFile
4 from optparse import OptionParser
5 import sys
6 from myutils import BetterConfigParser, tdrStyles, getRatio
7
8 ROOT.gROOT.SetBatch(True)
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 path = samplesinfo=config.get('Directories','limits')
37 outpath = samplesinfo=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 systematicsnaming8TeV = eval(config.get('LimitGeneral','systematicsnaming8TeV'))
45 systs=[systematicsnaming8TeV[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 for syst in systs:
71 #['CMS_res_j','CMS_scale_j','CMS_eff_b','CMS_fake_b_8TeV','UEPS']:
72 #for syst in ['CMS_vhbb_stats_']:
73
74
75 tdrStyle()
76
77 c = ROOT.TCanvas('','', 600, 600)
78 c.SetFillStyle(4000)
79 c.SetFrameFillStyle(1000)
80 c.SetFrameFillColor(0)
81 oben = ROOT.TPad('oben','oben',0,0.3 ,1.0,1.0)
82 oben.SetBottomMargin(0)
83 oben.SetFillStyle(4000)
84 oben.SetFrameFillStyle(1000)
85 oben.SetFrameFillColor(0)
86 unten = ROOT.TPad('unten','unten',0,0.0,1.0,0.3)
87 unten.SetTopMargin(0.)
88 unten.SetBottomMargin(0.35)
89 unten.SetFillStyle(4000)
90 unten.SetFrameFillStyle(1000)
91 unten.SetFrameFillColor(0)
92 oben.Draw()
93 unten.Draw()
94 oben.cd()
95
96 ROOT.gPad.SetTicks(1,1)
97
98
99 Ntotal=input.Get(MC)
100 Utotal=input.Get(MC+syst+'Up')
101 #Utotal=input.Get(MC+syst+MC+'_'+channel+'Up')
102 Dtotal=input.Get(MC+syst+'Down')
103 #Dtotal=input.Get(MC+syst+MC+'_'+channel+'Down')
104 l = ROOT.TLegend(0.17, 0.8, 0.37, 0.65)
105
106 l.SetLineWidth(2)
107 l.SetBorderSize(0)
108 l.SetFillColor(0)
109 l.SetFillStyle(4000)
110 l.SetTextFont(62)
111 l.SetTextSize(0.035)
112
113
114 l.AddEntry(Ntotal,'nominal','PL')
115 l.AddEntry(Utotal,'up','PL')
116 l.AddEntry(Dtotal,'down','PL')
117 Ntotal.GetYaxis().SetRangeUser(0,1.5*Ntotal.GetBinContent(Ntotal.GetMaximumBin()))
118 Ntotal.SetMarkerStyle(8)
119 Ntotal.SetLineColor(1)
120 Ntotal.SetStats(0)
121 Ntotal.SetTitle(MC +' '+syst)
122 Ntotal.Draw("P0")
123 Ntotal.Draw("same")
124 Utotal.SetLineColor(4)
125 Utotal.SetLineStyle(4)
126 Utotal.SetLineWidth(2)
127 Utotal.Draw("same hist")
128 Dtotal.SetLineColor(2)
129 Dtotal.SetLineStyle(3)
130 Dtotal.SetLineWidth(2)
131 Dtotal.Draw("same hist")
132 l.SetFillColor(0)
133 l.SetBorderSize(0)
134 l.Draw()
135
136 title=myText('Shape Systematic %s in %s'%(syst,MC),0.17,0.85)
137
138 print 'Shape Systematic %s in %s'%(syst,MC)
139 print 'Up: \t%s'%Utotal.Integral()
140 print 'Nominal:\t%s'%Ntotal.Integral()
141 print 'Down: \t%s'%Dtotal.Integral()
142
143 unten.cd()
144 ROOT.gPad.SetTicks(1,1)
145
146 ratioU, errorU = getRatio(Utotal,Ntotal,xMin,xMax)
147 ratioD, errorD = getRatio(Dtotal,Ntotal,xMin,xMax)
148
149 ksScoreU = Ntotal.KolmogorovTest( Utotal )
150 chiScoreU = Ntotal.Chi2Test( Utotal , "WWCHI2/NDF")
151 ksScoreD = Ntotal.KolmogorovTest( Dtotal )
152 chiScoreD = Ntotal.Chi2Test( Dtotal , "WWCHI2/NDF")
153
154
155
156
157 ratioU.SetStats(0)
158 ratioU.SetMinimum(0.01)
159 ratioU.SetMaximum(2.49)
160 ratioU.GetYaxis().SetNdivisions(505)
161 #ratioU.GetYaxis().SetLabelSize(0.2)
162 #ratioU.GetYaxis().SetTitleSize(0.2)
163 #ratioU.GetYaxis().SetTitleOffset(0.2)
164 #ratioU.GetXaxis().SetLabelColor(10)
165 ratioU.SetLineColor(4)
166 ratioU.SetLineStyle(4)
167 ratioU.SetLineWidth(2)
168 ratioU.GetXaxis().SetTitle('BDT output')
169 ratioU.GetYaxis().SetTitle('Ratio')
170 ratioU.Draw("hist")
171 ratioU.SetTitle("")
172 ratioD.SetStats(0)
173 ratioD.GetYaxis().SetRangeUser(0.5,1.5)
174 ratioD.GetYaxis().SetNdivisions(502,0)
175 #ratioD.GetYaxis().SetLabelSize(0.2)
176 #ratioD.GetYaxis().SetTitleSize(0.2)
177 #ratioD.GetYaxis().SetTitleOffset(0.2)
178 #ratioD.GetXaxis().SetLabelColor(10)
179 ratioD.SetLineColor(2)
180 ratioD.SetLineStyle(3)
181 ratioD.SetLineWidth(2)
182 ratioD.Draw("hist same")
183 ratioD.SetTitle("")
184 m_one_line = ROOT.TLine(xMin,1,xMax,1)
185 m_one_line.SetLineStyle(7)
186 m_one_line.SetLineColor(4)
187 m_one_line.Draw("Same")
188
189
190 #name = outpath+Abin+'_M'+mass+'_'+channel+'_'+MC+syst+'.png'
191 #c.Print(name)
192 name = outpath+Abin+'_M'+mass+'_'+channel+'_'+MC+syst+'.pdf'
193 c.Print(name)
194
195
196 input.Close()