CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MultipleCompare.py
Go to the documentation of this file.
2 import sys
3 import os
4 from ROOT import gROOT, TCanvas, TFile, gStyle, TLegend, TH1F
6 
7 def Match(required, got):
8  for part in required.split('*'):
9  if got.find(part) == -1:
10  return False
11  return True
12 
13 gROOT.SetStyle('Plain')
14 gStyle.SetPalette(1)
15 gStyle.SetOptStat(0)
16 gStyle.SetPadGridX(True)
17 gStyle.SetPadGridY(True)
18 gStyle.SetOptTitle(0)
19 
20 testFile = TFile(sys.argv[1])
21 refFile = TFile(sys.argv[2])
22 ylabel = sys.argv[3]
23 if ylabel != 'Efficiency' and ylabel != 'Fake rate':
24  print 'Please specify in the third arg "Efficiency" or "Fake rate". Exiting...'
25  sys.exit()
26 toPlot = sys.argv[4:]
27 
28 maxLog = 3
29 for option in toPlot:
30  if(option.find('maxLog=') != -1):
31  maxLog= float(option[option.find('=')+1:])
32  toPlot.remove(option)
33 
34 #Takes the position of all plots that were produced
35 plotList = []
36 parList = ['pt', 'eta', 'phi', 'energy']
37 for attr in dir(validation.TauEfficiencies.plots):
38  if type(getattr(validation.TauEfficiencies.plots,attr)) is cms.PSet:
39  pset = getattr(validation.TauEfficiencies.plots,attr)
40  effPlot = pset.efficiency.value()
41  for par in parList:
42  plotList.append('DQMData/'+effPlot.replace('#PAR#',par))
43 
44 histoList = []
45 for plot in toPlot:
46  for path in plotList:
47  if Match(plot.lower(),path.lower()):
48  histoList.append(path)
49 
50 print histoList
51 legend = TLegend(0.6,0.82,0.6+0.39,0.82+0.17)
52 legend.SetHeader('')
53 canvas = TCanvas('MultiPlot','MultiPlot',validation.standardDrawingStuff.canvasSizeX.value(),validation.standardDrawingStuff.canvasSizeY.value())
54 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]
55 first = True
56 for histoPath,color in zip(histoList,colors):
57  testH = testFile.Get(histoPath)
58  if type(testH) != TH1F:
59  print 'Looking for '+histoPath
60  print 'Test plot now found! What the hell are you doing? Exiting...'
61  sys.exit()
62  xAx = histoPath[histoPath.find('Eff')+len('Eff'):]
63  if hasattr(validation.standardDrawingStuff.xAxes,xAx):
64  testH.GetXaxis().SetTitle( getattr(validation.standardDrawingStuff.xAxes,xAx).xAxisTitle.value())
65  testH.GetYaxis().SetTitle(ylabel)
66  testH.SetMarkerSize(1)
67  testH.SetMarkerStyle(20)
68  testH.SetMarkerColor(color)
69  legend.AddEntry(testH,histoPath[histoPath.rfind('/')+1:histoPath.find('Eff')],'p')
70  if first:
71  first = False
72  testH.Draw('ex0')
73  if ylabel=='Fake rate':
74  testH.GetYaxis().SetRangeUser(0.001,maxLog)
75  canvas.SetLogy()
76  canvas.Update()
77  else:
78  testH.Draw('same ex0 l')
79  refH = refFile.Get(histoPath)
80  if type(refH) != TH1F:
81  print 'Ref plot not found! It will not be plotted!'
82  continue
83  refH.SetLineColor(color)
84  refH.SetLineWidth(1)
85  refH.DrawCopy('same hist')
86  refH.SetFillColor(color)
87  refH.SetFillStyle(3001)
88  refH.Draw('same e3')
89 legend.Draw()
90 canvas.Print('MultipleCompare.pdf')
91 
92 
Definition: Match.h:7
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
dbl *** dir
Definition: mlp_gen.cc:35