File indexing completed on 2024-04-06 12:33:19
0001 from __future__ import print_function
0002 import FWCore.ParameterSet.Config as cms
0003 import copy
0004
0005 def CreatePlotEntry(analyzer, discriminatorLabel=None, step=True):
0006 """CreatePlotEntry(analyzer, discriminatorLabel)\n
0007 Creates a PSet with the informations used by TauDQMHistEffProducer\n
0008 where to find the numerator and denominator\n
0009 where to put the new plot and how to name it\n
0010 which variables control"""
0011
0012 producer = analyzer.TauProducer.pythonValue()[1:-1]
0013 ext = analyzer.ExtensionName.pythonValue()[1:-1]
0014 if discriminatorLabel == None:
0015 num = 'RecoTauV/%s%s_Matched/%sMatched_vs_#PAR#TauVisible'%(producer,ext,producer)
0016 out = 'RecoTauV/%s%s_Matched/PFJetMatchingEff#PAR#'%(producer,ext)
0017 else:
0018 num = 'RecoTauV/%s%s_%s/%s_vs_#PAR#TauVisible'%(producer,ext,discriminatorLabel,discriminatorLabel)
0019 if discriminatorLabel.find('DiscriminationBy') != -1:
0020 hname = discriminatorLabel[(discriminatorLabel.find('DiscriminationBy')+len('DiscriminationBy')):]
0021 else:
0022 hname = discriminatorLabel[(discriminatorLabel.find('Discrimination')+len('Discrimination')):]
0023 out = 'RecoTauV/%s%s_%s/%sEff#PAR#'%(producer,ext,discriminatorLabel,hname)
0024
0025 den = 'RecoTauV/%s%s_ReferenceCollection/nRef_Taus_vs_#PAR#TauVisible'%(producer,ext)
0026 ret = cms.PSet(
0027 numerator = cms.string(num),
0028 denominator = cms.string(den),
0029 efficiency = cms.string(out),
0030 parameter = cms.vstring('pt', 'eta', 'phi', 'pileup'),
0031 stepByStep = cms.bool(step)
0032 )
0033 return ret
0034
0035 def NameVariable(analyzer, discriminatorLabel=None):
0036 """NameVariable(analyzer, discriminatorLabel)\n
0037 returns a string with the name of the pset created by CreatePlotEntry"""
0038
0039 if analyzer.TauProducer.pythonValue()[1:-1] == 'shrinkingConePFTauProducer':
0040 if analyzer.ExtensionName.pythonValue()[1:-1] == 'Tanc':
0041 first='ShrinkingConeTanc'
0042 elif analyzer.ExtensionName.pythonValue()[1:-1] == 'LeadingPion':
0043 first='PFTauHighEfficiencyLeadingPion'
0044 elif analyzer.ExtensionName.pythonValue()[1:-1] == "":
0045 first='PFTauHighEfficiency'
0046 else:
0047
0048 first=analyzer.TauProducer.pythonValue()[1:-1]+analyzer.ExtensionName.pythonValue()[1:-1]
0049 elif analyzer.TauProducer.pythonValue()[1:-1] == 'hpsPFTauProducer':
0050 first='HPS'
0051 elif analyzer.TauProducer.pythonValue()[1:-1] == 'hpsTancTaus':
0052 first='HPSTanc'+analyzer.ExtensionName.value()
0053 else:
0054
0055 first=analyzer.TauProducer.pythonValue()[1:-1]+analyzer.ExtensionName.pythonValue()[1:-1]
0056
0057 if discriminatorLabel == None:
0058 last = 'Matching'
0059 else:
0060 if discriminatorLabel.find('DiscriminationBy') != -1:
0061 last = discriminatorLabel[(discriminatorLabel.find('DiscriminationBy')+len('DiscriminationBy')):]
0062 if last.find('TaNCfr') != -1:
0063 last = last[len('TaNCfr'):]
0064 else:
0065 last = discriminatorLabel[(discriminatorLabel.find('DiscriminationAgainst')+len('DiscriminationAgainst')):]+"Rejection"
0066
0067 return first+"ID"+last+"Efficiencies"
0068
0069 def PlotAnalyzer(pset, analyzer):
0070 """PlotAnalyzer(pset, analyzer)\n
0071 fills a PSet that contains all the performance plots for a anlyzer\n
0072 pset is the PSet to fill/add"""
0073
0074 setattr(pset,NameVariable(analyzer),CreatePlotEntry(analyzer))
0075
0076 for currentDiscriminator in analyzer.discriminators:
0077 label = currentDiscriminator.discriminator.pythonValue()[1:-1]
0078 step = currentDiscriminator.plotStep.value()
0079 setattr(pset,NameVariable(analyzer,label),CreatePlotEntry(analyzer,label,step))
0080
0081 class Scanner(object):
0082 """Class to scan a sequence and give a list of analyzer used and a list of their names"""
0083 def __init__(self):
0084 self._analyzerRef = []
0085 def enter(self,visitee):
0086 self._analyzerRef.append(visitee)
0087 def modules(self):
0088 return self._analyzerRef
0089 def leave(self, visitee):
0090 pass
0091
0092 def DisableQCuts(sequence):
0093 scanner = Scanner()
0094 sequence.visit(scanner)
0095 disabled = cms.PSet(
0096 isolationQualityCuts = cms.PSet(
0097 minTrackHits = cms.uint32(0),
0098 minTrackVertexWeight = cms.double(-1),
0099 minTrackPt = cms.double(0),
0100 maxTrackChi2 = cms.double(9999),
0101 minTrackPixelHits = cms.uint32(0),
0102 minGammaEt = cms.double(0),
0103 maxDeltaZ = cms.double(0.2),
0104 maxTransverseImpactParameter = cms.double(9999)
0105 ),
0106 pvFindingAlgo = cms.string('highestWeightForLeadTrack'),
0107 primaryVertexSrc = cms.InputTag("offlinePrimaryVertices"),
0108 signalQualityCuts = cms.PSet(
0109 minTrackHits = cms.uint32(0),
0110 minTrackVertexWeight = cms.double(-1),
0111 minTrackPt = cms.double(0),
0112 maxTrackChi2 = cms.double(9999),
0113 minTrackPixelHits = cms.uint32(0),
0114 minGammaEt = cms.double(0),
0115 maxDeltaZ = cms.double(0.2),
0116 maxTransverseImpactParameter = cms.double(9999)
0117 )
0118 )
0119 for module in scanner.modules():
0120 if hasattr(module,'qualityCuts'):
0121 setattr(module,'qualityCuts',disabled)
0122
0123
0124 def SetPlotSequence(sequence):
0125 """SetSequence(seqence)\n
0126 This Function return a PSet of the sequence given to be used by TauDQMHistEffProducer"""
0127 pset = cms.PSet()
0128 scanner = Scanner()
0129 sequence.visit(scanner)
0130 for analyzer in scanner.modules():
0131 PlotAnalyzer(pset, analyzer)
0132 return pset
0133
0134 def SpawnPSet(lArgument, subPset):
0135 """SpawnPSet(lArgument, subPset) --> cms.PSet\n
0136 lArgument is a list containing a list of three strings/values:\n
0137 1-name to give to the spawned pset\n
0138 2-variable(s) to be changed\n
0139 3-value(s) of the variable(s): SAME LENGTH OF 2-!\n
0140 Supported types: int string float(converted to double)"""
0141 ret = cms.PSet()
0142 for spawn in lArgument:
0143 if len(spawn) != 3:
0144 print("ERROR! SpawnPSet uses argument of three data\n")
0145 print(self.__doc__)
0146 return None
0147 if len(spawn[1]) != len(spawn[2]):
0148 print("ERROR! Lists of arguments to replace must have the same length")
0149 print(self.__doc__)
0150 return None
0151 spawnArg = copy.deepcopy(subPset)
0152 for par, val in zip(spawn[1],spawn[2]):
0153 if isinstance(val, str) :
0154 setattr(spawnArg,par,cms.string(val))
0155 elif isinstance(val, int) :
0156 setattr(spawnArg,par,cms.int32(val))
0157 elif isinstance(val, float) :
0158 setattr(spawnArg,par,cms.double(val))
0159 setattr(ret,spawn[0],spawnArg)
0160 return ret
0161
0162 def SetpByStep(analyzer, plotPset, useOnly):
0163 """SetpByStep(analyzer, plotPset) --> PSet\n
0164 This function produces the parameter set stepBystep for the EDAnalyzer TauDQMHistPlotter starting from the PSet produced for TauDQMHistEffProducer and the analyzer to plot"""
0165 standardEfficiencyOverlay = cms.PSet(
0166 parameter = cms.vstring('pt', 'eta', 'phi', 'pileup'),
0167 title = cms.string('TauId step by step efficiencies'),
0168 xAxis = cms.string('#PAR#'),
0169 yAxis = cms.string('efficiency'),
0170 legend = cms.string('efficiency_overlay'),
0171 labels = cms.vstring('pt', 'eta')
0172 )
0173 ret = cms.PSet(
0174 standardEfficiencyOverlay,
0175 plots = cms.VPSet()
0176 )
0177 producer = analyzer.TauProducer.pythonValue()[1:-1]
0178 ext = analyzer.ExtensionName.pythonValue()[1:-1]
0179 keyword = producer + ext + "_"
0180 counter = 0
0181 tancDisc = ['Matching','DecayModeSelection','LeadingPionPtCut','LeadingTrackFinding','LeadingTrackPtCut','Tanc','TancVLoose','TancLoose','TancMedium','TancRaw','TancTight','AgainstElectron','AgainstMuon']
0182 hpsDisc = ['Matching','DecayModeSelection','LooseIsolation','MediumIsolation','TightIsolation']
0183 for parName in plotPset.parameterNames_():
0184 isToBePlotted = getattr(plotPset,parName).stepByStep.value()
0185 if isToBePlotted:
0186 effplot = getattr(plotPset,parName).efficiency.pythonValue()[1:-1]
0187 discriminator = parName[parName.find('ID')+len('ID'):-len('Efficiencies')]
0188 if useOnly == 'tanc':
0189 useThis = discriminator in tancDisc
0190 elif useOnly == 'hps':
0191 useThis = discriminator in hpsDisc
0192 else :
0193 useThis = True
0194 if (effplot.find(keyword) != -1) and useThis:
0195 monEl = '#PROCESSDIR#/'+effplot
0196 counter = counter + 1
0197 drawOpt = 'eff_overlay0%s'%(counter)
0198 psetName = effplot[effplot.rfind('/')+1:-8]
0199 ret.plots.append(cms.PSet(
0200 dqmMonitorElements = cms.vstring(monEl),
0201 process = cms.string('test'),
0202 drawOptionEntry = cms.string(drawOpt),
0203 legendEntry = cms.string(psetName)
0204 ))
0205 return ret
0206
0207 def SpawnDrawJobs(analyzer, plotPset, useOnly=None):
0208 """SpwnDrawJobs(analyzer, plotPset) --> cms.PSet\n
0209 This function produces the parameter set drawJobs for the EDAnalyzer TauDQMHistPlotter starting from the PSet produced for TauDQMHistEffProducer and the analyzer to plot"""
0210 standardEfficiencyParameters = cms.PSet(
0211 parameter = cms.vstring('pt', 'eta', 'phi', 'pileup'),
0212 xAxis = cms.string('#PAR#'),
0213 yAxis = cms.string('efficiency'),
0214 legend = cms.string('efficiency'),
0215 labels = cms.vstring('pt', 'eta'),
0216 drawOptionSet = cms.string('efficiency')
0217 )
0218 ret = cms.PSet()
0219 tancDisc = ['Matching','DecayModeSelection','LeadingPionPtCut','LeadingTrackFinding','LeadingTrackPtCut','Tanc','TancVLoose','TancLoose','TancMedium','TancRaw','TancTight','AgainstElectron','AgainstMuon']
0220 hpsDisc = ['Matching','DecayModeSelection','LooseIsolation','MediumIsolation','TightIsolation']
0221 producer = analyzer.TauProducer.pythonValue()[1:-1]
0222 ext = analyzer.ExtensionName.pythonValue()[1:-1]
0223 keyword = producer + ext + "_"
0224 for parName in plotPset.parameterNames_():
0225 effplot = getattr(plotPset,parName).efficiency.pythonValue()[1:-1]
0226 discriminator = parName[parName.find('ID')+len('ID'):-len('Efficiencies')]
0227 if useOnly == 'tanc':
0228 useThis = discriminator in tancDisc
0229 elif useOnly == 'hps':
0230 useThis = discriminator in hpsDisc
0231 else :
0232 useThis = True
0233 if (effplot.find(keyword) != -1) and useThis:
0234 monEl = '#PROCESSDIR#/'+effplot
0235 psetName = effplot[effplot.rfind('/')+1:-5]
0236 psetVal = cms.PSet(
0237 standardEfficiencyParameters,
0238 plots = cms.PSet(
0239 dqmMonitorElements = cms.vstring(monEl),
0240 processes = cms.vstring('test', 'reference')
0241 )
0242 )
0243 setattr(ret,psetName,psetVal)
0244 setattr(ret,'TauIdEffStepByStep',SetpByStep(analyzer, plotPset,useOnly))
0245 return ret