CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 54 of file SteerMultipleCompare.py.

Referenced by main().

54 
55 def CleanArguments(argv, option):
56  #remove existing output arguments
57  while argv.count(option) > 0:
58  index = argv.index(option)
59  if index < len(argv)-1:
60  argv.pop(index+1)#drop the corresponding value
61  argv.pop(index)#drop the option itself
62 
63 
64 #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 39 of file SteerMultipleCompare.py.

References CreateDirectory().

Referenced by main().

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

Definition at line 26 of file SteerMultipleCompare.py.

References print().

Referenced by CreateBaseDirectory(), and CreateSubDirectory().

26 
27 def CreateDirectory(dir,addToExisting=False):
28  if os.path.exists(dir) and not addToExisting:
29  print("Output directory %s already exists! OK to overwrite?" % dir)
30  while True:
31  input = raw_input("Please enter [y/n] ")
32  if (input == 'y'):
33  break
34  elif (input == 'n'):
35  print(" ...exiting.")
36  sys.exit()
37  if not os.path.exists(dir):
38  os.makedirs(dir)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def SteerMultipleCompare.CreateSubDirectory (   basedir,
  path 
)

Definition at line 50 of file SteerMultipleCompare.py.

References CreateDirectory().

Referenced by plotOneByOne().

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

Definition at line 121 of file SteerMultipleCompare.py.

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

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

Definition at line 75 of file SteerMultipleCompare.py.

References MultipleCompare.main().

Referenced by plotDefaults().

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

Definition at line 84 of file SteerMultipleCompare.py.

References plotDefault().

Referenced by main().

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

Definition at line 65 of file SteerMultipleCompare.py.

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

Referenced by main().

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

Definition at line 17 of file SteerMultipleCompare.py.

Referenced by main().

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

Variable Documentation

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

Definition at line 11 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 12 of file SteerMultipleCompare.py.