1 from __future__
import print_function
2 import FWCore.ParameterSet.Config
as cms
6 """CreatePlotEntry(analyzer, discriminatorLabel)\n
7 Creates a PSet with the informations used by TauDQMHistEffProducer\n
8 where to find the numerator and denominator\n
9 where to put the new plot and how to name it\n
10 which variables control"""
12 producer = analyzer.TauProducer.pythonValue()[1:-1]
13 ext = analyzer.ExtensionName.pythonValue()[1:-1]
14 if discriminatorLabel ==
None:
15 num =
'RecoTauV/%s%s_Matched/%sMatched_vs_#PAR#TauVisible'%(producer,ext,producer)
16 out =
'RecoTauV/%s%s_Matched/PFJetMatchingEff#PAR#'%(producer,ext)
18 num =
'RecoTauV/%s%s_%s/%s_vs_#PAR#TauVisible'%(producer,ext,discriminatorLabel,discriminatorLabel)
19 if discriminatorLabel.find(
'DiscriminationBy') != -1:
20 hname = discriminatorLabel[(discriminatorLabel.find(
'DiscriminationBy')+len(
'DiscriminationBy')):]
22 hname = discriminatorLabel[(discriminatorLabel.find(
'Discrimination')+len(
'Discrimination')):]
23 out =
'RecoTauV/%s%s_%s/%sEff#PAR#'%(producer,ext,discriminatorLabel,hname)
25 den =
'RecoTauV/%s%s_ReferenceCollection/nRef_Taus_vs_#PAR#TauVisible'%(producer,ext)
27 numerator = cms.string(num),
28 denominator = cms.string(den),
29 efficiency = cms.string(out),
30 parameter = cms.vstring(
'pt',
'eta',
'phi',
'pileup'),
31 stepByStep = cms.bool(step)
36 """NameVariable(analyzer, discriminatorLabel)\n
37 returns a string with the name of the pset created by CreatePlotEntry"""
39 if analyzer.TauProducer.pythonValue()[1:-1] ==
'shrinkingConePFTauProducer':
40 if analyzer.ExtensionName.pythonValue()[1:-1] ==
'Tanc':
41 first=
'ShrinkingConeTanc'
42 elif analyzer.ExtensionName.pythonValue()[1:-1] ==
'LeadingPion':
43 first=
'PFTauHighEfficiencyLeadingPion'
44 elif analyzer.ExtensionName.pythonValue()[1:-1] ==
"":
45 first=
'PFTauHighEfficiency'
48 first=analyzer.TauProducer.pythonValue()[1:-1]+analyzer.ExtensionName.pythonValue()[1:-1]
49 elif analyzer.TauProducer.pythonValue()[1:-1] ==
'hpsPFTauProducer':
51 elif analyzer.TauProducer.pythonValue()[1:-1] ==
'hpsTancTaus':
52 first=
'HPSTanc'+analyzer.ExtensionName.value()
55 first=analyzer.TauProducer.pythonValue()[1:-1]+analyzer.ExtensionName.pythonValue()[1:-1]
57 if discriminatorLabel ==
None:
60 if discriminatorLabel.find(
'DiscriminationBy') != -1:
61 last = discriminatorLabel[(discriminatorLabel.find(
'DiscriminationBy')+len(
'DiscriminationBy')):]
62 if last.find(
'TaNCfr') != -1:
63 last = last[len(
'TaNCfr'):]
65 last = discriminatorLabel[(discriminatorLabel.find(
'DiscriminationAgainst')+len(
'DiscriminationAgainst')):]+
"Rejection"
67 return first+
"ID"+last+
"Efficiencies"
70 """PlotAnalyzer(pset, analyzer)\n
71 fills a PSet that contains all the performance plots for a anlyzer\n
72 pset is the PSet to fill/add"""
76 for currentDiscriminator
in analyzer.discriminators:
77 label = currentDiscriminator.discriminator.pythonValue()[1:-1]
78 step = currentDiscriminator.plotStep.value()
82 """Class to scan a sequence and give a list of analyzer used and a list of their names"""
94 sequence.visit(scanner)
96 isolationQualityCuts = cms.PSet(
97 minTrackHits = cms.uint32(0),
98 minTrackVertexWeight = cms.double(-1),
99 minTrackPt = cms.double(0),
100 maxTrackChi2 = cms.double(9999),
101 minTrackPixelHits = cms.uint32(0),
102 minGammaEt = cms.double(0),
103 maxDeltaZ = cms.double(0.2),
104 maxTransverseImpactParameter = cms.double(9999)
106 pvFindingAlgo = cms.string(
'highestWeightForLeadTrack'),
107 primaryVertexSrc = cms.InputTag(
"offlinePrimaryVertices"),
108 signalQualityCuts = cms.PSet(
109 minTrackHits = cms.uint32(0),
110 minTrackVertexWeight = cms.double(-1),
111 minTrackPt = cms.double(0),
112 maxTrackChi2 = cms.double(9999),
113 minTrackPixelHits = cms.uint32(0),
114 minGammaEt = cms.double(0),
115 maxDeltaZ = cms.double(0.2),
116 maxTransverseImpactParameter = cms.double(9999)
119 for module
in scanner.modules():
120 if hasattr(module,
'qualityCuts'):
121 setattr(module,
'qualityCuts',disabled)
125 """SetSequence(seqence)\n
126 This Function return a PSet of the sequence given to be used by TauDQMHistEffProducer"""
129 sequence.visit(scanner)
130 for analyzer
in scanner.modules():
135 """SpawnPSet(lArgument, subPset) --> cms.PSet\n
136 lArgument is a list containing a list of three strings/values:\n
137 1-name to give to the spawned pset\n
138 2-variable(s) to be changed\n
139 3-value(s) of the variable(s): SAME LENGTH OF 2-!\n
140 Supported types: int string float(converted to double)"""
142 for spawn
in lArgument:
144 print(
"ERROR! SpawnPSet uses argument of three data\n")
147 if len(spawn[1]) != len(spawn[2]):
148 print(
"ERROR! Lists of arguments to replace must have the same length")
151 spawnArg = copy.deepcopy(subPset)
152 for par, val
in zip(spawn[1],spawn[2]):
153 if isinstance(val, str) :
154 setattr(spawnArg,par,cms.string(val))
155 elif isinstance(val, int) :
156 setattr(spawnArg,par,cms.int32(val))
157 elif isinstance(val, float) :
158 setattr(spawnArg,par,cms.double(val))
159 setattr(ret,spawn[0],spawnArg)
163 """SetpByStep(analyzer, plotPset) --> PSet\n
164 This function produces the parameter set stepBystep for the EDAnalyzer TauDQMHistPlotter starting from the PSet produced for TauDQMHistEffProducer and the analyzer to plot"""
165 standardEfficiencyOverlay = cms.PSet(
166 parameter = cms.vstring(
'pt',
'eta',
'phi',
'pileup'),
167 title = cms.string(
'TauId step by step efficiencies'),
168 xAxis = cms.string(
'#PAR#'),
169 yAxis = cms.string(
'efficiency'),
170 legend = cms.string(
'efficiency_overlay'),
171 labels = cms.vstring(
'pt',
'eta')
174 standardEfficiencyOverlay,
177 producer = analyzer.TauProducer.pythonValue()[1:-1]
178 ext = analyzer.ExtensionName.pythonValue()[1:-1]
179 keyword = producer + ext +
"_"
181 tancDisc = [
'Matching',
'DecayModeSelection',
'LeadingPionPtCut',
'LeadingTrackFinding',
'LeadingTrackPtCut',
'Tanc',
'TancVLoose',
'TancLoose',
'TancMedium',
'TancRaw',
'TancTight',
'AgainstElectron',
'AgainstMuon']
182 hpsDisc = [
'Matching',
'DecayModeSelection',
'LooseIsolation',
'MediumIsolation',
'TightIsolation']
183 for parName
in plotPset.parameterNames_():
184 isToBePlotted = getattr(plotPset,parName).stepByStep.value()
186 effplot = getattr(plotPset,parName).efficiency.pythonValue()[1:-1]
187 discriminator = parName[parName.find(
'ID')+len(
'ID'):-len(
'Efficiencies')]
188 if useOnly ==
'tanc':
189 useThis = discriminator
in tancDisc
190 elif useOnly ==
'hps':
191 useThis = discriminator
in hpsDisc
194 if (effplot.find(keyword) != -1)
and useThis:
195 monEl =
'#PROCESSDIR#/'+effplot
196 counter = counter + 1
197 drawOpt =
'eff_overlay0%s'%(counter)
198 psetName = effplot[effplot.rfind(
'/')+1:-8]
199 ret.plots.append(cms.PSet(
200 dqmMonitorElements = cms.vstring(monEl),
201 process = cms.string(
'test'),
202 drawOptionEntry = cms.string(drawOpt),
203 legendEntry = cms.string(psetName)
208 """SpwnDrawJobs(analyzer, plotPset) --> cms.PSet\n
209 This function produces the parameter set drawJobs for the EDAnalyzer TauDQMHistPlotter starting from the PSet produced for TauDQMHistEffProducer and the analyzer to plot"""
210 standardEfficiencyParameters = cms.PSet(
211 parameter = cms.vstring(
'pt',
'eta',
'phi',
'pileup'),
212 xAxis = cms.string(
'#PAR#'),
213 yAxis = cms.string(
'efficiency'),
214 legend = cms.string(
'efficiency'),
215 labels = cms.vstring(
'pt',
'eta'),
216 drawOptionSet = cms.string(
'efficiency')
219 tancDisc = [
'Matching',
'DecayModeSelection',
'LeadingPionPtCut',
'LeadingTrackFinding',
'LeadingTrackPtCut',
'Tanc',
'TancVLoose',
'TancLoose',
'TancMedium',
'TancRaw',
'TancTight',
'AgainstElectron',
'AgainstMuon']
220 hpsDisc = [
'Matching',
'DecayModeSelection',
'LooseIsolation',
'MediumIsolation',
'TightIsolation']
221 producer = analyzer.TauProducer.pythonValue()[1:-1]
222 ext = analyzer.ExtensionName.pythonValue()[1:-1]
223 keyword = producer + ext +
"_"
224 for parName
in plotPset.parameterNames_():
225 effplot = getattr(plotPset,parName).efficiency.pythonValue()[1:-1]
226 discriminator = parName[parName.find(
'ID')+len(
'ID'):-len(
'Efficiencies')]
227 if useOnly ==
'tanc':
228 useThis = discriminator
in tancDisc
229 elif useOnly ==
'hps':
230 useThis = discriminator
in hpsDisc
233 if (effplot.find(keyword) != -1)
and useThis:
234 monEl =
'#PROCESSDIR#/'+effplot
235 psetName = effplot[effplot.rfind(
'/')+1:-5]
237 standardEfficiencyParameters,
239 dqmMonitorElements = cms.vstring(monEl),
240 processes = cms.vstring(
'test',
'reference')
243 setattr(ret,psetName,psetVal)
244 setattr(ret,
'TauIdEffStepByStep',
SetpByStep(analyzer, plotPset,useOnly))