CMS 3D CMS Logo

Functions

pfTools Namespace Reference

Functions

def adaptPFElectrons
def adaptPFMuons
def adaptPFPhotons
def adaptPFTaus
def addPFCandidates
def reconfigurePF2PATTaus
def removeMCMatchingPF2PAT
def switchToPFJets
def switchToPFMET
def tauTypeInPF2PAT
def usePF2PAT
def warningIsolation

Function Documentation

def pfTools::adaptPFElectrons (   process,
  module,
  postfix 
)

Definition at line 60 of file pfTools.py.

00061                                              :
00062     # module.useParticleFlow = True
00063     print "Adapting PF Electrons "
00064     print "********************* "
00065     warningIsolation()
00066     print
00067     module.useParticleFlow = True
00068     module.userIsolation   = cms.PSet()
00069     module.isoDeposits = cms.PSet(
00070         pfChargedHadrons = cms.InputTag("isoDepElectronWithCharged" + postfix),
00071         pfNeutralHadrons = cms.InputTag("isoDepElectronWithNeutral" + postfix),
00072         pfPhotons = cms.InputTag("isoDepElectronWithPhotons" + postfix)
00073         )
00074     module.isolationValues = cms.PSet(
00075         pfChargedHadrons = cms.InputTag("isoValElectronWithCharged" + postfix),
00076         pfNeutralHadrons = cms.InputTag("isoValElectronWithNeutral" + postfix),
00077         pfPhotons = cms.InputTag("isoValElectronWithPhotons" + postfix)
00078         )
00079 
00080     # COLIN: since we take the egamma momentum for pat Electrons, we must
00081     # match the egamma electron to the gen electrons, and not the PFElectron.
00082     # -> do not uncomment the line below.
00083     # process.electronMatch.src = module.pfElectronSource
00084     # COLIN: how do we depend on this matching choice?
00085 
00086     print " PF electron source:", module.pfElectronSource
00087     print " isolation  :"
00088     print module.isolationValues
00089     print " isodeposits: "
00090     print module.isoDeposits
00091     print
00092 
00093     print "removing traditional isolation"
00094 
00095     removeIfInSequence(process,  "patElectronIsolation",  "patDefaultSequence", postfix)

def pfTools::adaptPFMuons (   process,
  module,
  postfix = "" 
)

Definition at line 32 of file pfTools.py.

00033                                             :
00034     print "Adapting PF Muons "
00035     print "***************** "
00036     warningIsolation()
00037     print
00038     module.useParticleFlow = True
00039     module.userIsolation   = cms.PSet()
00040     module.isoDeposits = cms.PSet(
00041         pfChargedHadrons = cms.InputTag("isoDepMuonWithCharged" + postfix),
00042         pfNeutralHadrons = cms.InputTag("isoDepMuonWithNeutral" + postfix),
00043         pfPhotons = cms.InputTag("isoDepMuonWithPhotons" + postfix)
00044         )
00045     module.isolationValues = cms.PSet(
00046         pfChargedHadrons = cms.InputTag("isoValMuonWithCharged" + postfix),
00047         pfNeutralHadrons = cms.InputTag("isoValMuonWithNeutral" + postfix),
00048         pfPhotons = cms.InputTag("isoValMuonWithPhotons" + postfix)
00049         )
00050     # matching the pfMuons, not the standard muons.
00051     applyPostfix(process,"muonMatch",postfix).src = module.pfMuonSource
00052 
00053     print " muon source:", module.pfMuonSource
00054     print " isolation  :",
00055     print module.isolationValues
00056     print " isodeposits: "
00057     print module.isoDeposits
00058     print
00059 

def pfTools::adaptPFPhotons (   process,
  module 
)

Definition at line 96 of file pfTools.py.

00097                                   :
00098     raise RuntimeError, "Photons are not supported yet"

def pfTools::adaptPFTaus (   process,
  tauType = 'shrinkingConePFTau',
  postfix = "" 
)

Definition at line 228 of file pfTools.py.

00229                                                                      :
00230     # Set up the collection used as a preselection to use this tau type
00231     if tauType != 'hpsPFTau' :
00232         reconfigurePF2PATTaus(process, tauType, postfix=postfix)
00233     else:
00234         reconfigurePF2PATTaus(process, tauType,
00235                               ["DiscriminationByLooseChargedIsolation","DiscriminationByLooseIsolation"],
00236                               ["DiscriminationByDecayModeFinding"],
00237                               postfix=postfix)
00238     applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix)
00239 
00240     redoPFTauDiscriminators(process,
00241                             cms.InputTag(tauType+'Producer'),
00242                             applyPostfix(process,"patTaus", postfix).tauSource,
00243                             tauType, postfix=postfix)
00244 
00245     switchToPFTauByType(process, pfTauType=tauType,
00246                         pfTauLabelNew=applyPostfix(process,"patTaus", postfix).tauSource,
00247                         pfTauLabelOld=cms.InputTag(tauType+'Producer'),
00248                         postfix=postfix)
00249 
00250     applyPostfix(process,"makePatTaus", postfix).remove(
00251         applyPostfix(process,"patPFCandidateIsoDepositSelection", postfix)
00252         )
00253 
#helper function for PAT on PF2PAT sample
def pfTools::addPFCandidates (   process,
  src,
  patLabel = 'PFParticles',
  cut = "",
  postfix = "" 
)

Definition at line 259 of file pfTools.py.

00260                                                                          :
00261     from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles
00262     # make modules
00263     producer = patPFParticles.clone(pfCandidateSource = src)
00264     filter   = cms.EDFilter("PATPFParticleSelector",
00265                     src = cms.InputTag("pat" + patLabel),
00266                     cut = cms.string(cut))
00267     counter  = cms.EDFilter("PATCandViewCountFilter",
00268                     minNumber = cms.uint32(0),
00269                     maxNumber = cms.uint32(999999),
00270                     src       = cms.InputTag("pat" + patLabel))
00271     # add modules to process
00272     setattr(process, "pat"         + patLabel, producer)
00273     setattr(process, "selectedPat" + patLabel, filter)
00274     setattr(process, "countPat"    + patLabel, counter)
00275     # insert into sequence
00276     getattr(process, "patDefaultSequence"+postfix).replace(
00277         applyPostfix(process, "patCandidateSummary", postfix),
00278         producer+applyPostfix(process, "patCandidateSummary", postfix)
00279     )
00280     getattr(process, "patDefaultSequence"+postfix).replace(
00281         applyPostfix(process, "selectedPatCandidateSummary", postfix),
00282         filter+applyPostfix(process, "selectedPatCandidateSummary", postfix)
00283     )
00284     index = len( applyPostfix( process, "patDefaultSequence", postfix ).moduleNames() )
00285     applyPostfix( process, "patDefaultSequence", postfix ).insert( index, counter )
00286     # summary tables
00287     applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel))
00288     applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
00289 

def pfTools::reconfigurePF2PATTaus (   process,
  tauType = 'shrinkingConePFTau',
  pf2patSelection = ["DiscriminationByIsolation",
  DiscriminationByLeadingPionPtCut,
  selectionDependsOn = ["DiscriminationByLeadingTrackFinding"],
  producerFromType = lambda producer: producer+"Producer",
  postfix = "" 
)

Definition at line 101 of file pfTools.py.

00105                                       : producer+"Producer",
00106       postfix = ""):
00107    print "patTaus will be produced from taus of type: %s that pass %s" \
00108          % (tauType, pf2patSelection)
00109 
00110    #get baseSequence
00111    baseSequence = getattr(process,"pfTausBaseSequence"+postfix)
00112    #clean baseSequence from old modules
00113    for oldBaseModuleName in baseSequence.moduleNames():
00114        oldBaseModule = getattr(process,oldBaseModuleName)
00115        baseSequence.remove(oldBaseModule)
00116 
00117    # Get the prototype of tau producer to make, i.e. fixedConePFTauProducer
00118    producerName = producerFromType(tauType)
00119    # Set as the source for the pf2pat taus (pfTaus) selector
00120    applyPostfix(process,"pfTaus", postfix).src = producerName+postfix
00121    # Start our pf2pat taus base sequence
00122    oldTau = getattr(process,'pfTausProducer'+postfix)
00123    ## copy tau and setup it properly
00124    newTau = getattr(process,producerName).clone()
00125    ## adapted to new structure in RecoTauProducers PLEASE CHECK!!!
00126    if tauType=='shrinkingConePFTau': #Only shrCone tau has modifiers???
00127        # like this, it should have it already definied??
00128        newTau.modifiers[1] = cms.PSet(
00129            pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
00130            name = cms.string('pfTauTTIworkaround'+postfix),
00131            plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
00132            )
00133        newTau.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
00134    elif tauType=='fixedConePFTau':
00135        newTau.piZeroSrc = "pfJetsPiZeros"+postfix
00136    elif tauType=='hpsPFTau':
00137        newTau = process.combinatoricRecoTaus.clone()
00138        newTau.piZeroSrc="pfJetsLegacyHPSPiZeros"+postfix
00139        newTau.modifiers[2] = cms.PSet(
00140            pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
00141            name = cms.string('pfTauTTIworkaround'+postfix),
00142            plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
00143         )
00144        from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
00145        cloneProcessingSnippet(process, process.produceHPSPFTaus, postfix)
00146        massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
00147                               "PFTauProducer",
00148                               cms.InputTag("combinatoricRecoTaus"),
00149                               cms.InputTag("pfTausBase"+postfix) )
00150        getattr(process,"hpsPFTauProducer"+postfix).src = "pfTausBase"+postfix
00151 
00152    newTau.builders[0].pfCandSrc = oldTau.builders[0].pfCandSrc
00153    newTau.jetRegionSrc = oldTau.jetRegionSrc
00154    newTau.jetSrc = oldTau.jetSrc
00155 
00156    # replace old tau producer by new one put it into baseSequence
00157    setattr(process,"pfTausBase"+postfix,newTau)
00158    baseSequence += getattr(process,"pfTausBase"+postfix)
00159    if tauType=='hpsPFTau':
00160        baseSequence += getattr(process,"produceHPSPFTaus"+postfix)
00161    #make custom mapper to take postfix into account (could have gone with lambda of lambda but... )
00162    def producerIsTauTypeMapperWithPostfix(tauProducer):
00163        return lambda x: producerIsTauTypeMapper(tauProducer)+x.group(1)+postfix
00164 
00165    def recoTauTypeMapperWithGroup(tauProducer):
00166        return "%s(.*)"%recoTauTypeMapper(tauProducer)
00167 
00168    # Get our prediscriminants
00169    for predisc in selectionDependsOn:
00170       # Get the prototype
00171       originalName = tauType+predisc # i.e. fixedConePFTauProducerDiscriminationByLeadingTrackFinding
00172       clonedName = "pfTausBase"+predisc+postfix
00173       clonedDisc = getattr(process, originalName).clone()
00174       # Register in our process
00175       setattr(process, clonedName, clonedDisc)
00176       baseSequence += getattr(process, clonedName)
00177 
00178       tauCollectionToSelect = None
00179       if tauType != 'hpsPFTau' :
00180           tauCollectionToSelect = "pfTausBase"+postfix
00181           #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
00182       else:
00183           tauCollectionToSelect = "hpsPFTauProducer"+postfix
00184       # Adapt this discriminator for the cloned prediscriminators
00185       adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
00186                             oldTauTypeMapper=recoTauTypeMapperWithGroup,
00187                             newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
00188                             preservePFTauProducer=True)
00189       clonedDisc.PFTauProducer = tauCollectionToSelect
00190 
00191    # Reconfigure the pf2pat PFTau selector discrimination sources
00192    applyPostfix(process,"pfTaus", postfix).discriminators = cms.VPSet()
00193    for selection in pf2patSelection:
00194       # Get our discriminator that will be used to select pfTaus
00195       originalName = tauType+selection
00196       clonedName = "pfTausBase"+selection+postfix
00197       clonedDisc = getattr(process, originalName).clone()
00198       # Register in our process
00199       setattr(process, clonedName, clonedDisc)
00200 
00201       tauCollectionToSelect = None
00202 
00203       if tauType != 'hpsPFTau' :
00204           tauCollectionToSelect = cms.InputTag("pfTausBase"+postfix)
00205           #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
00206       else:
00207           tauCollectionToSelect = cms.InputTag("hpsPFTauProducer"+postfix)
00208       #Adapt our cloned discriminator to the new prediscriminants
00209       adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
00210                             oldTauTypeMapper=recoTauTypeMapperWithGroup,
00211                             newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
00212                             preservePFTauProducer=True)
00213       clonedDisc.PFTauProducer = tauCollectionToSelect
00214       baseSequence += clonedDisc
00215       # Add this selection to our pfTau selectors
00216       applyPostfix(process,"pfTaus", postfix).discriminators.append(cms.PSet(
00217          discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
00218       # Set the input of the final selector.
00219       if tauType != 'hpsPFTau':
00220           applyPostfix(process,"pfTaus", postfix).src = "pfTausBase"+postfix
00221       else:
00222           # If we are using HPS taus, we need to take the output of the clenaed
00223           # collection
00224           applyPostfix(process,"pfTaus", postfix).src = "hpsPFTauProducer"+postfix
00225 
00226 
00227 
def pfTools::removeMCMatchingPF2PAT (   process,
  postfix = "" 
)

Definition at line 355 of file pfTools.py.

00356                                                  :
00357     from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching
00358     removeIfInSequence(process,  "genForPF2PATSequence",  "patDefaultSequence", postfix)
00359     removeMCMatching(process, ['All'],postfix)
00360 

def pfTools::switchToPFJets (   process,
  input = cms.InputTag('pfNoTau'),
  algo = 'AK5',
  postfix = "",
  jetCorrections = ('AK5PFchs', ['L1FastJet',
  L2Relative,
  L3Absolute 
)

Definition at line 312 of file pfTools.py.

00313                                                                                                                                                             :
00314 
00315     print "Switching to PFJets,  ", algo
00316     print "************************ "
00317     print "input collection: ", input
00318 
00319     if( algo == 'IC5' ):
00320         genJetCollection = cms.InputTag('iterativeCone5GenJetsNoNu')
00321     elif algo == 'AK5':
00322         genJetCollection = cms.InputTag('ak5GenJetsNoNu')
00323     elif algo == 'AK7':
00324         genJetCollection = cms.InputTag('ak7GenJetsNoNu')
00325     else:
00326         print 'bad jet algorithm:', algo, '! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin'
00327         sys.exit(1)
00328 
00329     # changing the jet collection in PF2PAT:
00330     from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo
00331     inputCollection = getattr(process,"pfJets"+postfix).src
00332     setattr(process, "pfJets"+postfix, jetAlgo( algo ) ) # problem for cfgBrowser
00333     getattr(process,"pfJets"+postfix).src = inputCollection
00334     inputJetCorrLabel=jetCorrections
00335     switchJetCollection(process,
00336                         input,
00337                         jetIdLabel = algo,
00338                         doJTA=True,
00339                         doBTagging=True,
00340                         jetCorrLabel=inputJetCorrLabel,
00341                         #doType1MET=False,
00342                         doType1MET=True,
00343                         genJetCollection = genJetCollection,
00344                         doJetID = True,
00345                         postfix = postfix
00346                         )
00347     # check whether L1FastJet is in the list of correction levels or not
00348     applyPostfix(process, "patJetCorrFactors", postfix).useRho  = False    
00349     for corr in inputJetCorrLabel[1]:
00350         if corr == 'L1FastJet':
00351             applyPostfix(process, "patJetCorrFactors", postfix).useRho = True
00352     applyPostfix(process, "patJets", postfix).embedCaloTowers   = False
00353     applyPostfix(process, "patJets", postfix).embedPFCandidates = True
00354 
#-- Remove MC dependence ------------------------------------------------------
def pfTools::switchToPFMET (   process,
  input = cms.InputTag('pfMET'),
  type1 = False,
  postfix = "" 
)

Definition at line 290 of file pfTools.py.

00291                                                                                :
00292     print 'MET: using ', input
00293     if( not type1 ):
00294         oldMETSource = applyPostfix(process, "patMETs",postfix).metSource
00295         applyPostfix(process, "patMETs",postfix).metSource = input
00296         applyPostfix(process, "patMETs",postfix).addMuonCorrections = False
00297         getattr(process, "patDefaultSequence"+postfix).remove(
00298         applyPostfix(process, "patMETCorrections",postfix)
00299         )
00300     else:
00301         # type1 corrected MET
00302         # name of coreccted MET hardcoded in PAT and meaningless
00303         print 'Apply type1 corrections for MET'
00304         applyPostfix(process, "metJESCorAK5CaloJet",postfix).inputUncorMetLabel = input.getModuleLabel()
00305         applyPostfix(process, "metJESCorAK5CaloJet",postfix).metType = 'PFMET'
00306         applyPostfix(process, "metJESCorAK5CaloJet",postfix).jetPTthreshold = 1.0
00307         applyPostfix(process, "patMETs",postfix).metSource = "metJESCorAK5CaloJet"+postfix
00308         applyPostfix(process, "patMETs",postfix).addMuonCorrections = False
00309         getattr(process, "patDefaultSequence"+postfix).remove(
00310             applyPostfix(process, "metJESCorAK5CaloJetMuons",postfix)
00311             )

def pfTools::tauTypeInPF2PAT (   process,
  tauType = 'shrinkingConePFTau',
  postfix = "" 
)

Definition at line 254 of file pfTools.py.

00255                                                                        :
00256     process.load("CommonTools.ParticleFlow.pfTaus_cff")
00257     applyPostfix(process, "pfTaus",postfix).src = cms.InputTag(tauType+'Producer'+postfix)
00258 

def pfTools::usePF2PAT (   process,
  runPF2PAT = True,
  jetAlgo = 'AK5',
  runOnMC = True,
  postfix = "",
  jetCorrections = ('AK5PFchs', ['L1FastJet',
  L2Relative,
  L3Absolute 
)
Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence

Definition at line 361 of file pfTools.py.

00362                                                                                                                                                         :
00363     # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT.
00364     # CREATE ADDITIONAL FUNCTIONS IF NEEDED.
00365 
00366     """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
00367 
00368     # -------- CORE ---------------
00369     if runPF2PAT:
00370         process.load("CommonTools.ParticleFlow.PF2PAT_cff")
00371         #add Pf2PAT *before* cloning so that overlapping modules are cloned too
00372         #process.patDefaultSequence.replace( process.patCandidates, process.PF2PAT+process.patCandidates)
00373         process.patPF2PATSequence = cms.Sequence( process.PF2PAT + process.patDefaultSequence)
00374     else:
00375         process.patPF2PATSequence = cms.Sequence( process.patDefaultSequence )
00376 
00377     if not postfix == "":
00378         from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
00379         cloneProcessingSnippet(process, process.patPF2PATSequence, postfix)
00380         #delete everything pat PF2PAT modules! if you want to test the postfixing for completeness
00381         #from PhysicsTools.PatAlgos.tools.helpers import listModules,listSequences
00382         #for module in listModules(process.patDefaultSequence):
00383         #    if not module.label() is None: process.__delattr__(module.label())
00384         #for sequence in listSequences(process.patDefaultSequence):
00385         #    if not sequence.label() is None: process.__delattr__(sequence.label())
00386         #del process.patDefaultSequence
00387 
00388     removeCleaning(process, postfix=postfix)
00389 
00390     # -------- OBJECTS ------------
00391     # Muons
00392     adaptPFMuons(process,
00393                  applyPostfix(process,"patMuons",postfix),
00394                  postfix)
00395 
00396     # Electrons
00397     adaptPFElectrons(process,
00398                      applyPostfix(process,"patElectrons",postfix),
00399                      postfix)
00400 
00401     # Photons
00402     print "Temporarily switching off photons completely"
00403 
00404     removeSpecificPATObjects(process,['Photons'],False,postfix)
00405     removeIfInSequence(process,  "patPhotonIsolation",  "patDefaultSequence", postfix)
00406 
00407     # Jets
00408     if runOnMC :
00409         switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
00410                         jetCorrections=jetCorrections )
00411         applyPostfix(process,"patDefaultSequence",postfix).replace(
00412             applyPostfix(process,"patJetGenJetMatch",postfix),
00413             getattr(process,"genForPF2PATSequence") *
00414             applyPostfix(process,"patJetGenJetMatch",postfix)
00415             )
00416     else :
00417         if not 'L2L3Residual' in jetCorrections[1]:
00418             print '#################################################'
00419             print 'WARNING! Not using L2L3Residual but this is data.'
00420             print 'If this is okay with you, disregard this message.'
00421             print '#################################################'
00422         switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
00423                         jetCorrections=jetCorrections )
00424 
00425     # Taus
00426     adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix )
00427     #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix )
00428     #adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix )
00429 
00430     # MET
00431     switchToPFMET(process, cms.InputTag('pfMET'+postfix), postfix=postfix)
00432 
00433     # Unmasked PFCandidates
00434     addPFCandidates(process,cms.InputTag('pfNoJet'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix)
00435 
00436     if runOnMC:
00437         process.load("CommonTools.ParticleFlow.genForPF2PAT_cff")
00438         getattr(process, "patDefaultSequence"+postfix).replace(
00439             applyPostfix(process,"patCandidates",postfix),
00440             process.genForPF2PATSequence+applyPostfix(process,"patCandidates",postfix)
00441             )
00442     else:
00443         removeMCMatchingPF2PAT( process, postfix )
00444 
00445     print "Done: PF2PAT interfaced to PAT, postfix=", postfix
def pfTools::warningIsolation ( )

Definition at line 29 of file pfTools.py.

00030                       :
00031     print "WARNING: particle based isolation must be studied"