1 |
import ROOT
|
2 |
import sys, re, math
|
3 |
sys.path.append("/afs/naf.desy.de/user/n/nowaf/UserCode/nowaf/PythonScripts/")
|
4 |
import definitions as Def
|
5 |
import styles as Style
|
6 |
import MakeRealTauEst_cff as Helper
|
7 |
|
8 |
if __name__ == "__main__":
|
9 |
|
10 |
Def.SetGlobalStyles()
|
11 |
|
12 |
#fileDir = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/QCDFlat_xxxiv/"
|
13 |
#fileDir = "/afs/naf.desy.de/group/cms/scratch/nowaf/CMSSW_4_2_4/src/RA2/Configuration/FinalPlots/"
|
14 |
fileDir = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/RealTauEst/"
|
15 |
|
16 |
fileName = "_lxii"
|
17 |
s = "All"
|
18 |
|
19 |
#Type = "Pre"
|
20 |
#Type = "Full"
|
21 |
Type = "PreCheck"
|
22 |
|
23 |
draw = True
|
24 |
saveToEPS = False
|
25 |
saveToPS = False
|
26 |
|
27 |
|
28 |
eta = True
|
29 |
all = False
|
30 |
pre = False
|
31 |
inv = False
|
32 |
f2d = True
|
33 |
relIso = False
|
34 |
|
35 |
add = "Dijets"
|
36 |
if all:
|
37 |
add = "All"
|
38 |
pass
|
39 |
if pre:
|
40 |
add = "BaseLine"
|
41 |
pass
|
42 |
if inv:
|
43 |
add ="InvertMHT"
|
44 |
pass
|
45 |
|
46 |
add2 = "1D"
|
47 |
if f2d:
|
48 |
add2 = "2D"
|
49 |
pass
|
50 |
|
51 |
add3 = "Pt"
|
52 |
if eta:
|
53 |
add3 = "eta"
|
54 |
pass
|
55 |
if relIso:
|
56 |
add3 = "relIso"
|
57 |
pass
|
58 |
|
59 |
|
60 |
mcColor = ROOT.kRed - 9
|
61 |
errColor = ROOT.kRed + 2
|
62 |
|
63 |
logY = True
|
64 |
|
65 |
removeSamples = []
|
66 |
removeSamples.append( "TTbar" )
|
67 |
removeSamples.append( "GVJets" )
|
68 |
removeSamples.append( "WWJets" )
|
69 |
removeSamples.append( "Zinv" )
|
70 |
removeSamples.append( "ZJets" )
|
71 |
removeSamples.append( "WJets" )
|
72 |
removeSamples.append( "QCDFlat" )
|
73 |
#removeSamples.append( "Data" )
|
74 |
|
75 |
addSamples = []
|
76 |
#addSamples.append( "LM13" )
|
77 |
#addSamples.append( "LM3" )
|
78 |
#addSamples.append( "LM8" )
|
79 |
|
80 |
|
81 |
## samples = []
|
82 |
## samples.append( "TTbar" )
|
83 |
## samples.append( "GVJets" )
|
84 |
## samples.append( "VVJets" )
|
85 |
## samples.append( "Zinv" )
|
86 |
## samples.append( "ZJets" )
|
87 |
## samples.append( "WJets" )
|
88 |
## samples.append( "QCDFlat" )
|
89 |
## samples.append( "Data" )
|
90 |
## s = ""
|
91 |
## for sample in samples:
|
92 |
## if not sample in removeSamples:
|
93 |
## s += sample
|
94 |
## pass
|
95 |
## pass
|
96 |
saveName = "plots/FakeTauEst_DataClosure_" + s + "_" + add + "_" + add3 + "_" + add2 + fileName + "_" + Type
|
97 |
|
98 |
rebinDict = {}
|
99 |
rebinDict[ "MHTMHT" ] = 4
|
100 |
rebinDict[ "MHT" ] = 4
|
101 |
rebinDict[ "MHTUnweighted" ] = 4
|
102 |
rebinDict[ "HTHT" ] = 4
|
103 |
rebinDict[ "HT" ] = 4
|
104 |
rebinDict[ "HTUnweighted" ] = 4
|
105 |
rebinDict[ "JetPtUnweighted" ] = 4
|
106 |
rebinDict[ "JetPt" ] = 4
|
107 |
rebinDict[ "TauSelectionTau1Pt" ] = 4
|
108 |
if Type == "Full":
|
109 |
rebinDict[ "JetPtUnweighted" ] = 8
|
110 |
rebinDict[ "JetPt" ] = 8
|
111 |
rebinDict[ "TauSelectionTau1Pt" ] = 8
|
112 |
pass
|
113 |
|
114 |
if Type == "PreCheck":
|
115 |
dirFakeTau = "finalPlotTauPreSelectionPS/"
|
116 |
dirPredTau = "QCDPredictionAnalyzer2DEtaMDP/"
|
117 |
pass
|
118 |
|
119 |
print dirPredTau
|
120 |
|
121 |
histDict = {}
|
122 |
readIn = Helper.ReadIn( fileDir, fileName, rebinDict=rebinDict )
|
123 |
readIn.removeSamples( removeSamples )
|
124 |
readIn.addSamples( addSamples )
|
125 |
readIn.addHists( [ "HT", "JetPt" ] )
|
126 |
#print readIn.histList
|
127 |
histDict = readIn.getHists( dirPredTau )
|
128 |
|
129 |
histDictPred = {}
|
130 |
predReadIn = Helper.ReadIn( fileDir, fileName, rebinDict=rebinDict )
|
131 |
predReadIn.removeSamples( removeSamples )
|
132 |
predReadIn.addSamples( addSamples )
|
133 |
predReadIn.removeHists( [ "MHT" ] )
|
134 |
predReadIn.addHists( [ "nPredEvents", "statErr" ] )
|
135 |
#predReadIn.dontScale()
|
136 |
histDictPred = predReadIn.getHists( dirPredTau )
|
137 |
|
138 |
|
139 |
|
140 |
histDictSel = {}
|
141 |
selReadIn = Helper.ReadIn( fileDir, fileName, rebinDict=rebinDict )
|
142 |
selReadIn.removeSamples( removeSamples )
|
143 |
selReadIn.addSamples( addSamples )
|
144 |
selReadIn.removeHists( [ "MHT" ] )
|
145 |
selReadIn.addHists( [ "MHTMHT", "HTHT", "TauSelectionTau1Pt" ] )
|
146 |
histDictSel = selReadIn.getHists( dirFakeTau )
|
147 |
|
148 |
histDictUnscaled = {}
|
149 |
readInUnscaled = Helper.ReadIn( fileDir, fileName, rebinDict=rebinDict )
|
150 |
readInUnscaled.removeHists( [ "MHT" ] )
|
151 |
readInUnscaled.removeSamples( removeSamples )
|
152 |
readInUnscaled.addSamples( addSamples )
|
153 |
readInUnscaled.addHists( [ "HTUnweighted", "MHTUnweighted", "JetPtUnweighted" ] )
|
154 |
readInUnscaled.dontScale()
|
155 |
#print readIn.histList
|
156 |
histDictUnscaled = readInUnscaled.getHists( dirPredTau )
|
157 |
|
158 |
#histDictMCScaled = {}
|
159 |
#readInMCScaled = Helper.ReadIn( fileDir, fileName, rebinDict=rebinDict )
|
160 |
#readInMCScaled.removeHists( [ "MHT" ] )
|
161 |
#readInMCScaled.removeSamples( removeSamples )
|
162 |
#readInMCScaled.addSamples( addSamples )
|
163 |
#readInMCScaled.addHists( [ "MHTMCWeights" ] )
|
164 |
##print readIn.histList
|
165 |
#histDictMCScaled = readInMCScaled.getHists( dirPredTau )
|
166 |
|
167 |
print
|
168 |
print "Number of events in control region at L=", readIn.lumi
|
169 |
tauControl = 0.
|
170 |
#print "########## currently nonsense"
|
171 |
#for sample in readIn.sampleList:
|
172 |
# tauControl = histDictMCScaled[ "MHTMCWeights" ][ sample ].Integral()
|
173 |
# print sample, " : ", round( tauControl, 2 ),\
|
174 |
# " +- ", round( math.sqrt( histDictUnscaled[ "MHTUnweighted" ][ sample ].Integral() ) *\
|
175 |
# tauControl/histDictUnscaled[ "MHTUnweighted" ][ sample ].Integral(),2 )
|
176 |
# pass
|
177 |
|
178 |
print
|
179 |
print "Number of events in control sample (Data)"
|
180 |
for sample in readIn.sampleList:
|
181 |
print sample, " : ", round( histDictUnscaled[ "MHTUnweighted" ][ sample ].Integral(),2 ), \
|
182 |
" +- ", round( math.sqrt( histDictUnscaled[ "MHTUnweighted" ][ sample ].Integral() ), 2 )
|
183 |
pass
|
184 |
|
185 |
print
|
186 |
print "Number of Data events selected"
|
187 |
print
|
188 |
for sample in readIn.sampleList:
|
189 |
print sample, " : ", histDictSel[ "MHTMHT" ][ sample ].GetEntries()
|
190 |
|
191 |
print
|
192 |
print "----- tau-selected events (no gen tau) ----"
|
193 |
tauSel = 0.
|
194 |
for sample in selReadIn.sampleList:
|
195 |
tauSel = histDictSel[ "MHTMHT" ][ sample ].Integral()
|
196 |
print sample , " n sel events = ", round( tauSel,2 )
|
197 |
pass
|
198 |
|
199 |
|
200 |
#avFakeRate = tauSel / ( tauSel + tauControl )
|
201 |
#print
|
202 |
#print "Average fake rate=", round( avFakeRate, 2 )
|
203 |
#scaleControl = 1/( 1-avFakeRate )
|
204 |
#print "(Not done) Scale control sample with 1/(1-f)=", round( scaleControl, 2 )
|
205 |
|
206 |
|
207 |
print
|
208 |
print "----- pred Events ------"
|
209 |
for sample in predReadIn.sampleList:
|
210 |
print sample , " n pred events = ", round( histDictPred[ "nPredEvents" ][ sample ].GetBinContent( 1 ) ,2 ) ,\
|
211 |
" +- ", round( histDictPred[ "statErr" ][ sample ].GetBinContent( 1 ) ,2 )
|
212 |
|
213 |
#print sample , " n pred events * 1/(1-f) = ", \
|
214 |
# round( scaleControl * histDictPred[ "nPredEvents" ][ sample ].GetBinContent( 1 ) ,2 ) ,\
|
215 |
# " +- ", round( histDictPred[ "statErr" ][ sample ].GetBinContent( 1 ) ,2 )
|
216 |
pass
|
217 |
|
218 |
|
219 |
|
220 |
if draw:
|
221 |
|
222 |
print "###### plots are not scaled with 1/(1-f) yet ########"
|
223 |
|
224 |
#### get the full stat error and the hist binned stat error
|
225 |
errsDict = {}
|
226 |
errsBinDict = {}
|
227 |
for hist in readIn.histList:
|
228 |
errs = Helper.StackErr( histDict[ hist ], histDictUnscaled[ hist + "Unweighted" ] )
|
229 |
errsDict[ hist ], errsBinDict[ hist ] = errs.getStackErr()
|
230 |
pass
|
231 |
|
232 |
#### get the sample stack of all selected fake tau events
|
233 |
for hist in selReadIn.histList:
|
234 |
addup = Helper.AddUp( histDictSel[ hist ] )
|
235 |
histDictSel[ hist ][ "All" ] = addup.add()
|
236 |
pass
|
237 |
|
238 |
#### get the sample stack of predicted fake tau distributions
|
239 |
allHist = {}
|
240 |
for hist in histDict.keys():
|
241 |
addup = Helper.AddUp( histDict[ hist ] )
|
242 |
allHist[ hist ] = addup.add()
|
243 |
pass
|
244 |
|
245 |
#### get the hists for the stat errors
|
246 |
errHistUpDict = {}
|
247 |
errHistDwnDict = {}
|
248 |
for hist in allHist.keys():
|
249 |
ErrHists = Helper.StatErrorHists( allHist[ hist ],errsBinDict[ hist ] ,colorUp=errColor, colorDwn = mcColor )
|
250 |
errHistUpDict[ hist ], errHistDwnDict[ hist ] = ErrHists.getErrHists( histname = hist )
|
251 |
pass
|
252 |
|
253 |
cDict = {}
|
254 |
legDict = {}
|
255 |
ratioDict = {}
|
256 |
|
257 |
|
258 |
cDict[ "MHT" ] = ROOT.TCanvas( "MHT" , "MHT" )
|
259 |
cDict[ "MHT" ].cd()
|
260 |
allHist[ "MHT" ].UseCurrentStyle()
|
261 |
histDictSel[ "MHTMHT" ][ "All" ].UseCurrentStyle()
|
262 |
Style.setHistStyle( allHist[ "MHT" ],
|
263 |
status="BG",
|
264 |
color=mcColor,
|
265 |
xTitle="MHT [GeV]", yTitle="events" )
|
266 |
Style.setHistStyle( histDictSel[ "MHTMHT" ][ "All" ],
|
267 |
status="Data",
|
268 |
color=1,
|
269 |
xTitle="MHT [GeV]", yTitle="events" )
|
270 |
allHist[ "MHT" ].Draw( "hist" )
|
271 |
errHistUpDict[ "MHT" ][ "All" ].Draw( "same" )
|
272 |
errHistDwnDict[ "MHT" ][ "All" ].Draw( "same" )
|
273 |
histDictSel[ "MHTMHT" ][ "All" ].Draw( "same" )
|
274 |
|
275 |
errHistUpDict[ "MHT" ][ "All" ].Draw( "axissame" )
|
276 |
|
277 |
if logY:
|
278 |
allHist[ "MHT" ].SetMinimum( 6 * 10**-4 )
|
279 |
histDictSel[ "MHTMHT" ][ "All" ].SetMinimum( 6 * 10**-4 )
|
280 |
allHist[ "MHT" ].SetMaximum( 10**3 )
|
281 |
histDictSel[ "MHTMHT" ][ "All" ].SetMaximum( 10**3 )
|
282 |
pass
|
283 |
|
284 |
if logY:
|
285 |
ROOT.gPad.SetLogy()
|
286 |
pass
|
287 |
|
288 |
|
289 |
legDict[ "MHT" ] = Style.makeLegendSimple( [ histDictSel[ "MHTMHT" ][ "All" ],
|
290 |
allHist[ "MHT" ],
|
291 |
errHistUpDict[ "MHT" ][ "All" ], ],
|
292 |
[ "sel evts (MC)", "predicted", "stat err" ],
|
293 |
statusDict={ "predicted" : "BG",
|
294 |
"sel evts (MC)" : "Data",
|
295 |
"stat err" : "BG"})
|
296 |
|
297 |
|
298 |
legDict[ "MHT" ].Draw( "same" )
|
299 |
|
300 |
ratioDict[ "MHT" ] = Helper.Ratio( histDictSel[ "MHTMHT" ][ "All" ],
|
301 |
allHist[ "MHT" ],
|
302 |
mcHistErrDict=errsBinDict[ "MHT" ][ "All" ], colorUp=errColor )
|
303 |
ratioDict[ "MHT" ].drawRatio( ROOT.gPad )
|
304 |
|
305 |
|
306 |
|
307 |
cDict[ "HT" ] = ROOT.TCanvas( "HT" , "HT" )
|
308 |
cDict[ "HT" ].cd()
|
309 |
allHist[ "HT" ].UseCurrentStyle()
|
310 |
histDictSel[ "HTHT" ][ "All" ].UseCurrentStyle()
|
311 |
Style.setHistStyle( allHist[ "HT" ],
|
312 |
status="BG",
|
313 |
color=mcColor,
|
314 |
xTitle="HT [GeV]", yTitle="events" )
|
315 |
Style.setHistStyle( histDictSel[ "HTHT" ][ "All" ],
|
316 |
status="Data",
|
317 |
color=1,
|
318 |
xTitle="HT [GeV]", yTitle="events" )
|
319 |
allHist[ "HT" ].Draw( "hist" )
|
320 |
errHistUpDict[ "HT" ][ "All" ].Draw( "same" )
|
321 |
errHistDwnDict[ "HT" ][ "All" ].Draw( "same" )
|
322 |
histDictSel[ "HTHT" ][ "All" ].Draw( "same" )
|
323 |
|
324 |
errHistUpDict[ "HT" ][ "All" ].Draw( "axissame" )
|
325 |
|
326 |
if logY:
|
327 |
allHist[ "HT" ].SetMinimum( 6 * 10**-4 )
|
328 |
histDictSel[ "HTHT" ][ "All" ].SetMinimum( 6 * 10**-4 )
|
329 |
allHist[ "HT" ].SetMaximum( 10**3 )
|
330 |
histDictSel[ "HTHT" ][ "All" ].SetMaximum( 10**3 )
|
331 |
pass
|
332 |
|
333 |
if logY:
|
334 |
ROOT.gPad.SetLogy()
|
335 |
pass
|
336 |
|
337 |
|
338 |
legDict[ "HT" ] = Style.makeLegendSimple( [ histDictSel[ "HTHT" ][ "All" ],
|
339 |
allHist[ "HT" ],
|
340 |
errHistUpDict[ "HT" ][ "All" ], ],
|
341 |
[ "sel evts (MC)", "predicted", "stat err" ],
|
342 |
statusDict={ "predicted" : "BG",
|
343 |
"sel evts (MC)" : "Data",
|
344 |
"stat err" : "BG"})
|
345 |
|
346 |
|
347 |
legDict[ "HT" ].Draw( "same" )
|
348 |
|
349 |
ratioDict[ "HT" ] = Helper.Ratio( histDictSel[ "HTHT" ][ "All" ],
|
350 |
allHist[ "HT" ],
|
351 |
mcHistErrDict=errsBinDict[ "HT" ][ "All" ], colorUp=errColor )
|
352 |
ratioDict[ "HT" ].drawRatio( ROOT.gPad )
|
353 |
|
354 |
|
355 |
|
356 |
cDict[ "Tau1Pt" ] = ROOT.TCanvas( "Tau1Pt" , "Tau1Pt" )
|
357 |
cDict[ "Tau1Pt" ].cd()
|
358 |
allHist[ "JetPt" ].UseCurrentStyle()
|
359 |
histDictSel[ "TauSelectionTau1Pt" ][ "All" ].UseCurrentStyle()
|
360 |
Style.setHistStyle( allHist[ "JetPt" ],
|
361 |
status="BG",
|
362 |
color=mcColor,
|
363 |
xTitle="Tau1 P_{T} [GeV]", yTitle="events" )
|
364 |
Style.setHistStyle( histDictSel[ "TauSelectionTau1Pt" ][ "All" ],
|
365 |
status="Data",
|
366 |
color=1,
|
367 |
xTitle="Tau1 P_{T} [GeV]", yTitle="events" )
|
368 |
allHist[ "JetPt" ].Draw( "hist" )
|
369 |
errHistUpDict[ "JetPt" ][ "All" ].Draw( "same" )
|
370 |
errHistDwnDict[ "JetPt" ][ "All" ].Draw( "same" )
|
371 |
histDictSel[ "TauSelectionTau1Pt" ][ "All" ].Draw( "same" )
|
372 |
|
373 |
errHistUpDict[ "JetPt" ][ "All" ].Draw( "axissame" )
|
374 |
|
375 |
if logY:
|
376 |
allHist[ "JetPt" ].SetMinimum( 6 * 10**-4 )
|
377 |
histDictSel[ "TauSelectionTau1Pt" ][ "All" ].SetMinimum( 6 * 10**-4 )
|
378 |
allHist[ "JetPt" ].SetMaximum( 10**3 )
|
379 |
histDictSel[ "TauSelectionTau1Pt" ][ "All" ].SetMaximum( 10**3 )
|
380 |
pass
|
381 |
|
382 |
if logY:
|
383 |
ROOT.gPad.SetLogy()
|
384 |
pass
|
385 |
|
386 |
|
387 |
legDict[ "Tau1Pt" ] = Style.makeLegendSimple( [ histDictSel[ "TauSelectionTau1Pt" ][ "All" ],
|
388 |
allHist[ "JetPt" ],
|
389 |
errHistUpDict[ "JetPt" ][ "All" ], ],
|
390 |
[ "sel evts (MC)", "predicted", "stat err" ],
|
391 |
statusDict={ "predicted" : "BG",
|
392 |
"sel evts (MC)" : "Data",
|
393 |
"stat err" : "BG"})
|
394 |
|
395 |
|
396 |
legDict[ "Tau1Pt" ].Draw( "same" )
|
397 |
|
398 |
ratioDict[ "Tau1Pt" ] = Helper.Ratio( histDictSel[ "TauSelectionTau1Pt" ][ "All" ],
|
399 |
allHist[ "JetPt" ],
|
400 |
mcHistErrDict=errsBinDict[ "JetPt" ][ "All" ], colorUp=errColor )
|
401 |
ratioDict[ "Tau1Pt" ].drawRatio( ROOT.gPad )
|
402 |
|
403 |
|
404 |
if saveToPS:
|
405 |
Style.saveToPS( saveName, cDict )
|
406 |
pass
|
407 |
if saveToEPS:
|
408 |
Style.saveToEPS( saveName, cDict )
|
409 |
pass
|
410 |
pass
|
411 |
|
412 |
Def.DontQuit()
|