CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TauDecayModes.py
Go to the documentation of this file.
1 
2 class TauDecayModes( object ):
3 
4  def __init__(self):
5  self._decayModes()
6 
7  def _decayModes(self):
8  '''Builds the internal dictionaries from the enum defined in
9  http://cmslxr.fnal.gov/lxr/source/DataFormats/TauReco/interface/PFTau.h'''
10  tmp = [
11  'kNull',
12  'kOneProng0PiZero',
13  'kOneProng1PiZero',
14  'kOneProng2PiZero',
15  'kOneProng3PiZero',
16  'kOneProngNPiZero',
17  'kTwoProng0PiZero',
18  'kTwoProng1PiZero',
19  'kTwoProng2PiZero',
20  'kTwoProng3PiZero',
21  'kTwoProngNPiZero',
22  'kThreeProng0PiZero',
23  'kThreeProng1PiZero',
24  'kThreeProng2PiZero',
25  'kThreeProng3PiZero',
26  'kThreeProngNPiZero',
27  'kRareDecayMode'
28  ]
29  self.decayModes = dict( (index-1, name) for index, name in enumerate( tmp ) )
30  self.decayModeNames = dict( (value, key) for key, value \
31  in self.decayModes.iteritems() )
32 
33  def intToName( self, anInt ):
34  '''Returns the decay mode name corresponding to an int.'''
35  return self.decayModes[ anInt ]
36 
37  def nameToInt( self, aName ):
38  '''Returns the decay mode int corresponding to a name.'''
39  return self.decayModeNames[ aName ]
40 
41  def __str__(self):
42  return str( self.decayModes )
43 
44  def genDecayModeInt(self, daughters):
45  dm = self.genDecayMode(daughters)
46  return self.translateGenModeToInt(dm)
47 
48  def genDecayModeFromJetInt(self, c):
49  dm = self.genDecayModeFromGenJet(c)
50  return self.translateGenModeToInt(dm)
51 
52  def translateGenModeToInt(self, dm):
53  if dm in self.decayModeNames:
54  return self.nameToInt(dm)
55  elif dm == 'electron':
56  return -11
57  elif dm == 'muon':
58  return -13
59  elif dm == 'kOneProngOther':
60  return 100 # one-prong + 100
61  elif dm == 'kThreeProngOther':
62  return 110 # three-prong + 100
63  return -99
64 
65  @staticmethod
67  ''' Returns generated tau decay mode. Needs to be called on genJet
68  as stored in pat::Tau, if available.
69 
70  Translated from PhysicsTools/JetMCUtils/interface/JetMCTag.h,
71  which is not available in FWlite.
72  '''
73 
74  daughters = c.daughterPtrVector()
75 
76  return TauDecayModes.genDecayMode(daughters)
77 
78  @staticmethod
79  def genDecayMode(daughters):
80  ''' Returns the generated tau decay mode based on a passed list of all
81  final daughters before further decay (as contained in miniAOD).
82  '''
83  numElectrons = 0
84  numMuons = 0
85  numChargedHadrons = 0
86  numNeutralHadrons = 0
87  numPhotons = 0
88 
89  for daughter in daughters:
90  pdg_id = abs(daughter.pdgId())
91  if pdg_id == 22:
92  numPhotons += 1
93  elif pdg_id == 11:
94  numElectrons +=1
95  elif pdg_id == 13:
96  numMuons += 1
97  else:
98  if daughter.charge() != 0:
99  numChargedHadrons += 1
100  elif pdg_id not in [12, 14, 16]:
101  numNeutralHadrons += 1
102 
103  if numElectrons == 1:
104  return "electron"
105  if numMuons == 1:
106  return "muon"
107 
108  if numChargedHadrons == 1:
109  if numNeutralHadrons != 0:
110  return "kOneProngOther"
111  if numPhotons == 0:
112  return "kOneProng0PiZero"
113  elif numPhotons == 2:
114  return "kOneProng1PiZero"
115  elif numPhotons == 4:
116  return "kOneProng2PiZero"
117  elif numPhotons == 6:
118  return "kOneProng3PiZero"
119  else:
120  return "kOneProngNPiZero"
121  elif numChargedHadrons == 3:
122  if numNeutralHadrons != 0:
123  return "kThreeProngOther"
124  if numPhotons == 0:
125  return "kThreeProng0PiZero"
126  elif numPhotons == 2:
127  return "kThreeProng1PiZero"
128  elif numPhotons == 4:
129  return "kThreeProng2PiZero"
130  elif numPhotons == 6:
131  return "kThreeProng3PiZero"
132  else:
133  return "kThreeProngNPiZero"
134 
135  return "kRareDecayMode"
136 
137 tauDecayModes = TauDecayModes()
138 
139 if __name__ == '__main__':
140 
142  print dec
143 
144  print 0, dec.intToName(0)
145  print 'kThreeProng0PiZero', dec.nameToInt('kThreeProng0PiZero')
Abs< T >::type abs(const T &t)
Definition: Abs.h:22