ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/tools/make_table.py
Revision: 1.5
Committed: Wed Oct 20 03:52:09 2010 UTC (14 years, 6 months ago) by jengbou
Content type: text/x-python
Branch: MAIN
CVS Tags: gregj-20110224, gregj-20110223-v1, gregj-20110223, gregj-20110205, gregj-20110114, gregj-20110107, gregj-20101223, gregj-20101212, gregj-20101211, gregj-20101210-new, gregj-20101210, gregj-20101121, gregj-20101113-NEW, gregj-20101113, gregj-20101111-JES_JETONLY, gregj-20101103, gregj-20101101, gregj-20101019, HEAD
Changes since 1.4: +6 -7 lines
Error occurred while calculating annotation data.
Log Message:
update

File Contents

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