ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/nowaf/RootFilesInUse/MakeGraphPlots.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

# Content
1 import ROOT
2 import sys, re
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 FakeHelper as FH
7 from array import array
8
9 if __name__ == "__main__":
10
11 doDynamicRebin = True
12 dynamicRebin = 10
13
14 sampleList = []
15 #sampleList.append( "ZJets" )
16 #sampleList.append( "WJets" )
17 sampleList.append( "TTbar" )
18 #sampleList.append( "QCDFlat" )
19 #sampleList.append( "Data" )
20
21
22 fileDict = {}
23 #fileDict[ "WJets" ] = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/RealTauEst/WJets_cxviii.root"
24 fileDict[ "WJets" ] = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/WJets_full_ii/WJets_full_ii.root"
25 fileDict[ "QCDFlat" ] = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/RealTauEst/QCDFlat_full.root"
26 fileDict[ "TTbar" ] = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/TTbar_full_ii/TTbar_full_ii.root"
27 fileDict[ "Data" ] = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/Data_fakes_iii/Data_fakes_iii.root"
28 fileDict[ "WJets2" ] = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/RealTauEst/WJets_cxviii.root"
29 fileDict[ "TTbar2" ] = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/RealTauEst/TTbar_cxviii.root"
30
31 rebin = 2
32
33 xtitle = "P_{T}^{#tau} [GeV]"
34 ytitle = "#epsilon_{#tau}^{reco}"
35 #title = "t#bar{t} simulation, HT>350 GeV"
36 title = "W+Jets simulation, HT>350 GeV"
37 #title = "t#bar{t} simulation"
38 #xtitle = "P_{T}^{jet} [GeV]"
39 #ytitle = "fake rate"
40 #title = "QCDFlat simulation"
41
42 colorDict = {}
43 colorDict[ "FakeRateHT0/" ] = ROOT.kBlack
44 colorDict[ "FakeRateHT50/" ] = ROOT.kRed + 2
45 colorDict[ "FakeRateHT100/" ] = ROOT.kRed -7
46 colorDict[ "FakeRateHT150/" ] = ROOT.kMagenta + 3
47 colorDict[ "FakeRateHT200/" ] = ROOT.kViolet -8
48 colorDict[ "FakeRateHT250/" ] = ROOT.kViolet + 7
49 colorDict[ "FakeRateHT300/" ] = ROOT.kBlue - 4
50 colorDict[ "FakeRateHT350/" ] = ROOT.kAzure + 5
51 colorDict[ "EffRateHT350MHT0/" ] = ROOT.kCyan + 4
52 colorDict[ "EffRateHT350MHT50/" ] = ROOT.kCyan + 2
53 colorDict[ "EffRateHT350MHT100/" ] = ROOT.kGreen -6
54 colorDict[ "EffRateHT350MHT150/" ] = ROOT.kSpring + 4
55 colorDict[ "EffRate350HT400/" ] = ROOT.kYellow - 2
56 colorDict[ "EffRate400HT/" ] = ROOT.kYellow + 4
57 colorDict[ "EffRate350HT600/" ] = ROOT.kBlue - 6
58 colorDict[ "EffRate600HT/" ] = ROOT.kBlue + 4
59 colorDict[ "EffRatePreRed/" ] = ROOT.kBlack
60 colorDict[ "EffRateHT0/" ] = ROOT.kBlack
61 colorDict[ "EffRateHT50/" ] = ROOT.kRed + 2
62 colorDict[ "EffRateHT100/" ] = ROOT.kRed-7
63 colorDict[ "EffRateHT150/" ] = ROOT.kMagenta - 2
64 colorDict[ "EffRateHT200/" ] = ROOT.kViolet - 7
65 colorDict[ "EffRateHT250/" ] = ROOT.kViolet + 7
66 colorDict[ "EffRateHT300/" ] = ROOT.kBlue + 3
67 colorDict[ "EffRateHT350/" ] = ROOT.kBlue - 7
68
69
70 plotTitle = False
71 if not title == None:
72 plotTitle = True
73 pass
74 Def.SetGlobalStyles( withTitle=plotTitle )
75
76 dirs = []
77 #dirs.append( "FakeRateHT0/")
78 ##dirs.append( "FakeRateHT50/")
79 #dirs.append( "FakeRateHT100/")
80 ##dirs.append( "FakeRateHT150/")
81 ##dirs.append( "FakeRateHT200/")
82 #dirs.append( "FakeRateHT250/")
83 ##dirs.append( "FakeRateHT300/")
84 #dirs.append( "FakeRateHT350/")
85 ##
86 dirs.append( "EffRateHT50/")
87 dirs.append( "EffRateHT150/")
88 dirs.append( "EffRateHT250/")
89 dirs.append( "EffRateHT350/")
90 #dirs.append( "EffRateHT350MHT0/")
91 #dirs.append( "EffRateHT350MHT50/")
92 #dirs.append( "EffRateHT350MHT100/")
93 #dirs.append( "EffRateHT350MHT150/")
94 ##
95 #dirs.append( "EffRate350HT400/")
96 #dirs.append( "EffRate400HT/")
97 ##
98 #dirs.append( "EffRate350HT600/")
99 #dirs.append( "EffRate600HT/")
100
101 dirs2 = []
102 dirs2.append( "EffRatePreRed/")
103
104 initialHistDict = {}
105 initialHistDict[ "TauPt" ] = "GenPt"
106 #initialHistDict[ "MuonPtPromptNotFromTau" ] = "MuonPtPrompt"
107 #initialHistDict[ "JetTauPtJPT" ] = "JetPtJPT"
108
109 legendDict = {}
110 legendDict[ "FakeRateHT0/" ] = "No Selection"
111 legendDict[ "FakeRateHT50/" ] = "HT>50 GeV"
112 legendDict[ "FakeRateHT100/" ] = "HT>100 GeV"
113 legendDict[ "FakeRateHT150/" ] = "HT>150 GeV"
114 legendDict[ "FakeRateHT200/" ] = "HT>200 GeV"
115 legendDict[ "FakeRateHT250/" ] = "HT>250 GeV"
116 legendDict[ "FakeRateHT300/" ] = "HT>300 GeV"
117 legendDict[ "FakeRateHT350/" ] = "HT>350 GeV"
118 legendDict[ "EffRateHT350MHT0/" ] = "MHT>0 GeV"
119 legendDict[ "EffRateHT350MHT50/" ] = "MHT>50 GeV"
120 legendDict[ "EffRateHT350MHT100/" ] = "MHT>100 GeV"
121 legendDict[ "EffRateHT350MHT150/" ] = "MHT>150 GeV"
122 legendDict[ "EffRate350HT400/" ] = "350<HT<400 GeV"
123 legendDict[ "EffRate400HT/" ] = "HT>400 GeV"
124 legendDict[ "EffRate350HT600/" ] = "350<HT<600 GeV"
125 legendDict[ "EffRate600HT/" ] = "HT>600 GeV"
126 legendDict[ "EffRatePreRed/" ] = "Base-Line reduced"
127 legendDict[ "EffRateHT50/" ] = "HT>50 GeV"
128 legendDict[ "EffRateHT150/" ] = "HT>150 GeV"
129 legendDict[ "EffRateHT250/" ] = "HT>250 GeV"
130 legendDict[ "EffRateHT350/" ] = "HT>350 GeV"
131
132 ###########################################################################################
133 histDict = {}
134 graph = {}
135 for hist in initialHistDict:
136 #print "----- ", hist
137 histDict[ hist ] = {}
138 histDict[ initialHistDict[ hist ] ] = {}
139 graph[ hist ] = {}
140 for file in sampleList:
141 #print "-----", file
142 rootfile = ROOT.TFile.Open( fileDict[ file ] )
143 histDict[ hist ][ file ] = {}
144 histDict[ initialHistDict[ hist ] ][ file ] = {}
145 graph[ hist ][ file ] = {}
146 for dir in dirs:
147 #print "------", dir
148 histDict[ hist ][ file ][ dir ] = rootfile.Get( dir + hist )
149 histDict[ hist ][ file ][ dir ].SetDirectory( 0 )
150 histDict[ hist ][ file ][ dir ].UseCurrentStyle()
151 histDict[ hist ][ file ][ dir ].Rebin( rebin )
152
153 histDict[ initialHistDict[ hist ] ][ file ][ dir ] = rootfile.Get( dir + initialHistDict[ hist ] )
154 histDict[ initialHistDict[ hist ] ][ file ][ dir ].SetDirectory( 0 )
155 histDict[ initialHistDict[ hist ] ][ file ][ dir ].UseCurrentStyle()
156 histDict[ initialHistDict[ hist ] ][ file ][ dir ].Rebin( rebin )
157
158 if doDynamicRebin:
159 lowerBinsHist = FH.getLowerBins( histDict[ hist ][ file ][ dir ], nEntries=dynamicRebin )
160 lowerBinsHist2 = FH.getLowerBins( histDict[ initialHistDict[ hist ] ][ file ][ dir ],
161 nEntries=dynamicRebin )
162
163 rebinList = FH.mergeList( [ lowerBinsHist, lowerBinsHist2 ] )
164 obj = array( 'd' )
165 for b in rebinList:
166 obj.append( b )
167 pass
168 histDict[ hist ][ file ][ dir ] = \
169 histDict[ hist ][ file ][ dir ].Rebin( len( rebinList ) -1 , hist , obj )
170 histDict[ initialHistDict[ hist ] ][ file ][ dir ] = \
171 histDict[ initialHistDict[ hist ] ][ file ][ dir ].Rebin( len( rebinList ) -1 , hist , obj )
172 graph[ hist ][ file ][ dir ] = ROOT.TGraphAsymmErrors()
173 pass
174 graph[ hist ][ file ][ dir ].BayesDivide( histDict[ hist ][ file ][ dir ],
175 histDict[ initialHistDict[ hist ] ][ file ][ dir ] )
176 graph[ hist ][ file ][ dir ].UseCurrentStyle()
177 Style.setHistStyle( graph[ hist ][ file ][ dir ],
178 status="Err",
179 color=colorDict[ dir ],
180 xTitle=xtitle,
181 yTitle=ytitle,
182 title=title
183 )
184 pass
185 rootfile2 = ROOT.TFile.Open( fileDict[ file + "2" ] )
186 for dir2 in dirs2:
187 #print "-----", dir2
188 histDict[ hist ][ file ][ dir2 ] = rootfile2.Get( dir2 + hist )
189 histDict[ hist ][ file ][ dir2 ].SetDirectory( 0 )
190 histDict[ hist ][ file ][ dir2 ].UseCurrentStyle()
191 histDict[ hist ][ file ][ dir2 ].Rebin( rebin )
192
193 histDict[ initialHistDict[ hist ] ][ file ][ dir2 ] = rootfile2.Get( dir2 + initialHistDict[ hist ] )
194 histDict[ initialHistDict[ hist ] ][ file ][ dir2 ].SetDirectory( 0 )
195 histDict[ initialHistDict[ hist ] ][ file ][ dir2 ].UseCurrentStyle()
196 histDict[ initialHistDict[ hist ] ][ file ][ dir2 ].Rebin( rebin )
197
198 if doDynamicRebin:
199 lowerBinsHist = FH.getLowerBins( histDict[ hist ][ file ][ dir2 ], nEntries=dynamicRebin )
200 lowerBinsHist2 = FH.getLowerBins( histDict[ initialHistDict[ hist ] ][ file ][ dir2 ],
201 nEntries=dynamicRebin )
202
203 rebinList = FH.mergeList( [ lowerBinsHist, lowerBinsHist2 ] )
204 obj = array( 'd' )
205 for b in rebinList:
206 obj.append( b )
207 pass
208 histDict[ hist ][ file ][ dir2 ] = \
209 histDict[ hist ][ file ][ dir2 ].Rebin( len( rebinList ) -1 , hist , obj )
210 histDict[ initialHistDict[ hist ] ][ file ][ dir2 ] = \
211 histDict[ initialHistDict[ hist ] ][ file ][ dir2 ].Rebin( len( rebinList ) -1 , hist , obj )
212 graph[ hist ][ file ][ dir2 ] = ROOT.TGraphAsymmErrors()
213 pass
214 graph[ hist ][ file ][ dir2 ].BayesDivide( histDict[ hist ][ file ][ dir2 ],
215 histDict[ initialHistDict[ hist ] ][ file ][ dir2 ] )
216 graph[ hist ][ file ][ dir2 ].UseCurrentStyle()
217 Style.setHistStyle( graph[ hist ][ file ][ dir2 ],
218 status="Err",
219 color=colorDict[ dir2 ],
220 xTitle=xtitle,
221 yTitle=ytitle,
222 title=title
223 )
224 pass
225 pass
226 pass
227
228 ##################################################################################################################
229 ### draw
230
231 cDict = {}
232 legDict = {}
233 dirsjoined = dirs[:]
234 print dirsjoined
235 for d in dirs2:
236 dirsjoined.append( d )
237 pass
238 for file in sampleList:
239 cDict[ file ] = {}
240 legDict[ file ] = {}
241 for hist in initialHistDict.keys():
242 cDict[ file ][ hist ] = ROOT.TCanvas( file + hist , file + hist )
243 cDict[ file ][ hist ].cd()
244 glist = []
245 llist = []
246 same = "A"
247 for dir in dirsjoined:
248 graph[ hist ][ file ][ dir ].Draw( "P" + same )
249 same = "same"
250 glist.append( graph[ hist ][ file ][ dir ] )
251 llist.append( legendDict[ dir ] )
252 pass
253 legDict[ file ][ hist ] = Style.makeLegendSimple( glist,
254 llist,
255 #statusDict=statusDict,
256 style="ep",
257 position="umr" )
258 legDict[ file ][ hist ].Draw( "same" )
259 pass
260 Def.DontQuit()
261