1 |
mdunser |
1.1 |
#!/usr/bin/python
|
2 |
|
|
## written by an austrian.
|
3 |
|
|
|
4 |
|
|
import os, commands, math, sys
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
def getL1File(directory, region):
|
8 |
|
|
if not os.path.isdir(directory):
|
9 |
|
|
print 'Directory does not exist! I\'ll try give ../,dir. a try...'
|
10 |
|
|
directory='../'+directory
|
11 |
|
|
if not os.path.isdir(directory):
|
12 |
|
|
print 'still not a directory... exiting. be sure you exectute this script in the right place...'
|
13 |
|
|
sys.exit()
|
14 |
|
|
ls = os.listdir(directory) # get the list of files/directories
|
15 |
|
|
newls = []
|
16 |
|
|
for i in ls: # clean the list a bit
|
17 |
|
|
if ('L1' in i) and ('SR'+str(region) in i):
|
18 |
|
|
print i
|
19 |
|
|
newls.append(i)
|
20 |
|
|
return newls # return list of strings with correct L1 filenames for given region
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
def loadInfo(models):
|
24 |
|
|
#uncerts = ['acc', 'sigCont', 'jmetErr', 'btagErr', 'expLim', 'obsLim' ]
|
25 |
|
|
dic = {}
|
26 |
|
|
## loop on all files and store all values in a fairly complicated dictionary
|
27 |
|
|
for sig in models:
|
28 |
|
|
dic[sig] = {}
|
29 |
|
|
for reg in range(maxreg+1):
|
30 |
|
|
dic[sig][reg] = {}
|
31 |
|
|
filelist = getL1File(sig, reg)
|
32 |
|
|
for f in filelist:
|
33 |
|
|
fo = open(sig+'/'+f,'r')
|
34 |
|
|
unc = f.split('_')[2]
|
35 |
|
|
dic[sig][reg][unc] = {}
|
36 |
|
|
lines = fo.readlines()
|
37 |
|
|
for line in lines:
|
38 |
|
|
xval = line.split()[0]
|
39 |
|
|
yval = line.split()[1]
|
40 |
|
|
uval = line.split()[2]
|
41 |
|
|
dic[sig][reg][unc][xval+'_'+yval] = float(uval)
|
42 |
|
|
fo.close()
|
43 |
|
|
## all the info is stored now, calculate the rest of the info (combine uncertainties etc.)
|
44 |
|
|
for sig in dic.keys():
|
45 |
|
|
for reg in dic[sig].keys():
|
46 |
|
|
dic[sig][reg]['corrAcc'] = {}
|
47 |
|
|
dic[sig][reg]['totErr'] = {}
|
48 |
|
|
for p in dic[sig][reg]['acc'].keys():
|
49 |
|
|
dic[sig][reg]['corrAcc'][p] = dic[sig][reg]['acc'][p] - dic[sig][reg]['sigCont'][p]
|
50 |
claudioc |
1.2 |
dic[sig][reg]['totErr'][p] = math.sqrt(dic[sig][reg]['btagErr'][p]**2 + dic[sig][reg]['jmetErr'][p]**2)# more errors here once available
|
51 |
mdunser |
1.1 |
## add here also the ULs. will do that once everything is ready
|
52 |
|
|
|
53 |
|
|
return dic
|
54 |
|
|
|
55 |
|
|
maxreg = 8
|
56 |
|
|
## comment in all the model you want to have processed
|
57 |
|
|
## NB: a directory with the model name has to exist
|
58 |
|
|
models = ['T1tttt',
|
59 |
|
|
# 'sstop',
|
60 |
|
|
# 'glsbottom',
|
61 |
|
|
# 'glstop',
|
62 |
|
|
# 'sbottompair'
|
63 |
|
|
]
|
64 |
|
|
|
65 |
|
|
if __name__ == '__main__':
|
66 |
|
|
d = loadInfo(models)
|
67 |
|
|
## merging takes place here
|
68 |
|
|
for m in d.keys():
|
69 |
|
|
for r in d[m].keys():
|
70 |
|
|
## create the L2 files in the model directory
|
71 |
|
|
f = open(m+'/'+m+'_SR'+str(r)+'_md_.txt', 'w')
|
72 |
|
|
for p in d[m][r]['acc'].keys():
|
73 |
|
|
mx = int(p.split('_')[0])
|
74 |
|
|
my = int(p.split('_')[1])
|
75 |
|
|
ac = d[m][r]['corrAcc'][p]
|
76 |
|
|
er = d[m][r]['totErr'][p]
|
77 |
|
|
f.write('%10i\t\t%10i\t\t%.5f\t\t%.5f\n' %(mx, my, ac, er) )
|
78 |
|
|
f.close()
|