Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 import math
0002 
0003 from PhysicsTools.Heppy.physicsobjects.PhysicsObjects import Muon, Tau, Electron
0004 from PhysicsTools.Heppy.physicsobjects.PhysicsObject import PhysicsObject
0005 from PhysicsTools.Heppy.physicsobjects.HTauTauElectron import HTauTauElectron
0006 from CMGTools.RootTools.utils.DeltaR import deltaR2
0007 
0008 class DiObject( PhysicsObject ):
0009     '''Generic di-object class, to handle di-objects from the EDM file
0010     '''
0011     
0012     def __init__(self, diobject):
0013         '''diobject is the di-object read from the edm file'''
0014         self.diobject = diobject
0015         self.leg1Gen = None
0016         self.leg2Gen = None
0017         self.leg1DeltaR = -1
0018         self.leg2DeltaR = -1
0019         super(DiObject, self).__init__(diobject)
0020 
0021     def sumPt(self):
0022         '''pt_leg1 + pt_leg2, e.g. used for finding the best DiTau.'''
0023         return self.leg1().pt() + self.leg2().pt()
0024 
0025     def __str__(self):
0026         header = '{cls}: mvis={mvis}, mT={mt}, sumpT={sumpt}'.format(
0027             cls = self.__class__.__name__,
0028             mvis = self.diobject.mass(),
0029             mt = self.diobject.mTLeg2(),
0030             sumpt = self.sumPt() )
0031         return '\n'.join( [header,
0032                            '\t'+str(self.leg1()),
0033                            '\t'+str(self.leg2())] )
0034 
0035 
0036 
0037 class DiMuon( DiObject ):
0038 
0039     def __init__(self, diobject):
0040         super(DiMuon, self).__init__(diobject)
0041         self.mu1 = Muon( diobject.leg1() )
0042         self.mu2 = Muon( diobject.leg2() )
0043 
0044     def leg1(self):
0045         return self.mu1
0046 
0047     def leg2(self):
0048         return self.mu2
0049 
0050     def __str__(self):
0051         return 'DiMuon: mass={mass:5.2f}, sumpt={sumpt:5.2f}, pt={pt:5.2f}'.format(
0052             mass = self.mass(),
0053             sumpt = self.sumPt(),
0054             pt = self.pt()
0055             )
0056     
0057 
0058 class DiElectron( DiObject ):
0059 
0060     def __init__(self, diobject):
0061         super(DiElectron, self).__init__(diobject)
0062         self.ele1 = Electron( diobject.leg1() )
0063         self.ele2 = Electron( diobject.leg2() )
0064 
0065     def leg1(self):
0066         return self.ele1
0067 
0068     def leg2(self):
0069         return self.ele2
0070 
0071     def __str__(self):
0072         header = 'DiElectron: mvis=%3.2f, sumpT=%3.2f' \
0073                  % (self.diobject.mass(),
0074                     self.sumPt() )
0075         return '\n'.join( [header] )
0076 
0077 
0078 class DiTau( DiObject ):
0079     def __init__(self, diobject):
0080         super(DiTau, self).__init__(diobject)
0081         
0082     def match(self, genParticles):
0083         #TODO review matching algorithm
0084         #TODO move matching stuff even higher?
0085         # print self
0086         genTaus = []
0087         ZorPhotonorHiggs = [22, 23, 25, 35, 36, 37]
0088         for gen in genParticles:
0089             # print '\t', gen
0090             if abs(gen.pdgId())==15 and gen.mother().pdgId() in ZorPhotonorHiggs:
0091                 genTaus.append( gen )
0092         # print 'Gen taus: '
0093         # print '\n'.join( map( str, genTaus ) )
0094         if len(genTaus)!=2:
0095             #COLIN what about WW, ZZ? 
0096             return (-1, -1)
0097         else:
0098             dR2leg1Min, self.leg1Gen = ( float('inf'), None)
0099             dR2leg2Min, self.leg2Gen = ( float('inf'), None) 
0100             for genTau in genTaus:
0101                 dR2leg1 = deltaR2(self.leg1().eta(), self.leg1().phi(),
0102                                   genTau.eta(), genTau.phi() )
0103                 dR2leg2 = deltaR2(self.leg2().eta(), self.leg2().phi(),
0104                                   genTau.eta(), genTau.phi() )
0105                 if dR2leg1 <  dR2leg1Min:
0106                     dR2leg1Min, self.leg1Gen = (dR2leg1, genTau)
0107                 if dR2leg2 <  dR2leg2Min:
0108                     dR2leg2Min, self.leg2Gen = (dR2leg2, genTau)
0109             # print dR2leg1Min, dR2leg2Min
0110             # print self.leg1Gen
0111             # print self.leg2Gen
0112             self.leg1DeltaR = math.sqrt( dR2leg1Min )
0113             self.leg2DeltaR = math.sqrt( dR2leg2Min )
0114             return (self.leg1DeltaR, self.leg2DeltaR)        
0115 
0116 
0117 class TauMuon( DiTau ):
0118     '''Holds a CMG TauMuon, and the 2 legs as a python Tau and Muon'''
0119     def __init__(self, diobject):
0120         super(TauMuon, self).__init__(diobject)
0121         self.tau = Tau( self.leg1() )
0122         self.mu = Muon( self.leg2() )
0123 
0124     def leg1(self):
0125         return self.tau
0126 
0127     def leg2(self):
0128         return self.mu
0129 
0130 
0131 
0132 class TauElectron( DiTau ):
0133     def __init__(self, diobject):
0134         super(TauElectron, self).__init__(diobject)
0135         self.tau = Tau( diobject.leg1() )
0136         self.ele = HTauTauElectron( diobject.leg2() )
0137 
0138     def leg1(self):
0139         return self.tau
0140 
0141     def leg2(self):
0142         return self.ele
0143 
0144 
0145 class MuonElectron( DiTau ):
0146     def __init__(self, diobject):
0147         super(MuonElectron, self).__init__(diobject)
0148         self.mu = Muon( diobject.leg1() )
0149         self.ele = HTauTauElectron( diobject.leg2() )
0150 
0151     def leg1(self):
0152         return self.mu
0153 
0154     def leg2(self):
0155         return self.ele
0156 
0157 
0158 class TauTau( DiTau ):
0159     def __init__(self, diobject):
0160         super(TauTau, self).__init__(diobject)
0161         self.tau = Tau( diobject.leg1() )
0162         self.tau2 = Tau( diobject.leg2() )
0163 
0164     def leg1(self):
0165         return self.tau
0166 
0167     def leg2(self):
0168         return self.tau2
0169     
0170