CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions
ValidationUtils Namespace Reference

Classes

class  Scanner
 

Functions

def CreatePlotEntry
 
def DisableQCuts
 
def NameVariable
 
def PlotAnalyzer
 
def SetpByStep
 
def SetPlotSequence
 
def SpawnDrawJobs
 
def SpawnPSet
 

Function Documentation

def ValidationUtils.CreatePlotEntry (   analyzer,
  discriminatorLabel = None,
  step = True 
)
CreatePlotEntry(analyzer, discriminatorLabel)\n
Creates a PSet with the informations used by TauDQMHistEffProducer\n
where to find the numerator and denominator\n
where to put the new plot and how to name it\n
which variables control

Definition at line 5 of file ValidationUtils.py.

Referenced by PlotAnalyzer().

5 
6 def CreatePlotEntry(analyzer, discriminatorLabel=None, step=True):
7  """CreatePlotEntry(analyzer, discriminatorLabel)\n
8  Creates a PSet with the informations used by TauDQMHistEffProducer\n
9  where to find the numerator and denominator\n
10  where to put the new plot and how to name it\n
11  which variables control"""
12 
13  producer = analyzer.TauProducer.pythonValue()[1:-1]
14  ext = analyzer.ExtensionName.pythonValue()[1:-1]
15  if discriminatorLabel == None:
16  num = 'RecoTauV/%s%s_Matched/%sMatched_vs_#PAR#TauVisible'%(producer,ext,producer)
17  out = 'RecoTauV/%s%s_Matched/PFJetMatchingEff#PAR#'%(producer,ext)
18  else:
19  num = 'RecoTauV/%s%s_%s/%s_vs_#PAR#TauVisible'%(producer,ext,discriminatorLabel,discriminatorLabel)
20  if discriminatorLabel.find('DiscriminationBy') != -1:
21  hname = discriminatorLabel[(discriminatorLabel.find('DiscriminationBy')+len('DiscriminationBy')):]
22  else:
23  hname = discriminatorLabel[(discriminatorLabel.find('Discrimination')+len('Discrimination')):]
24  out = 'RecoTauV/%s%s_%s/%sEff#PAR#'%(producer,ext,discriminatorLabel,hname)
25 
26  den = 'RecoTauV/%s%s_ReferenceCollection/nRef_Taus_vs_#PAR#TauVisible'%(producer,ext)
27  ret = cms.PSet(
28  numerator = cms.string(num),
29  denominator = cms.string(den),
30  efficiency = cms.string(out),
31  parameter = cms.vstring('pt', 'eta', 'phi', 'pileup'),
32  stepByStep = cms.bool(step)
33  )
34  return ret
def ValidationUtils.DisableQCuts (   sequence)

Definition at line 92 of file ValidationUtils.py.

92 
93 def DisableQCuts(sequence):
94  scanner = Scanner()
95  sequence.visit(scanner)
96  disabled = cms.PSet(
97  isolationQualityCuts = cms.PSet(
98  minTrackHits = cms.uint32(0),
99  minTrackVertexWeight = cms.double(-1),
100  minTrackPt = cms.double(0),
101  maxTrackChi2 = cms.double(9999),
102  minTrackPixelHits = cms.uint32(0),
103  minGammaEt = cms.double(0),
104  maxDeltaZ = cms.double(0.2),
105  maxTransverseImpactParameter = cms.double(9999)
106  ),
107  pvFindingAlgo = cms.string('highestWeightForLeadTrack'),
108  primaryVertexSrc = cms.InputTag("offlinePrimaryVertices"),
109  signalQualityCuts = cms.PSet(
110  minTrackHits = cms.uint32(0),
111  minTrackVertexWeight = cms.double(-1),
112  minTrackPt = cms.double(0),
113  maxTrackChi2 = cms.double(9999),
114  minTrackPixelHits = cms.uint32(0),
115  minGammaEt = cms.double(0),
116  maxDeltaZ = cms.double(0.2),
117  maxTransverseImpactParameter = cms.double(9999)
118  )
119  )
120  for module in scanner.modules():
121  if hasattr(module,'qualityCuts'):
122  setattr(module,'qualityCuts',disabled)
123 
def ValidationUtils.NameVariable (   analyzer,
  discriminatorLabel = None 
)
NameVariable(analyzer, discriminatorLabel)\n
returns a string with the name of the pset created by CreatePlotEntry

Definition at line 35 of file ValidationUtils.py.

Referenced by PlotAnalyzer().

35 
36 def NameVariable(analyzer, discriminatorLabel=None):
37  """NameVariable(analyzer, discriminatorLabel)\n
38  returns a string with the name of the pset created by CreatePlotEntry"""
39  #This part is messy, there is no way to directly link the producer and the name of the variable. There are more exception than rules! IF THE DISCRIMINATOR NAME CHANGES YOU HAVE TO CHANHE IT HERE TOO!
40  if analyzer.TauProducer.pythonValue()[1:-1] == 'shrinkingConePFTauProducer':
41  if analyzer.ExtensionName.pythonValue()[1:-1] == 'Tanc':
42  first='ShrinkingConeTanc'
43  elif analyzer.ExtensionName.pythonValue()[1:-1] == 'LeadingPion':
44  first='PFTauHighEfficiencyLeadingPion'
45  elif analyzer.ExtensionName.pythonValue()[1:-1] == "":
46  first='PFTauHighEfficiency'
47  else:
48  #print 'Case not found check the available cases in Validation/RecoTau/python/ValidationUtils.py -- NameVariable'
49  first=analyzer.TauProducer.pythonValue()[1:-1]+analyzer.ExtensionName.pythonValue()[1:-1]
50  elif analyzer.TauProducer.pythonValue()[1:-1] == 'hpsPFTauProducer':
51  first='HPS'
52  elif analyzer.TauProducer.pythonValue()[1:-1] == 'hpsTancTaus':
53  first='HPSTanc'+analyzer.ExtensionName.value()
54  else:
55  #print 'Case not found check the available cases in Validation/RecoTau/python/ValidationUtils.py -- NameVariable'
56  first=analyzer.TauProducer.pythonValue()[1:-1]+analyzer.ExtensionName.pythonValue()[1:-1]
57 
58  if discriminatorLabel == None:
59  last = 'Matching'
60  else:
61  if discriminatorLabel.find('DiscriminationBy') != -1:
62  last = discriminatorLabel[(discriminatorLabel.find('DiscriminationBy')+len('DiscriminationBy')):]
63  if last.find('TaNCfr') != -1:
64  last = last[len('TaNCfr'):]
65  else:
66  last = discriminatorLabel[(discriminatorLabel.find('DiscriminationAgainst')+len('DiscriminationAgainst')):]+"Rejection"
67 
68  return first+"ID"+last+"Efficiencies"
def ValidationUtils.PlotAnalyzer (   pset,
  analyzer 
)
PlotAnalyzer(pset, analyzer)\n
fills a PSet that contains all the performance plots for a anlyzer\n
pset is the PSet to fill/add

Definition at line 69 of file ValidationUtils.py.

References CreatePlotEntry(), and NameVariable().

Referenced by SetPlotSequence().

69 
70 def PlotAnalyzer(pset, analyzer):
71  """PlotAnalyzer(pset, analyzer)\n
72  fills a PSet that contains all the performance plots for a anlyzer\n
73  pset is the PSet to fill/add"""
74 
75  setattr(pset,NameVariable(analyzer),CreatePlotEntry(analyzer))
76 
77  for currentDiscriminator in analyzer.discriminators:
78  label = currentDiscriminator.discriminator.pythonValue()[1:-1]
79  step = currentDiscriminator.plotStep.value()
80  setattr(pset,NameVariable(analyzer,label),CreatePlotEntry(analyzer,label,step))
def ValidationUtils.SetpByStep (   analyzer,
  plotPset,
  useOnly 
)
SetpByStep(analyzer, plotPset) --> PSet\n
 This function produces the parameter set stepBystep for the EDAnalyzer TauDQMHistPlotter starting from the PSet produced for TauDQMHistEffProducer and the analyzer to plot

Definition at line 162 of file ValidationUtils.py.

Referenced by SpawnDrawJobs().

163 def SetpByStep(analyzer, plotPset, useOnly):
164  """SetpByStep(analyzer, plotPset) --> PSet\n
165  This function produces the parameter set stepBystep for the EDAnalyzer TauDQMHistPlotter starting from the PSet produced for TauDQMHistEffProducer and the analyzer to plot"""
166  standardEfficiencyOverlay = cms.PSet(
167  parameter = cms.vstring('pt', 'eta', 'phi', 'pileup'),
168  title = cms.string('TauId step by step efficiencies'),
169  xAxis = cms.string('#PAR#'),
170  yAxis = cms.string('efficiency'),
171  legend = cms.string('efficiency_overlay'),
172  labels = cms.vstring('pt', 'eta')
173  )
174  ret = cms.PSet(
175  standardEfficiencyOverlay,
176  plots = cms.VPSet()
177  )
178  producer = analyzer.TauProducer.pythonValue()[1:-1]
179  ext = analyzer.ExtensionName.pythonValue()[1:-1]
180  keyword = producer + ext + "_"
181  counter = 0
182  tancDisc = ['Matching','DecayModeSelection','LeadingPionPtCut','LeadingTrackFinding','LeadingTrackPtCut','Tanc','TancVLoose','TancLoose','TancMedium','TancRaw','TancTight','AgainstElectron','AgainstMuon']
183  hpsDisc = ['Matching','DecayModeSelection','LooseIsolation','MediumIsolation','TightIsolation']
184  for parName in plotPset.parameterNames_():
185  isToBePlotted = getattr(plotPset,parName).stepByStep.value()
186  if isToBePlotted:
187  effplot = getattr(plotPset,parName).efficiency.pythonValue()[1:-1]
188  discriminator = parName[parName.find('ID')+len('ID'):-len('Efficiencies')]
189  if useOnly == 'tanc':
190  useThis = discriminator in tancDisc
191  elif useOnly == 'hps':
192  useThis = discriminator in hpsDisc
193  else :
194  useThis = True
195  if (effplot.find(keyword) != -1) and useThis:
196  monEl = '#PROCESSDIR#/'+effplot
197  counter = counter + 1
198  drawOpt = 'eff_overlay0%s'%(counter)
199  psetName = effplot[effplot.rfind('/')+1:-8]
200  ret.plots.append(cms.PSet(
201  dqmMonitorElements = cms.vstring(monEl),
202  process = cms.string('test'),
203  drawOptionEntry = cms.string(drawOpt),
204  legendEntry = cms.string(psetName)
205  ))
206  return ret
def ValidationUtils.SetPlotSequence (   sequence)
SetSequence(seqence)\n
This Function return a PSet of the sequence given to be used by TauDQMHistEffProducer

Definition at line 124 of file ValidationUtils.py.

References PlotAnalyzer().

125 def SetPlotSequence(sequence):
126  """SetSequence(seqence)\n
127  This Function return a PSet of the sequence given to be used by TauDQMHistEffProducer"""
128  pset = cms.PSet()
129  scanner = Scanner()
130  sequence.visit(scanner)
131  for analyzer in scanner.modules():#The first one is the sequence itself
132  PlotAnalyzer(pset, analyzer)
133  return pset
def ValidationUtils.SpawnDrawJobs (   analyzer,
  plotPset,
  useOnly = None 
)
SpwnDrawJobs(analyzer, plotPset) --> cms.PSet\n
This function produces the parameter set drawJobs for the EDAnalyzer TauDQMHistPlotter starting from the PSet produced for TauDQMHistEffProducer and the analyzer to plot

Definition at line 207 of file ValidationUtils.py.

References SetpByStep().

208 def SpawnDrawJobs(analyzer, plotPset, useOnly=None):
209  """SpwnDrawJobs(analyzer, plotPset) --> cms.PSet\n
210  This function produces the parameter set drawJobs for the EDAnalyzer TauDQMHistPlotter starting from the PSet produced for TauDQMHistEffProducer and the analyzer to plot"""
211  standardEfficiencyParameters = cms.PSet(
212  parameter = cms.vstring('pt', 'eta', 'phi', 'pileup'),
213  xAxis = cms.string('#PAR#'),
214  yAxis = cms.string('efficiency'),
215  legend = cms.string('efficiency'),
216  labels = cms.vstring('pt', 'eta'),
217  drawOptionSet = cms.string('efficiency')
218  )
219  ret = cms.PSet()
220  tancDisc = ['Matching','DecayModeSelection','LeadingPionPtCut','LeadingTrackFinding','LeadingTrackPtCut','Tanc','TancVLoose','TancLoose','TancMedium','TancRaw','TancTight','AgainstElectron','AgainstMuon']
221  hpsDisc = ['Matching','DecayModeSelection','LooseIsolation','MediumIsolation','TightIsolation']
222  producer = analyzer.TauProducer.pythonValue()[1:-1]
223  ext = analyzer.ExtensionName.pythonValue()[1:-1]
224  keyword = producer + ext + "_"
225  for parName in plotPset.parameterNames_():
226  effplot = getattr(plotPset,parName).efficiency.pythonValue()[1:-1]
227  discriminator = parName[parName.find('ID')+len('ID'):-len('Efficiencies')]
228  if useOnly == 'tanc':
229  useThis = discriminator in tancDisc
230  elif useOnly == 'hps':
231  useThis = discriminator in hpsDisc
232  else :
233  useThis = True
234  if (effplot.find(keyword) != -1) and useThis:
235  monEl = '#PROCESSDIR#/'+effplot
236  psetName = effplot[effplot.rfind('/')+1:-5]
237  psetVal = cms.PSet(
238  standardEfficiencyParameters,
239  plots = cms.PSet(
240  dqmMonitorElements = cms.vstring(monEl),
241  processes = cms.vstring('test', 'reference')
242  )
243  )
244  setattr(ret,psetName,psetVal)
245  setattr(ret,'TauIdEffStepByStep',SetpByStep(analyzer, plotPset,useOnly))
246  return ret #control if it's ok
def ValidationUtils.SpawnPSet (   lArgument,
  subPset 
)
SpawnPSet(lArgument, subPset) --> cms.PSet\n
lArgument is a list containing a list of three strings/values:\n
       1-name to give to the spawned pset\n
       2-variable(s) to be changed\n
       3-value(s) of the variable(s): SAME LENGTH OF 2-!\n
       Supported types: int string float(converted to double)

Definition at line 134 of file ValidationUtils.py.

References print(), and ComparisonHelper.zip().

135 def SpawnPSet(lArgument, subPset):
136  """SpawnPSet(lArgument, subPset) --> cms.PSet\n
137  lArgument is a list containing a list of three strings/values:\n
138  1-name to give to the spawned pset\n
139  2-variable(s) to be changed\n
140  3-value(s) of the variable(s): SAME LENGTH OF 2-!\n
141  Supported types: int string float(converted to double)"""
142  ret = cms.PSet()
143  for spawn in lArgument:
144  if len(spawn) != 3:
145  print("ERROR! SpawnPSet uses argument of three data\n")
146  print(self.__doc__)
147  return None
148  if len(spawn[1]) != len(spawn[2]):
149  print("ERROR! Lists of arguments to replace must have the same length")
150  print(self.__doc__)
151  return None
152  spawnArg = copy.deepcopy(subPset)
153  for par, val in zip(spawn[1],spawn[2]):
154  if isinstance(val, str) :
155  setattr(spawnArg,par,cms.string(val))
156  elif isinstance(val, int) :
157  setattr(spawnArg,par,cms.int32(val))
158  elif isinstance(val, float) :
159  setattr(spawnArg,par,cms.double(val))
160  setattr(ret,spawn[0],spawnArg)
161  return ret
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47