CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MergeFilesAndCalculateEfficiencies_cfg.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 """
3 
4  MergeFilesAndCalculateEfficiencies.py
5 
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
9 
10  Usage: cmsRun MergeFilesAndCalculateEfficiencies.py OutputFile InputFiles
11 
12  Example: ./MergeFilesAndCalculateEfficiencies.py CMSSW_3_1_0_Signal.root CMSSW_3_1_0_ZTT_*.root
13 
14 """
15 
16 import os
17 import sys
18 import FWCore.ParameterSet.Config as cms
19 
20 if len(sys.argv) < 4:
21  print "Error. Expected at least 2 arguments\n\nUsage: MergeFilesAndCalculateEfficiencies.py OutputFile InputFileGlob"
22  sys.exit()
23 
24 OutputFile = sys.argv[2]
25 Inputs = sys.argv[3:]
26 
27 for aFile in Inputs:
28  if not os.path.exists(aFile):
29  print "Input file %s does not exist!" % aFile
30  sys.exit()
31 
32 if os.path.exists(OutputFile):
33  GotGoodValue = False
34  userInput = ""
35  while not GotGoodValue:
36  userInput = raw_input("Output file %s exists; replace it? [yn] " % OutputFile).strip()
37  if userInput != 'y' and userInput != 'n':
38  print "Please enter y or n"
39  else:
40  GotGoodValue = True
41  if userInput == 'n':
42  sys.exit()
43 
44 # Merge files using hadd utility
45 commandString = "hadd -f %s " % OutputFile
46 for aFile in Inputs:
47  commandString += aFile
48  commandString += " "
49 
50 os.system(commandString)
51 
52 print "Running cmsRun command to generate efficiencies"
53 
54 process = cms.Process("TEST")
55 
56 process.source = cms.Source("EmptySource")
57 
58 process.maxEvents = cms.untracked.PSet(
59  input = cms.untracked.int32(1)
60 )
61 
62 process.DQMStore = cms.Service("DQMStore")
63 process.load("Validation.RecoTau.RecoTauValidation_cfi")
64 
65 process.loadFile = cms.EDAnalyzer("DQMFileLoader",
66  myFiles = cms.PSet(
67  inputFileNames = cms.vstring(OutputFile),
68  scaleFactor = cms.double(1.),
69  )
70 )
71 
72 process.saveTauEff = cms.EDAnalyzer("DQMSimpleFileSaver",
73 # outputFileName = cms.string(OutputFile.replace('.root', '_Eff.root'))
74  outputFileName = cms.string(OutputFile)
75 )
76 
77 process.p = cms.Path(
78  process.loadFile*
79  process.TauEfficiencies*
80  process.saveTauEff
81  )
82 
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16