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
35  : decayModeStringToId(label, entries + 1);
36  }
37 
38  constexpr char const *decayModeIdToString(reco::PFTau::hadronicDecayMode mode, entry const *entries) {
39  return !entries->label ? "unknown"
40  : (entries->mode == mode ? entries->label : decayModeIdToString(mode, entries + 1));
41  }
42  } // namespace
43 
45  int modeAsInt = static_cast<int>(mode);
46  return (modeAsInt / PFTau::kOneProngNPiZero) + 1;
47  }
48 
50  int modeAsInt = static_cast<int>(mode);
51  return (modeAsInt % PFTau::kOneProngNPiZero);
52  }
53 
55  // If no tracks exist, this is definitely not a tau!
56  if (!nCharged)
57  return PFTau::kNull;
58  // Find the maximum number of PiZeros our parameterization can hold
59  const unsigned int maxPiZeros = PFTau::kOneProngNPiZero;
60  // Determine our track index
61  unsigned int trackIndex = (nCharged - 1) * (maxPiZeros + 1);
62  // Check if we handle the given number of tracks
63  if (trackIndex >= PFTau::kRareDecayMode)
64  return PFTau::kRareDecayMode;
65 
67  return static_cast<PFTau::hadronicDecayMode>(trackIndex + nPiZeros);
68  }
69 
71  return decayModeStringToId(name.c_str(), dmTranslatorMap);
72  }
73 
75  return decayModeIdToString(decayMode, dmTranslatorMap);
76  }
77 
79  if (!genJet)
80  return reco::PFTau::kNull;
82  }
83 
84  } // namespace tau
85 } // 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
float x
unsigned int piZerosInDecayMode(PFTau::hadronicDecayMode mode)
reco::PFTau::hadronicDecayMode mode
unsigned int chargedHadronsInDecayMode(PFTau::hadronicDecayMode mode)
Reverse mapping of decay modes into multiplicities.