CMS 3D CMS Logo

PFTauDecayModeTools.cc
Go to the documentation of this file.
1 #include <map>
5 
6 namespace reco {
7  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[] = {{"unknown", reco::PFTau::kNull},
19  {"oneProng0Pi0", reco::PFTau::kOneProng0PiZero},
20  {"oneProng1Pi0", reco::PFTau::kOneProng1PiZero},
21  {"oneProng2Pi0", reco::PFTau::kOneProng2PiZero},
22  {"oneProngOther", reco::PFTau::kOneProngNPiZero},
23  {"threeProng0Pi0", reco::PFTau::kThreeProng0PiZero},
24  {"threeProng1Pi0", reco::PFTau::kThreeProng1PiZero},
25  {"threeProngOther", reco::PFTau::kThreeProngNPiZero},
26  {"electron", reco::PFTau::kNull},
27  {"muon", reco::PFTau::kNull},
28  {nullptr, reco::PFTau::kNull}};
29 
30  constexpr bool same(char const *x, char const *y) { return !*x && !*y ? true : (*x == *y && same(x + 1, y + 1)); }
31 
32  constexpr enum reco::PFTau::hadronicDecayMode decayModeStringToId(char const *label, entry const *entries) {
33  return !entries->label ? reco::PFTau::kRareDecayMode
34  : same(entries->label, label) ? entries->mode : decayModeStringToId(label, entries + 1);
35  }
36 
37  constexpr char const *decayModeIdToString(reco::PFTau::hadronicDecayMode mode, entry const *entries) {
38  return !entries->label ? "unknown"
39  : (entries->mode == mode ? entries->label : decayModeIdToString(mode, entries + 1));
40  }
41  } // namespace
42 
44  int modeAsInt = static_cast<int>(mode);
45  return (modeAsInt / PFTau::kOneProngNPiZero) + 1;
46  }
47 
49  int modeAsInt = static_cast<int>(mode);
50  return (modeAsInt % PFTau::kOneProngNPiZero);
51  }
52 
54  // If no tracks exist, this is definitely not a tau!
55  if (!nCharged)
56  return PFTau::kNull;
57  // Find the maximum number of PiZeros our parameterization can hold
58  const unsigned int maxPiZeros = PFTau::kOneProngNPiZero;
59  // Determine our track index
60  unsigned int trackIndex = (nCharged - 1) * (maxPiZeros + 1);
61  // Check if we handle the given number of tracks
62  if (trackIndex >= PFTau::kRareDecayMode)
63  return PFTau::kRareDecayMode;
64 
65  nPiZeros = (nPiZeros <= maxPiZeros) ? nPiZeros : maxPiZeros;
66  return static_cast<PFTau::hadronicDecayMode>(trackIndex + nPiZeros);
67  }
68 
70  return decayModeStringToId(name.c_str(), dmTranslatorMap);
71  }
72 
74  return decayModeIdToString(decayMode, dmTranslatorMap);
75  }
76 
78  if (!genJet)
79  return reco::PFTau::kNull;
81  }
82 
83  } // namespace tau
84 } // namespace reco
std::string genTauDecayMode(const reco::CompositePtrCandidate &c)
Definition: JetMCTag.cc:70
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;)
char const * label
Jets made from MC generator particles.
Definition: GenJet.h:23
fixed size matrix
hadronicDecayMode
Definition: PFTau.h:38
unsigned int piZerosInDecayMode(PFTau::hadronicDecayMode mode)
reco::PFTau::hadronicDecayMode mode
unsigned int chargedHadronsInDecayMode(PFTau::hadronicDecayMode mode)
Reverse mapping of decay modes into multiplicities.
#define constexpr