-
Notifications
You must be signed in to change notification settings - Fork 7
/
tableFromCards.py
executable file
·154 lines (116 loc) · 5.12 KB
/
tableFromCards.py
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python
import re
from sys import argv
import os.path
from optparse import OptionParser
from math import sqrt,fabs
parser = OptionParser()
parser.add_option("-s", "--stat", dest="stat", default=False, action="store_true") # ignore systematic uncertainties to consider statistical uncertainties only
parser.add_option("-S", "--force-shape", dest="shape", default=False, action="store_true") # ignore systematic uncertainties to consider statistical uncertainties only
parser.add_option("-a", "--asimov", dest="asimov", default=False, action="store_true")
parser.add_option("-m", "--mass", dest="mass", default=125, type="float")
(options, args) = parser.parse_args()
options.bin = True # fake that is a binary output, so that we parse shape lines
options.noJMax = False
options.nuisancesToExclude = ''
from DatacardParser import *
DC = parseCard(file(args[0]), options)
nuisToConsider = [ y for y in DC.systs ]
errors = {}
for nuis in nuisToConsider:
if nuis[2] == 'gmN': gmN = nuis[3][0]
else : gmN = 0
for channel in nuis[4]:
#print channel
if channel not in errors.keys(): errors[channel] = {}
for process in nuis[4][channel]:
newError = 0.
if nuis[2] == 'gmN': gmN = nuis[3][0]
if nuis[4][channel][process] == 0: continue
#print nuis[2],gmN
if gmN != 0:
newError = nuis[4][channel][process] * sqrt(gmN) / DC.exp[channel][process]
else:
#print nuis[4][channel][process]
if not isinstance ( nuis[4][channel][process], float ) :
# [0.95, 1.23]
#if len(nuis[4][channel][process]) == 2 :
newError = fabs((nuis[4][channel][process][1]-nuis[4][channel][process][0])/2.) # symmetrized
else :
newError = fabs(1-nuis[4][channel][process])
if process in errors[channel].keys():
errors[channel][process] += newError*newError
else:
errors[channel][process] = newError*newError
for channel in errors:
for process in errors[channel]:
errors[channel][process] = sqrt(errors[channel][process])
for x in DC.exp:
for y in DC.exp[x]:
print "%10s %10s %10.2f +/- %10.2f (%10.2f \\%%)" % (x,y,DC.exp[x][y],DC.exp[x][y]*errors[x][y],errors[x][y]*100)
size = "footnotesize"
print "\n"
print "========================="
print "\n latex style \n"
print "\\begin{table}[h!]\\begin{center}"
print ("\\%s{\\begin{tabular}{" % size)
print ("c|"),
for channel in DC.exp:
print ("c |"),
print "} \\hline"
print (" "),
for channel in DC.exp:
print ("& %13s " % channel.replace('_', '-')),
print ("\\\\ \\hline")
signals = DC.list_of_signals()
backgrounds = DC.list_of_backgrounds()
totsig = {}
errtotsig = {}
totbkg = {}
errtotbkg = {}
for s in signals :
print (" %13s " % s.replace('_', '-')),
for channel in DC.exp:
if s in DC.exp[channel].keys(): # possible that some backgrounds appear only in some channels
print (" & %10.2f +/- %10.2f (%10.0f \\%%) " % (DC.exp[channel][s],DC.exp[channel][s]*errors[channel][s],errors[channel][s]*100)),
if channel not in totsig.keys(): totsig[channel] = 0.0
if channel not in errtotsig.keys(): errtotsig[channel] = 0.0
totsig[channel] = totsig[channel] + DC.exp[channel][s]
errtotsig[channel] = errtotsig[channel] + (DC.exp[channel][s]*errors[channel][s] * DC.exp[channel][s]*errors[channel][s])
#print " <<< sqrt errtotsig[",channel,"] = ", sqrt(errtotsig[channel]) , ">>> "
else :
print (" & - "),
print ("\\\\")
print ("\\hline")
print (" %13s " % "signal"),
for channel in DC.exp:
errtotsig[channel] = sqrt(errtotsig[channel])
print (" & %10.2f +/- %10.2f (%10.0f \\%%) " % (totsig[channel],errtotsig[channel],errtotsig[channel]/totsig[channel]*100)),
print ("\\\\")
print ("\\hline")
for b in backgrounds :
print (" %13s " % b.replace('_', '-')),
for channel in DC.exp:
if b in DC.exp[channel].keys(): # possible that some backgrounds appear only in some channels
print (" & %10.2f +/- %10.2f (%10.0f \\%%) " % (DC.exp[channel][b],DC.exp[channel][b]*errors[channel][b],errors[channel][b]*100)),
if channel not in totbkg.keys(): totbkg[channel] = 0.0
if channel not in errtotbkg.keys(): errtotbkg[channel] = 0.0
totbkg[channel] = totbkg[channel] + DC.exp[channel][b]
errtotbkg[channel] = errtotbkg[channel] + (DC.exp[channel][b]*errors[channel][b] * DC.exp[channel][b]*errors[channel][b])
else :
print (" & - "),
print ("\\\\")
print ("\\hline")
print (" %13s " % "background"),
for channel in DC.exp:
errtotbkg[channel] = sqrt(errtotbkg[channel])
print (" & %10.2f +/- %10.2f (%10.0f\\%%) " % (totbkg[channel],errtotbkg[channel],errtotbkg[channel]/totbkg[channel]*100)),
print ("\\\\")
print ("\\hline")
print "\\end{tabular}"
print "}"
print "\\end{center}"
print "\n\n\n"
print "\\end{table}"
print "========================="
print "\n\n\n"