CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecoTauValidation_cfi.py
Go to the documentation of this file.
2 import Validation.RecoTau.ValidationUtils as Utils
3 import copy
4 import re
5 import os
6 
7 #from Validation.RecoTau.ValidationOptions_cff import *
8 
9 
10 """
11 
12  RecoTauValidation_cfi.py
13 
14  Contains the standard tau validation parameters. It is organized into
15  the following sections.
16 
17  DENOMINATOR
18 
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)
21 
22  The denominator kinematic cutter requires that
23 
24  HISTOGRAMS
25 
26  Produce numerator and denominator histgorams used to produce
27  tau efficiency plots
28 
29  Provides sequence:
30  TauValNumeratorAndDenominator
31  Requires:
32  tauValSelectedDenominator (filtered GenJet collection)
33 
34  EFFICIENCY
35 
36  Using numerator and denominators, calculate and store
37  the efficiency curves
38 
39  Provides sequence:
40  TauEfficiencies
41  Requires:
42  TauValNumeratorAndDenominator
43 
44  PLOTTING
45 
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
49 
50  Provides sequence:
51  loadTau
52  plotTauValidation
53  loadAndPlotTauValidation
54 
55  Requires:
56  TauEfficiencies, external root file to compare to
57 
58  Plotting must be executed in a separate cmsRun job!
59 
60  UTILITIES
61 
62  Various scripts to automate things...
63 
64 
65 """
66 
67 """
68 
69 DENOMINATOR
70 
71 """
72 
73 kinematicSelectedTauValDenominatorCut = cms.string('pt > 5. && abs(eta) < 2.5')
74 denominator = cms.InputTag("kinematicSelectedTauValDenominator")
75 
76 """
77 
78 HISTOGRAMS
79 
80  Plot the pt/eta/energy/phi spectrum of PFTaus that pass
81  a series of PFTauDiscriminator cuts.
82 
83  These will be used as the numerator/denominators of the
84  efficiency calculations
85 """
86 
87 #Helper process to make future cloning easier
88 proc = cms.Process('helper')
89 
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), #TRUE FOR TEST ONLY
95  #RefCollection = cms.InputTag("TauGenJetProducer","selectedGenTauDecaysToHadronsPt5Cumulative"),
96  RefCollection = denominator,
97  TauPtCut = cms.double(0.), #almost deprecated, since recoCuts provides more flexibility
98  recoCuts = cms.string(''), #filter reconstructed candidates. leave this empty to select all. or use sth like: pt > 20 & abs(eta) < 2.3
99  genCuts = cms.string(''), #filter generated candidates. leave this empty to select all. or use sth like: pt > 20 & abs(eta) < 2.3
100  chainCuts = cms.bool(False) #Decide whether to chain discriminators or not
101 )
102 
103 GenericTriggerSelectionParameters = cms.PSet(
104  andOr = cms.bool( False ),#specifies the logical combination of the single filters' (L1, HLT and DCS) decisions at top level (True=OR)
105  dbLabel = cms.string("PFTauDQMTrigger"),#specifies the label under which the DB payload is available from the ESSource or Global Tag
106  andOrHlt = cms.bool(True),#specifies the logical combination of the single HLT paths' decisions (True=OR)
107  hltInputTag = cms.InputTag("TriggerResults::HLT"),
108  #hltDBKey = cms.string('jetmet_highptjet'),#Tag of the record in the database, where IOV-based HLT paths are found. This record overwrites the configuration parameter hltPaths
109  hltPaths = cms.vstring('HLT_IsoMu*_eta*_LooseIsoPFTau*_v*','HLT_DoubleIsoPFTau*_Trk*_eta*_v*'),#Lists logical expressions of HLT paths, which should have accepted the event (fallback in case DB unaccessible)
110  errorReplyHlt = cms.bool(False),#specifies the desired return value of the HLT filter and the single HLT path filter in case of certain errors
111  verbosityLevel = cms.uint32(0) #0: complete silence (default), needed for T0 processing;
112 )
113 
114 proc.templateAnalyzer = cms.EDAnalyzer(
115  "TauTagValidation",
116  StandardMatchingParameters,
117  GenericTriggerSelection = GenericTriggerSelectionParameters,
118  ExtensionName = cms.string(""),
119  TauProducer = cms.InputTag(''),
120  discriminators = cms.VPSet(
121  )
122 )
123 
124 proc.RunHPSValidation = proc.templateAnalyzer.clone()
125 proc.RunHPSValidation.ExtensionName = ""
126 #RunHPSValidation.TauPtCut = cms.double(15.)
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("hpsPFTauDiscriminationByDecayModeFindingNewDMs"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
131  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByDecayModeFindingOldDMs"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
132  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVLooseChargedIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
133  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseChargedIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
134  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightChargedIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
135  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
136  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVLooseCombinedIsolationDBSumPtCorr"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
137  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
138  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumCombinedIsolationDBSumPtCorr"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
139  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
140  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr3Hits"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
141  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumCombinedIsolationDBSumPtCorr3Hits"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
142  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr3Hits"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
143  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVLooseIsolationMVA3oldDMwoLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
144  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseIsolationMVA3oldDMwoLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
145  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumIsolationMVA3oldDMwoLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
146  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightIsolationMVA3oldDMwoLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
147  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVTightIsolationMVA3oldDMwoLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
148  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVVTightIsolationMVA3oldDMwoLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
149  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVLooseIsolationMVA3oldDMwLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
150  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseIsolationMVA3oldDMwLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
151  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumIsolationMVA3oldDMwLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
152  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightIsolationMVA3oldDMwLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
153  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVTightIsolationMVA3oldDMwLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
154  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVVTightIsolationMVA3oldDMwLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
155  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVLooseIsolationMVA3newDMwoLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
156  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseIsolationMVA3newDMwoLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
157  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumIsolationMVA3newDMwoLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
158  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightIsolationMVA3newDMwoLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
159  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVTightIsolationMVA3newDMwoLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
160  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVVTightIsolationMVA3newDMwoLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
161  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVLooseIsolationMVA3newDMwLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
162  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseIsolationMVA3newDMwLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
163  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumIsolationMVA3newDMwLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
164  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightIsolationMVA3newDMwLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
165  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVTightIsolationMVA3newDMwLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
166  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVVTightIsolationMVA3newDMwLT"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
167  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
168  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
169  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
170  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5VLooseElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
171  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5LooseElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
172  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5MediumElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
173  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5TightElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
174  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5VTightElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
175  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseMuonRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
176  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumMuonRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
177  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightMuonRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
178  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseMuonRejection2"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
179  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumMuonRejection2"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
180  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightMuonRejection2"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
181  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseMuonRejection3"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
182  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightMuonRejection3"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
183  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVALooseMuonRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
184  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVAMediumMuonRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
185  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVATightMuonRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
186 )
187 
188 proc.TauValNumeratorAndDenominator = cms.Sequence(
189  proc.RunHPSValidation
190  )
191 
192 """
193 
194 EFFICIENCY
195 
196  Tau efficiency calculations
197 
198  Define the Efficiency curves to produce. Each
199  efficiency producer takes the numberator and denominator
200  histograms and the dependent variables.
201 """
202 
203 plotPset = Utils.SetPlotSequence(proc.TauValNumeratorAndDenominator)
204 proc.efficiencies = cms.EDAnalyzer(
205  "TauDQMHistEffProducer",
206  plots = plotPset
207  )
208 
209 
210 ################################################
211 #
212 # Normalizes All the histograms
213 #
214 ################################################
215 
216 proc.normalizePlots = cms.EDAnalyzer(
217  "DQMHistNormalizer",
218  plotNamesToNormalize = cms.vstring('*_pTRatio_*','*_Size_*','*_SumPt_*','*_dRTauRefJet*'),
219  reference = cms.string('*_pTRatio_allHadronic')
220  )
221 
222 proc.TauEfficiencies = cms.Sequence(
223  proc.efficiencies*
224  proc.normalizePlots
225  )
226 
227 """
228 
229 PLOTTING
230 
231  loadTau: load two separate TauVal root files into the DQM
232  so the plotter can access them
233 
234 """
235 
236 loadTau = cms.EDAnalyzer("TauDQMFileLoader",
237  test = cms.PSet(
238  #inputFileNames = cms.vstring('/afs/cern.ch/user/f/friis/scratch0/MyValidationArea/310pre6NewTags/src/Validation/RecoTau/test/CMSSW_3_1_0_pre6_ZTT_0505Fixes.root'),
239  inputFileNames = cms.vstring('/opt/sbg/cms/ui4_data1/dbodin/CMSSW_3_5_1/src/TauID/QCD_recoFiles/TauVal_CMSSW_3_6_0_QCD.root'),
240  scaleFactor = cms.double(1.),
241  dqmDirectory_store = cms.string('test')
242  ),
243  reference = cms.PSet(
244  inputFileNames = cms.vstring('/opt/sbg/cms/ui4_data1/dbodin/CMSSW_3_5_1/src/TauID/QCD_recoFiles/TauVal_CMSSW_3_6_0_QCD.root'),
245  scaleFactor = cms.double(1.),
246  dqmDirectory_store = cms.string('reference')
247  )
248 )
249 
250 # Lots of junk to define the plot style
251 
252 # standard drawing stuff
253 xAxisStuff = cms.PSet(
254  xAxisTitle = cms.string('P_{T} / GeV'),
255  xAxisTitleOffset = cms.double(0.9),
256  xAxisTitleSize = cms.double(0.05)
257 )
258 xModifiers = [['pt',['xAxisTitle'],['P_{T} / GeV']],['eta',['xAxisTitle'],['#eta']],['phi',['xAxisTitle'],['#phi']],['pileup',['xAxisTitle'],['# of Reco Vertices']]]
259 
260 yAxisStuff =cms.PSet(
261  yScale = cms.string('linear'), # linear/log
262  minY_linear = cms.double(0.),
263  maxY_linear = cms.double(1.6),
264  minY_log = cms.double(0.001),
265  maxY_log = cms.double(1.8),
266  yAxisTitle = cms.string('#varepsilon'),
267  yAxisTitleOffset = cms.double(1.1),
268  yAxisTitleSize = cms.double(0.05)
269 )
270 yModifiers = [['efficiency',['yScale','yAxisTitle'],['linear','#varepsilon']],['fakeRate',['yScale','yAxisTitle'],['log','Fake rate']]]
271 
272 legStuff = cms.PSet(
273  posX = cms.double(0.50),
274  posY = cms.double(0.72),
275  sizeX = cms.double(0.39),
276  sizeY = cms.double(0.17),
277  header = cms.string(''),
278  option = cms.string('brNDC'),
279  borderSize = cms.int32(0),
280  fillColor = cms.int32(0)
281 )
282 legModifiers = [['efficiency',['posY','sizeY'],[0.72,0.17]],['efficiency_overlay',['posY','sizeY'],[0.66,0.23]]]
283 
284 drawOptStuff = cms.PSet(
285  markerColor = cms.int32(1),
286  markerSize = cms.double(1.),
287  markerStyle = cms.int32(20),
288  lineColor = cms.int32(1),
289  lineStyle = cms.int32(1),
290  lineWidth = cms.int32(2),
291  drawOption = cms.string('ex0'),
292  drawOptionLegend = cms.string('p')
293 )
294 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]]]
295 
296 standardDrawingStuff = cms.PSet(
297  canvasSizeX = cms.int32(640),
298  canvasSizeY = cms.int32(640),
299  indOutputFileName = cms.string('#PLOT#.png'),
300  xAxes = Utils.SpawnPSet(xModifiers,xAxisStuff),
301  yAxes = Utils.SpawnPSet(yModifiers,yAxisStuff),
302  legends = Utils.SpawnPSet(legModifiers,legStuff),
303  labels = cms.PSet(
304  pt = cms.PSet(
305  posX = cms.double(0.19),
306  posY = cms.double(0.77),
307  sizeX = cms.double(0.12),
308  sizeY = cms.double(0.04),
309  option = cms.string('brNDC'),
310  borderSize = cms.int32(0),
311  fillColor = cms.int32(0),
312  textColor = cms.int32(1),
313  textSize = cms.double(0.04),
314  textAlign = cms.int32(22),
315  text = cms.vstring('P_{T} > 5 GeV') #vstring not supported by SpawnPSet
316  ),
317  eta = cms.PSet(
318  posX = cms.double(0.19),
319  posY = cms.double(0.83),
320  sizeX = cms.double(0.12),
321  sizeY = cms.double(0.04),
322  option = cms.string('brNDC'),
323  borderSize = cms.int32(0),
324  fillColor = cms.int32(0),
325  textColor = cms.int32(1),
326  textSize = cms.double(0.04),
327  textAlign = cms.int32(22),
328  text = cms.vstring('-2.5 < #eta < +2.5')
329  )
330  ),
331  drawOptionSets = cms.PSet(
332  efficiency = cms.PSet(
333  test = cms.PSet(
334  markerColor = cms.int32(4),
335  markerSize = cms.double(1.),
336  markerStyle = cms.int32(20),
337  lineColor = cms.int32(1),
338  lineStyle = cms.int32(1),
339  lineWidth = cms.int32(1),
340  drawOption = cms.string('ep'),
341  drawOptionLegend = cms.string('p')
342  ),
343  reference = cms.PSet(
344  lineColor = cms.int32(1),
345  lineStyle = cms.int32(1),
346  lineWidth = cms.int32(1),
347  fillColor = cms.int32(41),
348  drawOption = cms.string('eBand'),
349  drawOptionLegend = cms.string('l')
350  )
351  )
352  ),
353  drawOptionEntries = Utils.SpawnPSet(drawOptModifiers,drawOptStuff)
354 )
355 
356 standardCompareTestAndReference = cms.PSet(
357  processes = cms.PSet(
358  test = cms.PSet(
359  dqmDirectory = cms.string('test'),
360  legendEntry = cms.string('no test label'),
361  type = cms.string('smMC') # Data/smMC/bsmMC/smSumMC
362  ),
363  reference = cms.PSet(
364  dqmDirectory = cms.string('reference'),
365  legendEntry = cms.string('no ref label'),
366  type = cms.string('smMC') # Data/smMC/bsmMC/smSumMC
367  )
368  ),
369 )
370 
371 
372 ##################################################
373 #
374 # The plotting of HPS Efficiencies
375 #
376 ##################################################
377 ## plotHPSEfficiencies = cms.EDAnalyzer("TauDQMHistPlotter",
378 ## standardDrawingStuff,
379 ## standardCompareTestAndReference,
380 ## drawJobs = Utils.SpawnDrawJobs(RunHPSValidation, plotPset),
381 ## outputFilePath = cms.string('./hpsPFTauProducer/'),
382 ## PrintToFile = cms.bool(True)
383 ## )
384 ## #clone for DQM
385 ## plotHPSEfficiencies2 = plotHPSEfficiencies.clone()
386 
387 
388 ##################################################
389 #
390 # The plotting of all the Shrinking cone leading pion efficiencies
391 #
392 ##################################################
393 ## plotPFTauHighEfficiencyEfficienciesLeadingPion = cms.EDAnalyzer("TauDQMHistPlotter",
394 ## standardDrawingStuff,
395 ## standardCompareTestAndReference,
396 ## drawJobs = Utils.SpawnDrawJobs(PFTausHighEfficiencyLeadingPionBothProngs, plotPset),
397 ## outputFilePath = cms.string('./shrinkingConePFTauProducerLeadingPion/'),
398 ## PrintToFile = cms.bool(True)
399 ## )
400 ## #clone for DQM
401 ## plotPFTauHighEfficiencyEfficienciesLeadingPion2 = plotPFTauHighEfficiencyEfficienciesLeadingPion.clone()
402 
403 
404 ## plotTauValidation = cms.Sequence(
405 ## plotPFTauHighEfficiencyEfficienciesLeadingPion
406 ## +plotHPSEfficiencies
407 ## )
408 
409 ## plotTauValidation2 = cms.Sequence(
410 ## plotPFTauHighEfficiencyEfficienciesLeadingPion2
411 ## +plotHPSEfficiencies2
412 ## )
413 
414 
415 ## loadAndPlotTauValidation = cms.Sequence(
416 ## loadTau
417 ## +plotTauValidation
418 ## )
419 
420 """
421 
422 UTILITIES
423 
424 """
425 
427  """ Helper class that applies a given function to all modules
428  in a sequence """
429  def __init__(self,function):
430  self.functor = function
431  def enter(self, module):
432  self.functor(module)
433  def leave(self, module):
434  pass
435 
437  input = re.sub('fixedConePFTauProducer', 'pfRecoTauProducer', input)
438  #fixedDiscriminationRegex = re.compile('fixedConePFTauDiscrimination( \w* )')
439  fixedDiscriminationRegex = re.compile('fixedConePFTauDiscrimination(\w*)')
440  input = fixedDiscriminationRegex.sub(r'pfRecoTauDiscrimination\1', input)
441  input = re.sub('shrinkingConePFTauProducer', 'pfRecoTauProducerHighEfficiency', input)
442  shrinkingDiscriminationRegex = re.compile('shrinkingConePFTauDiscrimination(\w*)')
443  input = shrinkingDiscriminationRegex.sub(r'pfRecoTauDiscrimination\1HighEfficiency', input)
444  return input
445 
446 
448  """ Converts a draw job defined to compare 31X named PFTau validtion efficiencies
449  to comapre a 31X to a 22X named validation """
450  # get the list of drawjobs { name : copyOfPSet }
451  if not hasattr(input, "drawJobs"):
452  return
453  myDrawJobs = input.drawJobs.parameters_()
454  for drawJobName, drawJobData in myDrawJobs.iteritems():
455  print drawJobData
456  if not drawJobData.plots.pythonTypeName() == "cms.PSet":
457  continue
458  pSetToInsert = cms.PSet(
459  standardEfficiencyParameters,
460  plots = cms.VPSet(
461  # test plot w/ modern names
462  cms.PSet(
463  dqmMonitorElements = drawJobData.plots.dqmMonitorElements,
464  process = cms.string('test'),
465  drawOptionEntry = cms.string('eff_overlay01'),
466  legendEntry = cms.string(input.processes.test.legendEntry.value())
467  ),
468  # ref plot w/ vintage name
469  cms.PSet(
470  # translate the name
471  dqmMonitorElements = cms.vstring(TranslateToLegacyProdNames(drawJobData.plots.dqmMonitorElements.value()[0])),
472  process = cms.string('reference'),
473  drawOptionEntry = cms.string('eff_overlay02'),
474  legendEntry = cms.string(input.processes.reference.legendEntry.value())
475  )
476  )
477  )
478  input.drawJobs.__setattr__(drawJobName, pSetToInsert)
479 
480 def MakeLabeler(TestLabel, ReferenceLabel):
481  def labeler(module):
482  if hasattr(module, 'processes'):
483  if module.processes.hasParameter(['test', 'legendEntry']) and module.processes.hasParameter([ 'reference', 'legendEntry']):
484  module.processes.test.legendEntry = TestLabel
485  module.processes.reference.legendEntry = ReferenceLabel
486  print "Set test label to %s and reference label to %s for plot producer %s" % (TestLabel, ReferenceLabel, module.label())
487  else:
488  print "ERROR in RecoTauValidation_cfi::MakeLabeler - trying to set test/reference label but %s does not have processes.(test/reference).legendEntry parameters!" % module.label()
489  return labeler
490 
491 def SetYmodulesToLog(matchingNames = []):
492  ''' set all modules whose name contains one of the matching names to log y scale'''
493  def yLogger(module):
494  ''' set a module to use log scaling in the yAxis'''
495  if hasattr(module, 'drawJobs'):
496  print "EK DEBUG"
497  drawJobParamGetter = lambda subName : getattr(module.drawJobs, subName)
498  #for subModule in [getattr(module.drawJobs, subModuleName) for subModuleName in dir(module.drawJobs)]:
499  attrNames = dir(module.drawJobs)
500  for subModuleName, subModule in zip(attrNames, map(drawJobParamGetter, attrNames)):
501  matchedNames = [name for name in matchingNames if subModuleName.find( name) > -1] # matching sub strings
502  if len(matchingNames) == 0:
503  matchedNames = ['take','everything','and','dont','bother']
504  if hasattr(subModule, "yAxis") and len(matchedNames):
505  print "Setting drawJob: ", subModuleName, " to log scale."
506  subModule.yAxis = cms.string('fakeRate') #'fakeRate' configuration specifies the log scaling
507  if len(matchingNames) == 0:
508  module.yAxes.efficiency.maxY_log = 40
509  module.yAxes.fakeRate.maxY_log = 40
510  return yLogger
511 
512 
513 def SetBaseDirectory(Directory):
514  def BaseDirectorizer(module):
515  newPath = Directory
516  #if module.hasParameter("outputFilePath"):
517  if hasattr(module, "outputFilePath"):
518  oldPath = module.outputFilePath.value()
519  newPath = os.path.join(newPath, oldPath)
520  if not os.path.exists(newPath):
521  os.makedirs(newPath)
522  print newPath
523  module.outputFilePath = cms.string("%s" % newPath)
524  return BaseDirectorizer
525 
527  if hasattr(module, 'drawJobs'):
528  #get draw job parameter names
529  drawJobs = module.drawJobs.parameterNames_()
530  for drawJob in drawJobs:
531  if drawJob != "TauIdEffStepByStep":
532  module.drawJobs.__delattr__(drawJob)
533  print "Removing comparison plot", drawJob
534 
535 def SetPlotDirectory(myPlottingSequence, directory):
536  myFunctor = ApplyFunctionToSequence(SetBaseDirectory(directory))
537  myPlottingSequence.visit(myFunctor)
538 
539 def SetTestAndReferenceLabels(myPlottingSequence, TestLabel, ReferenceLabel):
540  myFunctor = ApplyFunctionToSequence(MakeLabeler(TestLabel, ReferenceLabel))
541  myPlottingSequence.visit(myFunctor)
542 
543 def SetCompareToLegacyProductNames(myPlottingSequence):
544  myFunctor = ApplyFunctionToSequence(ConvertDrawJobToLegacyCompare)
545  myPlottingSequence.visit(myFunctor)
546 
547 def SetTestFileToPlot(myProcess, FileLoc):
548  myProcess.loadTau.test.inputFileNames = cms.vstring(FileLoc)
549 
550 def SetReferenceFileToPlot(myProcess, FileLoc):
551  if FileLoc == None:
552  del myProcess.loadTau.reference
553  else:
554  myProcess.loadTau.reference.inputFileNames = cms.vstring(FileLoc)
555 
556 def SetLogScale(myPlottingSequence):
558  myPlottingSequence.visit(myFunctor)
559 
560 def SetSmartLogScale(myPlottingSequence):
561  myFunctor = ApplyFunctionToSequence(SetYmodulesToLog(['Electron', 'Muon', 'Isolation', 'TaNC']))
562  myPlottingSequence.visit(myFunctor)
563 
564 def SetPlotOnlyStepByStep(myPlottingSequence):
565  myFunctor = ApplyFunctionToSequence(RemoveComparisonPlotCommands)
566  myPlottingSequence.visit(myFunctor)
567 
568 def SetValidationExtention(module, extension):
569  module.ExtensionName = module.ExtensionName.value()+extension
570 
571 def setBinning(module,pset):
572  if module._TypedParameterizable__type == 'TauTagValidation':
573  module.histoSettings = pset
574 
575 def setTrigger(module,pset):
576  if hasattr(module,'_TypedParameterizable__type') and module._TypedParameterizable__type == 'TauTagValidation':
577  setattr(module,'turnOnTrigger',cms.bool(True)) #Turns on trigger (in case is off)
578  for item in pset.parameters_().items():
579  setattr(module.GenericTriggerSelection,item[0],item[1])
dbl *** dir
Definition: mlp_gen.cc:35