Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <boost/foreach.hpp>
00024 #include <boost/ptr_container/ptr_map.hpp>
00025
00026 #include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h"
00027 #include "RecoTauTag/RecoTau/interface/RecoTauMVAHelper.h"
00028 #include "RecoTauTag/RecoTau/interface/PFTauDecayModeTools.h"
00029
00030 #include "DataFormats/TauReco/interface/PFTau.h"
00031 #include "DataFormats/TauReco/interface/PFTauFwd.h"
00032
00033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00035
00036
00037 class RecoTauMVADiscriminator : public PFTauDiscriminationProducerBase {
00038 public:
00039 explicit RecoTauMVADiscriminator(const edm::ParameterSet& pset);
00040 ~RecoTauMVADiscriminator() {}
00041
00042 void beginEvent(const edm::Event&, const edm::EventSetup&);
00043 double discriminate(const reco::PFTauRef&);
00044
00045 private:
00046
00047 typedef boost::ptr_map<reco::PFTau::hadronicDecayMode,
00048 reco::tau::RecoTauMVAHelper> MVAMap;
00049
00050 std::auto_ptr<reco::tau::RecoTauMVAHelper> defaultMVA_;
00051
00052 MVAMap mvas_;
00053 std::string dbLabel_;
00054 double unsupportedDMValue_;
00055 bool remapOutput_;
00056 };
00057
00058 RecoTauMVADiscriminator::RecoTauMVADiscriminator(const edm::ParameterSet& pset)
00059 :PFTauDiscriminationProducerBase(pset) {
00060 std::string dbLabel;
00061 if (pset.exists("dbLabel"))
00062 dbLabel = pset.getParameter<std::string>("dbLabel");
00063
00064 unsupportedDMValue_ = (pset.exists("unsupportedDecayModeValue")) ?
00065 pset.getParameter<double>("unsupportedDecayModeValue")
00066 : prediscriminantFailValue_;
00067
00068 remapOutput_ = pset.getParameter<bool>("remapOutput");
00069
00070 typedef std::vector<edm::ParameterSet> VPSet;
00071 const VPSet& mvas = pset.getParameter<VPSet>("mvas");
00072
00073 for (VPSet::const_iterator mva = mvas.begin(); mva != mvas.end(); ++mva) {
00074 unsigned int nCharged = mva->getParameter<unsigned int>("nCharged");
00075 unsigned int nPiZeros = mva->getParameter<unsigned int>("nPiZeros");
00076 reco::PFTau::hadronicDecayMode decayMode = reco::tau::translateDecayMode(
00077 nCharged, nPiZeros);
00078
00079 if (!mvas_.count(decayMode)) {
00080 std::string computerName = mva->getParameter<std::string>("mvaLabel");
00081
00082 mvas_.insert(
00083 decayMode, new reco::tau::RecoTauMVAHelper(computerName, dbLabel));
00084 } else {
00085 edm::LogError("DecayModeNotUnique") << "The tau decay mode with "
00086 "nCharged/nPiZero = " << nCharged << "/" << nPiZeros << " dm: "
00087 << decayMode <<
00088 " is associated to multiple MVA implmentations, "
00089 "the second instantiation is being ignored!!!";
00090 }
00091 }
00092
00093
00094 if (pset.exists("defaultMVA")) {
00095 defaultMVA_.reset(new reco::tau::RecoTauMVAHelper(
00096 pset.getParameter<std::string>("defaultMVA"),
00097 dbLabel));
00098 }
00099
00100 }
00101
00102 void RecoTauMVADiscriminator::beginEvent(const edm::Event& evt,
00103 const edm::EventSetup& es) {
00104
00105 BOOST_FOREACH(MVAMap::value_type mva, mvas_) {
00106 mva.second->setEvent(evt, es);
00107 }
00108 if (defaultMVA_.get())
00109 defaultMVA_->setEvent(evt, es);
00110 }
00111
00112
00113 double RecoTauMVADiscriminator::discriminate(const reco::PFTauRef& tau) {
00114
00115 MVAMap::iterator mva = mvas_.find(tau->decayMode());
00116
00117 double output = unsupportedDMValue_;
00118 if (mva != mvas_.end() || defaultMVA_.get()) {
00119 if (mva != mvas_.end())
00120 output = mva->second->operator()(tau);
00121 else
00122 output = defaultMVA_->operator()(tau);
00123
00124 if (remapOutput_) {
00125 output += 1.;
00126 output /= 2.;
00127 }
00128 }
00129 return output;
00130 }
00131
00132 #include "FWCore/Framework/interface/MakerMacros.h"
00133 DEFINE_FWK_MODULE(RecoTauMVADiscriminator);