CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/CommonTools/ParticleFlow/python/Tools/pfIsolation.py

Go to the documentation of this file.
00001 # Colin, March 2012
00002 
00003 import FWCore.ParameterSet.Config as cms
00004 from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
00005 
00006 def _getattrGenerator( process, postfix ):
00007     '''A function generator to simplify the getattr syntax'''
00008     def fun(name):
00009         return getattr(process, name+postfix)
00010     return fun
00011 
00012 
00013 _PFBRECO_loaded = False
00014 
00015 def _loadPFBRECO(process):
00016     '''The particle-flow based reconstruction sequence should be loaded once in the process.
00017     Not optimal, should load it only if it is not detected (hasattr)'''
00018     global _PFBRECO_loaded
00019     if _PFBRECO_loaded is False: 
00020         _PFBRECO_loaded = True
00021         process.load("CommonTools.ParticleFlow.PFBRECO_cff")
00022 
00023 
00024 def setupPFIso(process, leptonCollection, particleName, newpostfix='PFIso'):
00025     '''Generic function to setup particle-based isolation for a given lepton collection.
00026     Returns the isolation sequence.
00027     You are responsible for adding it to your path.
00028 
00029     leptonCollection could e.g. be "gsfElectrons" or "muons"
00030     particleName must be either "Electron" or "Muon".
00031     newpostfix can be specified to define several particle-flow isolation sequences
00032     '''
00033     lepshort = None
00034     if particleName=='Electron':
00035         lepshort='el'
00036     elif particleName=='Muon':
00037         lepshort='mu'
00038     else:
00039         raise ValueError('particleName should be equal to "Electron" or "Muon"')
00040     
00041     _loadPFBRECO(process)
00042 
00043     postfix = ''
00044     # ADD VETOES IN ENDCAPS!
00045     fullpostfix = postfix+newpostfix
00046     ga = _getattrGenerator( process, postfix )
00047     ganew = _getattrGenerator( process, fullpostfix )
00048 
00049     leptonSeq = cms.Sequence(
00050         ga('pf{lepton}IsolationSequence'.format(lepton=particleName))  
00051         )
00052     setattr( process, 'std{lepton}Sequence{postfix}'.format(lepton=particleName,
00053                                                    postfix=postfix), leptonSeq)
00054 
00055     leptonSource = leptonCollection
00056     cloneProcessingSnippet(process,
00057                            ga('std{lepton}Sequence'.format(lepton=particleName)),
00058                            newpostfix)
00059 
00060     ganew("{lepshort}PFIsoDepositCharged".format(lepshort=lepshort) ).src = leptonSource
00061     ganew("{lepshort}PFIsoDepositChargedAll".format(lepshort=lepshort)).src = leptonSource
00062     ganew("{lepshort}PFIsoDepositNeutral".format(lepshort=lepshort)).src = leptonSource
00063     ganew("{lepshort}PFIsoDepositGamma".format(lepshort=lepshort)).src = leptonSource
00064     ganew("{lepshort}PFIsoDepositPU".format(lepshort=lepshort)).src = leptonSource
00065 
00066     return ganew('std{lepton}Sequence'.format(lepton=particleName))
00067 
00068 
00069 
00070 def setupPFMuonIso(process, muonCollection, postfix='PFIso' ):
00071     '''Set up particle-based isolation for the muons in muonCollection.
00072 
00073     Calls setupPFIso.
00074     '''
00075     return setupPFIso( process, muonCollection, 'Muon', postfix)
00076 
00077 
00078 
00079 def setupPFElectronIso(process, electronCollection, postfix='PFIso' ):
00080     '''Set up particle-based isolation for the electrons in electronCollection.
00081 
00082     Calls setupPFIso.
00083     '''
00084     #    print 'WARNING!!! the vetoes are the ones defined for the PF e-s (no veto...).'
00085     #    print 'Vetoes should be applied in the endcaps when doing particle-based isolation on gsfElectrons.'
00086     #    print 'Need a volunteer to implement that.'
00087     return setupPFIso( process, electronCollection, 'Electron', postfix)
00088 
00089     
00090