Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-12 03:09:40

0001 #include <map>
0002 #include "RecoTauTag/RecoTau/interface/PFTauDecayModeTools.h"
0003 #include "DataFormats/JetReco/interface/GenJet.h"
0004 #include "PhysicsTools/JetMCUtils/interface/JetMCTag.h"
0005 
0006 namespace reco {
0007   namespace tau {
0008 
0009     namespace {
0010       struct entry {
0011         char const *label;
0012         reco::PFTau::hadronicDecayMode mode;
0013       };
0014 
0015       // Convert the string decay mode from PhysicsTools to the
0016       // PFTau::hadronicDecayMode format
0017       constexpr entry dmTranslatorMap[] = {{"unknown", reco::PFTau::kNull},
0018                                            {"rare", reco::PFTau::kRareDecayMode},
0019                                            {"oneProng0Pi0", reco::PFTau::kOneProng0PiZero},
0020                                            {"oneProng1Pi0", reco::PFTau::kOneProng1PiZero},
0021                                            {"oneProng2Pi0", reco::PFTau::kOneProng2PiZero},
0022                                            {"oneProngOther", reco::PFTau::kOneProngNPiZero},
0023                                            {"threeProng0Pi0", reco::PFTau::kThreeProng0PiZero},
0024                                            {"threeProng1Pi0", reco::PFTau::kThreeProng1PiZero},
0025                                            {"threeProngOther", reco::PFTau::kThreeProngNPiZero},
0026                                            {"electron", reco::PFTau::kNull},
0027                                            {"muon", reco::PFTau::kNull},
0028                                            {nullptr, reco::PFTau::kNull}};
0029 
0030       constexpr bool same(char const *x, char const *y) { return !*x && !*y ? true : (*x == *y && same(x + 1, y + 1)); }
0031 
0032       constexpr enum reco::PFTau::hadronicDecayMode decayModeStringToId(char const *label, entry const *entries) {
0033         return !entries->label               ? reco::PFTau::kRareDecayMode
0034                : same(entries->label, label) ? entries->mode
0035                                              : decayModeStringToId(label, entries + 1);
0036       }
0037 
0038       constexpr char const *decayModeIdToString(reco::PFTau::hadronicDecayMode mode, entry const *entries) {
0039         return !entries->label ? "unknown"
0040                                : (entries->mode == mode ? entries->label : decayModeIdToString(mode, entries + 1));
0041       }
0042     }  // namespace
0043 
0044     unsigned int chargedHadronsInDecayMode(PFTau::hadronicDecayMode mode) {
0045       int modeAsInt = static_cast<int>(mode);
0046       return (modeAsInt / PFTau::kOneProngNPiZero) + 1;
0047     }
0048 
0049     unsigned int piZerosInDecayMode(PFTau::hadronicDecayMode mode) {
0050       int modeAsInt = static_cast<int>(mode);
0051       return (modeAsInt % PFTau::kOneProngNPiZero);
0052     }
0053 
0054     PFTau::hadronicDecayMode translateDecayMode(unsigned int nCharged, unsigned int nPiZeros) {
0055       // If no tracks exist, this is definitely not a tau!
0056       if (!nCharged)
0057         return PFTau::kNull;
0058       // Find the maximum number of PiZeros our parameterization can hold
0059       const unsigned int maxPiZeros = PFTau::kOneProngNPiZero;
0060       // Determine our track index
0061       unsigned int trackIndex = (nCharged - 1) * (maxPiZeros + 1);
0062       // Check if we handle the given number of tracks
0063       if (trackIndex >= PFTau::kRareDecayMode)
0064         return PFTau::kRareDecayMode;
0065 
0066       nPiZeros = (nPiZeros <= maxPiZeros) ? nPiZeros : maxPiZeros;
0067       return static_cast<PFTau::hadronicDecayMode>(trackIndex + nPiZeros);
0068     }
0069 
0070     PFTau::hadronicDecayMode translateGenDecayModeToReco(const std::string &name) {
0071       return decayModeStringToId(name.c_str(), dmTranslatorMap);
0072     }
0073 
0074     std::string translateRecoDecayModeToGen(PFTau::hadronicDecayMode decayMode) {
0075       return decayModeIdToString(decayMode, dmTranslatorMap);
0076     }
0077 
0078     PFTau::hadronicDecayMode getDecayMode(const reco::GenJet *genJet) {
0079       if (!genJet)
0080         return reco::PFTau::kNull;
0081       return translateGenDecayModeToReco(JetMCTagUtils::genTauDecayMode(*genJet));
0082     }
0083 
0084   }  // namespace tau
0085 }  // namespace reco