ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/nowaf/RootFilesInUse/GetEventYield.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 MakeRealTauEst_cff as RT
7 import math
8
9 if __name__ == "__main__":
10
11 Def.SetGlobalStyles()
12
13 #lumi = 180.
14 #lumi = 4683.9
15 lumi = 4992.1
16 ### v4
17 #lumi = 927.9
18
19
20 makeTexFile = True
21
22 cut = None
23 #cut = 650.
24
25 removeSamples = []
26 #removeSamples.append( "TTbar" )
27 removeSamples.append( "GVJets" )
28 #removeSamples.append( "WWJets" )
29 #removeSamples.append( "Zinv" )
30 #removeSamples.append( "ZJets" )
31 #removeSamples.append( "WJets" )
32 #removeSamples.append( "QCDFlat" )
33 #removeSamples.append( "Data" )
34
35 addSample = []
36 #addSample.append( "WWJets" )
37 addSample.append( "LM13" )
38 addSample.append( "LM2" )
39 #addSample.append( "LM8" )
40
41 allSamples = []
42 allSamples = []
43 allSamples.append( "TTbar" )
44 #allSamples.append( "GVJets" )
45 allSamples.append( "WWJets" )
46 #allSamples.append( "Zinv" )
47 allSamples.append( "ZJets" )
48 allSamples.append( "WJets" )
49 #allSamples.append( "QCDFlat" )
50 #allSamples.append( "Data" )
51 #allSamples.append( "LM13" )
52 #allSamples.append( "LM2" )
53
54 nameMap = {}
55 nameMap[ "LM13" ] = "LMThirteen"
56 nameMap[ "LM2" ] = "LMTwo"
57
58
59 fileDir = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/RealTauEst/"
60 bDir = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionI/mSugraScanTan50_TaNC_cuts/"
61
62 #fileName = "_fakes_xxviii"
63 fileName = "_clxix"
64
65 ##add = "_xxxv"
66 ###add = "_tightID"
67
68
69 #dir = "finalPlotTauPreSelection/"
70 #dir = "finalPlotTau/"
71
72 dir = "finalPlotTauPreSelectionControl/"
73 #dir = "finalPlotTauControl/"
74
75 #dir = "finalPlotTauPreSelectionControlLepFakes/"
76
77 #dir = "finalPlotTauPreSelectionControl20MHT40/"
78 #dir = "finalPlotTauControl20MHT40/"
79
80 #dir = "finalPlotTauPreSelectionControl40MHT60/"
81 #dir = "finalPlotTauControl40MHT60/"
82
83 #dir = "finalPlotTauPreSelectionControl60MHT100/"
84 #dir = "finalPlotTauControl60MHT100/"
85
86 #dir = "finalPlotTauPreSelectionControl60MHT80/"
87 #dir = "finalPlotTauPreSelectionControl60MHT80HT500/"
88 #dir = "finalPlotTauControl60MHT80/"
89
90 #dir = "finalPlotTauPreSelectionControl80MHT100/"
91 #dir = "finalPlotTauPreSelectionControl80MHT100HT500/"
92 #dir = "finalPlotTauControl80MHT100/"
93
94 #dir = "finalPlotTauPreSelectionControl100MHT120/"
95 #dir = "finalPlotTauPreSelectionControl100MHT120HT500/"
96 #dir = "finalPlotTauControl100MHT120/"
97
98 #dir = "finalPlotTauPreSelectionControl120MHT140/"
99 #dir = "finalPlotTauPreSelectionControl120MHT140HT500/"
100 #dir = "finalPlotTauControl120MHT140/"
101
102 #dir = "finalPlotTauPreSelectionMatchedTauControl/"
103 #dir = "finalPlotTauMatchedTauControl/"
104
105 #dir = "finalPlotTauInvertMHTControl/"
106 #dir = "finalPlotTauGen/"
107
108 #dir = "finalPlotTauPreSelectionGenVetoTau/"
109 #dir = "finalPlotGenVetoTau/"
110
111 Type = "Full"
112 roundTo = 1
113 if re.search( "Pre", dir ):
114 Type = "BaseLine"
115 roundTo = 0
116 pass
117
118 histList = []
119 #histList.append( "MHTMHT" )
120 histList.append( "HTHT" )
121
122
123 statusDict = {}
124 statusDict[ "QCDFlat" ] = "BG"
125 statusDict[ "TTbar" ] = "BG"
126 statusDict[ "GVJets" ] = "BG"
127 statusDict[ "ZJets" ] = "BG"
128 statusDict[ "Zinv" ] = "BG"
129 statusDict[ "VVJets" ] = "BG"
130 statusDict[ "WWJets" ] = "BG"
131 statusDict[ "WJets" ] = "BG"
132 statusDict[ "Data" ] = "Data"
133 statusDict[ "LM13" ] = "Signal"
134 statusDict[ "LM7" ] = "Signal"
135 statusDict[ "LM8" ] = "Signal"
136 statusDict[ "GMSBc" ] = "Signal"
137 statusDict[ "LM3" ] = "Signal"
138 statusDict[ "LM9" ] = "Signal"
139 statusDict[ "LM12" ] = "Signal"
140 statusDict[ "330_340" ] = "Signal"
141 statusDict[ "330_390" ] = "Signal"
142 statusDict[ "LM2" ] = "Signal"
143
144
145 #helper = RT.ReadIn( fileDir, "TTbar" )
146 #scalingFactors = helper.scalingFactors
147
148
149 #histDict = {}
150 #for hist in histList:
151 # print "----- ", hist
152 # histDict[ hist ] = {}
153 # for file in sampleList:
154 # rootfile = ROOT.TFile.Open( fileDict[ file ] )
155 # #print file
156 # histDict[ hist ][ file ] = rootfile.Get( dir + hist )
157 # histDict[ hist ][ file ].SetDirectory( 0 )
158 # print file, " scalingFactor=", scalingFactors[ file ]
159 # if file in scalingFactors.keys():
160 # histDict[ hist ][ file ].Scale( scalingFactors[ file ] )
161 # pass
162 # rootfile.Close()
163 # pass
164 # pass
165
166
167 readIn = RT.ReadIn( fileDir, fileName, lumi=lumi )
168 readIn.removeSamples( removeSamples )
169 readIn.addSamples( addSample )
170 readIn.removeHists( [ "MHT" ] )
171 readIn.addHists( histList )
172 #readIn.dontScale()
173 histDict = readIn.getHists( dir )
174
175 readInUnscaled = RT.ReadIn( fileDir, fileName )
176 readInUnscaled.removeSamples( removeSamples )
177 readInUnscaled.addSamples( addSample )
178 readInUnscaled.removeHists( [ "MHT" ] )
179 readInUnscaled.addHists( histList )
180 readInUnscaled.dontScale()
181 histDictUnscaled = readInUnscaled.getHists( dir )
182
183 ################## tex file ############################################################
184
185 if makeTexFile:
186 TF = Def.MakeTexFile( fileName="tex/newCommandsSelection" + Type )
187 TF.addCommand( name="Sel" + Type + "Lumi",
188 value=lumi/1000.,
189 roundTo=1 )
190 pass
191
192 bg = 0.
193 bgerr = 0.
194 lowestBin = 0
195 if not cut == None:
196 lowestBin = histDict[ histList[ 0 ] ][ "QCDFlat" ].FindBin( cut )
197 pass
198 print "#################EventYields###############"
199 print " Lumi=", lumi
200 print "========", dir, "========="
201 for sample in readIn.sampleList:
202 if statusDict[ sample ] == "BG":
203 nbins = histDict[ histList[ 0 ] ][ sample ].GetNbinsX() + 1
204 err = ROOT.Double( 0 )
205 val = histDict[ histList[ 0 ] ][ sample ].IntegralAndError( lowestBin, nbins, err )
206 #bgerr += ( math.sqrt( histDictUnscaled[ histList[ 0 ] ][ sample ].Integral( lowestBin, nbins ) ) *\
207 # readIn.scalingFactors[ sample ] )**2
208 bgerr += err**2
209 bg += val
210 print sample, ": ", round( val, 2 ), " +- ",round( err, 2 )
211
212 if makeTexFile:
213 TF.addCommand( name="Sel" + Type + sample,
214 value=val,
215 roundTo=roundTo )
216 TF.addCommand( name="Sel" + Type + sample + "StatUncert",
217 value=err,
218 roundTo=roundTo )
219 pass
220
221 pass
222 pass
223
224 for s in allSamples:
225 if makeTexFile and not s in readIn.sampleList:
226 TF.addCommand( name="Sel" + Type + s,
227 value="-",
228 roundTo=None )
229 TF.addCommand( name="Sel" + Type + s + "StatUncert",
230 value="-",
231 roundTo=None )
232 pass
233 pass
234
235
236 print "-------- BG ---------"
237 print "BG: ", round( bg, 2 ), " +- ", round( math.sqrt( bgerr ),2 )
238
239 if makeTexFile:
240 TF.addCommand( name="Sel" + Type + "All",
241 value=bg,
242 roundTo=roundTo )
243 TF.addCommand( name="Sel" + Type + "All" + "StatUncert",
244 value=math.sqrt( bgerr ),
245 roundTo=roundTo )
246 pass
247
248
249 print "--------Data---------"
250 if "Data" in readIn.sampleList:
251 nbinsdata = histDict[ histList[ 0 ] ][ "Data" ].GetNbinsX() + 1
252 print "Data: ", round( histDict[ histList[ 0 ] ][ "Data" ].Integral( lowestBin, nbinsdata ), 2 ), \
253 " +- ", round( math.sqrt( histDict[ histList[ 0 ] ][ "Data" ].Integral( lowestBin, nbinsdata ) ), 2 )
254
255 if makeTexFile:
256 TF.addCommand( name="Sel" + Type + "Data",
257 value=histDict[ histList[ 0 ] ][ "Data" ].Integral( lowestBin, nbinsdata ),
258 roundTo=0 )
259 TF.addCommand( name="Sel" + Type + "Data" + "StatUncert",
260 value=math.sqrt( histDict[ histList[ 0 ] ][ "Data" ].Integral( lowestBin, nbinsdata ) ),
261 roundTo=roundTo )
262 pass
263
264 print "-------Signal--------"
265 for sample in readIn.sampleList:
266 if statusDict[ sample ] == "Signal":
267 nbinssignal = histDict[ histList[ 0 ] ][ sample ].GetNbinsX() + 1
268 nserr = ROOT.Double( 0 )
269 ns = histDict[ histList[ 0 ] ][ sample ].IntegralAndError( lowestBin, nbinssignal, nserr )
270 print sample, ": ", round( ns, 2 ), " +- ", round( nserr, 2 )
271
272 if makeTexFile:
273 TF.addCommand( name="Sel" + Type + nameMap[ sample ],
274 value=ns,
275 roundTo=roundTo )
276 TF.addCommand( name="Sel" + Type + nameMap[ sample ] + "StatUncert",
277 value=nserr,
278 roundTo=roundTo )
279 pass
280
281 pass
282 pass
283 print "###########################################"
284 #print
285 print "------ Number of used MC evens ----"
286 #print
287 mcall = 0
288 for sample in readInUnscaled.sampleList:
289 nbins = histDict[ histList[ 0 ] ][ sample ].GetNbinsX() + 1
290 mc = histDictUnscaled[ histList[ 0 ] ][ sample ].GetEntries()
291 mcall += mc
292 print sample, ": ", mc
293 s = sample
294 if sample in nameMap.keys():
295 s = nameMap[ sample ]
296 pass
297 TF.addCommand( name="Sel" + Type + s + "MC",
298 value=mc,
299 roundTo=0 )
300 pass
301 TF.addCommand( name="Sel" + Type + "All" + "MC",
302 value=mcall,
303 roundTo=0 )
304
305 if makeTexFile:
306 TF.writeTexFile()
307 pass
308
309
310 pass
311