2 import Validation.RecoTau.ValidationUtils
as Utils
12 RecoTauValidation_cfi.py
14 Contains the standard tau validation parameters. It is organized into
15 the following sections.
19 Set common kinematic cuts (pt > 5 and eta < 2.5) on the denominator source.
20 Note that the denominator depends on the type of test (signal/background/e etc)
22 The denominator kinematic cutter requires that
26 Produce numerator and denominator histgorams used to produce
30 TauValNumeratorAndDenominator
32 tauValSelectedDenominator (filtered GenJet collection)
36 Using numerator and denominators, calculate and store
42 TauValNumeratorAndDenominator
46 Plot curves calculated in efficiency, in both an overlay mode
47 showing overall performance for a release, and the indvidual
48 discriminator efficiency compared to a given release
53 loadAndPlotTauValidation
56 TauEfficiencies, external root file to compare to
58 Plotting must be executed in a separate cmsRun job!
62 Various scripts to automate things...
73 kinematicSelectedTauValDenominatorCut = cms.string(
'pt > 5. && abs(eta) < 2.5')
74 denominator = cms.InputTag(
"kinematicSelectedTauValDenominator")
80 Plot the pt/eta/energy/phi spectrum of PFTaus that pass
81 a series of PFTauDiscriminator cuts.
83 These will be used as the numerator/denominators of the
84 efficiency calculations
88 proc = cms.Process(
'helper')
90 StandardMatchingParameters = cms.PSet(
91 DataType = cms.string(
'Leptons'),
92 MatchDeltaR_Leptons = cms.double(0.15),
93 MatchDeltaR_Jets = cms.double(0.3),
94 SaveOutputHistograms = cms.bool(
False),
96 RefCollection = denominator,
97 TauPtCut = cms.double(0.),
98 recoCuts = cms.string(
''),
99 genCuts = cms.string(
''),
100 chainCuts = cms.bool(
False)
103 GenericTriggerSelectionParameters = cms.PSet(
104 andOr = cms.bool(
False ),
105 dbLabel = cms.string(
"PFTauDQMTrigger"),
106 andOrHlt = cms.bool(
True),
107 hltInputTag = cms.InputTag(
"TriggerResults::HLT"),
109 hltPaths = cms.vstring(
'HLT_IsoMu*_eta*_LooseIsoPFTau*_v*',
'HLT_DoubleIsoPFTau*_Trk*_eta*_v*'),
110 errorReplyHlt = cms.bool(
False),
111 verbosityLevel = cms.uint32(0)
114 proc.templateAnalyzer = cms.EDAnalyzer(
116 StandardMatchingParameters,
117 GenericTriggerSelection = GenericTriggerSelectionParameters,
118 ExtensionName = cms.string(
""),
119 TauProducer = cms.InputTag(
''),
120 discriminators = cms.VPSet(
124 proc.RunHPSValidation = proc.templateAnalyzer.clone()
125 proc.RunHPSValidation.ExtensionName =
""
127 proc.RunHPSValidation.TauProducer = cms.InputTag(
'hpsPFTauProducer')
128 proc.RunHPSValidation.discriminators = cms.VPSet(
129 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByDecayModeFinding"),selectionCut = cms.double(0.5),plotStep = cms.bool(
True)),
130 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByVLooseChargedIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(
False)),
131 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByLooseChargedIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(
False)),
132 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByTightChargedIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(
False)),
133 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByLooseIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(
False)),
134 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByVLooseCombinedIsolationDBSumPtCorr"),selectionCut = cms.double(0.5),plotStep = cms.bool(
True)),
135 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr"),selectionCut = cms.double(0.5),plotStep = cms.bool(
True)),
136 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByMediumCombinedIsolationDBSumPtCorr"),selectionCut = cms.double(0.5),plotStep = cms.bool(
True)),
137 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr"),selectionCut = cms.double(0.5),plotStep = cms.bool(
True)),
138 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByLooseElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(
False)),
139 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByMediumElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(
True)),
140 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByTightElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(
False)),
141 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByLooseMuonRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(
True)),
142 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByMediumMuonRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(
True)),
143 cms.PSet( discriminator = cms.string(
"hpsPFTauDiscriminationByTightMuonRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(
False)),
147 proc.TauValNumeratorAndDenominator = cms.Sequence(
148 proc.RunHPSValidation
155 Tau efficiency calculations
157 Define the Efficiency curves to produce. Each
158 efficiency producer takes the numberator and denominator
159 histograms and the dependent variables.
162 plotPset = Utils.SetPlotSequence(proc.TauValNumeratorAndDenominator)
163 proc.efficiencies = cms.EDAnalyzer(
164 "TauDQMHistEffProducer",
175 proc.normalizePlots = cms.EDAnalyzer(
177 plotNamesToNormalize = cms.vstring(
'*_pTRatio_*',
'*_Size_*',
'*_SumPt_*',
'*_dRTauRefJet*'),
178 reference = cms.string(
'*_pTRatio_allHadronic')
181 proc.TauEfficiencies = cms.Sequence(
190 loadTau: load two separate TauVal root files into the DQM
191 so the plotter can access them
195 loadTau = cms.EDAnalyzer(
"TauDQMFileLoader",
198 inputFileNames = cms.vstring(
'/opt/sbg/cms/ui4_data1/dbodin/CMSSW_3_5_1/src/TauID/QCD_recoFiles/TauVal_CMSSW_3_6_0_QCD.root'),
199 scaleFactor = cms.double(1.),
200 dqmDirectory_store = cms.string(
'test')
202 reference = cms.PSet(
203 inputFileNames = cms.vstring(
'/opt/sbg/cms/ui4_data1/dbodin/CMSSW_3_5_1/src/TauID/QCD_recoFiles/TauVal_CMSSW_3_6_0_QCD.root'),
204 scaleFactor = cms.double(1.),
205 dqmDirectory_store = cms.string(
'reference')
212 xAxisStuff = cms.PSet(
213 xAxisTitle = cms.string(
'P_{T} / GeV'),
214 xAxisTitleOffset = cms.double(0.9),
215 xAxisTitleSize = cms.double(0.05)
217 xModifiers = [[
'pt',[
'xAxisTitle'],[
'P_{T} / GeV']],[
'eta',[
'xAxisTitle'],[
'#eta']],[
'phi',[
'xAxisTitle'],[
'#phi']],[
'pileup',[
'xAxisTitle'],[
'# of Reco Vertices']]]
219 yAxisStuff =cms.PSet(
220 yScale = cms.string(
'linear'),
221 minY_linear = cms.double(0.),
222 maxY_linear = cms.double(1.6),
223 minY_log = cms.double(0.001),
224 maxY_log = cms.double(1.8),
225 yAxisTitle = cms.string(
'#varepsilon'),
226 yAxisTitleOffset = cms.double(1.1),
227 yAxisTitleSize = cms.double(0.05)
229 yModifiers = [[
'efficiency',[
'yScale',
'yAxisTitle'],[
'linear',
'#varepsilon']],[
'fakeRate',[
'yScale',
'yAxisTitle'],[
'log',
'Fake rate']]]
232 posX = cms.double(0.50),
233 posY = cms.double(0.72),
234 sizeX = cms.double(0.39),
235 sizeY = cms.double(0.17),
236 header = cms.string(
''),
237 option = cms.string(
'brNDC'),
238 borderSize = cms.int32(0),
239 fillColor = cms.int32(0)
241 legModifiers = [[
'efficiency',[
'posY',
'sizeY'],[0.72,0.17]],[
'efficiency_overlay',[
'posY',
'sizeY'],[0.66,0.23]]]
243 drawOptStuff = cms.PSet(
244 markerColor = cms.int32(1),
245 markerSize = cms.double(1.),
246 markerStyle = cms.int32(20),
247 lineColor = cms.int32(1),
248 lineStyle = cms.int32(1),
249 lineWidth = cms.int32(2),
250 drawOption = cms.string(
'ex0'),
251 drawOptionLegend = cms.string(
'p')
253 drawOptModifiers = [[
'eff_overlay01',[
'markerColor',
'lineColor'],[1,1]],[
'eff_overlay02',[
'markerColor',
'lineColor'],[2,2]],[
'eff_overlay03',[
'markerColor',
'lineColor'],[3,3]],[
'eff_overlay04',[
'markerColor',
'lineColor'],[4,4]],[
'eff_overlay05',[
'markerColor',
'lineColor'],[6,6]],[
'eff_overlay06',[
'markerColor',
'lineColor'],[5,5]],[
'eff_overlay07',[
'markerColor',
'lineColor'],[7,7]],[
'eff_overlay08',[
'markerColor',
'lineColor'],[28,28]],[
'eff_overlay09',[
'markerColor',
'lineColor',
'markerStyle'],[2,2,29]],[
'eff_overlay010',[
'markerColor',
'lineColor',
'markerStyle'],[4,4,29]],[
'eff_overlay011',[
'markerColor',
'lineColor',
'markerStyle'],[6,6,29]]]
255 standardDrawingStuff = cms.PSet(
256 canvasSizeX = cms.int32(640),
257 canvasSizeY = cms.int32(640),
258 indOutputFileName = cms.string(
'#PLOT#.png'),
259 xAxes = Utils.SpawnPSet(xModifiers,xAxisStuff),
260 yAxes = Utils.SpawnPSet(yModifiers,yAxisStuff),
261 legends = Utils.SpawnPSet(legModifiers,legStuff),
264 posX = cms.double(0.19),
265 posY = cms.double(0.77),
266 sizeX = cms.double(0.12),
267 sizeY = cms.double(0.04),
268 option = cms.string(
'brNDC'),
269 borderSize = cms.int32(0),
270 fillColor = cms.int32(0),
271 textColor = cms.int32(1),
272 textSize = cms.double(0.04),
273 textAlign = cms.int32(22),
274 text = cms.vstring(
'P_{T} > 5 GeV')
277 posX = cms.double(0.19),
278 posY = cms.double(0.83),
279 sizeX = cms.double(0.12),
280 sizeY = cms.double(0.04),
281 option = cms.string(
'brNDC'),
282 borderSize = cms.int32(0),
283 fillColor = cms.int32(0),
284 textColor = cms.int32(1),
285 textSize = cms.double(0.04),
286 textAlign = cms.int32(22),
287 text = cms.vstring(
'-2.5 < #eta < +2.5')
290 drawOptionSets = cms.PSet(
291 efficiency = cms.PSet(
293 markerColor = cms.int32(4),
294 markerSize = cms.double(1.),
295 markerStyle = cms.int32(20),
296 lineColor = cms.int32(1),
297 lineStyle = cms.int32(1),
298 lineWidth = cms.int32(1),
299 drawOption = cms.string(
'ep'),
300 drawOptionLegend = cms.string(
'p')
302 reference = cms.PSet(
303 lineColor = cms.int32(1),
304 lineStyle = cms.int32(1),
305 lineWidth = cms.int32(1),
306 fillColor = cms.int32(41),
307 drawOption = cms.string(
'eBand'),
308 drawOptionLegend = cms.string(
'l')
312 drawOptionEntries = Utils.SpawnPSet(drawOptModifiers,drawOptStuff)
315 standardCompareTestAndReference = cms.PSet(
316 processes = cms.PSet(
318 dqmDirectory = cms.string(
'test'),
319 legendEntry = cms.string(
'no test label'),
320 type = cms.string(
'smMC')
322 reference = cms.PSet(
323 dqmDirectory = cms.string(
'reference'),
324 legendEntry = cms.string(
'no ref label'),
325 type = cms.string(
'smMC')
386 """ Helper class that applies a given function to all modules
396 input = re.sub(
'fixedConePFTauProducer',
'pfRecoTauProducer', input)
398 fixedDiscriminationRegex = re.compile(
'fixedConePFTauDiscrimination(\w*)')
399 input = fixedDiscriminationRegex.sub(
r'pfRecoTauDiscrimination\1', input)
400 input = re.sub(
'shrinkingConePFTauProducer',
'pfRecoTauProducerHighEfficiency', input)
401 shrinkingDiscriminationRegex = re.compile(
'shrinkingConePFTauDiscrimination(\w*)')
402 input = shrinkingDiscriminationRegex.sub(
r'pfRecoTauDiscrimination\1HighEfficiency', input)
407 """ Converts a draw job defined to compare 31X named PFTau validtion efficiencies
408 to comapre a 31X to a 22X named validation """
410 if not hasattr(input,
"drawJobs"):
412 myDrawJobs = input.drawJobs.parameters_()
413 for drawJobName, drawJobData
in myDrawJobs.iteritems():
415 if not drawJobData.plots.pythonTypeName() ==
"cms.PSet":
417 pSetToInsert = cms.PSet(
418 standardEfficiencyParameters,
422 dqmMonitorElements = drawJobData.plots.dqmMonitorElements,
423 process = cms.string(
'test'),
424 drawOptionEntry = cms.string(
'eff_overlay01'),
425 legendEntry = cms.string(input.processes.test.legendEntry.value())
431 process = cms.string(
'reference'),
432 drawOptionEntry = cms.string(
'eff_overlay02'),
433 legendEntry = cms.string(input.processes.reference.legendEntry.value())
437 input.drawJobs.__setattr__(drawJobName, pSetToInsert)
441 if hasattr(module,
'processes'):
442 if module.processes.hasParameter([
'test',
'legendEntry'])
and module.processes.hasParameter([
'reference',
'legendEntry']):
443 module.processes.test.legendEntry = TestLabel
444 module.processes.reference.legendEntry = ReferenceLabel
445 print "Set test label to %s and reference label to %s for plot producer %s" % (TestLabel, ReferenceLabel, module.label())
447 print "ERROR in RecoTauValidation_cfi::MakeLabeler - trying to set test/reference label but %s does not have processes.(test/reference).legendEntry parameters!" % module.label()
451 ''' set all modules whose name contains one of the matching names to log y scale'''
453 ''' set a module to use log scaling in the yAxis'''
454 if hasattr(module,
'drawJobs'):
456 drawJobParamGetter =
lambda subName : getattr(module.drawJobs, subName)
458 attrNames =
dir(module.drawJobs)
459 for subModuleName, subModule
in zip(attrNames,
map(drawJobParamGetter, attrNames)):
460 matchedNames = [name
for name
in matchingNames
if subModuleName.find( name) > -1]
461 if len(matchingNames) == 0:
462 matchedNames = [
'take',
'everything',
'and',
'dont',
'bother']
463 if hasattr(subModule,
"yAxis")
and len(matchedNames):
464 print "Setting drawJob: ", subModuleName,
" to log scale."
465 subModule.yAxis = cms.string(
'fakeRate')
466 if len(matchingNames) == 0:
467 module.yAxes.efficiency.maxY_log = 40
468 module.yAxes.fakeRate.maxY_log = 40
473 def BaseDirectorizer(module):
476 if hasattr(module,
"outputFilePath"):
477 oldPath = module.outputFilePath.value()
478 newPath = os.path.join(newPath, oldPath)
479 if not os.path.exists(newPath):
482 module.outputFilePath = cms.string(
"%s" % newPath)
483 return BaseDirectorizer
486 if hasattr(module,
'drawJobs'):
488 drawJobs = module.drawJobs.parameterNames_()
489 for drawJob
in drawJobs:
490 if drawJob !=
"TauIdEffStepByStep":
491 module.drawJobs.__delattr__(drawJob)
492 print "Removing comparison plot", drawJob
496 myPlottingSequence.visit(myFunctor)
500 myPlottingSequence.visit(myFunctor)
504 myPlottingSequence.visit(myFunctor)
507 myProcess.loadTau.test.inputFileNames = cms.vstring(FileLoc)
511 del myProcess.loadTau.reference
513 myProcess.loadTau.reference.inputFileNames = cms.vstring(FileLoc)
517 myPlottingSequence.visit(myFunctor)
521 myPlottingSequence.visit(myFunctor)
525 myPlottingSequence.visit(myFunctor)
528 module.ExtensionName = module.ExtensionName.value()+extension
531 if module._TypedParameterizable__type ==
'TauTagValidation':
532 module.histoSettings = pset
535 if hasattr(module,
'_TypedParameterizable__type')
and module._TypedParameterizable__type ==
'TauTagValidation':
536 setattr(module,
'turnOnTrigger',cms.bool(
True))
537 for item
in pset.parameters_().items():
538 setattr(module.GenericTriggerSelection,item[0],item[1])
def SetPlotOnlyStepByStep
def TranslateToLegacyProdNames
def ConvertDrawJobToLegacyCompare
def SetValidationExtention
The plotting of HPS Efficiencies.
def SetReferenceFileToPlot
def RemoveComparisonPlotCommands
def SetTestAndReferenceLabels
def SetCompareToLegacyProductNames