ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/tools/make_table.py
Revision: 1.2
Committed: Fri Sep 10 05:04:49 2010 UTC (14 years, 7 months ago) by jengbou
Content type: text/x-python
Branch: MAIN
CVS Tags: gregj-20100925, gregj-20100916, gregj-iks-20100910
Changes since 1.1: +191 -29 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 jengbou 1.1 from ROOT import *
2    
3     import sys,os
4     #################################
5     # Modify selection accordingly to
6     # read $path/Results_${sel}.txt
7     # and make table
8     #################################
9    
10     #________________________________________________________________
11     def main():
12    
13     if len(sys.argv) < 1:
14     print "[usage] make_table.py <dir> or"
15 jengbou 1.2 print "e.g. make_table.py /Users/jengbou/Desktop/TopWork/Analysis/CMSSW_3_6_3/Results_2.88pb-1_XXXX/MC/"
16 jengbou 1.1 sys.exit()
17    
18     path = sys.argv[1]
19    
20 jengbou 1.2 # select = ['Sel0','Sel1','Sel2','Sel3','Sel4']
21     select = [sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5],sys.argv[6]]
22 jengbou 1.1
23     outName = "Summary_Results.txt"
24     outfile = open(path+outName, 'w')
25     outfile.write("<STYLE type=\"text/css\">\n")
26     outfile.write("td.alr {text-align: right}\n")
27     outfile.write("</STYLE>\n")
28     outfile.write("<table border=\"1\">\n")
29 jengbou 1.2
30 jengbou 1.1 outfile.write("<tr>")
31 jengbou 1.2 outfile.write("<th BGCOLOR=\"#99CCFF\"> Selection </th>")
32 jengbou 1.1 files = []
33     for sel in select:
34     files.append(path+'Results_'+sel+'.txt')
35 jengbou 1.2 outfile.write("<th BGCOLOR=\"#99CCFF\">")
36 jengbou 1.1 outfile.write(sel)
37     outfile.write("</th>")
38     outfile.write("</tr>\n")
39    
40 jengbou 1.2 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 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     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 jengbou 1.1 if line.find("combined") > -1:
76     nth_rcd += 1
77 jengbou 1.2 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 jengbou 1.1
104 jengbou 1.2 nth_file += 1
105 jengbou 1.1
106 jengbou 1.2 #### 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 jengbou 1.1 outfile.write("</tr>\n")
112 jengbou 1.2
113 jengbou 1.1 outfile.write("<tr>")
114 jengbou 1.2 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 jengbou 1.1
119 jengbou 1.2 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 jengbou 1.1 outfile.write("</tr>\n")
124 jengbou 1.2
125 jengbou 1.1 outfile.write("<tr>")
126 jengbou 1.2 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 jengbou 1.1
131 jengbou 1.2 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 jengbou 1.1
221 jengbou 1.2 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 jengbou 1.1 outfile.write("</tr>\n")
246    
247     outfile.write("</table>")
248     outfile.close()
249    
250    
251     if __name__ =='__main__':
252     sys.exit(main())
253