CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoTauTag/RecoTau/src/PFTauDecayModeTools.cc

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   // Convert the string decay mode from PhysicsTools to the
00011   // PFTau::hadronicDecayMode format
00012   static std::map<std::string, reco::PFTau::hadronicDecayMode> dmTranslator =
00013     boost::assign::map_list_of
00014     ("oneProng0Pi0", reco::PFTau::kOneProng0PiZero)
00015     ("oneProng1Pi0", reco::PFTau::kOneProng1PiZero)
00016     ("oneProng2Pi0", reco::PFTau::kOneProng2PiZero)
00017     ("oneProngOther", reco::PFTau::kOneProngNPiZero)
00018     ("threeProng0Pi0", reco::PFTau::kThreeProng0PiZero)
00019     ("threeProng1Pi0", reco::PFTau::kThreeProng1PiZero)
00020     ("threeProngOther", reco::PFTau::kThreeProngNPiZero)
00021     ("electron", reco::PFTau::kNull)
00022     ("muon", reco::PFTau::kNull);
00023 
00024   static std::map<reco::PFTau::hadronicDecayMode, std::string> dmInverter =
00025     boost::assign::map_list_of
00026     (reco::PFTau::kOneProng0PiZero, "oneProng0Pi0")
00027     (reco::PFTau::kOneProng1PiZero, "oneProng1Pi0")
00028     (reco::PFTau::kOneProng2PiZero, "oneProng2Pi0")
00029     (reco::PFTau::kOneProngNPiZero, "oneProngOther")
00030     (reco::PFTau::kThreeProng0PiZero, "threeProng0Pi0")
00031     (reco::PFTau::kThreeProng1PiZero, "threeProng1Pi0")
00032     (reco::PFTau::kThreeProngNPiZero, "threeProngOther")
00033     (reco::PFTau::kNull, "unknown")
00034     (reco::PFTau::kRareDecayMode, "rare");
00035 }
00036 
00037 unsigned int chargedHadronsInDecayMode(PFTau::hadronicDecayMode mode) {
00038    int modeAsInt = static_cast<int>(mode);
00039    return (modeAsInt / PFTau::kOneProngNPiZero) + 1;
00040 }
00041 
00042 unsigned int piZerosInDecayMode(PFTau::hadronicDecayMode mode) {
00043    int modeAsInt = static_cast<int>(mode);
00044    return (modeAsInt % PFTau::kOneProngNPiZero);
00045 }
00046 
00047 PFTau::hadronicDecayMode translateDecayMode(
00048     unsigned int nCharged, unsigned int nPiZeros) {
00049    // If no tracks exist, this is definitely not a tau!
00050    if(!nCharged) return PFTau::kNull;
00051    // Find the maximum number of PiZeros our parameterization can hold
00052    const unsigned int maxPiZeros = PFTau::kOneProngNPiZero;
00053    // Determine our track index
00054    unsigned int trackIndex = (nCharged-1)*(maxPiZeros+1);
00055    // Check if we handle the given number of tracks
00056    if(trackIndex >= PFTau::kRareDecayMode) return PFTau::kRareDecayMode;
00057 
00058    nPiZeros = (nPiZeros <= maxPiZeros) ? nPiZeros : maxPiZeros;
00059    return static_cast<PFTau::hadronicDecayMode>(trackIndex + nPiZeros);
00060 }
00061 
00062 PFTau::hadronicDecayMode translateGenDecayModeToReco(
00063     const std::string& name) {
00064   std::map<std::string, reco::PFTau::hadronicDecayMode>::const_iterator
00065     found = dmTranslator.find(name);
00066   if (found != dmTranslator.end()) {
00067     return found->second;
00068   } else
00069     return reco::PFTau::kRareDecayMode;
00070 }
00071 
00072 std::string translateRecoDecayModeToGen(PFTau::hadronicDecayMode decayMode) {
00073   std::map<reco::PFTau::hadronicDecayMode, std::string>::const_iterator
00074     found = dmInverter.find(decayMode);
00075   if (found != dmInverter.end()) {
00076     return found->second;
00077   } else
00078     return "unknown";
00079 }
00080 
00081 
00082 PFTau::hadronicDecayMode getDecayMode(const reco::GenJet* genJet) {
00083   if (!genJet)
00084     return reco::PFTau::kNull;
00085   return translateGenDecayModeToReco(JetMCTagUtils::genTauDecayMode(*genJet));
00086 }
00087 
00088 }} // end namespace reco::tau