Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:28

0001 from PhysicsTools.Heppy.physicsobjects.Lepton import Lepton
0002 from PhysicsTools.Heppy.physicsutils.TauDecayModes import tauDecayModes
0003 import math
0004 
0005 # Find all tau IDs here: 
0006 # https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuidePFTauID#Tau_ID_2014_preparation_for_AN1
0007 # and the names by which they are accessible with tau.tauId(...) here
0008 # http://cmslxr.fnal.gov/lxr/source/PhysicsTools/PatAlgos/python/producersLayer1/tauProducer_cfi.py
0009 
0010 class Tau(Lepton):
0011     
0012     def __init__(self, tau):
0013         self.tau = tau
0014         super(Tau, self).__init__(tau)
0015         
0016     def relIso(self, dBetaFactor=0, allCharged=0):
0017         '''Just making the tau behave as a lepton, with dummy parameters.'''
0018         return -1
0019 
0020     def relIsoR(self, R=0.3, dBetaFactor=0, allCharged=0):
0021         '''Just making the tau behave as a lepton, with dummy parameters.'''
0022         return -1
0023 
0024     def mvaId(self):
0025         '''For a transparent treatment of electrons, muons and taus. Returns -99'''
0026         return -99
0027 
0028     def dxy_approx(self, vertex=None):
0029         '''Returns standard dxy for an arbitrary passed vertex'''
0030         if vertex is None:
0031             vertex = self.associatedVertex
0032         vtx = self.leadChargedHadrCand().vertex()
0033         p4 = self.p4()
0034         return ( - (vtx.x()-vertex.position().x()) *  p4.y()
0035                  + (vtx.y()-vertex.position().y()) *  p4.x() ) /  p4.pt()
0036 
0037     def dxy(self, vertex=None):
0038         '''More precise dxy calculation as pre-calculated in the tau object
0039         for the primary vertex it was constructed with.
0040         Returns standard dxy calculation if the passed vertex differs from the
0041         one in the tau object.
0042         '''
0043         if vertex is None:
0044             vertex = self.associatedVertex
0045         # x/y/z are directly saved in the tau object instead of a reference to 
0046         # the PV
0047         if abs(vertex.z() == self.vertex().z()) < 0.0001:
0048             return self.physObj.dxy()
0049         else:
0050             return self.dxy_approx(vertex)
0051 
0052     def dz(self, vertex=None):
0053         if vertex is None:
0054             vertex = self.associatedVertex
0055         vtx = self.leadChargedHadrCand().vertex()
0056         p4 = self.p4()
0057         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()
0058     
0059     def zImpact(self, vertex=None):
0060         '''z impact at ECAL surface'''
0061         if vertex is None:
0062             vertex = self.associatedVertex
0063         return vertex.z() + 130./math.tan(self.theta())
0064 
0065     def __str__(self):
0066         lep = super(Tau, self).__str__()
0067         spec = '\t\tTau: decay = {decMode:<15}'.format(
0068             decMode = tauDecayModes.intToName(self.decayMode())
0069         )
0070         return '\n'.join([lep, spec])
0071 
0072 
0073 def isTau(leg):
0074     '''Duck-typing a tau'''
0075     try:
0076         # Method independently implemented in pat tau and PF tau
0077         leg.leadPFChargedHadrCandsignedSipt()
0078     except AttributeError:
0079         return False
0080     return True
0081