CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/RecoTauTag/RecoTau/interface/RecoTauMVAHelper.h

Go to the documentation of this file.
00001 #ifndef RecoTauTag_RecoTau_RecoTauMVAHelper_h
00002 #define RecoTauTag_RecoTau_RecoTauMVAHelper_h
00003 
00004 /*
00005  * RecoTauMVAHelper
00006  *
00007  * Manages DB retrieval and application of MVAComputers to reco::PFTaus.  Takes
00008  * as input a name (into an MVAComputerContainer) and an optional esLabel.  The
00009  * MVA helper retrieves the MVA from the database and determines the associated
00010  * list of discriminant functions.  These discriminant functions are all defined
00011  * as RecoTauDiscriminantPlugins.  This class then builds the appropriate
00012  * plugins.  When passed a tau using operator(), the class computes the output
00013  * of all discriminates, passes them to the MVA, and returns the result.
00014  *
00015  * The plugin can also be used to pass training data to the MVA framework.  See
00016  * RecoTauTag/TauTagTools/test/training for examples.
00017  *
00018  * Options for the different plugins can be specified with the pluginOptions.
00019  * Any entry in the pluginOptionPSet will passed to the plugin of the same name.
00020  *
00021  * Author: Evan K. Friis (UC Davis)
00022  *
00023  * Based on code by Christophe Saoute in -
00024  * PhysicsTools/MVAComputer/interface/MVAModuleHelper.h
00025  */
00026 
00027 #include <boost/ptr_container/ptr_map.hpp>
00028 #include <string>
00029 
00030 #include "RecoTauTag/RecoTau/interface/RecoTauDiscriminantPlugins.h"
00031 
00032 #include "PhysicsTools/MVAComputer/interface/MVAComputerCache.h"
00033 #include "PhysicsTools/MVAComputer/interface/Variable.h"
00034 #include "DataFormats/TauReco/interface/PFTauFwd.h"
00035 #include "FWCore/Framework/interface/EventSetup.h"
00036 #include "FWCore/Framework/interface/Event.h"
00037 
00038 namespace reco { namespace tau {
00039 
00040 class RecoTauMVAHelper {
00041   public:
00042     explicit RecoTauMVAHelper(const std::string &name,
00043                               const std::string &eslabel,
00044                               const edm::ParameterSet &pluginOptions);
00045     ~RecoTauMVAHelper() {}
00046 
00047     // Setup event information and retrive MVA from DB
00048     void setEvent(const edm::Event& evt, const edm::EventSetup &es);
00049 
00050     // Apply MVA to tau and return result
00051     double operator()(const PFTauRef &tau) const;
00052 
00053     // Retrive the raw input for a given tau that would be passed to the MVA
00054     const PhysicsTools::Variable::ValueList& discriminants(
00055         const PFTauRef& tau) const;
00056 
00057     // Add a training event of type <target> with given weight
00058     void train(const PFTauRef &tau, bool target, double weight = 1.0) const;
00059   private:
00060     // Name of computer in the DB record
00061     std::string name_;
00062     // Name of label for event setup record
00063     std::string eslabel_;
00064     // Options to pass to the plugins
00065     edm::ParameterSet pluginOptions_;
00066 
00067     PhysicsTools::MVAComputerCache computer_;
00068     // Map our discriminant plugins to their "MVA name"
00069     typedef boost::ptr_map<PhysicsTools::AtomicId, RecoTauDiscriminantPlugin>
00070         PluginMap;
00071     PluginMap plugins_;
00072     // Helper function to load relevant plugins for a MVA computer
00073     void loadDiscriminantPlugins(
00074         const PhysicsTools::Calibration::MVAComputer &computer);
00075     // Load the plugin values for this tau
00076     void fillValues(const reco::PFTauRef& tau) const;
00077     mutable PhysicsTools::Variable::ValueList values_;
00078 };
00079 }}  // end reco::tau
00080 #endif