CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 4 of file ValidationUtils.py.

Referenced by PlotAnalyzer().

4 
5 def CreatePlotEntry(analyzer, discriminatorLabel=None, step=True):
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"""
11 
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)
17  if producer.find('caloReco') != -1:
18  out = 'RecoTauV/%s%s_Matched/CaloJetMatchingEff#PAR#'%(producer,ext)
19  else:
20  out = 'RecoTauV/%s%s_Matched/PFJetMatchingEff#PAR#'%(producer,ext)
21  else:
22  num = 'RecoTauV/%s%s_%s/%s_vs_#PAR#TauVisible'%(producer,ext,discriminatorLabel,discriminatorLabel)
23  if discriminatorLabel.find('DiscriminationBy') != -1:
24  hname = discriminatorLabel[(discriminatorLabel.find('DiscriminationBy')+len('DiscriminationBy')):]
25  else:
26  hname = discriminatorLabel[(discriminatorLabel.find('Discrimination')+len('Discrimination')):]
27  out = 'RecoTauV/%s%s_%s/%sEff#PAR#'%(producer,ext,discriminatorLabel,hname)
28 
29  den = 'RecoTauV/%s%s_ReferenceCollection/nRef_Taus_vs_#PAR#TauVisible'%(producer,ext)
30  ret = cms.PSet(
31  numerator = cms.string(num),
32  denominator = cms.string(den),
33  efficiency = cms.string(out),
34  parameter = cms.vstring('pt', 'eta', 'phi', 'pileup'),
35  stepByStep = cms.bool(step)
36  )
37  return ret
def ValidationUtils.DisableQCuts (   sequence)

Definition at line 97 of file ValidationUtils.py.

97 
98 def DisableQCuts(sequence):
99  scanner = Scanner()
100  sequence.visit(scanner)
101  disabled = cms.PSet(
102  isolationQualityCuts = cms.PSet(
103  minTrackHits = cms.uint32(0),
104  minTrackVertexWeight = cms.double(-1),
105  minTrackPt = cms.double(0),
106  maxTrackChi2 = cms.double(9999),
107  minTrackPixelHits = cms.uint32(0),
108  minGammaEt = cms.double(0),
109  maxDeltaZ = cms.double(0.2),
110  maxTransverseImpactParameter = cms.double(9999)
111  ),
112  pvFindingAlgo = cms.string('highestWeightForLeadTrack'),
113  primaryVertexSrc = cms.InputTag("offlinePrimaryVertices"),
114  signalQualityCuts = cms.PSet(
115  minTrackHits = cms.uint32(0),
116  minTrackVertexWeight = cms.double(-1),
117  minTrackPt = cms.double(0),
118  maxTrackChi2 = cms.double(9999),
119  minTrackPixelHits = cms.uint32(0),
120  minGammaEt = cms.double(0),
121  maxDeltaZ = cms.double(0.2),
122  maxTransverseImpactParameter = cms.double(9999)
123  )
124  )
125  for module in scanner.modules():
126  if hasattr(module,'qualityCuts'):
127  setattr(module,'qualityCuts',disabled)
128 
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 38 of file ValidationUtils.py.

Referenced by PlotAnalyzer().

38 
39 def NameVariable(analyzer, discriminatorLabel=None):
40  """NameVariable(analyzer, discriminatorLabel)\n
41  returns a string with the name of the pset created by CreatePlotEntry"""
42  #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!
43  if analyzer.TauProducer.pythonValue()[1:-1] == 'shrinkingConePFTauProducer':
44  if analyzer.ExtensionName.pythonValue()[1:-1] == 'Tanc':
45  first='ShrinkingConeTanc'
46  elif analyzer.ExtensionName.pythonValue()[1:-1] == 'LeadingPion':
47  first='PFTauHighEfficiencyLeadingPion'
48  elif analyzer.ExtensionName.pythonValue()[1:-1] == "":
49  first='PFTauHighEfficiency'
50  else:
51  #print 'Case not found check the available cases in Validation/RecoTau/python/ValidationUtils.py -- NameVariable'
52  first=analyzer.TauProducer.pythonValue()[1:-1]+analyzer.ExtensionName.pythonValue()[1:-1]
53  elif analyzer.TauProducer.pythonValue()[1:-1] == 'hpsPFTauProducer':
54  first='HPS'
55  elif analyzer.TauProducer.pythonValue()[1:-1] == 'hpsTancTaus':
56  first='HPSTanc'+analyzer.ExtensionName.value()
57  elif analyzer.TauProducer.pythonValue()[1:-1] == 'caloRecoTauProducer':
58  first='CaloTau'
59  else:
60  #print 'Case not found check the available cases in Validation/RecoTau/python/ValidationUtils.py -- NameVariable'
61  first=analyzer.TauProducer.pythonValue()[1:-1]+analyzer.ExtensionName.pythonValue()[1:-1]
62 
63  if discriminatorLabel == None:
64  last = 'Matching'
65  else:
66  if discriminatorLabel.find('DiscriminationBy') != -1:
67  last = discriminatorLabel[(discriminatorLabel.find('DiscriminationBy')+len('DiscriminationBy')):]
68  if last.find('TaNCfr') != -1:
69  last = last[len('TaNCfr'):]
70  else:
71  last = discriminatorLabel[(discriminatorLabel.find('DiscriminationAgainst')+len('DiscriminationAgainst')):]+"Rejection"
72 
73  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 74 of file ValidationUtils.py.

References CreatePlotEntry(), and NameVariable().

Referenced by SetPlotSequence().

74 
75 def PlotAnalyzer(pset, analyzer):
76  """PlotAnalyzer(pset, analyzer)\n
77  fills a PSet that contains all the performance plots for a anlyzer\n
78  pset is the PSet to fill/add"""
79 
80  setattr(pset,NameVariable(analyzer),CreatePlotEntry(analyzer))
81 
82  for currentDiscriminator in analyzer.discriminators:
83  label = currentDiscriminator.discriminator.pythonValue()[1:-1]
84  step = currentDiscriminator.plotStep.value()
85  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 168 of file ValidationUtils.py.

Referenced by SpawnDrawJobs().

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

References PlotAnalyzer().

130 def SetPlotSequence(sequence):
131  """SetSequence(seqence)\n
132  This Function return a PSet of the sequence given to be used by TauDQMHistEffProducer"""
133  pset = cms.PSet()
134  scanner = Scanner()
135  sequence.visit(scanner)
136  for analyzer in scanner.modules():#The first one is the sequence itself
137  if type(analyzer) is cms.EDAnalyzer:
138  PlotAnalyzer(pset, analyzer)
139  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 213 of file ValidationUtils.py.

References SetpByStep().

214 def SpawnDrawJobs(analyzer, plotPset, useOnly=None):
215  """SpwnDrawJobs(analyzer, plotPset) --> cms.PSet\n
216  This function produces the parameter set drawJobs for the EDAnalyzer TauDQMHistPlotter starting from the PSet produced for TauDQMHistEffProducer and the analyzer to plot"""
217  standardEfficiencyParameters = cms.PSet(
218  parameter = cms.vstring('pt', 'eta', 'phi', 'pileup'),
219  xAxis = cms.string('#PAR#'),
220  yAxis = cms.string('efficiency'),
221  legend = cms.string('efficiency'),
222  labels = cms.vstring('pt', 'eta'),
223  drawOptionSet = cms.string('efficiency')
224  )
225  ret = cms.PSet()
226  tancDisc = ['Matching','DecayModeSelection','LeadingPionPtCut','LeadingTrackFinding','LeadingTrackPtCut','Tanc','TancVLoose','TancLoose','TancMedium','TancRaw','TancTight','AgainstElectron','AgainstMuon']
227  hpsDisc = ['Matching','DecayModeSelection','LooseIsolation','MediumIsolation','TightIsolation']
228  producer = analyzer.TauProducer.pythonValue()[1:-1]
229  ext = analyzer.ExtensionName.pythonValue()[1:-1]
230  keyword = producer + ext + "_"
231  for parName in plotPset.parameterNames_():
232  effplot = getattr(plotPset,parName).efficiency.pythonValue()[1:-1]
233  discriminator = parName[parName.find('ID')+len('ID'):-len('Efficiencies')]
234  if useOnly == 'tanc':
235  useThis = discriminator in tancDisc
236  elif useOnly == 'hps':
237  useThis = discriminator in hpsDisc
238  else :
239  useThis = True
240  if (effplot.find(keyword) != -1) and useThis:
241  monEl = '#PROCESSDIR#/'+effplot
242  psetName = effplot[effplot.rfind('/')+1:-5]
243  psetVal = cms.PSet(
244  standardEfficiencyParameters,
245  plots = cms.PSet(
246  dqmMonitorElements = cms.vstring(monEl),
247  processes = cms.vstring('test', 'reference')
248  )
249  )
250  setattr(ret,psetName,psetVal)
251  setattr(ret,'TauIdEffStepByStep',SetpByStep(analyzer, plotPset,useOnly))
252  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 140 of file ValidationUtils.py.

141 def SpawnPSet(lArgument, subPset):
142  """SpawnPSet(lArgument, subPset) --> cms.PSet\n
143  lArgument is a list containing a list of three strings/values:\n
144  1-name to give to the spawned pset\n
145  2-variable(s) to be changed\n
146  3-value(s) of the variable(s): SAME LENGTH OF 2-!\n
147  Supported types: int string float(converted to double)"""
148  ret = cms.PSet()
149  for spawn in lArgument:
150  if len(spawn) != 3:
151  print "ERROR! SpawnPSet uses argument of three data\n"
152  print self.__doc__
153  return None
154  if len(spawn[1]) != len(spawn[2]):
155  print "ERROR! Lists of arguments to replace must have the same length"
156  print self.__doc__
157  return None
158  spawnArg = copy.deepcopy(subPset)
159  for par, val in zip(spawn[1],spawn[2]):
160  if type(val) is str :
161  setattr(spawnArg,par,cms.string(val))
162  elif type(val) is int :
163  setattr(spawnArg,par,cms.int32(val))
164  elif type(val) is float :
165  setattr(spawnArg,par,cms.double(val))
166  setattr(ret,spawn[0],spawnArg)
167  return ret