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