00001 from FWCore.GuiBrowsers.ConfigToolBase import *
00002
00003 class AddElectronUserIsolation(ConfigToolBase):
00004
00005 """ add userIsolation to patElectron
00006 """
00007 _label='addElectronUserIsolation'
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
00029 from RecoEgamma.EgammaIsolationAlgos.eleIsoDeposits_cff import eleIsoDepositTk, eleIsoDepositEcalFromHits, eleIsoDepositHcalFromTowers
00030 from RecoEgamma.EgammaIsolationAlgos.eleIsoFromDeposits_cff import eleIsoFromDepsTk, eleIsoFromDepsEcalFromHitsByCrystal, eleIsoFromDepsHcalFromTowers
00031
00032 eleIsoDepositEcalFromHits.ExtractorPSet.barrelEcalHits = cms.InputTag("reducedEcalRecHitsEB")
00033 eleIsoDepositEcalFromHits.ExtractorPSet.endcapEcalHits = cms.InputTag("reducedEcalRecHitsEE")
00034
00035
00036 isolationKey=0
00037
00038 for obj in range(len(isolationTypes)):
00039 if ( isolationTypes[obj] == 'Tracker' or isolationTypes[obj] == 'All'):
00040 print "adding predefined userIsolation to pat::Electron for Tracker"
00041 print " -> to access this information call pat::Electron::userIsolation(pat::TrackIso) in your analysis code <-"
00042 isolationKey=isolationKey+1
00043 from PhysicsTools.PatAlgos.recoLayer0.electronIsolation_cff import patElectronTrackIsolation
00044 process.patElectronTrackIsolation
00045 process.patDefaultSequence.replace( process.patElectrons, process.patElectronTrackIsolation*process.patElectrons )
00046
00047 if ( isolationTypes[obj] == 'Ecal' or isolationTypes[obj] == 'All'):
00048 print "adding predefined userIsolation to pat::Electron for Ecal"
00049 print " -> to access this information call pat::Electron::userIsolation(pat::EcalIso ) in your analysis code <-"
00050 isolationKey=isolationKey+10
00051 from PhysicsTools.PatAlgos.recoLayer0.electronIsolation_cff import patElectronEcalIsolation
00052 process.patElectronEcalIsolation
00053 process.patDefaultSequence.replace( process.patElectrons, process.patElectronEcalIsolation*process.patElectrons )
00054
00055 if ( isolationTypes[obj] == 'Hcal' or isolationTypes[obj] == 'All'):
00056 print "adding predefined userIsolation to pat::Electron for Hcal"
00057 print " -> to access this information call pat::Electron::userIsolation(pat::HcalIso ) in your analysis code <-"
00058 isolationKey=isolationKey+100
00059 from PhysicsTools.PatAlgos.recoLayer0.electronIsolation_cff import patElectronHcalIsolation
00060 process.patElectronHcalIsolation = patElectronHcalIsolation
00061 process.patDefaultSequence.replace( process.patElectrons, process.patElectronHcalIsolation*process.patElectrons )
00062
00063
00064 if ( isolationKey == 1 ):
00065
00066 process.patElectrons.isoDeposits = cms.PSet(
00067 tracker = cms.InputTag("eleIsoDepositTk"),
00068 )
00069 process.patElectrons.userIsolation = cms.PSet(
00070 tracker = cms.PSet(
00071 src = cms.InputTag("eleIsoFromDepsTk"),
00072 ),
00073 )
00074 if ( isolationKey == 10 ):
00075
00076 process.patElectrons.isoDeposits = cms.PSet(
00077 ecal = cms.InputTag("eleIsoDepositEcalFromHits"),
00078 )
00079 process.patElectrons.userIsolation = cms.PSet(
00080 ecal = cms.PSet(
00081 src = cms.InputTag("eleIsoFromDepsEcalFromHitsByCrystal"),
00082 ),
00083 )
00084 if ( isolationKey == 100 ):
00085
00086 process.patElectrons.isoDeposits = cms.PSet(
00087 hcal = cms.InputTag("eleIsoDepositHcalFromTowers"),
00088 )
00089 process.patElectrons.userIsolation = cms.PSet(
00090 hcal = cms.PSet(
00091 src = cms.InputTag("eleIsoFromDepsHcalFromTowers"),
00092 ),
00093 )
00094 if ( isolationKey == 11 ):
00095
00096 process.patElectrons.isoDeposits = cms.PSet(
00097 tracker = cms.InputTag("eleIsoDepositTk"),
00098 ecal = cms.InputTag("eleIsoDepositEcalFromHits"),
00099 )
00100 process.patElectrons.userIsolation = cms.PSet(
00101 tracker = cms.PSet(
00102 src = cms.InputTag("eleIsoFromDepsTk"),
00103 ),
00104 ecal = cms.PSet(
00105 src = cms.InputTag("eleIsoFromDepsEcalFromHitsByCrystal"),
00106 ),
00107 )
00108 if ( isolationKey == 101 ):
00109
00110 process.patElectrons.isoDeposits = cms.PSet(
00111 tracker = cms.InputTag("eleIsoDepositTk"),
00112 hcal = cms.InputTag("eleIsoDepositHcalFromTowers"),
00113 )
00114 process.patElectrons.userIsolation = cms.PSet(
00115 tracker = cms.PSet(
00116 src = cms.InputTag("eleIsoFromDepsTk"),
00117 ),
00118 hcal = cms.PSet(
00119 src = cms.InputTag("eleIsoFromDepsHcalFromTowers"),
00120 ),
00121 )
00122 if ( isolationKey == 110 ):
00123
00124 process.patElectrons.isoDeposits = cms.PSet(
00125 ecal = cms.InputTag("eleIsoDepositEcalFromHits"),
00126 hcal = cms.InputTag("eleIsoDepositHcalFromTowers"),
00127 )
00128 process.patElectrons.userIsolation = cms.PSet(
00129 ecal = cms.PSet(
00130 src = cms.InputTag("eleIsoFromDepsEcalFromHitsByCrystal"),
00131 ),
00132 hcal = cms.PSet(
00133 src = cms.InputTag("eleIsoFromDepsHcalFromTowers"),
00134 ),
00135 )
00136 if ( isolationKey == 111 ):
00137
00138 process.patElectrons.isoDeposits = cms.PSet(
00139 tracker = cms.InputTag("eleIsoDepositTk"),
00140 ecal = cms.InputTag("eleIsoDepositEcalFromHits"),
00141 hcal = cms.InputTag("eleIsoDepositHcalFromTowers"),
00142 )
00143 process.patElectrons.userIsolation = cms.PSet(
00144 tracker = cms.PSet(
00145 src = cms.InputTag("eleIsoFromDepsTk"),
00146 ),
00147 ecal = cms.PSet(
00148 src = cms.InputTag("eleIsoFromDepsEcalFromHitsByCrystal"),
00149 ),
00150 hcal = cms.PSet(
00151 src = cms.InputTag("eleIsoFromDepsHcalFromTowers"),
00152 ),
00153 )
00154
00155
00156 addElectronUserIsolation=AddElectronUserIsolation()