CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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 
00025 unsigned int chargedHadronsInDecayMode(PFTau::hadronicDecayMode mode) {
00026    int modeAsInt = static_cast<int>(mode);
00027    return (modeAsInt / PFTau::kOneProngNPiZero) + 1;
00028 }
00029 
00030 unsigned int piZerosInDecayMode(PFTau::hadronicDecayMode mode) {
00031    int modeAsInt = static_cast<int>(mode);
00032    return (modeAsInt % PFTau::kOneProngNPiZero);
00033 }
00034 
00035 PFTau::hadronicDecayMode translateDecayMode(
00036     unsigned int nCharged, unsigned int nPiZeros) {
00037    // If no tracks exist, this is definitely not a tau!
00038    if(!nCharged) return PFTau::kNull;
00039    // Find the maximum number of PiZeros our parameterization can hold
00040    const unsigned int maxPiZeros = PFTau::kOneProngNPiZero;
00041    // Determine our track index
00042    unsigned int trackIndex = (nCharged-1)*(maxPiZeros+1);
00043    // Check if we handle the given number of tracks
00044    if(trackIndex >= PFTau::kRareDecayMode) return PFTau::kRareDecayMode;
00045 
00046    nPiZeros = (nPiZeros <= maxPiZeros) ? nPiZeros : maxPiZeros;
00047    return static_cast<PFTau::hadronicDecayMode>(trackIndex + nPiZeros);
00048 }
00049 
00050 PFTau::hadronicDecayMode translateGenDecayModeToReco(
00051     const std::string& name) {
00052   std::map<std::string, reco::PFTau::hadronicDecayMode>::const_iterator
00053     found = dmTranslator.find(name);
00054   if (found != dmTranslator.end()) {
00055     return found->second;
00056   } else
00057     return reco::PFTau::kRareDecayMode;
00058 }
00059 
00060 PFTau::hadronicDecayMode getDecayMode(const reco::GenJet* genJet) {
00061   if (!genJet)
00062     return reco::PFTau::kNull;
00063   return translateGenDecayModeToReco(JetMCTagUtils::genTauDecayMode(*genJet));
00064 }
00065 
00066 }} // end namespace reco::tau