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 cutsElectronMVA3Medium = [0.933,0.921,0.944,0.945,0.918,0.941,0.981,0.943,0.956,0.947,0.951,0.95,0.897,0.958,0.955,0.942]
6 
7 class Tau( Lepton ):
8 
9  def __init__(self, tau):
10  self.tau = tau
11  super(Tau, self).__init__(tau)
12  self.eOverP = None
13 
14  # JAN FIXME - check what's available in miniAOD and if we need this at all
15  def calcEOverP(self):
16  if self.eOverP is not None:
17  return self.eOverP
18  self.leadChargedEnergy = self.tau.leadChargedHadrEcalEnergy() \
19  + self.tau.leadChargedHadrHcalEnergy()
20  # self.leadChargedMomentum = self.tau.leadChargedHadrPt() / math.sin(self.tau.theta())
21  self.leadChargedMomentum = self.tau.leadPFChargedHadrCand().energy()
23  return self.eOverP
24 
25  def relIso(self, dummy1, dummy2):
26  '''Just making the tau behave as a lepton.'''
27  return -1
28 
29  def mvaId(self):
30  '''For a transparent treatment of electrons, muons and taus. Returns -99'''
31  return -99
32 
33  def dxy(self, vertex=None):
34  if vertex is None:
35  vertex = self.associatedVertex
36  vtx = self.vertex() # FIXME
37  p4 = self.p4()
38  return ( - (vtx.x()-vertex.position().x()) * p4.y()
39  + (vtx.y()-vertex.position().y()) * p4.x() ) / p4.pt()
40 
41  def dz(self, vertex=None):
42  if vertex is None:
43  vertex = self.associatedVertex
44  vtx = self.vertex() # FIXME
45  p4 = self.p4()
46  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()
47 
48  def zImpact(self, vertex=None):
49  '''z impact at ECAL surface'''
50  if vertex is None:
51  vertex = self.associatedVertex
52  return vertex.z() + 130./math.tan(self.theta())
53 
54  def __str__(self):
55  lep = super(Tau, self).__str__()
56  return lep
57  #spec = '\t\tTau: decay = {decMode:<15}, eOverP = {eOverP:4.2f}, isoMVALoose = {isoMVALoose}'.format(
58  # decMode = tauDecayModes.intToName( self.decayMode() ),
59  # eOverP = self.calcEOverP(),
60  # isoMVALoose = self.tauID('byLooseIsoMVA')
61  # )
62  #return '\n'.join([lep, spec])
63 
64  def electronMVA3Medium(self):
65  '''Custom electron MVA 3 medium WP used for H->tau tau'''
66  icat = int(round(self.tauID('againstElectronMVA3category')))
67  if icat < 0:
68  return False
69  elif icat > 15:
70  return True
71 
72  rawMVA = self.tauID('againstElectronMVA3raw')
73  return rawMVA > cutsElectronMVA3Medium[icat]
74 
75 
76 def isTau(leg):
77  '''Duck-typing a tau'''
78  try:
79  # Taken from BaseTau to work for both PFTaus and PAT Taus
80  # (can maybe find a less expensive method)
81  leg.leadTrack()
82  except AttributeError:
83  return False
84  return True
85 
def mvaId
Definition: Tau.py:29
def zImpact
Definition: Tau.py:48
def electronMVA3Medium
Definition: Tau.py:64
def dxy
Definition: Tau.py:33
def relIso
Definition: Tau.py:25
float float float z
def dz
Definition: Tau.py:41
def calcEOverP
Definition: Tau.py:15
tau
Definition: Tau.py:10
eOverP
Definition: Tau.py:12
Definition: Tau.py:7
def __str__
Definition: Tau.py:54
def __init__
Definition: Tau.py:9
Definition: Lepton.py:1
leadChargedMomentum
Definition: Tau.py:21
Definition: DDAxes.h:10
leadChargedEnergy
Definition: Tau.py:18
bool isTau(const Candidate &part)
Definition: pdgIdUtils.h:15