CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
photonTools.py
Go to the documentation of this file.
2 
4 
5  """ add userIsolation to patPhoton
6  """
7  _label='addPhotonUserIsolation'
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  from RecoEgamma.EgammaIsolationAlgos.gamIsoDeposits_cff import gamIsoDepositTk, gamIsoDepositEcalFromHits, gamIsoDepositHcalFromTowers
29  from RecoEgamma.EgammaIsolationAlgos.gamIsoFromDepsModules_cff import gamIsoFromDepsTk, gamIsoFromDepsEcalFromHits, gamIsoFromDepsHcalFromTowers
30 
31  gamIsoDepositEcalFromHits.ExtractorPSet.barrelEcalHits = cms.InputTag("reducedEcalRecHitsEB")
32  gamIsoDepositEcalFromHits.ExtractorPSet.endcapEcalHits = cms.InputTag("reducedEcalRecHitsEE")
33 
34  # key to define the parameter sets
35  isolationKey=0
36  # add pre-requisits to the photon
37  for obj in range(len(isolationTypes)):
38  if ( isolationTypes[obj] == 'Tracker' or isolationTypes[obj] == 'All'):
39  print "adding predefined userIsolation to pat::Photon for Tracker"
40  print " -> to access this information call pat::Photon::userIsolation(pat::TrackIso) in your analysis code <-"
41  isolationKey=isolationKey+1
42  from PhysicsTools.PatAlgos.recoLayer0.photonIsolation_cff import patPhotonTrackIsolation
43  process.patPhotonTrackIsolation
44  process.patDefaultSequence.replace( process.patPhotons, process.patPhotonTrackIsolation*process.patPhotons )
45 
46  if ( isolationTypes[obj] == 'Ecal' or isolationTypes[obj] == 'All'):
47  print "adding predefined userIsolation to pat::Photon for Ecal"
48  print " -> to access this information call pat::Photon::userIsolation(pat::EcalIso ) in your analysis code <-"
49  isolationKey=isolationKey+10
50  from PhysicsTools.PatAlgos.recoLayer0.photonIsolation_cff import patPhotonEcalIsolation
51  process.patPhotonEcalIsolation
52  process.patDefaultSequence.replace( process.patPhotons, process.patPhotonEcalIsolation*process.patPhotons )
53 
54  if ( isolationTypes[obj] == 'Hcal' or isolationTypes[obj] == 'All'):
55  print "adding predefined userIsolation to pat::Photon for Hcal"
56  print " -> to access this information call pat::Photon::userIsolation(pat::HcalIso ) in your analysis code <-"
57  isolationKey=isolationKey+100
58  from PhysicsTools.PatAlgos.recoLayer0.photonIsolation_cff import patPhotonHcalIsolation
59  process.patPhotonHcalIsolation = patPhotonHcalIsolation
60  process.patDefaultSequence.replace( process.patPhotons, process.patPhotonHcalIsolation*process.patPhotons )
61 
62  # do the corresponding replacements in the pat photon
63  if ( isolationKey == 1 ):
64  # tracker
65  process.patPhotons.isoDeposits = cms.PSet(
66  tracker = cms.InputTag("gamIsoDepositTk"),
67  )
68  process.patPhotons.userIsolation = cms.PSet(
69  tracker = cms.PSet(
70  src = cms.InputTag("gamIsoFromDepsTk"),
71  ),
72  )
73  if ( isolationKey == 10 ):
74  # ecal
75  process.patPhotons.isoDeposits = cms.PSet(
76  ecal = cms.InputTag("gamIsoDepositEcalFromHits"),
77  )
78  process.patPhotons.userIsolation = cms.PSet(
79  ecal = cms.PSet(
80  src = cms.InputTag("gamIsoFromDepsEcalFromHits"),
81  ),
82  )
83  if ( isolationKey == 100 ):
84  # hcal
85  process.patPhotons.isoDeposits = cms.PSet(
86  hcal = cms.InputTag("gamIsoDepositHcalFromTowers"),
87  )
88  process.patPhotons.userIsolation = cms.PSet(
89  hcal = cms.PSet(
90  src = cms.InputTag("gamIsoFromDepsHcalFromTowers"),
91  ),
92  )
93  if ( isolationKey == 11 ):
94  # ecal + tracker
95  process.patPhotons.isoDeposits = cms.PSet(
96  tracker = cms.InputTag("gamIsoDepositTk"),
97  ecal = cms.InputTag("gamIsoDepositEcalFromHits"),
98  )
99  process.patPhotons.userIsolation = cms.PSet(
100  tracker = cms.PSet(
101  src = cms.InputTag("gamIsoFromDepsTk"),
102  ),
103  ecal = cms.PSet(
104  src = cms.InputTag("gamIsoFromDepsEcalFromHits"),
105  ),
106  )
107  if ( isolationKey == 101 ):
108  # hcal + tracker
109  process.patPhotons.isoDeposits = cms.PSet(
110  tracker = cms.InputTag("gamIsoDepositTk"),
111  hcal = cms.InputTag("gamIsoDepositHcalFromTowers"),
112  )
113  process.patPhotons.userIsolation = cms.PSet(
114  tracker = cms.PSet(
115  src = cms.InputTag("gamIsoFromDepsTk"),
116  ),
117  hcal = cms.PSet(
118  src = cms.InputTag("gamIsoFromDepsHcalFromTowers"),
119  ),
120  )
121  if ( isolationKey == 110 ):
122  # hcal + ecal
123  process.patPhotons.isoDeposits = cms.PSet(
124  ecal = cms.InputTag("gamIsoDepositEcalFromHits"),
125  hcal = cms.InputTag("gamIsoDepositHcalFromTowers"),
126  )
127  process.patPhotons.userIsolation = cms.PSet(
128  ecal = cms.PSet(
129  src = cms.InputTag("gamIsoFromDepsEcalFromHits"),
130  ),
131  hcal = cms.PSet(
132  src = cms.InputTag("gamIsoFromDepsHcalFromTowers"),
133  ),
134  )
135  if ( isolationKey == 111 ):
136  # hcal + ecal + tracker
137  process.patPhotons.isoDeposits = cms.PSet(
138  tracker = cms.InputTag("gamIsoDepositTk"),
139  ecal = cms.InputTag("gamIsoDepositEcalFromHits"),
140  hcal = cms.InputTag("gamIsoDepositHcalFromTowers"),
141  )
142  process.patPhotons.userIsolation = cms.PSet(
143  tracker = cms.PSet(
144  src = cms.InputTag("gamIsoFromDepsTk"),
145  ),
146  ecal = cms.PSet(
147  src = cms.InputTag("gamIsoFromDepsEcalFromHits"),
148  ),
149  hcal = cms.PSet(
150  src = cms.InputTag("gamIsoFromDepsHcalFromTowers"),
151  ),
152  )
153 
154 
155 addPhotonUserIsolation=AddPhotonUserIsolation()