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 bool takeAbs_; 00027 double min_; 00028 double max_; 00029 typedef std::pair<edm::InputTag, edm::Handle<reco::PFTauDiscriminator> > DiscInfo; 00030 std::vector<DiscInfo> discriminators_; 00031 }; 00032 00033 RecoTauDiscriminantFromDiscriminator::RecoTauDiscriminantFromDiscriminator( 00034 const edm::ParameterSet& pset):RecoTauDiscriminantPlugin(pset) { 00035 takeAbs_ = pset.existsAs<bool>("takeAbs") ? 00036 pset.getParameter<bool>("takeAbs") : false; 00037 min_ = pset.existsAs<double>("minValue") ? 00038 pset.getParameter<double>("minValue") : -1*std::numeric_limits<double>::max(); 00039 max_ = pset.existsAs<double>("maxValue") ? 00040 pset.getParameter<double>("maxValue") : std::numeric_limits<double>::max(); 00041 00042 if (pset.existsAs<edm::InputTag>("discSrc")) { 00043 discriminators_.push_back(std::make_pair( 00044 pset.getParameter<edm::InputTag>("discSrc"), 00045 edm::Handle<reco::PFTauDiscriminator>())); 00046 } else { 00047 // Get multiple discriminators. This supports the case when the MVAHelper 00048 // class might be dealing with multiple tau collections (training) 00049 std::vector<edm::InputTag> discriminators = 00050 pset.getParameter<std::vector<edm::InputTag> >("discSrc"); 00051 BOOST_FOREACH(const edm::InputTag& tag, discriminators) { 00052 discriminators_.push_back(std::make_pair( 00053 tag, edm::Handle<reco::PFTauDiscriminator>())); 00054 } 00055 } 00056 } 00057 00058 // Called by base class at the beginning of every event 00059 void RecoTauDiscriminantFromDiscriminator::beginEvent() { 00060 BOOST_FOREACH(DiscInfo& discInfo, discriminators_) { 00061 evt()->getByLabel(discInfo.first, discInfo.second); 00062 } 00063 } 00064 00065 std::vector<double> RecoTauDiscriminantFromDiscriminator::operator()( 00066 const reco::PFTauRef& tau) const { 00067 edm::ProductID tauProdId = tau.id(); 00068 double result = -999; 00069 bool foundGoodDiscriminator = false; 00070 for (size_t i = 0; i < discriminators_.size(); ++i) { 00071 // Check if the discriminator actually exists 00072 if (!discriminators_[i].second.isValid()) 00073 continue; 00074 const reco::PFTauDiscriminator& disc = *(discriminators_[i].second); 00075 if (tauProdId == disc.keyProduct().id()) { 00076 foundGoodDiscriminator = true; 00077 result = (disc)[tau]; 00078 break; 00079 } 00080 } 00081 // In case no discriminator is found. 00082 if (!foundGoodDiscriminator) { 00083 std::stringstream error; 00084 error << "Couldn't find a PFTauDiscriminator usable with given tau." 00085 << std::endl << " Input tau has product id: " << tau.id() << std::endl; 00086 for (size_t i = 0; i < discriminators_.size(); ++i ) { 00087 error << "disc: " << discriminators_[i].first; 00088 error << " isValid: " << discriminators_[i].second.isValid(); 00089 if (discriminators_[i].second.isValid()) { 00090 error << " product: " << discriminators_[i].second->keyProduct().id(); 00091 } 00092 error << std::endl; 00093 } 00094 edm::LogError("BadDiscriminatorConfiguration") << error.str(); 00095 } 00096 if (result < min_) 00097 result = min_; 00098 if (result > max_) 00099 result = max_; 00100 return std::vector<double>(1, result); 00101 } 00102 00103 }} // end namespace reco::tau 00104 00105 #include "FWCore/Framework/interface/MakerMacros.h" 00106 DEFINE_EDM_PLUGIN(RecoTauDiscriminantPluginFactory, 00107 reco::tau::RecoTauDiscriminantFromDiscriminator, 00108 "RecoTauDiscriminantFromDiscriminator");