#include <RecoTauMVAHelper.h>
Public Member Functions | |
const PhysicsTools::Variable::ValueList & | discriminants (const PFTauRef &tau) const |
double | operator() (const PFTauRef &tau) const |
RecoTauMVAHelper (const std::string &name, const std::string &eslabel, const edm::ParameterSet &pluginOptions) | |
void | setEvent (const edm::Event &evt, const edm::EventSetup &es) |
void | train (const PFTauRef &tau, bool target, double weight=1.0) const |
~RecoTauMVAHelper () | |
Private Types | |
typedef boost::ptr_map < PhysicsTools::AtomicId, RecoTauDiscriminantPlugin > | PluginMap |
Private Member Functions | |
void | fillValues (const reco::PFTauRef &tau) const |
void | loadDiscriminantPlugins (const PhysicsTools::Calibration::MVAComputer &computer) |
Private Attributes | |
PhysicsTools::MVAComputerCache | computer_ |
std::string | eslabel_ |
std::string | name_ |
edm::ParameterSet | pluginOptions_ |
PluginMap | plugins_ |
PhysicsTools::Variable::ValueList | values_ |
Definition at line 40 of file RecoTauMVAHelper.h.
typedef boost::ptr_map<PhysicsTools::AtomicId, RecoTauDiscriminantPlugin> reco::tau::RecoTauMVAHelper::PluginMap [private] |
Definition at line 70 of file RecoTauMVAHelper.h.
reco::tau::RecoTauMVAHelper::RecoTauMVAHelper | ( | const std::string & | name, |
const std::string & | eslabel, | ||
const edm::ParameterSet & | pluginOptions | ||
) | [explicit] |
Definition at line 16 of file RecoTauMVAHelper.cc.
: name_(name), eslabel_(eslabel), pluginOptions_(pluginOptions) {}
reco::tau::RecoTauMVAHelper::~RecoTauMVAHelper | ( | ) | [inline] |
Definition at line 45 of file RecoTauMVAHelper.h.
{}
const PhysicsTools::Variable::ValueList & reco::tau::RecoTauMVAHelper::discriminants | ( | const PFTauRef & | tau | ) | const |
Definition at line 108 of file RecoTauMVAHelper.cc.
References PhysicsTools::Variable::ValueList::clear(), fillValues(), and values_.
{ values_.clear(); fillValues(tau); return values_; }
void reco::tau::RecoTauMVAHelper::fillValues | ( | const reco::PFTauRef & | tau | ) | const [private] |
Definition at line 80 of file RecoTauMVAHelper.cc.
References PhysicsTools::Variable::ValueList::add(), error, instance, edm::detail::isnan(), pfTaus_cff::plugin, plugins_, metsig::tau, and values_.
Referenced by discriminants(), operator()(), and train().
{ // Loop over the relevant discriminators and the output for (PluginMap::const_iterator plugin = plugins_.begin(); plugin != plugins_.end(); ++plugin) { PhysicsTools::AtomicId id = plugin->first; std::vector<double> pluginOutput = (plugin->second)->operator()(tau); // Check for nans for(size_t instance = 0; instance < pluginOutput.size(); ++instance) { if (std::isnan(pluginOutput[instance])) { std::ostringstream error; error << "A nan was detected in" << " the tau MVA variable " << id << " returning zero instead!" << " The PFTau: " << *tau << std::endl; tau->dump(error); edm::LogError("CorruptedMVAInput") << error.str(); pluginOutput[instance] = 0.0; } } //std::cout << "id: " << id << " first: " << pluginOutput[0] << std::endl; // Build values and copy into values vector std::for_each(pluginOutput.begin(), pluginOutput.end(), boost::bind(&PhysicsTools::Variable::ValueList::add, boost::ref(values_), id, _1)); } }
void reco::tau::RecoTauMVAHelper::loadDiscriminantPlugins | ( | const PhysicsTools::Calibration::MVAComputer & | computer | ) | [private] |
Definition at line 43 of file RecoTauMVAHelper.cc.
References edm::ParameterSet::addParameter(), SurfaceDeformationFactory::create(), reco::tau::discPluginName(), edm::ParameterSet::exists(), reco::get(), edm::ParameterSet::getParameter(), PhysicsTools::Calibration::MVAComputer::inputSet, AlCaHLTBitMon_ParallelJobs::options, pluginOptions_, and plugins_.
Referenced by setEvent().
{ typedef std::vector<PhysicsTools::Calibration::Variable> VarList; // List of input variables for this MVA. const VarList &vars = comp.inputSet; // Load the plugin for each of the Var if needed BOOST_FOREACH(const VarList::value_type& var, vars) { // Check to make sure it isn't a magic variable if (std::strncmp(var.name.c_str(), "__", 2) != 0) { // If we haven't added yet, build it. PhysicsTools::AtomicId varId(var.name); if (!plugins_.count(varId)) { edm::ParameterSet options; if (pluginOptions_.exists(var.name)) { options = pluginOptions_.getParameter<edm::ParameterSet>(var.name); }; // Make sure it has a name (required by base class) if (!options.exists("name")) options.addParameter("name", "MVA_" + var.name); // Check if we want to specify the plugin name manually. This is // required for things like the discriminant from discriminators, which // take an InputTag. If we want to have more than one, we have to be // able take the MVA name (like FlightPathSig) and map it to // RecoTauDiscriminantFromDiscriminator[disc input tag = flight path sig] // Otherwise we just keep our regular plugin mapping. std::string pluginName = reco::tau::discPluginName(var.name); if (options.exists("plugin")) { pluginName = options.getParameter<std::string>("plugin"); } plugins_.insert( varId, RecoTauDiscriminantPluginFactory::get()->create( pluginName, options)); } } } }
double reco::tau::RecoTauMVAHelper::operator() | ( | const PFTauRef & | tau | ) | const |
Definition at line 115 of file RecoTauMVAHelper.cc.
References PhysicsTools::Variable::ValueList::clear(), computer_, fillValues(), and values_.
void reco::tau::RecoTauMVAHelper::setEvent | ( | const edm::Event & | evt, |
const edm::EventSetup & | es | ||
) |
Definition at line 21 of file RecoTauMVAHelper.cc.
References computer_, eslabel_, edm::EventSetup::get(), PhysicsTools::MVAComputerCache::get(), patZpeak::handle, loadDiscriminantPlugins(), name_, pfTaus_cff::plugin, plugins_, edm::ESHandle< T >::product(), and PhysicsTools::MVAComputerCache::update().
Referenced by RecoTauMVATrainer::analyze().
{ // Update our MVA from the DB using PhysicsTools::Calibration::MVAComputerContainer; edm::ESHandle<MVAComputerContainer> handle; if (eslabel_.size()) { es.get<TauTagMVAComputerRcd>().get(eslabel_, handle); } else { es.get<TauTagMVAComputerRcd>().get(handle); } const MVAComputerContainer *container = handle.product(); // Load our MVA bool reload = computer_.update(container, name_.c_str()); // If the MVA changed, update our list of discriminant plugins if (reload && computer_.get()) loadDiscriminantPlugins(container->find(name_)); // Update the event info for all of our discriminators BOOST_FOREACH(PluginMap::value_type plugin, plugins_) { plugin.second->setup(evt, es); } }
void reco::tau::RecoTauMVAHelper::train | ( | const PFTauRef & | tau, |
bool | target, | ||
double | weight = 1.0 |
||
) | const |
Definition at line 124 of file RecoTauMVAHelper.cc.
References PhysicsTools::Variable::ValueList::add(), PhysicsTools::Variable::ValueList::clear(), computer_, fillValues(), and values_.
{ static const PhysicsTools::AtomicId kTargetId("__TARGET__"); static const PhysicsTools::AtomicId kWeightId("__WEIGHT__"); if (!computer_) return; values_.clear(); values_.add(kTargetId, target); values_.add(kWeightId, weight); // Build the discriminant values fillValues(tau); computer_->eval(values_); }
Definition at line 67 of file RecoTauMVAHelper.h.
Referenced by operator()(), setEvent(), and train().
std::string reco::tau::RecoTauMVAHelper::eslabel_ [private] |
Definition at line 63 of file RecoTauMVAHelper.h.
Referenced by setEvent().
std::string reco::tau::RecoTauMVAHelper::name_ [private] |
Definition at line 61 of file RecoTauMVAHelper.h.
Referenced by setEvent().
Definition at line 65 of file RecoTauMVAHelper.h.
Referenced by loadDiscriminantPlugins().
Definition at line 71 of file RecoTauMVAHelper.h.
Referenced by fillValues(), loadDiscriminantPlugins(), and setEvent().
PhysicsTools::Variable::ValueList reco::tau::RecoTauMVAHelper::values_ [mutable, private] |
Definition at line 77 of file RecoTauMVAHelper.h.
Referenced by discriminants(), fillValues(), operator()(), and train().