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 usePF2PAT
def usePFIso
def warningIsolation

Function Documentation

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

Definition at line 121 of file pfTools.py.

00122                                              :
00123     # module.useParticleFlow = True
00124     print "Adapting PF Electrons "
00125     print "********************* "
00126     warningIsolation()
00127     print
00128     module.useParticleFlow = True
00129     module.userIsolation   = cms.PSet()
00130     module.isoDeposits = cms.PSet(
00131         pfChargedHadrons = cms.InputTag("elPFIsoDepositCharged" + postfix),
00132         pfChargedAll = cms.InputTag("elPFIsoDepositChargedAll" + postfix),
00133         pfPUChargedHadrons = cms.InputTag("elPFIsoDepositPU" + postfix),
00134         pfNeutralHadrons = cms.InputTag("elPFIsoDepositNeutral" + postfix),
00135         pfPhotons = cms.InputTag("elPFIsoDepositGamma" + postfix)
00136         )
00137     module.isolationValues = cms.PSet(
00138         pfChargedHadrons = cms.InputTag("elPFIsoValueCharged04PFId"+ postfix),
00139         pfChargedAll = cms.InputTag("elPFIsoValueChargedAll04PFId"+ postfix),
00140         pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU04PFId" + postfix),
00141         pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral04PFId" + postfix),
00142         pfPhotons = cms.InputTag("elPFIsoValueGamma04PFId" + postfix)
00143         )
00144 
00145     # COLIN: since we take the egamma momentum for pat Electrons, we must
00146     # match the egamma electron to the gen electrons, and not the PFElectron.
00147     # -> do not uncomment the line below.
00148     # process.electronMatch.src = module.pfElectronSource
00149     # COLIN: how do we depend on this matching choice?
00150 
00151     print " PF electron source:", module.pfElectronSource
00152     print " isolation  :"
00153     print module.isolationValues
00154     print " isodeposits: "
00155     print module.isoDeposits
00156     print
00157 
00158     print "removing traditional isolation"
00159 
00160     removeIfInSequence(process,  "patElectronIsolation",  "patDefaultSequence", postfix)

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

Definition at line 33 of file pfTools.py.

00034                                                           :
00035     #FIXME: adaptPFElectrons can use this function.
00036     module.isoDeposits = cms.PSet(
00037         pfChargedHadrons = cms.InputTag("elPFIsoDepositCharged" + postfix),
00038         pfChargedAll = cms.InputTag("elPFIsoDepositChargedAll" + postfix),
00039         pfPUChargedHadrons = cms.InputTag("elPFIsoDepositPU" + postfix),
00040         pfNeutralHadrons = cms.InputTag("elPFIsoDepositNeutral" + postfix),
00041         pfPhotons = cms.InputTag("elPFIsoDepositGamma" + postfix)
00042         )
00043     module.isolationValues = cms.PSet(
00044         pfChargedHadrons = cms.InputTag("elPFIsoValueCharged04PFId"+ postfix),
00045         pfChargedAll = cms.InputTag("elPFIsoValueChargedAll04PFId"+ postfix),
00046         pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU04PFId" + postfix),
00047         pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral04PFId" + postfix),
00048         pfPhotons = cms.InputTag("elPFIsoValueGamma04PFId" + postfix)
00049         )
00050     module.isolationValuesNoPFId = cms.PSet(
00051         pfChargedHadrons = cms.InputTag("elPFIsoValueCharged04NoPFId"+ postfix),
00052         pfChargedAll = cms.InputTag("elPFIsoValueChargedAll04NoPFId"+ postfix),
00053         pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU04NoPFId" + postfix),
00054         pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral04NoPFId" + postfix),
00055         pfPhotons = cms.InputTag("elPFIsoValueGamma04NoPFId" + postfix)
00056         )

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

Definition at line 57 of file pfTools.py.

00058                                                       :
00059     #FIXME: adaptPFMuons can use this function.
00060     module.isoDeposits = cms.PSet(
00061         pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix),
00062         pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix),
00063         pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix),
00064         pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix),
00065         pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix)
00066         )
00067     module.isolationValues = cms.PSet(
00068         pfChargedHadrons = cms.InputTag("muPFIsoValueCharged04"+ postfix),
00069         pfChargedAll = cms.InputTag("muPFIsoValueChargedAll04"+ postfix),
00070         pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU04" + postfix),
00071         pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral04" + postfix),
00072         pfPhotons = cms.InputTag("muPFIsoValueGamma04" + postfix)
00073         )

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

Definition at line 89 of file pfTools.py.

00090                                             :
00091     print "Adapting PF Muons "
00092     print "***************** "
00093     warningIsolation()
00094     print
00095     module.useParticleFlow = True
00096     module.userIsolation   = cms.PSet()
00097     module.isoDeposits = cms.PSet(
00098         pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix),
00099         pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix),
00100         pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix),
00101         pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix),
00102         pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix)
00103         )
00104     module.isolationValues = cms.PSet(
00105         pfChargedHadrons = cms.InputTag("muPFIsoValueCharged04"+ postfix),
00106         pfChargedAll = cms.InputTag("muPFIsoValueChargedAll04"+ postfix),
00107         pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU04" + postfix),
00108         pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral04" + postfix),
00109         pfPhotons = cms.InputTag("muPFIsoValueGamma04" + postfix)
00110         )
00111     # matching the pfMuons, not the standard muons.
00112     applyPostfix(process,"muonMatch",postfix).src = module.pfMuonSource
00113 
00114     print " muon source:", module.pfMuonSource
00115     print " isolation  :",
00116     print module.isolationValues
00117     print " isodeposits: "
00118     print module.isoDeposits
00119     print
00120 

def pfTools::adaptPFPhotons (   process,
  module 
)

Definition at line 161 of file pfTools.py.

00162                                   :
00163     raise RuntimeError, "Photons are not supported yet"

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

Definition at line 308 of file pfTools.py.

00309                                                                      :
00310     # Set up the collection used as a preselection to use this tau type
00311     if tauType != 'hpsPFTau' :
00312         reconfigurePF2PATTaus(process, tauType, postfix=postfix)
00313     else:
00314         reconfigurePF2PATTaus(process, tauType,
00315                               ["DiscriminationByLooseCombinedIsolationDBSumPtCorr"],
00316                               ["DiscriminationByDecayModeFinding"],
00317                               postfix=postfix)
00318     # new default use unselected taus (selected only for jet cleaning)
00319     if tauType != 'hpsPFTau' :
00320         applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTausBase"+postfix)
00321     else:
00322         applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
00323     # to use preselected collection (old default) uncomment line below
00324     #applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix)
00325 
00326 
00327     redoPFTauDiscriminators(process,
00328                             cms.InputTag(tauType+'Producer'),
00329                             applyPostfix(process,"patTaus", postfix).tauSource,
00330                             tauType, postfix=postfix)
00331 
00332     switchToPFTauByType(process, pfTauType=tauType,
00333                         pfTauLabelNew=applyPostfix(process,"patTaus", postfix).tauSource,
00334                         pfTauLabelOld=cms.InputTag(tauType+'Producer'),
00335                         postfix=postfix)
00336 
00337     applyPostfix(process,"makePatTaus", postfix).remove(
00338         applyPostfix(process,"patPFCandidateIsoDepositSelection", postfix)
00339         )
00340 
#helper function for PAT on PF2PAT sample
def pfTools::adaptPVs (   process,
  pvCollection = cms.InputTag('offlinePrimaryVertices'),
  postfix = '' 
)

Definition at line 463 of file pfTools.py.

00464                                                                                       :
00465 
00466     print "Switching PV collection for PF2PAT:", pvCollection
00467     print "***********************************"
00468 
00469     # PV sources to be exchanged:
00470     pvExchange = ['Vertices','vertices','pvSrc','primaryVertices','srcPVs']
00471     # PV sources NOT to be exchanged:
00472     #noPvExchange = ['src','PVProducer','primaryVertexSrc','vertexSrc','primaryVertex']
00473 
00474     # find out all added jet collections (they don't belong to PF2PAT)
00475     interPostfixes = []
00476     for m in getattr(process,'patPF2PATSequence'+postfix).moduleNames():
00477         if m.startswith('patJets') and m.endswith(postfix) and not len(m)==len('patJets')+len(postfix):
00478             interPostfix = m.replace('patJets','')
00479             interPostfix = interPostfix.replace(postfix,'')
00480             interPostfixes.append(interPostfix)
00481 
00482     # exchange the primary vertex source of all relevant modules
00483     for m in getattr(process,'patPF2PATSequence'+postfix).moduleNames():
00484         modName = m.replace(postfix,'')
00485         # only if the module has a source with a relevant name
00486         for namePvSrc in pvExchange:
00487             if hasattr(getattr(process,m),namePvSrc):
00488                 # only if the module is not coming from an added jet collection
00489                 interPostFixFlag = False
00490                 for pfix in interPostfixes:
00491                     if modName.endswith(pfix):
00492                         interPostFixFlag = True
00493                         break
00494                 if not interPostFixFlag:
00495                     setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
00496 

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

Definition at line 346 of file pfTools.py.

00347                                                                          :
00348     from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles
00349     # make modules
00350     producer = patPFParticles.clone(pfCandidateSource = src)
00351     filter   = cms.EDFilter("PATPFParticleSelector",
00352                     src = cms.InputTag("pat" + patLabel),
00353                     cut = cms.string(cut))
00354     counter  = cms.EDFilter("PATCandViewCountFilter",
00355                     minNumber = cms.uint32(0),
00356                     maxNumber = cms.uint32(999999),
00357                     src       = cms.InputTag("pat" + patLabel))
00358     # add modules to process
00359     setattr(process, "pat"         + patLabel, producer)
00360     setattr(process, "selectedPat" + patLabel, filter)
00361     setattr(process, "countPat"    + patLabel, counter)
00362     # insert into sequence
00363     getattr(process, "patDefaultSequence"+postfix).replace(
00364         applyPostfix(process, "patCandidateSummary", postfix),
00365         producer+applyPostfix(process, "patCandidateSummary", postfix)
00366     )
00367     getattr(process, "patDefaultSequence"+postfix).replace(
00368         applyPostfix(process, "selectedPatCandidateSummary", postfix),
00369         filter+applyPostfix(process, "selectedPatCandidateSummary", postfix)
00370     )
00371     index = len( applyPostfix( process, "patDefaultSequence", postfix ).moduleNames() )
00372     applyPostfix( process, "patDefaultSequence", postfix ).insert( index, counter )
00373     # summary tables
00374     applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel))
00375     applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
00376 

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

Definition at line 166 of file pfTools.py.

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

Definition at line 457 of file pfTools.py.

00458                                                                         :
00459     from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching
00460     removeIfInSequence(process, "genForPF2PATSequence", "patDefaultSequence", postfix)
00461     removeMCMatching(process, names=['All'], postfix=postfix, outputModules=outputModules)
00462 

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

Definition at line 394 of file pfTools.py.

00395                                                                                                                                                                                                :
00396 
00397     print "Switching to PFJets,  ", algo
00398     print "************************ "
00399     print "input collection: ", input
00400 
00401     if( algo == 'IC5' ):
00402         genJetCollection = cms.InputTag('iterativeCone5GenJetsNoNu')
00403     elif algo == 'AK5':
00404         genJetCollection = cms.InputTag('ak5GenJetsNoNu')
00405     elif algo == 'AK7':
00406         genJetCollection = cms.InputTag('ak7GenJetsNoNu')
00407     else:
00408         print 'bad jet algorithm:', algo, '! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin'
00409         sys.exit(1)
00410 
00411     # changing the jet collection in PF2PAT:
00412     from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo
00413     inputCollection = getattr(process,"pfJets"+postfix).src
00414     setattr(process,"pfJets"+postfix,jetAlgo(algo)) # problem for cfgBrowser
00415     getattr(process,"pfJets"+postfix).src = inputCollection
00416     inputJetCorrLabel=jetCorrections
00417     switchJetCollection(process,
00418                         input,
00419                         jetIdLabel = algo,
00420                         doJTA=True,
00421                         doBTagging=True,
00422                         jetCorrLabel=inputJetCorrLabel,
00423                         doType1MET=type1,
00424                         genJetCollection = genJetCollection,
00425                         doJetID = True,
00426                         postfix = postfix,
00427                         outputModules = outputModules
00428                         )
00429     # check whether L1FastJet is in the list of correction levels or not
00430     applyPostfix(process, "patJetCorrFactors", postfix).useRho = False
00431     for corr in inputJetCorrLabel[1]:
00432         if corr == 'L1FastJet':
00433             applyPostfix(process, "patJetCorrFactors", postfix).useRho = True
00434             applyPostfix(process, "pfJets", postfix).doAreaFastjet = True
00435             applyPostfix(process, "kt6PFJets", postfix).src = inputCollection
00436             # do correct treatment for TypeI MET corrections
00437             if type1:
00438                 for mod in getattr(process,'patPF2PATSequence'+postfix).moduleNames():
00439                     if mod.startswith("kt6"):
00440                         prefix = mod.replace(postfix,'')
00441                         prefix = prefix.replace('kt6PFJets','')
00442                         prefix = prefix.replace('kt6CaloJets','')
00443                         prefix = getattr(process,'patJetCorrFactors'+prefix+postfix).payload.pythonValue().replace("'","")
00444                         for essource in process.es_sources_().keys():
00445                             if essource == prefix+'L1FastJet':
00446                                 setattr(process,essource+postfix,getattr(process,essource).clone(srcRho=cms.InputTag(mod,'rho')))
00447                                 setattr(process,prefix+'CombinedCorrector'+postfix,getattr(process,prefix+'CombinedCorrector').clone())
00448                                 getattr(process,prefix+'CorMet'+postfix).corrector = prefix+'CombinedCorrector'+postfix
00449                                 for cor in getattr(process,prefix+'CombinedCorrector'+postfix).correctors:
00450                                     if cor == essource:
00451                                         idx = getattr(process,prefix+'CombinedCorrector'+postfix).correctors.index(essource);
00452                                         getattr(process,prefix+'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
00453 
00454     applyPostfix(process, "patJets", postfix).embedCaloTowers   = False
00455     applyPostfix(process, "patJets", postfix).embedPFCandidates = True
00456 
#-- Remove MC dependence ------------------------------------------------------
def pfTools::switchToPFMET (   process,
  input = cms.InputTag('pfMET'),
  type1 = False,
  postfix = "" 
)

Definition at line 377 of file pfTools.py.

00378                                                                                :
00379     print 'MET: using ', input
00380     if( not type1 ):
00381         oldMETSource = applyPostfix(process, "patMETs",postfix).metSource
00382         applyPostfix(process, "patMETs",postfix).metSource = input
00383         applyPostfix(process, "patMETs",postfix).addMuonCorrections = False
00384         getattr(process, "patDefaultSequence"+postfix).remove(applyPostfix(process, "patMETCorrections",postfix))
00385     else:
00386         # type1 corrected MET
00387         # name of corrected MET hardcoded in PAT and meaningless
00388         print 'Apply TypeI corrections for MET'
00389         getattr(process, "patDefaultSequence"+postfix).remove(applyPostfix(process, "patMETCorrections",postfix))
00390         jecLabel = getattr(process,'patJetCorrFactors'+postfix).payload.pythonValue().replace("'","")
00391         getattr(process,jecLabel+'CorMet'+postfix).inputUncorMetLabel = input.getModuleLabel()
00392         getattr(process,'patMETs'+postfix).metSource = jecLabel+'CorMet'+postfix
00393         getattr(process,'patMETs'+postfix).addMuonCorrections = False

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

Definition at line 341 of file pfTools.py.

00342                                                                        :
00343     process.load("CommonTools.ParticleFlow.pfTaus_cff")
00344     applyPostfix(process, "pfTaus",postfix).src = cms.InputTag(tauType+'Producer'+postfix)
00345 

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 497 of file pfTools.py.

00498                                                                                                                                                                                                                                                             :
00499     # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT.
00500     # CREATE ADDITIONAL FUNCTIONS IF NEEDED.
00501 
00502     """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
00503 
00504     # -------- CORE ---------------
00505     if runPF2PAT:
00506         process.load("CommonTools.ParticleFlow.PF2PAT_cff")
00507         #add Pf2PAT *before* cloning so that overlapping modules are cloned too
00508         #process.patDefaultSequence.replace( process.patCandidates, process.PF2PAT+process.patCandidates)
00509         process.patPF2PATSequence = cms.Sequence( process.PF2PAT + process.patDefaultSequence)
00510     else:
00511         process.patPF2PATSequence = cms.Sequence( process.patDefaultSequence )
00512 
00513     if not postfix == "":
00514         from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
00515         cloneProcessingSnippet(process, process.patPF2PATSequence, postfix)
00516         #delete everything pat PF2PAT modules! if you want to test the postfixing for completeness
00517         #from PhysicsTools.PatAlgos.tools.helpers import listModules,listSequences
00518         #for module in listModules(process.patDefaultSequence):
00519         #    if not module.label() is None: process.__delattr__(module.label())
00520         #for sequence in listSequences(process.patDefaultSequence):
00521         #    if not sequence.label() is None: process.__delattr__(sequence.label())
00522         #del process.patDefaultSequence
00523 
00524     removeCleaning(process, postfix=postfix, outputModules=outputModules)
00525 
00526     # -------- OBJECTS ------------
00527     # Muons
00528     adaptPFMuons(process,
00529                  applyPostfix(process,"patMuons",postfix),
00530                  postfix)
00531 
00532     # Electrons
00533     adaptPFElectrons(process,
00534                      applyPostfix(process,"patElectrons",postfix),
00535                      postfix)
00536 
00537     # Photons
00538     print "Temporarily switching off photons completely"
00539 
00540     removeSpecificPATObjects(process,names=['Photons'],outputModules=outputModules,postfix=postfix)
00541     removeIfInSequence(process,"patPhotonIsolation","patDefaultSequence",postfix)
00542 
00543     # Jets
00544     if runOnMC :
00545         switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
00546                         jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
00547         applyPostfix(process,"patDefaultSequence",postfix).replace(
00548             applyPostfix(process,"patJetGenJetMatch",postfix),
00549             getattr(process,"genForPF2PATSequence") *
00550             applyPostfix(process,"patJetGenJetMatch",postfix)
00551             )
00552     else :
00553         if not 'L2L3Residual' in jetCorrections[1]:
00554             print '#################################################'
00555             print 'WARNING! Not using L2L3Residual but this is data.'
00556             print 'If this is okay with you, disregard this message.'
00557             print '#################################################'
00558         switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
00559                         jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
00560 
00561     # Taus
00562     #adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix )
00563     #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix )
00564     adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix )
00565 
00566     # MET
00567     switchToPFMET(process, cms.InputTag('pfMET'+postfix), type1=typeIMetCorrections, postfix=postfix)
00568 
00569     # Unmasked PFCandidates
00570     addPFCandidates(process,cms.InputTag('pfNoJet'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix)
00571 
00572     # adapt primary vertex collection
00573     adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
00574 
00575     if runOnMC:
00576         process.load("CommonTools.ParticleFlow.genForPF2PAT_cff")
00577         getattr(process, "patDefaultSequence"+postfix).replace(
00578             applyPostfix(process,"patCandidates",postfix),
00579             process.genForPF2PATSequence+applyPostfix(process,"patCandidates",postfix)
00580             )
00581     else:
00582         removeMCMatchingPF2PAT(process,postfix=postfix,outputModules=outputModules)
00583 
00584     print "Done: PF2PAT interfaced to PAT, postfix=", postfix
def pfTools::usePFIso (   process,
  postfix = "PFIso" 
)

Definition at line 76 of file pfTools.py.

00077                                         :
00078     print "Building particle-based isolation "
00079     print "***************** "
00080     process.eleIsoSequence = setupPFElectronIso(process, 'gsfElectrons', postfix)
00081     process.muIsoSequence = setupPFMuonIso(process, 'muons', postfix)
00082     adaptPFIsoMuons( process, applyPostfix(process,"patMuons",""), postfix)
00083     adaptPFIsoElectrons( process, applyPostfix(process,"patElectrons",""), postfix)
00084     getattr(process,'patDefaultSequence').replace( getattr(process,"patCandidates"),
00085                                                    process.pfParticleSelectionSequence +
00086                                                    process.eleIsoSequence +
00087                                                    process.muIsoSequence +
00088                                                    getattr(process,"patCandidates") )

def pfTools::warningIsolation ( )

Definition at line 29 of file pfTools.py.

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