CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Validation/RecoTau/Tools/MultipleCompare.py

Go to the documentation of this file.
00001 import FWCore.ParameterSet.Config as cms
00002 import sys
00003 import os
00004 from ROOT import gROOT, TCanvas, TFile, gStyle, TLegend, TH1F
00005 import Validation.RecoTau.RecoTauValidation_cfi as validation
00006 
00007 def Match(required, got):
00008     for part in required.split('*'):
00009         if got.find(part) == -1:
00010             return False
00011     return True
00012 
00013 gROOT.SetStyle('Plain')
00014 gStyle.SetPalette(1)
00015 gStyle.SetOptStat(0)
00016 gStyle.SetPadGridX(True)
00017 gStyle.SetPadGridY(True)
00018 gStyle.SetOptTitle(0)
00019 
00020 testFile = TFile(sys.argv[1])
00021 refFile = TFile(sys.argv[2])
00022 ylabel = sys.argv[3]
00023 if ylabel != 'Efficiency' and ylabel != 'Fake rate':
00024     print 'Please specify in the third arg "Efficiency" or "Fake rate". Exiting...'
00025     sys.exit()
00026 toPlot = sys.argv[4:]
00027 
00028 maxLog = 3
00029 for option in toPlot:
00030     if(option.find('maxLog=') != -1):
00031         maxLog= float(option[option.find('=')+1:])
00032         toPlot.remove(option)
00033 
00034 #Takes the position of all plots that were produced
00035 plotList = []
00036 parList = ['pt', 'eta', 'phi', 'energy']
00037 for attr in dir(validation.TauEfficiencies.plots):
00038     if type(getattr(validation.TauEfficiencies.plots,attr)) is cms.PSet:
00039         pset = getattr(validation.TauEfficiencies.plots,attr)
00040         effPlot = pset.efficiency.value()
00041         for par in parList:
00042             plotList.append('DQMData/'+effPlot.replace('#PAR#',par))
00043 
00044 histoList = []
00045 for plot in toPlot:
00046     for path in plotList:
00047         if Match(plot.lower(),path.lower()):
00048             histoList.append(path)
00049 
00050 print histoList
00051 legend = TLegend(0.6,0.82,0.6+0.39,0.82+0.17)
00052 legend.SetHeader('')
00053 canvas = TCanvas('MultiPlot','MultiPlot',validation.standardDrawingStuff.canvasSizeX.value(),validation.standardDrawingStuff.canvasSizeY.value())
00054 colors = [2,3,4,6,5,7,28,1,2,3,4,6,5,7,28,1,2,3,4,6,5,7,28,1,2,3,4,6,5,7,28,1,2,3,4,6,5,7,28,1]
00055 first = True
00056 for histoPath,color in zip(histoList,colors):
00057     testH = testFile.Get(histoPath)
00058     if type(testH) != TH1F:
00059         print 'Looking for '+histoPath
00060         print 'Test plot now found! What the hell are you doing? Exiting...'
00061         sys.exit()
00062     xAx = histoPath[histoPath.find('Eff')+len('Eff'):]
00063     if hasattr(validation.standardDrawingStuff.xAxes,xAx):
00064         testH.GetXaxis().SetTitle( getattr(validation.standardDrawingStuff.xAxes,xAx).xAxisTitle.value())
00065     testH.GetYaxis().SetTitle(ylabel)
00066     testH.SetMarkerSize(1)
00067     testH.SetMarkerStyle(20)
00068     testH.SetMarkerColor(color)
00069     legend.AddEntry(testH,histoPath[histoPath.rfind('/')+1:histoPath.find('Eff')],'p')
00070     if first:
00071         first = False
00072         testH.Draw('ex0')
00073         if ylabel=='Fake rate':
00074             testH.GetYaxis().SetRangeUser(0.001,maxLog)
00075             canvas.SetLogy()
00076             canvas.Update()
00077     else:
00078         testH.Draw('same ex0 l')
00079     refH = refFile.Get(histoPath)
00080     if type(refH) != TH1F:
00081         print 'Ref plot not found! It will not be plotted!'
00082         continue
00083     refH.SetLineColor(color)
00084     refH.SetLineWidth(1)
00085     refH.DrawCopy('same hist')
00086     refH.SetFillColor(color)
00087     refH.SetFillStyle(3001)
00088     refH.Draw('same e3')
00089 legend.Draw()
00090 canvas.Print('MultipleCompare.pdf')
00091 
00092