CMS 3D CMS Logo

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