CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Compare_cfg.py
Go to the documentation of this file.
1 import os
2 import sys
3 import shutil
4 
5 try:
6  ReleaseBase = os.path.join(os.environ['CMSSW_BASE'], "src")
7  ReleaseVersion = os.environ['CMSSW_VERSION']
8 except KeyError:
9  print "CMSSW enviroment not set, please run cmsenv!"
10  sys.exit()
11 
12 import glob
13 import FWCore.ParameterSet.Config as cms
14 import FWCore.ParameterSet.VarParsing as VarParsing
15 
16 #options = VarParsing.VarParsing ('standard')
18 
19 options.register( 'compareTo',
20  '',
21  VarParsing.VarParsing.multiplicity.singleton,
22  VarParsing.VarParsing.varType.string,
23  "Specify path to directory to compare to. e.g. Validation_CMSSW_2_2_9/ZTT_recoFiles"
24  )
25 
26 options.register( 'testLabel',
27  ReleaseVersion,
28  VarParsing.VarParsing.multiplicity.singleton,
29  VarParsing.VarParsing.varType.string,
30  "Label for test release (this one)"
31  )
32 
33 options.register( 'referenceLabel',
34  'NOLABEL',
35  VarParsing.VarParsing.multiplicity.singleton,
36  VarParsing.VarParsing.varType.string,
37  "Label for reference release (to compare too)"
38  )
39 
40 options.register( 'referenceUsesLegacyProdNames',
41  0,
42  VarParsing.VarParsing.multiplicity.singleton,
43  VarParsing.VarParsing.varType.int,
44  "Set to 1 if the reference files contains old (eg pfRecoTauProducer) PFTau product names"
45  )
46 
47 options.register( 'usesLegacyProdNames',
48  0,
49  VarParsing.VarParsing.multiplicity.singleton,
50  VarParsing.VarParsing.varType.int,
51  "Set to 2 if ALL files contains old (eg pfRecoTauProducer) PFTau product names"
52  )
53 
54 options.register( 'scale',
55  'linear',
56  VarParsing.VarParsing.multiplicity.singleton,
57  VarParsing.VarParsing.varType.string,
58  "Set scale of yaxis on plots (linear/log/smartlog) smartlog option sets only high-purity (TaNC, electron, muon) discriminators to log"
59  )
60 
61 options.parseArguments()
62 
63 process = cms.Process('MakingPlots')
64 process.DQMStore = cms.Service("DQMStore")
65 
66 process.maxEvents = cms.untracked.PSet(
67  input = cms.untracked.int32(0)
68 )
69 
70 process.source = cms.Source("EmptySource")
71 
72 # Get test file name
73 rootFilesInCurrentDirectory = glob.glob("*.root")
74 if len(rootFilesInCurrentDirectory) != 1:
75  print "There must be one (and only one) root files in the current directory, otherwise I don't know what to compare!"
76  sys.exit()
77 testRootFile = rootFilesInCurrentDirectory[0]
78 print "Loading test file: ", testRootFile
79 
80 EventType = "unknown"
81 # Get event type
82 if testRootFile.find("ZTT"):
83  EventType = 'ZTT'
84 elif testRootFile.find('QCD'):
85  EventType = 'QCD'
86 elif testRootFile.find('ZEE'):
87  EventType = 'ZEE'
88 elif testRootFile.find('ZMM'):
89  EventType = 'ZMM'
90 
91 #Get the reference file name
92 refDirectory = os.path.abspath(options.compareTo)
93 rootFilesInRefDirectory = glob.glob(os.path.join(refDirectory, "*.root"))
94 if len(rootFilesInCurrentDirectory) != 1:
95  print "There must be one (and only one) root files in the test directory, otherwise I don't know what to compare!"
96  sys.exit()
97 
98 refRootFile = rootFilesInRefDirectory[0]
99 print "Loading reference file: ", refRootFile
100 
101 
102 
103 CleanReferenceLabel = options.referenceLabel.replace(" ","").replace("-","")
104 CleanTestLabel = options.testLabel.replace(" ","").replace("-","")
105 
106 # Output dir to hold the comparision
107 PlotOutputDir = "ComparedTo" + CleanReferenceLabel
108 
109 #Save the reference root file and configuration for safekeeping
110 RefOutputDir = os.path.join(PlotOutputDir, "ReferenceData")
111 if not os.path.exists(RefOutputDir):
112  os.makedirs(RefOutputDir)
113 
114 shutil.copy(refRootFile, RefOutputDir)
115 shutil.copytree(os.path.join(refDirectory, "Config"), os.path.join(RefOutputDir, "Config"))
116 
117 PlotOutputDir = os.path.join(PlotOutputDir, "Plots")
118 if not os.path.exists(PlotOutputDir):
119  os.makedirs(PlotOutputDir)
120 
121 
122 # Load plotting sequences
123 process.load("Validation.RecoTau.RecoTauValidation_cfi")
124 
125 #set scale
126 from Validation.RecoTau.RecoTauValidation_cfi import SetLogScale
127 from Validation.RecoTau.RecoTauValidation_cfi import SetSmartLogScale
128 if options.scale == 'log':
129  print "Setting everything to log scale"
130  SetLogScale(process.plotTauValidation)
131 elif options.scale == 'smartlog':
132  print "Setting high purity discriminators to log scale"
133  SetSmartLogScale(process.plotTauValidation)
134 
135 
136 # Get helper functions
137 from Validation.RecoTau.RecoTauValidation_cfi import SetTestFileToPlot
138 from Validation.RecoTau.RecoTauValidation_cfi import SetReferenceFileToPlot
139 from Validation.RecoTau.RecoTauValidation_cfi import SetPlotDirectory
140 from Validation.RecoTau.RecoTauValidation_cfi import SetTestAndReferenceLabels
141 
142 #Set the test/reference files
143 SetTestFileToPlot(process, testRootFile)
144 SetReferenceFileToPlot(process, refRootFile)
145 
146 # Switch to 22X style names if desired
147 from Validation.RecoTau.RecoTauValidation_cfi import SetCompareToLegacyProductNames
148 if options.usesLegacyProdNames == 1:
149  from Validation.RecoTau.RecoTauValidation_cfi import UseLegacyProductNames
150  # remove the tanc from the sequence
151  process.plotTauValidation = cms.Sequence(process.plotTauValidationNoTanc)
152  UseLegacyProductNames(process.plotTauValidation)
153 elif options.referenceUsesLegacyProdNames == 1:
154  SetCompareToLegacyProductNames(process.plotTauValidation)
155 
156 # Set the right plot directoy
157 print process.plotTauValidation
158 SetPlotDirectory(process.plotTauValidation, PlotOutputDir)
159 
160 # Now the directories have been built (by SetPlotDirectory)
161 # lets generate the webpages
162 for baseDir, producerPlotDir in [os.path.split(x) for x in filter(os.path.isdir, glob.glob(os.path.join(PlotOutputDir, "*")))]:
163  baseDirCommand = "cd %s;" % baseDir
164  webpageMaker = "$VALTOOLS/make_comparison_webpage ";
165  webpageOptions = "%s %s %s %s" % (CleanTestLabel, CleanReferenceLabel, producerPlotDir, EventType)
166  os.system(baseDirCommand+webpageMaker+webpageOptions)
167 
168 
169 
170 SetTestAndReferenceLabels(process.plotTauValidation, options.testLabel, options.referenceLabel)
171 
172 #############################
173 # Path to be executed
174 ###############################
175 
176 process.p = cms.Path( process.loadTau
177  +process.plotTauValidation
178  )
179 
180 cfgLog = open(os.path.join(PlotOutputDir, "plot_config.py"), "write")
181 
182 print >>cfgLog, process.dumpPython()
183 
184 
def replace
Definition: linker.py:10
tuple filter
USE THIS FOR SKIMMED TRACKS process.p = cms.Path(process.hltLevel1GTSeed*process.skimming*process.offlineBeamSpot*process.TrackRefitter2) OTHERWISE USE THIS.
Definition: align_tpl.py:86