CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Muon.py
Go to the documentation of this file.
1 from PhysicsTools.Heppy.physicsobjects.Lepton import Lepton
2 
3 class Muon( Lepton ):
4  def __init__(self, *args, **kwargs):
5  super(Muon, self).__init__(*args, **kwargs)
6  self._trackForDxyDz = "muonBestTrack"
7 
8  def setTrackForDxyDz(self,what):
9  if not hasattr(self,what):
10  raise RuntimeError, "I don't have a track called "+what
11  self._trackForDxyDz = what
12 
13  def looseId( self ):
14  '''Loose ID as recommended by mu POG.'''
15  return self.physObj.isLooseMuon()
16 
17  def tightId( self ):
18  '''Tight ID as recommended by mu POG (unless redefined in the lepton analyzer).'''
19  return getattr(self,"tightIdResult",self.muonID("POG_ID_Tight"))
20 
21  def muonID(self, name, vertex=None):
22  if name == "" or name is None:
23  return True
24  if name.startswith("POG_"):
25  if name == "POG_ID_Loose": return self.physObj.isLooseMuon()
26  if vertex is None:
27  vertex = getattr(self, 'associatedVertex', None)
28  if name == "POG_ID_Tight": return self.physObj.isTightMuon(vertex)
29  if name == "POG_ID_HighPt": return self.physObj.isHighPtMuon(vertex)
30  if name == "POG_ID_Soft": return self.physObj.isSoftMuon(vertex)
31  if name == "POG_ID_TightNoVtx": return self.looseId() and \
32  self.isGlobalMuon() and \
33  self.globalTrack().normalizedChi2() < 10 and \
34  self.globalTrack().hitPattern().numberOfValidMuonHits() > 0 and \
35  self.numberOfMatchedStations()>1 and \
36  self.innerTrack().hitPattern().numberOfValidPixelHits()>0 and \
37  self.innerTrack().hitPattern().trackerLayersWithMeasurement() > 5
38  if name == "POG_ID_Medium":
39  if not self.looseId(): return False
40  goodGlb = self.physObj.isGlobalMuon() and self.physObj.globalTrack().normalizedChi2() < 3 and self.physObj.combinedQuality().chi2LocalPosition < 12 and self.physObj.combinedQuality().trkKink < 20;
41  return self.physObj.innerTrack().validFraction() >= 0.8 and self.physObj.segmentCompatibility() >= (0.303 if goodGlb else 0.451)
42  if name == "POG_Global_OR_TMArbitrated":
43  return self.physObj.isGlobalMuon() or (self.physObj.isTrackerMuon() and self.physObj.numberOfMatchedStations() > 0)
44  return self.physObj.muonID(name)
45 
46  def mvaId(self):
47  '''For a transparent treatment of electrons and muons. Returns -99'''
48  return -99
49 
50 
51 
52  def absEffAreaIso(self,rho,effectiveAreas):
53  return self.absIsoFromEA(rho,self.eta(),effectiveAreas.muon)
54 
55 
56 
57  def dxy(self, vertex=None):
58  '''either pass the vertex, or set associatedVertex before calling the function.
59  note: the function does not work with standalone muons as innerTrack
60  is not available.
61  '''
62  if vertex is None:
63  vertex = self.associatedVertex
64  return getattr(self,self._trackForDxyDz)().dxy( vertex.position() )
65 
66  def edxy(self):
67  '''returns the uncertainty on dxy (from gsf track)'''
68  return getattr(self,self._trackForDxyDz)().dxyError()
69 
70 
71  def dz(self, vertex=None):
72  '''either pass the vertex, or set associatedVertex before calling the function.
73  note: the function does not work with standalone muons as innerTrack
74  is not available.
75  '''
76  if vertex is None:
77  vertex = self.associatedVertex
78  return getattr(self,self._trackForDxyDz)().dz( vertex.position() )
79 
80  def edz(self):
81  '''returns the uncertainty on dxz (from gsf track)'''
82  return getattr(self,self._trackForDxyDz)().dzError()
83 
84  def chargedHadronIsoR(self,R=0.4):
85  if R == 0.3: return self.physObj.pfIsolationR03().sumChargedHadronPt
86  elif R == 0.4: return self.physObj.pfIsolationR04().sumChargedHadronPt
87  raise RuntimeError, "Muon chargedHadronIso missing for R=%s" % R
88 
89  def neutralHadronIsoR(self,R=0.4):
90  if R == 0.3: return self.physObj.pfIsolationR03().sumNeutralHadronEt
91  elif R == 0.4: return self.physObj.pfIsolationR04().sumNeutralHadronEt
92  raise RuntimeError, "Muon neutralHadronIso missing for R=%s" % R
93 
94  def photonIsoR(self,R=0.4):
95  if R == 0.3: return self.physObj.pfIsolationR03().sumPhotonEt
96  elif R == 0.4: return self.physObj.pfIsolationR04().sumPhotonEt
97  raise RuntimeError, "Muon photonIso missing for R=%s" % R
98 
99  def chargedAllIsoR(self,R=0.4):
100  if R == 0.3: return self.physObj.pfIsolationR03().sumChargedParticlePt
101  elif R == 0.4: return self.physObj.pfIsolationR04().sumChargedParticlePt
102  raise RuntimeError, "Muon chargedAllIso missing for R=%s" % R
103 
104  def chargedAllIso(self):
105  return self.chargedAllIsoR()
106 
107  def puChargedHadronIsoR(self,R=0.4):
108  if R == 0.3: return self.physObj.pfIsolationR03().sumPUPt
109  elif R == 0.4: return self.physObj.pfIsolationR04().sumPUPt
110  raise RuntimeError, "Muon chargedHadronIso missing for R=%s" % R
111 
112 
113 
114 
def chargedHadronIsoR
Definition: Muon.py:84
def dxy
Definition: Muon.py:57
def chargedAllIso
Definition: Muon.py:104
def edxy
Definition: Muon.py:66
def neutralHadronIsoR
Definition: Muon.py:89
def setTrackForDxyDz
Definition: Muon.py:8
def photonIsoR
Definition: Muon.py:94
def mvaId
Definition: Muon.py:46
def __init__
Definition: Muon.py:4
def edz
Definition: Muon.py:80
def absEffAreaIso
Definition: Muon.py:52
Definition: Muon.py:3
_trackForDxyDz
Definition: Muon.py:6
def looseId
Definition: Muon.py:13
def dz
Definition: Muon.py:71
def tightId
Definition: Muon.py:17
def puChargedHadronIsoR
Definition: Muon.py:107
Definition: Lepton.py:1
def chargedAllIsoR
Definition: Muon.py:99
def muonID
Definition: Muon.py:21