CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/RecoTauTag/TauTagTools/plugins/RecoTauDistanceFromTruthPlugin.cc

Go to the documentation of this file.
00001 #include "RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h"
00002 
00003 #include "DataFormats/TauReco/interface/PFTau.h"
00004 #include "DataFormats/TauReco/interface/PFTauFwd.h"
00005 #include "DataFormats/JetReco/interface/GenJet.h"
00006 #include "DataFormats/JetReco/interface/GenJetCollection.h"
00007 #include "DataFormats/Common/interface/Association.h"
00008 //#include "DataFormats/Common/interface/AssociativeIterator.h"
00009 
00010 #include <boost/foreach.hpp>
00011 #include <boost/bind.hpp>
00012 #include <boost/iterator/filter_iterator.hpp>
00013 
00014 namespace tautools {
00015 
00016 class RecoTauDistanceFromTruthPlugin : public reco::tau::RecoTauCleanerPlugin {
00017   public:
00018     RecoTauDistanceFromTruthPlugin(const edm::ParameterSet& pset);
00019     virtual ~RecoTauDistanceFromTruthPlugin() {}
00020     double operator()(const reco::PFTauRef&) const;
00021     void beginEvent();
00022   private:
00023     edm::InputTag matchingSrc_;
00024     typedef edm::Association<reco::GenJetCollection> GenJetAssociation;
00025     edm::Handle<GenJetAssociation> genTauMatch_;
00026 };
00027 
00028 RecoTauDistanceFromTruthPlugin::RecoTauDistanceFromTruthPlugin(
00029     const edm::ParameterSet& pset): reco::tau::RecoTauCleanerPlugin(pset) {
00030   matchingSrc_ = pset.getParameter<edm::InputTag>("matching");
00031 }
00032 
00033 void RecoTauDistanceFromTruthPlugin::beginEvent() {
00034   // Load the matching information
00035   evt()->getByLabel(matchingSrc_, genTauMatch_);
00036 }
00037 
00038 double RecoTauDistanceFromTruthPlugin::operator()(const reco::PFTauRef& tauRef) const {
00039 
00040   GenJetAssociation::reference_type truth = (*genTauMatch_)[tauRef];
00041 
00042   // Check if the matching exists, if not return +infinity
00043   if (truth.isNull())
00044     return std::numeric_limits<double>::infinity();
00045 
00046   return std::abs(tauRef->pt() - truth->pt());
00047 }
00048 
00049 } // end tautools namespace
00050 
00051 
00052 // Register our plugin
00053 #include "FWCore/Framework/interface/MakerMacros.h"
00054 DEFINE_EDM_PLUGIN(RecoTauCleanerPluginFactory, tautools::RecoTauDistanceFromTruthPlugin, "RecoTauDistanceFromTruthPlugin");