CMS 3D CMS Logo

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 
Tau.Tau
Definition: Tau.py:10
Lepton
Definition: Lepton.py:1
Tau.Tau.tau
tau
Definition: Tau.py:13
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
Tau.Tau.dxy_approx
def dxy_approx(self, vertex=None)
Definition: Tau.py:28
Tau.Tau.relIso
def relIso(self, dBetaFactor=0, allCharged=0)
Definition: Tau.py:16
Tau.Tau.dz
def dz(self, vertex=None)
Definition: Tau.py:52
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
Tau.Tau.__str__
def __str__(self)
Definition: Tau.py:65
Tau.isTau
def isTau(leg)
Definition: Tau.py:73
Tau.Tau.mvaId
def mvaId(self)
Definition: Tau.py:24
Tau.Tau.zImpact
def zImpact(self, vertex=None)
Definition: Tau.py:59
format
Tau.Tau.relIsoR
def relIsoR(self, R=0.3, dBetaFactor=0, allCharged=0)
Definition: Tau.py:20
Tau.Tau.__init__
def __init__(self, tau)
Definition: Tau.py:12
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Tau.Tau.dxy
def dxy(self, vertex=None)
Definition: Tau.py:37