CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DiObject.py
Go to the documentation of this file.
1 import math
2 
3 from PhysicsTools.Heppy.physicsobjects.PhysicsObjects import Muon, Tau, Electron
5 from PhysicsTools.Heppy.physicsobjects.HTauTauElectron import HTauTauElectron
6 from CMGTools.RootTools.utils.DeltaR import deltaR2
7 
9  '''Generic di-object class, to handle di-objects from the EDM file
10  '''
11 
12  def __init__(self, diobject):
13  '''diobject is the di-object read from the edm file'''
14  self.diobject = diobject
15  self.leg1Gen = None
16  self.leg2Gen = None
17  self.leg1DeltaR = -1
18  self.leg2DeltaR = -1
19  super(DiObject, self).__init__(diobject)
20 
21  def sumPt(self):
22  '''pt_leg1 + pt_leg2, e.g. used for finding the best DiTau.'''
23  return self.leg1().pt() + self.leg2().pt()
24 
25  def __str__(self):
26  header = '{cls}: mvis={mvis}, mT={mt}, sumpT={sumpt}'.format(
27  cls = self.__class__.__name__,
28  mvis = self.diobject.mass(),
29  mt = self.diobject.mTLeg2(),
30  sumpt = self.sumPt() )
31  return '\n'.join( [header,
32  '\t'+str(self.leg1()),
33  '\t'+str(self.leg2())] )
34 
35 
36 
37 class DiMuon( DiObject ):
38 
39  def __init__(self, diobject):
40  super(DiMuon, self).__init__(diobject)
41  self.mu1 = Muon( diobject.leg1() )
42  self.mu2 = Muon( diobject.leg2() )
43 
44  def leg1(self):
45  return self.mu1
46 
47  def leg2(self):
48  return self.mu2
49 
50  def __str__(self):
51  return 'DiMuon: mass={mass:5.2f}, sumpt={sumpt:5.2f}, pt={pt:5.2f}'.format(
52  mass = self.mass(),
53  sumpt = self.sumPt(),
54  pt = self.pt()
55  )
56 
57 
59 
60  def __init__(self, diobject):
61  super(DiElectron, self).__init__(diobject)
62  self.ele1 = Electron( diobject.leg1() )
63  self.ele2 = Electron( diobject.leg2() )
64 
65  def leg1(self):
66  return self.ele1
67 
68  def leg2(self):
69  return self.ele2
70 
71  def __str__(self):
72  header = 'DiElectron: mvis=%3.2f, sumpT=%3.2f' \
73  % (self.diobject.mass(),
74  self.sumPt() )
75  return '\n'.join( [header] )
76 
77 
78 class DiTau( DiObject ):
79  def __init__(self, diobject):
80  super(DiTau, self).__init__(diobject)
81 
82  def match(self, genParticles):
83  #TODO review matching algorithm
84  #TODO move matching stuff even higher?
85  # print self
86  genTaus = []
87  ZorPhotonorHiggs = [22, 23, 25, 35, 36, 37]
88  for gen in genParticles:
89  # print '\t', gen
90  if abs(gen.pdgId())==15 and gen.mother().pdgId() in ZorPhotonorHiggs:
91  genTaus.append( gen )
92  # print 'Gen taus: '
93  # print '\n'.join( map( str, genTaus ) )
94  if len(genTaus)!=2:
95  #COLIN what about WW, ZZ?
96  return (-1, -1)
97  else:
98  dR2leg1Min, self.leg1Gen = ( float('inf'), None)
99  dR2leg2Min, self.leg2Gen = ( float('inf'), None)
100  for genTau in genTaus:
101  dR2leg1 = deltaR2(self.leg1().eta(), self.leg1().phi(),
102  genTau.eta(), genTau.phi() )
103  dR2leg2 = deltaR2(self.leg2().eta(), self.leg2().phi(),
104  genTau.eta(), genTau.phi() )
105  if dR2leg1 < dR2leg1Min:
106  dR2leg1Min, self.leg1Gen = (dR2leg1, genTau)
107  if dR2leg2 < dR2leg2Min:
108  dR2leg2Min, self.leg2Gen = (dR2leg2, genTau)
109  # print dR2leg1Min, dR2leg2Min
110  # print self.leg1Gen
111  # print self.leg2Gen
112  self.leg1DeltaR = math.sqrt( dR2leg1Min )
113  self.leg2DeltaR = math.sqrt( dR2leg2Min )
114  return (self.leg1DeltaR, self.leg2DeltaR)
115 
116 
117 class TauMuon( DiTau ):
118  '''Holds a CMG TauMuon, and the 2 legs as a python Tau and Muon'''
119  def __init__(self, diobject):
120  super(TauMuon, self).__init__(diobject)
121  self.tau = Tau( self.leg1() )
122  self.mu = Muon( self.leg2() )
123 
124  def leg1(self):
125  return self.tau
126 
127  def leg2(self):
128  return self.mu
129 
130 
131 
133  def __init__(self, diobject):
134  super(TauElectron, self).__init__(diobject)
135  self.tau = Tau( diobject.leg1() )
136  self.ele = HTauTauElectron( diobject.leg2() )
137 
138  def leg1(self):
139  return self.tau
140 
141  def leg2(self):
142  return self.ele
143 
144 
146  def __init__(self, diobject):
147  super(MuonElectron, self).__init__(diobject)
148  self.mu = Muon( diobject.leg1() )
149  self.ele = HTauTauElectron( diobject.leg2() )
150 
151  def leg1(self):
152  return self.mu
153 
154  def leg2(self):
155  return self.ele
156 
157 
158 class TauTau( DiTau ):
159  def __init__(self, diobject):
160  super(TauTau, self).__init__(diobject)
161  self.tau = Tau( diobject.leg1() )
162  self.tau2 = Tau( diobject.leg2() )
163 
164  def leg1(self):
165  return self.tau
166 
167  def leg2(self):
168  return self.tau2
169 
170 
Definition: Muon.py:1
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: Tau.py:1
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36