CMS 3D CMS Logo

RecoTauValidation_cfi.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import FWCore.ParameterSet.Config as cms
3 import Validation.RecoTau.ValidationUtils as Utils
4 import copy
5 import re
6 import os
7 
8 import RecoTauTag.Configuration.HPSPFTaus_cff as RecoModules #Working point indices are extracted from here
9 
10 #from Validation.RecoTau.ValidationOptions_cff import *
11 
12 
13 """
14 import six
15 
16  RecoTauValidation_cfi.py
17 
18  Contains the standard tau validation parameters. It is organized into
19  the following sections.
20 
21  DENOMINATOR
22 
23  Set common kinematic cuts (pt > 5 and eta < 2.5) on the denominator source.
24  Note that the denominator depends on the type of test (signal/background/e etc)
25 
26  The denominator kinematic cutter requires that
27 
28  HISTOGRAMS
29 
30  Produce numerator and denominator histgorams used to produce
31  tau efficiency plots
32 
33  Provides sequence:
34  TauValNumeratorAndDenominator
35  Requires:
36  tauValSelectedDenominator (filtered GenJet collection)
37 
38  EFFICIENCY
39 
40  Using numerator and denominators, calculate and store
41  the efficiency curves
42 
43  Provides sequence:
44  TauEfficiencies
45  Requires:
46  TauValNumeratorAndDenominator
47 
48  PLOTTING
49 
50  Plot curves calculated in efficiency, in both an overlay mode
51  showing overall performance for a release, and the indvidual
52  discriminator efficiency compared to a given release
53 
54  Provides sequence:
55  loadTau
56  plotTauValidation
57  loadAndPlotTauValidation
58 
59  Requires:
60  TauEfficiencies, external root file to compare to
61 
62  Plotting must be executed in a separate cmsRun job!
63 
64  UTILITIES
65 
66  Various scripts to automate things...
67 
68 
69 """
70 
71 """
72 
73 DENOMINATOR
74 
75 """
76 
77 kinematicSelectedTauValDenominatorCut = cms.string('pt > 5. && abs(eta) < 2.5')
78 denominator = cms.InputTag("kinematicSelectedTauValDenominator")
79 
80 """
81 
82 HISTOGRAMS
83 
84  Plot the pt/eta/energy/phi spectrum of PFTaus that pass
85  a series of PFTauDiscriminator cuts.
86 
87  These will be used as the numerator/denominators of the
88  efficiency calculations
89 """
90 
91 #Helper process to make future cloning easier
92 proc = cms.Process('helper')
93 
94 StandardMatchingParameters = cms.PSet(
95  DataType = cms.string('Leptons'),
96  MatchDeltaR_Leptons = cms.double(0.15),
97  MatchDeltaR_Jets = cms.double(0.3),
98  SaveOutputHistograms = cms.bool(False), #TRUE FOR TEST ONLY
99  #RefCollection = cms.InputTag("TauGenJetProducer","selectedGenTauDecaysToHadronsPt5Cumulative"),
100  RefCollection = denominator,
101  TauPtCut = cms.double(0.), #almost deprecated, since recoCuts provides more flexibility
102  recoCuts = cms.string(''), #filter reconstructed candidates. leave this empty to select all. or use sth like: pt > 20 & abs(eta) < 2.3
103  genCuts = cms.string(''), #filter generated candidates. leave this empty to select all. or use sth like: pt > 20 & abs(eta) < 2.3
104  chainCuts = cms.bool(False) #Decide whether to chain discriminators or not
105 )
106 
107 GenericTriggerSelectionParameters = cms.PSet(
108  andOr = cms.bool( False ),#specifies the logical combination of the single filters' (L1, HLT and DCS) decisions at top level (True=OR)
109  dbLabel = cms.string("PFTauDQMTrigger"),#specifies the label under which the DB payload is available from the ESSource or Global Tag
110  andOrHlt = cms.bool(True),#specifies the logical combination of the single HLT paths' decisions (True=OR)
111  hltInputTag = cms.InputTag("TriggerResults::HLT"),
112  #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
113  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)
114  errorReplyHlt = cms.bool(False),#specifies the desired return value of the HLT filter and the single HLT path filter in case of certain errors
115  verbosityLevel = cms.uint32(0) #0: complete silence (default), needed for T0 processing;
116 )
117 
118 from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer
119 proc.templateAnalyzer = DQMEDAnalyzer(
120  "TauTagValidation",
121  StandardMatchingParameters,
122  GenericTriggerSelection = GenericTriggerSelectionParameters,
123  ExtensionName = cms.string(""),
124  TauProducer = cms.InputTag(''),
125  discriminators = cms.VPSet(
126  )
127 )
128 
129 
130 proc.RunHPSValidation = proc.templateAnalyzer.clone()
131 
132 #for fast sim we need to ignore the HLT TriggerResults
133 from Configuration.Eras.Modifier_fastSim_cff import fastSim
134 fastSim.toModify(
135  proc.RunHPSValidation,
136  hltInputTag = cms.InputTag(""),
137  GenericTriggerSelection=dict(hltInputTag = cms.InputTag(""))
138 )
139 
140 proc.RunHPSValidation.ExtensionName = ""
141 #RunHPSValidation.TauPtCut = cms.double(15.)
142 proc.RunHPSValidation.TauProducer = cms.InputTag('hpsPFTauProducer')
143 
144 def tauIDMVAinputs(module, wp):
145  return {"container" : cms.string(module), "workingPointIndex" : cms.int32(-1 if wp=="raw" else getattr(RecoModules, module).workingPoints.index(wp))}
146 def tauIDbasicinputs(module, wp):
147  index = RecoModules.getBasicTauDiscriminatorRawIndex(getattr(RecoModules, module), wp, True)
148  if index==None:
149  index = RecoModules.getBasicTauDiscriminatorWPIndex(getattr(RecoModules, module), wp, True)
150  else:
151  index = -index - 1 #use negative indices for raw values
152  if index!=None:
153  return {"container" : cms.string(module), "workingPointIndex" : cms.int32(index)}
154  print ("Basic Tau Discriminator <{}> <{}> for Validation configuration not found!".format(module, wp))
155  raise Exception
156 
157 proc.RunHPSValidation.discriminators = cms.VPSet(
158  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByDecayModeFinding"),plotStep = cms.bool(True),selectionCut = cms.double(0.5),container = cms.string("")),
159  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByDecayModeFindingNewDMs"),plotStep = cms.bool(True),selectionCut = cms.double(0.5),container = cms.string("")),
160  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByDecayModeFindingOldDMs"),plotStep = cms.bool(True),selectionCut = cms.double(0.5),container = cms.string("")),
161  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr3Hits"),plotStep = cms.bool(True),container = cms.string("hpsPFTauBasicDiscriminators"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByLooseCombinedIsolationDBSumPtCorr3Hits")),
162  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumCombinedIsolationDBSumPtCorr3Hits"),plotStep = cms.bool(True),container = cms.string("hpsPFTauBasicDiscriminators"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByMediumCombinedIsolationDBSumPtCorr3Hits")),
163  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr3Hits"),plotStep = cms.bool(True),container = cms.string("hpsPFTauBasicDiscriminators"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByTightCombinedIsolationDBSumPtCorr3Hits")),
164  #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
165  #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumElectronRejection"),plotStep = cms.bool(True),selectionCut = cms.double(0.5),container = cms.string("")),
166  #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
167  #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5VLooseElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
168  #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5LooseElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
169  #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5MediumElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
170  #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5TightElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
171  #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5VTightElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
172  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseMuonRejection3"),plotStep = cms.bool(True),container = cms.string("hpsPFTauDiscriminationByMuonRejection3"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByLooseMuonRejection3")),
173  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightMuonRejection3"),plotStep = cms.bool(True),container = cms.string("hpsPFTauDiscriminationByMuonRejection3"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByTightMuonRejection3")),
174  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA6VLooseElectronRejection"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByMVA6ElectronRejection"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VLoose")),
175  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA6LooseElectronRejection"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByMVA6ElectronRejection"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Loose")),
176  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA6MediumElectronRejection"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByMVA6ElectronRejection"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Medium")),
177  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA6TightElectronRejection"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByMVA6ElectronRejection"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Tight")),
178  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA6VTightElectronRejection"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByMVA6ElectronRejection"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VTight")),
179  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBoldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VLoose")),
180  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseIsolationMVArun2v1DBoldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Loose")),
181  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumIsolationMVArun2v1DBoldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Medium")),
182  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightIsolationMVArun2v1DBoldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Tight")),
183  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVTightIsolationMVArun2v1DBoldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VTight")),
184  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVVTightIsolationMVArun2v1DBoldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VVTight")),
185  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBnewDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VLoose")),
186  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseIsolationMVArun2v1DBnewDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Loose")),
187  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumIsolationMVArun2v1DBnewDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Medium")),
188  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightIsolationMVArun2v1DBnewDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Tight")),
189  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVTightIsolationMVArun2v1DBnewDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VTight")),
190  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVVTightIsolationMVArun2v1DBnewDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VVTight")),
191  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr3HitsdR03"),plotStep = cms.bool(True),container = cms.string("hpsPFTauBasicDiscriminatorsdR03"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByLooseCombinedIsolationDBSumPtCorr3HitsdR03")),
192  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumCombinedIsolationDBSumPtCorr3HitsdR03"),plotStep = cms.bool(True),container = cms.string("hpsPFTauBasicDiscriminatorsdR03"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByMediumCombinedIsolationDBSumPtCorr3HitsdR03")),
193  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr3HitsdR03"),plotStep = cms.bool(True),container = cms.string("hpsPFTauBasicDiscriminatorsdR03"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByTightCombinedIsolationDBSumPtCorr3HitsdR03")),
194  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBdR03oldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VLoose")),
195  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseIsolationMVArun2v1DBdR03oldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Loose")),
196  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumIsolationMVArun2v1DBdR03oldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Medium")),
197  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightIsolationMVArun2v1DBdR03oldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Tight")),
198  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVTightIsolationMVArun2v1DBdR03oldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VTight")),
199  cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVVTightIsolationMVArun2v1DBdR03oldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VVTight")),
200 )
201 
202 proc.TauValNumeratorAndDenominator = cms.Sequence(
203  proc.RunHPSValidation
204  )
205 
206 """
207 
208 EFFICIENCY
209 
210  Tau efficiency calculations
211 
212  Define the Efficiency curves to produce. Each
213  efficiency producer takes the numberator and denominator
214  histograms and the dependent variables.
215 """
216 
217 plotPset = Utils.SetPlotSequence(proc.TauValNumeratorAndDenominator)
218 from DQMServices.Core.DQMEDHarvester import DQMEDHarvester
219 proc.efficiencies = DQMEDHarvester(
220  "TauDQMHistEffProducer",
221  plots = plotPset
222  )
223 
224 
225 
230 
231 proc.normalizePlots = cms.EDAnalyzer(
232  "DQMHistNormalizer",
233  plotNamesToNormalize = cms.vstring('*_pTRatio_*','*_Size_*','*_SumPt_*','*_dRTauRefJet*'),
234  reference = cms.string('*_pTRatio_allHadronic')
235  )
236 
237 proc.TauEfficiencies = cms.Sequence(
238  proc.efficiencies*
239  proc.normalizePlots
240  )
241 
242 """
243 
244 PLOTTING
245 
246  loadTau: load two separate TauVal root files into the DQM
247  so the plotter can access them
248 
249 """
250 
251 loadTau = DQMEDAnalyzer("TauDQMFileLoader",
252  test = cms.PSet(
253  #inputFileNames = cms.vstring('/afs/cern.ch/user/f/friis/scratch0/MyValidationArea/310pre6NewTags/src/Validation/RecoTau/test/CMSSW_3_1_0_pre6_ZTT_0505Fixes.root'),
254  inputFileNames = cms.vstring('/opt/sbg/cms/ui4_data1/dbodin/CMSSW_3_5_1/src/TauID/QCD_recoFiles/TauVal_CMSSW_3_6_0_QCD.root'),
255  scaleFactor = cms.double(1.),
256  dqmDirectory_store = cms.string('test')
257  ),
258  reference = cms.PSet(
259  inputFileNames = cms.vstring('/opt/sbg/cms/ui4_data1/dbodin/CMSSW_3_5_1/src/TauID/QCD_recoFiles/TauVal_CMSSW_3_6_0_QCD.root'),
260  scaleFactor = cms.double(1.),
261  dqmDirectory_store = cms.string('reference')
262  )
263 )
264 
265 # Lots of junk to define the plot style
266 
267 # standard drawing stuff
268 xAxisStuff = cms.PSet(
269  xAxisTitle = cms.string('P_{T} / GeV'),
270  xAxisTitleOffset = cms.double(0.9),
271  xAxisTitleSize = cms.double(0.05)
272 )
273 xModifiers = [['pt',['xAxisTitle'],['P_{T} / GeV']],['eta',['xAxisTitle'],['#eta']],['phi',['xAxisTitle'],['#phi']],['pileup',['xAxisTitle'],['# of Reco Vertices']]]
274 
275 yAxisStuff =cms.PSet(
276  yScale = cms.string('linear'), # linear/log
277  minY_linear = cms.double(0.),
278  maxY_linear = cms.double(1.6),
279  minY_log = cms.double(0.001),
280  maxY_log = cms.double(1.8),
281  yAxisTitle = cms.string('#varepsilon'),
282  yAxisTitleOffset = cms.double(1.1),
283  yAxisTitleSize = cms.double(0.05)
284 )
285 yModifiers = [['efficiency',['yScale','yAxisTitle'],['linear','#varepsilon']],['fakeRate',['yScale','yAxisTitle'],['log','Fake rate']]]
286 
287 legStuff = cms.PSet(
288  posX = cms.double(0.50),
289  posY = cms.double(0.72),
290  sizeX = cms.double(0.39),
291  sizeY = cms.double(0.17),
292  header = cms.string(''),
293  option = cms.string('brNDC'),
294  borderSize = cms.int32(0),
295  fillColor = cms.int32(0)
296 )
297 legModifiers = [['efficiency',['posY','sizeY'],[0.72,0.17]],['efficiency_overlay',['posY','sizeY'],[0.66,0.23]]]
298 
299 drawOptStuff = cms.PSet(
300  markerColor = cms.int32(1),
301  markerSize = cms.double(1.),
302  markerStyle = cms.int32(20),
303  lineColor = cms.int32(1),
304  lineStyle = cms.int32(1),
305  lineWidth = cms.int32(2),
306  drawOption = cms.string('ex0'),
307  drawOptionLegend = cms.string('p')
308 )
309 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]]]
310 
311 standardDrawingStuff = cms.PSet(
312  canvasSizeX = cms.int32(640),
313  canvasSizeY = cms.int32(640),
314  indOutputFileName = cms.string('#PLOT#.png'),
315  xAxes = Utils.SpawnPSet(xModifiers,xAxisStuff),
316  yAxes = Utils.SpawnPSet(yModifiers,yAxisStuff),
317  legends = Utils.SpawnPSet(legModifiers,legStuff),
318  labels = cms.PSet(
319  pt = cms.PSet(
320  posX = cms.double(0.19),
321  posY = cms.double(0.77),
322  sizeX = cms.double(0.12),
323  sizeY = cms.double(0.04),
324  option = cms.string('brNDC'),
325  borderSize = cms.int32(0),
326  fillColor = cms.int32(0),
327  textColor = cms.int32(1),
328  textSize = cms.double(0.04),
329  textAlign = cms.int32(22),
330  text = cms.vstring('P_{T} > 5 GeV') #vstring not supported by SpawnPSet
331  ),
332  eta = cms.PSet(
333  posX = cms.double(0.19),
334  posY = cms.double(0.83),
335  sizeX = cms.double(0.12),
336  sizeY = cms.double(0.04),
337  option = cms.string('brNDC'),
338  borderSize = cms.int32(0),
339  fillColor = cms.int32(0),
340  textColor = cms.int32(1),
341  textSize = cms.double(0.04),
342  textAlign = cms.int32(22),
343  text = cms.vstring('-2.5 < #eta < +2.5')
344  )
345  ),
346  drawOptionSets = cms.PSet(
347  efficiency = cms.PSet(
348  test = cms.PSet(
349  markerColor = cms.int32(4),
350  markerSize = cms.double(1.),
351  markerStyle = cms.int32(20),
352  lineColor = cms.int32(1),
353  lineStyle = cms.int32(1),
354  lineWidth = cms.int32(1),
355  drawOption = cms.string('ep'),
356  drawOptionLegend = cms.string('p')
357  ),
358  reference = cms.PSet(
359  lineColor = cms.int32(1),
360  lineStyle = cms.int32(1),
361  lineWidth = cms.int32(1),
362  fillColor = cms.int32(41),
363  drawOption = cms.string('eBand'),
364  drawOptionLegend = cms.string('l')
365  )
366  )
367  ),
368  drawOptionEntries = Utils.SpawnPSet(drawOptModifiers,drawOptStuff)
369 )
370 
371 standardCompareTestAndReference = cms.PSet(
372  processes = cms.PSet(
373  test = cms.PSet(
374  dqmDirectory = cms.string('test'),
375  legendEntry = cms.string('no test label'),
376  type = cms.string('smMC') # Data/smMC/bsmMC/smSumMC
377  ),
378  reference = cms.PSet(
379  dqmDirectory = cms.string('reference'),
380  legendEntry = cms.string('no ref label'),
381  type = cms.string('smMC') # Data/smMC/bsmMC/smSumMC
382  )
383  ),
384 )
385 
386 
387 
401 
402 
403 
417 
418 
419 
423 
424 
428 
429 
430 
434 
435 """
436 
437 UTILITIES
438 
439 """
440 
442  """ Helper class that applies a given function to all modules
443  in a sequence """
444  def __init__(self,function):
445  self.functor = function
446  def enter(self, module):
447  self.functor(module)
448  def leave(self, module):
449  pass
450 
452  input = re.sub('fixedConePFTauProducer', 'pfRecoTauProducer', input)
453  #fixedDiscriminationRegex = re.compile('fixedConePFTauDiscrimination( \w* )')
454  fixedDiscriminationRegex = re.compile('fixedConePFTauDiscrimination(\w*)')
455  input = fixedDiscriminationRegex.sub(r'pfRecoTauDiscrimination\1', input)
456  input = re.sub('shrinkingConePFTauProducer', 'pfRecoTauProducerHighEfficiency', input)
457  shrinkingDiscriminationRegex = re.compile('shrinkingConePFTauDiscrimination(\w*)')
458  input = shrinkingDiscriminationRegex.sub(r'pfRecoTauDiscrimination\1HighEfficiency', input)
459  return input
460 
461 
463  """ Converts a draw job defined to compare 31X named PFTau validtion efficiencies
464  to comapre a 31X to a 22X named validation """
465  # get the list of drawjobs { name : copyOfPSet }
466  if not hasattr(input, "drawJobs"):
467  return
468  myDrawJobs = input.drawJobs.parameters_()
469  for drawJobName, drawJobData in six.iteritems(myDrawJobs):
470  print(drawJobData)
471  if not drawJobData.plots.pythonTypeName() == "cms.PSet":
472  continue
473  pSetToInsert = cms.PSet(
474  standardEfficiencyParameters,
475  plots = cms.VPSet(
476  # test plot w/ modern names
477  cms.PSet(
478  dqmMonitorElements = drawJobData.plots.dqmMonitorElements,
479  process = cms.string('test'),
480  drawOptionEntry = cms.string('eff_overlay01'),
481  legendEntry = cms.string(input.processes.test.legendEntry.value())
482  ),
483  # ref plot w/ vintage name
484  cms.PSet(
485  # translate the name
486  dqmMonitorElements = cms.vstring(TranslateToLegacyProdNames(drawJobData.plots.dqmMonitorElements.value()[0])),
487  process = cms.string('reference'),
488  drawOptionEntry = cms.string('eff_overlay02'),
489  legendEntry = cms.string(input.processes.reference.legendEntry.value())
490  )
491  )
492  )
493  input.drawJobs.__setattr__(drawJobName, pSetToInsert)
494 
495 def MakeLabeler(TestLabel, ReferenceLabel):
496  def labeler(module):
497  if hasattr(module, 'processes'):
498  if module.processes.hasParameter(['test', 'legendEntry']) and module.processes.hasParameter([ 'reference', 'legendEntry']):
499  module.processes.test.legendEntry = TestLabel
500  module.processes.reference.legendEntry = ReferenceLabel
501  print("Set test label to %s and reference label to %s for plot producer %s" % (TestLabel, ReferenceLabel, module.label()))
502  else:
503  print("ERROR in RecoTauValidation_cfi::MakeLabeler - trying to set test/reference label but %s does not have processes.(test/reference).legendEntry parameters!" % module.label())
504  return labeler
505 
506 def SetYmodulesToLog(matchingNames = []):
507  ''' set all modules whose name contains one of the matching names to log y scale'''
508  def yLogger(module):
509  ''' set a module to use log scaling in the yAxis'''
510  if hasattr(module, 'drawJobs'):
511  print("EK DEBUG")
512  drawJobParamGetter = lambda subName : getattr(module.drawJobs, subName)
513  #for subModule in [getattr(module.drawJobs, subModuleName) for subModuleName in dir(module.drawJobs)]:
514  attrNames = dir(module.drawJobs)
515  for subModuleName, subModule in zip(attrNames, map(drawJobParamGetter, attrNames)):
516  matchedNames = [name for name in matchingNames if subModuleName.find( name) > -1] # matching sub strings
517  if len(matchingNames) == 0:
518  matchedNames = ['take','everything','and','dont','bother']
519  if hasattr(subModule, "yAxis") and len(matchedNames):
520  print("Setting drawJob: ", subModuleName, " to log scale.")
521  subModule.yAxis = cms.string('fakeRate') #'fakeRate' configuration specifies the log scaling
522  if len(matchingNames) == 0:
523  module.yAxes.efficiency.maxY_log = 40
524  module.yAxes.fakeRate.maxY_log = 40
525  return yLogger
526 
527 
528 def SetBaseDirectory(Directory):
529  def BaseDirectorizer(module):
530  newPath = Directory
531  #if module.hasParameter("outputFilePath"):
532  if hasattr(module, "outputFilePath"):
533  oldPath = module.outputFilePath.value()
534  newPath = os.path.join(newPath, oldPath)
535  if not os.path.exists(newPath):
536  os.makedirs(newPath)
537  print(newPath)
538  module.outputFilePath = cms.string("%s" % newPath)
539  return BaseDirectorizer
540 
542  if hasattr(module, 'drawJobs'):
543  #get draw job parameter names
544  drawJobs = module.drawJobs.parameterNames_()
545  for drawJob in drawJobs:
546  if drawJob != "TauIdEffStepByStep":
547  module.drawJobs.__delattr__(drawJob)
548  print("Removing comparison plot", drawJob)
549 
550 def SetPlotDirectory(myPlottingSequence, directory):
551  myFunctor = ApplyFunctionToSequence(SetBaseDirectory(directory))
552  myPlottingSequence.visit(myFunctor)
553 
554 def SetTestAndReferenceLabels(myPlottingSequence, TestLabel, ReferenceLabel):
555  myFunctor = ApplyFunctionToSequence(MakeLabeler(TestLabel, ReferenceLabel))
556  myPlottingSequence.visit(myFunctor)
557 
558 def SetCompareToLegacyProductNames(myPlottingSequence):
559  myFunctor = ApplyFunctionToSequence(ConvertDrawJobToLegacyCompare)
560  myPlottingSequence.visit(myFunctor)
561 
562 def SetTestFileToPlot(myProcess, FileLoc):
563  myProcess.loadTau.test.inputFileNames = cms.vstring(FileLoc)
564 
565 def SetReferenceFileToPlot(myProcess, FileLoc):
566  if FileLoc == None:
567  del myProcess.loadTau.reference
568  else:
569  myProcess.loadTau.reference.inputFileNames = cms.vstring(FileLoc)
570 
571 def SetLogScale(myPlottingSequence):
573  myPlottingSequence.visit(myFunctor)
574 
575 def SetSmartLogScale(myPlottingSequence):
576  myFunctor = ApplyFunctionToSequence(SetYmodulesToLog(['Electron', 'Muon', 'Isolation', 'TaNC']))
577  myPlottingSequence.visit(myFunctor)
578 
579 def SetPlotOnlyStepByStep(myPlottingSequence):
580  myFunctor = ApplyFunctionToSequence(RemoveComparisonPlotCommands)
581  myPlottingSequence.visit(myFunctor)
582 
583 def SetValidationExtention(module, extension):
584  module.ExtensionName = module.ExtensionName.value()+extension
585 
586 def setBinning(module,pset):
587  if module._TypedParameterizable__type == 'TauTagValidation':
588  module.histoSettings = pset
589 
590 def setTrigger(module,pset):
591  if hasattr(module,'_TypedParameterizable__type') and module._TypedParameterizable__type == 'TauTagValidation':
592  setattr(module,'turnOnTrigger',cms.bool(True)) #Turns on trigger (in case is off)
593  for item in pset.parameters_().items():
594  setattr(module.GenericTriggerSelection,item[0],item[1])
RecoTauValidation_cfi.SetCompareToLegacyProductNames
def SetCompareToLegacyProductNames(myPlottingSequence)
Definition: RecoTauValidation_cfi.py:558
HPSPFTaus_cff
RecoTauValidation_cfi.TranslateToLegacyProdNames
def TranslateToLegacyProdNames(input)
Definition: RecoTauValidation_cfi.py:451
RecoTauValidation_cfi.setBinning
def setBinning(module, pset)
Definition: RecoTauValidation_cfi.py:586
RecoTauValidation_cfi.ApplyFunctionToSequence
The plotting of HPS Efficiencies.
Definition: RecoTauValidation_cfi.py:441
mps_monitormerge.items
list items
Definition: mps_monitormerge.py:29
RecoTauValidation_cfi.SetReferenceFileToPlot
def SetReferenceFileToPlot(myProcess, FileLoc)
Definition: RecoTauValidation_cfi.py:565
RecoTauValidation_cfi.tauIDbasicinputs
def tauIDbasicinputs(module, wp)
Definition: RecoTauValidation_cfi.py:146
RecoTauValidation_cfi.setTrigger
def setTrigger(module, pset)
Definition: RecoTauValidation_cfi.py:590
RecoTauValidation_cfi.SetBaseDirectory
def SetBaseDirectory(Directory)
Definition: RecoTauValidation_cfi.py:528
RecoTauValidation_cfi.ApplyFunctionToSequence.enter
def enter(self, module)
Definition: RecoTauValidation_cfi.py:446
RecoTauValidation_cfi.SetSmartLogScale
def SetSmartLogScale(myPlottingSequence)
Definition: RecoTauValidation_cfi.py:575
RecoTauValidation_cfi.SetPlotOnlyStepByStep
def SetPlotOnlyStepByStep(myPlottingSequence)
Definition: RecoTauValidation_cfi.py:579
DQMEDAnalyzer
Definition: DQMEDAnalyzer.py:1
RecoTauValidation_cfi.SetTestFileToPlot
def SetTestFileToPlot(myProcess, FileLoc)
Definition: RecoTauValidation_cfi.py:562
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
RecoTauValidation_cfi.MakeLabeler
def MakeLabeler(TestLabel, ReferenceLabel)
Definition: RecoTauValidation_cfi.py:495
RecoTauValidation_cfi.RemoveComparisonPlotCommands
def RemoveComparisonPlotCommands(module)
Definition: RecoTauValidation_cfi.py:541
ComparisonHelper::zip
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
Definition: L1TStage2CaloLayer1.h:41
DQMEDHarvester
Definition: DQMEDHarvester.py:1
RecoTauValidation_cfi.SetYmodulesToLog
def SetYmodulesToLog(matchingNames=[])
Definition: RecoTauValidation_cfi.py:506
RecoTauValidation_cfi.ApplyFunctionToSequence.__init__
def __init__(self, function)
Definition: RecoTauValidation_cfi.py:444
RecoTauValidation_cfi.SetValidationExtention
def SetValidationExtention(module, extension)
Definition: RecoTauValidation_cfi.py:583
RecoTauValidation_cfi.SetTestAndReferenceLabels
def SetTestAndReferenceLabels(myPlottingSequence, TestLabel, ReferenceLabel)
Definition: RecoTauValidation_cfi.py:554
RecoTauValidation_cfi.SetLogScale
def SetLogScale(myPlottingSequence)
Definition: RecoTauValidation_cfi.py:571
format
RecoTauValidation_cfi.ConvertDrawJobToLegacyCompare
def ConvertDrawJobToLegacyCompare(input)
Definition: RecoTauValidation_cfi.py:462
RecoTauValidation_cfi.tauIDMVAinputs
def tauIDMVAinputs(module, wp)
Definition: RecoTauValidation_cfi.py:144
RecoTauValidation_cfi.ApplyFunctionToSequence.functor
functor
Definition: RecoTauValidation_cfi.py:445
genParticles_cff.map
map
Definition: genParticles_cff.py:11
RecoTauValidation_cfi.SetPlotDirectory
def SetPlotDirectory(myPlottingSequence, directory)
Definition: RecoTauValidation_cfi.py:550
RecoTauValidation_cfi.ApplyFunctionToSequence.leave
def leave(self, module)
Definition: RecoTauValidation_cfi.py:448
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23