CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoTauTag/TauTagTools/plugins/RecoTauDecayModeTruthMatchPlugin.cc

Go to the documentation of this file.
00001 /*
00002  * RecoTauDecayModeTruthMatchPlugin
00003  *
00004  * Author: Evan K. Friis, UC Davis
00005  *
00006  * Implements a RecoTauCleaner plugin that returns the difference
00007  * between the reconstructed decay mode and true decay mode index.
00008  *
00009  * By requiring the return value to be zero one can select reco taus
00010  * that have the decay mode correctly reconstructed.
00011  *
00012  * $Id. $
00013  */
00014 
00015 #include "RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h"
00016 
00017 #include "DataFormats/TauReco/interface/PFTau.h"
00018 #include "DataFormats/TauReco/interface/PFTauFwd.h"
00019 #include "DataFormats/JetReco/interface/GenJet.h"
00020 #include "DataFormats/JetReco/interface/GenJetCollection.h"
00021 #include "DataFormats/Common/interface/Association.h"
00022 
00023 #include "PhysicsTools/JetMCUtils/interface/JetMCTag.h"
00024 
00025 #include <boost/foreach.hpp>
00026 #include <boost/assign.hpp>
00027 #include <map>
00028 
00029 namespace {
00030   // Convert the string decay mode from PhysicsTools to the
00031   // PFTau::hadrondicDecayMode format
00032   static std::map<std::string, reco::PFTau::hadronicDecayMode> dmTranslator =
00033     boost::assign::map_list_of
00034     ("oneProng0Pi0", reco::PFTau::kOneProng0PiZero)
00035     ("oneProng1Pi0", reco::PFTau::kOneProng1PiZero)
00036     ("oneProng2Pi0", reco::PFTau::kOneProng2PiZero)
00037     ("oneProngOther", reco::PFTau::kOneProngNPiZero)
00038     ("threeProng0Pi0", reco::PFTau::kThreeProng0PiZero)
00039     ("threeProng1Pi0", reco::PFTau::kThreeProng1PiZero)
00040     ("threeProngOther", reco::PFTau::kThreeProngNPiZero)
00041     ("electron", reco::PFTau::kNull)
00042     ("muon", reco::PFTau::kNull);
00043 }
00044 
00045 namespace tautools {
00046 
00047 class RecoTauDecayModeTruthMatchPlugin : public reco::tau::RecoTauCleanerPlugin
00048 {
00049   public:
00050     explicit RecoTauDecayModeTruthMatchPlugin(const edm::ParameterSet& pset);
00051     virtual ~RecoTauDecayModeTruthMatchPlugin() {}
00052     double operator()(const reco::PFTauRef&) const;
00053     void beginEvent();
00054 
00055   private:
00056     edm::InputTag matchingSrc_;
00057     typedef edm::Association<reco::GenJetCollection> GenJetAssociation;
00058     edm::Handle<GenJetAssociation> genTauMatch_;
00059 };
00060 
00061 // ctor
00062 RecoTauDecayModeTruthMatchPlugin::RecoTauDecayModeTruthMatchPlugin(
00063     const edm::ParameterSet& pset): RecoTauCleanerPlugin(pset),
00064   matchingSrc_(pset.getParameter<edm::InputTag>("matching")) {}
00065 
00066 // Called by base class at the beginning of each event
00067 void RecoTauDecayModeTruthMatchPlugin::beginEvent() {
00068   // Load the matching information
00069   evt()->getByLabel(matchingSrc_, genTauMatch_);
00070 }
00071 
00072 // Determine a number giving the quality of the input tau.  Lower numbers are
00073 // better - zero indicates that the reco decay mode matches the truth.
00074 double RecoTauDecayModeTruthMatchPlugin::operator()(const reco::PFTauRef& tau)
00075   const {
00076   GenJetAssociation::reference_type truth = (*genTauMatch_)[tau];
00077   // Check if the matching exists, if not return +infinity
00078   if (truth.isNull())
00079     return std::numeric_limits<double>::infinity();
00080   // Get the difference in decay mode.  The closer to zero, the more the decay
00081   // mode is matched.
00082   return std::abs(
00083       dmTranslator[JetMCTagUtils::genTauDecayMode(*truth)] - tau->decayMode());
00084 }
00085 
00086 } // end tautools namespace
00087 
00088 #include "FWCore/Framework/interface/MakerMacros.h"
00089 DEFINE_EDM_PLUGIN(RecoTauCleanerPluginFactory, tautools::RecoTauDecayModeTruthMatchPlugin, "RecoTauDecayModeTruthMatchPlugin");