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 mvaId(self):
21  '''For a transparent treatment of electrons, muons and taus. Returns -99'''
22  return -99
23 
24  def dxy_approx(self, vertex=None):
25  '''Returns standard dxy for an arbitrary passed vertex'''
26  if vertex is None:
27  vertex = self.associatedVertex
28  vtx = self.leadChargedHadrCand().vertex()
29  p4 = self.p4()
30  return ( - (vtx.x()-vertex.position().x()) * p4.y()
31  + (vtx.y()-vertex.position().y()) * p4.x() ) / p4.pt()
32 
33  def dxy(self, vertex=None):
34  '''More precise dxy calculation as pre-calculated in the tau object
35  for the primary vertex it was constructed with.
36  Returns standard dxy calculation if the passed vertex differs from the
37  one in the tau object.
38  '''
39  if vertex is None:
40  vertex = self.associatedVertex
41  # x/y/z are directly saved in the tau object instead of a reference to
42  # the PV
43  if abs(vertex.z() == self.vertex().z()) < 0.0001:
44  return self.physObj.dxy()
45  else:
46  return self.dxy_approx(vertex)
47 
48  def dz(self, vertex=None):
49  if vertex is None:
50  vertex = self.associatedVertex
51  vtx = self.leadChargedHadrCand().vertex()
52  p4 = self.p4()
53  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()
54 
55  def zImpact(self, vertex=None):
56  '''z impact at ECAL surface'''
57  if vertex is None:
58  vertex = self.associatedVertex
59  return vertex.z() + 130./math.tan(self.theta())
60 
61  def __str__(self):
62  lep = super(Tau, self).__str__()
63  spec = '\t\tTau: decay = {decMode:<15}'.format(
64  decMode = tauDecayModes.intToName(self.decayMode())
65  )
66  return '\n'.join([lep, spec])
67 
68 
69 def isTau(leg):
70  '''Duck-typing a tau'''
71  try:
72  # Method independently implemented in pat tau and PF tau
73  leg.leadPFChargedHadrCandsignedSipt()
74  except AttributeError:
75  return False
76  return True
77 
def mvaId
Definition: Tau.py:20
def zImpact
Definition: Tau.py:55
def dxy
Definition: Tau.py:33
def relIso
Definition: Tau.py:16
def dz
Definition: Tau.py:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def dxy_approx
Definition: Tau.py:24
tau
Definition: Tau.py:13
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
Definition: Tau.py:10
def __str__
Definition: Tau.py:61
def __init__
Definition: Tau.py:12
Definition: Lepton.py:1
bool isTau(const Candidate &part)
Definition: pdgIdUtils.h:15