1 |
import ROOT
|
2 |
import ConfigParser, re
|
3 |
import sys
|
4 |
sys.path.append( '/afs/naf.desy.de/user/n/nowaf/CMSSW_3_3_6/src/LeptonSel/LeptonSel/rootScripts' )
|
5 |
import definitions as Def
|
6 |
from math import sqrt
|
7 |
|
8 |
def main(argv):
|
9 |
#import sys
|
10 |
|
11 |
basepath = ''
|
12 |
|
13 |
try:
|
14 |
options, arguments = getopt.getopt(argv, "hp:", ["help","path="])
|
15 |
|
16 |
except getopt.GetoptError:
|
17 |
usage()
|
18 |
sys.exit(2)
|
19 |
|
20 |
for opt, arg in options:
|
21 |
if opt in ("-h", "--help"):
|
22 |
usage()
|
23 |
sys.exit(2)
|
24 |
elif opt in ("-p", "--path"):
|
25 |
basepath = arg
|
26 |
|
27 |
if basepath == '':
|
28 |
print "Error! Need path to .cfg file to continue."
|
29 |
sys.exit(2)
|
30 |
|
31 |
return basepath
|
32 |
|
33 |
def usage():
|
34 |
|
35 |
print "Script to plot all XC study plots for the di lepton analysis"
|
36 |
print "Options and arguments:"
|
37 |
print "-h, --help\t\t: print this help message and exit"
|
38 |
print "-p, --path\t\t: relative path to the .cfg file"
|
39 |
|
40 |
pass
|
41 |
|
42 |
|
43 |
|
44 |
def readTheConfig(name):
|
45 |
"""
|
46 |
read in the config file
|
47 |
"""
|
48 |
config = ConfigParser.ConfigParser()
|
49 |
config.read( name )
|
50 |
|
51 |
return config
|
52 |
|
53 |
def getStudiedCut( name ):
|
54 |
"""
|
55 |
gets the studied cut out of the section name
|
56 |
"""
|
57 |
studied = ""
|
58 |
if re.search( "EJ", name ) or re.search( "PJ", name ):
|
59 |
studied = "cut on E_{shared}/E_{Jet}"
|
60 |
if re.search( "dR", name ):
|
61 |
studied = "max #delta R (non iso elec, jet)"
|
62 |
elif re.search( "MJ", name ):
|
63 |
studied = "#delta R (muon, jet)"
|
64 |
|
65 |
return studied
|
66 |
|
67 |
def MakeDivision( h_1, h_2, option ):
|
68 |
"""
|
69 |
divides two histograms, computes errors
|
70 |
and returns the result
|
71 |
"""
|
72 |
#h_1.Sumw2()
|
73 |
#h_2.Sumw2()
|
74 |
hist = h_2.Clone()
|
75 |
hist.Divide( h_1, h_2, 1., 1., option )
|
76 |
|
77 |
return hist
|
78 |
|
79 |
def Fill( hist, option, weight ):
|
80 |
"""
|
81 |
h.SetBinContent sets the content right, but has only
|
82 |
one wheighted entry then. This gives problems in dividing the
|
83 |
histograms. This fill function takes care of that
|
84 |
"""
|
85 |
for i in range( 0, weight ):
|
86 |
hist.Fill( float( option ) )
|
87 |
|
88 |
return hist
|
89 |
|
90 |
|
91 |
if __name__ == "__main__":
|
92 |
|
93 |
import getopt
|
94 |
|
95 |
basepath = main(sys.argv[1:])
|
96 |
|
97 |
|
98 |
Def.SetGlobalStyles( "emr" )
|
99 |
|
100 |
saves = {}
|
101 |
|
102 |
config = readTheConfig( basepath )
|
103 |
|
104 |
for section in config.sections():
|
105 |
|
106 |
print "section: ", section
|
107 |
|
108 |
studied_cut = getStudiedCut( section )
|
109 |
|
110 |
nbin = 9
|
111 |
min = 0.05
|
112 |
max = 0.95
|
113 |
if( re.search( "EJ_dR", section ) ):
|
114 |
min = 0.15
|
115 |
max = 1.05
|
116 |
pass
|
117 |
|
118 |
h_mu_m = ROOT.TH1F( "h_mu_m", "h_mu_m",nbin,min,max )
|
119 |
h_mu_gen = ROOT.TH1F( "h_mu_gen", "h_mu_gen",nbin,min,max )
|
120 |
h_mu_nm = ROOT.TH1F( "h_mu_nm", "h_mu_nm",nbin,min,max )
|
121 |
h_mu_all = ROOT.TH1F( "h_mu_all", "h_mu_all",nbin,min,max )
|
122 |
h_el_m = ROOT.TH1F( "h_el_m", "h_el_m",nbin,min,max )
|
123 |
h_el_gen = ROOT.TH1F( "h_el_gen", "h_el_gen",nbin,min,max )
|
124 |
h_el_nm = ROOT.TH1F( "h_el_nm", "h_el_nm",nbin,min,max )
|
125 |
h_el_all = ROOT.TH1F( "h_el_all", "h_el_all",nbin,min,max )
|
126 |
h_ph_m = ROOT.TH1F( "h_ph_m", "h_ph_m",nbin,min,max )
|
127 |
h_ph_gen = ROOT.TH1F( "h_ph_gen", "h_ph_gen",nbin,min,max )
|
128 |
h_ph_nm = ROOT.TH1F( "h_ph_nm", "h_ph_nm",nbin,min,max )
|
129 |
h_ph_all = ROOT.TH1F( "h_ph_all", "h_ph_all",nbin,min,max )
|
130 |
h_je_m = ROOT.TH1F( "h_je_m", "h_je_m",nbin,min,max )
|
131 |
h_je_gen = ROOT.TH1F( "h_je_gen", "h_je_gen",nbin,min,max )
|
132 |
h_je_nm = ROOT.TH1F( "h_je_nm", "h_je_nm",nbin,min,max )
|
133 |
h_je_all = ROOT.TH1F( "h_je_all", "h_je_all",nbin,min,max )
|
134 |
|
135 |
h_mu_m.Sumw2()
|
136 |
h_mu_gen.Sumw2()
|
137 |
h_mu_nm.Sumw2()
|
138 |
h_mu_all.Sumw2()
|
139 |
h_el_m.Sumw2()
|
140 |
h_el_gen.Sumw2()
|
141 |
h_el_nm.Sumw2()
|
142 |
h_el_all.Sumw2()
|
143 |
h_ph_m.Sumw2()
|
144 |
h_ph_gen.Sumw2()
|
145 |
h_ph_nm.Sumw2()
|
146 |
h_ph_all.Sumw2()
|
147 |
h_je_m.Sumw2()
|
148 |
h_je_gen.Sumw2()
|
149 |
h_je_nm.Sumw2()
|
150 |
h_je_all.Sumw2()
|
151 |
|
152 |
|
153 |
#print type( h_mu_eff)
|
154 |
|
155 |
for option in config.options( section ):
|
156 |
|
157 |
print "option: ", option
|
158 |
|
159 |
if re.search( "afs", config.get( section, option ) ) or re.search( "current", config.get( section, option ) ):
|
160 |
fin = Def.ReadInRootFile( config.get( section, option ) + "/studyXC.root" )
|
161 |
else:
|
162 |
fin = Def.ReadInRootFile( "./../test/" + config.get( section, option ) + "/studyXC.root" )
|
163 |
|
164 |
|
165 |
Tree_ = fin.Get( 'StudyXC' )
|
166 |
mu_all = Def.defineArray( 'i', 1 )
|
167 |
mu_gen = Def.defineArray( 'i', 1 )
|
168 |
mu_m = Def.defineArray( 'i', 1 )
|
169 |
mu_nm = Def.defineArray( 'i', 1 )
|
170 |
el_all = Def.defineArray( 'i', 1 )
|
171 |
el_gen = Def.defineArray( 'i', 1 )
|
172 |
el_m = Def.defineArray( 'i', 1 )
|
173 |
el_nm = Def.defineArray( 'i', 1 )
|
174 |
ph_all = Def.defineArray( 'i', 1 )
|
175 |
ph_gen = Def.defineArray( 'i', 1 )
|
176 |
ph_m = Def.defineArray( 'i', 1 )
|
177 |
ph_nm = Def.defineArray( 'i', 1 )
|
178 |
je_all = Def.defineArray( 'i', 1 )
|
179 |
je_gen = Def.defineArray( 'i', 1 )
|
180 |
je_m = Def.defineArray( 'i', 1 )
|
181 |
je_nm = Def.defineArray( 'i', 1 )
|
182 |
|
183 |
Tree_.SetBranchAddress( "MuonsAll", mu_all )
|
184 |
Tree_.SetBranchAddress( "MuonsGen", mu_gen )
|
185 |
Tree_.SetBranchAddress( "MuonsNotMatched", mu_nm )
|
186 |
Tree_.SetBranchAddress( "MuonsMatched", mu_m )
|
187 |
Tree_.SetBranchAddress( "ElectronsAll", el_all )
|
188 |
Tree_.SetBranchAddress( "ElectronsGen", el_gen )
|
189 |
Tree_.SetBranchAddress( "ElectronsNotMatched", el_nm )
|
190 |
Tree_.SetBranchAddress( "ElectronsMatched", el_m )
|
191 |
Tree_.SetBranchAddress( "PhotonsAll", ph_all )
|
192 |
Tree_.SetBranchAddress( "PhotonsGen", ph_gen )
|
193 |
Tree_.SetBranchAddress( "PhotonsNotMatched", ph_nm )
|
194 |
Tree_.SetBranchAddress( "PhotonsMatched", ph_m )
|
195 |
Tree_.SetBranchAddress( "JetsAll", je_all )
|
196 |
Tree_.SetBranchAddress( "JetsGen", je_gen )
|
197 |
Tree_.SetBranchAddress( "JetsNotMatched", je_nm )
|
198 |
Tree_.SetBranchAddress( "JetsMatched", je_m )
|
199 |
|
200 |
n_mu_all = 0
|
201 |
n_mu_gen = 0
|
202 |
n_mu_m = 0
|
203 |
n_mu_nm = 0
|
204 |
n_el_all = 0
|
205 |
n_el_gen = 0
|
206 |
n_el_m = 0
|
207 |
n_el_nm = 0
|
208 |
n_ph_all = 0
|
209 |
n_ph_gen = 0
|
210 |
n_ph_m = 0
|
211 |
n_ph_nm = 0
|
212 |
n_je_all = 0
|
213 |
n_je_gen = 0
|
214 |
n_je_m = 0
|
215 |
n_je_nm = 0
|
216 |
|
217 |
n_bytes = 0
|
218 |
for ent in range( 0, Tree_.GetEntries() ):
|
219 |
|
220 |
n_bytes += Tree_.GetEntry( ent )
|
221 |
n_mu_all += mu_all[0]
|
222 |
n_mu_gen += mu_gen[0]
|
223 |
n_mu_m += mu_m[0]
|
224 |
n_mu_nm += mu_nm[0]
|
225 |
n_el_all += el_all[0]
|
226 |
n_el_gen += el_gen[0]
|
227 |
n_el_m += el_m[0]
|
228 |
n_el_nm += el_nm[0]
|
229 |
n_ph_all += ph_all[0]
|
230 |
n_ph_gen += ph_gen[0]
|
231 |
n_ph_m += ph_m[0]
|
232 |
n_ph_nm += ph_nm[0]
|
233 |
n_je_all += je_all[0]
|
234 |
n_je_gen += je_gen[0]
|
235 |
n_je_m += je_m[0]
|
236 |
n_je_nm += je_nm[0]
|
237 |
pass
|
238 |
|
239 |
|
240 |
Fill( h_mu_m, option, n_mu_m )
|
241 |
Fill( h_mu_gen, option, n_mu_gen )
|
242 |
Fill( h_mu_nm, option, n_mu_nm )
|
243 |
Fill( h_mu_all, option, n_mu_all )
|
244 |
Fill( h_el_m, option, n_el_m )
|
245 |
Fill( h_el_gen, option, n_el_gen )
|
246 |
Fill( h_el_nm, option, n_el_nm )
|
247 |
Fill( h_el_all, option, n_el_all )
|
248 |
Fill( h_ph_m, option, n_ph_m )
|
249 |
Fill( h_ph_gen, option, n_ph_gen )
|
250 |
Fill( h_ph_nm, option, n_ph_nm )
|
251 |
Fill( h_ph_all, option, n_ph_all )
|
252 |
Fill( h_je_m, option, n_je_m )
|
253 |
Fill( h_je_gen, option, n_je_gen )
|
254 |
Fill( h_je_nm, option, n_je_nm )
|
255 |
Fill( h_je_all, option, n_je_all )
|
256 |
|
257 |
print "n_mu_all: ", n_mu_all
|
258 |
print "n_mu_m : ", n_mu_m
|
259 |
print "n_mu_nm : ", n_mu_nm
|
260 |
print "n_mu_gen: ", n_mu_gen
|
261 |
|
262 |
pass
|
263 |
|
264 |
h_mu_eff = MakeDivision( h_mu_m, h_mu_gen, "B" )
|
265 |
h_mu_cont = MakeDivision( h_mu_nm, h_mu_all, "B" )
|
266 |
h_el_eff = MakeDivision( h_el_m, h_el_gen, "B" )
|
267 |
h_el_cont = MakeDivision( h_el_nm, h_el_all, "B" )
|
268 |
h_ph_eff = MakeDivision( h_ph_m, h_ph_gen, "B" )
|
269 |
h_ph_cont = MakeDivision( h_ph_nm, h_ph_all, "B" )
|
270 |
h_je_eff = MakeDivision( h_je_m, h_je_gen, "B" )
|
271 |
h_je_cont = MakeDivision( h_je_nm, h_je_all, "B" )
|
272 |
|
273 |
#for i in range( 0, 9 ):
|
274 |
# print "error in bin ", i, ": ", h_mu_eff.GetBinError( i )
|
275 |
|
276 |
|
277 |
### wrong errors here
|
278 |
h_mu_ratio = MakeDivision( h_mu_eff, h_mu_cont, "" )
|
279 |
h_el_ratio = MakeDivision( h_el_eff, h_el_cont, "" )
|
280 |
h_ph_ratio = MakeDivision( h_ph_eff, h_ph_cont, "" )
|
281 |
h_je_ratio = MakeDivision( h_je_eff, h_je_cont, "" )
|
282 |
|
283 |
|
284 |
## draw the hists for each section
|
285 |
c_mu = ROOT.TCanvas( "c_mu", section + "_Muon" ,1,71,300,600 )
|
286 |
c_mu.Divide(1,2)
|
287 |
c_mu.cd(1)
|
288 |
Def.DrawSmall( c_mu, \
|
289 |
[h_mu_eff, h_mu_cont], [8,50], ["eff","cont"], \
|
290 |
studied_cut, "", "", \
|
291 |
False, 0, False, "ur", section + "muons", saves)
|
292 |
|
293 |
c_mu.cd(2)
|
294 |
Def.DrawSmall( c_mu, \
|
295 |
[h_mu_ratio], [4], ["ratio"], \
|
296 |
studied_cut, "ratio eff / sqrt(cont)", "", \
|
297 |
False, 0, False, "ur", section + "muons_ratio", saves)
|
298 |
|
299 |
c_el = ROOT.TCanvas( "c_el", section + "_Elecs" ,1,71,300,600 )
|
300 |
c_el.Divide(1,2)
|
301 |
c_el.cd(1)
|
302 |
Def.DrawSmall( c_el, \
|
303 |
[h_el_eff, h_el_cont], [8,50], ["eff","cont"], \
|
304 |
studied_cut, "", "", \
|
305 |
False, 0, False, "ur", section + "elecs", saves)
|
306 |
|
307 |
c_el.cd(2)
|
308 |
Def.DrawSmall( c_el, \
|
309 |
[h_el_ratio], [4], ["ratio"], \
|
310 |
studied_cut, "ratio eff / sqrt(cont)", "", \
|
311 |
False, 0, False, "ur", section + "elecs_ratio", saves)
|
312 |
|
313 |
c_ph = ROOT.TCanvas( "c_ph", section + "_Photons" ,1,71,300,600 )
|
314 |
c_ph.Divide(1,2)
|
315 |
c_ph.cd(1)
|
316 |
Def.DrawSmall( c_ph, \
|
317 |
[h_ph_eff, h_ph_cont], [8,50], ["eff","cont"], \
|
318 |
studied_cut, "", "", \
|
319 |
False, 0, False, "ur", section + "phots", saves)
|
320 |
|
321 |
c_ph.cd(2)
|
322 |
Def.DrawSmall( c_ph, \
|
323 |
[h_ph_ratio], [4], ["ratio"], \
|
324 |
studied_cut, "ratio eff / sqrt(cont)", "", \
|
325 |
False, 0, False, "ur", section + "phots_ratio", saves)
|
326 |
|
327 |
c_je = ROOT.TCanvas( "c_je", section + "_Jets" ,1,71,300,600 )
|
328 |
c_je.Divide(1,2)
|
329 |
c_je.cd(1)
|
330 |
Def.DrawSmall( c_je, \
|
331 |
[h_je_eff, h_je_cont], [8,50], ["eff","cont"], \
|
332 |
studied_cut, "", "", \
|
333 |
False, 0, False, "ur", section + "jets", saves)
|
334 |
|
335 |
c_je.cd(2)
|
336 |
Def.DrawSmall( c_je, \
|
337 |
[h_je_ratio], [4], ["ratio"], \
|
338 |
studied_cut, "ratio eff / sqrt(cont)", "", \
|
339 |
False, 0, False, "ur", section + "jets_ratio", saves)
|
340 |
|
341 |
|
342 |
pass
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
Def.DontQuit()
|