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.45 by wulsin, Tue Jun 25 11:17:16 2013 UTC vs.
Revision 1.46 by lantonel, Tue Jun 25 13:01:03 2013 UTC

# Line 15 | Line 15 | from OSUT3Analysis.Configuration.process
15  
16   parser = OptionParser()
17   parser = set_commandline_arguments(parser)
18 +
19 + parser.add_option("-f", "--fancy", action="store_true", dest="makeFancy", default=False,
20 +                  help="removes the title and replaces it with the official CMS plot heading")
21   parser.add_option("--ylog", action="store_true", dest="setLogY", default=False,          
22                    help="Set logarithmic scale on vertical axis on all plots")    
23   parser.add_option("--ymin", dest="setYMin",
# Line 89 | Line 92 | else:
92      LumiInFb = intLumi/1000.
93      LumiText = "L_{int} = " + str.format('{0:.1f}', LumiInFb) + " fb^{-1}"
94  
92    
95   #bestest place for lumi. label, in top left corner
96   topLeft_x_left    = 0.1375839
97   topLeft_x_right   = 0.4580537
98   topLeft_y_bottom  = 0.8479021
99   topLeft_y_top     = 0.9475524
100   topLeft_y_offset  = 0.035
101 <                                                                        
101 >
102 > #set the text for the fancy heading
103 > HeaderText = "CMS Preliminary: " + LumiText + " at #sqrt{s} = 8 TeV"
104 >
105 > #position for header
106 > header_x_left    = 0.2181208
107 > header_x_right   = 0.9562937
108 > header_y_bottom  = 0.9479866
109 > header_y_top     = 0.9947552
110 >
111 >
112 >
113 > ##########################################################################################################################################
114 > ##########################################################################################################################################
115 > ##########################################################################################################################################
116 >
117 > def plainTextString(inputString):
118 >    inputString.replace(' ','_')
119 >    inputString.replace('<','lt')
120 >    inputString.replace('>','gt')
121 >    inputString.replace('(','')
122 >    inputString.replace(')','')
123 >    inputString.replace('=','eq')    
124 >
125 >    return inputString                                                            
126                                                                              
127   ##########################################################################################################################################
128   ##########################################################################################################################################
# Line 155 | Line 181 | def MakeOneDHist(pathToDir,histogramName
181      
182      Stack = THStack("stack",histogramName)
183  
184 +    HeaderLabel = TPaveLabel(header_x_left,header_y_bottom,header_x_right,header_y_top,HeaderText,"NDC")
185 +    HeaderLabel.SetTextAlign(32)
186 +    HeaderLabel.SetBorderSize(0)
187 +    HeaderLabel.SetFillColor(0)
188 +    HeaderLabel.SetFillStyle(0)
189 +
190      LumiLabel = TPaveLabel(topLeft_x_left,topLeft_y_bottom,topLeft_x_right,topLeft_y_top,LumiText,"NDC")
191      LumiLabel.SetBorderSize(0)
192      LumiLabel.SetFillColor(0)
# Line 219 | Line 251 | def MakeOneDHist(pathToDir,histogramName
251                  Histogram.Rebin(RebinFactor)
252  
253          xAxisLabel = Histogram.GetXaxis().GetTitle()
254 <        histoTitle = Histogram.GetTitle()
254 >        if not arguments.makeFancy:
255 >            histoTitle = Histogram.GetTitle()
256 >        else:
257 >            histoTitle = ""
258 >
259  
260          legLabel = labels[sample]
261          if (arguments.printYields):
# Line 472 | Line 508 | def MakeOneDHist(pathToDir,histogramName
508          SignalMCLegend.Draw()
509  
510  
511 +    # Deciding which text labels to draw and drawing them
512 +    drawLumiLabel = False
513 +    drawNormLabel = False
514 +    offsetNormLabel = False
515 +    drawHeaderLabel = False
516 +
517      if not arguments.normalizeToUnitArea or numDataSamples > 0: #don't draw the lumi label if there's no data and it's scaled to unit area
518 +        drawLumiLabel = True
519 +        #move the normalization label down before drawing if we drew the lumi. label
520 +        offsetNormLabel = True
521 +    if arguments.normalizeToUnitArea or arguments.normalizeToData:
522 +        drawNormLabel = True
523 +    if arguments.makeFancy:
524 +        drawHeaderLabel = True
525 +        drawLumiLabel = False
526 +
527 +    #now that flags are set, draw the appropriate labels
528 +
529 +    if drawLumiLabel:
530          LumiLabel.Draw()
531 <        if arguments.normalizeToUnitArea or arguments.normalizeToData:
532 <            #move the normalization label down before drawing if we drew the lumi. label
531 >
532 >    if drawNormLabel:
533 >        if offsetNormLabel:
534              NormLabel.SetY1NDC(topLeft_y_bottom-topLeft_y_offset)
535              NormLabel.SetY2NDC(topLeft_y_top-topLeft_y_offset)
536 <            NormLabel.Draw()
537 <
538 <    elif arguments.normalizeToUnitArea or arguments.normalizeToData:
484 <        NormLabel.SetY1NDC(topLeft_y_bottom)
485 <        NormLabel.SetY2NDC(topLeft_y_top)
536 >        else:
537 >            NormLabel.SetY1NDC(topLeft_y_bottom)
538 >            NormLabel.SetY2NDC(topLeft_y_top)
539          NormLabel.Draw()
540  
541 +    if drawHeaderLabel:
542 +        HeaderLabel.Draw()
543 +
544 +
545 +
546 +
547 +    #drawing the ratio or difference plot if requested
548  
549      if makeRatioPlots or makeDiffPlots:
550          Canvas.cd(2)
# Line 526 | Line 586 | def MakeOneDHist(pathToDir,histogramName
586  
587      Canvas.Write()
588      if arguments.savePDFs:
589 <        pathToDirString = pathToDir.replace(' ','_').replace('<','lt').replace('>','gt').replace('(','').replace(')','').replace('=','eq')
589 >        pathToDirString = plainTextString(pathToDir)
590          Canvas.SaveAs(condor_dir+"/stacked_histograms_pdfs/"+pathToDirString+"/"+histogramName+".pdf")
591  
592  
# Line 573 | Line 633 | def MakeTwoDHist(pathToDir,histogramName
633                  inputFile.Close()
634                  xAxisLabel = Histogram.GetXaxis().GetTitle()
635                  yAxisLabel = Histogram.GetYaxis().GetTitle()
636 <                histoTitle = Histogram.GetTitle()
636 >                if not arguments.makeFancy:
637 >                    histoTitle = Histogram.GetTitle()
638 >                else:
639 >                    histoTitle = ""
640              
641                  if( types[sample] == "bgMC"):
642  
# Line 682 | Line 745 | inputFile.cd()
745   outputFile.cd()
746  
747   if arguments.savePDFs:
748 <    os.system("rm -r %s/stacked_histograms_pdfs" % (condor_dir))
748 >    os.system("rm -rf %s/stacked_histograms_pdfs" % (condor_dir))
749      os.system("mkdir %s/stacked_histograms_pdfs" % (condor_dir))
750      
751  
# Line 693 | Line 756 | for key in inputFile.GetListOfKeys():
756      rootDirectory = key.GetName()
757      outputFile.mkdir(rootDirectory)
758      if arguments.savePDFs:
759 <        os.system("mkdir %s/stacked_histograms_pdfs/%s" % (condor_dir,rootDirectory.replace(' ','_').replace('<','lt').replace('>','gt').replace('(','').replace(')','').replace('=','eq')))
759 >        os.system("mkdir %s/stacked_histograms_pdfs/%s" % (condor_dir,plainTextString(rootDirectory)))
760  
761      #cd to root directory and look for histograms
762      inputFile.cd(rootDirectory)
# Line 711 | Line 774 | for key in inputFile.GetListOfKeys():
774              outputFile.cd(rootDirectory)
775              gDirectory.mkdir(key2.GetName())
776              if arguments.savePDFs:
777 <                os.system("mkdir %s/stacked_histograms_pdfs/%s" % (condor_dir,level2Directory.replace(' ','_').replace('<','lt').replace('>','gt').replace('(','').replace(')','').replace('=','eq')))
777 >                os.system("mkdir %s/stacked_histograms_pdfs/%s" % (condor_dir,plainTextString(level2Directory)))
778  
779              #####################################################
780              ###  This layer is typically the "channels" layer ###
# Line 731 | Line 794 | for key in inputFile.GetListOfKeys():
794                      outputFile.cd(level2Directory)
795                      gDirectory.mkdir(key3.GetName())
796                      if arguments.savePDFs:
797 <                        os.system("mkdir %s/stacked_histograms_pdfs/%s" % (condor_dir,level3Directory.replace(' ','_').replace('<','lt').replace('>','gt').replace('(','').replace(')','').replace('=','eq')))
797 >                        os.system("mkdir %s/stacked_histograms_pdfs/%s" % (condor_dir,plainTextString(level3Directory)))
798  
799                      #################################################
800                      ###  This layer is typically the "cuts" layer ###

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines