CMS 3D CMS Logo

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