CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFTauDecayModeTools.cc
Go to the documentation of this file.
1 #include <map>
2 #include <boost/assign.hpp>
6 
7 namespace reco { namespace tau {
8 
9 namespace {
10  struct entry {
11  char const *label;
13  };
14 
15  // Convert the string decay mode from PhysicsTools to the
16  // PFTau::hadronicDecayMode format
17  constexpr entry dmTranslatorMap[] = {
18  {"unknown", reco::PFTau::kNull},
20  {"oneProng0Pi0", reco::PFTau::kOneProng0PiZero},
21  {"oneProng1Pi0", reco::PFTau::kOneProng1PiZero},
22  {"oneProng2Pi0", reco::PFTau::kOneProng2PiZero},
23  {"oneProngOther", reco::PFTau::kOneProngNPiZero},
24  {"threeProng0Pi0", reco::PFTau::kThreeProng0PiZero},
25  {"threeProng1Pi0", reco::PFTau::kThreeProng1PiZero},
26  {"threeProngOther", reco::PFTau::kThreeProngNPiZero},
27  {"electron", reco::PFTau::kNull},
28  {"muon", reco::PFTau::kNull},
30  };
31 
32  constexpr bool same(char const *x, char const *y) {
33  return !*x && !*y ? true : (*x == *y && same(x+1, y+1));
34  }
35 
36  constexpr enum reco::PFTau::hadronicDecayMode decayModeStringToId(char const *label, entry const *entries) {
37  return !entries->label ? reco::PFTau::kRareDecayMode : same(entries->label, label) ? entries->mode : decayModeStringToId(label, entries+1);
38  }
39 
40  constexpr char const *decayModeIdToString(reco::PFTau::hadronicDecayMode mode, entry const *entries) {
41  return !entries->label ? "unknown" : (entries->mode == mode ? entries->label : decayModeIdToString(mode, entries+1));
42  }
43 }
44 
46  int modeAsInt = static_cast<int>(mode);
47  return (modeAsInt / PFTau::kOneProngNPiZero) + 1;
48 }
49 
51  int modeAsInt = static_cast<int>(mode);
52  return (modeAsInt % PFTau::kOneProngNPiZero);
53 }
54 
56  unsigned int nCharged, unsigned int nPiZeros) {
57  // If no tracks exist, this is definitely not a tau!
58  if(!nCharged) return PFTau::kNull;
59  // Find the maximum number of PiZeros our parameterization can hold
60  const unsigned int maxPiZeros = PFTau::kOneProngNPiZero;
61  // Determine our track index
62  unsigned int trackIndex = (nCharged-1)*(maxPiZeros+1);
63  // Check if we handle the given number of tracks
64  if(trackIndex >= PFTau::kRareDecayMode) return PFTau::kRareDecayMode;
65 
66  nPiZeros = (nPiZeros <= maxPiZeros) ? nPiZeros : maxPiZeros;
67  return static_cast<PFTau::hadronicDecayMode>(trackIndex + nPiZeros);
68 }
69 
71  const std::string& name) {
72  return decayModeStringToId(name.c_str(), dmTranslatorMap);
73 }
74 
76  return decayModeIdToString(decayMode, dmTranslatorMap);
77 }
78 
79 
81  if (!genJet)
82  return reco::PFTau::kNull;
84 }
85 
86 }} // end namespace reco::tau
std::string genTauDecayMode(const reco::CompositePtrCandidate &c)
Definition: JetMCTag.cc:81
PFTau::hadronicDecayMode translateGenDecayModeToReco(const std::string &genName)
Convert a genTau decay mode string (&#39;oneProng0Pi0&#39;) to the RECO enum.
PFTau::hadronicDecayMode translateDecayMode(unsigned int nCharged, unsigned int nPiZero)
PFTau::hadronicDecayMode getDecayMode(const reco::GenJet *genJet)
std::string translateRecoDecayModeToGen(PFTau::hadronicDecayMode decayMode)
Convert a RECO enum decay mode to a string (&#39;oneProng0Pi0&#39;)
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
Jets made from MC generator particles.
Definition: GenJet.h:25
unsigned int nCharged(const GenJet &jet)
hadronicDecayMode
Definition: PFTau.h:34
unsigned int piZerosInDecayMode(PFTau::hadronicDecayMode mode)
x
Definition: VDTMath.h:216
unsigned int chargedHadronsInDecayMode(PFTau::hadronicDecayMode mode)
Reverse mapping of decay modes into multiplicities.
#define constexpr