CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
electronTools.py
Go to the documentation of this file.
2 
4 
5  """ add userIsolation to patElectron
6  """
7  _label='addElectronUserIsolation'
8  _defaultParameters=dicttypes.SortedKeysDict()
9 
10  def __init__(self):
11  ConfigToolBase.__init__(self)
12  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'])
13  self._parameters=copy.deepcopy(self._defaultParameters)
14  self._comment = ''
15 
17  return self._defaultParameters
18 
19  def __call__(self,process,isolationTypes=None) :
20  if isolationTypes is None:
21  isolationTypes=self._defaultParameters['isolationTypes'].value
22  self.setParameter('isolationTypes',isolationTypes)
23  self.apply(process)
24 
25  def toolCode(self, process):
26  isolationTypes=self._parameters['isolationTypes'].value
27 
28  # includes to fix fastsim problems
29  from RecoEgamma.EgammaIsolationAlgos.eleIsoDeposits_cff import eleIsoDepositTk, eleIsoDepositEcalFromHits, eleIsoDepositHcalFromTowers
30  from RecoEgamma.EgammaIsolationAlgos.eleIsoFromDeposits_cff import eleIsoFromDepsTk, eleIsoFromDepsEcalFromHitsByCrystal, eleIsoFromDepsHcalFromTowers
31 
32  eleIsoDepositEcalFromHits.ExtractorPSet.barrelEcalHits = cms.InputTag("reducedEcalRecHitsEB")
33  eleIsoDepositEcalFromHits.ExtractorPSet.endcapEcalHits = cms.InputTag("reducedEcalRecHitsEE")
34 
35  # key to define the parameter sets
36  isolationKey=0
37  # add pre-requisits to the electron
38  for obj in range(len(isolationTypes)):
39  if ( isolationTypes[obj] == 'Tracker' or isolationTypes[obj] == 'All'):
40  print "adding predefined userIsolation to pat::Electron for Tracker"
41  print " -> to access this information call pat::Electron::userIsolation(pat::TrackIso) in your analysis code <-"
42  isolationKey=isolationKey+1
43  from PhysicsTools.PatAlgos.recoLayer0.electronIsolation_cff import patElectronTrackIsolation
44  process.patElectronTrackIsolation
45  process.patDefaultSequence.replace( process.patElectrons, process.patElectronTrackIsolation*process.patElectrons )
46 
47  if ( isolationTypes[obj] == 'Ecal' or isolationTypes[obj] == 'All'):
48  print "adding predefined userIsolation to pat::Electron for Ecal"
49  print " -> to access this information call pat::Electron::userIsolation(pat::EcalIso ) in your analysis code <-"
50  isolationKey=isolationKey+10
51  from PhysicsTools.PatAlgos.recoLayer0.electronIsolation_cff import patElectronEcalIsolation
52  process.patElectronEcalIsolation
53  process.patDefaultSequence.replace( process.patElectrons, process.patElectronEcalIsolation*process.patElectrons )
54 
55  if ( isolationTypes[obj] == 'Hcal' or isolationTypes[obj] == 'All'):
56  print "adding predefined userIsolation to pat::Electron for Hcal"
57  print " -> to access this information call pat::Electron::userIsolation(pat::HcalIso ) in your analysis code <-"
58  isolationKey=isolationKey+100
59  from PhysicsTools.PatAlgos.recoLayer0.electronIsolation_cff import patElectronHcalIsolation
60  process.patElectronHcalIsolation = patElectronHcalIsolation
61  process.patDefaultSequence.replace( process.patElectrons, process.patElectronHcalIsolation*process.patElectrons )
62 
63  # do the corresponding replacements in the pat electron
64  if ( isolationKey == 1 ):
65  # tracker
66  process.patElectrons.isoDeposits = cms.PSet(
67  tracker = cms.InputTag("eleIsoDepositTk"),
68  )
69  process.patElectrons.userIsolation = cms.PSet(
70  tracker = cms.PSet(
71  src = cms.InputTag("eleIsoFromDepsTk"),
72  ),
73  )
74  if ( isolationKey == 10 ):
75  # ecal
76  process.patElectrons.isoDeposits = cms.PSet(
77  ecal = cms.InputTag("eleIsoDepositEcalFromHits"),
78  )
79  process.patElectrons.userIsolation = cms.PSet(
80  ecal = cms.PSet(
81  src = cms.InputTag("eleIsoFromDepsEcalFromHitsByCrystal"),
82  ),
83  )
84  if ( isolationKey == 100 ):
85  # hcal
86  process.patElectrons.isoDeposits = cms.PSet(
87  hcal = cms.InputTag("eleIsoDepositHcalFromTowers"),
88  )
89  process.patElectrons.userIsolation = cms.PSet(
90  hcal = cms.PSet(
91  src = cms.InputTag("eleIsoFromDepsHcalFromTowers"),
92  ),
93  )
94  if ( isolationKey == 11 ):
95  # ecal + tracker
96  process.patElectrons.isoDeposits = cms.PSet(
97  tracker = cms.InputTag("eleIsoDepositTk"),
98  ecal = cms.InputTag("eleIsoDepositEcalFromHits"),
99  )
100  process.patElectrons.userIsolation = cms.PSet(
101  tracker = cms.PSet(
102  src = cms.InputTag("eleIsoFromDepsTk"),
103  ),
104  ecal = cms.PSet(
105  src = cms.InputTag("eleIsoFromDepsEcalFromHitsByCrystal"),
106  ),
107  )
108  if ( isolationKey == 101 ):
109  # hcal + tracker
110  process.patElectrons.isoDeposits = cms.PSet(
111  tracker = cms.InputTag("eleIsoDepositTk"),
112  hcal = cms.InputTag("eleIsoDepositHcalFromTowers"),
113  )
114  process.patElectrons.userIsolation = cms.PSet(
115  tracker = cms.PSet(
116  src = cms.InputTag("eleIsoFromDepsTk"),
117  ),
118  hcal = cms.PSet(
119  src = cms.InputTag("eleIsoFromDepsHcalFromTowers"),
120  ),
121  )
122  if ( isolationKey == 110 ):
123  # hcal + ecal
124  process.patElectrons.isoDeposits = cms.PSet(
125  ecal = cms.InputTag("eleIsoDepositEcalFromHits"),
126  hcal = cms.InputTag("eleIsoDepositHcalFromTowers"),
127  )
128  process.patElectrons.userIsolation = cms.PSet(
129  ecal = cms.PSet(
130  src = cms.InputTag("eleIsoFromDepsEcalFromHitsByCrystal"),
131  ),
132  hcal = cms.PSet(
133  src = cms.InputTag("eleIsoFromDepsHcalFromTowers"),
134  ),
135  )
136  if ( isolationKey == 111 ):
137  # hcal + ecal + tracker
138  process.patElectrons.isoDeposits = cms.PSet(
139  tracker = cms.InputTag("eleIsoDepositTk"),
140  ecal = cms.InputTag("eleIsoDepositEcalFromHits"),
141  hcal = cms.InputTag("eleIsoDepositHcalFromTowers"),
142  )
143  process.patElectrons.userIsolation = cms.PSet(
144  tracker = cms.PSet(
145  src = cms.InputTag("eleIsoFromDepsTk"),
146  ),
147  ecal = cms.PSet(
148  src = cms.InputTag("eleIsoFromDepsEcalFromHitsByCrystal"),
149  ),
150  hcal = cms.PSet(
151  src = cms.InputTag("eleIsoFromDepsHcalFromTowers"),
152  ),
153  )
154 
155 
156 addElectronUserIsolation=AddElectronUserIsolation()