CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/PhysicsTools/PatAlgos/python/tools/photonTools.py

Go to the documentation of this file.
00001 from FWCore.GuiBrowsers.ConfigToolBase import *
00002 
00003 class AddPhotonUserIsolation(ConfigToolBase):
00004 
00005     """ add userIsolation to patPhoton
00006     """
00007     _label='addPhotonUserIsolation'    
00008     _defaultParameters=dicttypes.SortedKeysDict()
00009     
00010     def __init__(self):
00011         ConfigToolBase.__init__(self)
00012         self.addParameter(self._defaultParameters,'isolationTypes',['All'],'List of predefined userIsolation types to be added; possible values are [\'Tracker\',\'Ecal\',\'Hcal\'] or just [\'All\']', allowedValues=['Tracker','Ecal','Hcal','All'])
00013         self._parameters=copy.deepcopy(self._defaultParameters)
00014         self._comment = ''
00015 
00016     def getDefaultParameters(self):
00017         return self._defaultParameters
00018 
00019     def __call__(self,process,isolationTypes=None) :
00020         if  isolationTypes is None:
00021             isolationTypes=self._defaultParameters['isolationTypes'].value 
00022         self.setParameter('isolationTypes',isolationTypes)
00023         self.apply(process) 
00024         
00025     def toolCode(self, process):                
00026         isolationTypes=self._parameters['isolationTypes'].value
00027 
00028         from RecoEgamma.EgammaIsolationAlgos.gamIsoDeposits_cff import gamIsoDepositTk, gamIsoDepositEcalFromHits, gamIsoDepositHcalFromTowers
00029         from RecoEgamma.EgammaIsolationAlgos.gamIsoFromDepsModules_cff import gamIsoFromDepsTk, gamIsoFromDepsEcalFromHits, gamIsoFromDepsHcalFromTowers
00030         
00031         gamIsoDepositEcalFromHits.ExtractorPSet.barrelEcalHits = cms.InputTag("reducedEcalRecHitsEB")
00032         gamIsoDepositEcalFromHits.ExtractorPSet.endcapEcalHits = cms.InputTag("reducedEcalRecHitsEE")
00033         
00034         # key to define the parameter sets
00035         isolationKey=0
00036         # add pre-requisits to the photon
00037         for obj in range(len(isolationTypes)):
00038             if ( isolationTypes[obj] == 'Tracker' or isolationTypes[obj] == 'All'):
00039                 print "adding predefined userIsolation to pat::Photon for Tracker"
00040                 print " -> to access this information call pat::Photon::userIsolation(pat::TrackIso) in your analysis code <-"
00041                 isolationKey=isolationKey+1
00042                 from PhysicsTools.PatAlgos.recoLayer0.photonIsolation_cff import patPhotonTrackIsolation
00043                 process.patPhotonTrackIsolation
00044                 process.patDefaultSequence.replace( process.patPhotons, process.patPhotonTrackIsolation*process.patPhotons )
00045                 
00046             if ( isolationTypes[obj] == 'Ecal'    or isolationTypes[obj] == 'All'):
00047                 print "adding predefined userIsolation to pat::Photon for Ecal"
00048                 print " -> to access this information call pat::Photon::userIsolation(pat::EcalIso ) in your analysis code <-"
00049                 isolationKey=isolationKey+10
00050                 from PhysicsTools.PatAlgos.recoLayer0.photonIsolation_cff import patPhotonEcalIsolation
00051                 process.patPhotonEcalIsolation            
00052                 process.patDefaultSequence.replace( process.patPhotons, process.patPhotonEcalIsolation*process.patPhotons )
00053                 
00054             if ( isolationTypes[obj] == 'Hcal'    or isolationTypes[obj] == 'All'):
00055                 print "adding predefined userIsolation to pat::Photon for Hcal"
00056                 print " -> to access this information call pat::Photon::userIsolation(pat::HcalIso ) in your analysis code <-"
00057                 isolationKey=isolationKey+100
00058                 from PhysicsTools.PatAlgos.recoLayer0.photonIsolation_cff import patPhotonHcalIsolation            
00059                 process.patPhotonHcalIsolation = patPhotonHcalIsolation
00060                 process.patDefaultSequence.replace( process.patPhotons, process.patPhotonHcalIsolation*process.patPhotons )  
00061                 
00062         # do the corresponding replacements in the pat photon
00063         if ( isolationKey ==   1 ):
00064             # tracker
00065             process.patPhotons.isoDeposits = cms.PSet(
00066                 tracker = cms.InputTag("gamIsoDepositTk"),
00067             )
00068             process.patPhotons.userIsolation = cms.PSet(
00069                 tracker = cms.PSet(
00070                 src = cms.InputTag("gamIsoFromDepsTk"),
00071                 ),
00072             )
00073         if ( isolationKey ==  10 ):
00074             # ecal
00075             process.patPhotons.isoDeposits = cms.PSet(
00076                 ecal    = cms.InputTag("gamIsoDepositEcalFromHits"),
00077             )
00078             process.patPhotons.userIsolation = cms.PSet(
00079                 ecal = cms.PSet(
00080                 src = cms.InputTag("gamIsoFromDepsEcalFromHits"),
00081                 ),
00082             )
00083         if ( isolationKey == 100 ):
00084             # hcal
00085             process.patPhotons.isoDeposits = cms.PSet(
00086                 hcal    = cms.InputTag("gamIsoDepositHcalFromTowers"),
00087             )
00088             process.patPhotons.userIsolation = cms.PSet(
00089                 hcal = cms.PSet(
00090                 src = cms.InputTag("gamIsoFromDepsHcalFromTowers"),
00091                 ),
00092             )
00093         if ( isolationKey ==  11 ):
00094             # ecal + tracker
00095             process.patPhotons.isoDeposits = cms.PSet(
00096                 tracker = cms.InputTag("gamIsoDepositTk"),
00097                 ecal    = cms.InputTag("gamIsoDepositEcalFromHits"),
00098             )
00099             process.patPhotons.userIsolation = cms.PSet(
00100                 tracker = cms.PSet(
00101                 src = cms.InputTag("gamIsoFromDepsTk"),
00102                 ),
00103                 ecal = cms.PSet(
00104                 src = cms.InputTag("gamIsoFromDepsEcalFromHits"),
00105                 ),
00106             )
00107         if ( isolationKey == 101 ):
00108             # hcal + tracker
00109             process.patPhotons.isoDeposits = cms.PSet(
00110                 tracker = cms.InputTag("gamIsoDepositTk"),
00111                 hcal    = cms.InputTag("gamIsoDepositHcalFromTowers"),
00112             )
00113             process.patPhotons.userIsolation = cms.PSet(
00114                 tracker = cms.PSet(
00115                 src = cms.InputTag("gamIsoFromDepsTk"),
00116                 ),
00117                 hcal = cms.PSet(
00118                 src = cms.InputTag("gamIsoFromDepsHcalFromTowers"),
00119                 ),
00120             )
00121         if ( isolationKey == 110 ):
00122             # hcal + ecal
00123             process.patPhotons.isoDeposits = cms.PSet(
00124                 ecal    = cms.InputTag("gamIsoDepositEcalFromHits"),
00125                 hcal    = cms.InputTag("gamIsoDepositHcalFromTowers"),
00126             )
00127             process.patPhotons.userIsolation = cms.PSet(
00128                 ecal = cms.PSet(
00129                 src = cms.InputTag("gamIsoFromDepsEcalFromHits"),
00130                 ),
00131                 hcal = cms.PSet(
00132                 src = cms.InputTag("gamIsoFromDepsHcalFromTowers"),
00133                 ),
00134             )
00135         if ( isolationKey == 111 ):
00136             # hcal + ecal + tracker
00137             process.patPhotons.isoDeposits = cms.PSet(
00138                 tracker = cms.InputTag("gamIsoDepositTk"),
00139                 ecal    = cms.InputTag("gamIsoDepositEcalFromHits"),
00140                 hcal    = cms.InputTag("gamIsoDepositHcalFromTowers"),
00141             )
00142             process.patPhotons.userIsolation = cms.PSet(
00143                 tracker = cms.PSet(
00144                 src = cms.InputTag("gamIsoFromDepsTk"),
00145                 ),
00146                 ecal = cms.PSet(
00147                 src = cms.InputTag("gamIsoFromDepsEcalFromHits"),
00148                 ),
00149                 hcal = cms.PSet(
00150                 src = cms.InputTag("gamIsoFromDepsHcalFromTowers"),
00151                 ),
00152             )
00153 
00154 
00155 addPhotonUserIsolation=AddPhotonUserIsolation()