Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-23 02:25:59

0001 import FWCore.ParameterSet.Config as cms
0002 
0003 # require the EXISTANCE of a track - not necessarily above any pt cut (above the basic 0.5 GeV filter)
0004 leadTrackFinding = cms.PSet(
0005       Producer = cms.InputTag('pfRecoTauDiscriminationByLeadingTrackFinding'),
0006       cut = cms.double(0.5)
0007 )
0008 
0009 # Require no prediscriminants
0010 noPrediscriminants = cms.PSet(
0011       BooleanOperator = cms.string("and"),
0012       )
0013 
0014 # Require the existence of a lead track
0015 requireLeadTrack = cms.PSet(
0016       BooleanOperator = cms.string("and"),
0017       leadTrack = leadTrackFinding,
0018       )
0019 
0020 # This is equivalent to the lead track case, and shoudl be deprecated.  
0021 #  Preserved for backwards compatibility
0022 requireLeadPion = cms.PSet(
0023       BooleanOperator = cms.string("and"),
0024       leadPion = leadTrackFinding,
0025       )
0026 
0027 def subParameterSets(pSet):
0028    ''' Generator to return all sub-PSets in a PSet '''
0029    for name, value in pSet.parameters_().items():
0030       if isinstance(value, cms.PSet):
0031          yield getattr(pSet, name)
0032 
0033 # For RECO type taus, where the tau producer is [tauType]Producer 
0034 import re
0035 recoTauTypeMapperRegex = re.compile("(\w*)Producer")
0036 def recoTauTypeMapper(tauProducer):
0037    return recoTauTypeMapperRegex.match(tauProducer).group(1)
0038 
0039 # For taus where the producer name is the type, like "allLayer1Taus", etc
0040 producerIsTauTypeMapper = lambda tauProducer: tauProducer
0041 
0042 def adaptTauDiscriminator(discriminator, newTauProducer='shrinkingConePFTauProducer',
0043       oldTauTypeMapper=recoTauTypeMapper, newTauTypeMapper=recoTauTypeMapper,
0044       preservePFTauProducer = False):
0045    ''' Change a TauDiscriminator to use a different tau/prediscriminant sources
0046 
0047    Tau discriminators use the following convention: 
0048         [tauType]DiscriminationByXXX
0049 
0050    i.e. fixedConePFTauDiscriminationByIsolation,
0051    allLayer1TausDiscriminationByIsolation, etc
0052 
0053    However, the mapping of tauType to tau producer name is not constant.  In
0054    RECO, the form is [tauType]Producer.  In PAT, the producer is just named
0055    [tauType].  To manage this oldTauTypeMapper and newTauTypeMapper are
0056    functions with signature f(str) that translate a TauProducer name (like
0057    shrinkingConePFTauProducer) to its type (shrinkingConePFTau).  Two types of
0058    mapping are provided, 
0059         * recoTauTypeMapper
0060               shrinkingConePFTauProducer->shrinkingConePFTau
0061         * producerIsTauTypeMapper
0062               allLayer1Taus->allLayer1Taus
0063 
0064    '''
0065 
0066    oldTauProducer = discriminator.PFTauProducer
0067    if isinstance(newTauProducer, str):
0068       newTauProducer = cms.InputTag(newTauProducer)
0069 
0070    # This is useful for the PF2PAT case where you wish to set the producer name
0071    # seperately
0072    if not preservePFTauProducer: 
0073       discriminator.PFTauProducer = newTauProducer
0074 
0075    oldTauType = oldTauTypeMapper(oldTauProducer.value())
0076    newTauType = newTauTypeMapper(newTauProducer.value())
0077 
0078    replacementRegex = re.compile(oldTauType)
0079 
0080    # Adapt all the prediscriminants
0081    for prediscriminant in subParameterSets(discriminator.Prediscriminants):
0082       oldProducer = prediscriminant.Producer.value() 
0083       # Replace the old tau type by the new tau type in the prediscrimant
0084       # producer
0085       prediscriminant.Producer = cms.InputTag(replacementRegex.sub(newTauType,
0086          oldProducer))
0087 
0088 def adaptTauDiscriminatorSequence(sequence, **kwargs):
0089    def fixer(discriminator):
0090       if hasattr(discriminator, "Prediscriminants"):
0091          adaptTauDiscriminator(discriminator, **kwargs)
0092    sequence.visit(fixer)
0093 
0094 def setTauSource(discriminator, newTauProducer):
0095    ''' Same as adaptTauDiscriminator, kept for backwards compatibility'''
0096    adaptTauDiscriminator(discriminator, newTauProducer)
0097