CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/Validation/RecoTau/Tools/MergeFilesAndCalculateEfficiencies_cfg.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 """
00003 
00004      MergeFilesAndCalculateEfficiencies.py
00005 
00006         Merges multiple root files containing the numerator and denominator histograms produced by the
00007         TauTagValidation package.  The efficiency (num/denominator) is then computed 
00008         as defined Validation/RecoTau/python/RecoTauValidation_cff.py and stored in OutputFile_Eff.root
00009 
00010      Usage: cmsRun MergeFilesAndCalculateEfficiencies.py OutputFile InputFiles
00011 
00012      Example: ./MergeFilesAndCalculateEfficiencies.py CMSSW_3_1_0_Signal.root CMSSW_3_1_0_ZTT_*.root
00013 
00014 """
00015 
00016 import os
00017 import sys
00018 import FWCore.ParameterSet.Config as cms
00019 from Validation.RecoTau.ValidationOptions_cff import allowedOptions
00020 
00021 if len(sys.argv) < 5:
00022    print "Error. Expected at least 3 arguments\n\nUsage: MergeFilesAndCalculateEfficiencies.py dataType OutputFile InputFileGlob"
00023    sys.exit()
00024 
00025 dataType   = sys.argv[2]
00026 OutputFile = sys.argv[3]
00027 Inputs     = sys.argv[4:]
00028 
00029 if not dataType in allowedOptions['eventType']:
00030    print "Error. The first argument must be the dataType. Types availables are:"
00031    print allowedOptions['eventType']
00032    sys.exit()
00033 
00034 for aFile in Inputs:
00035    if not os.path.exists(aFile):
00036       print "Input file %s does not exist!" % aFile
00037       sys.exit()
00038 
00039 if os.path.exists(OutputFile):
00040    GotGoodValue = False
00041    userInput = ""
00042    while not GotGoodValue:
00043       userInput = raw_input("Output file %s exists; replace it? [yn] " % OutputFile).strip()
00044       if userInput != 'y' and userInput != 'n':
00045          print "Please enter y or n"
00046       else:
00047          GotGoodValue = True
00048    if userInput == 'n':
00049       sys.exit()
00050 
00051 # Merge files using hadd utility
00052 commandString  = "hadd -f %s " % OutputFile
00053 for aFile in Inputs:
00054    commandString += aFile
00055    commandString += " "
00056 
00057 os.system(commandString)
00058 
00059 print "Running cmsRun command to generate efficiencies"
00060 
00061 process = cms.Process("TEST")
00062 
00063 process.source = cms.Source("EmptySource")
00064 
00065 process.maxEvents = cms.untracked.PSet(
00066     input = cms.untracked.int32(1)
00067 )
00068 
00069 process.DQMStore = cms.Service("DQMStore")
00070 process.load("Validation.RecoTau.dataTypes.ValidateTausOn%s_cff"%dataType)
00071 
00072 process.loadFile   = cms.EDAnalyzer("TauDQMFileLoader",
00073       myFiles = cms.PSet(
00074          inputFileNames = cms.vstring(OutputFile),
00075          scaleFactor = cms.double(1.),
00076          )
00077 )
00078 
00079 process.saveTauEff = cms.EDAnalyzer("TauDQMSimpleFileSaver",
00080 #  outputFileName = cms.string(OutputFile.replace('.root', '_Eff.root'))
00081   outputFileName = cms.string(OutputFile)
00082 )
00083 
00084 process.p = cms.Path(
00085       process.loadFile*
00086       getattr(process,'TauEfficiencies%s'%dataType)*
00087       process.saveTauEff
00088       )
00089