Go to the documentation of this file.00001 #include <map>
00002 #include <boost/assign.hpp>
00003 #include "RecoTauTag/RecoTau/interface/PFTauDecayModeTools.h"
00004 #include "DataFormats/JetReco/interface/GenJet.h"
00005 #include "PhysicsTools/JetMCUtils/interface/JetMCTag.h"
00006
00007 namespace reco { namespace tau {
00008
00009 namespace {
00010 struct entry {
00011 char const *label;
00012 reco::PFTau::hadronicDecayMode mode;
00013 };
00014
00015
00016
00017 constexpr entry dmTranslatorMap[] = {
00018 {"unknown", reco::PFTau::kNull},
00019 {"rare", reco::PFTau::kRareDecayMode},
00020 {"oneProng0Pi0", reco::PFTau::kOneProng0PiZero},
00021 {"oneProng1Pi0", reco::PFTau::kOneProng1PiZero},
00022 {"oneProng2Pi0", reco::PFTau::kOneProng2PiZero},
00023 {"oneProngOther", reco::PFTau::kOneProngNPiZero},
00024 {"threeProng0Pi0", reco::PFTau::kThreeProng0PiZero},
00025 {"threeProng1Pi0", reco::PFTau::kThreeProng1PiZero},
00026 {"threeProngOther", reco::PFTau::kThreeProngNPiZero},
00027 {"electron", reco::PFTau::kNull},
00028 {"muon", reco::PFTau::kNull},
00029 {0,reco::PFTau::kNull}
00030 };
00031
00032 constexpr bool same(char const *x, char const *y) {
00033 return !*x && !*y ? true : (*x == *y && same(x+1, y+1));
00034 }
00035
00036 constexpr enum reco::PFTau::hadronicDecayMode decayModeStringToId(char const *label, entry const *entries) {
00037 return !entries->label ? reco::PFTau::kRareDecayMode : same(entries->label, label) ? entries->mode : decayModeStringToId(label, entries+1);
00038 }
00039
00040 constexpr char const *decayModeIdToString(reco::PFTau::hadronicDecayMode mode, entry const *entries) {
00041 return !entries->label ? "unknown" : (entries->mode == mode ? entries->label : decayModeIdToString(mode, entries+1));
00042 }
00043 }
00044
00045 unsigned int chargedHadronsInDecayMode(PFTau::hadronicDecayMode mode) {
00046 int modeAsInt = static_cast<int>(mode);
00047 return (modeAsInt / PFTau::kOneProngNPiZero) + 1;
00048 }
00049
00050 unsigned int piZerosInDecayMode(PFTau::hadronicDecayMode mode) {
00051 int modeAsInt = static_cast<int>(mode);
00052 return (modeAsInt % PFTau::kOneProngNPiZero);
00053 }
00054
00055 PFTau::hadronicDecayMode translateDecayMode(
00056 unsigned int nCharged, unsigned int nPiZeros) {
00057
00058 if(!nCharged) return PFTau::kNull;
00059
00060 const unsigned int maxPiZeros = PFTau::kOneProngNPiZero;
00061
00062 unsigned int trackIndex = (nCharged-1)*(maxPiZeros+1);
00063
00064 if(trackIndex >= PFTau::kRareDecayMode) return PFTau::kRareDecayMode;
00065
00066 nPiZeros = (nPiZeros <= maxPiZeros) ? nPiZeros : maxPiZeros;
00067 return static_cast<PFTau::hadronicDecayMode>(trackIndex + nPiZeros);
00068 }
00069
00070 PFTau::hadronicDecayMode translateGenDecayModeToReco(
00071 const std::string& name) {
00072 return decayModeStringToId(name.c_str(), dmTranslatorMap);
00073 }
00074
00075 std::string translateRecoDecayModeToGen(PFTau::hadronicDecayMode decayMode) {
00076 return decayModeIdToString(decayMode, dmTranslatorMap);
00077 }
00078
00079
00080 PFTau::hadronicDecayMode getDecayMode(const reco::GenJet* genJet) {
00081 if (!genJet)
00082 return reco::PFTau::kNull;
00083 return translateGenDecayModeToReco(JetMCTagUtils::genTauDecayMode(*genJet));
00084 }
00085
00086 }}