CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Tau.py
Go to the documentation of this file.
1 from PhysicsTools.Heppy.physicsobjects.Lepton import Lepton
2 from PhysicsTools.Heppy.physicsutils.TauDecayModes import tauDecayModes
3 import math
4 
5 # Find all tau IDs here:
6 # https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuidePFTauID#Tau_ID_2014_preparation_for_AN1
7 # and the names by which they are accessible with tau.tauId(...) here
8 # http://cmslxr.fnal.gov/lxr/source/PhysicsTools/PatAlgos/python/producersLayer1/tauProducer_cfi.py
9 
10 class Tau(Lepton):
11 
12  def __init__(self, tau):
13  self.tau = tau
14  super(Tau, self).__init__(tau)
15 
16  def relIso(self, dBetaFactor=0, allCharged=0):
17  '''Just making the tau behave as a lepton, with dummy parameters.'''
18  return -1
19 
20  def relIsoR(self, R=0.3, dBetaFactor=0, allCharged=0):
21  '''Just making the tau behave as a lepton, with dummy parameters.'''
22  return -1
23 
24  def mvaId(self):
25  '''For a transparent treatment of electrons, muons and taus. Returns -99'''
26  return -99
27 
28  def dxy_approx(self, vertex=None):
29  '''Returns standard dxy for an arbitrary passed vertex'''
30  if vertex is None:
31  vertex = self.associatedVertex
32  vtx = self.leadChargedHadrCand().vertex()
33  p4 = self.p4()
34  return ( - (vtx.x()-vertex.position().x()) * p4.y()
35  + (vtx.y()-vertex.position().y()) * p4.x() ) / p4.pt()
36 
37  def dxy(self, vertex=None):
38  '''More precise dxy calculation as pre-calculated in the tau object
39  for the primary vertex it was constructed with.
40  Returns standard dxy calculation if the passed vertex differs from the
41  one in the tau object.
42  '''
43  if vertex is None:
44  vertex = self.associatedVertex
45  # x/y/z are directly saved in the tau object instead of a reference to
46  # the PV
47  if abs(vertex.z() == self.vertex().z()) < 0.0001:
48  return self.physObj.dxy()
49  else:
50  return self.dxy_approx(vertex)
51 
52  def dz(self, vertex=None):
53  if vertex is None:
54  vertex = self.associatedVertex
55  vtx = self.leadChargedHadrCand().vertex()
56  p4 = self.p4()
57  return (vtx.z()-vertex.position().z()) - ((vtx.x()-vertex.position().x())*p4.x()+(vtx.y()-vertex.position().y())*p4.y())/ p4.pt() * p4.z()/ p4.pt()
58 
59  def zImpact(self, vertex=None):
60  '''z impact at ECAL surface'''
61  if vertex is None:
62  vertex = self.associatedVertex
63  return vertex.z() + 130./math.tan(self.theta())
64 
65  def __str__(self):
66  lep = super(Tau, self).__str__()
67  spec = '\t\tTau: decay = {decMode:<15}'.format(
68  decMode = tauDecayModes.intToName(self.decayMode())
69  )
70  return '\n'.join([lep, spec])
71 
72 
73 def isTau(leg):
74  '''Duck-typing a tau'''
75  try:
76  # Method independently implemented in pat tau and PF tau
77  leg.leadPFChargedHadrCandsignedSipt()
78  except AttributeError:
79  return False
80  return True
81 
def mvaId
Definition: Tau.py:24
def zImpact
Definition: Tau.py:59
def dxy
Definition: Tau.py:37
def relIso
Definition: Tau.py:16
def dz
Definition: Tau.py:52
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def dxy_approx
Definition: Tau.py:28
tau
Definition: Tau.py:13
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
Definition: Tau.py:10
def __str__
Definition: Tau.py:65
def __init__
Definition: Tau.py:12
Definition: Lepton.py:1
def relIsoR
Definition: Tau.py:20
bool isTau(const Candidate &part)
Definition: pdgIdUtils.h:15