-
Notifications
You must be signed in to change notification settings - Fork 0
/
bothmakeplots.py
215 lines (198 loc) · 7.63 KB
/
bothmakeplots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
from pull import *
from correlation import *
import os
def makecorrelation(allnames, corrmatrix, filename):
#corrmatrix.reverse()
toberemove = []
realsysname = []
for i in range(len(allnames)):
# if "gamma_stat" in allnames[i]:
# toberemove.append(i)
# if "mu" == allnames[i]:
# toberemove.append(i)
#if allnames[i][0:3] != "Sys":
if "bin" in allnames[i]:
toberemove.append(i)
#print(allnames[i][0:3])
else:
realsysname.append(allnames[i])
syscorrmatrix = []
for i in range(len(allnames)):
if i not in toberemove:
tem_corr = []
for j in range(len(corrmatrix[i])):
if j not in toberemove:
tem_corr.append(corrmatrix[i][j])
syscorrmatrix.append(tem_corr)
#print(len(syscorrmatrix), len(syscorrmatrix[0]), len(realsysname))
correlation(syscorrmatrix, realsysname, filename)
toberemove = []
for i in range(len(realsysname)):
donotremoveit = 0
for each in syscorrmatrix[i]:
if abs(each) > 0.2:
donotremoveit += 1
if donotremoveit < 2:
toberemove.append(i)
#print(toberemove)
syscorrmatrix_sm = []
realsysname_sm = []
for i in range(len(realsysname)):
if i in toberemove:
continue
realsysname_sm.append(realsysname[i])
tem = []
for j in range(len(syscorrmatrix[i])):
if j not in toberemove:
tem.append(syscorrmatrix[i][j])
syscorrmatrix_sm.append(tem)
correlation(syscorrmatrix_sm, realsysname_sm, filename + "sm", number=True)
havemu = False
datafile = "GlobalFit_fitres_unconditionnal_mu0.txt"
if "GlobalFit_fitres_unconditionnal_mu1.txt" in os.listdir():
datafile = "GlobalFit_fitres_unconditionnal_mu1.txt"
# if "GlobalFit_fitres_conditionnal_mu0.txt" in os.listdir():
# datafile = "GlobalFit_fitres_conditionnal_mu0.txt"
asimovfile = "GlobalFit_fitres_unconditionnal_mu0_as.txt"
if "GlobalFit_fitres_conditionnal_mu0.txt" in os.listdir():
datafile = "GlobalFit_fitres_conditionnal_mu0.txt"
asimovfile = "GlobalFit_fitres_conditionnal_mu1_as.txt"
havemu = True
sysnames = []
syspullcentre = []
syspullerror = []
statnames = []
statpullcentre = []
statpullerror = []
allnames = []
corrmatrix = []
with open(datafile) as f:
ispull = False
iscorr = False
for each_line in f:
if ispull:
if "&" in each_line:
iname = each_line.index("&")
name_tem = each_line[0:iname]
name_tem = name_tem.replace('\\','')
name_tem = name_tem.replace(' ','')
i1centre = each_line.index("$") + 1
i2centre = each_line.index("^")
pullcentre_tem = float(each_line[i1centre:i2centre])
i1error = each_line.index("+") + 1
i2error = each_line.index("}")
pullerror_tem = float(each_line[i1error:i2error])
allnames.append(name_tem)
if not havemu:
if name_tem[0] == 'n':
allnames[-1] = 'mu'
allnames.append(name_tem)
havemu = True
if "gamma_stat" in name_tem:
statnames.append(name_tem)
statpullcentre.append(pullcentre_tem)
statpullerror.append(pullerror_tem)
else:
sysnames.append(name_tem)
syspullcentre.append(pullcentre_tem)
syspullerror.append(pullerror_tem)
else:
ispull = False
elif iscorr:
corr_tem = [float(i) for i in each_line.split()]
if len(corr_tem) > 3:
corr_tem.reverse()
corrmatrix.append(corr_tem)
if "NUISANCE_PARAMETERS" in each_line:
ispull = True
if "CORRELATION_MATRIX" in each_line:
iscorr = True
sysnames_as = []
syspullcentre_as = []
syspullerror_as = []
statnames_as = []
statpullcentre_as = []
statpullerror_as = []
allnames_as = []
corrmatrix_as = []
havemu = False
if "GlobalFit_fitres_conditionnal_mu1.txt" in os.listdir():
havemu = True
if "GlobalFit_fitres_conditionnal_mu0.txt" in os.listdir():
havemu = True
with open(asimovfile) as f:
ispull = False
iscorr = False
for each_line in f:
if ispull:
if "&" in each_line:
iname = each_line.index("&")
name_tem = each_line[0:iname]
name_tem = name_tem.replace('\\','')
name_tem = name_tem.replace(' ','')
i1centre = each_line.index("$") + 1
i2centre = each_line.index("^")
pullcentre_tem = float(each_line[i1centre:i2centre])
i1error = each_line.index("+") + 1
i2error = each_line.index("}")
pullerror_tem = float(each_line[i1error:i2error])
allnames_as.append(name_tem)
if not havemu:
if name_tem[0] == 'n':
allnames_as[-1] = 'mu'
allnames_as.append(name_tem)
havemu = True
if "gamma_stat" in name_tem:
statnames_as.append(name_tem)
statpullcentre_as.append(pullcentre_tem)
statpullerror_as.append(pullerror_tem)
else:
sysnames_as.append(name_tem)
syspullcentre_as.append(pullcentre_tem)
syspullerror_as.append(pullerror_tem)
else:
ispull = False
elif iscorr:
corr_tem = [float(i) for i in each_line.split()]
if len(corr_tem) > 3:
corr_tem.reverse()
corrmatrix_as.append(corr_tem)
if "NUISANCE_PARAMETERS" in each_line:
ispull = True
if "CORRELATION_MATRIX" in each_line:
iscorr = True
for each, eachas in zip(sysnames, sysnames_as):
if each != eachas:
print("Error: sysname order does not match!")
exit(1)
findlumi = False
for i in range(len(sysnames)):
if sysnames[i][0:3] == "Sys":
sysnames[i] = sysnames[i][3:]
continue
if not findlumi and sysnames[i] == "Luminositynosity":
sysnames[i] = "Luminosity"
findlumi = True
findlumi = False
for i in range(len(allnames)):
if allnames[i][0:3] == "Sys":
allnames[i] = allnames[i][3:]
continue
if not findlumi and allnames[i] == "Luminositynosity":
allnames[i] = "Luminosity"
findlumi = True
findlumi = False
for i in range(len(allnames_as)):
if allnames_as[i][0:3] == "Sys":
allnames_as[i] = allnames_as[i][3:]
continue
if not findlumi and allnames_as[i] == "Luminositynosity":
allnames_as[i] = "Luminosity"
findlumi = True
middlepull = int(len(sysnames)/2)
pull(syspullcentre,syspullerror,sysnames,"pullplot", datac=syspullcentre_as, datae=syspullerror_as)
pull(syspullcentre[0:middlepull],syspullerror[0:middlepull],sysnames[0:middlepull],"pullplot1", datac=syspullcentre_as[0:middlepull], datae=syspullerror_as[0:middlepull])
pull(syspullcentre[middlepull+1:],syspullerror[middlepull+1:],sysnames[middlepull+1:],"pullplot2", datac=syspullcentre_as[middlepull+1:], datae=syspullerror_as[middlepull+1:])
pull(statpullcentre,statpullerror,statnames,"pullstatplot", datac=statpullcentre_as, datae=statpullerror_as)
makecorrelation(allnames, corrmatrix, "correlation_sysandnorm")
makecorrelation(allnames_as, corrmatrix_as, "correlation_sysandnorm_as")