ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/tools/make_table.py
(Generate patch)

Comparing UserCode/Jeng/tools/make_table.py (file contents):
Revision 1.1 by jengbou, Wed Sep 8 06:48:09 2010 UTC vs.
Revision 1.2 by jengbou, Fri Sep 10 05:04:49 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines