CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 import os
00002 import sys
00003 import shutil
00004 
00005 try:
00006    ReleaseBase = os.path.join(os.environ['CMSSW_BASE'], "src")
00007    ReleaseVersion = os.environ['CMSSW_VERSION']
00008 except KeyError:
00009    print "CMSSW enviroment not set, please run cmsenv!"
00010    sys.exit()
00011 
00012 import glob
00013 import FWCore.ParameterSet.Config as cms
00014 import FWCore.ParameterSet.VarParsing as VarParsing
00015 
00016 #options = VarParsing.VarParsing ('standard')
00017 options = VarParsing.VarParsing ()
00018 
00019 options.register( 'compareTo',
00020                   '',
00021                   VarParsing.VarParsing.multiplicity.singleton,
00022                   VarParsing.VarParsing.varType.string,
00023                   "Specify path to directory to compare to. e.g. Validation_CMSSW_2_2_9/ZTT_recoFiles"
00024                  )
00025 
00026 options.register( 'testLabel',
00027                   ReleaseVersion,
00028                   VarParsing.VarParsing.multiplicity.singleton,
00029                   VarParsing.VarParsing.varType.string,
00030                   "Label for test release (this one)"
00031                  )
00032 
00033 options.register( 'referenceLabel',
00034                   'NOLABEL',
00035                   VarParsing.VarParsing.multiplicity.singleton,
00036                   VarParsing.VarParsing.varType.string,
00037                   "Label for reference release (to compare too)"
00038                  )
00039 
00040 options.register( 'referenceUsesLegacyProdNames',
00041                   0,
00042                   VarParsing.VarParsing.multiplicity.singleton,
00043                   VarParsing.VarParsing.varType.int,
00044                   "Set to 1 if the reference files contains old (eg pfRecoTauProducer) PFTau product names"
00045                  ) 
00046 
00047 options.register( 'usesLegacyProdNames',
00048                   0,
00049                   VarParsing.VarParsing.multiplicity.singleton,
00050                   VarParsing.VarParsing.varType.int,
00051                   "Set to 2 if ALL files contains old (eg pfRecoTauProducer) PFTau product names"
00052                  ) 
00053 
00054 options.register( 'scale',
00055                   'linear',
00056                   VarParsing.VarParsing.multiplicity.singleton,
00057                   VarParsing.VarParsing.varType.string,
00058                   "Set scale of yaxis on plots (linear/log/smartlog) smartlog option sets only high-purity (TaNC, electron, muon) discriminators to log"
00059                   )
00060 
00061 options.parseArguments()
00062 
00063 process = cms.Process('MakingPlots')
00064 process.DQMStore = cms.Service("DQMStore")
00065 
00066 process.maxEvents = cms.untracked.PSet(            
00067     input = cms.untracked.int32(0)         
00068 )
00069 
00070 process.source = cms.Source("EmptySource")
00071 
00072 # Get test file name
00073 rootFilesInCurrentDirectory = glob.glob("*.root")
00074 if len(rootFilesInCurrentDirectory) != 1:
00075    print "There must be one (and only one) root files in the current directory, otherwise I don't know what to compare!"
00076    sys.exit()
00077 testRootFile = rootFilesInCurrentDirectory[0]
00078 print "Loading test file: ", testRootFile
00079 
00080 EventType = "unknown"
00081 # Get event type
00082 if testRootFile.find("ZTT"):
00083    EventType = 'ZTT'
00084 elif testRootFile.find('QCD'):
00085    EventType = 'QCD'
00086 elif testRootFile.find('ZEE'):
00087    EventType = 'ZEE'
00088 elif testRootFile.find('ZMM'):
00089    EventType = 'ZMM'
00090 
00091 #Get the reference file name
00092 refDirectory = os.path.abspath(options.compareTo)
00093 rootFilesInRefDirectory = glob.glob(os.path.join(refDirectory, "*.root"))
00094 if len(rootFilesInCurrentDirectory) != 1:
00095    print "There must be one (and only one) root files in the test directory, otherwise I don't know what to compare!"
00096    sys.exit()
00097 
00098 refRootFile = rootFilesInRefDirectory[0]
00099 print "Loading reference file: ", refRootFile
00100 
00101 
00102 
00103 CleanReferenceLabel = options.referenceLabel.replace(" ","").replace("-","")
00104 CleanTestLabel      = options.testLabel.replace(" ","").replace("-","")
00105 
00106 # Output dir to hold the comparision
00107 PlotOutputDir = "ComparedTo" + CleanReferenceLabel
00108 
00109 #Save the reference root file and configuration for safekeeping
00110 RefOutputDir = os.path.join(PlotOutputDir, "ReferenceData")
00111 if not os.path.exists(RefOutputDir):
00112    os.makedirs(RefOutputDir)
00113 
00114 shutil.copy(refRootFile, RefOutputDir)
00115 shutil.copytree(os.path.join(refDirectory, "Config"), os.path.join(RefOutputDir, "Config"))
00116 
00117 PlotOutputDir = os.path.join(PlotOutputDir, "Plots")
00118 if not os.path.exists(PlotOutputDir):
00119    os.makedirs(PlotOutputDir)
00120 
00121 
00122 # Load plotting sequences
00123 process.load("Validation.RecoTau.RecoTauValidation_cfi")
00124 
00125 #set scale
00126 from Validation.RecoTau.RecoTauValidation_cfi import SetLogScale
00127 from Validation.RecoTau.RecoTauValidation_cfi import SetSmartLogScale
00128 if options.scale == 'log':
00129    print "Setting everything to log scale"
00130    SetLogScale(process.plotTauValidation)
00131 elif options.scale == 'smartlog':
00132    print "Setting high purity discriminators to log scale"
00133    SetSmartLogScale(process.plotTauValidation)
00134 
00135 
00136 # Get helper functions
00137 from Validation.RecoTau.RecoTauValidation_cfi import SetTestFileToPlot
00138 from Validation.RecoTau.RecoTauValidation_cfi import SetReferenceFileToPlot
00139 from Validation.RecoTau.RecoTauValidation_cfi import SetPlotDirectory
00140 from Validation.RecoTau.RecoTauValidation_cfi import SetTestAndReferenceLabels
00141 
00142 #Set the test/reference files
00143 SetTestFileToPlot(process, testRootFile)
00144 SetReferenceFileToPlot(process, refRootFile)
00145 
00146 # Switch to 22X style names if desired
00147 from Validation.RecoTau.RecoTauValidation_cfi import SetCompareToLegacyProductNames
00148 if options.usesLegacyProdNames == 1:
00149    from Validation.RecoTau.RecoTauValidation_cfi import UseLegacyProductNames
00150    # remove the tanc from the sequence
00151    process.plotTauValidation = cms.Sequence(process.plotTauValidationNoTanc)
00152    UseLegacyProductNames(process.plotTauValidation)
00153 elif options.referenceUsesLegacyProdNames == 1:
00154    SetCompareToLegacyProductNames(process.plotTauValidation)
00155 
00156 # Set the right plot directoy
00157 print process.plotTauValidation
00158 SetPlotDirectory(process.plotTauValidation, PlotOutputDir)
00159 
00160 # Now the directories have been built (by SetPlotDirectory)
00161 #  lets generate the webpages
00162 for baseDir, producerPlotDir in [os.path.split(x) for x in filter(os.path.isdir, glob.glob(os.path.join(PlotOutputDir, "*")))]:
00163    baseDirCommand = "cd %s;" % baseDir
00164    webpageMaker   = "$VALTOOLS/make_comparison_webpage ";
00165    webpageOptions = "%s %s %s %s" % (CleanTestLabel, CleanReferenceLabel, producerPlotDir, EventType)
00166    os.system(baseDirCommand+webpageMaker+webpageOptions)
00167 
00168 
00169 
00170 SetTestAndReferenceLabels(process.plotTauValidation, options.testLabel, options.referenceLabel)
00171 
00172 #############################
00173 # Path to be executed
00174 ###############################
00175 
00176 process.p = cms.Path( process.loadTau 
00177                      +process.plotTauValidation
00178                      )
00179 
00180 cfgLog = open(os.path.join(PlotOutputDir, "plot_config.py"), "write")
00181 
00182 print >>cfgLog,  process.dumpPython()
00183  
00184