CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoTauTag/RecoTau/plugins/RecoTauDiscriminantFromDiscriminator.cc

Go to the documentation of this file.
00001 /*
00002  * RecoTauDiscriminantFromDiscriminator
00003  *
00004  * Makes a discriminator function from a PFRecoTauDiscriminator stored in the
00005  * event.
00006  *
00007  * Author: Evan K. Friis (UC Davis)
00008  *
00009  */
00010 
00011 #include <boost/foreach.hpp>
00012 #include <sstream>
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 #include "RecoTauTag/RecoTau/interface/RecoTauDiscriminantPlugins.h"
00015 #include "DataFormats/TauReco/interface/PFTauDiscriminator.h"
00016 
00017 namespace reco { namespace tau {
00018 
00019 class RecoTauDiscriminantFromDiscriminator : public RecoTauDiscriminantPlugin{
00020   public:
00021     explicit RecoTauDiscriminantFromDiscriminator(
00022         const edm::ParameterSet& pset);
00023     void beginEvent();
00024     std::vector<double> operator()(const reco::PFTauRef& tau) const;
00025   private:
00026     typedef std::pair<edm::InputTag, edm::Handle<reco::PFTauDiscriminator> > DiscInfo;
00027     std::vector<DiscInfo> discriminators_;
00028 };
00029 
00030 RecoTauDiscriminantFromDiscriminator::RecoTauDiscriminantFromDiscriminator(
00031     const edm::ParameterSet& pset):RecoTauDiscriminantPlugin(pset) {
00032   if (pset.existsAs<edm::InputTag>("discSrc")) {
00033     discriminators_.push_back(std::make_pair(
00034           pset.getParameter<edm::InputTag>("discSrc"),
00035           edm::Handle<reco::PFTauDiscriminator>()));
00036   } else {
00037     // Get multiple discriminators.  This supports the case when the MVAHelper
00038     // class might be dealing with multiple tau collections (training)
00039     std::vector<edm::InputTag> discriminators =
00040       pset.getParameter<std::vector<edm::InputTag> >("discSrc");
00041     BOOST_FOREACH(const edm::InputTag& tag, discriminators) {
00042       discriminators_.push_back(std::make_pair(
00043             tag, edm::Handle<reco::PFTauDiscriminator>()));
00044     }
00045   }
00046 }
00047 
00048 // Called by base class at the beginning of every event
00049 void RecoTauDiscriminantFromDiscriminator::beginEvent() {
00050   BOOST_FOREACH(DiscInfo& discInfo, discriminators_) {
00051     evt()->getByLabel(discInfo.first, discInfo.second);
00052   }
00053 }
00054 
00055 std::vector<double> RecoTauDiscriminantFromDiscriminator::operator()(
00056     const reco::PFTauRef& tau) const {
00057   edm::ProductID tauProdId = tau.id();
00058   for (size_t i = 0; i < discriminators_.size(); ++i) {
00059     // Check if the discriminator actually exists
00060     if (!discriminators_[i].second.isValid())
00061       continue;
00062     const reco::PFTauDiscriminator& disc = *(discriminators_[i].second);
00063     if (tauProdId == disc.keyProduct().id())
00064       return std::vector<double>(1, (disc)[tau]);
00065   }
00066   // Can only reach this point if not appropriate discriminator is defined for
00067   // the passed tau.
00068   std::stringstream error;
00069   error << "Couldn't find a PFTauDiscriminator usable with given tau."
00070     << std::endl << " Input tau has product id: " << tau.id() << std::endl;
00071   for (size_t i = 0; i < discriminators_.size(); ++i ) {
00072     error << "disc: " << discriminators_[i].first;
00073     error << " isValid: " << discriminators_[i].second.isValid();
00074     if (discriminators_[i].second.isValid()) {
00075       error << " product: " << discriminators_[i].second->keyProduct().id();
00076     }
00077     error << std::endl;
00078   }
00079   edm::LogError("BadDiscriminatorConfiguration") << error.str();
00080   return std::vector<double>(1,-999);
00081 }
00082 
00083 }} // end namespace reco::tau
00084 
00085 #include "FWCore/Framework/interface/MakerMacros.h"
00086 DEFINE_EDM_PLUGIN(RecoTauDiscriminantPluginFactory,
00087     reco::tau::RecoTauDiscriminantFromDiscriminator,
00088     "RecoTauDiscriminantFromDiscriminator");