CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/PhysicsTools/PatAlgos/python/tools/tauTools.py

Go to the documentation of this file.
00001 import FWCore.ParameterSet.Config as cms
00002 
00003 from PhysicsTools.PatAlgos.tools.coreTools import *
00004 from FWCore.GuiBrowsers.ConfigToolBase import *
00005 from PhysicsTools.PatAlgos.tools.helpers import applyPostfix
00006 from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
00007 from RecoTauTag.RecoTau.TauDiscriminatorTools import *
00008 
00009 def redoPFTauDiscriminators(process,
00010                             oldPFTauLabel = cms.InputTag('shrinkingConePFTauProducer'),
00011                             newPFTauLabel = cms.InputTag('shrinkingConePFTauProducer'),
00012                             tauType = 'shrinkingConePFTau', postfix = ""):
00013     print 'Tau discriminators: ', oldPFTauLabel, '->', newPFTauLabel
00014     print 'Tau type: ', tauType
00015     #oldPFTauLabel.setModuleLabel(oldPFTauLabel.getModuleLabel()+postfix)
00016     tauSrc = 'PFTauProducer'
00017 
00018     tauDiscriminationSequence = None
00019 
00020     if tauType == 'hpsPFTau':
00021         process.patHPSPFTauDiscrimination = process.produceAndDiscriminateHPSPFTaus.copy()
00022         # remove producers
00023         for iname in process.patHPSPFTauDiscrimination.moduleNames():
00024             if not (iname.find("DiscriminationBy")>-1 or iname.find("DiscriminationAgainst")>-1):
00025                 process.patHPSPFTauDiscrimination.remove(getattr(process,iname) )
00026         tauDiscriminationSequence = cloneProcessingSnippet(process, process.patHPSPFTauDiscrimination, postfix)
00027 
00028     elif tauType == 'hpsTancTaus': #to be checked if correct
00029         process.patHPSTaNCPFTauDiscrimination = process.hpsTancTauInitialSequence.copy()
00030         process.patHPSTaNCPFTauDiscrimination *= process.hpsTancTauDiscriminantSequence
00031         # remove producers
00032         for iname in process.patHPSTaNCPFTauDiscrimination.moduleNames():
00033             if not (iname.find("DiscriminationBy")>-1 or iname.find("DiscriminationAgainst")>-1):
00034                 process.patHPSTaNCPFTauDiscrimination.remove(getattr(process,iname) )
00035         tauDiscriminationSequence = cloneProcessingSnippet(process, process.patHPSTaNCPFTauDiscrimination, postfix)
00036 
00037     elif tauType == 'fixedConePFTau':
00038         process.patFixedConePFTauDiscrimination = process.produceAndDiscriminateFixedConePFTaus.copy()
00039         # remove producers
00040         for iname in process.patFixedConePFTauDiscrimination.moduleNames():
00041             if not (iname.find("DiscriminationBy")>-1 or iname.find("DiscriminationAgainst")>-1):
00042                 process.patFixedConePFTauDiscrimination.remove(getattr(process,iname) )
00043         tauDiscriminationSequence =  cloneProcessingSnippet(process, process.patFixedConePFTauDiscrimination, postfix)
00044 
00045     elif tauType == 'shrinkingConePFTau': #shr cone with TaNC
00046         process.patShrinkingConePFTauDiscrimination = process.produceAndDiscriminateShrinkingConePFTaus.copy()
00047         process.patShrinkingConePFTauDiscrimination *= process.produceShrinkingConeDiscriminationByTauNeuralClassifier
00048         # remove producers
00049         for iname in process.patShrinkingConePFTauDiscrimination.moduleNames():
00050             if not (iname.find("DiscriminationBy")>-1 or iname.find("DiscriminationAgainst")>-1):
00051                 process.patShrinkingConePFTauDiscrimination.remove(getattr(process,iname) )
00052         tauDiscriminationSequence =  cloneProcessingSnippet(process, process.patShrinkingConePFTauDiscrimination, postfix)
00053 
00054     elif tauType == 'caloTau':
00055         # fill calo sequence by discriminants
00056         process.patCaloTauDiscrimination = process.tautagging.copy()
00057         # remove producers
00058         for iname in process.patCaloTauDiscrimination.moduleNames():
00059             if not (iname.find("DiscriminationBy")>-1 or iname.find("DiscriminationAgainst")>-1):
00060                 process.patCaloTauDiscrimination.remove(getattr(process,iname) )
00061         tauDiscriminationSequence =  cloneProcessingSnippet(process, process.patCaloTauDiscrimination, postfix)
00062         tauSrc = 'CaloTauProducer'
00063     else:
00064         raise StandardError, "Unkown tauType: '%s'"%tauType
00065 
00066     applyPostfix(process,"patDefaultSequence",postfix).replace(
00067         applyPostfix(process,"patTaus",postfix),
00068         tauDiscriminationSequence*applyPostfix(process,"patTaus",postfix)
00069     )
00070 
00071     massSearchReplaceParam(tauDiscriminationSequence, tauSrc, oldPFTauLabel, newPFTauLabel)
00072 
00073 # switch to CaloTau collection
00074 def switchToCaloTau(process,
00075                     pfTauLabelOld = cms.InputTag('shrinkingConePFTauProducer'),
00076                     pfTauLabelNew = cms.InputTag('caloRecoTauProducer'),
00077                     patTauLabel = "",
00078                     postfix = ""):
00079     print ' Taus: ', pfTauLabelOld, '->', pfTauLabelNew
00080 
00081     caloTauLabel = pfTauLabelNew
00082     applyPostfix(process, "tauMatch" + patTauLabel, postfix).src = caloTauLabel
00083     applyPostfix(process, "tauGenJetMatch"+ patTauLabel, postfix).src = caloTauLabel
00084 
00085     applyPostfix(process, "patTaus" + patTauLabel, postfix).tauSource = caloTauLabel
00086     applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = _buildIDSourcePSet('caloRecoTau', classicTauIDSources, postfix)
00087 #    applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = cms.PSet(        
00088 #        leadingTrackFinding = cms.InputTag("caloRecoTauDiscriminationByLeadingTrackFinding" + postfix),
00089 #        leadingTrackPtCut   = cms.InputTag("caloRecoTauDiscriminationByLeadingTrackPtCut" + postfix),
00090 #        trackIsolation      = cms.InputTag("caloRecoTauDiscriminationByTrackIsolation" + postfix),
00091 #        ecalIsolation       = cms.InputTag("caloRecoTauDiscriminationByECALIsolation" + postfix),
00092 #        byIsolation         = cms.InputTag("caloRecoTauDiscriminationByIsolation" + postfix),
00093 #        againstElectron     = cms.InputTag("caloRecoTauDiscriminationAgainstElectron" + postfix),
00094 #        againstMuon         = cms.InputTag("caloRecoTauDiscriminationAgainstMuon" + postfix)
00095 #    )
00096     ## Isolation is somewhat an issue, so we start just by turning it off
00097     print "NO PF Isolation will be computed for CaloTau (this could be improved later)"
00098     applyPostfix(process, "patTaus" + patTauLabel, postfix).isolation   = cms.PSet()
00099     applyPostfix(process, "patTaus" + patTauLabel, postfix).isoDeposits = cms.PSet()
00100     applyPostfix(process, "patTaus" + patTauLabel, postfix).userIsolation = cms.PSet()
00101 
00102     ## adapt cleanPatTaus
00103     if hasattr(process, "cleanPatTaus" + patTauLabel + postfix):
00104         getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = \
00105       'tauID("leadingTrackFinding") > 0.5 & tauID("leadingTrackPtCut") > 0.5' \
00106      + ' & tauID("byIsolation") > 0.5 & tauID("againstElectron") > 0.5 & (signalTracks.size() = 1 | signalTracks.size() = 3)'
00107 
00108 def _buildIDSourcePSet(pfTauType, idSources, postfix =""):
00109     """ Build a PSet defining the tau ID sources to embed into the pat::Tau """
00110     output = cms.PSet()
00111     for label, discriminator in idSources:
00112         setattr(output, label, cms.InputTag(pfTauType + discriminator + postfix))
00113     return output
00114 
00115 def _switchToPFTau(process,
00116                    pfTauLabelOld,
00117                    pfTauLabelNew,
00118                    pfTauType,
00119                    idSources,
00120                    patTauLabel = "",
00121                    postfix = ""):
00122     """internal auxiliary function to switch to **any** PFTau collection"""  
00123     print ' Taus: ', pfTauLabelOld, '->', pfTauLabelNew
00124     
00125     applyPostfix(process, "tauMatch" + patTauLabel, postfix).src = pfTauLabelNew
00126     applyPostfix(process, "tauGenJetMatch" + patTauLabel, postfix).src = pfTauLabelNew
00127     
00128     applyPostfix(process, "tauIsoDepositPFCandidates" + patTauLabel, postfix).src = pfTauLabelNew
00129     applyPostfix(process, "tauIsoDepositPFCandidates" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew
00130     applyPostfix(process, "tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).src = pfTauLabelNew
00131     applyPostfix(process, "tauIsoDepositPFChargedHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew
00132     applyPostfix(process, "tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).src = pfTauLabelNew
00133     applyPostfix(process, "tauIsoDepositPFNeutralHadrons" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew
00134     applyPostfix(process, "tauIsoDepositPFGammas" + patTauLabel, postfix).src = pfTauLabelNew
00135     applyPostfix(process, "tauIsoDepositPFGammas" + patTauLabel, postfix).ExtractorPSet.tauSource = pfTauLabelNew
00136     
00137     applyPostfix(process, "patTaus" + patTauLabel, postfix).tauSource = pfTauLabelNew
00138     applyPostfix(process, "patTaus" + patTauLabel, postfix).tauIDSources = _buildIDSourcePSet(pfTauType, idSources, postfix)
00139 
00140     applyPostfix(process, "cleanPatTaus" + patTauLabel, postfix).preselection = \
00141       'tauID("leadingTrackFinding") > 0.5 & tauID("leadingPionPtCut") > 0.5 & tauID("byIsolationUsingLeadingPion") > 0.5' \
00142      + ' & tauID("againstMuon") > 0.5 & tauID("againstElectron") > 0.5' \
00143      + ' & (signalPFChargedHadrCands.size() = 1 | signalPFChargedHadrCands.size() = 3)'
00144 
00145 # Name mapping for classic tau ID sources (present for fixed and shrinkingCones)
00146 classicTauIDSources = [
00147     ("leadingTrackFinding", "DiscriminationByLeadingTrackFinding"),
00148     ("leadingTrackPtCut", "DiscriminationByLeadingTrackPtCut"),
00149     ("trackIsolation", "DiscriminationByTrackIsolation"),
00150     ("ecalIsolation", "DiscriminationByECALIsolation"),
00151     ("byIsolation", "DiscriminationByIsolation"),
00152     ("againstElectron", "DiscriminationAgainstElectron"),
00153     ("againstMuon", "DiscriminationAgainstMuon") ]
00154 
00155 classicPFTauIDSources = [
00156     ("leadingPionPtCut", "DiscriminationByLeadingPionPtCut"),
00157     ("trackIsolationUsingLeadingPion", "DiscriminationByTrackIsolationUsingLeadingPion"),
00158     ("ecalIsolationUsingLeadingPion", "DiscriminationByECALIsolationUsingLeadingPion"),
00159     ("byIsolationUsingLeadingPion", "DiscriminationByIsolationUsingLeadingPion")]
00160 
00161 # Tau Neural Classifier Discriminators
00162 tancTauIDSources = [
00163     ("byTaNC", "DiscriminationByTaNC"),
00164     ("byTaNCfrOnePercent", "DiscriminationByTaNCfrOnePercent"),
00165     ("byTaNCfrHalfPercent", "DiscriminationByTaNCfrHalfPercent"),
00166     ("byTaNCfrQuarterPercent", "DiscriminationByTaNCfrQuarterPercent"),
00167     ("byTaNCfrTenthPercent", "DiscriminationByTaNCfrTenthPercent") ]
00168 
00169 # Hadron-plus-strip(s) (HPS) Tau Discriminators
00170 hpsTauIDSources = [
00171     ("decayModeFinding", "DiscriminationByDecayModeFinding"),
00172     ("byVLooseIsolation", "DiscriminationByVLooseIsolation"),
00173     ("byLooseIsolation", "DiscriminationByLooseIsolation"),
00174     ("byMediumIsolation", "DiscriminationByMediumIsolation"),
00175     ("byTightIsolation", "DiscriminationByTightIsolation"),
00176     ("againstElectronLoose", "DiscriminationByLooseElectronRejection"),
00177     ("againstElectronMedium", "DiscriminationByMediumElectronRejection"),
00178     ("againstElectronTight", "DiscriminationByTightElectronRejection"),
00179     ("againstMuonLoose", "DiscriminationByLooseMuonRejection"),
00180     ("againstMuonTight", "DiscriminationByTightMuonRejection") ]
00181 
00182 # Discriminators of new HPS + TaNC combined Tau id. algorithm
00183 hpsTancTauIDSources = [
00184     ("leadingTrackFinding", "DiscriminationByLeadingTrackFinding"),
00185     ("leadingTrackPtCut", "DiscriminationByLeadingTrackPtCut"),
00186     ("leadingPionPtCut", "DiscriminationByLeadingPionPtCut"),
00187     ("byTaNCraw", "DiscriminationByTancRaw"),
00188     ("byTaNC", "DiscriminationByTanc"),
00189     ("byTaNCvloose", "DiscriminationByTancVLoose"),
00190     ("byTaNCloose", "DiscriminationByTancLoose"),
00191     ("byTaNCmedium", "DiscriminationByTancMedium"),
00192     ("byTaNCtight", "DiscriminationByTancTight"),
00193     ("decayModeFinding", "DiscriminationByDecayModeSelection"),
00194     ("byHPSvloose", "DiscriminationByVLooseIsolation"),
00195     ("byHPSloose", "DiscriminationByLooseIsolation"),
00196     ("byHPSmedium", "DiscriminationByMediumIsolation"),
00197     ("byHPStight", "DiscriminationByTightIsolation"),
00198     ("againstElectronLoose", "DiscriminationByLooseElectronRejection"),
00199     ("againstElectronMedium", "DiscriminationByMediumElectronRejection"),
00200     ("againstElectronTight", "DiscriminationByTightElectronRejection"),
00201     ("againstMuonLoose", "DiscriminationByLooseMuonRejection"),
00202     ("againstMuonTight", "DiscriminationByTightMuonRejection") ]
00203 
00204 # switch to PFTau collection produced for fixed dR = 0.07 signal cone size
00205 def switchToPFTauFixedCone(process,
00206                            pfTauLabelOld = cms.InputTag('shrinkingConePFTauProducer'),
00207                            pfTauLabelNew = cms.InputTag('fixedConePFTauProducer'),
00208                            patTauLabel = "",
00209                            postfix = ""):
00210     fixedConeIDSources = copy.copy(classicTauIDSources)
00211     fixedConeIDSources.extend(classicPFTauIDSources)
00212 
00213     _switchToPFTau(process, pfTauLabelOld, pfTauLabelNew, 'fixedConePFTau', fixedConeIDSources,
00214                    patTauLabel = patTauLabel, postfix = postfix)
00215 
00216 # switch to PFTau collection produced for shrinking signal cone of size dR = 5.0/Et(PFTau)
00217 def switchToPFTauShrinkingCone(process,
00218                                pfTauLabelOld = cms.InputTag('shrinkingConePFTauProducer'),
00219                                pfTauLabelNew = cms.InputTag('shrinkingConePFTauProducer'),
00220                                patTauLabel = "",
00221                                postfix = ""):
00222     shrinkingIDSources = copy.copy(classicTauIDSources)
00223     shrinkingIDSources.extend(classicPFTauIDSources)
00224     # Only shrinkingCone has associated TaNC discriminators, so add them here
00225     shrinkingIDSources.extend(tancTauIDSources)
00226     
00227     _switchToPFTau(process, pfTauLabelOld, pfTauLabelNew, 'shrinkingConePFTau', shrinkingIDSources,
00228                    patTauLabel = patTauLabel, postfix = postfix)
00229 
00230 # switch to hadron-plus-strip(s) (HPS) PFTau collection
00231 def switchToPFTauHPS(process, 
00232                      pfTauLabelOld = cms.InputTag('shrinkingConePFTauProducer'),
00233                      pfTauLabelNew = cms.InputTag('hpsPFTauProducer'),
00234                      patTauLabel = "",
00235                      postfix = ""):
00236     _switchToPFTau(process, pfTauLabelOld, pfTauLabelNew, 'hpsPFTau', hpsTauIDSources,
00237                    patTauLabel = patTauLabel, postfix = postfix)
00238     
00239     ## adapt cleanPatTaus
00240     if hasattr(process, "cleanPatTaus" + patTauLabel + postfix):
00241         getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = \
00242       'pt > 15 & abs(eta) < 2.3 & tauID("decayModeFinding") > 0.5 & tauID("byLooseIsolation") > 0.5' \
00243      + ' & tauID("againstMuonTight") > 0.5 & tauID("againstElectronLoose") > 0.5'
00244 
00245 # switch to hadron-plus-strip(s) (HPS) PFTau collection
00246 def switchToPFTauHPSpTaNC(process, 
00247                           pfTauLabelOld = cms.InputTag('shrinkingConePFTauProducer'),
00248                           pfTauLabelNew = cms.InputTag('hpsTancTaus'),
00249                           patTauLabel = "",
00250                           postfix = ""):
00251     _switchToPFTau(process, pfTauLabelOld, pfTauLabelNew, 'hpsTancTaus', hpsTancTauIDSources,
00252                    patTauLabel = patTauLabel, postfix = postfix)
00253     
00254     ## adapt cleanPatTaus
00255     if hasattr(process, "cleanPatTaus" + patTauLabel + postfix):
00256         getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = \
00257       'pt > 15 & abs(eta) < 2.3 & tauID("decayModeFinding") > 0.5 & tauID("byHPSloose") > 0.5' \
00258      + ' & tauID("againstMuonTight") > 0.5 & tauID("againstElectronLoose") > 0.5'
00259 
00260 # Select switcher by string
00261 def switchToPFTauByType(process,
00262                         pfTauType = None,
00263                         pfTauLabelNew = None,
00264                         pfTauLabelOld = cms.InputTag('shrinkingConePFTauProducer'),
00265                         patTauLabel = "",
00266                         postfix = "" ):
00267     mapping = { 'shrinkingConePFTau' : switchToPFTauShrinkingCone,
00268                 'fixedConePFTau' : switchToPFTauFixedCone,
00269                 'hpsPFTau' : switchToPFTauHPS,
00270                 'caloRecoTau' : switchToCaloTau,
00271                 'hpsTancPFTau' : switchToPFTauHPSpTaNC }
00272     mapping[pfTauType](process, pfTauLabelOld = pfTauLabelOld, pfTauLabelNew = pfTauLabelNew,
00273                        patTauLabel = patTauLabel, postfix = postfix)
00274 
00275 # switch to PFTau collection that was default in PAT production in CMSSW_3_1_x release series
00276 def switchTo31Xdefaults(process):
00277     switchToPFTauFixedCone(process)
00278     process.cleanPatTaus.preselection = cms.string('tauID("byIsolation") > 0')
00279     
00280 class AddTauCollection(ConfigToolBase):
00281 
00282     """ Add a new collection of taus. Takes the configuration from the
00283     already configured standard tau collection as starting point;
00284     replaces before calling addTauCollection will also affect the
00285     new tau collections
00286     """
00287     _label='addTauCollection'
00288     _defaultParameters=dicttypes.SortedKeysDict()
00289     def __init__(self):
00290         ConfigToolBase.__init__(self)
00291         self.addParameter(self._defaultParameters, 'tauCollection',
00292                           self._defaultValue, 'Input tau collection', cms.InputTag)
00293         self.addParameter(self._defaultParameters, 'algoLabel',
00294                           self._defaultValue, "label to indicate the tau algorithm (e.g.'shrinkingCone')", str)
00295         self.addParameter(self._defaultParameters, 'typeLabel',
00296                           self._defaultValue, "label to indicate the type of constituents (either 'PFTau' or 'Tau')", str)
00297         self.addParameter(self._defaultParameters, 'doPFIsoDeposits',
00298                           True, "run sequence for computing particle-flow based IsoDeposits")
00299         self.addParameter(self._defaultParameters, 'standardAlgo',
00300                           "shrinkingCone", "standard algorithm label of the collection from which the clones " \
00301                          + "for the new tau collection will be taken from " \
00302                          + "(note that this tau collection has to be available in the event before hand)")
00303         self.addParameter(self._defaultParameters, 'standardType',
00304                           "PFTau", "standard constituent type label of the collection from which the clones " \
00305                          + " for the new tau collection will be taken from "\
00306                          + "(note that this tau collection has to be available in the event before hand)")
00307         
00308         self._parameters=copy.deepcopy(self._defaultParameters)
00309         self._comment = ""
00310         
00311     def getDefaultParameters(self):
00312         return self._defaultParameters
00313 
00314     def __call__(self,process,
00315                  tauCollection      = None,
00316                  algoLabel          = None,
00317                  typeLabel          = None,
00318                  doPFIsoDeposits    = None,
00319                  standardAlgo       = None,
00320                  standardType       = None):
00321 
00322         if tauCollection is None:
00323             tauCollection = self._defaultParameters['tauCollection'].value
00324         if algoLabel is None:
00325             algoLabel = self._defaultParameters['algoLabel'].value
00326         if typeLabel is None:
00327             typeLabel = self._defaultParameters['typeLabel'].value
00328         if doPFIsoDeposits is None:
00329             doPFIsoDeposits = self._defaultParameters['doPFIsoDeposits'].value
00330         if standardAlgo is None:
00331             standardAlgo = self._defaultParameters['standardAlgo'].value
00332         if standardType is None:
00333             standardType = self._defaultParameters['standardType'].value
00334 
00335         self.setParameter('tauCollection', tauCollection)
00336         self.setParameter('algoLabel', algoLabel)
00337         self.setParameter('typeLabel', typeLabel)
00338         self.setParameter('doPFIsoDeposits', doPFIsoDeposits)
00339         self.setParameter('standardAlgo', standardAlgo)
00340         self.setParameter('standardType', standardType)
00341    
00342         self.apply(process) 
00343         
00344     def toolCode(self, process):        
00345         tauCollection = self._parameters['tauCollection'].value
00346         algoLabel = self._parameters['algoLabel'].value
00347         typeLabel = self._parameters['typeLabel'].value
00348         doPFIsoDeposits = self._parameters['doPFIsoDeposits'].value
00349         standardAlgo = self._parameters['standardAlgo'].value
00350         standardType = self._parameters['standardType'].value
00351 
00352         ## disable computation of particle-flow based IsoDeposits
00353         ## in case tau is of CaloTau type
00354         if typeLabel == 'Tau':
00355 #            print "NO PF Isolation will be computed for CaloTau (this could be improved later)"
00356             doPFIsoDeposits = False
00357  
00358         ## create old module label from standardAlgo
00359         ## and standardType and return
00360         def oldLabel(prefix = ''):
00361             if prefix == '':
00362                 return "patTaus"
00363             else:
00364                 return prefix + "PatTaus"
00365 
00366         ## capitalize first character of appended part
00367         ## when creating new module label
00368         ## (giving e.g. "patTausCaloRecoTau")
00369         def capitalize(label):
00370             return label[0].capitalize() + label[1:]    
00371 
00372         ## create new module label from old module
00373         ## label and return
00374         def newLabel(oldLabel):
00375             newLabel = oldLabel
00376             if ( oldLabel.find(standardAlgo) >= 0 and oldLabel.find(standardType) >= 0 ):
00377                 oldLabel = oldLabel.replace(standardAlgo, algoLabel).replace(standardType, typeLabel)
00378             else:
00379                 oldLabel = oldLabel + capitalize(algoLabel + typeLabel)
00380             return oldLabel
00381 
00382         ## clone module and add it to the patDefaultSequence
00383         def addClone(hook, **replaceStatements):
00384             ## create a clone of the hook with corresponding
00385             ## parameter replacements
00386             newModule = getattr(process, hook).clone(**replaceStatements)
00387             ## add the module to the sequence
00388             addModuleToSequence(hook, newModule)
00389 
00390         ## clone module for computing particle-flow IsoDeposits
00391         def addPFIsoDepositClone(hook, **replaceStatements):
00392             newModule = getattr(process, hook).clone(**replaceStatements)
00393             newModuleIsoDepositExtractor = getattr(newModule, "ExtractorPSet")
00394             setattr(newModuleIsoDepositExtractor, "tauSource", getattr(newModule, "src"))
00395             addModuleToSequence(hook, newModule)
00396             
00397         ## add module to the patDefaultSequence
00398         def addModuleToSequence(hook, newModule):
00399             hookModule = getattr(process, hook)
00400             ## add the new module with standardAlgo &
00401             ## standardType replaced in module label
00402             setattr(process, newLabel(hook), newModule)
00403             ## add new module to default sequence
00404             ## just behind the hookModule
00405             process.patDefaultSequence.replace( hookModule, hookModule*newModule )        
00406 
00407         ## add a clone of patTaus
00408         addClone(oldLabel(), tauSource = tauCollection)
00409         
00410         ## add a clone of selectedPatTaus    
00411         addClone(oldLabel('selected'), src = cms.InputTag(newLabel(oldLabel())))
00412         
00413         ## add a clone of cleanPatTaus    
00414         addClone(oldLabel('clean'), src=cms.InputTag(newLabel(oldLabel('selected'))))
00415 
00416         ## get attributes of new module
00417         newTaus = getattr(process, newLabel(oldLabel()))
00418 
00419         ## add a clone of gen tau matching
00420         addClone('tauMatch', src = tauCollection)
00421         addClone('tauGenJetMatch', src = tauCollection)
00422 
00423         ## add a clone of IsoDeposits computed based on particle-flow
00424         if doPFIsoDeposits:
00425             addPFIsoDepositClone('tauIsoDepositPFCandidates', src = tauCollection)
00426             addPFIsoDepositClone('tauIsoDepositPFChargedHadrons', src = tauCollection)
00427             addPFIsoDepositClone('tauIsoDepositPFNeutralHadrons', src = tauCollection)
00428             addPFIsoDepositClone('tauIsoDepositPFGammas', src = tauCollection)
00429 
00430         ## fix label for input tag
00431         def fixInputTag(x): x.setModuleLabel(newLabel(x.moduleLabel))
00432 
00433         ## provide patTau inputs with individual labels
00434         fixInputTag(newTaus.genParticleMatch)
00435         fixInputTag(newTaus.genJetMatch)
00436         fixInputTag(newTaus.isoDeposits.pfAllParticles)
00437         fixInputTag(newTaus.isoDeposits.pfNeutralHadron)
00438         fixInputTag(newTaus.isoDeposits.pfChargedHadron)
00439         fixInputTag(newTaus.isoDeposits.pfGamma)
00440         fixInputTag(newTaus.userIsolation.pfAllParticles.src)
00441         fixInputTag(newTaus.userIsolation.pfNeutralHadron.src)
00442         fixInputTag(newTaus.userIsolation.pfChargedHadron.src)
00443         fixInputTag(newTaus.userIsolation.pfGamma.src)
00444         
00445         ## set discriminators
00446         ## (using switchTauCollection functions)
00447         oldTaus = getattr(process, oldLabel())
00448 #        if typeLabel == 'Tau':
00449 #            switchToCaloTau(process,
00450 #                            pfTauLabel = getattr(oldTaus, "tauSource"),
00451 #                            caloTauLabel = getattr(newTaus, "tauSource"),
00452 #                            patTauLabel = capitalize(algoLabel + typeLabel))
00453 #        else:
00454         switchToPFTauByType(process, pfTauType = algoLabel + typeLabel,
00455                                 pfTauLabelNew = getattr(newTaus, "tauSource"),
00456                                 pfTauLabelOld = getattr(oldTaus, "tauSource"),
00457                                 patTauLabel = capitalize(algoLabel + typeLabel))
00458        
00459 addTauCollection=AddTauCollection()