1 |
#!/usr/bin/env python
|
2 |
import pickle
|
3 |
import ROOT
|
4 |
from array import array
|
5 |
import sys, os
|
6 |
from optparse import OptionParser
|
7 |
from copy import copy,deepcopy
|
8 |
from math import sqrt
|
9 |
ROOT.gROOT.SetBatch(True)
|
10 |
|
11 |
#CONFIGURE
|
12 |
argv = sys.argv
|
13 |
parser = OptionParser()
|
14 |
parser.add_option("-R", "--region", dest="region", default="",
|
15 |
help="region to plot")
|
16 |
parser.add_option("-M", "--figure_of_merit", dest="fom", default="",
|
17 |
help="figure of merit to be used to weight the plots. Possibilities: s/b, s/sqrt(b)")
|
18 |
parser.add_option("-C", "--config", dest="config", default=[], action="append",
|
19 |
help="configuration file")
|
20 |
(opts, args) = parser.parse_args(argv)
|
21 |
if opts.config =="":
|
22 |
opts.config = "config"
|
23 |
|
24 |
from myutils import BetterConfigParser, printc, ParseInfo, mvainfo, StackMaker, HistoMaker
|
25 |
|
26 |
print opts.config
|
27 |
opts.config.append('8TeVconfig/vhbbPlotDef.ini')
|
28 |
config = BetterConfigParser()
|
29 |
config.read(opts.config)
|
30 |
|
31 |
def get_s_over_b(fName):
|
32 |
#using bin 9, 10, 11
|
33 |
s=0
|
34 |
b=0
|
35 |
histos = get_th1(fName)
|
36 |
for histo in histos:
|
37 |
if 'data' in histo.GetName(): continue
|
38 |
for i in range(9,11):
|
39 |
if 'VH' in histo.GetName():
|
40 |
s+=histo.GetBinContent(i)
|
41 |
else:
|
42 |
b+=histo.GetBinContent(i)
|
43 |
return s/b
|
44 |
|
45 |
def get_s_over_sb(fName):
|
46 |
#using bin 9, 10, 11
|
47 |
s=0
|
48 |
b=0
|
49 |
histos = get_th1(fName)
|
50 |
for histo in histos:
|
51 |
if 'data' in histo.GetName(): continue
|
52 |
for i in range(9,11):
|
53 |
if 'VH' in histo.GetName():
|
54 |
s+=histo.GetBinContent(i)
|
55 |
else:
|
56 |
b+=histo.GetBinContent(i)
|
57 |
return s/(s+b)
|
58 |
|
59 |
|
60 |
def get_th1(fName):
|
61 |
infile = ROOT.TFile.Open(fName,'read')
|
62 |
th1 = []
|
63 |
for key in ROOT.gDirectory.GetListOfKeys():
|
64 |
infile.cd()
|
65 |
th1.append(key.ReadObj())
|
66 |
return th1
|
67 |
|
68 |
def plot():
|
69 |
signalRegion = True
|
70 |
region = 'plot'
|
71 |
var = 'Hmass'
|
72 |
|
73 |
stack = StackMaker(config,var,region,signalRegion)
|
74 |
|
75 |
# fileList = [
|
76 |
# '/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Wln_ch1_Wenu3_PreFit.root',
|
77 |
# '/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Zll_ZeeHighPt_PreFit.root',
|
78 |
# '/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Znn_HighPt_ZnunuHighPt_8TeV_PreFit.root',
|
79 |
# '/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Wln_ch2_Wmunu3_PreFit.root',
|
80 |
# '/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Zll_ZmmHighPt_PreFit.root']
|
81 |
|
82 |
|
83 |
fileList = [
|
84 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Zll_ZmmMedPt_PostFit_s.root',
|
85 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Zll_ZeeMedPt_PostFit_s.root',
|
86 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Znn_MedPt_ZnunuMedPt_8TeV_PostFit_s.root',
|
87 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Wln_ch2_Wmunu2_PostFit_s.root',
|
88 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Znn_LowPt_ZnunuLowPt_8TeV_PostFit_s.root',
|
89 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Zll_ZmmLowPt_PostFit_s.root',
|
90 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Zll_ZeeLowPt_PostFit_s.root',
|
91 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Wln_ch1_Wenu_PostFit_s.root',
|
92 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Wln_ch2_Wmunu_PostFit_s.root',
|
93 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Wln_ch1_WenuHighPt_PostFit_s.root',
|
94 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Zll_ZeeHighPt_PostFit_s.root',
|
95 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Znn_HighPt_ZnunuHighPt_8TeV_PostFit_s.root',
|
96 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Wln_ch2_WmunuHighPt_PostFit_s.root',
|
97 |
'/shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Zll_ZmmHighPt_PostFit_s.root']
|
98 |
|
99 |
|
100 |
# #tau
|
101 |
# /shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Wtn_Wtn_PostFit_s.root
|
102 |
|
103 |
|
104 |
# #Med
|
105 |
# /shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Zll_ZmmMedPt_PostFit_s.root
|
106 |
# /shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Zll_ZeeMedPt_PostFit_s.root
|
107 |
# /shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Znn_MedPt_ZnunuMedPt_8TeV_PostFit_s.root
|
108 |
# /shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Wln_ch2_Wmunu2_PostFit_s.root
|
109 |
|
110 |
# #Low
|
111 |
|
112 |
# /shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Znn_LowPt_ZnunuLowPt_8TeV_PostFit_s.root
|
113 |
# /shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Zll_ZmmLowPt_PostFit_s.root
|
114 |
# /shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Zll_ZeeLowPt_PostFit_s.root
|
115 |
# /shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Wln_ch1_Wenu_PostFit_s.root
|
116 |
# /shome/bortigno/VHbbAnalysis/postPreApp//LHCP_PostFit/MJJ_Wln_ch2_Wmunu_PostFit_s.root
|
117 |
|
118 |
fileList += ['ZeeLowPt_7TeV.root','ZmmLowPt_7TeV.root','WmnLowPt_7TeV.root','ZnnLowPt_7TeV.root']
|
119 |
fileList += ['ZeeHighPt_7TeV.root','ZmmHighPt_7TeV.root','WmnHighPt_7TeV.root','ZnnHighPt_7TeV.root']
|
120 |
|
121 |
histosL = []
|
122 |
for file in fileList:
|
123 |
print file
|
124 |
print get_s_over_b(file)
|
125 |
for th1 in get_th1(file):
|
126 |
if opts.fom == 's/b':
|
127 |
th1.Scale(10*get_s_over_b(file))
|
128 |
if opts.fom == 's/s+b':
|
129 |
th1.Scale(10*get_s_over_sb(file))
|
130 |
|
131 |
histosL.append(th1)
|
132 |
|
133 |
print 'histoL'
|
134 |
print histosL
|
135 |
typs = []
|
136 |
typsL = []
|
137 |
datas = []
|
138 |
datasL = []
|
139 |
|
140 |
#append the name just once
|
141 |
for histo in histosL:
|
142 |
typsL.append(histo.GetName())
|
143 |
if 'data' in histo.GetName():
|
144 |
datasL.append(histo)
|
145 |
|
146 |
#datasL.append(datas)
|
147 |
#typsL.append(typs)
|
148 |
print typsL
|
149 |
|
150 |
stack.histos = histosL
|
151 |
stack.typs = typsL
|
152 |
stack.datas = datasL
|
153 |
# stack.datatyps = Ldatatyps[v]
|
154 |
stack.datanames='data_obs'
|
155 |
#if signalRegion:
|
156 |
# stack.overlay = ['VH','VVHF','VVLF']
|
157 |
# stack.options['pdfName'] = stack.options['pdfName'].replace('.pdf','_preFit.pdf')
|
158 |
stack.options['pdfName'] = stack.options['pdfName'].replace('.pdf','_combined78tev_postFit_s_over_sb.pdf')
|
159 |
# stack.options['pdfName'] = stack.options['pdfName'].replace('.pdf','_highPt_7tev.pdf')
|
160 |
# stack.options['pdfName'] = stack.options['pdfName'].replace('.pdf','_combined_postFit_s_over_b_Hpt_weight_1.pdf'
|
161 |
stack.lumi = 19040
|
162 |
stack.doPlot()
|
163 |
|
164 |
# stack.options['pdfName'] = stack.options['pdfName'].replace('.pdf','_subtructed.pdf')
|
165 |
# stack.doSubPlot(['VH','VVHF','VVLF'])
|
166 |
print 'i am done!\n'
|
167 |
|
168 |
|
169 |
plot()
|
170 |
sys.exit(0)
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|