4 MergeFilesAndCalculateEfficiencies.py
6 Merges multiple root files containing the numerator and denominator histograms produced by the
7 TauTagValidation package. The efficiency (num/denominator) is then computed
8 as defined Validation/RecoTau/python/RecoTauValidation_cff.py and stored in OutputFile_Eff.root
10 Usage: cmsRun MergeFilesAndCalculateEfficiencies.py OutputFile InputFiles
12 Example: ./MergeFilesAndCalculateEfficiencies.py CMSSW_3_1_0_Signal.root CMSSW_3_1_0_ZTT_*.root
15 from __future__
import print_function
19 import FWCore.ParameterSet.Config
as cms
20 from Validation.RecoTau.ValidationOptions_cff
import allowedOptions
23 print(
"Error. Expected at least 3 arguments\n\nUsage: MergeFilesAndCalculateEfficiencies.py dataType OutputFile InputFileGlob")
26 dataType = sys.argv[2]
27 OutputFile = sys.argv[3]
30 if not dataType
in allowedOptions[
'eventType']:
31 print(
"Error. The first argument must be the dataType. Types availables are:")
32 print(allowedOptions[
'eventType'])
36 if not os.path.exists(aFile):
37 print(
"Input file %s does not exist!" % aFile)
40 if os.path.exists(OutputFile):
43 while not GotGoodValue:
44 userInput = raw_input(
"Output file %s exists; replace it? [yn] " % OutputFile).
strip()
45 if userInput !=
'y' and userInput !=
'n':
46 print(
"Please enter y or n")
53 commandString =
"hadd -f %s " % OutputFile
55 commandString += aFile
58 os.system(commandString)
60 print(
"Running cmsRun command to generate efficiencies")
62 process = cms.Process(
"TEST")
64 process.source = cms.Source(
"EmptySource")
66 process.maxEvents = cms.untracked.PSet(
67 input = cms.untracked.int32(1)
70 process.DQMStore = cms.Service(
"DQMStore")
71 process.load(
"Validation.RecoTau.dataTypes.ValidateTausOn%s_cff"%dataType)
73 process.loadFile = cms.EDAnalyzer(
"TauDQMFileLoader",
75 inputFileNames = cms.vstring(OutputFile),
76 scaleFactor = cms.double(1.),
80 process.saveTauEff = cms.EDAnalyzer(
"TauDQMSimpleFileSaver",
82 outputFileName = cms.string(OutputFile)
87 getattr(process,
'TauEfficiencies%s'%dataType)*