-
Notifications
You must be signed in to change notification settings - Fork 2
/
plotRatios_experimental.py
131 lines (92 loc) · 3.86 KB
/
plotRatios_experimental.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
import ROOT
class TFValidator:
def __init__(self,input_ws_file,fit_file):
self.fiws = ROOT.TFile.Open(input_ws_file)
self.workspace = self.fiws.Get("w")
self.fit_file = ROOT.TFile.Open(fit_file)
self.r = ROOT.TRandom3()
self.nbins=9
self.ntoys = 1000
self.cat = "MTR_2017"
self.ZProc = "mumu"
self.WProc = "munu"
self.ZR = "MUMU"
self.WR = "MUNU"
def calcR(self,b):
zq = self.workspace.function("%sQCDV_%s_bin%d"%(self.cat,self.ZProc,b)).getVal()
ze = self.workspace.function("%sEWKV_%s_bin%d"%(self.cat,self.ZProc,b)).getVal()
wq = self.workspace.function("%sQCDV_%s_bin%d"%(self.cat,self.WProc,b)).getVal()
we = self.workspace.function("%sEWKV_%s_bin%d"%(self.cat,self.WProc,b)).getVal()
return (ze+zq)/(we+wq)
def returnRMS(self,b,includeStat=False):
r2=0
mean=0
allpars = self.workspace.function("%sQCDV_%s_bin%d"%(self.cat,self.ZProc,b)).getParameters(ROOT.RooArgSet())
allpars2 = self.workspace.function("%sEWKV_%s_bin%d"%(self.cat,self.ZProc,b)).getParameters(ROOT.RooArgSet())
allpars.add(allpars2)
npar = allpars.getSize()
collactedParams = []
for t in range(self.ntoys):
#for n in range(npar):
iter = allpars.createIterator()
while 1:
tpar = iter.Next() # allpars.at(n)
if tpar == None : break
# ignore theory uncertainties - also of course, ignore scale factors (float params)
# not even sure of the first 2 but they are constant at least
if "TF_syst_fnlo_SF" in tpar.GetName(): continue
if "ewkqcdratio_stat" in tpar.GetName(): continue
if "QCDwzratioQCDcorrSyst" in tpar.GetName(): continue
if "EWKwzratioQCDcorrSyst" in tpar.GetName(): continue
if "QCDwzratio_EWK_corr_on_Strong" in tpar.GetName(): continue
if "EWKwzratio_EWK_corr_on_Strong_bin" in tpar.GetName(): continue
if "QCDwzratio_stat_bin" in tpar.GetName(): continue
if "QCDZ_SR_bin" in tpar.GetName() : continue
if t==0: collactedParams.append(tpar.GetName())
self.workspace.var(tpar.GetName()).setVal(self.r.Gaus(0,1))
rwz = self.calcR(b)
#print rwz
r2 += rwz*rwz
mean += rwz
mean /=self.ntoys
rms = (r2/self.ntoys - mean*mean)**0.5
#print " Parameters for ", self.cat, self.ZProc, " -> "
#for p in collactedParams: print p
#print " ---------------------------------------------"
# Reset
iter = allpars.createIterator()
while 1:
tpar = iter.Next() # allpars.at(n)
if tpar == None : break
if "TF_syst_fnlo_SF" in tpar.GetName(): continue
if "ewkqcdratio_stat" in tpar.GetName(): continue
if "QCDwzratioQCDcorrSyst" in tpar.GetName(): continue
if "EWKwzratioQCDcorrSyst" in tpar.GetName(): continue
if "QCDwzratio_EWK_corr_on_Strong" in tpar.GetName(): continue
if "EWKwzratio_EWK_corr_on_Strong_bin" in tpar.GetName(): continue
if "QCDwzratio_stat_bin" in tpar.GetName(): continue
if "QCDZ_SR_bin" in tpar.GetName() : continue
self.workspace.var(tpar.GetName()).setVal(0)
return rms
def calcRdata(self,b):
data_Z = self.fit_file.Get("shapes_prefit/%s/data"%self.ZR)
Zd = data_Z.GetY()[b-1]
Ze = 0.5*(data_Z.GetErrorYhigh(b-1)+data_Z.GetErrorYlow(b-1))
data_W = self.fit_file.Get("shapes_prefit/%s/data"%self.WR)
Wd = data_W.GetY()[b-1]
We = 0.5*(data_W.GetErrorYhigh(b-1)+data_W.GetErrorYlow(b-1))
# Remove the backgrounds!
TT_Z = self.fit_file.Get("shapes_prefit/%s/TOP"%self.ZR)
ttZ_d = TT_Z.GetBinContent(b)
VV_Z = self.fit_file.Get("shapes_prefit/%s/VV"%self.ZR)
VVZ_d = VV_Z.GetBinContent(b)
# Remove the backgrounds!
TT_W = self.fit_file.Get("shapes_prefit/%s/TOP"%self.WR)
ttW_d = TT_W.GetBinContent(b)
VV_W = self.fit_file.Get("shapes_prefit/%s/VV"%self.WR)
VVW_d = VV_W.GetBinContent(b)
Wd -= (ttW_d+VVW_d)
Zd -= (ttZ_d+VVZ_d)
rwz = Zd/Wd
rwz_e = rwz * ( ( (Ze/Zd)**2 + (We/Wd)**2)**0.5 )
return rwz, rwz_e