ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/tools/make_table.py
Revision: 1.1
Committed: Wed Sep 8 06:48:09 2010 UTC (14 years, 7 months ago) by jengbou
Content type: text/x-python
Branch: MAIN
Log Message:
add files

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     print "e.g. make_table.py /Users/jengbou/Desktop/TopWork/Analysis/CMSSW_3_6_3/Results_2.88pb-1_NEW/MC/"
16     sys.exit()
17    
18     path = sys.argv[1]
19    
20     select = ['Sel0','Sel1','Sel2','Sel3','Sel4']
21    
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     outfile.write("<tr>")
29     outfile.write("<th> Selection </th>")
30    
31     files = []
32     for sel in select:
33     files.append(path+'Results_'+sel+'.txt')
34     outfile.write("<th>")
35     outfile.write(sel)
36     outfile.write("</th>")
37    
38     outfile.write("</tr>\n")
39     outfile.write("<tr>")
40    
41     ksvalT = []
42     ksvalS = []
43     ksvalB = []
44    
45     for f in files:
46    
47     print "\n Open File: " + f
48     txtfile = open(f,"r")
49     infolist = txtfile.readlines()
50    
51     nth_rcd = 0
52     for line in infolist:
53     if line.find("Events in Data") > -1:
54     ksvalT.append(line[line.find("=")+1:-1])
55     if line.find("combined") > -1:
56     nth_rcd += 1
57     if nth_rcd == 1:
58     ksvalB.append(line[line.find("=")+1:-1])
59     if nth_rcd == 2:
60     ksvalS.append(line[line.find("=")+1:-1])
61    
62     outfile.write("<th> Total number of events </th>")
63     for val in ksvalT:
64     outfile.write("<th>"+val+"</th>")
65    
66     outfile.write("</tr>\n")
67     outfile.write("<tr>")
68     outfile.write("<th> QCD (%) </th>")
69     for val in ksvalB:
70     outfile.write("<th>")
71     outfile.write(val)
72     outfile.write("</th>")
73    
74     outfile.write("</tr>\n")
75     outfile.write("<tr>")
76     outfile.write("<th> WJets (%) </th>")
77    
78     for val in ksvalS:
79     outfile.write("<th>")
80     outfile.write(val)
81     outfile.write("</th>")
82    
83     outfile.write("</tr>\n")
84    
85     outfile.write("</table>")
86     outfile.close()
87    
88    
89     if __name__ =='__main__':
90     sys.exit(main())
91