7 |
|
|
8 |
|
class StackMaker: |
9 |
|
def __init__(self, config, var,region,SignalRegion): |
10 |
– |
plotConfig = BetterConfigParser() |
11 |
– |
plotConfig.read('vhbbPlotDef.ini') |
10 |
|
section='Plot:%s'%region |
11 |
|
self.var = var |
12 |
|
self.SignalRegion=SignalRegion |
13 |
|
self.normalize = eval(config.get(section,'Normalize')) |
14 |
|
self.log = eval(config.get(section,'log')) |
15 |
< |
if plotConfig.has_option('plotDef:%s'%var,'log') and not self.log: |
16 |
< |
self.log = eval(plotConfig.get('plotDef:%s'%var,'log')) |
15 |
> |
if config.has_option('plotDef:%s'%var,'log') and not self.log: |
16 |
> |
self.log = eval(config.get('plotDef:%s'%var,'log')) |
17 |
|
self.blind = eval(config.get(section,'blind')) |
18 |
|
if self.blind: blindopt='blind' |
19 |
|
else: blindopt = 'noblind' |
28 |
|
if config.has_option(section,'nBins'): |
29 |
|
self.nBins = int(eval(config.get(section,'nBins'))/self.rebin) |
30 |
|
else: |
31 |
< |
self.nBins = int(eval(plotConfig.get('plotDef:%s'%var,'nBins'))/self.rebin) |
31 |
> |
self.nBins = int(eval(config.get('plotDef:%s'%var,'nBins'))/self.rebin) |
32 |
|
print self.nBins |
33 |
|
if config.has_option(section,'min'): |
34 |
|
self.xMin = eval(config.get(section,'min')) |
35 |
|
else: |
36 |
< |
self.xMin = eval(plotConfig.get('plotDef:%s'%var,'min')) |
36 |
> |
self.xMin = eval(config.get('plotDef:%s'%var,'min')) |
37 |
|
if config.has_option(section,'max'): |
38 |
|
self.xMax = eval(config.get(section,'max')) |
39 |
|
else: |
40 |
< |
self.xMax = eval(plotConfig.get('plotDef:%s'%var,'max')) |
41 |
< |
self.name = plotConfig.get('plotDef:%s'%var,'relPath') |
40 |
> |
self.xMax = eval(config.get('plotDef:%s'%var,'max')) |
41 |
> |
self.name = config.get('plotDef:%s'%var,'relPath') |
42 |
|
self.mass = config.get(section,'Signal') |
43 |
|
data = config.get(section,'Datas') |
44 |
|
if '<mass>' in self.name: |
51 |
|
self.colorDict=eval(config.get('Plot_general','colorDict')) |
52 |
|
self.typLegendDict=eval(config.get('Plot_general','typLegendDict')) |
53 |
|
self.anaTag = config.get("Analysis","tag") |
54 |
< |
self.xAxis = plotConfig.get('plotDef:%s'%var,'xAxis') |
55 |
< |
self.options = [self.name,'',self.xAxis,self.nBins,self.xMin,self.xMax,'%s_%s.pdf'%(region,var),region,datacut,self.mass,data,blindopt] |
54 |
> |
self.xAxis = config.get('plotDef:%s'%var,'xAxis') |
55 |
> |
self.options = [self.name,'',self.xAxis,self.nBins,self.xMin,self.xMax,'%s_%s_%s.pdf'%(region,var,self.mass),region,datacut,self.mass,data,blindopt] |
56 |
> |
#self.xAxis = config.get('plotDef:%s'%var,'xAxis') |
57 |
> |
#self.options = [self.name,'',self.xAxis,self.nBins,self.xMin,self.xMax,'%s_%s.pdf'%(region,var),region,datacut,self.mass,data,blindopt] |
58 |
> |
self.plotDir = config.get('Directories','plotpath') |
59 |
> |
self.maxRatioUncert = 0.5 |
60 |
> |
if self.SignalRegion: |
61 |
> |
self.maxRatioUncert = 1000. |
62 |
|
self.config = config |
63 |
|
self.datas = None |
64 |
|
self.datatyps = None |
105 |
|
|
106 |
|
oben.cd() |
107 |
|
allStack = ROOT.THStack(self.var,'') |
108 |
< |
l = ROOT.TLegend(0.63, 0.60,0.92,0.92) |
108 |
> |
l = ROOT.TLegend(0.63, 0.55,0.92,0.92) |
109 |
|
l.SetLineWidth(2) |
110 |
|
l.SetBorderSize(0) |
111 |
|
l.SetFillColor(0) |
145 |
|
addFlag = 'Z(e^{-}e^{+})H(b#bar{b})' |
146 |
|
elif 'Zmm' in self.datanames: |
147 |
|
addFlag = 'Z(#mu^{-}#mu^{+})H(b#bar{b})' |
148 |
+ |
elif 'Znn' in self.datanames: |
149 |
+ |
addFlag = 'Z(#nu#nu)H(b#bar{b})' |
150 |
+ |
elif 'Wmn' in self.datanames: |
151 |
+ |
addFlag = 'W(#mu#nu)H(b#bar{b})' |
152 |
+ |
elif 'Wen' in self.datanames: |
153 |
+ |
addFlag = 'W(e#nu)H(b#bar{b})' |
154 |
|
for i in range(0,len(self.datas)): |
155 |
|
d1.Add(self.datas[i],1) |
156 |
|
print "\033[1;32m\n\tDATA integral = %s\033[1;m"%d1.Integral() |
158 |
|
if flow > 0: |
159 |
|
print "\033[1;31m\tU/O flow: %s\033[1;m"%flow |
160 |
|
|
161 |
< |
self.overlay.SetLineColor(2) |
162 |
< |
self.overlay.SetLineWidth(2) |
163 |
< |
self.overlay.SetFillColor(0) |
164 |
< |
self.overlay.SetFillStyle(4000) |
165 |
< |
self.overlay.SetNameTitle('Overlay','Overlay') |
161 |
> |
if self.overlay: |
162 |
> |
self.overlay.SetLineColor(2) |
163 |
> |
self.overlay.SetLineWidth(2) |
164 |
> |
self.overlay.SetFillColor(0) |
165 |
> |
self.overlay.SetFillStyle(4000) |
166 |
> |
self.overlay.SetNameTitle('Overlay','Overlay') |
167 |
|
|
168 |
|
l.AddEntry(d1,datatitle,'P') |
169 |
|
for j in range(0,k): |
170 |
|
l.AddEntry(self.histos[j],self.typLegendDict[self.typs[j]],'F') |
171 |
< |
l.AddEntry(self.overlay,self.typLegendDict['Overlay'],'L') |
171 |
> |
if self.overlay: |
172 |
> |
l.AddEntry(self.overlay,self.typLegendDict['Overlay'],'L') |
173 |
|
|
174 |
|
if self.normalize: |
175 |
|
if MC_integral != 0: stackscale=d1.Integral()/MC_integral |
176 |
< |
self.overlay.Scale(stackscale) |
176 |
> |
if self.overlay: |
177 |
> |
self.overlay.Scale(stackscale) |
178 |
|
stackhists=allStack.GetHists() |
179 |
|
for blabla in stackhists: |
180 |
|
if MC_integral != 0: blabla.Scale(stackscale) |
181 |
|
|
182 |
< |
if self.SignalRegion: |
183 |
< |
allMC=allStack.GetStack().At(allStack.GetStack().GetLast()-1).Clone() |
184 |
< |
else: |
185 |
< |
allMC=allStack.GetStack().Last().Clone() |
182 |
> |
#if self.SignalRegion: |
183 |
> |
# allMC=allStack.GetStack().At(allStack.GetStack().GetLast()-1).Clone() |
184 |
> |
#else: |
185 |
> |
allMC=allStack.GetStack().Last().Clone() |
186 |
|
|
187 |
|
allStack.SetTitle() |
188 |
|
allStack.Draw("hist") |
189 |
|
allStack.GetXaxis().SetTitle('') |
190 |
|
yTitle = 'Entries' |
191 |
|
if not '/' in yTitle: |
192 |
< |
yAppend = '%s' %(allStack.GetXaxis().GetBinWidth(1)) |
192 |
> |
yAppend = '%.2f' %(allStack.GetXaxis().GetBinWidth(1)) |
193 |
|
yTitle = '%s / %s' %(yTitle, yAppend) |
194 |
|
allStack.GetYaxis().SetTitle(yTitle) |
195 |
|
allStack.GetXaxis().SetRangeUser(self.xMin,self.xMax) |
201 |
|
l.AddEntry(theErrorGraph,"MC uncert. (stat.)","fl") |
202 |
|
Ymax = max(allStack.GetMaximum(),d1.GetMaximum())*1.7 |
203 |
|
if self.log: |
204 |
< |
allStack.SetMinimum(0.05) |
205 |
< |
Ymax = Ymax*ROOT.TMath.Power(10,1.6*(ROOT.TMath.Log(1.6*(Ymax/0.1))/ROOT.TMath.Log(10)))*(0.6*0.1) |
204 |
> |
allStack.SetMinimum(0.1) |
205 |
> |
Ymax = Ymax*ROOT.TMath.Power(10,1.2*(ROOT.TMath.Log(1.2*(Ymax/0.1))/ROOT.TMath.Log(10)))*(0.2*0.1) |
206 |
|
ROOT.gPad.SetLogy() |
207 |
|
allStack.SetMaximum(Ymax) |
208 |
|
c.Update() |
210 |
|
#allStack.Draw("hist") |
211 |
|
l.SetFillColor(0) |
212 |
|
l.SetBorderSize(0) |
213 |
< |
|
214 |
< |
self.overlay.Draw('hist,same') |
213 |
> |
|
214 |
> |
if self.overlay: |
215 |
> |
self.overlay.Draw('hist,same') |
216 |
|
d1.Draw("E,same") |
217 |
|
l.Draw() |
218 |
|
|
232 |
|
#l2.SetTextSize(0.035) |
233 |
|
l2.SetNColumns(2) |
234 |
|
|
235 |
< |
ratio, error = getRatio(d1,allMC,self.xMin,self.xMax) |
235 |
> |
|
236 |
> |
ratio, error = getRatio(d1,allMC,self.xMin,self.xMax,"",self.maxRatioUncert) |
237 |
|
ksScore = d1.KolmogorovTest( allMC ) |
238 |
|
chiScore = d1.Chi2Test( allMC , "UWCHI2/NDF") |
239 |
|
print ksScore |
254 |
|
|
255 |
|
l2.AddEntry(self.AddErrors,"MC uncert. (stat. + syst.)","f") |
256 |
|
|
257 |
+ |
#ksScore = d1.KolmogorovTest( self.AddErrors ) |
258 |
+ |
#chiScore = d1.Chi2Test( self.AddErrors , "UWCHI2/NDF") |
259 |
+ |
|
260 |
+ |
|
261 |
|
l2.AddEntry(ratioError,"MC uncert. (stat.)","f") |
262 |
|
|
263 |
|
l2.Draw() |
276 |
|
t0.SetTextFont(ROOT.gStyle.GetLabelFont()) |
277 |
|
if not self.log: |
278 |
|
t0.DrawTextNDC(0.1059,0.96, "0") |
279 |
< |
|
280 |
< |
name = '%s/%s' %(self.config.get('Directories','plotpath'),self.options[6]) |
279 |
> |
if not os.path.exists(self.plotDir): |
280 |
> |
os.makedirs(os.path.dirname(self.plotDir)) |
281 |
> |
name = '%s/%s' %(self.plotDir,self.options[6]) |
282 |
|
c.Print(name) |