ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/JohnStupak/python/doPostProc.py
Revision: 1.2
Committed: Thu Dec 20 17:44:46 2012 UTC (12 years, 4 months ago) by jstupak
Content type: text/x-python
Branch: MAIN
Changes since 1.1: +65 -102 lines
Log Message:
cleanup and comments

File Contents

# User Rev Content
1 jstupak 1.1 from ROOT import *
2     gROOT.SetBatch(1)
3     from LJMet.Com.Sample import samplesForPlotting as samples
4     from tdrStyle import *
5     setTDRStyle()
6     gStyle.SetOptStat(False)
7    
8     DEBUG=False
9    
10     inputDir='/uscms_data/d1/jstupak/analysisOutputs/'
11     inputDir+='2012_12_16/newEventSelTest'
12    
13     bJetRequirements=['0p','0','1','1p','2p']
14    
15     channels=['el','mu']
16    
17     doCutTable=True
18     doFracFit=True
19    
20     outputName=inputDir+'/plots.root'
21    
22     #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23    
24     elLumi=6732.0
25     muLumi=12211.0
26    
27     treeName='ljmet'
28    
29     sharedSelectionCuts='jet_0_pt_WprimeCalc >= 100 && jet_1_pt_WprimeCalc >= 40'
30     elSelectionCuts='elec_1_pt_WprimeCalc > 30 && abs(elec_1_eta_WprimeCalc) < 2.5 && elec_1_RelIso_WprimeCalc < 0.1 && corr_met_WprimeCalc > 20'
31     muSelectionCuts='muon_1_pt_WprimeCalc > 26 && abs(muon_1_eta_WprimeCalc) < 2.1 && muon_1_RelIso_WprimeCalc < 0.12 && corr_met_WprimeCalc > 20'
32    
33     SFWj = 0.85
34     SFWc = 0.92*1.66
35     SFWb = 0.92*1.21
36    
37     lumiFracUnc = 0.022
38     ttbarSigmaFracUnc = 0.15
39     wJetsSigmaFracUnc = 0.20
40     otherSigmaFracUnc = 0.20
41    
42     #---------------------------------------------------------------------------------------------------------------------------------------------
43    
44     output=TFile(outputName,"RECREATE")
45     bkgdNorms={}
46 jstupak 1.2 QCDFrac={}
47     QCDFracUnc={}
48     fakeRate={}
49     fitChi2={}
50     fitNDF={}
51 jstupak 1.1
52     class WPrimePlot:
53    
54     def __init__(self,name,distribution,nBins=100,xMin=0,xMax=100,xTitle='',yLog=True,nB="0",otherCuts='',channel='el'):
55     self.name=name; self.distribution=distribution; self.nBins=nBins; self.xMin=xMin; self.xMax=xMax; self.xTitle=xTitle; self.yLog=yLog; self.nB=nB; self.otherCuts=otherCuts; self.channel=channel;
56     if not bkgdNorms.has_key(self.nB): bkgdNorms[self.nB]={}
57     if not QCDFrac.has_key(self.nB):
58     QCDFrac[self.nB]={}
59     QCDFracUnc[self.nB]={}
60 jstupak 1.2 fakeRate[self.nB]={}
61 jstupak 1.1 fitChi2[self.nB]={}
62     fitNDF[self.nB]={}
63    
64     def Prepare(self):
65     result={}
66    
67     cuts=sharedSelectionCuts
68     if self.channel=='el': cuts+='&&'+elSelectionCuts
69     elif self.channel=='mu': cuts+='&&'+muSelectionCuts
70    
71     if self.nB=="0":
72     bTagCut='((jet_0_tag_WprimeCalc + jet_1_tag_WprimeCalc)==0)'
73     elif self.nB=="0p":
74     bTagCut='1'
75     elif self.nB=="1":
76     bTagCut='((jet_0_tag_WprimeCalc + jet_1_tag_WprimeCalc)==1)'
77     elif self.nB=="1p":
78     bTagCut='((jet_0_tag_WprimeCalc + jet_1_tag_WprimeCalc)>=1)'
79     elif self.nB=="2":
80     bTagCut='((jet_0_tag_WprimeCalc + jet_1_tag_WprimeCalc)==2)'
81     elif self.nB=="2p":
82     #bTagCut='((jet_0_tag_WprimeCalc + jet_1_tag_WprimeCalc)>=2)'
83     bTagCut='((jet_0_tag_WprimeCalc==1 && (jet_1_tag_WprimeCalc + jet_2_tag_WprimeCalc + jet_3_tag_WprimeCalc + jet_4_tag_WprimeCalc + jet_5_tag_WprimeCalc + jet_6_tag_WprimeCalc + jet_7_tag_WprimeCalc + jet_8_tag_WprimeCalc + jet_9_tag_WprimeCalc) >= 1 ) || (jet_1_tag_WprimeCalc==1 && (jet_0_tag_WprimeCalc + jet_2_tag_WprimeCalc + jet_3_tag_WprimeCalc + jet_4_tag_WprimeCalc + jet_5_tag_WprimeCalc + jet_6_tag_WprimeCalc + jet_7_tag_WprimeCalc + jet_8_tag_WprimeCalc + jet_9_tag_WprimeCalc) >= 1))'
84 jstupak 1.2
85     #make name unique
86 jstupak 1.1 self.name+='_nB'+self.nB+'_'+self.channel
87    
88     if (self.channel == 'el'): lumi=elLumi
89     elif (self.channel == 'mu'): lumi=muLumi
90 jstupak 1.2
91     #get histograms with proper normalization
92 jstupak 1.1 for sample in samples:
93 jstupak 1.2 #skip electron (muon) data for muon (electron) channel
94 jstupak 1.1 if (self.channel=='el' and 'SingleMu' in sample.name) or (self.channel=='mu' and 'SingleEl' in sample.name): continue
95    
96     sample.file=TFile(inputDir+'/'+sample.name+'.root')
97     sample.tree=sample.file.Get(treeName)
98     hName=self.name+'_'+sample.name
99     sample.h=TH1F(hName,";"+self.xTitle,self.nBins,self.xMin,self.xMax)
100    
101     if sample.tree.GetLeaf('sampleWeight_WprimeCalc'): weight='sampleWeight_WprimeCalc'
102     else: weight='1' #for backwards compatibility
103    
104     if sample.isMC:
105 jstupak 1.2 SF=1. #not currently being used
106 jstupak 1.1 weight+='*weight_PU_ABC_PileUpCalc'
107     if (self.channel == 'el'): weight+='*weight_ElectronEff_WprimeCalc'
108     elif (self.channel == 'mu'): weight+='*weight_MuonEff_WprimeCalc'
109    
110     if sample.name=='WJets':
111     sample.tree.Draw(self.distribution+">>"+hName,weight+'*'+str(SFWj)+'*('+cuts+'&&'+bTagCut+'&& n_Bjets_WprimeCalc==0 && n_Cjets_WprimeCalc==0)','goff')
112     sample.tree.Draw(self.distribution+">>+"+hName,weight+'*'+str(SFWc)+'*('+cuts+'&&'+bTagCut+'&& n_Bjets_WprimeCalc==0 && n_Cjets_WprimeCalc>0)','goff')
113     sample.tree.Draw(self.distribution+">>+"+hName,weight+'*'+str(SFWb)+'*('+cuts+'&&'+bTagCut+'&& n_Bjets_WprimeCalc>0)','goff')
114     bTagEff=sample.h.Integral(0,self.nBins+1)
115 jstupak 1.2
116     #get shape from untagged sample
117 jstupak 1.1 sample.tree.Draw(self.distribution+">>"+hName,weight+'*'+str(SFWj)+'*('+cuts+'&& n_Bjets_WprimeCalc==0 && n_Cjets_WprimeCalc==0)','goff')
118     result['W+light']=sample.h.Integral(0,self.nBins+1)
119     sample.tree.Draw(self.distribution+">>+"+hName,weight+'*'+str(SFWc)+'*('+cuts+'&& n_Bjets_WprimeCalc==0 && n_Cjets_WprimeCalc>0)','goff')
120     result['W+c']=sample.h.Integral(0,self.nBins+1)-result['W+light']
121     sample.tree.Draw(self.distribution+">>+"+hName,weight+'*'+str(SFWb)+'*('+cuts+'&& n_Bjets_WprimeCalc>0)','goff')
122     result['W+b']=sample.h.Integral(0,self.nBins+1)-result['W+light']-result['W+c']
123     bTagEff/=sample.h.Integral(0,self.nBins+1)
124 jstupak 1.2
125     sample.h.Scale(bTagEff) #get proper normalization
126 jstupak 1.1 result['W+b']*=bTagEff*SF*lumi*sample.crossSection/sample.nEvents
127     result['W+c']*=bTagEff*SF*lumi*sample.crossSection/sample.nEvents
128     result['W+b']*=bTagEff*SF*lumi*sample.crossSection/sample.nEvents
129    
130     else:
131     nSelectedRaw=sample.tree.Draw(self.distribution+">>"+hName,weight+'*('+cuts+'&&'+bTagCut+')','goff')
132    
133     if sample.isMC and sample.h.Integral(0,self.nBins+1)!=0: sample.h.Scale(SF*lumi*sample.crossSection/sample.nEvents)
134    
135 jstupak 1.2 if DEBUG: #for event comparison
136 jstupak 1.1 if 'TTbar_Powheg' in sample.name and self.channel=='el':
137     sample.tree.SetScanField(0)
138 jstupak 1.2 print '\n',sample.name,' ',self.channel
139     sample.tree.Scan('run_CommonCalc:lumi_CommonCalc:event_CommonCalc:corr_met_WprimeCalc:jet_0_pt_WprimeCalc:jet_1_pt_WprimeCalc:elec_1_pt_WprimeCalc:elec_1_eta_WprimeCalc:elec_1_RelIso_WprimeCalc:muon_1_pt_WprimeCalc:muon_1_eta_WprimeCalc:muon_1_RelIso_WprimeCalc','('+cuts+'&&'+bTagCut+')')
140 jstupak 1.1
141 jstupak 1.2 result[sample.name]=sample.h.Integral(0,self.nBins+1) #for cutflow table
142 jstupak 1.1
143 jstupak 1.2 #format histograms and draw plots
144 jstupak 1.1 output.cd()
145     self.signals=[]
146     self.backgroundStack=THStack()
147     self.ewk=TH1F(self.name+'_ewk',';'+self.xTitle,self.nBins,self.xMin,self.xMax)
148     self.top=TH1F(self.name+'_top',';'+self.xTitle,self.nBins,self.xMin,self.xMax)
149     self.qcd=TH1F(self.name+'_qcd',';'+self.xTitle,self.nBins,self.xMin,self.xMax)
150     self.data=TH1F(self.name+'_data',';'+self.xTitle,self.nBins,self.xMin,self.xMax)
151     self.data.SetMarkerStyle(20)
152     for sample in samples:
153     if (self.channel=='el' and 'SingleMu' in sample.name) or (self.channel=='mu' and 'SingleEl' in sample.name): continue
154     elif sample.doQCD:
155     self.qcd.Add(sample.h)
156     elif sample.isSignal:
157     sample.h.Scale(20)
158     sample.h.SetLineColor(1)
159     sample.h.SetLineStyle(6+len(self.signals))
160     self.signals+=[sample.h]
161     elif sample.isBackground:
162     if sample.name[0]=='T': self.top.Add(sample.h)
163     else: self.ewk.Add(sample.h)
164     elif sample.isData: self.data.Add(sample.h)
165     sample.h.SetLineWidth(2)
166    
167     self.qcd.SetFillColor(ROOT.kBlue)
168     self.qcd.SetLineColor(ROOT.kBlue+2)
169     self.ewk.SetFillColor(ROOT.kGreen-3)
170     self.ewk.SetLineColor(ROOT.kGreen-2)
171     self.top.SetFillColor(ROOT.kRed-7)
172     self.top.SetLineColor(ROOT.kRed-4)
173    
174 jstupak 1.2 #get QCD normalization
175 jstupak 1.1 if doFracFit:
176 jstupak 1.2 #zero out any negetive bins if present
177 jstupak 1.1 for binNo in range(0,self.nBins+1):
178     if self.qcd.GetBinContent(binNo)<0:
179     self.qcd.SetBinContent(binNo,0)
180     self.qcd.SetBinError(binNo,0)
181 jstupak 1.2 if not bkgdNorms[self.nB].has_key(self.channel): #if fit hasn't been performed yet for this channel/multiplicity
182     bkgdNorms[self.nB][self.channel]=self.getNorms() #do the fit
183     if bkgdNorms[self.nB][self.channel]: #if fit was succesful
184 jstupak 1.1 value=Double()
185     error=Double()
186     self.fitter.GetResult(0,value,error)
187     QCDFrac[self.nB][self.channel]=value
188     QCDFracUnc[self.nB][self.channel]=error
189     fitChi2[self.nB][self.channel]=self.fitter.GetChisquare()
190     fitNDF[self.nB][self.channel]=self.fitter.GetNDF()
191 jstupak 1.2 fakeRate[self.nB][self.channel]=bkgdNorms[self.nB][self.channel]['qcd']/self.qcd.Integral(0,self.nBins+1)
192     self.ewk.Scale(bkgdNorms[self.nB][self.channel]['ewk']/self.ewk.Integral(0,self.nBins+1)) #this is only done to show results of fit
193     self.top.Scale(bkgdNorms[self.nB][self.channel]['top']/self.top.Integral(0,self.nBins+1)) #this is only done to show results of fit
194     self.qcd.Scale(fakeRate[self.nB][self.channel])
195    
196     #Scheme Choice
197     #Scheme B
198     #if self.nB=='2p': self.qcd.Scale(fakeRate['1p'][self.channel])
199     #else: self.qcd.Scale(fakeRate[self.nB][self.channel])
200     #Scheme C
201     self.qcd.Scale(fakeRate['0p'][self.channel])
202    
203 jstupak 1.1 self.backgroundStack.Add(self.qcd)
204     self.backgroundStack.Add(self.ewk)
205     self.backgroundStack.Add(self.top)
206    
207     self.background=self.backgroundStack.GetStack().Last().Clone(self.name+'_background')
208     result['Total Background']=self.background.Integral(0,self.nBins+1)
209     result['Data']=self.data.Integral(0,self.nBins+1)
210     result['QCD']=self.qcd.Integral(0,self.nBins+1)
211    
212     return result
213    
214    
215     def Draw(self):
216    
217     self.canvas=TCanvas(self.name,"",1000,800)
218    
219     yDiv=0.35
220 jstupak 1.2 self.uPad=TPad("uPad","",0,yDiv,1,1) #for actual plots
221 jstupak 1.1 self.uPad.SetBottomMargin(0)
222     self.uPad.SetRightMargin(.05)
223     self.uPad.SetLeftMargin(.18)
224     self.uPad.Draw()
225    
226 jstupak 1.2 self.lPad=TPad("lPad","",0,0,1,yDiv) #for sigma runner
227 jstupak 1.1 self.lPad.SetTopMargin(0)
228 jstupak 1.2 self.lPad.SetBottomMargin(.4)
229 jstupak 1.1 self.lPad.SetRightMargin(.05)
230     self.lPad.SetLeftMargin(.18)
231     self.lPad.SetGridy()
232     self.lPad.Draw()
233    
234     self.data.SetMaximum(2*self.data.GetMaximum())
235     self.data.SetMinimum(0.025)
236     self.data.GetYaxis().CenterTitle()
237     self.data.GetXaxis().SetLabelSize(0)
238     self.data.GetYaxis().SetLabelSize(0.08)
239     self.data.GetYaxis().SetTitleSize(0.12)
240     self.data.GetYaxis().SetTitleOffset(.75)
241    
242     if self.yLog:
243     self.uPad.SetLogy()
244     self.data.SetMaximum(500*self.data.GetMaximum())
245    
246     binWidth=round(self.data.GetBinWidth(1),5)
247     if binWidth-round(binWidth)<.001*binWidth: binWidth=int(round(binWidth))
248     yTitle="Events / "+str(binWidth)
249 jstupak 1.2 if '[' in self.xTitle and ']' in self.xTitle: #get units from x axis title
250 jstupak 1.1 begin=self.xTitle.find('[')+1
251     end=self.xTitle.find(']')
252     yTitle+=' '+self.xTitle[begin:end]
253     self.data.GetYaxis().SetTitle(yTitle)
254    
255     self.uPad.cd()
256 jstupak 1.2 self.data.Draw("E1") #draw data first because its easier to format a TH1 than a THStack
257 jstupak 1.1 self.backgroundStack.Draw("SAME HIST")
258     for signal in self.signals: signal.Draw("SAME HIST")
259 jstupak 1.2 self.data.Draw("SAME E1") #redraw data so its not hidden
260 jstupak 1.1 self.uPad.RedrawAxis()
261    
262 jstupak 1.2 #calculate stat+sys uncertainty
263 jstupak 1.1 self.uncBand=self.background.Clone("unc")
264     for binNo in range(0,self.nBins+1):
265     lumiUnc=0
266     sigmaUnc=0
267     statUnc=0
268     for sample in samples:
269     if sample.isBackground:
270     lumiUnc+=(sample.h.GetBinContent(binNo)*lumiFracUnc)**2
271     if sample.name=='WJets': sigmaFracUnc=wJetsSigmaFracUnc
272     elif sample.name[0]=='T': sigmaFracUnc=ttbarSigmaFracUnc
273 jstupak 1.2 else: sigmaFracUnc=otherSigmaFracUnc #WW, Z+Jets
274 jstupak 1.1 sigmaUnc+=(sample.h.GetBinContent(binNo)*sigmaFracUnc)**2
275     statUnc+=sample.h.GetBinError(binNo)**2
276     totalUnc=sqrt(lumiUnc+sigmaUnc+statUnc)
277     self.uncBand.SetBinError(binNo,totalUnc)
278     self.background.SetBinError(binNo,totalUnc)
279     self.uncBand.SetFillStyle(3344)
280     self.uncBand.SetFillColor(1)
281     self.uncBand.SetLineColor(1)
282     gStyle.SetHatchesLineWidth(1)
283     self.uncBand.Draw("SAME E2")
284    
285     legend=TLegend(0.60,0.60,0.90,0.90)
286     legend.SetShadowColor(0);
287     legend.SetFillColor(0);
288     legend.SetLineColor(0);
289     legend.AddEntry(self.data,"Data")
290     legend.AddEntry(self.top,"t#bar{t} + Single-Top", "f")
291     legend.AddEntry(self.ewk,"W#rightarrowl#nu + Z/#gamma*#rightarrowl^{+}l^{-} + VV" , "f")
292     legend.AddEntry(self.qcd,"QCD","f")
293     for signal in self.signals:
294     name=signal.GetName()
295     begin=name.find("Wprime")+6
296     end=name.find("Right")-2
297     dot=end-1
298     mass=name[begin:dot]+'.'+name[dot:end]
299     legend.AddEntry(signal, "W'_{R} x 20, m="+mass+" TeV", "l")
300     legend.AddEntry(self.uncBand , "Uncertainty" , "f")
301     legend.Draw("SAME")
302    
303     prelimTex=TLatex()
304     prelimTex.SetNDC()
305     prelimTex.SetTextSize(0.04)
306     prelimTex.SetTextAlign(31) # align right
307     if self.channel=='el': lumi=elLumi
308     elif self.channel=='mu': lumi=muLumi
309     lumi/=1000.
310     lumi=round(lumi,2)
311     prelimTex.DrawLatex(0.87, 0.95, "CMS Preliminary, "+str(lumi)+" fb^{-1} at #sqrt{s} = 8 TeV");
312    
313     if self.nB=="0":
314     bTagLabel="N_{b tags} = 0"
315     elif self.nB=="0p":
316     bTagLabel="N_{b tags} #geq 0"
317     elif self.nB=="1":
318     bTagLabel="N_{b tags} = 1"
319     elif self.nB=="1p":
320     bTagLabel="N_{b tags} #geq 1"
321     elif self.nB=="2":
322     bTagLabel="N_{b tags} = 2"
323     elif self.nB=="2p":
324     bTagLabel="N_{b tags} #geq 2"
325     channelTex = TLatex()
326     channelTex.SetNDC()
327     channelTex.SetTextSize(0.08)
328     channelTex.SetTextAlign(31) # align right
329     if self.channel=='el': text='e'
330     elif self.channel=='mu': text='#mu'
331     text+="+jets "+bTagLabel
332     channelTex.DrawLatex(0.5, 0.83, text);
333    
334     self.lPad.cd()
335     self.pull=self.data.Clone("pull")
336     for binNo in range(0,self.nBins+1):
337     if self.background.GetBinError(binNo)!=0:
338     self.pull.SetBinContent(binNo,(self.data.GetBinContent(binNo)-self.background.GetBinContent(binNo))/self.background.GetBinError(binNo))
339     self.pull.SetMaximum(3)
340     self.pull.SetMinimum(-3)
341     self.pull.SetFillColor(2)
342     self.pull.SetLineColor(2)
343     self.pull.GetXaxis().SetLabelSize(.15)
344     self.pull.GetXaxis().SetTitleSize(0.18)
345     self.pull.GetXaxis().SetTitle(self.xTitle)
346     self.pull.GetXaxis().SetTitleOffset(.95) #1.15
347     self.pull.GetYaxis().SetLabelSize(0.125)
348     self.pull.GetYaxis().SetTitleSize(0.1)
349     self.pull.GetYaxis().SetTitle('#sigma(Data-MC)')
350     self.pull.GetYaxis().SetTitleOffset(.35)
351     self.pull.GetYaxis().SetNdivisions(5);
352     self.pull.Draw("HIST")
353    
354     output.cd()
355 jstupak 1.2 self.canvas.Write()
356 jstupak 1.1 self.data.Write()
357     self.qcd.Write()
358     self.ewk.Write()
359     self.top.Write()
360     self.canvas.SaveAs(inputDir+'/'+self.name+'.pdf')
361 jstupak 1.2 #self.canvas.SaveAs(inputDir+'/'+self.name+'.eps')
362     #self.canvas.SaveAs(inputDir+'/'+self.name+'.C')
363 jstupak 1.1
364 jstupak 1.2 #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
365 jstupak 1.1
366 jstupak 1.2 #does the QCD fit
367 jstupak 1.1 def getNorms(self):
368     data=self.data.Clone("data")
369     backgrounds=TObjArray(3)
370     backgrounds.Add(self.qcd.Clone(self.name+'_qcd_fitRes'))
371     backgrounds.Add(self.ewk.Clone(self.name+'_ewk_fitRes'))
372     backgrounds.Add(self.top.Clone(self.name+'_top_fitRes'))
373    
374     self.fitter=TFractionFitter(data,backgrounds)
375     for binNo in range(self.nBins+2):
376     for hist in [data,backgrounds[0],backgrounds[1],backgrounds[2]]:
377 jstupak 1.2 if hist.GetBinContent(binNo)<5: self.fitter.ExcludeBin(binNo) #can't have bins with very small content included in fit
378 jstupak 1.1
379     status=self.fitter.Fit()
380    
381     result={}
382     if status==0:
383     value=Double()
384     error=Double()
385    
386     fitChi2[self.nB][self.channel]=self.fitter.GetChisquare()
387     fitNDF[self.nB][self.channel]=self.fitter.GetNDF()
388    
389     self.fitter.GetResult(0,value,error)
390     result['qcd']=value*data.Integral(0,self.nBins+1)
391     QCDFrac[self.nB][self.channel]=value
392     QCDFracUnc[self.nB][self.channel]=error
393    
394     self.fitter.GetResult(1,value,error)
395     result['ewk']=value*data.Integral(0,self.nBins+1)
396     self.fitter.GetResult(2,value,error)
397     result['top']=value*data.Integral(0,self.nBins+1)
398    
399     return result
400    
401    
402     ##################################################################################################################################################################
403    
404     if __name__=='__main__':
405    
406     yields={}
407     plots=[]
408     for n in bJetRequirements:
409     yields[n]={}
410 jstupak 1.2
411 jstupak 1.1 if doFracFit:
412     plots+=[#WPrimePlot(name='corr_met_fitRes',distribution='corr_met_WprimeCalc',nBins=250,xMin=0,xMax=1000,xTitle='E_{T}^{miss} [GeV]',yLog=True,nB=n,channel='el'),
413     WPrimePlot(name='electron0_RelIso_fitRes',distribution='elec_1_RelIso_WprimeCalc',nBins=90,xMin=0,xMax=0.15,xTitle='electron Rel. Isolation',yLog=True,nB=n,channel='el'),
414     #WPrimePlot(name='corr_met_fitRes',distribution='corr_met_WprimeCalc',nBins=250,xMin=0,xMax=1000,xTitle='E_{T}^{miss} [GeV]',yLog=True,nB=n,channel='mu'),
415     #WPrimePlot(name='muon0_RelIso_fitRes',distribution='muon_1_RelIso_WprimeCalc',nBins=250,xMin=0,xMax=0.15,xTitle='muon Rel. Isolation',yLog=True,nB=n,channel='mu')
416     ]
417    
418     if doCutTable:
419     plots+=[WPrimePlot(name='electron0_pt',distribution='elec_1_pt_WprimeCalc',nBins=100,xMin=0,xMax=7000,xTitle='electron p_{T} [GeV]',yLog=True,nB=n,channel='el'),
420     WPrimePlot(name='muon0_pt',distribution='muon_1_pt_WprimeCalc',nBins=100,xMin=0,xMax=7000,xTitle='muon p_{T} [GeV]',yLog=True,nB=n,channel='mu')
421     ]
422    
423     else:
424     plots+=[WPrimePlot(name='electron0_pt',distribution='elec_1_pt_WprimeCalc',nBins=100,xMin=0,xMax=1000,xTitle='electron p_{T} [GeV]',yLog=True,nB=n,channel='el'),
425     WPrimePlot(name='electron0_eta',distribution='elec_1_eta_WprimeCalc',nBins=50,xMin=-2.5,xMax=2.5,xTitle='electron #eta',yLog=False,nB=n,channel='el'),
426     WPrimePlot(name='electron0_RelIso',distribution='elec_1_RelIso_WprimeCalc',nBins=30,xMin=0,xMax=0.15,xTitle='electron Rel. Isolation',yLog=True,nB=n,channel='el'),
427    
428     #WPrimePlot(name='muon0_pt',distribution='muon_1_pt_WprimeCalc',nBins=100,xMin=0,xMax=1000,xTitle='muon p_{T} [GeV]',yLog=True,nB=n,channel='mu'),
429     #WPrimePlot(name='muon0_eta',distribution='muon_1_eta_WprimeCalc',nBins=50,xMin=-2.5,xMax=2.5,xTitle='muon #eta',yLog=False,nB=n,channel='mu'),
430     #WPrimePlot(name='muon0_RelIso',distribution='muon_1_RelIso_WprimeCalc',nBins=30,xMin=0,xMax=0.15,xTitle='muon Rel. Isolation',yLog=True,nB=n,channel='mu')
431     ]
432     for c in channels:
433     plots+=[WPrimePlot(name='BestJetJet2W_M',distribution='BestJetJet2W_M_LjetsTopoCalcNew',nBins=68,xMin=100,xMax=3500,xTitle='M(tb) [GeV]',yLog=True,nB=n,channel=c),
434     #WPrimePlot(name='Jet1Jet2W_M',distribution='Jet1Jet2W_M_LjetsTopoCalcNew',nBins=68,xMin=100,xMax=3500,xTitle='M(tb) [GeV]',yLog=True,nB=n,channel=c),
435     WPrimePlot(name='corr_met',distribution='corr_met_WprimeCalc',nBins=100,xMin=0,xMax=1000,xTitle='E_{T}^{miss} [GeV]',yLog=True,nB=n,channel=c),
436     #WPrimePlot(name='PFjet0_pt',distribution='jet_0_pt_WprimeCalc',nBins=130,xMin=0,xMax=1300,xTitle='p_{T} (jet1) [GeV]',yLog=True,nB=n,channel=c),
437     #WPrimePlot(name='PFjet0_eta',distribution='jet_0_eta_WprimeCalc',nBins=50,xMin=-2.5,xMax=2.5,xTitle='#eta (jet1)',yLog=False,nB=n,channel=c),
438     #WPrimePlot(name='PFjet1_pt',distribution='jet_1_pt_WprimeCalc',nBins=120,xMin=0,xMax=1200,xTitle='p_{T} (jet2) [GeV]',yLog=True,nB=n,channel=c),
439     #WPrimePlot(name='PFjet1_eta',distribution='jet_1_eta_WprimeCalc',nBins=50,xMin=-2.5,xMax=2.5,xTitle='#eta (jet2)',yLog=False,nB=n,channel=c),
440     #WPrimePlot(name='PFjet2_pt',distribution='jet_2_pt_WprimeCalc',nBins=80,xMin=0,xMax=800,xTitle='p_{T} (jet3) [GeV]',yLog=True,nB=n,channel=c),
441     #WPrimePlot(name='PFjet2_eta',distribution='jet_2_eta_WprimeCalc',nBins=50,xMin=-2.5,xMax=2.5,xTitle='#eta (jet3)',yLog=False,nB=n,channel=c),
442     WPrimePlot(name='TopMass_Best',distribution='BestTop_LjetsTopoCalcNew',nBins=100,xMin=0,xMax=1000,xTitle='M(best jet,W) [GeV]',yLog=True,nB=n,channel=c),
443     #WPrimePlot(name='TopPt_Best',distribution='BestTop_Pt_LjetsTopoCalcNew',nBins=150,xMin=0,xMax=1500,xTitle='p_{T}(best jet,W) [GeV]',yLog=True,nB=n,channel=c),
444     #WPrimePlot(name='Pt_Jet1Jet2',distribution='Jet1Jet2_Pt_LjetsTopoCalcNew',nBins=150,xMin=0,xMax=1500,xTitle='p_{T}(jet1,jet2) [GeV]',yLog=True,nB=n,channel=c),
445     #WPrimePlot(name='HT',distribution='Ht_LjetsTopoCalcNew',nBins=125,xMin=0,xMax=2500,xTitle='H_{T} [GeV]',yLog=True,nB=n,channel=c),
446     WPrimePlot(name='nPV',distribution='nPV_WprimeCalc',nBins=50,xMin=0,xMax=50,xTitle='# Vertices',yLog=True,nB=n,channel=c)
447     ]
448    
449     for plot in plots:
450     yields[plot.nB][plot.channel]=plot.Prepare()
451     plot.Draw()
452    
453     cWidth=15; nameWidth=35
454     for c in channels:
455 jstupak 1.2 print ("CHANNEL:"+c).ljust(nameWidth+(2*cWidth+1)),"N_b"
456 jstupak 1.1 print "".ljust(nameWidth),
457     for n in bJetRequirements: print n.ljust(cWidth),
458     print
459     for sample in ['Data','QCD']: #,'W+light','W+c','W+b']:
460     print sample.ljust(nameWidth),
461     for n in bJetRequirements:
462     try: print str(int(round(yields[n][c][sample]))).ljust(cWidth),
463     except: pass
464     print
465     for sample in samples:
466     if (c=='el' and 'SingleMu' in sample.name) or (c=='mu' and 'SingleEl' in sample.name) or 'QCD_' in sample.name: continue
467     if sample.isData: continue
468     print sample.name.ljust(nameWidth),
469     for n in bJetRequirements:
470     print str(int(round(yields[n][c][sample.name]))).ljust(cWidth),
471     print
472     for sample in ['Total Background']:
473     print sample.ljust(nameWidth),
474     for n in bJetRequirements:
475     print str(int(round(yields[n][c][sample]))).ljust(cWidth),
476     print
477     print 'Background/Data'.ljust(nameWidth),
478     for n in bJetRequirements:
479     print str(round(yields[n][c]['Total Background']/yields[n][c]['Data'],3)).ljust(cWidth),
480     print 3*'\n'
481    
482 jstupak 1.2 if doFracFit:
483     for c in channels:
484     print 'CHANNEL:',c
485     for n in bJetRequirements:
486     print 'nB:',n
487     print 'QCDFrac =',QCDFrac[n][c]
488     print 'QCDFracUnc =',QCDFracUnc[n][c]
489     print "fake rate:",fakeRate[n][c]
490     print '100*QCDFracUnc/QCDFrac =',100*QCDFracUnc[n][c]/QCDFrac[n][c]
491     print 'chi2/nDF =',fitChi2[n][c]/fitNDF[n][c]
492     print