ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/nowaf/RootFilesInUse/MakeDataPlots.py
Revision: 1.1.1.1 (vendor branch)
Committed: Tue Mar 20 13:12:08 2012 UTC (13 years, 1 month ago) by nowak
Content type: text/x-python
Branch: rootFilesInUse, MAIN
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
Log Message:
t files in use

File Contents

# User Rev Content
1 nowak 1.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 RT
7     from copy import deepcopy
8    
9     if __name__ == "__main__":
10    
11    
12     fileDir = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/RealTauEst/"
13    
14     #fileName = "_xciv"
15     fileName = "_clxix"
16    
17     ### v4
18     #lumi = 927.9
19     #lumi = 4.7
20     lumi = 5.0
21    
22     theTheTitle = "L = " + str( round( lumi,1 ) ) + " fb^{-1}, #sqrt{s} = 7 TeV"
23     #theTheTitle = "CMS Preliminary, L = " + str( round( lumi,1 ) ) + " fb^{-1}, #sqrt{s} = 7 TeV"
24    
25     draw = False
26     saveToEPS = False
27     saveToPS = False
28     logY = True
29     displaySignal = False ## not working currently
30    
31     plotRatio = True
32     displayNEvents = False
33     plotTitle = True
34     doSystScaling = False
35     statErrsOnly = False
36     displayControlPlots = False
37    
38     Def.SetGlobalStyles( withTitle=plotTitle )
39     ROOT.gStyle.SetHatchesSpacing( 1 )
40    
41     #Type = "Pre"
42     Type = "Full"
43     #Type = "PreCheck"
44    
45     roundTo = 0
46     if Type == "Full":
47     roundTo = 1
48     pass
49    
50     #fakeColor = ROOT.kRed - 9
51     realColor = ROOT.kGreen - 9
52     fakeColor = ROOT.kCyan + 2
53     #errColor = ROOT.kRed + 2
54    
55     removeSamples = []
56     removeSamples.append( "TTbar" )
57     removeSamples.append( "GVJets" )
58     removeSamples.append( "WWJets" )
59     removeSamples.append( "Zinv" )
60     removeSamples.append( "ZJets" )
61     removeSamples.append( "WJets" )
62     removeSamples.append( "QCDFlat" )
63     #removeSamples.append( "Data" )
64    
65     saveName = "plots/Data/final/Data_" + Type + fileName + "_pixelLumi"
66     if re.search( "Preliminary", theTheTitle ):
67     saveName = saveName + "_CMSPrelim"
68     pass
69    
70     theSystDictMT = {}
71     theSystDictFT = {}
72     scaleRealTau = 1.
73     scaleFakeTau = 1.
74     if doSystScaling:
75     scaleRealTau = 1./1.07 ### 9% overprediction due to non-W background
76     if Type == "Full":
77     scaleRealTau = 1./1.19### 9% overprediction due to non-W background
78     pass
79     scaleFakeTau = 1.15 ### sel/pred = 1.15
80     pass
81     if not statErrsOnly:
82     if doSystScaling:
83     theSystDictFT[ "Closure" ] = {}
84     theSystDictFT[ "Closure" ][ "Up" ] = 0.15 ### method uncertainty
85     theSystDictFT[ "Closure" ][ "Dwn" ] =0.15 ###
86     pass
87     theSystDictFT[ "Znunu" ] = {}
88     theSystDictFT[ "Znunu" ][ "Up" ] = 0.05 ### Z->nunu presence
89     theSystDictFT[ "Znunu" ][ "Dwn" ] =0.05
90     theSystDictFT[ "leptonFakesFT" ] = {}
91     theSystDictFT[ "leptonFakesFT" ][ "Up" ] = 0.01 ### tau fakes by light leptons
92     theSystDictFT[ "leptonFakesFT" ][ "Dwn" ] =0.01
93     theSystDictFT[ "FakesClosure" ] = {}
94     theSystDictFT[ "FakesClosure" ][ "Up" ] = 0.28
95     theSystDictFT[ "FakesClosure" ][ "Dwn" ] = 0.28
96     if Type == "Pre":
97     theSystDictFT[ "FakesStat" ] = {}
98     theSystDictFT[ "FakesStat" ][ "Up" ] = 0.02
99     theSystDictFT[ "FakesStat" ][ "Dwn" ] = 0.02
100     elif Type == "Full":
101     theSystDictFT[ "FakesStat" ] = {}
102     theSystDictFT[ "FakesStat" ][ "Up" ] = 0.02
103     theSystDictFT[ "FakesStat" ][ "Dwn" ] = 0.02
104     pass
105     pass
106     if not statErrsOnly:
107     theSystDictMT[ "tauRecoEffPAS" ] = {}
108     theSystDictMT[ "tauRecoEffPAS" ][ "Up" ] = 0.07
109     theSystDictMT[ "tauRecoEffPAS" ][ "Dwn" ] = 0.07
110     theSystDictMT[ "muIso" ] = {}
111     theSystDictMT[ "muIso" ][ "Up" ] = 0.002
112     theSystDictMT[ "muIso" ][ "Dwn" ] = 0.002
113     theSystDictMT[ "leptonFakesMT" ] = {}
114     theSystDictMT[ "leptonFakesMT" ][ "Up" ] = 0.01 ### tau fakes by light leptons
115     theSystDictMT[ "leptonFakesMT" ][ "Dwn" ] =0.01
116     if Type == "Pre":
117     theSystDictMT[ "tauRecoEffStat" ] = {}
118     theSystDictMT[ "tauRecoEffStat" ][ "Up" ] = 0.02
119     theSystDictMT[ "tauRecoEffStat" ][ "Dwn" ] = 0.02
120     theSystDictMT[ "probNotFromTau" ] = {}
121     theSystDictMT[ "probNotFromTau" ][ "Up" ] = 0.01
122     theSystDictMT[ "probNotFromTau" ][ "Dwn" ] = 0.01
123     theSystDictMT[ "TriggerMuonSmear" ] = {}
124     theSystDictMT[ "TriggerMuonSmear" ][ "Up" ] = 0.01
125     theSystDictMT[ "TriggerMuonSmear" ][ "Dwn" ] = 0.01
126     #theSystDictMT[ "non-W" ] = {}
127     #theSystDictMT[ "non-W" ][ "Up" ] = 0.07 ### 9% overprediction due to non-W background
128     #theSystDictMT[ "non-W" ][ "Dwn" ] = 0.07 ### 9% overprediction due to non-W background
129     elif Type == "Full":
130     theSystDictMT[ "tauRecoEffStat" ] = {}
131     theSystDictMT[ "tauRecoEffStat" ][ "Up" ] = 0.03
132     theSystDictMT[ "tauRecoEffStat" ][ "Dwn" ] = 0.03
133     theSystDictMT[ "probNotFromTau" ] = {}
134     theSystDictMT[ "probNotFromTau" ][ "Up" ] = 0.01
135     theSystDictMT[ "probNotFromTau" ][ "Dwn" ] = 0.01
136     #theSystDictMT[ "non-W" ] = {}
137     #theSystDictMT[ "non-W" ][ "Up" ] = 0.19 ### 9% overprediction due to non-W background
138     #theSystDictMT[ "non-W" ][ "Dwn" ] = 0.19 ### 9% overprediction due to non-W background
139     theSystDictMT[ "TTbar" ] = {}
140     theSystDictMT[ "TTbar" ][ "Up" ] = 0.04
141     theSystDictMT[ "TTbar" ][ "Dwn" ] = 0.04
142     pass
143     pass
144    
145    
146    
147    
148     rebinDict = {}
149     rebinDict[ "MHTMHT" ] = 4
150     rebinDict[ "MHT" ] = 4
151     rebinDict[ "MHTUnweighted" ] = 4
152     rebinDict[ "MHTUnscaled" ] = 4
153     rebinDict[ "MHTMHTEta" ] = 4
154     rebinDict[ "MHTEta" ] = 4
155     rebinDict[ "MHTUnweightedEta" ] = 4
156     rebinDict[ "MHTUnscaledEta" ] = 4
157     rebinDict[ "MHTMHTPhi" ] = 4
158     rebinDict[ "MHTPhi" ] = 4
159     rebinDict[ "MHTUnweightedPhi" ] = 4
160     rebinDict[ "MHTUnscaledPhi" ] = 4
161     rebinDict[ "HTHT" ] = 4
162     rebinDict[ "HT" ] = 4
163     rebinDict[ "HTUnweighted" ] = 4
164     rebinDict[ "HTUnscaled" ] = 4
165     rebinDict[ "JetPtUnweighted" ] = 4
166     rebinDict[ "JetPt" ] = 4
167     rebinDict[ "Tau1Pt" ] = 4
168     rebinDict[ "Tau1PtUnscaled" ] = 4
169     rebinDict[ "TauSelectionTau1Pt" ] = 4
170     rebinDict[ "JetEtaUnweighted" ] = 4
171     rebinDict[ "JetEta" ] = 4
172     rebinDict[ "Tau1Eta" ] = 4
173     rebinDict[ "Tau1EtaUnscaled" ] = 4
174     rebinDict[ "TauSelectionTau1Eta" ] = 4
175     rebinDict[ "JetPhiUnweighted" ] = 4
176     rebinDict[ "JetPhi" ] = 4
177     rebinDict[ "Tau1Phi" ] = 4
178     rebinDict[ "Tau1PhiUnscaled" ] = 4
179     rebinDict[ "TauSelectionTau1Phi" ] = 4
180     rebinDict[ "Jet1Pt" ] = 2
181     rebinDict[ "Jet1PtUnweighted" ] = 2
182     rebinDict[ "Jet1PtUnscaled" ] = 2
183     rebinDict[ "JetSelection30Jet1Pt" ] = 2
184     rebinDict[ "Jet1Eta" ] = 4
185     rebinDict[ "Jet1EtaUnweighted" ] = 4
186     rebinDict[ "Jet1EtaUnscaled" ] = 4
187     rebinDict[ "JetSelection30Jet1Eta" ] = 4
188     rebinDict[ "Jet1Phi" ] = 4
189     rebinDict[ "Jet1PhiUnweighted" ] = 4
190     rebinDict[ "Jet1PhiUnscaled" ] = 4
191     rebinDict[ "JetSelection30Jet1Phi" ] = 4
192     rebinDict[ "Jet2Pt" ] = 2
193     rebinDict[ "Jet2PtUnweighted" ] = 2
194     rebinDict[ "Jet2PtUnscaled" ] = 2
195     rebinDict[ "JetSelection30Jet2Pt" ] = 2
196     rebinDict[ "Jet2Eta" ] = 4
197     rebinDict[ "Jet2EtaUnweighted" ] = 4
198     rebinDict[ "Jet2EtaUnscaled" ] = 4
199     rebinDict[ "JetSelection30Jet2Eta" ] = 4
200     rebinDict[ "Jet2Phi" ] = 4
201     rebinDict[ "Jet2PhiUnweighted" ] = 4
202     rebinDict[ "Jet2PhiUnscaled" ] = 4
203     rebinDict[ "JetSelection30Jet2Phi" ] = 4
204     rebinDict[ "Jet3Pt" ] = 2
205     rebinDict[ "Jet3PtUnweighted" ] = 2
206     rebinDict[ "Jet3PtUnscaled" ] = 2
207     rebinDict[ "JetSelection30Jet3Pt" ] = 2
208     rebinDict[ "Jet3Eta" ] = 4
209     rebinDict[ "Jet3EtaUnweighted" ] = 4
210     rebinDict[ "Jet3EtaUnscaled" ] = 4
211     rebinDict[ "JetSelection30Jet3Eta" ] = 4
212     rebinDict[ "Jet3Phi" ] = 4
213     rebinDict[ "Jet3PhiUnweighted" ] = 4
214     rebinDict[ "Jet3PhiUnscaled" ] = 4
215     rebinDict[ "JetSelection30Jet3Phi" ] = 4
216     rebinDict[ "TauSelectiondPhiMHTTau" ] = 4
217     rebinDict[ "DPhiMHTTauUnweighted" ] = 4
218     rebinDict[ "DPhiMHTTau" ] = 4
219     rebinDict[ "DPhiMHTTauUnscaled" ] = 4
220     rebinDict[ "MHTdPhiMinmhtDphi" ] = 4
221     rebinDict[ "MinDPhiMHTJUnweighted" ] = 4
222     rebinDict[ "MinDPhiMHTJ" ] = 4
223     rebinDict[ "MinDPhiMHTJUnscaled" ] = 4
224     rebinDict[ "DPhi12Unweighted" ] = 4
225     rebinDict[ "MHTdPhiMindPhi12" ] = 4
226     rebinDict[ "DPhi12" ] = 4
227     rebinDict[ "DPhi12Unscaled" ] = 4
228     rebinDict[ "MHTdPhiMindPhi13" ] = 6
229     rebinDict[ "DPhi13Unweighted" ] = 6
230     rebinDict[ "DPhi13" ] = 6
231     rebinDict[ "DPhi13Unscaled" ] = 6
232     rebinDict[ "MHTdPhiMindPhi23" ] = 4
233     rebinDict[ "DPhi23Unweighted" ] = 4
234     rebinDict[ "DPhi23" ] = 4
235     rebinDict[ "DPhi23Unscaled" ] = 4
236     if Type == "Full":
237     rebinDict[ "JetPtUnweighted" ] = 1
238     rebinDict[ "JetPt" ] = 1
239     rebinDict[ "Tau1Pt" ] = 1
240     rebinDict[ "Tau1PtUnscaled" ] = 1
241     rebinDict[ "TauSelectionTau1Pt" ] = 1
242     pass
243    
244     dirTau = "finalPlotTauPreSelectionControl/"
245     dirPredFakeTau = "QCDPredictionAnalyzerInvertPre2D/"
246     dirPredRealTau = "MuonTemplateAnalyzerPre/"
247     if Type == "Full":
248     dirTau = "finalPlotTauControl/"
249     dirPredFakeTau = "QCDPredictionAnalyzerInvert2D/"
250     dirPredRealTau = "MuonTemplateAnalyzer/"
251     pass
252     if Type == "PreCheck":
253     dirTau = "finalPlotTauPreSelectionPS/"
254     dirPredFakeTau = "QCDPredictionAnalyzer2DEtaMDP/"
255     dirPredRealTau = "MuonTemplateAnalyzerPreMDP/"
256    
257     yRangeDict = {}
258     yRangeDict[ "MHT" ] = ( 6*10**-2, 10**3 )
259     yRangeDict[ "HT" ] = ( 6*10**-2, 10**3 )
260     yRangeDict[ "Tau1Pt" ] = ( 6*10**-2, 10**3 )
261     yRangeDict[ "Tau1Eta" ] = ( 6*10**-2, 5 * 10**4 )
262     yRangeDict[ "Jet1Pt" ] = ( 6*10**-2, 10**3 )
263     yRangeDict[ "Jet1Eta" ] = ( 6*10**-2, 5 * 10**4 )
264     yRangeDict[ "Jet2Pt" ] = ( 6*10**-2, 10**3 )
265     yRangeDict[ "Jet2Eta" ] = ( 6*10**-2, 5 * 10**4 )
266     yRangeDict[ "Jet3Pt" ] = ( 6*10**-2, 10**3 )
267     yRangeDict[ "Jet3Eta" ] = ( 6*10**-2, 5 * 10**4 )
268     yRangeDict[ "NumberOfJets" ] = ( 6*10**-2, 10**3 )
269     yRangeDict[ "DPhiMHTTau" ] = ( 6*10**-2, 10**3 )
270     yRangeDict[ "MinDPhiMHTJ" ] = ( 6*10**-2, 10**4 )
271     yRangeDict[ "DPhi12" ] = ( 6*10**-2, 10**4 )
272     yRangeDict[ "DPhi13" ] = ( 6*10**-2, 10**4 )
273     yRangeDict[ "DPhi23" ] = ( 6*10**-2, 10**4 )
274     if Type == "Full":
275     yRangeDict[ "MHT" ] = ( 6*10**-2, 10**2 )
276     yRangeDict[ "HT" ] = ( 6*10**-2, 5*10**2 )
277     yRangeDict[ "Tau1Pt" ] = ( 6*10**-2, 10**2 )
278     pass
279    
280     xRangeDict = {}
281     xRangeDict[ "MHT" ] = ( 250,1000 )
282     xRangeDict[ "HT" ] = ( 350,2000 )
283     xRangeDict[ "Tau1Pt" ] = ( 0,1000 )
284     xRangeDict[ "Jet1Pt" ] = ( 0,1600 )
285     xRangeDict[ "Jet2Pt" ] = ( 0,1600 )
286     xRangeDict[ "Jet3Pt" ] = ( 0,1600 )
287     if Type == "Full":
288     xRangeDict[ "MHT" ] = ( 400,1000 )
289     xRangeDict[ "HT" ] = ( 600,2000 )
290     xRangeDict[ "Tau1Pt" ] = ( 0,1000 )
291     pass
292    
293     posDict = {}
294     posDict[ "DPhi12" ] = "ul"
295     posDict[ "DPhi13" ] = "ul"
296     posDict[ "DPhi23" ] = "ul"
297    
298     addSamples = []
299     addSamples.append( "LM13" )
300     addSamples.append( "LM3" )
301     addSamples.append( "LM8" )
302     fileNameSusy = "_liv"
303     if displaySignal:
304     yRangeDict[ "MHT" ] = ( 6*10**-2, 5*10**2 )
305     yRangeDict[ "HT" ] = ( 6*10**-2, 10**4 )
306     yRangeDict[ "Tau1Pt" ] = ( 6*10**-2, 7*10**2 )
307     if Type == "Full":
308     yRangeDict[ "MHT" ] = ( 6*10**-2, 10**3 )
309     yRangeDict[ "HT" ] = ( 6*10**-2, 5*10**2 )
310     yRangeDict[ "Tau1Pt" ] = ( 6*10**-2, 10**2 )
311     pass
312     pass
313    
314     ############################################################
315    
316     ### the selection.
317     selReadIn = RT.ReadIn( fileDir, fileName, rebinDict=rebinDict )
318     selReadIn.removeSamples( removeSamples )
319     selReadIn.removeHists( [ "MHT" ] )
320     selReadIn.addHists( [ "MHTMHT", "HTHT", "TauSelectionTau1Pt" ] )
321     if displayControlPlots:
322     selReadIn.addHists( [ "MHTMHTEta", "MHTMHTPhi",
323     "TauSelectionTau1Eta", "TauSelectionTau1Phi",
324     "JetSelection30Jet1Pt", "JetSelection30Jet1Eta", "JetSelection30Jet1Phi",
325     "JetSelection30Jet2Pt", "JetSelection30Jet2Eta", "JetSelection30Jet2Phi",
326     "JetSelection30Jet3Pt", "JetSelection30Jet3Eta", "JetSelection30Jet3Phi",
327     "JetSelection30NumberOfJets", "TauSelectiondPhiMHTTau", "MHTdPhiMinmhtDphi",
328     "MHTdPhiMindPhi12","MHTdPhiMindPhi13", "MHTdPhiMindPhi23" ] )
329     pass
330     histDictSel = selReadIn.getHists( dirTau )
331    
332     ### these are the predicted events for fake taus.
333     ### binned in MHT, HT, JetPt
334     readIn = RT.ReadIn( fileDir, fileName, rebinDict=rebinDict, externalScalingFactor=scaleFakeTau )
335     #readIn.dontScale()
336     readIn.removeSamples( removeSamples )
337     readIn.addHists( [ "HT", "JetPt" ] )
338     if displayControlPlots:
339     readIn.addHists( [ "MHTEta", "MHTPhi",
340     "JetEta", "JetPhi",
341     "Jet1Pt", "Jet1Eta", "Jet1Phi",
342     "Jet2Pt", "Jet2Eta", "Jet2Phi",
343     "Jet3Pt", "Jet3Eta", "Jet3Phi",
344     "nJets", "DPhiMHTTau",
345     "MinDPhiMHTJ","DPhi12",
346     "DPhi13", "DPhi23" ] )
347     pass
348     #print readIn.histList
349     histDictFakeTau = readIn.getHists( dirPredFakeTau )
350    
351     ### unscaled hists for fake prediction
352     ### needed for stat err
353     readInUnscaled = RT.ReadIn( fileDir, fileName, rebinDict=rebinDict )
354     readInUnscaled.removeHists( [ "MHT" ] )
355     readInUnscaled.removeSamples( removeSamples )
356     readInUnscaled.addHists( [ "HTUnweighted", "MHTUnweighted", "JetPtUnweighted" ] )
357     if displayControlPlots:
358     readInUnscaled.addHists( [ "MHTEtaUnweighted", "MHTPhiUnweighted",
359     "JetEtaUnweighted", "JetPhiUnweighted",
360     "Jet1PtUnweighted", "Jet1EtaUnweighted", "Jet1PhiUnweighted",
361     "Jet2PtUnweighted", "Jet2EtaUnweighted", "Jet2PhiUnweighted",
362     "Jet3PtUnweighted", "Jet3EtaUnweighted", "Jet3PhiUnweighted",
363     "nJetsUnweighted", "DPhiMHTTauUnweighted",
364     "MinDPhiMHTJUnweighted","DPhi12Unweighted",
365     "DPhi13Unweighted", "DPhi23Unweighted" ] )
366     pass
367     readInUnscaled.dontScale()
368     #print readIn.histList
369     histDictFakeTauUnscaled = readInUnscaled.getHists( dirPredFakeTau )
370    
371     ### predicted events for real taus
372     ### binned in MHT, HT, TauPt
373     muonTausReadIn = RT.ReadIn( fileDir,
374     fileName,
375     rebinDict=rebinDict,
376     externalScalingFactor=scaleRealTau
377     )
378     muonTausReadIn.changeScalingFactor( "Data", 1 - 0.352 ) ### hadronic branching fraction
379     muonTausReadIn.removeSamples( removeSamples )
380     muonTausReadIn.removeHists( [ "MHT" ] )
381     muonTausReadIn.addHists( [ "MHT" ] )
382     muonTausReadIn.addHists( [ "HT" ] )
383     muonTausReadIn.addHists( [ "Tau1Pt" ] )
384     if displayControlPlots:
385     muonTausReadIn.addHists( [ "MHTEta", "MHTPhi",
386     "Tau1Eta", "Tau1Phi",
387     "Jet1Pt", "Jet1Eta", "Jet1Phi",
388     "Jet2Pt", "Jet2Eta", "Jet2Phi",
389     "Jet3Pt", "Jet3Eta", "Jet3Phi",
390     "NumberOfJets",
391     "DPhiMHTTau", "MinDPhiMHTJ",
392     "DPhi12", "DPhi13", "DPhi23" ] )
393     pass
394     histDictRealTau = muonTausReadIn.getHists( dirPredRealTau )
395    
396     ### unscaled hists for real tau pred
397     ### needed for stat err
398     muonTausReadInUnscaled = RT.ReadIn( fileDir, fileName, rebinDict=rebinDict )
399     muonTausReadInUnscaled.removeSamples( removeSamples )
400     muonTausReadInUnscaled.removeHists( [ "MHT" ] )
401     muonTausReadInUnscaled.addHists( [ "MHTUnscaled" ] )
402     muonTausReadInUnscaled.addHists( [ "HTUnscaled" ] )
403     muonTausReadInUnscaled.addHists( [ "Tau1PtUnscaled" ] )
404     if displayControlPlots:
405     muonTausReadInUnscaled.addHists( [ "MHTEtaUnscaled", "MHTPhiUnscaled",
406     "Tau1EtaUnscaled", "Tau1PhiUnscaled",
407     "Jet1PtUnscaled", "Jet1EtaUnscaled", "Jet1PhiUnscaled",
408     "Jet2PtUnscaled", "Jet2EtaUnscaled", "Jet2PhiUnscaled",
409     "Jet3PtUnscaled", "Jet3EtaUnscaled", "Jet3PhiUnscaled",
410     "NumberOfJetsUnscaled",
411     "DPhiMHTTauUnscaled", "MinDPhiMHTJUnscaled",
412     "DPhi12Unscaled", "DPhi13Unscaled", "DPhi23Unscaled" ] )
413     pass
414     #muonTausReadInUnscaled.dontScale()
415     histDictRealTauUnscaled = muonTausReadInUnscaled.getHists( dirPredRealTau )
416    
417     ################### get syst from stat errs on weights #################################
418     realTausSystReadIn = RT.ReadIn( fileDir, fileName, rebinDict={} )
419     realTausSystReadIn.changeScalingFactor( "Data", 1 - 0.352 )
420     realTausSystReadIn.removeSamples( removeSamples )
421     #realTausSystReadIn.addSamples( addSample )
422     realTausSystReadIn.removeHists( [ "MHT" ] )
423     realTausSystReadIn.addHists( [ "IsoErr" ] )
424     realTausSystReadIn.addHists( [ "RecoErr" ] )
425     realTausSystReadIn.addHists( [ "EffErrUp" ] )
426     realTausSystReadIn.addHists( [ "EffErrDwn" ] )
427     realTausSystReadIn.addHists( [ "NoTauErrUp" ] )
428     realTausSystReadIn.addHists( [ "NoTauErrDwn" ] )
429     histDictMTSyst = realTausSystReadIn.getHists( dirPredRealTau )
430     SFH = RT.SystFromHist( dict=histDictMTSyst )
431     sDict = SFH.getSystDict()
432    
433     fakeTausSystReadIn = RT.ReadIn( fileDir, fileName, rebinDict={} )
434     fakeTausSystReadIn.removeSamples( removeSamples )
435     fakeTausSystReadIn.removeHists( [ "MHT" ] )
436     fakeTausSystReadIn.addHists( [ "StatErrUp" ] )
437     fakeTausSystReadIn.addHists( [ "StatErrDwn" ] )
438     histDictFTSyst = fakeTausSystReadIn.getHists( dirPredFakeTau )
439     SFHfakes = RT.SystFromHist( dict=histDictFTSyst )
440     sDictfakes = SFHfakes.getSystDict()
441    
442     print
443     print "--------- syst --------"
444     for syst in sDict.keys():
445     print syst, " abs=", round( math.sqrt( sDict[ syst ] ),4 ), \
446     " rel=", round( math.sqrt( sDict[ syst ] )/ histDictRealTau[ "MHT" ][ "Data" ].Integral(),4 )
447     pass
448     for syst in sDictfakes.keys():
449     print syst, " abs=", round( math.sqrt( sDictfakes[ syst ] ),4 ), \
450     " rel=", round( math.sqrt( sDictfakes[ syst ] )/ histDictFakeTau[ "MHT" ][ "Data" ].Integral(),4 )
451     pass
452    
453     ########################################################################################
454    
455     ################### get the stat errs for estimate #####################################
456     errsMTDict = {}
457     errsMTDictBin= {}
458     for hist in muonTausReadInUnscaled.histList:
459     nameScaled = "".join( hist.split( "Unscaled" ) )
460     errsMT = RT.StackErr( histDictRealTau[ nameScaled ], histDictRealTauUnscaled[ hist ] )
461     errsMTDict[ nameScaled ], errsMTDictBin[ nameScaled ] = errsMT.getStackErr()
462     pass
463    
464     errsFTDict = {}
465     errsFTDictBin= {}
466     for hist in readInUnscaled.histList:
467     nameScaled = "".join( hist.split( "Unweighted" ) )
468     errsFT = RT.StackErr( histDictFakeTau[ nameScaled ], histDictFakeTauUnscaled[ hist ] )
469     errsFTDict[ nameScaled ], errsFTDictBin[ nameScaled ] = errsFT.getStackErr()
470     pass
471    
472     errsDict = {}
473     errsDictBin= {}
474     for name in errsMTDictBin.keys():
475     nameFT = name
476     if name == "Tau1Pt":
477     nameFT = "JetPt"
478     elif name == "Tau1Eta":
479     nameFT = "JetEta"
480     elif name == "Tau1Phi":
481     nameFT = "JetPhi"
482     elif name == "NumberOfJets":
483     nameFT = "nJets"
484     pass
485     errsDict[ name ] = {}
486     errsDict[ name ][ "All" ] = math.sqrt( errsMTDict[ name ][ "All" ]**2 +\
487     errsFTDict[ nameFT ][ "All" ]**2 )
488     errsDictBin[ name ] = {}
489     errsDictBin[ name ][ "All" ] = {}
490     for bin in errsMTDictBin[ name ][ "All" ].keys():
491     #### squared!
492     errsDictBin[ name ][ "All" ][ bin ] = errsMTDictBin[ name ][ "All" ][ bin ] + \
493     errsFTDictBin[ nameFT ][ "All" ][ bin ]
494     pass
495     pass
496     ########################################################################################
497    
498     ################### get the syst ers ###################################################
499     errsMTSystDict = {}
500     errsMTSystDictBin = {}
501     if not statErrsOnly:
502     for hist in muonTausReadIn.histList:
503     errsMTSystDict[ hist ] = {}
504     errsMTSyst = RT.SystErr( histDictRealTau[ hist ][ "Data" ], theSystDict=theSystDictMT )
505     #errsSystDict[ hist ], errsSystDictBin[ hist ] = errsSyst.getSystErr()
506     tuple = errsMTSyst.getSystErr()
507     errsMTSystDict[ hist ][ "Up" ] = tuple[ 0 ][ 0 ]
508     errsMTSystDict[ hist ][ "Dwn" ] = tuple[ 0 ][ 1 ]
509     errsMTSystDictBin[ hist ] = tuple[ 1 ]
510     pass
511     pass
512    
513     errsFTSystDict = {}
514     errsFTSystDictBin = {}
515     if not statErrsOnly:
516     for hist in readIn.histList:
517     errsFTSystDict[ hist ] = {}
518     errsFTSyst = RT.SystErr( histDictFakeTau[ hist ][ "Data" ], theSystDict=theSystDictFT )
519     #errsSystDict[ hist ], errsSystDictBin[ hist ] = errsSyst.getSystErr()
520     tuple = errsFTSyst.getSystErr()
521     errsFTSystDict[ hist ][ "Up" ] = tuple[ 0 ][ 0 ]
522     errsFTSystDict[ hist ][ "Dwn" ] = tuple[ 0 ][ 1 ]
523     errsFTSystDictBin[ hist ] = tuple[ 1 ]
524     pass
525     pass
526    
527    
528     ################### get the combined ers ###################################################
529     errsCombinedDictBin = {}
530     errsCombinedDictBin[ "Up" ] = deepcopy( errsDictBin ) ### makes a true copy, *not* an alias
531     errsCombinedDictBin[ "Dwn" ] = deepcopy( errsDictBin ) ### makes a true copy, *not* an alias
532     if not statErrsOnly:
533     errsCombinedDictBin = {}
534     errsCombinedDictBin[ "Up" ] = {}
535     errsCombinedDictBin[ "Dwn" ] = {}
536     for hist in histDictRealTau.keys():
537     histFT = hist
538     if hist == "Tau1Pt":
539     histFT = "JetPt"
540     elif hist == "Tau1Eta":
541     histFT = "JetEta"
542     elif hist == "Tau1Phi":
543     histFT = "JetPhi"
544     elif hist == "NumberOfJets":
545     histFT = "nJets"
546     pass
547     errsCombinedDictBin[ "Up" ][ hist ] = {}
548     errsCombinedDictBin[ "Dwn" ][ hist ] = {}
549     errsCombinedDictBin[ "Up" ][ hist ][ "All" ] = {}
550     errsCombinedDictBin[ "Dwn" ][ hist ][ "All" ] = {}
551     for bin in errsDictBin[ hist ][ "All" ].keys():
552     ### all errDicts already squared
553     errsCombinedDictBin[ "Up" ][ hist ][ "All" ][ bin ] = errsDictBin[ hist ][ "All" ][ bin ] + \
554     errsFTSystDictBin[ histFT ][ bin ][ "Up" ] + \
555     errsMTSystDictBin[ hist ][ bin ][ "Up" ]
556     errsCombinedDictBin[ "Dwn" ][ hist ][ "All" ][ bin ] = errsDictBin[ hist ][ "All" ][ bin ] + \
557     errsFTSystDictBin[ histFT ][ bin ][ "Dwn" ] + \
558     errsMTSystDictBin[ hist ][ bin ][ "Dwn" ]
559     pass
560     pass
561     pass
562    
563     #print "UP: ", errsCombinedDictBin[ "Up" ][ "MHT" ][ "All" ]
564     #print "Dwn: ", errsCombinedDictBin[ "Dwn" ][ "MHT" ][ "All" ]
565    
566     ########################################################################################
567    
568     #### signal selection.
569     #if displaySignal:
570     # signalReadIn = RT.ReadIn( fileDir, fileNameSusy, rebinDict=rebinDict, lumi=lumi )
571     # signalReadIn.removeSamples( removeSamples )
572     # signalReadIn.removeSamples( [ "Data" ] )
573     # signalReadIn.addSamples( addSamples )
574     # signalReadIn.removeHists( [ "MHT" ] )
575     # signalReadIn.addHists( [ "MHTMHT", "HTHT", "TauSelectionTau1Pt" ] )
576     # histDictSignal = signalReadIn.getHists( dirTau )
577    
578     #######################################################################
579    
580     #### the selected events
581     print "############################################################################"
582     nSel = histDictSel[ "MHTMHT" ][ "Data" ].Integral()
583     #nFake = histDictFakeTau[ "MHT" ][ "Data" ].Integral()
584     #nReal = histDictRealTau[ "MHT" ][ "Data" ].Integral()
585    
586     #ftFactor = histDictFakeTau[ "MHT" ][ "Data" ].Integral()/\
587     # histDictFakeTauUnscaled[ "MHTUnweighted" ][ "Data" ].Integral()
588     fterr = ROOT.Double( 0 )
589     nFake = histDictFakeTau[ "MHT" ][ "Data" ].IntegralAndError( 0,histDictFakeTau[ "MHT" ][ "Data" ].GetNbinsX() + 1,
590     fterr )
591     print "Fake-tau est =", round( nFake,2 ), " +- ", round( fterr,2 ), " (stat)",\
592     " + ", round( math.sqrt( errsFTSystDict[ "MHT" ][ "Up" ] ),2 ),\
593     " - ", round( math.sqrt( errsFTSystDict[ "MHT" ][ "Dwn" ] ),2 ), " (syst)"
594     #rtFactor = histDictRealTau[ "MHT" ][ "Data" ].Integral()/\
595     # histDictRealTauUnscaled[ "MHTUnscaled" ][ "Data" ].Integral()
596     rterr = ROOT.Double( 0 )
597     nReal = histDictRealTau[ "MHT" ][ "Data" ].IntegralAndError( 0, histDictRealTau[ "MHT" ][ "Data" ].GetNbinsX()+ 1,
598     rterr )
599     print "Real-tau est =", round( nReal,2 ) , " +- ", round( rterr,2 ), " (stat)",\
600     " + ", round( math.sqrt( errsMTSystDict[ "MHT" ][ "Up" ] ),2 ),\
601     " - ", round( math.sqrt( errsMTSystDict[ "MHT" ][ "Dwn" ] ),2 ), " (syst)"
602    
603     print "--------------------------------------------------------------------------"
604     print "Sum =", round( nFake + nReal,2 ), " +- ", round( math.sqrt( fterr**2 + rterr**2 ) ,2 ), " (stat)",\
605     " + ", round( math.sqrt( errsMTSystDict[ "MHT" ][ "Up" ] + errsFTSystDict[ "MHT" ][ "Up" ] ),2 ),\
606     " - ", round( math.sqrt( errsMTSystDict[ "MHT" ][ "Dwn" ] + errsFTSystDict[ "MHT" ][ "Dwn" ] ),2 ), " (syst)"
607     print "--------------------------------------------------------------------------"
608     print "--------------------------------------------------------------------------"
609    
610     print "Selected events=", histDictSel[ "MHTMHT" ][ "Data" ].Integral(),\
611     " +- ", round( math.sqrt( histDictSel[ "MHTMHT" ][ "Data" ].Integral() ),2 )
612     print "--------------------------------------------------------------------------"
613     print "--------------------------------------------------------------------------"
614     print
615     print "------------------ control regions ---------------------------------------"
616     print "Fake-tau contr =", histDictFakeTauUnscaled[ "MHTUnweighted" ][ "Data" ].Integral(), " +- ",\
617     round( math.sqrt( histDictFakeTauUnscaled[ "MHTUnweighted" ][ "Data" ].Integral() ), 2 )
618     print "Real-tau contr =",histDictRealTauUnscaled[ "MHTUnscaled" ][ "Data" ].Integral(), " +- ",\
619     round( math.sqrt( histDictRealTauUnscaled[ "MHTUnscaled" ][ "Data" ].Integral() ),2 )
620     print "###########################################################################"
621    
622     TF = Def.MakeTexFile( fileName="tex/newCommandsData" + Type )
623     TF.addCommand( name="Data" + Type + "Lumi",
624     value=lumi,
625     roundTo=1 )
626     TF.addCommand( name="Data" + Type + "RTPred",
627     value=nReal,
628     roundTo=roundTo )
629     TF.addCommand( name="Data" + Type + "RTPredStatUncert",
630     value=rterr,
631     roundTo=roundTo )
632     if not statErrsOnly:
633     TF.addCommand( name="Data" + Type + "RTPredSystUncertUp",
634     value=math.sqrt( errsMTSystDict[ "MHT" ][ "Up" ] ),
635     roundTo=roundTo )
636     TF.addCommand( name="Data" + Type + "RTPredSystUncertDwn",
637     value=math.sqrt( errsMTSystDict[ "MHT" ][ "Dwn" ] ),
638     roundTo=roundTo )
639     pass
640    
641     TF.addCommand( name="Data" + Type + "RTPredVEvts",
642     value=histDictRealTauUnscaled[ "MHTUnscaled" ][ "Data" ].Integral(),
643     roundTo=0 )
644     TF.addCommand( name="Data" + Type + "RTPredVEvtsStatUncert",
645     value=math.sqrt( histDictRealTauUnscaled[ "MHTUnscaled" ][ "Data" ].Integral() ),
646     roundTo=0 )
647     TF.addCommand( name="Data" + Type + "FTPred",
648     value=nFake,
649     roundTo=roundTo )
650     TF.addCommand( name="Data" + Type + "FTPredStatUncert",
651     value=fterr,
652     roundTo=roundTo )
653     if not statErrsOnly:
654     TF.addCommand( name="Data" + Type + "FTPredSystUncertUp",
655     value=math.sqrt( errsFTSystDict[ "MHT" ][ "Up" ] ),
656     roundTo=roundTo )
657     TF.addCommand( name="Data" + Type + "FTPredSystUncertDwn",
658     value=math.sqrt( errsFTSystDict[ "MHT" ][ "Dwn" ] ),
659     roundTo=roundTo )
660     pass
661     TF.addCommand( name="Data" + Type + "FTPredVEvts",
662     value=histDictFakeTauUnscaled[ "MHTUnweighted" ][ "Data" ].Integral(),
663     roundTo=0 )
664     TF.addCommand( name="Data" + Type + "FTPredVEvtsStatUncert",
665     value=math.sqrt( histDictFakeTauUnscaled[ "MHTUnweighted" ][ "Data" ].Integral() ),
666     roundTo=0 )
667     TF.addCommand( name="Data" + Type + "SumPred",
668     value=nReal + nFake,
669     roundTo=roundTo )
670     TF.addCommand( name="Data" + Type + "SumPredStatUncert",
671     value=math.sqrt( fterr**2 + rterr**2 ),
672     roundTo=roundTo )
673     TF.addCommand( name="Data" + Type + "SumPredSystUncertUp",
674     value=math.sqrt( errsMTSystDict[ "MHT" ][ "Up" ] +\
675     errsFTSystDict[ "MHT" ][ "Up" ] ),
676     roundTo=roundTo )
677     TF.addCommand( name="Data" + Type + "SumPredSystUncertDwn",
678     value=math.sqrt( errsMTSystDict[ "MHT" ][ "Dwn" ] +\
679     errsFTSystDict[ "MHT" ][ "Dwn" ] ), ## + errsSystDictFakes[ "MHT" ]**2
680     roundTo=roundTo )
681     TF.addCommand( name="Data" + Type + "Sel",
682     value=histDictSel[ "MHTMHT" ][ "Data" ].Integral(),
683     roundTo=0 )
684     TF.addCommand( name="Data" + Type + "SelStatUncert",
685     value=math.sqrt( histDictSel[ "MHTMHT" ][ "Data" ].Integral() ),
686     roundTo=0 )
687    
688    
689     TF.writeTexFile()
690    
691    
692    
693     #######################################################################
694    
695     if draw:
696    
697     ratioDict = {}
698     cDict = {}
699     legDict = {}
700     stackDict = {}
701    
702     theTitle = ""
703     if plotTitle:
704     theTitle = theTheTitle
705     pass
706    
707    
708     pos = "umr"
709     #if Type == "Full":
710     # pos = "ul"
711     # pass
712    
713    
714     ##### prepare the legends
715     lList = [ "Data",
716     "Real Tau Est.",
717     "Fake Tau Est." ]
718     sDict = { "Real Tau Est." : "BG",
719     "Data" : "Data",
720     "Fake Tau Est." : "BG"}
721    
722     if displayNEvents:
723     lList = [ "Data (" + str( int( nSel ) ) + ")",
724     "Real Tau Est (" + str( round( nReal,1 ) ) + ")",
725     "Fake Tau Est (" + str( round( nFake,1 ) ) + ")" ]
726     sDict = { "Real Tau Est (" + str( round( nReal,1 ) ) + ")" : "BG",
727     "Data (" + str( int( nSel ) ) + ")" : "Data",
728     "Fake Tau Est (" + str( round( nFake,1 ) ) + ")" : "BG"}
729     pass
730    
731     nameMap = {}
732     nameMap[ "MHT" ] = "MHTMHT"
733     nameMap[ "MHTEta" ] = "MHTMHTEta"
734     nameMap[ "MHTPhi" ] = "MHTMHTPhi"
735     nameMap[ "HT" ] = "HTHT"
736     nameMap[ "Tau1Pt" ] = "TauSelectionTau1Pt"
737     nameMap[ "Tau1Eta" ] = "TauSelectionTau1Eta"
738     nameMap[ "Tau1Phi" ] = "TauSelectionTau1Phi"
739     nameMap[ "Jet1Pt" ] = "JetSelection30Jet1Pt"
740     nameMap[ "Jet1Eta" ] = "JetSelection30Jet1Eta"
741     nameMap[ "Jet1Phi" ] = "JetSelection30Jet1Phi"
742     nameMap[ "Jet2Pt" ] = "JetSelection30Jet2Pt"
743     nameMap[ "Jet2Eta" ] = "JetSelection30Jet2Eta"
744     nameMap[ "Jet2Phi" ] = "JetSelection30Jet2Phi"
745     nameMap[ "Jet3Pt" ] = "JetSelection30Jet3Pt"
746     nameMap[ "Jet3Eta" ] = "JetSelection30Jet3Eta"
747     nameMap[ "Jet3Phi" ] = "JetSelection30Jet3Phi"
748     nameMap[ "NumberOfJets" ] = "JetSelection30NumberOfJets"
749     nameMap[ "DPhiMHTTau" ] = "TauSelectiondPhiMHTTau"
750     nameMap[ "MinDPhiMHTJ" ] = "MHTdPhiMinmhtDphi"
751     nameMap[ "DPhi12" ] = "MHTdPhiMindPhi12"
752     nameMap[ "DPhi13" ] = "MHTdPhiMindPhi13"
753     nameMap[ "DPhi23" ] = "MHTdPhiMindPhi23"
754    
755     nameMapFakes = {}
756     nameMapFakes[ "MHT" ] = "MHT"
757     nameMapFakes[ "MHTEta" ] = "MHTEta"
758     nameMapFakes[ "MHTPhi" ] = "MHTPhi"
759     nameMapFakes[ "HT" ] = "HT"
760     nameMapFakes[ "Tau1Pt" ] = "JetPt"
761     nameMapFakes[ "Tau1Eta" ] = "JetEta"
762     nameMapFakes[ "Tau1Phi" ] = "JetPhi"
763     nameMapFakes[ "Jet1Pt" ] = "Jet1Pt"
764     nameMapFakes[ "Jet1Eta" ] = "Jet1Eta"
765     nameMapFakes[ "Jet1Phi" ] = "Jet1Phi"
766     nameMapFakes[ "Jet2Pt" ] = "Jet2Pt"
767     nameMapFakes[ "Jet2Eta" ] = "Jet2Eta"
768     nameMapFakes[ "Jet2Phi" ] = "Jet2Phi"
769     nameMapFakes[ "Jet3Pt" ] = "Jet3Pt"
770     nameMapFakes[ "Jet3Eta" ] = "Jet3Eta"
771     nameMapFakes[ "Jet3Phi" ] = "Jet3Phi"
772     nameMapFakes[ "NumberOfJets" ] = "nJets"
773     nameMapFakes[ "DPhiMHTTau" ] = "DPhiMHTTau"
774     nameMapFakes[ "MinDPhiMHTJ" ] = "MinDPhiMHTJ"
775     nameMapFakes[ "DPhi12" ] = "DPhi12"
776     nameMapFakes[ "DPhi13" ] = "DPhi13"
777     nameMapFakes[ "DPhi23" ] = "DPhi23"
778    
779     xtitleDict = {}
780     xtitleDict[ "MHT" ] = "#slash H_{T} [GeV]"
781     xtitleDict[ "MHTEta" ] = "#eta^{MHT}"
782     xtitleDict[ "MHTPhi" ] = "#phi^{MHT}"
783     xtitleDict[ "HT" ] = "H_{T} [GeV]"
784     xtitleDict[ "Tau1Pt" ] = "P_{T}^{#tau} [GeV]"
785     xtitleDict[ "Tau1Eta" ] = "#eta^{#tau}"
786     xtitleDict[ "Tau1Phi" ] = "#phi^{#tau}"
787     xtitleDict[ "Jet1Pt" ] = "P_{T}^{jet1} [GeV]"
788     xtitleDict[ "Jet1Eta" ] = "#eta^{jet1}"
789     xtitleDict[ "Jet1Phi" ] = "#phi^{jet1}"
790     xtitleDict[ "Jet2Pt" ] = "P_{T}^{jet2} [GeV]"
791     xtitleDict[ "Jet2Eta" ] = "#eta^{jet2}"
792     xtitleDict[ "Jet2Phi" ] = "#phi^{jet2}"
793     xtitleDict[ "Jet3Pt" ] = "P_{T}^{jet3} [GeV]"
794     xtitleDict[ "Jet3Eta" ] = "#eta^{jet3}"
795     xtitleDict[ "Jet3Phi" ] = "#phi^{jet3}"
796     xtitleDict[ "NumberOfJets" ] = "Number of jets"
797     xtitleDict[ "DPhiMHTTau" ] = "#Delta#Phi(MHT,#tau)"
798     xtitleDict[ "DPhi12" ] = "#Delta#Phi(jet1,jet2)"
799     xtitleDict[ "DPhi13" ] = "#Delta#Phi(jet1,jet3)"
800     xtitleDict[ "DPhi23" ] = "#Delta#Phi(jet2,jet3)"
801     xtitleDict[ "MinDPhiMHTJ" ] = "min #Delta#Phi(MHT,jet123)"
802    
803    
804     ##### make the err hists
805     #print "--------------Warning!!----ErrHist currently nonsense!"
806     #MEG = RT.MakeErrGraph( fakeDict=histDictFakeTau, fakeDictU=histDictFakeTauUnscaled,
807     # realDict=histDictRealTau, realDictU=histDictRealTauUnscaled,
808     # systDict= errsCombinedDictBin)
809     MEG = RT.MakeErrGraph( fakeDict=histDictFakeTau,
810     realDict=histDictRealTau,
811     errDict= errsCombinedDictBin
812     )
813     graphDict = MEG.getErrGraphs()
814    
815    
816     for hist in muonTausReadIn.histList:
817     #### get the x,y titles
818     ytitle = "Events"
819     if re.search( "GeV", xtitleDict[ hist ] ):
820     b = histDictSel[ nameMap[ hist ] ][ "Data" ].GetBinWidth( 1 )
821     ytitle = "Events/"+ str( int( b ) ) + " GeV"
822     pass
823     ### get new legend position if necessary
824     if hist in posDict.keys():
825     pos = posDict[ hist ]
826     pass
827     ### take your canvas bags ...
828     cDict[ hist ] = ROOT.TCanvas( hist , hist )
829     cDict[ hist ].cd()
830    
831     #### set Styles for selected Events
832     Style.setHistStyle( histDictSel[ nameMap[ hist ] ][ "Data" ],
833     status="Data",
834     color=1,
835     markerStyle=20,
836     xTitle=xtitleDict[ hist ],
837     yTitle=ytitle,
838     title=theTitle )
839     #### set style for fake tau est
840     Style.setHistStyle( histDictFakeTau[ nameMapFakes[ hist ] ][ "Data" ],
841     status="BG",
842     color=fakeColor,
843     xTitle=xtitleDict[ hist ],
844     yTitle=ytitle,
845     title=theTitle )
846     ### set style for real tau est
847     Style.setHistStyle( histDictRealTau[ hist ][ "Data" ],
848     status="BG",
849     color=realColor,
850     xTitle=xtitleDict[ hist ],
851     yTitle=ytitle,
852     title=theTitle )
853     #### set the style for Susy if necessary
854     #if displaySignal:
855     # Style.setHistStyle( histDictSignal[ nameMap[ hist ] ][ "LM13" ],
856     # status="Signal",
857     # color=ROOT.kAzure-4,
858     # xTitle=xTitleDict[ hist ],
859     # yTitle=ytitle,
860     # title=theTitle )
861    
862     ### i am legend
863     hlist = [ histDictSel[ nameMap[ hist ] ][ "Data" ],
864     histDictRealTau[ hist ][ "Data" ],
865     histDictFakeTau[ nameMapFakes[ hist ] ][ "Data" ] ]
866     legDict[ hist ] = Style.makeLegendSimple( hlist,
867     lList,
868     statusDict=sDict,
869     position = pos )
870    
871     ### style for uncertainties
872     Style.setHistStyle( graphDict[ hist ],
873     status="Err",
874     color=1,
875     fillStyle=3354,
876     xTitle=xtitleDict[ hist ],
877     yTitle=ytitle )
878    
879     ##### get the ratio plots
880     xmin = None
881     xmax = None
882     if hist in xRangeDict.keys():
883     xmin = xRangeDict[ hist ][ 0 ]
884     xmax = xRangeDict[ hist ][ 1 ]
885     pass
886     if plotRatio:
887     print "Warning! Asymm errors not implemented in ratio plot!"
888     #print MEG.errDict
889     ratioDict[ hist ] = RT.RatioData( dataHist=histDictSel[ nameMap[ hist ] ][ "Data" ],
890     fakeHist=histDictFakeTau[ nameMapFakes[ hist ] ][ "Data" ],
891     realHist=histDictRealTau[ hist ][ "Data" ],
892     colorErr=1,
893     mcHistErrDict=MEG.errDict[ "Up" ][ hist ][ "All" ],
894     xmin=xmin,
895     xmax=xmax,
896     title = "Data/Bkg" )
897     pass
898    
899     #### get the stacks
900     stackDict[ hist ] = histDictFakeTau[ nameMapFakes[ hist ] ][ "Data" ].Clone()
901     stackDict[ hist ].Add( histDictRealTau[ hist ][ "Data" ] )
902     stackDict[ hist ].UseCurrentStyle()
903     Style.setHistStyle( stackDict[ hist ],
904     status="BG",
905     color=realColor,
906     xTitle=xtitleDict[ hist ],
907     yTitle=ytitle,
908     title=theTitle )
909    
910     #### now draw.
911     if logY:
912     if( hist in yRangeDict.keys() ):
913     stackDict[ hist ].GetYaxis().SetRangeUser( yRangeDict[ hist ][ 0 ],
914     yRangeDict[ hist ][ 1 ] )
915     pass
916     pass
917     stackDict[ hist ].Draw( "hist" )
918     histDictFakeTau[ nameMapFakes[ hist ] ][ "Data" ].Draw( "samehist" )
919     if( hist in xRangeDict.keys() ):
920     stackDict[ hist ].GetXaxis().SetRangeUser( xRangeDict[ hist ][ 0 ],
921     xRangeDict[ hist ][ 1 ] )
922     pass
923     histDictSel[ nameMap[ hist ] ][ "Data" ].Draw( "same" )
924     graphDict[ hist ].Draw( "sameE2" )
925     stackDict[ hist ].Draw( "axissame" )
926     if logY:
927     ROOT.gPad.SetLogy()
928     pass
929     cDict[ hist ].Update()
930     legDict[ hist ].Draw( "same" )
931     if plotRatio:
932     ratioDict[ hist ].drawRatio( ROOT.gPad )
933     pass
934    
935     pass
936    
937    
938     if saveToPS:
939     Style.saveToPS( saveName, cDict )
940     pass
941     if saveToEPS:
942     Style.saveToEPS( saveName, cDict )
943     pass
944     pass
945    
946    
947     ####################### Kolmogorov test ###############################
948    
949     print "------------ KolmogorovTest ------------"
950     print "MHT: KS=", stackDict[ "MHT" ].KolmogorovTest( histDictSel[ "MHTMHT" ][ "Data" ] )
951    
952     ####################### TauPT test ###################################
953     print
954     print "------------ Tau Pt test ---------------"
955     inte = histDictRealTauUnscaled[ "Tau1PtUnscaled" ][ "Data" ].Integral()
956     bin100 = histDictRealTauUnscaled[ "Tau1PtUnscaled" ][ "Data" ].FindBin( 100. )
957     inte100 = histDictRealTauUnscaled[ "Tau1PtUnscaled" ][ "Data" ].Integral( bin100, histDictRealTauUnscaled[ "Tau1PtUnscaled" ][ "Data" ].GetNbinsX() + 1 )
958     print "Fraction of taus with pt>100 Gev = ", round( inte100/inte, 2 )
959     bin20 = histDictRealTauUnscaled[ "Tau1PtUnscaled" ][ "Data" ].FindBin( 20. )
960     inte20 = histDictRealTauUnscaled[ "Tau1PtUnscaled" ][ "Data" ].Integral( 0, bin20 )
961     print "Fraction of taus with pt<20 Gev = ", round( inte20/inte, 2 )
962    
963     Def.DontQuit()
964     pass
965    
966    
967    
968    
969    
970