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.

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

00214                                                                      :
00215     # Set up the collection used as a preselection to use this tau type    
00216     if tauType != 'hpsPFTau' :
00217         reconfigurePF2PATTaus(process, tauType, postfix=postfix)
00218     else:
00219         reconfigurePF2PATTaus(process, tauType,
00220                               ["DiscriminationByLooseIsolation"],
00221                               ["DiscriminationByDecayModeFinding"],
00222                               postfix=postfix)
00223     applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix)
00224     
00225     redoPFTauDiscriminators(process, 
00226                             cms.InputTag(tauType+'Producer'),
00227                             applyPostfix(process,"patTaus", postfix).tauSource,
00228                             tauType, postfix=postfix)
00229 
00230     switchToPFTauByType(process, pfTauType=tauType,
00231                         pfTauLabelNew=applyPostfix(process,"patTaus", postfix).tauSource,
00232                         pfTauLabelOld=cms.InputTag(tauType+'Producer'),
00233                         postfix=postfix)
00234 
00235     applyPostfix(process,"makePatTaus", postfix).remove(
00236         applyPostfix(process,"patPFCandidateIsoDepositSelection", postfix)
00237         )
00238 
#helper function for PAT on PF2PAT sample
def pfTools::addPFCandidates (   process,
  src,
  patLabel = 'PFParticles',
  cut = "",
  postfix = "" 
)

Definition at line 244 of file pfTools.py.

00245                                                                          :
00246     from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles
00247     # make modules
00248     producer = patPFParticles.clone(pfCandidateSource = src)
00249     filter   = cms.EDFilter("PATPFParticleSelector", 
00250                     src = cms.InputTag("pat" + patLabel), 
00251                     cut = cms.string(cut))
00252     counter  = cms.EDFilter("PATCandViewCountFilter",
00253                     minNumber = cms.uint32(0),
00254                     maxNumber = cms.uint32(999999),
00255                     src       = cms.InputTag("pat" + patLabel))
00256     # add modules to process
00257     setattr(process, "pat"         + patLabel, producer)
00258     setattr(process, "selectedPat" + patLabel, filter)
00259     setattr(process, "countPat"    + patLabel, counter)
00260     # insert into sequence
00261     getattr(process, "patDefaultSequence"+postfix).replace(
00262         applyPostfix(process, "patCandidateSummary", postfix),
00263         producer+applyPostfix(process, "patCandidateSummary", postfix)
00264     )
00265     getattr(process, "patDefaultSequence"+postfix).replace(
00266         applyPostfix(process, "selectedPatCandidateSummary", postfix),
00267         filter+applyPostfix(process, "selectedPatCandidateSummary", postfix)
00268     )
00269 
00270     tmpCountPatCandidates = applyPostfix(process, "countPatCandidates", postfix)
00271     tmpCountPatCandidates+=counter
00272     # summary tables
00273     applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel))
00274     applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
00275 
        
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        newTau.PFTauTagInfoProducer = cms.InputTag("pfTauTagInfoProducer"+postfix)
00137    elif tauType=='hpsPFTau':
00138        newTau = process.combinatoricRecoTaus.clone()
00139        newTau.piZeroSrc="pfJetsLegacyHPSPiZeros"+postfix
00140        newTau.modifiers[2] = cms.PSet(
00141            pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
00142            name = cms.string('pfTauTTIworkaround'+postfix),
00143            plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
00144         )
00145        from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
00146        cloneProcessingSnippet(process, process.produceHPSPFTaus, postfix)
00147        massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
00148                               "PFTauProducer",
00149                               cms.InputTag("combinatoricRecoTaus"),
00150                               cms.InputTag("pfTausBase"+postfix) )
00151        getattr(process,"hpsPFTauProducer"+postfix).src = "pfTausBase"+postfix
00152 
00153    if not tauType=='fixedConePFTau':
00154        newTau.builders[0].pfCandSrc = oldTau.builders[0].pfCandSrc
00155    newTau.jetSrc = oldTau.jetSrc
00156 
00157    # replace old tau producter by new one put it into baseSequence
00158    setattr(process,"pfTausBase"+postfix,newTau)
00159    baseSequence += getattr(process,"pfTausBase"+postfix)
00160    if tauType=='hpsPFTau':
00161        baseSequence += getattr(process,"produceHPSPFTaus"+postfix)   
00162    #make custom mapper to take postfix into account (could have gone with lambda of lambda but... )
00163    def producerIsTauTypeMapperWithPostfix(tauProducer):
00164        return lambda x: producerIsTauTypeMapper(tauProducer)+x.group(1)+postfix
00165 
00166    def recoTauTypeMapperWithGroup(tauProducer):
00167        return "%s(.*)"%recoTauTypeMapper(tauProducer)
00168 
00169    # Get our prediscriminants
00170    for predisc in selectionDependsOn:
00171       # Get the prototype
00172       originalName = tauType+predisc # i.e. fixedConePFTauProducerDiscriminationByLeadingTrackFinding
00173       clonedName = "pfTausBase"+predisc+postfix
00174       clonedDisc = getattr(process, originalName).clone()
00175       # Register in our process
00176       setattr(process, clonedName, clonedDisc)
00177       baseSequence += getattr(process, clonedName)
00178       if tauType != 'hpsPFTau' :
00179           clonedDisc.PFTauProducer = cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
00180       else:
00181           clonedDisc.PFTauProducer = cms.InputTag("hpsPFTauProducer"+postfix)
00182       # Adapt this discriminator for the cloned prediscriminators 
00183       adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
00184                             oldTauTypeMapper=recoTauTypeMapperWithGroup,
00185                             newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
00186                             preservePFTauProducer=True)
00187       clonedDisc.PFTauProducer = cms.InputTag("pfTausBase"+postfix)
00188    # Reconfigure the pf2pat PFTau selector discrimination sources
00189    applyPostfix(process,"pfTaus", postfix).discriminators = cms.VPSet()
00190    for selection in pf2patSelection:
00191       # Get our discriminator that will be used to select pfTaus
00192       originalName = tauType+selection
00193       clonedName = "pfTausBase"+selection+postfix
00194       clonedDisc = getattr(process, originalName).clone()
00195       # Register in our process
00196       setattr(process, clonedName, clonedDisc)
00197       if tauType != 'hpsPFTau' :
00198           clonedDisc.PFTauProducer = cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
00199       else:
00200           clonedDisc.PFTauProducer = cms.InputTag("hpsPFTauProducer"+postfix)
00201       # Adapt our cloned discriminator to the new prediscriminants
00202       adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
00203                             oldTauTypeMapper=recoTauTypeMapperWithGroup,
00204                             newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
00205                             preservePFTauProducer=True)
00206       clonedDisc.PFTauProducer = cms.InputTag("pfTausBase"+postfix)
00207       baseSequence += clonedDisc
00208       # Add this selection to our pfTau selectors
00209       applyPostfix(process,"pfTaus", postfix).discriminators.append(cms.PSet(
00210          discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
00211       applyPostfix(process,"pfTaus", postfix).src = "pfTausBase"+postfix
00212 
def pfTools::removeMCMatchingPF2PAT (   process,
  postfix = "" 
)

Definition at line 337 of file pfTools.py.

00338                                                  :
00339     from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching
00340     removeIfInSequence(process,  "genForPF2PATSequence",  "patDefaultSequence", postfix)
00341     removeMCMatching(process, ['All'],postfix)
00342 

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

Definition at line 298 of file pfTools.py.

00299                                                                                                                                             :
00300 
00301     print "Switching to PFJets,  ", algo
00302     print "************************ "
00303     print "input collection: ", input
00304 
00305     if( algo == 'IC5' ):
00306         genJetCollection = cms.InputTag('iterativeCone5GenJetsNoNu')
00307     elif algo == 'AK5':
00308         genJetCollection = cms.InputTag('ak5GenJetsNoNu')
00309     elif algo == 'AK7':
00310         genJetCollection = cms.InputTag('ak7GenJetsNoNu')
00311     else:
00312         print 'bad jet algorithm:', algo, '! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin'
00313         sys.exit(1)
00314 
00315     # changing the jet collection in PF2PAT:
00316     from PhysicsTools.PFCandProducer.Tools.jetTools import jetAlgo
00317     inputCollection = getattr(process,"pfJets"+postfix).src
00318     setattr(process, "pfJets"+postfix, jetAlgo( algo ) ) # problem for cfgBrowser
00319     getattr(process,"pfJets"+postfix).src = inputCollection
00320     inputJetCorrLabel=(algo+'PF',jetCorrections)
00321     switchJetCollection(process,
00322                         input,
00323                         jetIdLabel = algo,
00324                         doJTA=True,
00325                         doBTagging=True,
00326                         jetCorrLabel=inputJetCorrLabel, 
00327                         #doType1MET=False,
00328                         doType1MET=True,
00329                         genJetCollection = genJetCollection,
00330                         doJetID = True,
00331                         postfix = postfix
00332                         )
00333     
00334     applyPostfix(process, "patJets", postfix).embedCaloTowers   = False
00335     applyPostfix(process, "patJets", postfix).embedPFCandidates   = True
00336     
#-- Remove MC dependence ------------------------------------------------------
def pfTools::switchToPFMET (   process,
  input = cms.InputTag('pfMET'),
  type1 = False,
  postfix = "" 
)

Definition at line 276 of file pfTools.py.

00277                                                                                :
00278     print 'MET: using ', input
00279     if( not type1 ):
00280         oldMETSource = applyPostfix(process, "patMETs",postfix).metSource
00281         applyPostfix(process, "patMETs",postfix).metSource = input
00282         applyPostfix(process, "patMETs",postfix).addMuonCorrections = False
00283         getattr(process, "patDefaultSequence"+postfix).remove(
00284         applyPostfix(process, "patMETCorrections",postfix)
00285         )
00286     else:
00287         # type1 corrected MET
00288         # name of coreccted MET hardcoded in PAT and meaningless
00289         print 'Apply type1 corrections for MET'
00290         applyPostfix(process, "metJESCorAK5CaloJet",postfix).inputUncorMetLabel = input.getModuleLabel()
00291         applyPostfix(process, "metJESCorAK5CaloJet",postfix).metType = 'PFMET'
00292         applyPostfix(process, "metJESCorAK5CaloJet",postfix).jetPTthreshold = 1.0
00293         applyPostfix(process, "patMETs",postfix).metSource = "metJESCorAK5CaloJet"+postfix
00294         applyPostfix(process, "patMETs",postfix).addMuonCorrections = False
00295         getattr(process, "patDefaultSequence"+postfix).remove(
00296             applyPostfix(process, "metJESCorAK5CaloJetMuons",postfix)
00297             )

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

Definition at line 239 of file pfTools.py.

00239                                                                        : 
00240     process.load("PhysicsTools.PFCandProducer.pfTaus_cff")
00241     applyPostfix(process, "pfTaus",postfix).src = cms.InputTag(tauType+'Producer'+postfix)
00242             
00243 
def pfTools::usePF2PAT (   process,
  runPF2PAT = True,
  jetAlgo = 'AK5',
  runOnMC = True,
  postfix = "" 
)
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 343 of file pfTools.py.

00344                                                                                  :
00345     # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT.
00346     # CREATE ADDITIONAL FUNCTIONS IF NEEDED.
00347 
00348     """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
00349 
00350     # -------- CORE ---------------
00351     if runPF2PAT:
00352         process.load("PhysicsTools.PFCandProducer.PF2PAT_cff")
00353         #add Pf2PAT *before* cloning so that overlapping modules are cloned too
00354         #process.patDefaultSequence.replace( process.patCandidates, process.PF2PAT+process.patCandidates)
00355         process.patPF2PATSequence = cms.Sequence( process.PF2PAT + process.patDefaultSequence)
00356     else:
00357         process.patPF2PATSequence = cms.Sequence( process.patDefaultSequence )
00358         
00359     if not postfix == "":
00360         from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
00361         cloneProcessingSnippet(process, process.patPF2PATSequence, postfix)
00362         #delete everything pat PF2PAT modules! if you want to test the postfixing for completeness
00363         #from PhysicsTools.PatAlgos.tools.helpers import listModules,listSequences
00364         #for module in listModules(process.patDefaultSequence):
00365         #    if not module.label() is None: process.__delattr__(module.label())
00366         #for sequence in listSequences(process.patDefaultSequence):
00367         #    if not sequence.label() is None: process.__delattr__(sequence.label())
00368         #del process.patDefaultSequence
00369 
00370     removeCleaning(process, postfix=postfix)
00371 
00372     # -------- OBJECTS ------------
00373     # Muons
00374     adaptPFMuons(process, 
00375                  applyPostfix(process,"patMuons",postfix),
00376                  postfix)
00377 
00378     # Electrons
00379     adaptPFElectrons(process,
00380                      applyPostfix(process,"patElectrons",postfix),
00381                      postfix)
00382 
00383     # Photons
00384     print "Temporarily switching off photons completely"
00385 
00386     removeSpecificPATObjects(process,['Photons'],False,postfix)
00387     removeIfInSequence(process,  "patPhotonIsolation",  "patDefaultSequence", postfix)
00388 
00389     # Jets
00390     if runOnMC :
00391         switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
00392                         jetCorrections=['L1Offset','L2Relative','L3Absolute'] )
00393         applyPostfix(process,"patDefaultSequence",postfix).replace(
00394             applyPostfix(process,"patJetGenJetMatch",postfix),
00395             getattr(process,"genForPF2PATSequence") *
00396             applyPostfix(process,"patJetGenJetMatch",postfix)
00397             )
00398     else :
00399         switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
00400                         jetCorrections=['L1Offset','L2Relative','L3Absolute', 'L2L3Residual'] )
00401 
00402     # Taus
00403     adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix )
00404     #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix )
00405     #adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix )
00406 
00407     # MET
00408     switchToPFMET(process, cms.InputTag('pfMET'+postfix), postfix=postfix)
00409 
00410     # Unmasked PFCandidates
00411     addPFCandidates(process,cms.InputTag('pfNoJet'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix)
00412 
00413     if runOnMC:
00414         process.load("PhysicsTools.PFCandProducer.genForPF2PAT_cff")
00415         getattr(process, "patDefaultSequence"+postfix).replace(
00416             applyPostfix(process,"patCandidates",postfix),
00417             process.genForPF2PATSequence+applyPostfix(process,"patCandidates",postfix)
00418             )
00419     else:
00420         removeMCMatchingPF2PAT( process, postfix )
00421 
00422     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"