forked from kit-cn-cms/BoostedAnalyzer_runscripts_NAF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeYieldTables.py
More file actions
155 lines (118 loc) · 3.2 KB
/
makeYieldTables.py
File metadata and controls
155 lines (118 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import sys
from subprocess import call
from datetime import date
def write_syst(file,value):
file.write(value[0]+' &')
for val in value[1:]:
file.write(val+" &")
file.write('\\\\ \n')
def write_foot(file):
file.write('\\hline\n')
file.write('\end{tabular}\n')
file.write('\\end{center}\n')
def write_head(file,columns):
#print columns
file.write('\\begin{center}\n')
file.write('\\begin{tabular}{l')
for entry in columns[1:]:
file.write('c')
file.write('}\n')
file.write('\\hline\n')
for entry in columns[:-1]:
file.write(entry+' &')
file.write(columns[-1]+' \\\\ \n')
file.write('\\hline\n')
##begin script
if len(sys.argv)<=2:
print "usage:"
print "python makeYieldTables.py OUPUTFILE_WITHOUT_EXTENSION LIST_OF_INPUT_CUTFLOWS"
exit(0)
first=True
samples=[]
suffixes=["MC_MadGraph_","MC_aMCatNLO_"]
affixes=["_nominal_Cutflow.txt","_JESDOWN_Cutflow.txt","_JESUP_Cutflow.txt"]
outfile = sys.argv[1]
for filename in sys.argv[2:]:
sample=[]
steps=[]
nGen=[]
yields=[]
lines=[]
infile=open(filename,"r")
rawlines=list(infile)
for rawline in rawlines:
rawline=rawline.replace("\n","")
lines.append(rawline)
#print filename
samplename=filename.rsplit("/",1)[1]
for suffix in suffixes:
if suffix in samplename:
samplename=samplename.replace(suffix,"")
for affix in affixes:
if affix in samplename:
samplename=samplename.replace(affix,"")
#print samplename
sample.append(samplename)
for line in lines:
print line
splitline=line.split(" : ")
steps.append(splitline[1])
for line in lines:
splitline=line.split(" : ")
nGen.append(splitline[2])
for line in lines:
splitline=line.split(" : ")
yields.append(splitline[3])
sample.append(steps)
sample.append(nGen)
sample.append(yields)
print sample
samples.append(sample)
#print samples
for sample in samples:
if len(sample[1])!=len(samples[0][1]):
print sample[0], " has the wrong number of cutflow steps"
exit(1)
out=open(outfile+"_events.tex","w")
out.write( '\\documentclass{article}\n')
out.write( '\\begin{document}')
s=[]
for sample in samples:
s.append(sample[0])
#print s
write_head(out,["cutflow steps"]+s)
for step in samples[0][1]:
line=[]
line.append(step)
i=samples[0][1].index(step)
for s in samples:
line.append(s[2][i])
write_syst(out,line)
write_foot(out)
out.write("\\end{document}")
out.close()
call(["pdflatex","-interaction","batchmode",outfile+"_events.tex"])
call(["pdftopng",outfile+"_events.pdf",outfile+"_events.png"])
print "did the table for the number of events"
out=open(outfile+"_yields.tex","w")
out.write( '\\documentclass{article}\n')
out.write( '\\begin{document}')
s=[]
for sample in samples:
s.append(sample[0])
#print s
write_head(out,["cutflow steps"]+s)
for step in samples[0][1]:
line=[]
line.append(step)
i=samples[0][1].index(step)
for s in samples:
print s
line.append(s[3][i])
write_syst(out,line)
write_foot(out)
out.write("\\end{document}")
out.close()
call(["pdflatex","-interaction","batchmode",outfile+"_yields.tex"])
call(["pdftopng",outfile+"_yields.pdf",outfile+"_yields.png"])
print "did the table for the yields"