CMS 3D CMS Logo

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.

00054                                 :
00055   #remove existing output arguments
00056   while argv.count(option) > 0:
00057     index = argv.index(option)
00058     if index < len(argv)-1:
00059       argv.pop(index+1)#drop the corresponding value
00060     argv.pop(index)#drop the option itself
00061 
00062 
00063 #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.

00039                                 :
00040   if options.out == 'MultipleCompare.png' or options.out.find('.')!=-1:
00041     #default case, so no directory was given
00042     #or a filename was given
00043     outputDirName = 'MultipleCompareOutput'
00044   else:
00045     outputDirName = options.out
00046   outputDir = os.path.join(os.getcwd(), outputDirName)
00047   CreateDirectory(outputDir)
00048   return outputDir

def SteerMultipleCompare::CreateDirectory (   dir,
  addToExisting = False 
)

Definition at line 25 of file SteerMultipleCompare.py.

00026                                             :
00027   if os.path.exists(dir) and not addToExisting:
00028     print "Output directory %s already exists!  OK to overwrite?" % dir
00029     while True:
00030       input = raw_input("Please enter [y/n] ")
00031       if (input == 'y'):
00032         break
00033       elif (input == 'n'):
00034         print " ...exiting."
00035         sys.exit()
00036   if not os.path.exists(dir):
00037     os.makedirs(dir)

def SteerMultipleCompare::CreateSubDirectory (   basedir,
  path 
)

Definition at line 49 of file SteerMultipleCompare.py.

00050                                      :
00051   outputDir = os.path.join(basedir, path)
00052   CreateDirectory(outputDir,True)

def SteerMultipleCompare::main (   argv = None)

Definition at line 120 of file SteerMultipleCompare.py.

00121                    :
00122   if argv is None:
00123     argv = sys.argv
00124   
00125   options, toPlot = MultipleCompare.LoadCommandlineOptions(argv)
00126       
00127   gROOT.SetBatch()
00128 
00129   testFile = TFile(options.test)
00130   refFile = None
00131   if options.ref != '':
00132     refFile = TFile(options.ref)
00133 
00134   plotList = []
00135   MultipleCompare.MapDirStructure( testFile,'',plotList)
00136 
00137   if len(plotList)<1:
00138     print '\tError: Please specify at least one histogram. The following ones are available in the root file.'
00139     print plotList
00140     sys.exit()
00141 
00142   histoList = []
00143   histoSubNames = []
00144   paths = []
00145   massiveMode = False
00146   for plot in toPlot:
00147     #clean the arguments. toPlot contains the list of positional arguments leftover after parsing options
00148     argv.remove(plot)
00149     for path in plotList:
00150       if MultipleCompare.Match(plot.lower(),path.lower()):
00151         histoList.append(path)
00152         strippedPath, strippedPlot = StripPath(path)
00153         paths.append(strippedPath)
00154         histoSubNames.append(strippedPlot)
00155         #print histoSubNames[-1]
00156       elif plot.find('massiveMode') != -1:
00157         massiveMode = True
00158 
00159   CleanArguments(argv,'--output')
00160   CleanArguments(argv,'-o')
00161           
00162   outputDir = CreateBaseDirectory(options)
00163 
00164   if massiveMode:
00165     print "Massive mode: scan all subdirs and make plots comparing each histogram one by one."
00166     plotOneByOne(argv, outputDir, histoList, histoSubNames, paths)          
00167   else:
00168     print "Default mode: Make default plot combinations."
00169     plotDefaults(argv, options, outputDir)
00170 
00171 
#only execute main() if manually run
def SteerMultipleCompare::plotDefault (   argv,
  outputDir,
  name,
  type,
  plots,
  addArgv = [] 
)

Definition at line 74 of file SteerMultipleCompare.py.

00075                                                                :
00076   tmpArgv = argv[:]
00077   tmpArgv.append('-o')  
00078   tmpArgv.append(outputDir+'/'+name+type)
00079   tmpArgv.extend(addArgv)
00080   tmpArgv.extend(plots)
00081   MultipleCompare.main(tmpArgv)
00082 
#make some default plots grouping several histograms
def SteerMultipleCompare::plotDefaults (   argv,
  options,
  outputDir 
)

Definition at line 83 of file SteerMultipleCompare.py.

00084                                           :
00085   name = 'Validation_'
00086   if options.testLabel != None:
00087     name += options.testLabel+'_'
00088   else:
00089     name += options.test+'_vs_'
00090   if options.refLabel != None:
00091     name += options.refLabel+'_'
00092   else:
00093     name += options.ref+'_'
00094   outputType = '.eps'
00095   additionalArgv = []
00096   if outputDir.find('QCD')!=-1:
00097     additionalArgv.append('-f') #fakerate
00098   plotDefault(argv, outputDir, name, 'LeptonRejectionEffphi'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*Rejection/*Effphi'], additionalArgv)
00099   plotDefault(argv, outputDir, name, 'LeptonRejectionEffeta'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*Rejection/*Effeta'], additionalArgv)
00100   plotDefault(argv, outputDir, name, 'LeptonRejectionEffpt'+outputType,  ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*Rejection/*Effpt'], additionalArgv)
00101 
00102   if outputDir.find('QCD')!=-1:
00103     additionalArgv.append('--logScale')
00104   plotDefault(argv, outputDir, name, 'Effphi'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*Effphi', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*Effphi'], additionalArgv)
00105   plotDefault(argv, outputDir, name, 'Effeta'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*Effeta', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*Effeta'], additionalArgv)
00106   plotDefault(argv, outputDir, name, 'Effpt'+outputType,  ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*Effpt', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*Effpt'], additionalArgv)
00107 
00108   plotDefault(argv, outputDir, name, 'pTRatio_allHadronic'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_pTRatio_allHadronic', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_pTRatio_allHadronic'])
00109   plotDefault(argv, outputDir, name, 'pTRatio_oneProng1Pi0'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_pTRatio_oneProng1Pi0', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_pTRatio_oneProng1Pi0'])
00110   plotDefault(argv, outputDir, name, 'pTRatio_threeProng0Pi0'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_pTRatio_threeProng0Pi0', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_pTRatio_threeProng0Pi0'])
00111 
00112   plotDefault(argv, outputDir, name, 'Size_isolationPFChargedHadrCands'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_Size_isolationPFChargedHadrCands', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_Size_isolationPFChargedHadrCands'])
00113   plotDefault(argv, outputDir, name, 'Size_isolationPFNeutrHadrCands'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_Size_isolationPFNeutrHadrCands', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_Size_isolationPFNeutrHadrCands'])
00114   plotDefault(argv, outputDir, name, 'Size_isolationPFGammaCands'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_Size_isolationPFGammaCands', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_Size_isolationPFGammaCands'])
00115 
00116   plotDefault(argv, outputDir, name, 'SumPt_isolationPFChargedHadrCands'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_SumPt_isolationPFChargedHadrCands', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_SumPt_isolationPFChargedHadrCands'])
00117   plotDefault(argv, outputDir, name, 'SumPt_isolationPFNeutrHadrCands'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_SumPt_isolationPFNeutrHadrCands', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_SumPt_isolationPFNeutrHadrCands'])
00118   plotDefault(argv, outputDir, name, 'SumPt_isolationPFGammaCands'+outputType, ['DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationByDecayModeFinding/*_SumPt_isolationPFGammaCands', 'DQMData/RecoTauV/hpsPFTauProducer_hpsPFTauDiscriminationBy*CombinedIsolationDBSumPtCorr/*_SumPt_isolationPFGammaCands'])
00119 

def SteerMultipleCompare::plotOneByOne (   argv,
  outputDir,
  histoList,
  histoSubNames,
  paths 
)

Definition at line 64 of file SteerMultipleCompare.py.

00065                                                                   :
00066   for hist, name, path in zip(histoList, histoSubNames, paths):
00067     CreateSubDirectory(outputDir, path)
00068     #now give modified arguments to MultipleCompare
00069     tmpArgv = argv[:]
00070     tmpArgv.append('-o')
00071     tmpArgv.append(outputDir+'/'+path+'/'+name+'.png')
00072     tmpArgv.append(hist)
00073     MultipleCompare.main(tmpArgv)

def SteerMultipleCompare::StripPath (   name)

Definition at line 16 of file SteerMultipleCompare.py.

00017                    :
00018   path = ''
00019   plot = ''
00020   matches = re.match(r'(.*)\/(.*)$', name)
00021   if matches:
00022     path = matches.group(1)
00023     plot = matches.group(2)
00024   return [path, plot]


Variable Documentation

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

Definition at line 10 of file SteerMultipleCompare.py.

Initial value:
00001 """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
00002 Usage: SteerMultipleCompare.py -T testFile -R refFile [options] [search strings that you want to apply '*' is supported as special character]
00003   see MultiCompare.py for details
00004   """

Definition at line 11 of file SteerMultipleCompare.py.