-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreadDC_and_plot_subset.py
102 lines (66 loc) · 2.8 KB
/
readDC_and_plot_subset.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
#!/usr/bin/python
import os
import sys
import subprocess
import operator
from ROOT import TFile, TH1F, TCanvas, gStyle, TLine
from commands import getstatusoutput
from operator import itemgetter
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
def getLimitFromFile (filename) :
filenameResult = filename+".limit.txt"
print " >> file: "+filenameResult
f = open (filenameResult, 'r')
calcLimit = f.read()
isThereTheLimit = False
for line in calcLimit.split ('\n') :
if line.find ('Expected 50.0') != -1 :
isThereTheLimit = True
if isThereTheLimit :
thisLimit = [line for line in calcLimit.split ('\n') if line.find ('Expected 50.0') != -1][0].split ()[4]
else :
thisLimit = -1.
print "thisLimit = "+str(thisLimit)
return thisLimit
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
def clean (basename) :
getstatusoutput('rm ./' + basename + '*')
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
def lookAtSystematics (datacardname) :
# open the datacard file
# ---- ---- ---- ---- ---- ---- ---- ----
print 'Opening original input datacard: ', datacardname
nametag = datacardname.split ('/')[-1].replace ('.txt', '')
thepath = datacardname.replace (nametag + '.txt', '')
Results = {}
syslist = []
# get the actual result with the original datacard
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
nominalLimit = getLimitFromFile (datacardname)
Results['NOMINAL'] = nominalLimit
# get the result with the modified datacard
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
filename = thepath + 'tempo.subset.' + nametag
thisLimit = getLimitFromFile (filename)
Results["subset"] = thisLimit
# get the result with no systematics
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
filename = thepath + 'tempo.stats.txt'
statsLimit = getLimitFromFile (filename)
Results["STATISTICAL"] = statsLimit
print "**********************************"
for kind in Results :
print " > ",kind," = ",Results[kind]
print "**********************************"
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
if __name__ == '__main__':
if len (sys.argv) < 2 :
print 'input datacard folder missing\n'
exit (1)
folderName = sys.argv[1].split ('/')[-1] + '_copy_subset'
currentFolder = getstatusoutput ('pwd')[1]
listOfDatacards = []
for elem in getstatusoutput ('ls ' + str (folderName) + ' | grep -v tempo | grep -v limit | grep -v submit | grep txt')[1].split ('\n'):
listOfDatacards.append (currentFolder + '/' + folderName + '/' + str (elem))
for datacard in listOfDatacards :
lookAtSystematics (datacard)