1 |
jengbou |
1.1 |
|
2 |
|
|
import sys,os
|
3 |
|
|
#################################
|
4 |
|
|
# Modify selection accordingly to
|
5 |
|
|
# read $path/Results_${sel}.txt
|
6 |
|
|
# and make table
|
7 |
|
|
#################################
|
8 |
|
|
|
9 |
|
|
#________________________________________________________________
|
10 |
|
|
def main():
|
11 |
|
|
|
12 |
|
|
if len(sys.argv) < 1:
|
13 |
|
|
print "[usage] make_table.py <dir> or"
|
14 |
jengbou |
1.2 |
print "e.g. make_table.py /Users/jengbou/Desktop/TopWork/Analysis/CMSSW_3_6_3/Results_2.88pb-1_XXXX/MC/"
|
15 |
jengbou |
1.1 |
sys.exit()
|
16 |
|
|
|
17 |
|
|
path = sys.argv[1]
|
18 |
|
|
|
19 |
jengbou |
1.2 |
# select = ['Sel0','Sel1','Sel2','Sel3','Sel4']
|
20 |
jengbou |
1.3 |
select = [sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5],sys.argv[6],sys.argv[7]]
|
21 |
jengbou |
1.1 |
|
22 |
|
|
outName = "Summary_Results.txt"
|
23 |
|
|
outfile = open(path+outName, 'w')
|
24 |
|
|
outfile.write("<STYLE type=\"text/css\">\n")
|
25 |
|
|
outfile.write("td.alr {text-align: right}\n")
|
26 |
|
|
outfile.write("</STYLE>\n")
|
27 |
|
|
outfile.write("<table border=\"1\">\n")
|
28 |
jengbou |
1.2 |
|
29 |
jengbou |
1.1 |
outfile.write("<tr>")
|
30 |
jengbou |
1.2 |
outfile.write("<th BGCOLOR=\"#99CCFF\"> Selection </th>")
|
31 |
jengbou |
1.1 |
files = []
|
32 |
|
|
for sel in select:
|
33 |
|
|
files.append(path+'Results_'+sel+'.txt')
|
34 |
jengbou |
1.2 |
outfile.write("<th BGCOLOR=\"#99CCFF\">")
|
35 |
jengbou |
1.1 |
outfile.write(sel)
|
36 |
|
|
outfile.write("</th>")
|
37 |
|
|
outfile.write("</tr>\n")
|
38 |
|
|
|
39 |
jengbou |
1.2 |
n_col = len(select) ## num of selection/files
|
40 |
|
|
|
41 |
jengbou |
1.3 |
n_row = 27 ## mum of values for each sel
|
42 |
jengbou |
1.2 |
mtxVal = [[0 for col in range(n_col)] for row in range(n_row)]
|
43 |
jengbou |
1.3 |
mtxErrVal = [[0 for col in range(n_col)] for row in range(8)]
|
44 |
jengbou |
1.2 |
|
45 |
|
|
nth_file = 0;
|
46 |
jengbou |
1.1 |
|
47 |
|
|
for f in files:
|
48 |
|
|
|
49 |
|
|
print "\n Open File: " + f
|
50 |
|
|
txtfile = open(f,"r")
|
51 |
|
|
infolist = txtfile.readlines()
|
52 |
|
|
|
53 |
|
|
nth_rcd = 0
|
54 |
jengbou |
1.2 |
nth_proc_b = 0;
|
55 |
|
|
nth_proc_s = 0;
|
56 |
jengbou |
1.1 |
for line in infolist:
|
57 |
jengbou |
1.2 |
## Total events in (pseudo) Data
|
58 |
|
|
if line.find("Events in Data") > -1: ## Total evts
|
59 |
jengbou |
1.3 |
mtxVal[0][nth_file] = line[line.find("=")+1:line.find("+/-")]
|
60 |
|
|
mtxErrVal[0][nth_file] = line[line.find("+/-")+3:-1]
|
61 |
jengbou |
1.2 |
## QCD, InvSel QCD/Data and WJets
|
62 |
|
|
if line.find("Events QCD sample") > -1: ## Total QCD MC evts
|
63 |
jengbou |
1.3 |
mtxVal[20][nth_file] = line[line.find("=")+1:line.find("+/-")]
|
64 |
|
|
mtxErrVal[1][nth_file] = line[line.find("+/-")+3:-1]
|
65 |
jengbou |
1.2 |
if line.find("Events InvSel sample") > -1: ## Total InvSel QCD/Data evts
|
66 |
jengbou |
1.3 |
mtxVal[21][nth_file] = line[line.find("=")+1:line.find("+/-")]
|
67 |
|
|
mtxErrVal[2][nth_file] = line[line.find("+/-")+3:-1]
|
68 |
|
|
if line.find("Events WJets sample") > -1: ## Total WJets MC evts
|
69 |
|
|
mtxVal[22][nth_file] = line[line.find("=")+1:line.find("+/-")]
|
70 |
|
|
mtxErrVal[3][nth_file] = line[line.find("+/-")+3:-1]
|
71 |
jengbou |
1.2 |
## Non-wjets_MC
|
72 |
jengbou |
1.3 |
if line.find("Events TTbar sample") > -1: ## Total TTbar MC evts
|
73 |
|
|
mtxVal[23][nth_file] = line[line.find("=")+1:line.find("+/-")]
|
74 |
|
|
mtxErrVal[4][nth_file] = line[line.find("+/-")+3:-1]
|
75 |
|
|
if line.find("Events ZJets sample") > -1: ## Total ZJets MC evts
|
76 |
|
|
mtxVal[24][nth_file] = line[line.find("=")+1:line.find("+/-")]
|
77 |
|
|
mtxErrVal[5][nth_file] = line[line.find("+/-")+3:-1]
|
78 |
|
|
if line.find("Events STtch sample") > -1: ## Total STtch MC evts
|
79 |
|
|
mtxVal[25][nth_file] = line[line.find("=")+1:line.find("+/-")]
|
80 |
|
|
mtxErrVal[6][nth_file] = line[line.find("+/-")+3:-1]
|
81 |
|
|
if line.find("Total MC Events") > -1: ## Total MC evts
|
82 |
|
|
mtxVal[26][nth_file] = line[line.find("=")+1:line.find("+/-")]
|
83 |
|
|
mtxErrVal[7][nth_file] = line[line.find("+/-")+3:-1]
|
84 |
jengbou |
1.2 |
|
85 |
jengbou |
1.1 |
if line.find("combined") > -1:
|
86 |
|
|
nth_rcd += 1
|
87 |
jengbou |
1.2 |
if nth_rcd == 1: ## % of QCD
|
88 |
|
|
mtxVal[1][nth_file] = line[line.find("=")+1:-1]
|
89 |
|
|
if nth_rcd == 2: ## % of WJets
|
90 |
|
|
mtxVal[2][nth_file] = line[line.find("=")+1:-1]
|
91 |
|
|
if line.find("Scale Factor") > -1: ## SF QCD
|
92 |
|
|
mtxVal[3][nth_file] = line[line.find("MC =")+4:-1]
|
93 |
|
|
if line.find("allKS") > -1: ## SF WJets
|
94 |
|
|
mtxVal[4][nth_file] = line[line.find("sample =")+8:-1]
|
95 |
|
|
|
96 |
|
|
if line.find("proc_background") > -1:
|
97 |
|
|
nth_proc_b += 1
|
98 |
|
|
if nth_proc_b == 1:
|
99 |
|
|
mtxVal[5][nth_file] = line[line.find("=")+1:-1]
|
100 |
|
|
if nth_proc_b == 2:
|
101 |
|
|
mtxVal[6][nth_file] = line[line.find("=")+1:-1]
|
102 |
|
|
if nth_proc_b == 3:
|
103 |
|
|
mtxVal[7][nth_file] = line[line.find("=")+1:-1]
|
104 |
|
|
|
105 |
|
|
if line.find("proc_sample") > -1:
|
106 |
|
|
nth_proc_s += 1
|
107 |
|
|
if nth_proc_s == 1:
|
108 |
|
|
mtxVal[8][nth_file] = line[line.find("=")+1:-1]
|
109 |
|
|
if nth_proc_s == 2:
|
110 |
|
|
mtxVal[9][nth_file] = line[line.find("=")+1:-1]
|
111 |
|
|
if nth_proc_s == 3:
|
112 |
|
|
mtxVal[10][nth_file] = line[line.find("=")+1:-1]
|
113 |
jengbou |
1.1 |
|
114 |
jengbou |
1.2 |
nth_file += 1
|
115 |
jengbou |
1.1 |
|
116 |
jengbou |
1.2 |
#### Summary of KSmax test
|
117 |
|
|
outfile.write("<tr>")
|
118 |
|
|
outfile.write("<th BGCOLOR=\"#66FF66\"> Total number of events </th>")
|
119 |
|
|
for i in range(n_col):
|
120 |
|
|
outfile.write("<th>"+mtxVal[0][i]+"</th>")
|
121 |
jengbou |
1.1 |
outfile.write("</tr>\n")
|
122 |
jengbou |
1.2 |
|
123 |
jengbou |
1.1 |
outfile.write("<tr>")
|
124 |
jengbou |
1.2 |
outfile.write("<th BGCOLOR=\"#66FF66\"> QCD (%) </th>")
|
125 |
|
|
for i in range(n_col):
|
126 |
jengbou |
1.3 |
outfile.write("<th>"+str(round(float(mtxVal[1][i]),2))+"</th>")
|
127 |
jengbou |
1.2 |
outfile.write("</tr>\n")
|
128 |
jengbou |
1.1 |
|
129 |
jengbou |
1.2 |
outfile.write("<tr>")
|
130 |
|
|
outfile.write("<th BGCOLOR=\"#66FF66\"> Nevt QCD </th>")
|
131 |
|
|
for i in range(n_col):
|
132 |
jengbou |
1.3 |
outfile.write("<th BGCOLOR=\"#CCFFCC\">"+str(int(round(float(mtxVal[1][i])*float(mtxVal[0][i])/100,0)))+"</th>")
|
133 |
jengbou |
1.1 |
outfile.write("</tr>\n")
|
134 |
jengbou |
1.2 |
|
135 |
jengbou |
1.1 |
outfile.write("<tr>")
|
136 |
jengbou |
1.2 |
outfile.write("<th BGCOLOR=\"#66FF66\"> Scale Factor for QCD </th>")
|
137 |
|
|
for i in range(n_col):
|
138 |
jengbou |
1.3 |
outfile.write("<th>"+str(round(float(mtxVal[3][i]),3))+"</th>")
|
139 |
jengbou |
1.2 |
outfile.write("</tr>\n")
|
140 |
jengbou |
1.1 |
|
141 |
jengbou |
1.2 |
outfile.write("<tr>")
|
142 |
|
|
outfile.write("<th BGCOLOR=\"#66FF66\"> WJets (%) </th>")
|
143 |
|
|
for i in range(n_col):
|
144 |
jengbou |
1.3 |
outfile.write("<th>"+str(round(float(mtxVal[2][i]),2))+"</th>")
|
145 |
jengbou |
1.2 |
outfile.write("</tr>\n")
|
146 |
|
|
|
147 |
|
|
outfile.write("<tr>")
|
148 |
|
|
outfile.write("<th BGCOLOR=\"#66FF66\"> Nevt WJets </th>")
|
149 |
|
|
for i in range(n_col):
|
150 |
jengbou |
1.3 |
outfile.write("<th BGCOLOR=\"#CCFFCC\">"+str(int(round(float(mtxVal[2][i])*float(mtxVal[0][i])/100,0)))+"</th>")
|
151 |
jengbou |
1.2 |
outfile.write("</tr>\n")
|
152 |
|
|
|
153 |
|
|
outfile.write("<tr>")
|
154 |
|
|
outfile.write("<th BGCOLOR=\"#66FF66\"> Scale Factor for WJets </th>")
|
155 |
|
|
for i in range(n_col):
|
156 |
|
|
outfile.write("<th>"+mtxVal[4][i]+"</th>")
|
157 |
|
|
outfile.write("</tr>\n")
|
158 |
|
|
|
159 |
|
|
outfile.write("<tr>")
|
160 |
|
|
outfile.write("<th BGCOLOR=\"#66FF66\"> Others (%) </th>")
|
161 |
|
|
for i in range(n_col):
|
162 |
|
|
val = 100 - float(mtxVal[1][i]) - float(mtxVal[2][i])
|
163 |
jengbou |
1.3 |
outfile.write("<th>"+str(round(val,2))+"</th>")
|
164 |
jengbou |
1.2 |
outfile.write("</tr>\n")
|
165 |
|
|
|
166 |
|
|
outfile.write("<tr>")
|
167 |
|
|
outfile.write("<th colspan=\""+str(int(n_col)+1)+"\"> Others: Z+Jets, ")
|
168 |
|
|
outfile.write("t<span style=\"text-decoration:overline;\"> t </span> and single top t-ch </th>")
|
169 |
|
|
outfile.write("</tr>\n")
|
170 |
|
|
|
171 |
|
|
#### Separate KS test
|
172 |
|
|
outfile.write("<tr>")
|
173 |
|
|
outfile.write("<th BGCOLOR=\"#00FF00\" colspan=\""+str(int(n_col)+1)+"\"> Separate KS test results </th>")
|
174 |
|
|
outfile.write("</tr>\n")
|
175 |
|
|
|
176 |
|
|
outfile.write("<tr>")
|
177 |
|
|
outfile.write("<th BGCOLOR=\"#FFFF00\" colspan=\""+str(int(n_col)+1)+"\"> Muon P<sub>T</sub> </th>")
|
178 |
|
|
outfile.write("</tr>\n")
|
179 |
|
|
|
180 |
|
|
outfile.write("<tr>")
|
181 |
|
|
outfile.write("<th > SF<sub>QCD</sub> </th>")
|
182 |
|
|
for i in range(n_col):
|
183 |
|
|
val = float(mtxVal[5][i])*float(mtxVal[21][i])/float(mtxVal[20][i])
|
184 |
jengbou |
1.3 |
outfile.write("<th>"+str(round(val,3))+"</th>")
|
185 |
jengbou |
1.2 |
outfile.write("</tr>\n")
|
186 |
|
|
|
187 |
|
|
outfile.write("<tr>")
|
188 |
|
|
outfile.write("<th > SF<sub>WJets</sub> </th>")
|
189 |
|
|
for i in range(n_col):
|
190 |
|
|
outfile.write("<th>"+mtxVal[8][i]+"</th>")
|
191 |
|
|
outfile.write("</tr>\n")
|
192 |
|
|
|
193 |
|
|
outfile.write("<tr>")
|
194 |
|
|
outfile.write("<th BGCOLOR=\"#FFFF00\" colspan=\""+str(int(n_col)+1)+"\"> MET </th>")
|
195 |
|
|
outfile.write("</tr>\n")
|
196 |
|
|
|
197 |
|
|
outfile.write("<tr>")
|
198 |
|
|
outfile.write("<th > SF<sub>QCD</sub> </th>")
|
199 |
|
|
for i in range(n_col):
|
200 |
|
|
val = float(mtxVal[6][i])*float(mtxVal[21][i])/float(mtxVal[20][i])
|
201 |
jengbou |
1.3 |
outfile.write("<th>"+str(round(val,3))+"</th>")
|
202 |
jengbou |
1.2 |
outfile.write("</tr>\n")
|
203 |
|
|
|
204 |
|
|
outfile.write("<tr>")
|
205 |
|
|
outfile.write("<th > SF<sub>WJets</sub> </th>")
|
206 |
|
|
for i in range(n_col):
|
207 |
|
|
outfile.write("<th>"+mtxVal[9][i]+"</th>")
|
208 |
|
|
outfile.write("</tr>\n")
|
209 |
|
|
|
210 |
|
|
outfile.write("<tr>")
|
211 |
|
|
outfile.write("<th BGCOLOR=\"#FFFF00\" colspan=\""+str(int(n_col)+1)+"\"> M<sub>T</sub> </th>")
|
212 |
|
|
outfile.write("</tr>\n")
|
213 |
|
|
|
214 |
|
|
outfile.write("<tr>")
|
215 |
|
|
outfile.write("<th > SF<sub>QCD</sub> </th>")
|
216 |
|
|
for i in range(n_col):
|
217 |
|
|
val = float(mtxVal[7][i])*float(mtxVal[21][i])/float(mtxVal[20][i])
|
218 |
jengbou |
1.3 |
outfile.write("<th>"+str(round(val,3))+"</th>")
|
219 |
jengbou |
1.2 |
outfile.write("</tr>\n")
|
220 |
|
|
|
221 |
|
|
outfile.write("<tr>")
|
222 |
|
|
outfile.write("<th > SF<sub>WJets</sub> </th>")
|
223 |
|
|
for i in range(n_col):
|
224 |
|
|
outfile.write("<th>"+mtxVal[10][i]+"</th>")
|
225 |
|
|
outfile.write("</tr>\n")
|
226 |
|
|
|
227 |
|
|
outfile.write("<tr>")
|
228 |
|
|
outfile.write("<th BGCOLOR=\"#0066FF\" colspan=\""+str(int(n_col)+1)+"\"> MC expected events </th>")
|
229 |
|
|
outfile.write("</tr>\n")
|
230 |
jengbou |
1.1 |
|
231 |
jengbou |
1.2 |
outfile.write("<tr>")
|
232 |
|
|
outfile.write("<th > t<span style=\"text-decoration:overline;\"> t </span></th>")
|
233 |
|
|
for i in range(n_col):
|
234 |
jengbou |
1.3 |
outfile.write("<th>"+str(round(float(mtxVal[23][i]),1))+"</th>")
|
235 |
jengbou |
1.2 |
outfile.write("</tr>\n")
|
236 |
|
|
outfile.write("<tr>")
|
237 |
|
|
outfile.write("<th > W+jets </th>")
|
238 |
|
|
for i in range(n_col):
|
239 |
jengbou |
1.3 |
outfile.write("<th>"+str(round(float(mtxVal[22][i]),1))+"</th>")
|
240 |
jengbou |
1.2 |
outfile.write("</tr>\n")
|
241 |
|
|
outfile.write("<tr>")
|
242 |
|
|
outfile.write("<th > Z+jets </th>")
|
243 |
|
|
for i in range(n_col):
|
244 |
jengbou |
1.3 |
outfile.write("<th>"+str(round(float(mtxVal[24][i]),1))+"</th>")
|
245 |
jengbou |
1.2 |
outfile.write("</tr>\n")
|
246 |
|
|
outfile.write("<tr>")
|
247 |
|
|
outfile.write("<th > Single Top t-ch </th>")
|
248 |
|
|
for i in range(n_col):
|
249 |
jengbou |
1.3 |
outfile.write("<th>"+str(round(float(mtxVal[25][i]),1))+"</th>")
|
250 |
jengbou |
1.2 |
outfile.write("</tr>\n")
|
251 |
|
|
outfile.write("<tr>")
|
252 |
|
|
outfile.write("<th > QCD </th>")
|
253 |
|
|
for i in range(n_col):
|
254 |
jengbou |
1.3 |
outfile.write("<th>"+str(round(float(mtxVal[20][i]),1))+"</th>")
|
255 |
jengbou |
1.1 |
outfile.write("</tr>\n")
|
256 |
|
|
|
257 |
|
|
outfile.write("</table>")
|
258 |
|
|
outfile.close()
|
259 |
|
|
|
260 |
|
|
|
261 |
|
|
if __name__ =='__main__':
|
262 |
|
|
sys.exit(main())
|
263 |
|
|
|