CMS 3D CMS Logo

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.

00005                                                                  :
00006     """CreatePlotEntry(analyzer, discriminatorLabel)\n
00007     Creates a PSet with the informations used by DQMHistEffProducer\n
00008     where to find the numerator and denominator\n
00009     where to put the new plot and how to name it\n
00010     which variables control"""
00011 
00012     producer = analyzer.TauProducer.pythonValue()[1:-1]
00013     ext = analyzer.ExtensionName.pythonValue()[1:-1]
00014     if discriminatorLabel == None:
00015         num = 'RecoTauV/%s%s_Matched/%sMatched_vs_#PAR#TauVisible'%(producer,ext,producer)
00016         #out = 'RecoTauV/%s%s_Matched/PFJetMatchingEff#PAR#'%(producer,ext)
00017         if producer.find('caloReco') != -1:
00018             out = 'RecoTauV/%s%s_Matched/CaloJetMatchingEff#PAR#'%(producer,ext)
00019         else:
00020             out = 'RecoTauV/%s%s_Matched/PFJetMatchingEff#PAR#'%(producer,ext)
00021     else:
00022         num = 'RecoTauV/%s%s_%s/%s_vs_#PAR#TauVisible'%(producer,ext,discriminatorLabel,discriminatorLabel)
00023         if discriminatorLabel.find('DiscriminationBy') != -1:
00024             hname = discriminatorLabel[(discriminatorLabel.find('DiscriminationBy')+len('DiscriminationBy')):]
00025         else:
00026             hname = discriminatorLabel[(discriminatorLabel.find('Discrimination')+len('Discrimination')):]
00027         out = 'RecoTauV/%s%s_%s/%sEff#PAR#'%(producer,ext,discriminatorLabel,hname)
00028 
00029     den = 'RecoTauV/%s%s_ReferenceCollection/nRef_Taus_vs_#PAR#TauVisible'%(producer,ext)
00030     ret = cms.PSet(
00031         numerator = cms.string(num),
00032         denominator = cms.string(den),
00033         efficiency = cms.string(out),
00034         parameter = cms.vstring('pt', 'eta', 'phi', 'energy'),
00035         stepByStep = cms.bool(step)
00036         )
00037     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.

00039                                                    :
00040     """NameVariable(analyzer, discriminatorLabel)\n
00041     returns a string with the name of the pset created by CreatePlotEntry"""
00042     #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!
00043     if analyzer.TauProducer.pythonValue()[1:-1] == 'shrinkingConePFTauProducer':
00044         if analyzer.ExtensionName.pythonValue()[1:-1] == 'Tanc':
00045             first='ShrinkingConeTanc'
00046         elif analyzer.ExtensionName.pythonValue()[1:-1] == 'LeadingPion':
00047             first='PFTauHighEfficiencyLeadingPion'
00048         elif analyzer.ExtensionName.pythonValue()[1:-1] == "":
00049             first='PFTauHighEfficiency'
00050         else:
00051             print 'Case not found check the available cases in Validation/RecoTau/python/ValidationUtils.py -- NameVariable'
00052             first=analyzer.TauProducer.pythonValue()[1:-1]+analyzer.ExtensionName.pythonValue()[1:-1]
00053     elif analyzer.TauProducer.pythonValue()[1:-1] == 'hpsPFTauProducer':
00054         first='HPS'
00055     elif analyzer.TauProducer.pythonValue()[1:-1] == 'hpsTancTaus':
00056         first='HPSTanc'+analyzer.ExtensionName.value()
00057     elif analyzer.TauProducer.pythonValue()[1:-1] == 'caloRecoTauProducer':
00058         first='CaloTau'
00059     else:
00060         print 'Case not found check the available cases in Validation/RecoTau/python/ValidationUtils.py -- NameVariable'
00061         first=analyzer.TauProducer.pythonValue()[1:-1]+analyzer.ExtensionName.pythonValue()[1:-1]
00062     
00063     if discriminatorLabel == None:
00064         last = 'Matching'
00065     else:
00066         if discriminatorLabel.find('DiscriminationBy') != -1:
00067             last = discriminatorLabel[(discriminatorLabel.find('DiscriminationBy')+len('DiscriminationBy')):]
00068             if last.find('TaNCfr') != -1:
00069                 last = last[len('TaNCfr'):]
00070         else:
00071             last = discriminatorLabel[(discriminatorLabel.find('DiscriminationAgainst')+len('DiscriminationAgainst')):]+"Rejection"
00072 
00073     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.

00075                                 :
00076     """PlotAnalyzer(pset, analyzer)\n
00077     fills a PSet that contains all the performance plots for a anlyzer\n
00078     pset is the PSet to fill/add"""
00079 
00080     setattr(pset,NameVariable(analyzer),CreatePlotEntry(analyzer))
00081 
00082     for currentDiscriminator in analyzer.discriminators:
00083         label = currentDiscriminator.discriminator.pythonValue()[1:-1]
00084         step = currentDiscriminator.plotStep.value()
00085         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.

00137                                            :
00138     """SetpByStep(analyzer, plotPset) --> PSet\n
00139      This function produces the parameter set stepBystep for the EDAnalyzer DQMHistPlotter starting from the PSet produced for DQMHistEffProducer and the analyzer to plot"""
00140     standardEfficiencyOverlay = cms.PSet(
00141         parameter = cms.vstring('pt', 'eta', 'phi', 'energy'),
00142         title = cms.string('TauId step by step efficiencies'),
00143         xAxis = cms.string('#PAR#'),
00144         yAxis = cms.string('efficiency'),
00145         legend = cms.string('efficiency_overlay'),
00146         labels = cms.vstring('pt', 'eta')
00147         )
00148     ret = cms.PSet(
00149         standardEfficiencyOverlay,
00150         plots = cms.VPSet()
00151         )
00152     producer = analyzer.TauProducer.pythonValue()[1:-1]
00153     ext = analyzer.ExtensionName.pythonValue()[1:-1]
00154     keyword = producer + ext + "_"
00155     counter = 0
00156     tancDisc = ['Matching','DecayModeSelection','LeadingPionPtCut','LeadingTrackFinding','LeadingTrackPtCut','Tanc','TancVLoose','TancLoose','TancMedium','TancRaw','TancTight','AgainstElectron','AgainstMuon']
00157     hpsDisc = ['Matching','DecayModeSelection','LooseIsolation','MediumIsolation','TightIsolation']
00158     for parName in plotPset.parameterNames_():
00159         isToBePlotted = getattr(plotPset,parName).stepByStep.value()
00160         if isToBePlotted:
00161             effplot = getattr(plotPset,parName).efficiency.pythonValue()[1:-1]
00162             discriminator = parName[parName.find('ID')+len('ID'):-len('Efficiencies')]
00163             if useOnly == 'tanc':
00164                 useThis = discriminator in tancDisc
00165             elif useOnly == 'hps':
00166                 useThis = discriminator in hpsDisc
00167             else :
00168                 useThis = True
00169             if (effplot.find(keyword) != -1) and useThis:
00170                 monEl = '#PROCESSDIR#/'+effplot
00171                 counter = counter + 1
00172                 drawOpt = 'eff_overlay0%s'%(counter)
00173                 psetName = effplot[effplot.rfind('/')+1:-8]
00174                 ret.plots.append(cms.PSet(
00175                     dqmMonitorElements = cms.vstring(monEl),
00176                     process = cms.string('test'),
00177                     drawOptionEntry = cms.string(drawOpt),
00178                     legendEntry = cms.string(psetName)
00179                     ))
00180     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.

00098                              :
00099     """SetSequence(seqence)\n
00100     This Function return a PSet of the sequence given to be used by DQMHistEffProducer"""
00101     pset = cms.PSet()
00102     scanner = Scanner()
00103     sequence.visit(scanner)
00104     for analyzer in scanner.modules():#The first one is the sequence itself
00105         if type(analyzer) is cms.EDAnalyzer:
00106             PlotAnalyzer(pset, analyzer)
00107     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.

00182                                                    :
00183     """SpwnDrawJobs(analyzer, plotPset) --> cms.PSet\n
00184     This function produces the parameter set drawJobs for the EDAnalyzer DQMHistPlotter starting from the PSet produced for DQMHistEffProducer and the analyzer to plot"""
00185     standardEfficiencyParameters = cms.PSet(
00186         parameter = cms.vstring('pt', 'eta', 'phi', 'energy'),
00187         xAxis = cms.string('#PAR#'),
00188         yAxis = cms.string('efficiency'),
00189         legend = cms.string('efficiency'),
00190         labels = cms.vstring('pt', 'eta'),
00191         drawOptionSet = cms.string('efficiency')
00192         )
00193     ret = cms.PSet()
00194     tancDisc = ['Matching','DecayModeSelection','LeadingPionPtCut','LeadingTrackFinding','LeadingTrackPtCut','Tanc','TancVLoose','TancLoose','TancMedium','TancRaw','TancTight','AgainstElectron','AgainstMuon']
00195     hpsDisc = ['Matching','DecayModeSelection','LooseIsolation','MediumIsolation','TightIsolation']
00196     producer = analyzer.TauProducer.pythonValue()[1:-1]
00197     ext = analyzer.ExtensionName.pythonValue()[1:-1]
00198     keyword = producer + ext + "_"
00199     for parName in plotPset.parameterNames_():
00200         effplot = getattr(plotPset,parName).efficiency.pythonValue()[1:-1]
00201         discriminator = parName[parName.find('ID')+len('ID'):-len('Efficiencies')]
00202         if useOnly == 'tanc':
00203             useThis = discriminator in tancDisc
00204         elif useOnly == 'hps':
00205             useThis = discriminator in hpsDisc
00206         else :
00207             useThis = True
00208         if (effplot.find(keyword) != -1) and useThis:
00209             monEl = '#PROCESSDIR#/'+effplot
00210             psetName = effplot[effplot.rfind('/')+1:-5]
00211             psetVal = cms.PSet(
00212                 standardEfficiencyParameters,
00213                 plots = cms.PSet(
00214                     dqmMonitorElements = cms.vstring(monEl),
00215                     processes = cms.vstring('test', 'reference')
00216                     )
00217             )
00218             setattr(ret,psetName,psetVal)
00219     setattr(ret,'TauIdEffStepByStep',SetpByStep(analyzer, plotPset,useOnly))
00220     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.

00109                                  :
00110     """SpawnPSet(lArgument, subPset) --> cms.PSet\n
00111     lArgument is a list containing a list of three strings/values:\n
00112            1-name to give to the spawned pset\n
00113            2-variable(s) to be changed\n
00114            3-value(s) of the variable(s): SAME LENGTH OF 2-!\n
00115            Supported types: int string float(converted to double)"""
00116     ret = cms.PSet()
00117     for spawn in lArgument:
00118         if len(spawn) != 3:
00119             print "ERROR! SpawnPSet uses argument of three data\n"
00120             print self.__doc__
00121             return None
00122         if len(spawn[1]) != len(spawn[2]):
00123             print "ERROR! Lists of arguments to replace must have the same length"
00124             print self.__doc__
00125             return None
00126         spawnArg = copy.deepcopy(subPset)
00127         for par, val in zip(spawn[1],spawn[2]):
00128             if type(val) is str :
00129                 setattr(spawnArg,par,cms.string(val))
00130             elif type(val) is int :
00131                 setattr(spawnArg,par,cms.int32(val))
00132             elif type(val) is float :
00133                 setattr(spawnArg,par,cms.double(val))
00134         setattr(ret,spawn[0],spawnArg)
00135     return ret