CMS 3D CMS Logo

Functions

pfTools Namespace Reference

Functions

def adaptPFElectrons
def adaptPFIsoElectrons
def adaptPFIsoMuons
def adaptPFMuons
def adaptPFPhotons
def adaptPFTaus
def adaptPVs
def addPFCandidates
def reconfigurePF2PATTaus
def removeMCMatchingPF2PAT
def switchToPFJets
def switchToPFMET
def tauTypeInPF2PAT
def useGsfElectrons
def usePF2PAT
def usePFIso
def warningIsolation

Function Documentation

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

Definition at line 135 of file pfTools.py.

00136                                              :
00137     # module.useParticleFlow = True
00138     print "Adapting PF Electrons "
00139     print "********************* "
00140     warningIsolation()
00141     print
00142     module.useParticleFlow = True
00143     module.pfElectronSource = cms.InputTag("pfIsolatedElectrons" + postfix)
00144     module.userIsolation   = cms.PSet()
00145     module.isoDeposits = cms.PSet(
00146         pfChargedHadrons = cms.InputTag("elPFIsoDepositCharged" + postfix),
00147         pfChargedAll = cms.InputTag("elPFIsoDepositChargedAll" + postfix),
00148         pfPUChargedHadrons = cms.InputTag("elPFIsoDepositPU" + postfix),
00149         pfNeutralHadrons = cms.InputTag("elPFIsoDepositNeutral" + postfix),
00150         pfPhotons = cms.InputTag("elPFIsoDepositGamma" + postfix)
00151         )
00152     module.isolationValues = cms.PSet(
00153         pfChargedHadrons = cms.InputTag("elPFIsoValueCharged04PFId"+ postfix),
00154         pfChargedAll = cms.InputTag("elPFIsoValueChargedAll04PFId"+ postfix),
00155         pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU04PFId" + postfix),
00156         pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral04PFId" + postfix),
00157         pfPhotons = cms.InputTag("elPFIsoValueGamma04PFId" + postfix)
00158         )
00159 
00160     # COLIN: since we take the egamma momentum for pat Electrons, we must
00161     # match the egamma electron to the gen electrons, and not the PFElectron.
00162     # -> do not uncomment the line below.
00163     # process.electronMatch.src = module.pfElectronSource
00164     # COLIN: how do we depend on this matching choice?
00165 
00166     print " PF electron source:", module.pfElectronSource
00167     print " isolation  :"
00168     print module.isolationValues
00169     print " isodeposits: "
00170     print module.isoDeposits
00171     print
00172 
00173     print "removing traditional isolation"
00174 
00175     removeIfInSequence(process,  "patElectronIsolation",  "patDefaultSequence", postfix)

def pfTools::adaptPFIsoElectrons (   process,
  module,
  postfix = "PFIso",
  dR = "04" 
)

Definition at line 48 of file pfTools.py.

00049                                                                      :
00050     #FIXME: adaptPFElectrons can use this function.
00051     module.isoDeposits = cms.PSet(
00052         pfChargedHadrons = cms.InputTag("elPFIsoDepositCharged" + postfix),
00053         pfChargedAll = cms.InputTag("elPFIsoDepositChargedAll" + postfix),
00054         pfPUChargedHadrons = cms.InputTag("elPFIsoDepositPU" + postfix),
00055         pfNeutralHadrons = cms.InputTag("elPFIsoDepositNeutral" + postfix),
00056         pfPhotons = cms.InputTag("elPFIsoDepositGamma" + postfix)
00057         )
00058     module.isolationValues = cms.PSet(
00059         pfChargedHadrons = cms.InputTag("elPFIsoValueCharged"+dR+"PFId"+ postfix),
00060         pfChargedAll = cms.InputTag("elPFIsoValueChargedAll"+dR+"PFId"+ postfix),
00061         pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU"+dR+"PFId" + postfix),
00062         pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral"+dR+"PFId" + postfix),
00063         pfPhotons = cms.InputTag("elPFIsoValueGamma"+dR+"PFId" + postfix)
00064         )
00065     module.isolationValuesNoPFId = cms.PSet(
00066         pfChargedHadrons = cms.InputTag("elPFIsoValueCharged"+dR+"NoPFId"+ postfix),
00067         pfChargedAll = cms.InputTag("elPFIsoValueChargedAll"+dR+"NoPFId"+ postfix),
00068         pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU"+dR+"NoPFId" + postfix),
00069         pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral"+dR+"NoPFId" + postfix),
00070         pfPhotons = cms.InputTag("elPFIsoValueGamma"+dR+"NoPFId" + postfix)
00071         )

def pfTools::adaptPFIsoMuons (   process,
  module,
  postfix = "PFIso",
  dR = "04" 
)

Definition at line 72 of file pfTools.py.

00073                                                                  :
00074     #FIXME: adaptPFMuons can use this function.
00075     module.isoDeposits = cms.PSet(
00076         pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix),
00077         pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix),
00078         pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix),
00079         pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix),
00080         pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix)
00081         )
00082     module.isolationValues = cms.PSet(
00083         pfChargedHadrons = cms.InputTag("muPFIsoValueCharged" + dR + postfix),
00084         pfChargedAll = cms.InputTag("muPFIsoValueChargedAll" + dR + postfix),
00085         pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU" + dR + postfix),
00086         pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral" + dR + postfix),
00087         pfPhotons = cms.InputTag("muPFIsoValueGamma" + dR + postfix)
00088         )

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

Definition at line 102 of file pfTools.py.

00103                                             :
00104     print "Adapting PF Muons "
00105     print "***************** "
00106     warningIsolation()
00107     print
00108     module.useParticleFlow = True
00109     module.pfMuonSource    = cms.InputTag("pfIsolatedMuons" + postfix)
00110     module.userIsolation   = cms.PSet()
00111     module.isoDeposits = cms.PSet(
00112         pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix),
00113         pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix),
00114         pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix),
00115         pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix),
00116         pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix)
00117         )
00118     module.isolationValues = cms.PSet(
00119         pfChargedHadrons = cms.InputTag("muPFIsoValueCharged04"+ postfix),
00120         pfChargedAll = cms.InputTag("muPFIsoValueChargedAll04"+ postfix),
00121         pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU04" + postfix),
00122         pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral04" + postfix),
00123         pfPhotons = cms.InputTag("muPFIsoValueGamma04" + postfix)
00124         )
00125     # matching the pfMuons, not the standard muons.
00126     applyPostfix(process,"muonMatch",postfix).src = module.pfMuonSource
00127 
00128     print " muon source:", module.pfMuonSource
00129     print " isolation  :",
00130     print module.isolationValues
00131     print " isodeposits: "
00132     print module.isoDeposits
00133     print
00134 

def pfTools::adaptPFPhotons (   process,
  module 
)

Definition at line 176 of file pfTools.py.

00177                                   :
00178     raise RuntimeError, "Photons are not supported yet"

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

Definition at line 322 of file pfTools.py.

00323                                                                      :
00324     # Set up the collection used as a preselection to use this tau type
00325     if tauType != 'hpsPFTau' :
00326         reconfigurePF2PATTaus(process, tauType, postfix=postfix)
00327     else:
00328         reconfigurePF2PATTaus(process, tauType,
00329                               ["DiscriminationByLooseCombinedIsolationDBSumPtCorr"],
00330                               ["DiscriminationByDecayModeFinding"],
00331                               postfix=postfix)
00332     # new default use unselected taus (selected only for jet cleaning)
00333     if tauType != 'hpsPFTau' :
00334         applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTausBase"+postfix)
00335     else:
00336         applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
00337     # to use preselected collection (old default) uncomment line below
00338     #applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix)
00339 
00340 
00341     redoPFTauDiscriminators(process,
00342                             cms.InputTag(tauType+'Producer'),
00343                             applyPostfix(process,"patTaus", postfix).tauSource,
00344                             tauType, postfix=postfix)
00345 
00346     switchToPFTauByType(process, pfTauType=tauType,
00347                         pfTauLabelNew=applyPostfix(process,"patTaus", postfix).tauSource,
00348                         pfTauLabelOld=cms.InputTag(tauType+'Producer'),
00349                         postfix=postfix)
00350 
00351     applyPostfix(process,"makePatTaus", postfix).remove(
00352         applyPostfix(process,"patPFCandidateIsoDepositSelection", postfix)
00353         )
00354 
#helper function for PAT on PF2PAT sample
def pfTools::adaptPVs (   process,
  pvCollection = cms.InputTag('offlinePrimaryVertices'),
  postfix = '' 
)

Definition at line 515 of file pfTools.py.

00516                                                                                       :
00517 
00518     print "Switching PV collection for PF2PAT:", pvCollection
00519     print "***********************************"
00520 
00521     # PV sources to be exchanged:
00522     pvExchange = ['Vertices','vertices','pvSrc','primaryVertices','srcPVs']
00523     # PV sources NOT to be exchanged:
00524     #noPvExchange = ['src','PVProducer','primaryVertexSrc','vertexSrc','primaryVertex']
00525 
00526     # find out all added jet collections (they don't belong to PF2PAT)
00527     interPostfixes = []
00528     for m in getattr(process,'patPF2PATSequence'+postfix).moduleNames():
00529         if m.startswith('patJets') and m.endswith(postfix) and not len(m)==len('patJets')+len(postfix):
00530             interPostfix = m.replace('patJets','')
00531             interPostfix = interPostfix.replace(postfix,'')
00532             interPostfixes.append(interPostfix)
00533 
00534     # exchange the primary vertex source of all relevant modules
00535     for m in getattr(process,'patPF2PATSequence'+postfix).moduleNames():
00536         modName = m.replace(postfix,'')
00537         # only if the module has a source with a relevant name
00538         for namePvSrc in pvExchange:
00539             if hasattr(getattr(process,m),namePvSrc):
00540                 # only if the module is not coming from an added jet collection
00541                 interPostFixFlag = False
00542                 for pfix in interPostfixes:
00543                     if modName.endswith(pfix):
00544                         interPostFixFlag = True
00545                         break
00546                 if not interPostFixFlag:
00547                     setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
00548 

def pfTools::addPFCandidates (   process,
  src,
  patLabel = 'PFParticles',
  cut = "",
  postfix = "" 
)

Definition at line 360 of file pfTools.py.

00361                                                                          :
00362     from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles
00363     # make modules
00364     producer = patPFParticles.clone(pfCandidateSource = src)
00365     filter   = cms.EDFilter("PATPFParticleSelector",
00366                     src = cms.InputTag("pat" + patLabel),
00367                     cut = cms.string(cut))
00368     counter  = cms.EDFilter("PATCandViewCountFilter",
00369                     minNumber = cms.uint32(0),
00370                     maxNumber = cms.uint32(999999),
00371                     src       = cms.InputTag("pat" + patLabel))
00372     # add modules to process
00373     setattr(process, "pat"         + patLabel, producer)
00374     setattr(process, "selectedPat" + patLabel, filter)
00375     setattr(process, "countPat"    + patLabel, counter)
00376     # insert into sequence
00377     getattr(process, "patDefaultSequence"+postfix).replace(
00378         applyPostfix(process, "patCandidateSummary", postfix),
00379         producer+applyPostfix(process, "patCandidateSummary", postfix)
00380     )
00381     getattr(process, "patDefaultSequence"+postfix).replace(
00382         applyPostfix(process, "selectedPatCandidateSummary", postfix),
00383         filter+applyPostfix(process, "selectedPatCandidateSummary", postfix)
00384     )
00385     index = len( applyPostfix( process, "patDefaultSequence", postfix ).moduleNames() )
00386     applyPostfix( process, "patDefaultSequence", postfix ).insert( index, counter )
00387     # summary tables
00388     applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel))
00389     applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
00390 

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

Definition at line 181 of file pfTools.py.

00185                                       : producer+"Producer",
00186       postfix = ""):
00187    print "patTaus will be produced from taus of type: %s that pass %s" \
00188          % (tauType, pf2patSelection)
00189 
00190    #get baseSequence
00191    baseSequence = getattr(process,"pfTausBaseSequence"+postfix)
00192    #clean baseSequence from old modules
00193    for oldBaseModuleName in baseSequence.moduleNames():
00194        oldBaseModule = getattr(process,oldBaseModuleName)
00195        baseSequence.remove(oldBaseModule)
00196 
00197    # Get the prototype of tau producer to make, i.e. fixedConePFTauProducer
00198    producerName = producerFromType(tauType)
00199    # Set as the source for the pf2pat taus (pfTaus) selector
00200    applyPostfix(process,"pfTaus", postfix).src = producerName+postfix
00201    # Start our pf2pat taus base sequence
00202    oldTauSansRefs = getattr(process,'pfTausProducerSansRefs'+postfix)
00203    oldTau = getattr(process,'pfTausProducer'+postfix)
00204    ## copy tau and setup it properly
00205    newTauSansRefs = None
00206    newTau = getattr(process,producerName).clone()
00207    ## adapted to new structure in RecoTauProducers PLEASE CHECK!!!
00208    if tauType=='shrinkingConePFTau':
00209        newTauSansRefs = getattr(process,producerName+"SansRefs").clone()
00210        newTauSansRefs.modifiers[1] = cms.PSet(
00211            pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
00212            name = cms.string('pfTauTTIworkaround'+postfix),
00213            plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
00214            )
00215        newTau.modifiers[1] = newTauSansRefs.modifiers[1]
00216        newTauSansRefs.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
00217        newTau.piZeroSrc = newTauSansRefs.piZeroSrc
00218        newTauSansRefs.builders[0].pfCandSrc = oldTauSansRefs.builders[0].pfCandSrc
00219        newTauSansRefs.jetRegionSrc = oldTauSansRefs.jetRegionSrc
00220        newTauSansRefs.jetSrc = oldTauSansRefs.jetSrc
00221    elif tauType=='fixedConePFTau':
00222        newTau.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
00223    elif tauType=='hpsPFTau':
00224        newTau = process.combinatoricRecoTaus.clone()
00225        newTau.piZeroSrc="pfJetsLegacyHPSPiZeros"+postfix
00226        newTau.modifiers[3] = cms.PSet(
00227            pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
00228            name = cms.string('pfTauTTIworkaround'+postfix),
00229            plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
00230            )
00231        from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
00232        cloneProcessingSnippet(process, process.produceHPSPFTaus, postfix)
00233        massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
00234                               "PFTauProducer",
00235                               cms.InputTag("combinatoricRecoTaus"),
00236                               cms.InputTag("pfTausBase"+postfix) )
00237        massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
00238                               "src",
00239                               cms.InputTag("combinatoricRecoTaus"),
00240                               cms.InputTag("pfTausBase"+postfix) )
00241 
00242    newTau.builders[0].pfCandSrc = oldTau.builders[0].pfCandSrc
00243    newTau.jetRegionSrc = oldTau.jetRegionSrc
00244    newTau.jetSrc = oldTau.jetSrc
00245 
00246    # replace old tau producer by new one put it into baseSequence
00247    setattr(process,"pfTausBase"+postfix,newTau)
00248    if tauType=='shrinkingConePFTau':
00249        setattr(process,"pfTausBaseSansRefs"+postfix,newTauSansRefs)
00250        getattr(process,"pfTausBase"+postfix).src = "pfTausBaseSansRefs"+postfix
00251        baseSequence += getattr(process,"pfTausBaseSansRefs"+postfix)
00252    baseSequence += getattr(process,"pfTausBase"+postfix)
00253    if tauType=='hpsPFTau':
00254        baseSequence += getattr(process,"produceHPSPFTaus"+postfix)
00255    #make custom mapper to take postfix into account (could have gone with lambda of lambda but... )
00256    def producerIsTauTypeMapperWithPostfix(tauProducer):
00257        return lambda x: producerIsTauTypeMapper(tauProducer)+x.group(1)+postfix
00258 
00259    def recoTauTypeMapperWithGroup(tauProducer):
00260        return "%s(.*)"%recoTauTypeMapper(tauProducer)
00261 
00262    # Get our prediscriminants
00263    for predisc in selectionDependsOn:
00264       # Get the prototype
00265       originalName = tauType+predisc # i.e. fixedConePFTauProducerDiscriminationByLeadingTrackFinding
00266       clonedName = "pfTausBase"+predisc+postfix
00267       clonedDisc = getattr(process, originalName).clone()
00268       # Register in our process
00269       setattr(process, clonedName, clonedDisc)
00270       baseSequence += getattr(process, clonedName)
00271 
00272       tauCollectionToSelect = None
00273       if tauType != 'hpsPFTau' :
00274           tauCollectionToSelect = "pfTausBase"+postfix
00275           #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
00276       else:
00277           tauCollectionToSelect = "hpsPFTauProducer"+postfix
00278       # Adapt this discriminator for the cloned prediscriminators
00279       adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
00280                             oldTauTypeMapper=recoTauTypeMapperWithGroup,
00281                             newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
00282                             preservePFTauProducer=True)
00283       clonedDisc.PFTauProducer = tauCollectionToSelect
00284 
00285    # Reconfigure the pf2pat PFTau selector discrimination sources
00286    applyPostfix(process,"pfTaus", postfix).discriminators = cms.VPSet()
00287    for selection in pf2patSelection:
00288       # Get our discriminator that will be used to select pfTaus
00289       originalName = tauType+selection
00290       clonedName = "pfTausBase"+selection+postfix
00291       clonedDisc = getattr(process, originalName).clone()
00292       # Register in our process
00293       setattr(process, clonedName, clonedDisc)
00294 
00295       tauCollectionToSelect = None
00296 
00297       if tauType != 'hpsPFTau' :
00298           tauCollectionToSelect = cms.InputTag("pfTausBase"+postfix)
00299           #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
00300       else:
00301           tauCollectionToSelect = cms.InputTag("hpsPFTauProducer"+postfix)
00302       #Adapt our cloned discriminator to the new prediscriminants
00303       adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
00304                             oldTauTypeMapper=recoTauTypeMapperWithGroup,
00305                             newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
00306                             preservePFTauProducer=True)
00307       clonedDisc.PFTauProducer = tauCollectionToSelect
00308       baseSequence += clonedDisc
00309       # Add this selection to our pfTau selectors
00310       applyPostfix(process,"pfTaus", postfix).discriminators.append(cms.PSet(
00311          discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
00312       # Set the input of the final selector.
00313       if tauType != 'hpsPFTau':
00314           applyPostfix(process,"pfTaus", postfix).src = "pfTausBase"+postfix
00315       else:
00316           # If we are using HPS taus, we need to take the output of the clenaed
00317           # collection
00318           applyPostfix(process,"pfTaus", postfix).src = "hpsPFTauProducer"+postfix
00319 
00320 
00321 
def pfTools::removeMCMatchingPF2PAT (   process,
  postfix = "",
  outputModules = ['out'] 
)

Definition at line 509 of file pfTools.py.

00510                                                                         :
00511     from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching
00512     removeIfInSequence(process, "genForPF2PATSequence", "patDefaultSequence", postfix)
00513     removeMCMatching(process, names=['All'], postfix=postfix, outputModules=outputModules)
00514 

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

Definition at line 447 of file pfTools.py.

00448                                                                                                                                                                                                :
00449 
00450     print "Switching to PFJets,  ", algo
00451     print "************************ "
00452     print "input collection: ", input
00453 
00454     if( algo == 'IC5' ):
00455         genJetCollection = cms.InputTag('iterativeCone5GenJetsNoNu')
00456     elif algo == 'AK5':
00457         genJetCollection = cms.InputTag('ak5GenJetsNoNu')
00458     elif algo == 'AK7':
00459         genJetCollection = cms.InputTag('ak7GenJetsNoNu')
00460     else:
00461         print 'bad jet algorithm:', algo, '! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin'
00462         sys.exit(1)
00463 
00464     # changing the jet collection in PF2PAT:
00465     from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo
00466     inputCollection = getattr(process,"pfJets"+postfix).src
00467     setattr(process,"pfJets"+postfix,jetAlgo(algo)) # problem for cfgBrowser
00468     getattr(process,"pfJets"+postfix).src = inputCollection
00469     inputJetCorrLabel=jetCorrections
00470     switchJetCollection(process,
00471                         input,
00472                         jetIdLabel = algo,
00473                         doJTA=True,
00474                         doBTagging=True,
00475                         jetCorrLabel=inputJetCorrLabel,
00476                         doType1MET=type1,
00477                         genJetCollection = genJetCollection,
00478                         doJetID = True,
00479                         postfix = postfix,
00480                         outputModules = outputModules
00481                         )
00482     # check whether L1FastJet is in the list of correction levels or not
00483     applyPostfix(process, "patJetCorrFactors", postfix).useRho = False
00484     for corr in inputJetCorrLabel[1]:
00485         if corr == 'L1FastJet':
00486             applyPostfix(process, "patJetCorrFactors", postfix).useRho = True
00487             applyPostfix(process, "pfJets", postfix).doAreaFastjet = True
00488             # do correct treatment for TypeI MET corrections
00489             if type1:
00490                 for mod in getattr(process,'patPF2PATSequence'+postfix).moduleNames():
00491                     if mod.startswith("kt6") and mod.endswith("Jets"+postfix):
00492                         prefix = mod.replace(postfix,'')
00493                         prefix = prefix.replace('kt6PFJets','')
00494                         prefix = prefix.replace('kt6CaloJets','')
00495                         prefix = getattr(process,'patJetCorrFactors'+prefix+postfix).payload.pythonValue().replace("'","")
00496                         for essource in process.es_sources_().keys():
00497                             if essource == prefix+'L1FastJet':
00498                                 setattr(process,essource+postfix,getattr(process,essource).clone(srcRho=cms.InputTag(mod,'rho')))
00499                                 setattr(process,prefix+'CombinedCorrector'+postfix,getattr(process,prefix+'CombinedCorrector').clone())
00500                                 getattr(process,prefix+'CorMet'+postfix).corrector = prefix+'CombinedCorrector'+postfix
00501                                 for cor in getattr(process,prefix+'CombinedCorrector'+postfix).correctors:
00502                                     if cor == essource:
00503                                         idx = getattr(process,prefix+'CombinedCorrector'+postfix).correctors.index(essource);
00504                                         getattr(process,prefix+'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
00505 
00506     applyPostfix(process, "patJets", postfix).embedCaloTowers   = False
00507     applyPostfix(process, "patJets", postfix).embedPFCandidates = True
00508 
#-- Remove MC dependence ------------------------------------------------------
def pfTools::switchToPFMET (   process,
  input = cms.InputTag('pfMET'),
  type1 = False,
  postfix = "" 
)

Definition at line 391 of file pfTools.py.

00392                                                                                :
00393     print 'MET: using ', input
00394     if( not type1 ):
00395         oldMETSource = applyPostfix(process, "patMETs",postfix).metSource
00396         applyPostfix(process, "patMETs",postfix).metSource = input
00397         applyPostfix(process, "patMETs",postfix).addMuonCorrections = False
00398         getattr(process, "patDefaultSequence"+postfix).remove(applyPostfix(process, "patMETCorrections",postfix))
00399     else:
00400         # type1 corrected MET
00401         # name of corrected MET hardcoded in PAT and meaningless
00402         print 'Apply TypeI corrections for MET'
00403         getattr(process, "patDefaultSequence"+postfix).remove(applyPostfix(process, "makePatMETs",postfix))
00404         jecLabel = getattr(process,'patJetCorrFactors'+postfix).levels
00405 
00406         if not hasattr(process,'producePatPFMETCorrections'):
00407             process.load("PhysicsTools.PatUtils.patPFMETCorrections_cff")
00408         #here add to the current path and give proper postfix
00409         if not hasattr(process,'producePatPFMETCorrections'+postfix):
00410             cloneProcessingSnippet(process,process.producePatPFMETCorrections,postfix)
00411         
00412         getattr(process,'patPFMet'+postfix).metSource = cms.InputTag('pfMET'+postfix)
00413 
00414         getattr(process,'selectedPatJetsForMETtype1p2Corr'+postfix).src = cms.InputTag('selectedPatJets'+postfix)
00415         getattr(process,'selectedPatJetsForMETtype2Corr'+postfix).src   = cms.InputTag('selectedPatJets'+postfix)
00416 
00417         getattr(process,'pfCandMETcorr'+postfix).src = cms.InputTag('pfNoJet'+postfix)
00418 
00419         getattr(process,'patPFJetMETtype1p2Corr'+postfix).offsetCorrLabel = cms.string(jecLabel[0])
00420         getattr(process,'patPFJetMETtype1p2Corr'+postfix).jetCorrLabel = cms.string(jecLabel[-1])
00421         getattr(process,'patPFJetMETtype1p2Corr'+postfix).type1JetPtThreshold = cms.double(10.0)
00422         getattr(process,'patPFJetMETtype1p2Corr'+postfix).skipEM    = cms.bool(False)
00423         getattr(process,'patPFJetMETtype1p2Corr'+postfix).skipMuons = cms.bool(False)
00424 
00425         getattr(process,'patPFJetMETtype2Corr'+postfix).offsetCorrLabel = cms.string(jecLabel[0])
00426         getattr(process,'patPFJetMETtype2Corr'+postfix).jetCorrLabel = cms.string(jecLabel[-1])
00427         getattr(process,'patPFJetMETtype2Corr'+postfix).type1JetPtThreshold = cms.double(10.0)
00428         getattr(process,'patPFJetMETtype2Corr'+postfix).skipEM    = cms.bool(False)
00429         getattr(process,'patPFJetMETtype2Corr'+postfix).skipMuons = cms.bool(False)
00430         
00431         getattr(process,'patType1CorrectedPFMet'+postfix).srcType1Corrections = cms.VInputTag(
00432             cms.InputTag("patPFJetMETtype1p2Corr"+postfix,"type1"),
00433             #cms.InputTag("patPFMETtype0Corr"+postfix),
00434             )
00435         getattr(process,'patType1p2CorrectedPFMet'+postfix).srcType1Corrections = cms.VInputTag(
00436             cms.InputTag("patPFJetMETtype1p2Corr"+postfix,"type1"),
00437             #cms.InputTag("patPFMETtype0Corr"+postfix),
00438             )
00439         
00440         getattr(process,'patMETs'+postfix).metSource = 'patType1CorrectedPFMet'+postfix
00441 
00442         getattr(process,"patDefaultSequence"+postfix).replace( getattr(process,'selectedPatJets'+postfix),
00443                                                                getattr(process,'selectedPatJets'+postfix)
00444                                                                *getattr(process,'producePatPFMETCorrections'+postfix)
00445                                                                *getattr(process,'patMETs'+postfix)
00446                                                               )

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

Definition at line 355 of file pfTools.py.

00356                                                                        :
00357     process.load("CommonTools.ParticleFlow.pfTaus_cff")
00358     applyPostfix(process, "pfTaus",postfix).src = cms.InputTag(tauType+'Producer'+postfix)
00359 

def pfTools::useGsfElectrons (   process,
  postfix,
  dR = "04" 
)

Definition at line 34 of file pfTools.py.

00035                                                 :
00036     print "using Gsf Electrons in PF2PAT"
00037     print "WARNING: this will destory the feature of top projection which solves the ambiguity between leptons and jets because"
00038     print "WARNING: there will be overlap between non-PF electrons and jets even though top projection is ON!"
00039     print "********************* "
00040     module = applyPostfix(process,"patElectrons",postfix)
00041     module.useParticleFlow = False
00042     print "Building particle-based isolation for GsfElectrons in PF2PAT(PFBRECO)"
00043     print "********************* "
00044     adaptPFIsoElectrons( process, module, postfix+"PFIso", dR )
00045     getattr(process,'patDefaultSequence'+postfix).replace( getattr(process,"patElectrons"+postfix),
00046                                                    setupPFElectronIso(process, 'gsfElectrons', "PFIso", postfix, runPF2PAT=True) +
00047                                                    getattr(process,"patElectrons"+postfix) )

def pfTools::usePF2PAT (   process,
  runPF2PAT = True,
  jetAlgo = 'AK5',
  runOnMC = True,
  postfix = "",
  jetCorrections = ('AK5PFchs', ['L1FastJet',
  L2Relative,
  L3Absolute,
  pvCollection = cms.InputTag('offlinePrimaryVertices'),
  typeIMetCorrections = False,
  outputModules = ['out'] 
)
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 549 of file pfTools.py.

00550                                                                                                                                                                                                                                                             :
00551     # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT.
00552     # CREATE ADDITIONAL FUNCTIONS IF NEEDED.
00553 
00554     """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
00555 
00556     # -------- CORE ---------------
00557     if runPF2PAT:
00558         process.load("CommonTools.ParticleFlow.PF2PAT_cff")
00559         #add Pf2PAT *before* cloning so that overlapping modules are cloned too
00560         #process.patDefaultSequence.replace( process.patCandidates, process.PF2PAT+process.patCandidates)
00561         process.patPF2PATSequence = cms.Sequence( process.PF2PAT + process.patDefaultSequence)
00562     else:
00563         process.patPF2PATSequence = cms.Sequence( process.patDefaultSequence )
00564 
00565     if not postfix == "":
00566         from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
00567         cloneProcessingSnippet(process, process.patPF2PATSequence, postfix)
00568         #delete everything pat PF2PAT modules! if you want to test the postfixing for completeness
00569         #from PhysicsTools.PatAlgos.tools.helpers import listModules,listSequences
00570         #for module in listModules(process.patDefaultSequence):
00571         #    if not module.label() is None: process.__delattr__(module.label())
00572         #for sequence in listSequences(process.patDefaultSequence):
00573         #    if not sequence.label() is None: process.__delattr__(sequence.label())
00574         #del process.patDefaultSequence
00575 
00576     removeCleaning(process, postfix=postfix, outputModules=outputModules)
00577 
00578     # -------- OBJECTS ------------
00579     # Muons
00580     adaptPFMuons(process,
00581                  applyPostfix(process,"patMuons",postfix),
00582                  postfix)
00583 
00584     # Electrons
00585     adaptPFElectrons(process,
00586                      applyPostfix(process,"patElectrons",postfix),
00587                      postfix)
00588 
00589     # Photons
00590     print "Temporarily switching off photons completely"
00591 
00592     removeSpecificPATObjects(process,names=['Photons'],outputModules=outputModules,postfix=postfix)
00593     removeIfInSequence(process,"patPhotonIsolation","patDefaultSequence",postfix)
00594 
00595     # Jets
00596     if runOnMC :
00597         switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
00598                         jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
00599         applyPostfix(process,"patDefaultSequence",postfix).replace(
00600             applyPostfix(process,"patJetGenJetMatch",postfix),
00601             getattr(process,"genForPF2PATSequence") *
00602             applyPostfix(process,"patJetGenJetMatch",postfix)
00603             )
00604     else :
00605         if not 'L2L3Residual' in jetCorrections[1]:
00606             print '#################################################'
00607             print 'WARNING! Not using L2L3Residual but this is data.'
00608             print 'If this is okay with you, disregard this message.'
00609             print '#################################################'
00610         switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
00611                         jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
00612 
00613     # Taus
00614     #adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix )
00615     #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix )
00616     adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix )
00617 
00618     # MET
00619     switchToPFMET(process, cms.InputTag('pfMET'+postfix), type1=typeIMetCorrections, postfix=postfix)
00620     if not runOnMC :
00621         if hasattr(process,'patPFMet'+postfix):
00622             getattr(process,'patPFMet'+postfix).addGenMET = cms.bool(False)
00623 
00624     # Unmasked PFCandidates
00625     addPFCandidates(process,cms.InputTag('pfNoJet'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix)
00626 
00627     # adapt primary vertex collection
00628     adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
00629 
00630     if runOnMC:
00631         process.load("CommonTools.ParticleFlow.genForPF2PAT_cff")
00632         getattr(process, "patDefaultSequence"+postfix).replace(
00633             applyPostfix(process,"patCandidates",postfix),
00634             process.genForPF2PATSequence+applyPostfix(process,"patCandidates",postfix)
00635             )
00636     else:
00637         removeMCMatchingPF2PAT(process,postfix=postfix,outputModules=outputModules)
00638 
00639     print "Done: PF2PAT interfaced to PAT, postfix=", postfix
def pfTools::usePFIso (   process,
  postfix = "PFIso" 
)

Definition at line 89 of file pfTools.py.

00090                                         :
00091     print "Building particle-based isolation "
00092     print "***************** "
00093     process.eleIsoSequence = setupPFElectronIso(process, 'gsfElectrons', postfix)
00094     process.muIsoSequence = setupPFMuonIso(process, 'muons', postfix)
00095     adaptPFIsoMuons( process, applyPostfix(process,"patMuons",""), postfix)
00096     adaptPFIsoElectrons( process, applyPostfix(process,"patElectrons",""), postfix)
00097     getattr(process,'patDefaultSequence').replace( getattr(process,"patCandidates"),
00098                                                    process.pfParticleSelectionSequence +
00099                                                    process.eleIsoSequence +
00100                                                    process.muIsoSequence +
00101                                                    getattr(process,"patCandidates") )

def pfTools::warningIsolation ( )

Definition at line 29 of file pfTools.py.

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