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 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 DQMHistEffProducer\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 DQMHistEffProducer\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', 'energy'),
35  stepByStep = cms.bool(step)
36  )
37  return ret
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().

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 DQMHistPlotter starting from the PSet produced for DQMHistEffProducer and the analyzer to plot

Definition at line 136 of file ValidationUtils.py.

Referenced by SpawnDrawJobs().

137 def SetpByStep(analyzer, plotPset, useOnly):
138  """SetpByStep(analyzer, plotPset) --> PSet\n
139  This function produces the parameter set stepBystep for the EDAnalyzer DQMHistPlotter starting from the PSet produced for DQMHistEffProducer and the analyzer to plot"""
140  standardEfficiencyOverlay = cms.PSet(
141  parameter = cms.vstring('pt', 'eta', 'phi', 'energy'),
142  title = cms.string('TauId step by step efficiencies'),
143  xAxis = cms.string('#PAR#'),
144  yAxis = cms.string('efficiency'),
145  legend = cms.string('efficiency_overlay'),
146  labels = cms.vstring('pt', 'eta')
147  )
148  ret = cms.PSet(
149  standardEfficiencyOverlay,
150  plots = cms.VPSet()
151  )
152  producer = analyzer.TauProducer.pythonValue()[1:-1]
153  ext = analyzer.ExtensionName.pythonValue()[1:-1]
154  keyword = producer + ext + "_"
155  counter = 0
156  tancDisc = ['Matching','DecayModeSelection','LeadingPionPtCut','LeadingTrackFinding','LeadingTrackPtCut','Tanc','TancVLoose','TancLoose','TancMedium','TancRaw','TancTight','AgainstElectron','AgainstMuon']
157  hpsDisc = ['Matching','DecayModeSelection','LooseIsolation','MediumIsolation','TightIsolation']
158  for parName in plotPset.parameterNames_():
159  isToBePlotted = getattr(plotPset,parName).stepByStep.value()
160  if isToBePlotted:
161  effplot = getattr(plotPset,parName).efficiency.pythonValue()[1:-1]
162  discriminator = parName[parName.find('ID')+len('ID'):-len('Efficiencies')]
163  if useOnly == 'tanc':
164  useThis = discriminator in tancDisc
165  elif useOnly == 'hps':
166  useThis = discriminator in hpsDisc
167  else :
168  useThis = True
169  if (effplot.find(keyword) != -1) and useThis:
170  monEl = '#PROCESSDIR#/'+effplot
171  counter = counter + 1
172  drawOpt = 'eff_overlay0%s'%(counter)
173  psetName = effplot[effplot.rfind('/')+1:-8]
174  ret.plots.append(cms.PSet(
175  dqmMonitorElements = cms.vstring(monEl),
176  process = cms.string('test'),
177  drawOptionEntry = cms.string(drawOpt),
178  legendEntry = cms.string(psetName)
179  ))
180  return ret
def ValidationUtils.SetPlotSequence (   sequence)
SetSequence(seqence)\n
This Function return a PSet of the sequence given to be used by DQMHistEffProducer

Definition at line 97 of file ValidationUtils.py.

97 
98 def SetPlotSequence(sequence):
99  """SetSequence(seqence)\n
100  This Function return a PSet of the sequence given to be used by DQMHistEffProducer"""
101  pset = cms.PSet()
102  scanner = Scanner()
103  sequence.visit(scanner)
104  for analyzer in scanner.modules():#The first one is the sequence itself
105  if type(analyzer) is cms.EDAnalyzer:
106  PlotAnalyzer(pset, analyzer)
107  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 DQMHistPlotter starting from the PSet produced for DQMHistEffProducer and the analyzer to plot

Definition at line 181 of file ValidationUtils.py.

References SetpByStep().

182 def SpawnDrawJobs(analyzer, plotPset, useOnly=None):
183  """SpwnDrawJobs(analyzer, plotPset) --> cms.PSet\n
184  This function produces the parameter set drawJobs for the EDAnalyzer DQMHistPlotter starting from the PSet produced for DQMHistEffProducer and the analyzer to plot"""
185  standardEfficiencyParameters = cms.PSet(
186  parameter = cms.vstring('pt', 'eta', 'phi', 'energy'),
187  xAxis = cms.string('#PAR#'),
188  yAxis = cms.string('efficiency'),
189  legend = cms.string('efficiency'),
190  labels = cms.vstring('pt', 'eta'),
191  drawOptionSet = cms.string('efficiency')
192  )
193  ret = cms.PSet()
194  tancDisc = ['Matching','DecayModeSelection','LeadingPionPtCut','LeadingTrackFinding','LeadingTrackPtCut','Tanc','TancVLoose','TancLoose','TancMedium','TancRaw','TancTight','AgainstElectron','AgainstMuon']
195  hpsDisc = ['Matching','DecayModeSelection','LooseIsolation','MediumIsolation','TightIsolation']
196  producer = analyzer.TauProducer.pythonValue()[1:-1]
197  ext = analyzer.ExtensionName.pythonValue()[1:-1]
198  keyword = producer + ext + "_"
199  for parName in plotPset.parameterNames_():
200  effplot = getattr(plotPset,parName).efficiency.pythonValue()[1:-1]
201  discriminator = parName[parName.find('ID')+len('ID'):-len('Efficiencies')]
202  if useOnly == 'tanc':
203  useThis = discriminator in tancDisc
204  elif useOnly == 'hps':
205  useThis = discriminator in hpsDisc
206  else :
207  useThis = True
208  if (effplot.find(keyword) != -1) and useThis:
209  monEl = '#PROCESSDIR#/'+effplot
210  psetName = effplot[effplot.rfind('/')+1:-5]
211  psetVal = cms.PSet(
212  standardEfficiencyParameters,
213  plots = cms.PSet(
214  dqmMonitorElements = cms.vstring(monEl),
215  processes = cms.vstring('test', 'reference')
216  )
217  )
218  setattr(ret,psetName,psetVal)
219  setattr(ret,'TauIdEffStepByStep',SetpByStep(analyzer, plotPset,useOnly))
220  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 108 of file ValidationUtils.py.

109 def SpawnPSet(lArgument, subPset):
110  """SpawnPSet(lArgument, subPset) --> cms.PSet\n
111  lArgument is a list containing a list of three strings/values:\n
112  1-name to give to the spawned pset\n
113  2-variable(s) to be changed\n
114  3-value(s) of the variable(s): SAME LENGTH OF 2-!\n
115  Supported types: int string float(converted to double)"""
116  ret = cms.PSet()
117  for spawn in lArgument:
118  if len(spawn) != 3:
119  print "ERROR! SpawnPSet uses argument of three data\n"
120  print self.__doc__
121  return None
122  if len(spawn[1]) != len(spawn[2]):
123  print "ERROR! Lists of arguments to replace must have the same length"
124  print self.__doc__
125  return None
126  spawnArg = copy.deepcopy(subPset)
127  for par, val in zip(spawn[1],spawn[2]):
128  if type(val) is str :
129  setattr(spawnArg,par,cms.string(val))
130  elif type(val) is int :
131  setattr(spawnArg,par,cms.int32(val))
132  elif type(val) is float :
133  setattr(spawnArg,par,cms.double(val))
134  setattr(ret,spawn[0],spawnArg)
135  return ret