test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
SteerMultipleCompare Namespace Reference

Functions

def CleanArguments
 
def CreateBaseDirectory
 
def CreateDirectory
 
def CreateSubDirectory
 
def main
 
def plotDefault
 
def plotDefaults
 
def plotOneByOne
 
def StripPath
 

Variables

string __author__ = "Lars Perchalla (lars.perchalla@cern.ch)"
 
string __doc__
 

Function Documentation

def SteerMultipleCompare.CleanArguments (   argv,
  option 
)

Definition at line 53 of file SteerMultipleCompare.py.

Referenced by main().

53 
54 def CleanArguments(argv, option):
55  #remove existing output arguments
56  while argv.count(option) > 0:
57  index = argv.index(option)
58  if index < len(argv)-1:
59  argv.pop(index+1)#drop the corresponding value
60  argv.pop(index)#drop the option itself
61 
62 
63 #execute Multicompare for each plot as a comparison one by one
#argv was modified to contain only one plot each
def SteerMultipleCompare.CreateBaseDirectory (   options)

Definition at line 38 of file SteerMultipleCompare.py.

References CreateDirectory().

Referenced by main().

38 
39 def CreateBaseDirectory(options):
40  if options.out == 'MultipleCompare.png' or options.out.find('.')!=-1:
41  #default case, so no directory was given
42  #or a filename was given
43  outputDirName = 'MultipleCompareOutput'
44  else:
45  outputDirName = options.out
46  outputDir = os.path.join(os.getcwd(), outputDirName)
47  CreateDirectory(outputDir)
48  return outputDir
def SteerMultipleCompare.CreateDirectory (   dir,
  addToExisting = False 
)

Definition at line 25 of file SteerMultipleCompare.py.

Referenced by CreateBaseDirectory(), and CreateSubDirectory().

25 
26 def CreateDirectory(dir,addToExisting=False):
27  if os.path.exists(dir) and not addToExisting:
28  print "Output directory %s already exists! OK to overwrite?" % dir
29  while True:
30  input = raw_input("Please enter [y/n] ")
31  if (input == 'y'):
32  break
33  elif (input == 'n'):
34  print " ...exiting."
35  sys.exit()
36  if not os.path.exists(dir):
37  os.makedirs(dir)
def SteerMultipleCompare.CreateSubDirectory (   basedir,
  path 
)

Definition at line 49 of file SteerMultipleCompare.py.

References CreateDirectory().

Referenced by plotOneByOne().

49 
50 def CreateSubDirectory(basedir, path):
51  outputDir = os.path.join(basedir, path)
52  CreateDirectory(outputDir,True)
def SteerMultipleCompare.main (   argv = None)

Definition at line 120 of file SteerMultipleCompare.py.

References CleanArguments(), CreateBaseDirectory(), MultipleCompare.LoadCommandlineOptions(), MultipleCompare.MapDirStructure(), MultipleCompare.Match(), plotDefaults(), plotOneByOne(), and StripPath().

121 def main(argv=None):
122  if argv is None:
123  argv = sys.argv
124 
125  options, toPlot = MultipleCompare.LoadCommandlineOptions(argv)
126 
127  gROOT.SetBatch()
128 
129  testFile = TFile(options.test)
130  refFile = None
131  if options.ref != '':
132  refFile = TFile(options.ref)
133 
134  plotList = []
135  MultipleCompare.MapDirStructure( testFile,'',plotList)
136 
137  if len(plotList)<1:
138  print '\tError: Please specify at least one histogram. The following ones are available in the root file.'
139  print plotList
140  sys.exit()
141 
142  histoList = []
143  histoSubNames = []
144  paths = []
145  massiveMode = False
146  for plot in toPlot:
147  #clean the arguments. toPlot contains the list of positional arguments leftover after parsing options
148  argv.remove(plot)
149  for path in plotList:
150  if MultipleCompare.Match(plot.lower(),path.lower()):
151  histoList.append(path)
152  strippedPath, strippedPlot = StripPath(path)
153  paths.append(strippedPath)
154  histoSubNames.append(strippedPlot)
155  #print histoSubNames[-1]
156  elif plot.find('massiveMode') != -1:
157  massiveMode = True
158 
159  CleanArguments(argv,'--output')
160  CleanArguments(argv,'-o')
161 
162  outputDir = CreateBaseDirectory(options)
163 
164  if massiveMode:
165  print "Massive mode: scan all subdirs and make plots comparing each histogram one by one."
166  plotOneByOne(argv, outputDir, histoList, histoSubNames, paths)
167  else:
168  print "Default mode: Make default plot combinations."
169  plotDefaults(argv, options, outputDir)
170 
171 
#only execute main() if manually run
def SteerMultipleCompare.plotDefault (   argv,
  outputDir,
  name,
  type,
  plots,
  addArgv = [] 
)

Definition at line 74 of file SteerMultipleCompare.py.

References MultipleCompare.main().

Referenced by plotDefaults().

74 
75 def plotDefault(argv, outputDir, name, type, plots, addArgv=[]):
76  tmpArgv = argv[:]
77  tmpArgv.append('-o')
78  tmpArgv.append(outputDir+'/'+name+type)
79  tmpArgv.extend(addArgv)
80  tmpArgv.extend(plots)
81  MultipleCompare.main(tmpArgv)
82 
#make some default plots grouping several histograms
def SteerMultipleCompare.plotDefaults (   argv,
  options,
  outputDir 
)

Definition at line 83 of file SteerMultipleCompare.py.

References plotDefault().

Referenced by main().

83 
84 def plotDefaults(argv, options, outputDir):
85  name = 'Validation_'
86  if options.testLabel != None:
87  name += options.testLabel+'_'
88  else:
89  name += options.test+'_vs_'
90  if options.refLabel != None:
91  name += options.refLabel+'_'
92  else:
93  name += options.ref+'_'
94  outputType = '.eps'
95  additionalArgv = []
96  if outputDir.find('QCD')!=-1:
97  additionalArgv.append('-f') #fakerate
98  plotDefault(argv, outputDir, name, 'LeptonRejectionEffphi'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*Rejection/*Effphi'], additionalArgv)
99  plotDefault(argv, outputDir, name, 'LeptonRejectionEffeta'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*Rejection/*Effeta'], additionalArgv)
100  plotDefault(argv, outputDir, name, 'LeptonRejectionEffpt'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*Rejection/*Effpt'], additionalArgv)
101 
102  if outputDir.find('QCD')!=-1:
103  additionalArgv.append('--logScale')
104  plotDefault(argv, outputDir, name, 'Effphi'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*Effphi', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*Effphi'], additionalArgv)
105  plotDefault(argv, outputDir, name, 'Effeta'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*Effeta', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*Effeta'], additionalArgv)
106  plotDefault(argv, outputDir, name, 'Effpt'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*Effpt', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*Effpt'], additionalArgv)
107 
108  plotDefault(argv, outputDir, name, 'pTRatio_allHadronic'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_pTRatio_allHadronic', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_pTRatio_allHadronic'])
109  plotDefault(argv, outputDir, name, 'pTRatio_oneProng1Pi0'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_pTRatio_oneProng1Pi0', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_pTRatio_oneProng1Pi0'])
110  plotDefault(argv, outputDir, name, 'pTRatio_threeProng0Pi0'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_pTRatio_threeProng0Pi0', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_pTRatio_threeProng0Pi0'])
111 
112  plotDefault(argv, outputDir, name, 'Size_isolationPFChargedHadrCands'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_Size_isolationPFChargedHadrCands', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_Size_isolationPFChargedHadrCands'])
113  plotDefault(argv, outputDir, name, 'Size_isolationPFNeutrHadrCands'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_Size_isolationPFNeutrHadrCands', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_Size_isolationPFNeutrHadrCands'])
114  plotDefault(argv, outputDir, name, 'Size_isolationPFGammaCands'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_Size_isolationPFGammaCands', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_Size_isolationPFGammaCands'])
115 
116  plotDefault(argv, outputDir, name, 'SumPt_isolationPFChargedHadrCands'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_SumPt_isolationPFChargedHadrCands', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_SumPt_isolationPFChargedHadrCands'])
117  plotDefault(argv, outputDir, name, 'SumPt_isolationPFNeutrHadrCands'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_SumPt_isolationPFNeutrHadrCands', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_SumPt_isolationPFNeutrHadrCands'])
118  plotDefault(argv, outputDir, name, 'SumPt_isolationPFGammaCands'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_SumPt_isolationPFGammaCands', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_SumPt_isolationPFGammaCands'])
119 
def SteerMultipleCompare.plotOneByOne (   argv,
  outputDir,
  histoList,
  histoSubNames,
  paths 
)

Definition at line 64 of file SteerMultipleCompare.py.

References CreateSubDirectory(), MultipleCompare.main(), and ComparisonHelper.zip().

Referenced by main().

64 
65 def plotOneByOne(argv, outputDir, histoList, histoSubNames, paths):
66  for hist, name, path in zip(histoList, histoSubNames, paths):
67  CreateSubDirectory(outputDir, path)
68  #now give modified arguments to MultipleCompare
69  tmpArgv = argv[:]
70  tmpArgv.append('-o')
71  tmpArgv.append(outputDir+'/'+path+'/'+name+'.png')
72  tmpArgv.append(hist)
73  MultipleCompare.main(tmpArgv)
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def SteerMultipleCompare.StripPath (   name)

Definition at line 16 of file SteerMultipleCompare.py.

Referenced by main().

16 
17 def StripPath(name):
18  path = ''
19  plot = ''
20  matches = re.match(r'(.*)\/(.*)$', name)
21  if matches:
22  path = matches.group(1)
23  plot = matches.group(2)
24  return [path, plot]

Variable Documentation

string SteerMultipleCompare.__author__ = "Lars Perchalla (lars.perchalla@cern.ch)"

Definition at line 10 of file SteerMultipleCompare.py.

string SteerMultipleCompare.__doc__
Initial value:
1 = """Script to execute multiple plotting commands via MultipleCompare.py. Switch between massiveMode producing a set of plots comparing each one by one, and defaultMode producing a smaller set of default plot combinations by adding the commandline option massiveMode:\n\n
2 Usage: SteerMultipleCompare.py -T testFile -R refFile [options] [search strings that you want to apply '*' is supported as special character]
3  see MultiCompare.py for details
4  """

Definition at line 11 of file SteerMultipleCompare.py.