-
Notifications
You must be signed in to change notification settings - Fork 1
/
readDC_and_plot_mu_subset.py
106 lines (70 loc) · 3.08 KB
/
readDC_and_plot_mu_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
101
102
103
104
#!/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 getMuErrorFromFile (filename) :
filenameResult = filename+".mu.txt"
print " >> file: "+filenameResult
f = open (filenameResult, 'r')
calcLimit = f.read()
# e.g. 0 1 2 3 4
# Best fit r: 0.723266 -0.259866/+0.292765 (68% CL)
isThereTheLimit = False
for line in calcLimit.split ('\n') :
if line.find ('Best fit r:') != -1 :
isThereTheLimit = True
if isThereTheLimit :
thisMuError = [line for line in calcLimit.split ('\n') if line.find ('Best fit r:') != -1][0].split ()[4]
errorMinus = float(thisMuError.replace('-','').replace('+','').split("/")[0])
errorPlus = float(thisMuError.replace('-','').replace('+','').split("/")[1])
error = (errorMinus+errorPlus) / 2.
else :
error = -1
return error
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
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 = getMuErrorFromFile (datacardname)
Results['NOMINAL'] = nominalLimit
# get the result with the modified datacard
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
filename = thepath + 'tempo.subset.' + nametag
thisLimit = getMuErrorFromFile (filename)
Results["subset"] = thisLimit
# get the result with no systematics
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
filename = thepath + 'tempo.stats.txt'
statsLimit = getMuErrorFromFile (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_mu_subset'
currentFolder = getstatusoutput ('pwd')[1]
listOfDatacards = []
for elem in getstatusoutput ('ls ' + str (folderName) + ' | grep -v tempo | grep -v .mu | grep -v submit | grep txt')[1].split ('\n'):
listOfDatacards.append (currentFolder + '/' + folderName + '/' + str (elem))
for datacard in listOfDatacards :
lookAtSystematics (datacard)