1 |
peller |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
import sys
|
6 |
|
|
import os
|
7 |
|
|
|
8 |
|
|
import ROOT
|
9 |
|
|
from ROOT import TFile
|
10 |
|
|
print 'hello\n'
|
11 |
|
|
|
12 |
|
|
from array import array
|
13 |
|
|
|
14 |
|
|
from math import sqrt
|
15 |
|
|
from copy import copy
|
16 |
|
|
#suppres the EvalInstace conversion warning bug
|
17 |
|
|
|
18 |
|
|
import warnings
|
19 |
|
|
warnings.filterwarnings( action='ignore', category=RuntimeWarning, message='creating converter.*' )
|
20 |
|
|
warnings.filterwarnings( action='ignore', category=RuntimeWarning, message='Error in <TTree::Fill>:*' )
|
21 |
|
|
from ConfigParser import SafeConfigParser
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
from samplesclass import sample
|
26 |
|
|
from mvainfos import mvainfo
|
27 |
|
|
import pickle
|
28 |
|
|
from progbar import progbar
|
29 |
|
|
from printcolor import printc
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
class DevNull:
|
33 |
|
|
def write(self, msg):
|
34 |
|
|
pass
|
35 |
|
|
|
36 |
|
|
sys.stderr = DevNull()
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
#CONFIGURE
|
42 |
|
|
|
43 |
|
|
#load config
|
44 |
|
|
config = SafeConfigParser()
|
45 |
|
|
config.read('./config')
|
46 |
|
|
|
47 |
|
|
#get locations:
|
48 |
|
|
Wdir=config.get('Directories','Wdir')
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
#systematics
|
52 |
|
|
systematics=config.get('systematics','systematics')
|
53 |
|
|
systematics=systematics.split(' ')
|
54 |
|
|
|
55 |
|
|
#TreeVar Array
|
56 |
|
|
MVA_Vars={}
|
57 |
|
|
for systematic in systematics:
|
58 |
|
|
MVA_Vars[systematic]=config.get('treeVars',systematic)
|
59 |
|
|
MVA_Vars[systematic]=MVA_Vars[systematic].split(' ')
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
weightF=config.get('Weights','weightF')
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
def getTree(job,cut):
|
71 |
|
|
Tree = ROOT.TChain(job.tree)
|
72 |
|
|
Tree.Add(job.getpath())
|
73 |
|
|
#Tree.SetDirectory(0)
|
74 |
|
|
CuttedTree=Tree.CopyTree(cut)
|
75 |
|
|
#CuttedTree.SetDirectory(0)
|
76 |
|
|
print '\t--> read in %s'%job.name
|
77 |
|
|
return CuttedTree
|
78 |
|
|
|
79 |
|
|
'''
|
80 |
|
|
def getTree(job):
|
81 |
|
|
Tree = ROOT.TChain(job.tree)
|
82 |
|
|
Tree.Add(job.getpath())
|
83 |
|
|
Tree.SetDirectory(0)
|
84 |
|
|
#CuttedTree.SetDirectory(0)
|
85 |
|
|
return Tree
|
86 |
|
|
''
|
87 |
|
|
def getTree(job):
|
88 |
|
|
Tree = ROOT.TChain(job.tree)
|
89 |
|
|
Tree.Add(job.getpath())
|
90 |
|
|
Tree.SetDirectory(0)
|
91 |
|
|
#CuttedTree.SetDirectory(0)
|
92 |
|
|
return Tree
|
93 |
|
|
'''
|
94 |
|
|
def getScale(job):
|
95 |
|
|
input = TFile.Open(job.getpath())
|
96 |
|
|
CountWithPU = input.Get("CountWithPU")
|
97 |
|
|
CountWithPU2011B = input.Get("CountWithPU2011B")
|
98 |
|
|
#print lumi*xsecs[i]/hist.GetBinContent(1)
|
99 |
peller |
1.2 |
return float(job.lumi)*float(job.xsec)*float(job.sf)/(0.46502*CountWithPU.GetBinContent(1)+0.53498*CountWithPU2011B.GetBinContent(1))*2/float(job.split)
|
100 |
peller |
1.1 |
|
101 |
|
|
|
102 |
|
|
def getHistoFromTree(job,options):
|
103 |
|
|
treeVar=options[0]
|
104 |
|
|
name=job.name
|
105 |
|
|
#title=job.plotname()
|
106 |
|
|
nBins=int(options[3])
|
107 |
|
|
xMin=float(options[4])
|
108 |
|
|
xMax=float(options[5])
|
109 |
|
|
if job.type != 'DATA':
|
110 |
|
|
cutcut=config.get('Cuts',options[7])
|
111 |
|
|
treeCut='%s & EventForTraining == 0'%cutcut
|
112 |
|
|
|
113 |
|
|
elif job.type == 'DATA':
|
114 |
|
|
treeCut=config.get('Cuts',options[8])
|
115 |
|
|
|
116 |
|
|
input = TFile.Open(job.getpath(),'read')
|
117 |
|
|
|
118 |
|
|
Tree = input.Get(job.tree)
|
119 |
|
|
#Tree=tmpTree.CloneTree()
|
120 |
|
|
#Tree.SetDirectory(0)
|
121 |
|
|
|
122 |
|
|
#Tree=tmpTree.Clone()
|
123 |
|
|
weightF=config.get('Weights','weightF')
|
124 |
|
|
#hTree = ROOT.TH1F('%s'%name,'%s'%title,nBins,xMin,xMax)
|
125 |
|
|
#hTree.SetDirectory(0)
|
126 |
|
|
|
127 |
|
|
#hTree.Sumw2()
|
128 |
|
|
#print 'drawing...'
|
129 |
|
|
if job.type != 'DATA':
|
130 |
|
|
#print treeCut
|
131 |
|
|
Tree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),'(%s)*(%s)' %(treeCut,weightF), "goff,e")
|
132 |
|
|
elif job.type == 'DATA':
|
133 |
|
|
Tree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),treeCut, "goff,e")
|
134 |
|
|
hTree = ROOT.gDirectory.Get(name)
|
135 |
|
|
#print job.name + ' Sumw2', hTree.GetEntries()
|
136 |
|
|
|
137 |
|
|
if job.type != 'DATA':
|
138 |
|
|
ScaleFactor = getScale(job)
|
139 |
|
|
if ScaleFactor != 0:
|
140 |
|
|
hTree.Scale(ScaleFactor)
|
141 |
|
|
|
142 |
|
|
print '\t-->import %s\t Integral: %s'%(job.name,hTree.Integral())
|
143 |
|
|
|
144 |
|
|
return hTree, job.group
|
145 |
|
|
|
146 |
|
|
'''
|
147 |
|
|
def getHistoFromTree(job,options):
|
148 |
|
|
treeVar=options[0]
|
149 |
|
|
name=job.name
|
150 |
|
|
#title=job.plotname()
|
151 |
|
|
nBins=int(options[3])
|
152 |
|
|
xMin=float(options[4])
|
153 |
|
|
xMax=float(options[5])
|
154 |
|
|
if job.type != 'DATA':
|
155 |
|
|
cutcut=config.get('Cuts',options[7])
|
156 |
|
|
treeCut='%s&&EventForTraining==0'%cutcut
|
157 |
|
|
|
158 |
|
|
elif job.type == 'DATA':
|
159 |
|
|
treeCut=config.get('Cuts',options[8])
|
160 |
|
|
|
161 |
|
|
Tree = getTree(job,treeCut)
|
162 |
|
|
|
163 |
|
|
weightF=config.get('Weights','weightF')
|
164 |
|
|
hTree = ROOT.TH1F('%s'%name,'%s'%title,nBins,xMin,xMax)
|
165 |
|
|
hTree.Sumw2()
|
166 |
|
|
#print 'drawing...'
|
167 |
|
|
if job.type != 'DATA':
|
168 |
|
|
Tree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),'%s*(%s)' %(weightF,'1'), "goff,e")
|
169 |
|
|
else:
|
170 |
|
|
Tree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),'1', "goff,e")
|
171 |
|
|
hTree = ROOT.gDirectory.Get(name)
|
172 |
|
|
hTree.SetDirectory(0)
|
173 |
|
|
#print job.name + ' Sumw2', hTree.GetEntries()
|
174 |
|
|
|
175 |
|
|
if job.type != 'DATA':
|
176 |
|
|
ScaleFactor = getScale(job)
|
177 |
|
|
if ScaleFactor != 0:
|
178 |
|
|
hTree.Scale(ScaleFactor)
|
179 |
|
|
|
180 |
|
|
print '\t-->import %s\t Integral: %s'%(job.name,hTree.Integral())
|
181 |
|
|
|
182 |
|
|
return hTree, job.group
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
'''
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
######################
|
192 |
|
|
|
193 |
|
|
path=sys.argv[1]
|
194 |
|
|
var=sys.argv[2]
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
plot=config.get('Limit',var)
|
198 |
|
|
|
199 |
|
|
infofile = open(path+'/samples.info','r')
|
200 |
|
|
info = pickle.load(infofile)
|
201 |
|
|
infofile.close()
|
202 |
|
|
|
203 |
|
|
options = plot.split(',')
|
204 |
|
|
name=options[1]
|
205 |
|
|
title = options[2]
|
206 |
|
|
nBins=int(options[3])
|
207 |
|
|
xMin=float(options[4])
|
208 |
|
|
xMax=float(options[5])
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
mass=options[9]
|
212 |
|
|
data=options[10]
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
setup=config.get('Limit','setup')
|
216 |
|
|
setup=setup.split(',')
|
217 |
|
|
|
218 |
|
|
ROOToutname = options[6]
|
219 |
|
|
outpath=config.get('Directories','limits')
|
220 |
|
|
outfile = ROOT.TFile(outpath+'vhbb_TH_'+ROOToutname+'.root', 'RECREATE')
|
221 |
peller |
1.2 |
discr_names = ['ZjLF','ZjCF','ZjHF', 'TT','VV', 's_Top', 'VH', 'WjLF', 'WjHF', 'QCD']
|
222 |
peller |
1.1 |
data_name = ['data_obs']
|
223 |
|
|
WS = ROOT.RooWorkspace('%s'%options[10],'%s'%options[10]) #Zee
|
224 |
|
|
print 'WS initialized'
|
225 |
|
|
disc= ROOT.RooRealVar('BDT','BDT',-1,1)
|
226 |
|
|
obs = ROOT.RooArgList(disc)
|
227 |
|
|
|
228 |
|
|
ROOT.gROOT.SetStyle("Plain")
|
229 |
|
|
#c = ROOT.TCanvas(name,title, 800, 600)
|
230 |
|
|
|
231 |
|
|
|
232 |
|
|
datas = []
|
233 |
|
|
datatyps =[]
|
234 |
|
|
histos = []
|
235 |
|
|
typs = []
|
236 |
|
|
statUps=[]
|
237 |
|
|
statDowns=[]
|
238 |
|
|
|
239 |
|
|
|
240 |
|
|
for job in info:
|
241 |
|
|
#print job.name
|
242 |
|
|
if job.type == 'BKG':
|
243 |
|
|
#print 'MC'
|
244 |
|
|
hTemp, typ = getHistoFromTree(job,options)
|
245 |
|
|
histos.append(hTemp)
|
246 |
|
|
typs.append(typ)
|
247 |
|
|
elif job.type == 'SIG' and job.name == mass:
|
248 |
|
|
hTemp, typ = getHistoFromTree(job,options)
|
249 |
|
|
histos.append(hTemp)
|
250 |
|
|
typs.append(typ)
|
251 |
|
|
elif job.name in data:
|
252 |
|
|
#print 'DATA'
|
253 |
|
|
hTemp, typ = getHistoFromTree(job,options)
|
254 |
|
|
datas.append(hTemp)
|
255 |
|
|
datatyps.append(typ)
|
256 |
|
|
|
257 |
|
|
MC_integral=0
|
258 |
|
|
MC_entries=0
|
259 |
|
|
|
260 |
|
|
for histo in histos:
|
261 |
|
|
MC_integral+=histo.Integral()
|
262 |
|
|
#MC_entries+=histo.GetEntries()
|
263 |
|
|
print "\033[1;32m\n\tMC integral = %s\033[1;m"%MC_integral
|
264 |
|
|
#flow = MC_entries-MC_integral
|
265 |
|
|
#if flow > 0:
|
266 |
|
|
# print "\033[1;31m\tU/O flow: %s\033[1;m"%flow
|
267 |
|
|
|
268 |
|
|
#ORDER AND ADD TOGETHER
|
269 |
|
|
|
270 |
|
|
ordnung=[]
|
271 |
|
|
ordnungtyp=[]
|
272 |
|
|
num=[0]*len(setup)
|
273 |
|
|
for i in range(0,len(setup)):
|
274 |
|
|
for j in range(0,len(histos)):
|
275 |
|
|
if typs[j] == setup[i]:
|
276 |
|
|
num[i]+=1
|
277 |
|
|
ordnung.append(histos[j])
|
278 |
|
|
ordnungtyp.append(typs[j])
|
279 |
|
|
|
280 |
|
|
del histos
|
281 |
|
|
del typs
|
282 |
|
|
|
283 |
|
|
histos=ordnung
|
284 |
|
|
typs=ordnungtyp
|
285 |
|
|
|
286 |
|
|
for k in range(0,len(num)):
|
287 |
|
|
for m in range(0,num[k]):
|
288 |
|
|
if m > 0:
|
289 |
|
|
|
290 |
|
|
#add
|
291 |
|
|
#for IND in range(histos[k].GetNbinsX()):
|
292 |
|
|
# content=histos[k].GetBinContent(IND)+histos[k+1].GetBinContent(IND)
|
293 |
|
|
# histos[k].SetBinContent(IND,content)
|
294 |
|
|
#histos[k].Sumw2()
|
295 |
|
|
#histos[k+1].Sumw2()
|
296 |
|
|
histos[k].Add(histos[k+1],1)
|
297 |
|
|
printc('red','','\t--> added %s to %s'%(typs[k],typs[k+1]))
|
298 |
|
|
del histos[k+1]
|
299 |
|
|
del typs[k+1]
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
for i in range(0,len(histos)):
|
305 |
|
|
histos[i].SetName(discr_names[i])
|
306 |
|
|
histos[i].SetDirectory(outfile)
|
307 |
|
|
histos[i].Write()
|
308 |
|
|
#histos[i].Draw("goff")
|
309 |
|
|
#histos[i].Write()
|
310 |
|
|
|
311 |
|
|
|
312 |
|
|
|
313 |
|
|
|
314 |
|
|
#printc('blue','',discr_names[i])
|
315 |
|
|
#print i
|
316 |
|
|
|
317 |
|
|
statUps.append(histos[i].Clone())
|
318 |
|
|
statDowns.append(histos[i].Clone())
|
319 |
|
|
statUps[i].SetName('%sCMS_vhbb_stats_%s_%sUp'%(discr_names[i],discr_names[i],options[10]))
|
320 |
|
|
statDowns[i].SetName('%sCMS_vhbb_stats_%s_%sDown'%(discr_names[i],discr_names[i],options[10]))
|
321 |
|
|
statUps[i].Sumw2()
|
322 |
|
|
statDowns[i].Sumw2()
|
323 |
|
|
|
324 |
|
|
#shift up and down with statistical error
|
325 |
|
|
for j in range(histos[i].GetNbinsX()):
|
326 |
|
|
#print '\t\t Up : %s'%(statUps[i].GetBinContent(j)+statUps[i].GetBinError(j))
|
327 |
|
|
#print '\t\t Nominal: %s'%histos[i].GetBinContent(j)
|
328 |
|
|
statUps[i].SetBinContent(j,statUps[i].GetBinContent(j)+statUps[i].GetBinError(j))
|
329 |
|
|
#print '\t\t Down: %s'%(statDowns[i].GetBinContent(j)-statDowns[i].GetBinError(j))
|
330 |
|
|
statDowns[i].SetBinContent(j,statDowns[i].GetBinContent(j)-statDowns[i].GetBinError(j))
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
|
|
statUps[i].SetDirectory(outfile)
|
335 |
|
|
statDowns[i].SetDirectory(outfile)
|
336 |
|
|
#statUps[i].Draw("goff")
|
337 |
|
|
statUps[i].Write()
|
338 |
|
|
#statUp.Write()
|
339 |
|
|
statDowns[i].Write()
|
340 |
|
|
#statDowns[i].Draw("goff")
|
341 |
|
|
#statDown.Write()
|
342 |
|
|
|
343 |
|
|
histPdf = ROOT.RooDataHist(discr_names[i],discr_names[i],obs,histos[i])
|
344 |
|
|
|
345 |
|
|
#UP stats of MCs
|
346 |
|
|
RooStatsUp = ROOT.RooDataHist('%sCMS_vhbb_stats_%s_%sUp'%(discr_names[i],discr_names[i],options[10]),'%sCMS_vhbb_stats_%s_%sUp'%(discr_names[i],discr_names[i],options[10]),obs, statUps[i])
|
347 |
|
|
#DOWN stats of MCs
|
348 |
|
|
RooStatsDown = ROOT.RooDataHist('%sCMS_vhbb_stats_%s_%sDown'%(discr_names[i],discr_names[i],options[10]),'%sCMS_vhbb_stats_%s_%sDown'%(discr_names[i],discr_names[i],options[10]),obs, statDowns[i])
|
349 |
|
|
|
350 |
|
|
|
351 |
|
|
|
352 |
|
|
|
353 |
|
|
getattr(WS,'import')(histPdf)
|
354 |
|
|
getattr(WS,'import')(RooStatsUp)
|
355 |
|
|
getattr(WS,'import')(RooStatsDown)
|
356 |
|
|
|
357 |
|
|
|
358 |
|
|
|
359 |
|
|
#frame=disc.frame()
|
360 |
|
|
|
361 |
|
|
|
362 |
|
|
#ROOT.RooAbsData.plotOn(histPdf,frame)
|
363 |
|
|
#frame.Draw()
|
364 |
|
|
|
365 |
|
|
#c.Print('~/Hbb/WStest/%s.png'%discr_names[i])
|
366 |
|
|
|
367 |
|
|
#del statUp
|
368 |
|
|
#del statDown
|
369 |
|
|
|
370 |
|
|
|
371 |
|
|
|
372 |
|
|
#print discr_names[i]
|
373 |
|
|
#print histos[i].Integral(0,nBins)
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
|
377 |
|
|
#dunnmies
|
378 |
|
|
#Wlight,Wbb,QCD
|
379 |
|
|
for i in range(6,9):
|
380 |
|
|
dummy = ROOT.TH1F(discr_names[i], "discriminator", nBins, xMin, xMax)
|
381 |
|
|
dummy.SetDirectory(outfile)
|
382 |
|
|
dummy.Write()
|
383 |
|
|
#dummy.Draw("goff")
|
384 |
|
|
|
385 |
|
|
#nominal
|
386 |
|
|
histPdf = ROOT.RooDataHist(discr_names[i],discr_names[i],obs,dummy)
|
387 |
|
|
#UP stats of MCs
|
388 |
|
|
RooStatsUp = ROOT.RooDataHist('%sCMS_vhbb_stats_%s_%sUp'%(discr_names[i],discr_names[i],options[10]),'%sCMS_vhbb_stats_%s_%sUp'%(discr_names[i],discr_names[i],options[10]),obs, dummy)
|
389 |
|
|
#DOWN stats of MCs
|
390 |
|
|
RooStatsDown = ROOT.RooDataHist('%sCMS_vhbb_stats_%s_%sDown'%(discr_names[i],discr_names[i],options[10]),'%sCMS_vhbb_stats_%s_%sDown'%(discr_names[i],discr_names[i],options[10]),obs, dummy)
|
391 |
|
|
|
392 |
|
|
getattr(WS,'import')(histPdf)
|
393 |
|
|
getattr(WS,'import')(RooStatsUp)
|
394 |
|
|
getattr(WS,'import')(RooStatsDown)
|
395 |
|
|
|
396 |
|
|
|
397 |
|
|
|
398 |
|
|
|
399 |
|
|
|
400 |
|
|
#HISTOGRAMM of DATA
|
401 |
|
|
d1 = ROOT.TH1F('d1','d1',nBins,xMin,xMax)
|
402 |
|
|
for i in range(0,len(datas)):
|
403 |
|
|
d1.Add(datas[i],1)
|
404 |
|
|
print "\033[1;32m\n\tDATA integral = %s\033[1;m"%d1.Integral()
|
405 |
|
|
flow = d1.GetEntries()-d1.Integral()
|
406 |
|
|
if flow > 0:
|
407 |
|
|
print "\033[1;31m\tU/O flow: %s\033[1;m"%flow
|
408 |
|
|
|
409 |
|
|
#datas[0]: data_obs
|
410 |
|
|
d1.SetName(data_name[0])
|
411 |
|
|
d1.SetDirectory(outfile)
|
412 |
|
|
d1.Write()
|
413 |
|
|
#d1.Draw("goff")
|
414 |
|
|
|
415 |
|
|
#ROOT.RooDataHist('data_obsHist','',RooArgList,??)
|
416 |
|
|
histPdf = ROOT.RooDataHist('data_obs','data_obs',obs,d1)
|
417 |
|
|
#ROOT.RooAbsData.plotOn(histPdf,frame)
|
418 |
|
|
#frame.Draw()
|
419 |
|
|
|
420 |
|
|
#c.Print('~/Hbb/WStest/d1.png')
|
421 |
|
|
#IMPORT
|
422 |
|
|
getattr(WS,'import')(histPdf)
|
423 |
|
|
|
424 |
|
|
#Number of Obs?
|
425 |
|
|
#nObs = int(d1.Integral())
|
426 |
|
|
|
427 |
|
|
|
428 |
|
|
|
429 |
|
|
|
430 |
|
|
#SYSTEMATICS:
|
431 |
|
|
|
432 |
|
|
#systematics=config.get('systematics','systematics')
|
433 |
|
|
#for sys in systematics[1:]
|
434 |
|
|
|
435 |
|
|
ud = ['up','down']
|
436 |
|
|
UD = ['Up','Down']
|
437 |
|
|
|
438 |
|
|
systhistosarray=[]
|
439 |
|
|
Coco=0
|
440 |
|
|
|
441 |
|
|
for sys in ['JER','JES','beff','bmis']:
|
442 |
|
|
|
443 |
|
|
for Q in range(0,2):
|
444 |
|
|
|
445 |
|
|
ff=options[0].split('.')
|
446 |
|
|
ff[1]='%s_%s'%(sys,ud[Q])
|
447 |
|
|
options[0]='.'.join(ff)
|
448 |
|
|
|
449 |
|
|
|
450 |
|
|
printc('blue','','\t\t--> doing systematic %s %s'%(sys,ud[Q]))
|
451 |
|
|
|
452 |
|
|
systhistosarray.append([])
|
453 |
|
|
#histosX = []
|
454 |
|
|
typsX = []
|
455 |
|
|
|
456 |
|
|
for job in info:
|
457 |
|
|
#print job.name
|
458 |
|
|
if job.type == 'BKG':
|
459 |
|
|
#print 'MC'
|
460 |
|
|
hTemp, typ = getHistoFromTree(job,options)
|
461 |
|
|
systhistosarray[Coco].append(hTemp)
|
462 |
|
|
typsX.append(typ)
|
463 |
|
|
|
464 |
|
|
elif job.type == 'SIG' and job.name == mass:
|
465 |
|
|
#print 'MC'
|
466 |
|
|
hTemp, typ = getHistoFromTree(job,options)
|
467 |
|
|
systhistosarray[Coco].append(hTemp)
|
468 |
|
|
typsX.append(typ)
|
469 |
|
|
|
470 |
|
|
|
471 |
|
|
MC_integral=0
|
472 |
|
|
MC_entries=0
|
473 |
|
|
|
474 |
|
|
for histoX in systhistosarray[Coco]:
|
475 |
|
|
MC_integral+=histoX.Integral()
|
476 |
|
|
#MC_entries+=histo.GetEntries()
|
477 |
|
|
print "\033[1;32m\n\tMC integral = %s\033[1;m"%MC_integral
|
478 |
|
|
#flow = MC_entries-MC_integral
|
479 |
|
|
#if flow > 0:
|
480 |
|
|
# print "\033[1;31m\tU/O flow: %s\033[1;m"%flow
|
481 |
|
|
|
482 |
|
|
#ORDER AND ADD TOGETHER
|
483 |
|
|
ordnungX=[]
|
484 |
|
|
ordnungtypX=[]
|
485 |
|
|
num=[0]*len(setup)
|
486 |
|
|
#printc('red','','num=%s'%num)
|
487 |
|
|
for i in range(0,len(setup)):
|
488 |
|
|
#printc('blue','','i am in %s'%setup[i])
|
489 |
|
|
for j in range(0,len(systhistosarray[Coco])):
|
490 |
|
|
#printc('blue','','i compare %s'%typsX[j])
|
491 |
|
|
if typsX[j] == setup[i]:
|
492 |
|
|
#print 'yes'
|
493 |
|
|
num[i]+=1
|
494 |
|
|
ordnungX.append(systhistosarray[Coco][j])
|
495 |
|
|
|
496 |
|
|
ordnungtypX.append(typsX[j])
|
497 |
|
|
#printc('red','','num=%s'%num)
|
498 |
|
|
|
499 |
|
|
#del systhistosarray[Coco]
|
500 |
|
|
del typsX
|
501 |
|
|
systhistosarray[Coco]=ordnungX
|
502 |
|
|
typsX=ordnungtypX
|
503 |
|
|
for k in range(0,len(num)):
|
504 |
|
|
for m in range(0,num[k]):
|
505 |
|
|
if m > 0:
|
506 |
|
|
systhistosarray[Coco][k].Add(systhistosarray[Coco][k+1],1)
|
507 |
|
|
#printc('red','','added %s to %s'%(typsX[k],typsX[k+1]))
|
508 |
|
|
del systhistosarray[Coco][k+1]
|
509 |
|
|
del typsX[k+1]
|
510 |
|
|
for i in range(0,len(systhistosarray[Coco])):
|
511 |
|
|
systhistosarray[Coco][i].SetName('%sCMS_%s%s'%(discr_names[i],sys,UD[Q]))
|
512 |
|
|
systhistosarray[Coco][i].SetDirectory(outfile)
|
513 |
|
|
systhistosarray[Coco][i].Write()
|
514 |
|
|
#systhistosarray[Coco][i].Draw("goff")
|
515 |
|
|
#histosX[i].Write()
|
516 |
|
|
|
517 |
|
|
histPdf = ROOT.RooDataHist('%sCMS_%s%s'%(discr_names[i],sys,UD[Q]),'%sCMS_%s%s'%(discr_names[i],sys,UD[Q]),obs,systhistosarray[Coco][i])
|
518 |
|
|
getattr(WS,'import')(histPdf)
|
519 |
|
|
|
520 |
|
|
|
521 |
|
|
Coco+=1
|
522 |
|
|
#print Coco
|
523 |
|
|
|
524 |
|
|
WS.writeToFile(outpath+'vhbb_WS_'+ROOToutname+'.root')
|
525 |
|
|
#WS.writeToFile("testWS.root")
|
526 |
|
|
|
527 |
|
|
|
528 |
|
|
|
529 |
|
|
|
530 |
|
|
#write DATAcard:
|
531 |
|
|
|
532 |
|
|
pier = open (Wdir+'/pier.txt','r')
|
533 |
|
|
scalefactors=pier.readlines()
|
534 |
|
|
pier.close()
|
535 |
|
|
|
536 |
|
|
f = open(outpath+'vhbb_DC_'+ROOToutname+'.txt','w')
|
537 |
|
|
f.write('imax\t1\tnumber of channels\n')
|
538 |
peller |
1.2 |
f.write('jmax\t9\tnumber of backgrounds (\'*\' = automatic)\n')
|
539 |
peller |
1.1 |
f.write('kmax\t*\tnumber of nuisance parameters (sources of systematical uncertainties)\n\n')
|
540 |
|
|
|
541 |
peller |
1.2 |
f.write('shapes * * vhbb_WS_%s.root $CHANNEL:$PROCESS $CHANNEL:$PROCESS$SYSTEMATIC\n\n'%ROOToutname)
|
542 |
peller |
1.1 |
f.write('bin\t%s\n\n'%options[10])
|
543 |
|
|
f.write('observation\t%s\n\n'%d1.Integral())
|
544 |
peller |
1.2 |
f.write('bin\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n'%(options[10],options[10],options[10],options[10],options[10],options[10],options[10],options[10],options[10],options[10]))
|
545 |
|
|
f.write('process\tVH\tWjLF\tWjHF\tZjLF\tZjCF\tZjHF\tTT\ts_Top\tVV\tQCD\n')
|
546 |
|
|
f.write('process\t0\t1\t2\t3\t4\t5\t6\t7\t8\t9\n')
|
547 |
|
|
f.write('rate\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n'%(histos[6].Integral(),0,0,histos[0].Integral(),histos[1].Integral(),histos[2].Integral(),histos[3].Integral(),histos[5].Integral(),histos[4].Integral(),0)) #\t1.918\t0.000 0.000\t135.831 117.86 18.718 1.508\t7.015\t0.000
|
548 |
|
|
|
549 |
|
|
|
550 |
|
|
f.write('lumi\tlnN\t1.045\t-\t-\t-\t-\t-\t-\t1.045\t1.045\t1.045\n\n')
|
551 |
|
|
f.write('pdf_qqbar\tlnN\t1.01\t-\t-\t-\t-\t-\t-\t-\t1.01\t-\n')
|
552 |
|
|
f.write('pdf_gg\tlnN\t-\t-\t-\t-\t-\t-\t-\t1.01\t-\t1.01\n')
|
553 |
|
|
f.write('QCDscale_VH\tlnN\t1.04\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
554 |
|
|
f.write('QCDscale_ttbar\tlnN\t-\t-\t-\t-\t-\t-\t-\t1.06\t-\t-\n')
|
555 |
|
|
f.write('QCDscale_VV\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t1.04\t-\n')
|
556 |
|
|
f.write('QCDscale_QCD\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\t1.30\n')
|
557 |
|
|
f.write('CMS_vhbb_boost_EWK\tlnN\t1.05\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
558 |
|
|
f.write('CMS_vhbb_boost_QCD\tlnN\t1.10\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
559 |
|
|
f.write('CMS_vhbb_ST\tlnN\t-\t-\t-\t-\t-\t-\t-\t1.29\t-\t-\n')
|
560 |
|
|
f.write('CMS_vhbb__VV\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t1.30\t-\n')
|
561 |
peller |
1.1 |
|
562 |
|
|
for line in scalefactors:
|
563 |
|
|
f.write(line)
|
564 |
|
|
|
565 |
|
|
'''
|
566 |
|
|
f.write('CMS_vhbb_WjLF_SF\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
567 |
|
|
f.write('CMS_vhbb_WjHF_SF\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
568 |
|
|
f.write('CMS_vhbb_ZjLF_SF\tlnN\t-\t-\t-\t1.06\t-\t-\t-\t-\t-\n')
|
569 |
|
|
f.write('CMS_vhbb_ZjHF_SF\tlnN\t-\t-\t-\t-\t1.17\t-\t-\t-\t-\n')
|
570 |
|
|
f.write('CMS_vhbb_TT_SF\tlnN\t-\t-\t-\t-\t-\t1.14\t-\t-\t-\n')
|
571 |
|
|
f.write('CMS_vhbb_QCD_SF\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
572 |
|
|
'''
|
573 |
|
|
|
574 |
peller |
1.2 |
f.write('CMS_trigger_m\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
575 |
|
|
f.write('CMS_trigger_e\tlnN\t1.02\t-\t-\t-\t-\t-\t-\t1.02\t1.02\t-\n')
|
576 |
|
|
f.write('CMS_vhbb_trigger_MET\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
577 |
peller |
1.1 |
'''
|
578 |
|
|
f.write('CMS_eff_m\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
579 |
|
|
f.write('CMS_eff_e\tlnN\t1.04\t-\t-\t-\t-\t-\t1.04\t1.04\t1.04\n')
|
580 |
|
|
f.write('CMS_toteff_b\tlnN\t1.10\t1.10\t1.00\t1.10\t1.00\t1.10\t1.10\t1.10\t1.10\n')
|
581 |
|
|
f.write('CMS_totscale_j\tlnN\t1.02\t-\t-\t-\t-\t-\t1.02\t1.02\t-\n')
|
582 |
|
|
f.write('CMS_totres_j\tlnN\t1.05\t1.03\t1.03\t1.03\t1.03\t1.03\t1.03\t1.05\t-\n')
|
583 |
|
|
f.write('CMS_vhbb_MET_nojets\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
584 |
|
|
f.write('CMS_vhbb_stats_VH_Wmn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
585 |
|
|
f.write('CMS_vhbb_stats_WjLF_Wmn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
586 |
|
|
f.write('CMS_vhbb_stats_WjHF_Wmn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
587 |
|
|
f.write('CMS_vhb_stats_ZjLF_Wmn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
588 |
|
|
f.write('CMS_vhbb_stats_ZjHF_Wmn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
589 |
|
|
f.write('CMS_vhbb_stats_TT_Wmn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
590 |
|
|
f.write('CMS_vhbb_stats_sT_Wmn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
591 |
|
|
f.write('CMS_vhbb_stats_VV_Wmn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
592 |
|
|
f.write('CMS_vhbb_stats_QCD_Wmn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
593 |
|
|
f.write('CMS_vhbb_stats_Wen\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
594 |
|
|
f.write('CMS_vhbb_stats_WjLF_Wen\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
595 |
|
|
f.write('CMS_vhbb_stats_WjHF_Wen\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
596 |
|
|
f.write('CMS_vhb_stats_ZjLF_Wen\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
597 |
|
|
f.write('CMS_vhbb_stats_ZjHF_Wen\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
598 |
|
|
f.write('CMS_vhbb_stats_TT_Wen\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
599 |
|
|
f.write('CMS_vhbb_stats_sT_Wen\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
600 |
|
|
f.write('CMS_vhbb_stats_VV_Wen\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
601 |
|
|
f.write('CMS_vhbb_stats_QCD_Wen\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
602 |
|
|
f.write('CMS_vhbb_stats_VH_Zmm\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
603 |
|
|
f.write('CMS_vhbb_stats_WjLF_Zmm\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
604 |
|
|
f.write('CMS_vhbb_stats_WjHF_Zmm\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
605 |
|
|
f.write('CMS_vhb_stats_ZjLF_Zmm\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
606 |
|
|
f.write('CMS_vhbb_stats_ZjHF_Zmm\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
607 |
|
|
f.write('CMS_vhbb_stats_TT_Zmm\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
608 |
|
|
f.write('CMS_vhbb_stats_sT_Zmm\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
609 |
|
|
f.write('CMS_vhbb_stats_VV_Zmm\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
610 |
|
|
f.write('CMS_vhbb_stats_QCD_Zmm\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
611 |
|
|
f.write('CMS_vhbb_stats_VH_Zee\tlnN\t1.03\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
612 |
|
|
f.write('CMS_vhbb_stats_WjLF_Zee\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
613 |
|
|
f.write('CMS_vhbb_stats_WjHF_Zee\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
614 |
|
|
f.write('CMS_vhb_stats_ZjLF_Zee\tlnN\t-\t-\t-\t1.05\t-\t-\t-\t-\t-\n')
|
615 |
|
|
f.write('CMS_vhbb_stats_ZjHF_Zee\tlnN\t-\t-\t-\t-\t1.07\t-\t-\t-\t-\n')
|
616 |
|
|
f.write('CMS_vhbb_stats_TT_Zee\tlnN\t-\t-\t-\t-\t-\t1.06\t-\t-\t-\n')
|
617 |
|
|
f.write('CMS_vhbb_stats_sT_Zee\tlnN\t-\t-\t-\t-\t-\t-\t1.30\t-\t-\n')
|
618 |
|
|
f.write('CMS_vhbb_stats_Diboson_Zee\tlnN\t-\t-\t-\t-\t-\t-\t-\t1.06\t-\n')
|
619 |
|
|
f.write('CMS_vhbb_stats_QCD_Zee\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
620 |
|
|
f.write('CMS_vhbb_stats_VH_Znn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
621 |
|
|
f.write('CMS_vhbb_stats_WjLF_Znn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
622 |
|
|
f.write('CMS_vhbb_stats_WjHF_Znn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
623 |
|
|
f.write('CMS_vhb_stats_ZjLF_Znn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
624 |
|
|
f.write('CMS_vhbb_stats_ZjHF_Znn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
625 |
|
|
f.write('CMS_vhbb_stats_TT_Znn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
626 |
|
|
f.write('CMS_vhbb_stats_sT_Znn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
627 |
|
|
f.write('CMS_vhbb_stats_VV_Znn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
628 |
|
|
f.write('CMS_vhbb_stats_QCD_Znn\tlnN\t-\t-\t-\t-\t-\t-\t-\t-\t-\n')
|
629 |
|
|
'''
|
630 |
|
|
#STATS
|
631 |
|
|
#f.write('Stats\tshape\t1.0\t-\t-\t1.0\t1.0\t1.0\t1.0\t1.0\t-\n')
|
632 |
|
|
|
633 |
|
|
|
634 |
|
|
# discr_names = ['Zudscg', 'Zbb', 'TTbar','VV', 'ST', 'Sig115', 'Wudscg', 'Wbb', 'QCD']
|
635 |
|
|
|
636 |
|
|
'''
|
637 |
|
|
f.write('Sig%sStats\tshape\t1.0\t-\t-\t-\t-\t-\t-\t-\t-\n'%mass[2:5])
|
638 |
|
|
#f.write('Stats\tshape\t-\t1.0\t-\t-\t-\t-\t-\t-\t-\n')
|
639 |
|
|
#f.write('Stats\tshape\t-\t-\t1.0\t-\t-\t-\t-\t-\t-\n')
|
640 |
|
|
f.write('ZudscgStats\tshape\t-\t-\t-\t1.0\t-\t-\t-\t-\t-\n')
|
641 |
|
|
f.write('ZbbStats\tshape\t-\t-\t-\t-\t1.0\t-\t-\t-\t-\n')
|
642 |
|
|
f.write('TTbarStats\tshape\t-\t-\t-\t-\t-\t1.0\t-\t-\t-\n')
|
643 |
|
|
f.write('STStats\tshape\t-\t-\t-\t-\t-\t-\t1.0\t-\t-\n')
|
644 |
|
|
f.write('VVStats\tshape\t-\t-\t-\t-\t-\t-\t-\t1.0\t-\n')
|
645 |
|
|
#f.write('Stats\tshape\t-\t-\t-\t-\t-\t-\t-\t-\t1.0\n')
|
646 |
|
|
'''
|
647 |
|
|
|
648 |
peller |
1.2 |
f.write('CMS_vhbb_stats_VH_%s\tshape\t1.0\t-\t-\t-\t-\t-\t-\t-\t-\t-\n'%options[10])
|
649 |
peller |
1.1 |
#f.write('Stats\tshape\t-\t1.0\t-\t-\t-\t-\t-\t-\t-\n')
|
650 |
|
|
#f.write('Stats\tshape\t-\t-\t1.0\t-\t-\t-\t-\t-\t-\n')
|
651 |
peller |
1.2 |
f.write('CMS_vhbb_stats_ZjLF_%s\tshape\t-\t-\t-\t1.0\t-\t-\t-\t-\t-\t-\n'%options[10])
|
652 |
|
|
f.write('CMS_vhbb_stats_ZjCF_%s\tshape\t-\t-\t-\t-\t1.0\t-\t-\t-\t-\t-\n'%options[10])
|
653 |
|
|
f.write('CMS_vhbb_stats_ZjHF_%s\tshape\t-\t-\t-\t-\t-\t1.0\t-\t-\t-\t-\n'%options[10])
|
654 |
|
|
f.write('CMS_vhbb_stats_TT_%s\tshape\t-\t-\t-\t-\t-\t-\t1.0\t-\t-\t-\n'%options[10])
|
655 |
|
|
f.write('CMS_vhbb_stats_s_Top_%s\tshape\t-\t-\t-\t-\t-\t-\t-\t1.0\t-\t-\n'%options[10])
|
656 |
|
|
f.write('CMS_vhbb_stats_VV_%s\tshape\t-\t-\t-\t-\t-\t-\t-\t-\t1.0\t-\n'%options[10])
|
657 |
peller |
1.1 |
#f.write('Stats\tshape\t-\t-\t-\t-\t-\t-\t-\t-\t1.0\n')
|
658 |
|
|
|
659 |
|
|
#Sig115 Wudscg Wbb Zudscg Zbb TTbar ST VV QCD
|
660 |
|
|
|
661 |
|
|
#SYST
|
662 |
peller |
1.2 |
f.write('CMS_JER\tshape\t1.0\t-\t-\t1.0\t1.0\t1.0\t1.0\t1.0\t1.0\t-\n')
|
663 |
|
|
f.write('CMS_JES\tshape\t1.0\t-\t-\t1.0\t1.0\t1.0\t1.0\t1.0\t1.0\t-\n')
|
664 |
|
|
f.write('CMS_beff\tshape\t1.0\t-\t-\t1.0\t1.0\t1.0\t1.0\t1.0\t1.0\t-\n')
|
665 |
|
|
f.write('CMS_bmis\tshape\t1.0\t-\t-\t1.0\t1.0\t1.0\t1.0\t1.0\t1.0\t-\n')
|
666 |
peller |
1.1 |
|
667 |
|
|
|
668 |
|
|
f.close()
|
669 |
|
|
|
670 |
|
|
|
671 |
|
|
outfile.Write()
|
672 |
|
|
outfile.Close()
|
673 |
|
|
|
674 |
|
|
|
675 |
|
|
|
676 |
|
|
|
677 |
|
|
|