ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makePlots.py
(Generate patch)

Comparing UserCode/OSUT3Analysis/Configuration/scripts/makePlots.py (file contents):
Revision 1.31 by lantonel, Mon Apr 15 13:48:09 2013 UTC vs.
Revision 1.32 by lantonel, Fri Apr 19 09:54:38 2013 UTC

# Line 38 | Line 38 | if arguments.makeRatioPlots and argument
38      print "You have requested both ratio and difference plots.  Will make just ratio plots instead"
39      arguments.makeRatioPlots = False
40  
41 < from ROOT import TFile, gROOT, gStyle, gDirectory, TStyle, THStack, TH1F, TCanvas, TString, TLegend, TArrow, THStack, TIter, TKey, TPaveLabel, gPad
41 > from ROOT import TFile, gROOT, gStyle, gDirectory, TStyle, THStack, TH1F, TCanvas, TString, TLegend, TLegendEntry, TArrow, THStack, TIter, TKey, TPaveLabel, gPad
42  
43   gROOT.SetBatch()
44   gStyle.SetOptStat(0)
# Line 124 | Line 124 | for channel in channels: # loop over fin
124              LumiLabel.SetBorderSize(0)
125              LumiLabel.SetFillColor(0)
126              LumiLabel.SetFillStyle(0)
127 <        
128 <
129 <            BgMCLegend = TLegend(0.70,0.65,0.94,0.89)
130 <            BgMCLegend.AddEntry (0, "Data & Bkgd. MC", "H").SetTextFont (62)
127 >            
128 >            BgMCLegend = TLegend()
129 >            BgTitle = BgMCLegend.AddEntry(0, "Data & Bkgd. MC", "H")
130 >            BgTitle.SetTextAlign(21)
131 >            BgTitle.SetTextFont(62)
132              BgMCLegend.SetBorderSize(0)
133              BgMCLegend.SetFillColor(0)
134              BgMCLegend.SetFillStyle(0)
135 <            SignalMCLegend = TLegend(0.45,0.65,0.70,0.89)
136 <            SignalMCLegend.AddEntry (0, "Signal MC", "H").SetTextFont (62)
135 >            SignalMCLegend = TLegend()
136 >            SignalTitle = SignalMCLegend.AddEntry(0, "Signal MC", "H")
137 >            SignalTitle.SetTextAlign(21)
138 >            SignalTitle.SetTextFont(62)
139              SignalMCLegend.SetBorderSize(0)
140              SignalMCLegend.SetFillColor(0)
141              SignalMCLegend.SetFillStyle(0)
# Line 140 | Line 143 | for channel in channels: # loop over fin
143              outputFile.cd(rootDirectory+"/"+channel)
144              Canvas = TCanvas(histogramName)
145              BgMCHistograms = []
146 +            BgMCLegendEntries = []
147              SignalMCHistograms = []
148 +            SignalMCLegendEntries = []
149              DataHistograms = []
150 +            DataLegendEntries = []
151 +            
152              
153              backgroundIntegral = 0
154              dataIntegral = 0
# Line 160 | Line 167 | for channel in channels: # loop over fin
167                  xAxisLabel = Histogram.GetXaxis().GetTitle()
168                  histoTitle = Histogram.GetTitle()
169  
170 <                legLabel = labels[sample]
170 >
171                  if (arguments.printYields):
172                      yieldHist = Histogram.Integral()
173                      legLabel = legLabel + " (%.1f)" % yieldHist
# Line 168 | Line 175 | for channel in channels: # loop over fin
175                  if( types[sample] == "bgMC"):
176                      
177                      numBgMCSamples += 1
178 +                    backgroundIntegral += Histogram.Integral()
179  
180 +                    Histogram.SetLineStyle(1)
181                      if(arguments.noStack):
182                          Histogram.SetFillStyle(0)
183                          Histogram.SetLineColor(colors[sample])
184                          Histogram.SetLineWidth(2)
176                        BgMCLegend.AddEntry(Histogram,legLabel,"L").SetTextFont (42)
185                      else:
186                          Histogram.SetFillStyle(1001)
187                          Histogram.SetFillColor(colors[sample])
188                          Histogram.SetLineColor(1)
189                          Histogram.SetLineWidth(1)
182                        BgMCLegend.AddEntry(Histogram,legLabel,"F").SetTextFont (42)
190  
191 <                    Histogram.SetLineStyle(1)
185 <                    
186 <                    backgroundIntegral += Histogram.Integral()
187 <                    
191 >                    BgMCLegendEntries.append(labels[sample])
192                      BgMCHistograms.append(Histogram)
193  
194                      
# Line 198 | Line 202 | for channel in channels: # loop over fin
202                      Histogram.SetLineWidth(2)
203                      if(arguments.normalizeToUnitArea and Histogram.Integral() > 0):
204                          Histogram.Scale(1./Histogram.Integral())
205 <                    SignalMCLegend.AddEntry(Histogram,legLabel,"L").SetTextFont (42)
205 >
206 >                    SignalMCLegendEntries.append(labels[sample])
207                      SignalMCHistograms.append(Histogram)
208                      
209                  elif( types[sample] == "data"):
210  
211                      numDataSamples += 1
212 <                    
212 >                    dataIntegral += Histogram.Integral()
213 >
214                      Histogram.SetFillStyle(0)
215                      Histogram.SetLineColor(colors[sample])
216                      Histogram.SetLineStyle(1)
217                      Histogram.SetLineWidth(2)
218                      if(arguments.normalizeToUnitArea and Histogram.Integral() > 0):
219                          Histogram.Scale(1./Histogram.Integral())
220 <                    
221 <                    dataIntegral += Histogram.Integral()
216 <                    
217 <                    BgMCLegend.AddEntry(Histogram,legLabel,"LEP").SetTextFont (42)
220 >
221 >                    DataLegendEntries.append(labels[sample])
222                      DataHistograms.append(Histogram)
223                      
224              if dataIntegral > 0 and backgroundIntegral > 0:
# Line 250 | Line 254 | for channel in channels: # loop over fin
254                  dataIntegral += DataHistograms[0].Integral()
255  
256  
257 <            ### Drawing histograms to canvas
257 >            ### formatting data histograms and adding to legend
258 >            counter = 0
259 >            for Histogram in DataHistograms:
260 >                    BgMCLegend.AddEntry(Histogram,DataLegendEntries[counter],"LEP").SetTextFont (42)
261 >                    counter = counter+1
262 >
263  
264 +            ### creating the histogram to represent the statistical errors on the stack
265              if numBgMCSamples is not 0:
266                  ErrorHisto = BgMCHistograms[0].Clone("errors")
267                  ErrorHisto.SetFillStyle(3001)
268                  ErrorHisto.SetFillColor(13)
269                  ErrorHisto.SetLineWidth(0)
270 +                BgMCLegend.AddEntry(ErrorHisto,"Stat. Errors","F").SetTextFont (42)
271                  for Histogram in BgMCHistograms:
272                      if Histogram is not BgMCHistograms[0]:
273                          ErrorHisto.Add(Histogram)
274  
275 +
276 +            ### formatting bgMC histograms and adding to legend
277 +            counter = numBgMCSamples-1
278 +            for Histogram in reversed(BgMCHistograms):
279 +                    if(arguments.noStack):
280 +                        BgMCLegend.AddEntry(Histogram,BgMCLegendEntries[counter],"L").SetTextFont (42)
281 +                    else:
282 +                        BgMCLegend.AddEntry(Histogram,BgMCLegendEntries[counter],"F").SetTextFont (42)
283 +                    counter = counter-1
284 +
285 +            ### formatting signalMC histograms and adding to legend
286 +            counter = 0
287 +            for Histogram in SignalMCHistograms:
288 +                    SignalMCLegend.AddEntry(Histogram,SignalMCLegendEntries[counter],"L").SetTextFont (42)
289 +                    counter = counter+1
290 +
291 +
292 +
293 +            ### Drawing histograms to canvas
294 +
295 +
296              outputFile.cd(rootDirectory+"/"+channel)        
297  
298              makeRatioPlots = arguments.makeRatioPlots
# Line 300 | Line 332 | for channel in channels: # loop over fin
332                      if makeRatioPlots or makeDiffPlots:
333                          Stack.GetHistogram().GetXaxis().SetLabelSize(0)
334                      #draw shaded error bands
335 <                    ErrorHisto.Draw("E2 SAME")
335 >                    ErrorHisto.Draw("A E2 SAME")
336  
337                      
338                  else:
# Line 310 | Line 342 | for channel in channels: # loop over fin
342                      BgMCHistograms[0].SetMaximum(1.1*finalMax)
343                      BgMCHistograms[0].SetMinimum(0.0001)
344                      for bgMCHist in BgMCHistograms:
345 <                        bgMCHist.Draw("HIST SAME")
345 >                        bgMCHist.Draw("A HIST SAME")
346                  for signalMCHist in SignalMCHistograms:
347 <                    signalMCHist.Draw("HIST SAME")
347 >                    signalMCHist.Draw("A HIST SAME")
348                  for dataHist in DataHistograms:
349 <                    dataHist.Draw("E SAME")
349 >                    dataHist.Draw("A E SAME")
350                                  
351              elif numSignalSamples is not 0:
352                  SignalMCHistograms[0].SetTitle(histoTitle)
# Line 324 | Line 356 | for channel in channels: # loop over fin
356                  SignalMCHistograms[0].SetMinimum(0.0001)
357                  for signalMCHist in SignalMCHistograms:
358                      if(signalMCHist is not SignalMCHistograms[0]):
359 <                        signalMCHist.Draw("HIST SAME")
359 >                        signalMCHist.Draw("A HIST SAME")
360                  for dataHist in DataHistograms:
361 <                    dataHist.Draw("E SAME")
361 >                    dataHist.Draw("A E SAME")
362  
363              elif(numDataSamples is not 0):
364                  DataHistograms[0].SetTitle(histoTitle)
# Line 336 | Line 368 | for channel in channels: # loop over fin
368                  DataHistograms[0].SetMinimum(0.0001)
369                  for dataHist in DataHistograms:
370                      if(dataHist is not DataHistograms[0]):
371 <                        dataHist.Draw("E SAME")
371 >                        dataHist.Draw("A E SAME")
372  
373              
374              if(numBgMCSamples is not 0 or numDataSamples is not 0):
375 +                BgMCLegend.SetX1NDC(0.75)
376 +                if numBgMCSamples is 0:
377 +                    BgMCLegend.SetY1NDC(0.9-0.05*(1+numDataSamples))
378 +                else:
379 +                    BgMCLegend.SetY1NDC(0.9-0.05*(2+numBgMCSamples+numDataSamples))
380 +                BgMCLegend.SetX2NDC(0.9)
381 +                BgMCLegend.SetY2NDC(0.9)
382                  BgMCLegend.Draw()
383 <            if(numSignalSamples is not 0):
383 >                if(numSignalSamples is not 0):
384 >                    SignalMCLegend.SetX1NDC(0.6)
385 >                    SignalMCLegend.SetY1NDC(0.9-0.05*(1+numSignalSamples))
386 >                    SignalMCLegend.SetX2NDC(0.75)
387 >                    SignalMCLegend.SetY2NDC(0.9)
388 >                    SignalMCLegend.Draw()
389 >            elif numSignalSamples is not 0:
390 >                SignalMCLegend.SetX1NDC(0.75)
391 >                SignalMCLegend.SetY1NDC(0.9-0.05*(1+numSignalSamples))
392 >                SignalMCLegend.SetX2NDC(0.9)
393 >                SignalMCLegend.SetY2NDC(0.9)
394                  SignalMCLegend.Draw()
395  
396              if not arguments.normalizeToUnitArea or numDataSamples > 0:
397                  LumiLabel.Draw()
398              if arguments.normalizeToData and numBgMCSamples > 0 and numDataSamples > 0:
399 <                NormLabel = TPaveLabel(0.1,0.75,0.35,0.85,"MC scaled to data","NDC")
399 >                if numSignalSamples is 0:
400 >                    NormLabel = TPaveLabel(0.6,0.85,0.75,0.9,"MC scaled to data","NDC")
401 >                else:
402 >                    NormLabel = TPaveLabel(0.45,0.85,0.6,0.9,"MC scaled to data","NDC")
403                  NormLabel.SetBorderSize(0)
404                  NormLabel.SetFillColor(0)
405                  NormLabel.SetFillStyle(0)
406                  NormLabel.Draw()
407              elif arguments.normalizeToUnitArea:
408 <                NormLabel = TPaveLabel(0.1,0.75,0.35,0.85,"Scaled to unit area","NDC")
408 >                if (numBgMCSamples is not 0 or numDataSamples is not 0) and numSignalSamples is 0:
409 >                    NormLabel = TPaveLabel(0.6,0.85,0.75,0.9,"Scaled to unit area","NDC")
410 >                else:
411 >                    NormLabel = TPaveLabel(0.45,0.85,0.6,0.9,"Scaled to unit area","NDC")
412                  NormLabel.SetBorderSize(0)
413                  NormLabel.SetFillColor(0)
414                  NormLabel.SetFillStyle(0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines