ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/plot_systematics.py
Revision: 1.3
Committed: Wed Oct 17 16:04:16 2012 UTC (12 years, 6 months ago) by peller
Content type: text/x-python
Branch: MAIN
CVS Tags: hcpPreApp
Changes since 1.2: +108 -32 lines
Log Message:
with a bit more config

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