CMS 3D CMS Logo

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